# Part 9: Expressions And Relations¶

## Expressions usable in \function¶

In a Mumie TeX problem document you may use the \function command within a variables section to define a variable of type function.

Syntax:
\function{ function_name }{ expression }

Example:

\begin{variables}
\number{a}{-2}
\function{f}{a*x^2+2}
\end{variables}


This introduces first a number variable a with value -2, and then a function variable f with value -2x²+2, considering that a is assigned the value -2.
More generally: An expression in a Mumie problem is by definition:

Definition
• a fixed number from a field defined by \field
• a variable name including variables (or functions) defined elsewhere in the variables section.
• if expr is an expression, then so is ( expr )
• if expr is an expression, then so is - expr
• if expr1 and expr2 are expressions, then expr1 + expr2 is an expression
• same for - ,* ,/ ,^, mod
• if expr is an expression, then so is sqrt( expr ), denoting the square root
• other admissible function names are:
• cbrt() -cubic root
• sin(), cos(), tan(), cot(), sinh(), cosh(), tanh, coth(), arcsin(), arccos(), arctan(), arccot(), arsinh(), arcosh(), artanh(), arcoth(), ln(), log_base() base must be integer or Euler number e, log(), exp() , with usual meaning
• also abs() for absolute value, fac() for integer factorial function, floor() math floor, re(), im() and conj() for complex real and imaginary part and complex conjugate,
• finally, sign() and theta() to denote the signum and Heaviside functions.
• if expr is an expression, then so is | expr | as an alternative for abs( expr )
• if expr is an expression and n is a positive integer, than expr#n is an alternative way to write expr^(1/n)
Hints:
• observe the usual precedence rules: so expr1 * expr2 is in general not the product of both expressions as seen by the example a+b*c+d
• mod denotes the modulo operator; thus, for two integral numbers a and b, a mod b is the reminder of the division of a by b
• standard functions have to be written with their parentheses, so sin x is not permitted
• do not denote variables by standard function names
• observe that in the generic TeX framework discussed here all functions defined by the \function command are expected to define functions on R, N, Q or, possibly, C, so the expression in function{ function_name }{ expression } should use at most one more variable than defined in the corresponding variables section, namely the independent variable of the function -placeholder-, denoting an element of the function domain. You may call it x or y or whatever, but this variable name must not occur in the variables section.

## Expressions usable in \checkFuncForZero¶

The \checkFuncForZero command is used to check a functional of user defined functions for being zero numerically.
User defined functions are e.g. defined by the student's inputs via the command \inputAsFunction. The corresponding inputs can be checked by the corrector program using the criterion delivered by \checkFuncForZero.

Syntax:
\checkFuncForZero{ functionial_expression }{ lower_check_bound }{ upper_check_bound }{ number_checkpoints }

A functional_expression is in principle an expression in the occuring functions which may be subject to the usual arithmetic operations and additionally composition and derivation operations.
So the definition of an expression as above is extended by the following:
• any expression as defined above is a functional expression, too
• a function name declared by an \inputAsFunction command in the same question block is a functional expression
• If expr is a functional expression and f is a function name either declared by a \function command or by an \inputAsFunction command in the same question block, then f[ expression ]is a functional expression (observe: you must use square brackets in case of these function names, while you have to use round brackets in case of standard functions like sqrt or sin)
• If expr is a functional expression, then D[ expression ] is a functional expression, denoting the derivative of expression (so avoid D as a functions or variables name)
This defines, what a syntactically correct functional expression is.
Hence in particular you may use
• fixed numbers as 3.1415
• valid number variables, declared by \number or \randint
• valid programmer defined functions declared by \function
• valid user defined (input) functions declared by \inputAsFunction
• explicitely defined functions (as x^2+3), but only x is allowed here as valid (non-declared) 'true' variable (-placeholder-)
Examples:
• f[g], if f and g are function names
• sin(f) , if f is a function name
• f[sin(x)] , if f is a function name
• D[D[f]] , if f is a function name
• f[x^3+a*x+b] , if f is a function's name and a is a declared number variable or function variable

The \randadjustIf command is used to redefine number variables which had been declared by \randint in order to avoid certain infavorable combinations of variables.

Syntax:
\randadjustIf { list_of_variables }{ avoidance_relation }

We define, what a relation is:
• If expr1, expr2 are expressions, then expr1 = expr2 is a relation
• same for the other comparision operators != (means unequal), >, <, >= , <=
• If rel is a relation, then [ rel ] is a relation (observe that square brackets are used to bundle relations)
• If rel1 , rel2 are relations, then rel1 AND rel2 is a relation, as well as rel1 OR rel2 and
NOT rel1 are relations

Observe the precedence rules: NOT precedes AND precedes OR.
Also, bear in mind, that we are talking about avoidance relations in the context of \randadjustIf , so in the example a

\randint{a}{2}{20}
\randint[Z]{b}{-20}{20}

\randint{a}{2}{20}