Skip to content
Classroom

Function (Algebraic Expression) Question Type

Students enter a mathematical function or algebraic expression without variable assignment. Commonly used for entering function definitions like f(x) = ....

Basic Syntax

[function]
answer = x^2 - 3*x + 2;

Options

answer (required)

The correct function expressed in terms of its variable(s).

[function]
answer = 2*sin(x) + cos(x);

variable

The variable(s) in the function. Defaults to x.

[function]
answer = a*t^2 + v*t + x0;
variable = t;

allowedvars

Variables that students are allowed to use in their answer.

[function]
answer = m*x + b;
variable = x;
allowedvars = m, x, b;

simplify

  • full (default) — Both expressions must simplify to the same form
  • none — Must match exactly
  • basic — Only combine like terms
[function]
answer = (x+1)*(x-1);
simplify = full;  // Accepts: x^2-1, x^2 - 1, etc.

allowcomplex

  • true — Allow complex numbers and complex functions
  • false (default) — Real numbers only
[function]
answer = sqrt(-1);
allowcomplex = true;

Examples

Linear Function

$m = rand(1, 5);
$b = rand(-5, 5);

Write the equation of a line with slope $m and y-intercept $b.
(Use `x` as your variable.)

[function]
answer = $m*x + $b;
variable = x;
simplify = full;

Piecewise Function

Write a piecewise function where:
- `f(x) = 2x` for `x ≤ 0`
- `f(x) = x^2` for `x > 0`

[function]
answer = {2*x : x <= 0, x^2 : x > 0};
variable = x;

Composition of Functions

If `f(x) = x^2 + 1` and `g(x) = 2*x`, find `f(g(x))`.

[function]
answer = 4*x^2 + 1;
variable = x;
simplify = full;

Inverse Function

Find the inverse of `f(x) = 3*x - 5`. Express as `f^(-1)(x) = ...`

[function]
answer = (x + 5)/3;
variable = x;
simplify = full;

Grading

The system: 1. Parses the student's expression as a function of the specified variable 2. Simplifies according to the simplify setting 3. Compares algebraically to the correct answer 4. Returns Correct if equivalent, Incorrect otherwise

Common Mistakes

  • Forgetting parentheses: 2x+3 vs. 2*(x+3) (very different!)
  • Operator precedence: Students often confuse order of operations
  • Implicit multiplication: 2x must be written as 2*x
  • Domain restrictions: Including domain notes when not asked (e.g., "x ≠ 0")

See Also

  • Calculated — Similar, but for standalone expressions
  • Interval — For domain/range notation
  • Solver Tool — Use symbolic math in your question text