Skip to content

SymbolicEqual

Edit on GitHub View Code


Supported Response Area Types

This evaluation function is supported by the following Response Area components:

  • TEXT
  • EXPRESSION

This function utilises the SymPy to provide a maths-aware comparsion of a student's response to the correct answer. This means that mathematically equivalent inputs will be marked as correct. Note that pi is a reserved constant and cannot be used as a symbol name.

Note that this function is designed to handle comparisons of mathematical expressions but has some limited ability to handle comparison of equations as well. More precisely, if the answer is of the form \(f(x_1,\ldots,x_n) = g(x_1,\ldots,x_n)\) and the response is of the form \(\tilde{f}(x_1,\ldots,x_n) = \tilde{g}(x_1,\ldots,x_n)\) then the function checks if \(f(x_1,\ldots,x_n) - g(x_1,\ldots,x_n)\) is a multiple of \(\tilde{f}(x_1,\ldots,x_n) / \tilde{g}(x_1,\ldots,x_n)\).

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.

Examples

Implemented versions of these examples can be found in the module 'Examples: Evaluation Functions'.

1 Setting input symbols to be assumed positive to avoid issues with fractional powers

In general \(\frac{\sqrt{a}}{\sqrt{b}} \neq \sqrt{\frac{a}{b}}\) but if \(a > 0\) and \(b > 0\) then \(\frac{\sqrt{a}}{\sqrt{b}} = \sqrt{\frac{a}{b}}\). The same is true for other fractional powers.

So if expression like these are expected in the answer and/or response then it is a good idea to use the symbol_assumptions parameter to note that \(a > 0\) and \(b > 0\). This can be done by setting symbol_assumptions to ('a','positive') ('b','positive').

The example given in the example problem set uses an EXPRESSION response area that uses SymbolicEqual with answer sqrt(a/b), strict_syntax set to false and symbol_assumptions set as above. Some examples of expressions that are accepted as correct: sqrt(a)/sqrt(b), (a/b)**(1/2), a**(1/2)/b**(1/2), (a/b)^(0.5), a^(0.5)/b^(0.5)