Builtin functions

The functions an expression may call, grouped by the kind of value they work on. This page is generated from rhema doc, so it lists exactly what the compiler accepts; calling one with the wrong number of arguments is an error the checker reports. A function given the wrong kind of value stops generation with a message naming both.

Numbers, text and rendering

Functions on numbers and text, and the two that write operators with the right brackets.

Function Arguments
str 1 The text of a number or other value.
paren 1 Its argument with brackets around it.
infix 3 infix($1, "+", $3): the two children joined by the operator text, bracketed as the precedence table requires.
prefix 2 prefix("\neg", $2): the operator text before the child, bracketed as the precedence table requires.
cond 3 cond(c, a, b): a when c is true, b otherwise.
abs 1 The absolute value of a number.
min 2 The smaller of two numbers.
max 2 The larger of two numbers.
bit_and 2 Bitwise and of two whole numbers; with bit_or, a way to track which of several items a subtree has used.
bit_or 2 Bitwise or of two whole numbers.
bit_xor 2 Bitwise exclusive or of two whole numbers.
number_latex 1 A number in LaTeX: a whole number as it is, a fraction as \frac{p}{q} with its sign in front.

Generators

Leaves that draw a whole number. They appear on the right of a production, or after random NAME =; their arguments are whole numbers.

Function Arguments
integer 1 integer(n): a whole number with exactly n digits.
nonzero_integer 1 nonzero_integer(n): as integer, never 0.
integer_between 2 integer_between(a, b): a whole number from a to b inclusive.
nonzero_integer_between 2 nonzero_integer_between(a, b): as integer_between, never 0.

Whole numbers

Counting and number theory on whole numbers: factorials, binomial coefficients and permutations, greatest common divisors and least common multiples, powers and inverses modulo n. A result too large for a 63-bit integer, or an inverse that does not exist, stops generation with a message.

Function Arguments
factorial 1 factorial(n): n!, for n from 0 to 20.
choose 2 choose(n, k): the number of ways to choose k of n; 0 when k is out of range.
permutations 2 permutations(n, k): the number of ordered choices of k of n.
gcd 2 The greatest common divisor of two whole numbers.
lcm 2 The least common multiple of two whole numbers.
pow_mod 3 pow_mod(a, k, n): the remainder of a^k on division by n, for k >= 0 and n > 0.
mod_inverse 2 mod_inverse(a, n): the x in 0..n-1 with a x = 1 (mod n); an error unless a and n are coprime.

Formulas

Symbolic expressions in named variables: constants, variables, the four operations and powers, sin, cos, tan, exp, ln and sqrt, with differentiation, substitution, a zero test and LaTeX. A formula answer is graded by WeBWorK as a formula.

Function Arguments
formula_constant 1
formula_variable 1
formula_add 2
formula_subtract 2
formula_multiply 2
formula_divide 2
formula_power 2
formula_negate 1
formula_sin 1
formula_cos 1
formula_tan 1
formula_exp 1
formula_ln 1
formula_sqrt 1
formula_substitute 3
differentiate 2 differentiate(f, "x"): the derivative of formula f with respect to x.
formula_latex 1
formula_is_zero 1
formula_to_polynomial 2

Polynomials

Polynomials in one variable with exact coefficients: building from monomials, linear and quadratic factors, arithmetic, expansion, evaluation, coefficients and degree, factored forms for the PolynomialFactors context, and LaTeX.

Function Arguments
polynomial_constant 2
polynomial_variable 1
polynomial_monomial 3
polynomial_linear 3
polynomial_quadratic 4
polynomial_add 2
polynomial_subtract 2
polynomial_multiply 2
polynomial_scale 2
polynomial_power 2
polynomial_derivative 1
polynomial_evaluate 2
polynomial_coefficient 2
polynomial_degree 1
polynomial_is_zero 1
polynomial_formula 1
polynomial_latex 1
polynomial_equation 2

Equations

Equations between two formulas, solved exactly where possible. An equation is not itself an answer: equation_solution_set and equation_unique_solution give one.

Function Arguments
equation 2
equation_normal_form 1
equation_latex 1
equation_is_satisfied 3
equation_has_exact_solutions 2
equation_solution_count 2
equation_solution_set 2
equation_unique_solution 2

Propositions

Propositional formulas over named variables, built from bool_var and the connectives, and decided by enumerating every assignment: evaluation under an assignment, equivalence, tautology and contradiction tests, model counting, rewriting without the conditional connectives, and shape inspection (top connective, counts of connectives and negations). A proposition answer is graded in the Boolean context.

Function Arguments
bool_var 1
bool_true 0
bool_false 0
bool_not 1
bool_and 2
bool_or 2
bool_xor 2
bool_imp 2
bool_iff 2
bool_latex 1
bool_equivalent 2
bool_evaluate 3
bool_sensitivity 3
bool_is_tautology 1
bool_is_contradiction 1
bool_is_tidy 1
bool_is_atom 1
bool_top 1
bool_size 1
bool_negations 1
bool_depth 1
bool_count 2
bool_variable_count 1
bool_model_count 1
bool_without_conditionals 1

Matrices

Matrices with exact rational entries: 2 by 2 and 3 by 3 construction, the identity, sum, difference, product, scalar multiple, transpose, determinant, inverse, entries, a matrix times a vector, and LaTeX (a whole matrix, or a row written as a linear equation). A matrix answer is graded in the Matrix context.

Function Arguments
matrix2 4
matrix3 9
matrix_identity 1
matrix_add 2
matrix_subtract 2
matrix_multiply 2
matrix_scale 2
matrix_transpose 1
matrix_determinant 1
matrix_inverse 1
matrix_is_invertible 1
matrix_entry 3
matrix_vector 2
matrix_latex 1
matrix_row_latex 2

Sets

Finite sets, intervals and rays of real numbers, with union, intersection and difference, and LaTeX. A set answer is graded in the Interval context.

Function Arguments
set_empty 0
set_insert 2
set_interval 4
set_above 2 set_above(a, closed): the numbers above a, (a, \infty), or from a, [a, \infty), when closed is true.
set_below 2 set_below(a, closed): the numbers below a, (-\infty, a), or up to a, (-\infty, a].
set_union 2
set_intersection 2
set_difference 2
set_latex 1

Vectors

Vectors with exact entries: sums, multiples, dot and cross products, norms, unit vectors, parallel and direction tests, and the answer forms WeBWorK's Vector context needs.

Function Arguments
vector_entry 2
vector2 2
vector3 3
vector4 4
vector_add 2
vector_subtract 2
vector_scale 2
vector_dot 2
vector_cross 2
vector_latex 1
vector_is_zero 1
vector_norm_answer 1
vector_unit_answer 1
vector_parallel_answer 1
vector_same_direction_answer 1

Complex numbers

A complex number from its real and imaginary parts, and its LaTeX. Complex arithmetic is written with the ordinary operators on the parts.

Function Arguments
complex 2
complex_latex 2

134 functions in all.