At the top of derivation pages I display errors associated with processing the page. Most of the errors are associated with the Abstract Syntax Trees (ASTs) that are in
For example, on the "curl curl identity" page https://derivationmap.net/review_derivation/000005/
in step 2339482: unable to eval AST for "sympy.Equality(cross(sympy.Symbol('E'), cross(Del, Del)), sympy.Function('nabla')(sympy.Add(sympy.Mul(sympy.Integer(-1), sympy.Symbol('E'), sympy.Pow(Del, sympy.Integer(2))), dot(sympy.Symbol('E'), Del))))"
I need to recreate the issue on my local instance of the site, so my first step is to launch a Docker image
cd ~/version_controlled/proofofconcept/v7_pickle_web_interface/flask/
make dockerlive
In the Docker container I have the same environment as the website, so I open Python and run Sympy to parse the expression
$ python
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
>>> import sympy
>>> sympy.__version__
'1.5.1'
>>> sympy.Equality(cross(sympy.Symbol('E'), cross(Del, Del)), sympy.Function('nabla')(sympy.Add(sympy.Mul(sympy.Integer(-1), sympy.Symbol('E'), sympy.Pow(Del, sympy.Integer(2))), dot(sympy.Symbol('E'), Del))))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'cross' is not defined
Looking in the file validate_dimensions_sympy.py the relevant import statements exist:
from sympy.vector import cross, dot # type: ignore
from sympy.vector.deloperator import Del # type: ignore
Next I looked in
logs/flask_critical_and_error_and_warning_and_info_and_debug.log
to see where the error is being observed.
The error occurs on line 2984 in controller.py.
Actually this reference is just a try/except based on validate_dimensions in validate_dimensions_sympy.py
As mentioned earlier, the "cross" and "dot" and "Del" are correctly imported. Going back to the REPL,
>>> from sympy.vector import cross, dot # type: ignore
>>> from sympy.vector.deloperator import Del # type: ignore
>>> sympy.Equality(cross(sympy.Symbol('E'), cross(Del, Del)), sympy.Function('nabla')(sympy.Add(sympy.Mul(sympy.Integer(-1), sympy.Symbol('E'), sympy.Pow(Del, sympy.Integer(2))), dot(sympy.Symbol('E'), Del))))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/sympy/core/cache.py", line 94, in wrapper
retval = cfunc(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/sympy/core/power.py", line 301, in __new__
obj = b._eval_power(e)
AttributeError: type object 'Del' has no attribute '_eval_power'
The other information in the error message we can leverage is step_ID. That step contains the expression_ID 7575859295 which has a complicated latex:
\\vec{ \\nabla} \\times \\vec{ \\nabla} \\times \\vec{E} = \\vec{ \\nabla}( \\vec{ \\nabla} \\cdot \\vec{E} - \\nabla^2 \\vec{E})
Eliminating the "\\vec{}" we get
\\nabla \\times \\nabla \\times E = \\nabla( \\nabla \\cdot E - \\nabla^2 E)
which can be parsed by Sympy:
>>> from sympy.parsing.latex import parse_latex
>>> parse_latex("\\nabla \\times \\nabla \\times E = \\nabla( \\nabla \\cdot E - \\nabla^2 E)")
Eq(E*(nabla*nabla), nabla(-E*nabla**2 + E*nabla))
>>> sympy.srepr(parse_latex("\\nabla \\times \\nabla \\times E = \\nabla( \\nabla \\cdot E - \\nabla^2 E)"))
"Equality(Mul(Symbol('E'), Mul(Symbol('nabla'), Symbol('nabla'))), Function('nabla')(Add(Mul(Integer(-1), Symbol('E'), Pow(Symbol('nabla'), Integer(2))), Mul(Symbol('E'), Symbol('nabla')))))"
The output string does not work as-is in the Python prompt
>>> Equality(Mul(Symbol('E'), Mul(Symbol('nabla'), Symbol('nabla'))), Function('nabla')(Add(Mul(Integer(-1), Symbol('E'), Pow(Symbol('nabla'), Integer(2))), Mul(Symbol('E'), Symbol('nabla')))))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'Equality' is not defined
Changes required:
- Mul --> cross
- Symbol('nabla') --> Del
- append "sympy." in front of commands
which gets us back to the original expression.
Staring at the expression, I see it contains
sympy.Pow(Del, sympy.Integer(2))
which is causing the error.
The solution is to replace the operation with
Mul(Del, Del)
in expression_ID 7575859295 in data.json