Skip to content

SymbolicEqual

Edit on GitHub View Code


Evaluates the equality between two symbolic expressions using the python SymPy package.

Note that pi is a reserved constant and cannot be used as a symbol name.

Inputs

Optional grading parameters

There are eight optional parameters that can be set: complexNumbers, elementary_functions, specialFunctions, strict_syntax, symbol_assumptions, multiple_answers_criteria, plus_minus and minus_plus.

complexNumbers

If you want to use I for the imaginary constant, set the grading parameter complexNumbers to True.

elementary_functions

When using implicit multiplication function names with mulitple characters are sometimes split and not interpreted properly. Setting elementary_functions to true will reserve the function names listed below and prevent them from being split. If a name is said to have one or more alternatives this means that it will accept the alternative names but the reserved name is what will be shown in the preview.

sin, sinc, csc (alternative cosec), cos, sec, tan, cot (alternative cotan), asin (alternative arcsin), acsc (alternatives arccsc, arccosec), acos (alternative arccos), asec (alternative arcsec), atan (alternative arctan), acot (alternatives arccot, arccotan), atan2 (alternative arctan2), sinh, cosh, tanh, csch (alternative cosech), sech, asinh (alternative arcsinh), acosh (alternative arccosh), atanh (alternative arctanh), acsch (alternatives arccsch, arcosech), asech (alternative arcsech), exp (alternative Exp), E (equivalent to exp(1), alternative e), log, sqrt, sign, Abs (alternative abs), Max (alternative max), Min (alternative min), arg, ceiling (alternative ceil), floor

specialFunctions

If you want to use the special functions beta (Euler Beta function), gamma (Gamma function) and zeta (Riemann Zeta function), set the grading parameter specialFunctions to True.

strict_syntax

If strict_syntax is set to true then the answer and response must have * or / between each part of the expressions and exponentiation must be done using **, e.g. 10*x*y/z**2 is accepted but 10xy/z^2 is not.

If strict_syntax is set to false, then * can be omitted and ^ used instead of **. In this case it is also recommended to list any multicharacter symbols expected to appear in the response as input symbols.

By default strict_syntax is set to true.

symbol_assumptions

This input parameter allows the author to set an extra assumption each symbol. Each assumption should be written on the form ('symbol','assumption name') and all pairs concatenated into a single string.

The possible assumption names can be found in this list: SymPy Assumption Predicates

multiple_answers_criteria

The \(\pm\) and \(\mp\) symbols can be represented in the answer or response by plus_minus and minus_plus respectively.

Answers or responses that contain \(\pm\) or \(\mp\) has two possible interpretations which requires further criteria for equality. The grading parameter multiple_answers_criteria controls this. The default setting, all, is that each answer must have a corresponding answer and vice versa. The setting all_responses check that all responses are valid answers and the setting all_answers checks that all answers are found among the responses.

plus_minus and minus_plus

The \(\pm\) and \(\mp\) symbols can be represented in the answer or response by plus_minus and minus_plus respectively.

To use other symbols for \(\pm\) and \(\mp\) set the grading parameters plus_minus and minus_plus to the desired symbol. Remark: symbol replacement is brittle and can have unintended consequences.

Outputs

Outputs to the eval command will feature:

{
  "command": "eval",
  "result": {
    "is_correct": "<bool>",
    "response_latex": "<str>",
    "response_simplified": "<str>",
    "level": "<int>"
  }
}

response_latex

This is a latex string, indicating how the user's response was understood by SymPy. It can be used to provide feedback in the front-end.

level

The function tests equality using three levels, of increasing complexity. This parameter indicates the level at which equality was found. It is not present if the result is incorrect.

response_simplified

This is a math-simplified string of the given response. All mathematically-equivalent expressions will yield identical strings under this field. This can be used by teacher dashboards when aggregating common student errors.

Examples