From 16b9977c23f23a706c19abac5fbd4f1b90f5f866 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Wed, 27 Aug 2025 11:26:11 +0100 Subject: [PATCH 1/5] Restructured content and added the workaround for reserved terms. --- app/docs/user.md | 66 +++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 23 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index 1c0b5a5..53712e0 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -496,7 +496,7 @@ $3$ If the parameter `complexNumbers` is set to `true` then `I` will be interpreted as the imaginary constant $i$. -**Note:** When `i` is used to denote the imaginary constant, then it can end up forming reserved keywords when used with other symbols, e.g. `xi` will be interpreted as $\xi$ instead of $x \cdot i$. To see how to avoid this kind of issue, see *Overriding greek letters or other reserved symbols with input symbols*. +**Note:** When `i` is used to denote the imaginary constant, then it can end up forming reserved keywords when used with other symbols, e.g. `xi` will be interpreted as $\xi$ instead of $x \cdot i$. To see how to avoid this kind of issue, see [Working with Reserved Characters](#workiing-with-reserved-characters). In this example, `complexNumbers` is set to `true` and the answer is `2+I`. An input symbols has also been added so that `I` can be replaced with `i` or `j`. @@ -508,26 +508,6 @@ Any response that is mathematically equivalent $2+i$ to will be accepted, e.g. ` Examples of how to use the `constant` and `function` assumptions for symbols. -#### Overriding greek letters or other reserved symbols with input symbols - -Sometimes there can be ambiguities in the expected responses. For example `xi` in a response could either be interpreted as the greek letter $\xi$ or as the multiplication $x \cdot i$. - -If there is an ambiguity the parser will choose the longest corresponding string, in the example above that means that `xi` will be interpreted as $\xi$ rather than $x \cdot i$. - -This behaviour can in many cases be overridden using input symbols, by letting the meaning with the longer corresponding string be an alternative to the interpretation consisting of several shorter strings. In the above example adding an input symbol with code `x\*i` and alternative `xi` will ensure that `xi` will be interpreted as $x \cdot i$ rather than $\xi$. - -In this example the answer is set to $5 x \mathbf{i}-12 y \mathbf{j}$, while `strict_syntax` is set to false and `elementary_functions` is set to true. - -In order for the response `5xi-12yj` to be interpreted as $5 x \mathbf{i}-12 y \mathbf{j}$ instead of $5 \xi-12 y \mathbf{j}$ the following input symbols have been added: - -| Symbol | Code | Alternatives | -|:--------------------|:-----|:-------------| -| `\$x\$` | x | | -| `\$\\mathbf{i}\$` | i | | -| `\$x \\mathbf{i}\$` | x\*i | xi | -| `\$y\$` | y | | -| `\$\\mathbf{j}\$` | j | | - #### Comparing equalities involving partial derivatives - Using the `constant` and `function` assumptions The response should be some expression that is equivalent to this equation (i.e. `answer`): @@ -618,7 +598,47 @@ Here is an example of an integral that can be fully evaluated, more specifically The boundary and function does not need to be defined explicitly. As an example of a more abstract integral we can consider $\int_a^b f(x)+g(x) \mathrm{d}x$. If the answer is set to `Integral(f(x)+g(x), (x, a, b))` then, for example, `int(g(x)+f(x), (x, a, b))` $\int_a^b g(x)+f(x) \mathrm{d}x$ and `int(f(x), (x, a, b)) + int(g(x), (x, a, b))` $\int_a^b f(x) \mathrm{d}x+\int_a^b g(x) \mathrm{d}x$. -## Euler's number +## Working with Reserved Characters -SymPy recommends that you not use I, E, S, N, C, O, or Q for variable or symbol names, as those are used for the imaginary unit, the base of the natural logarithm, the sympify function, numeric evaluation, the big O order symbol, and the assumptions object that holds a list of supported ask keys, respectively. You can use the mnemonic OSINEQ to remember what Symbols are defined by default in SymPy. Or better yet, always use lowercase letters for Symbol names. Python will not prevent you from overriding default SymPy names or functions, so be careful." +SymPy recommends that you not use I, E, S, N, C, O, or Q for variable or symbol names, as those are used for the imaginary unit ($i$), the base of the natural logarithm ($e$), the sympify function (`S()`), numeric evaluation (`N()`), the big O order symbol (as in $O(n)$), and the assumptions object that holds a list of supported ask keys (such as `Q.real`), respectively. You can use the mnemonic OSINEQ to remember what Symbols are defined by default in SymPy. Or better yet, always use lowercase letters for Symbol names. Python will not prevent you from overriding default SymPy names or functions, so be careful." For more information checkout the [SymPy Docs](https://docs.sympy.org/latest/explanation/gotchas.html#predefined-symbols) + +If you want to use a symbol that is usually reserved for some reserved character, e.g. ‘E’, do as follows: +1. Create an input symbol where the code is different that the symbol you want to use, e.g. ‘Ef’ or 'Euler' instead of ‘E’ +2. Add the symbol you want to use as an alternative, e.g. the alternatives could be set to ‘E’ + +#### Example: +For the answer: +$A/(b*l)$ + +And then add an input symbol: + +Symbol: ϵ +Code: b +Alternatives: ϵ,ε,E,e,Ep + +Here the answer A/El is marked as correct. + +Note: the 'code' in the input symbol must be a single letter symbol. You can use multi-letter alternatives though. + +Now you have a symbol 'b'. In Lambda Feedback, you can hide it from the input symbols. Unfortunately it must be single letter and, unfortunately, it can't be a lower case 'e'. + +### Overriding greek letters or other reserved symbols with input symbols + +Sometimes there can be ambiguities in the expected responses. For example `xi` in a response could either be interpreted as the greek letter $\xi$ or as the multiplication $x \cdot i$. + +If there is an ambiguity the parser will choose the longest corresponding string, in the example above that means that `xi` will be interpreted as $\xi$ rather than $x \cdot i$. + +This behaviour can in many cases be overridden using input symbols, by letting the meaning with the longer corresponding string be an alternative to the interpretation consisting of several shorter strings. In the above example adding an input symbol with code `x\*i` and alternative `xi` will ensure that `xi` will be interpreted as $x \cdot i$ rather than $\xi$. + +In this example the answer is set to $5 x \mathbf{i}-12 y \mathbf{j}$, while `strict_syntax` is set to false and `elementary_functions` is set to true. + +In order for the response `5xi-12yj` to be interpreted as $5 x \mathbf{i}-12 y \mathbf{j}$ instead of $5 \xi-12 y \mathbf{j}$ the following input symbols have been added: + +| Symbol | Code | Alternatives | +|:--------------------|:-----|:-------------| +| `\$x\$` | x | | +| `\$\\mathbf{i}\$` | i | | +| `\$x \\mathbf{i}\$` | x\*i | xi | +| `\$y\$` | y | | +| `\$\\mathbf{j}\$` | j | | From 23ee3cbe0b0d3b9d99f11c0d1282d244492a6f5c Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Fri, 29 Aug 2025 11:24:07 +0100 Subject: [PATCH 2/5] GH-221 Actioned Peter's comments in #222. --- app/docs/user.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index 53712e0..206253d 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -609,17 +609,14 @@ If you want to use a symbol that is usually reserved for some reserved character #### Example: For the answer: -$A/(b*l)$ - -And then add an input symbol: - +$A/(El*l)$ $E$ is reserved, so we replace $E$ with $b$ and provide alternatives as input symbols: Symbol: ϵ Code: b Alternatives: ϵ,ε,E,e,Ep Here the answer A/El is marked as correct. -Note: the 'code' in the input symbol must be a single letter symbol. You can use multi-letter alternatives though. +Note: the 'code' in the input symbol must be a single letter symbol. Now you have a symbol 'b'. In Lambda Feedback, you can hide it from the input symbols. Unfortunately it must be single letter and, unfortunately, it can't be a lower case 'e'. From 3c9e25e5464ddcc4ea27407b266116671f14559d Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Fri, 5 Sep 2025 16:02:13 +0100 Subject: [PATCH 3/5] GH-221 Refactored README to separate implicit multiplication --- app/docs/user.md | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index 206253d..725436e 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -609,17 +609,31 @@ If you want to use a symbol that is usually reserved for some reserved character #### Example: For the answer: -$A/(El*l)$ $E$ is reserved, so we replace $E$ with $b$ and provide alternatives as input symbols: +$A/(E*l)$, $E$ is reserved, so we replace $E$ with $ef$ and provide alternatives as input symbols: + +Symbol: $ϵ$ + +Code: `ef` + +Alternatives: `ϵ,ε,E,e,Ep` + +Here the answer $A/(E*l)$ is marked as correct. + + +### Reserved Characters and Implicit Multiplication +As implicit multiplication cannot decypher what is a multi-character code and what are two variables that should be multiplied, single letter codes should be used. + +#### Example +With `"convention": "implicit_higher_precedence"` set + +For the answer: +$A/(E*l)$ $E$ is reserved, so we replace $E$ with $b$ and provide alternatives as input symbols: Symbol: ϵ Code: b Alternatives: ϵ,ε,E,e,Ep Here the answer A/El is marked as correct. -Note: the 'code' in the input symbol must be a single letter symbol. - -Now you have a symbol 'b'. In Lambda Feedback, you can hide it from the input symbols. Unfortunately it must be single letter and, unfortunately, it can't be a lower case 'e'. - ### Overriding greek letters or other reserved symbols with input symbols Sometimes there can be ambiguities in the expected responses. For example `xi` in a response could either be interpreted as the greek letter $\xi$ or as the multiplication $x \cdot i$. From ccfaeb740c60351f009773a7950fc1e7b12584a5 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Thu, 2 Oct 2025 11:18:17 +0100 Subject: [PATCH 4/5] Added note about #223 in the docs --- app/docs/user.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index 725436e..ad85511 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -21,13 +21,15 @@ If you want to use `I` for the imaginary constant, set the grading parameter `co Changes the implicit multiplication convention. If unset it will default to `equal_precedence`. -If set to `implicit_higher_precedence` then implicit multiplication will have higher precedence than explicit multiplication, i.e. `1/ab` will be equal to `1/(ab)` and `1/a*b` will be equal to `(1/a)*b`. +If set to `implicit_higher_precedence` then implicit multiplication will have higher precedence than explicit multiplication, i.e. `1/ab` will be equal to `1/(ab)` and `1/a*b` will be equal to `(1/a)*b`. + +**_NOTE:_** Currently, if implicit multiplication has higher precedence, then multi-character custom symbols are not supported. For example, if you have defined the symbol `bc` with an answer `a/(bc*d)` then `a/(bcd)` will fail, as it is treated as `a/(b * c * d)`. If set to `equal_precedence` then implicit multiplication will have the same precedence than explicit multiplication, i.e. both `1/ab` and `1/a*b` will be equal to `(1/a)*b`. #### `criteria` -The `criteria` parameter can be used to customize the comparison performed by the evaluation function. If unset the evaluation function will will default to checking if the answer and response are symbolically equal. +The `criteria` parameter can be used to customize the comparison performed by the evaluation function. If unset the evaluation function will default to checking if the answer and response are symbolically equal. The `criteria` parameter takes a string that defines a set of (comma separated) mathematical statements. If all statements in the list are true the response is considered correct. From 960940c139b9e0c72e179546ca3d20699628ae29 Mon Sep 17 00:00:00 2001 From: Marcus Messer Date: Wed, 3 Dec 2025 11:10:39 +0000 Subject: [PATCH 5/5] Actioned comments --- app/docs/user.md | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/app/docs/user.md b/app/docs/user.md index ad85511..322d37f 100644 --- a/app/docs/user.md +++ b/app/docs/user.md @@ -609,32 +609,45 @@ If you want to use a symbol that is usually reserved for some reserved character 1. Create an input symbol where the code is different that the symbol you want to use, e.g. ‘Ef’ or 'Euler' instead of ‘E’ 2. Add the symbol you want to use as an alternative, e.g. the alternatives could be set to ‘E’ +See note in [`convention`](#convention) for the limitations of using multi character symbols and implicit multiplication higher precedence. + #### Example: For the answer: -$A/(E*l)$, $E$ is reserved, so we replace $E$ with $ef$ and provide alternatives as input symbols: +$A/(\epsilon*l)$, `e` is reserved as Euler's number, so we replace `e` with `ef` or any other character(s) that are not reserved or used in the expression and provide alternatives as input symbols: -Symbol: $ϵ$ +Symbol: $\epsilon$ Code: `ef` Alternatives: `ϵ,ε,E,e,Ep` -Here the answer $A/(E*l)$ is marked as correct. +Here the answer $A/(ef*l)$ is marked as correct, and so are the alternatives: +- $A/(ϵ*l)$ +- $A/(ε*l)$ +- $A/(E*l)$ +- $A/(e*l)$ +- $A/(Ep*l)$ + -### Reserved Characters and Implicit Multiplication -As implicit multiplication cannot decypher what is a multi-character code and what are two variables that should be multiplied, single letter codes should be used. #### Example +As implicit multiplication with higher precedence cannot decypher what is a multi-character code and what are two variables that should be multiplied (see [`convention`](#convention) for more detail), single letter codes should be used. With `"convention": "implicit_higher_precedence"` set For the answer: -$A/(E*l)$ $E$ is reserved, so we replace $E$ with $b$ and provide alternatives as input symbols: -Symbol: ϵ +$A/(\epsilon*l)$, `e` is reserved as Euler's number, so we replace `e` with `b` or any other character(s) that are not reserved or used in the expression and provide alternatives as input symbols: +Symbol: $\epsilon$ Code: b Alternatives: ϵ,ε,E,e,Ep -Here the answer A/El is marked as correct. +Here the following are marked as correct: +- $A/(b*l)$ or $A/(bl)$ or $A/bl$ +- $A/(ϵ*l)$ or $A/(ϵl)$ or $A/ϵl$ +- $A/(ε*l)$ or $A/(εl)$ or $A/εl$ +- $A/(E*l)$ or $A/(El)$ or $A/El$ +- $A/(e*l)$ or $A/(el)$ or $A/e*l$ +- $A/(Ep*l)$ or $A/(Epl)$ or $A/Epl$ ### Overriding greek letters or other reserved symbols with input symbols