0

I'm trying to use the simplify methods from Mathics in my Python program. The problem is, even I read the documentation of Mathics (https://mathics-development-guide.readthedocs.io/en/latest/extending/developing-code/calling-mathics-library-from-within-python-code.html) , I can't figure out how to use the "Simplify" method. I also tried to use the exemple one their documentation :

# This is the same as before
from mathics.session import MathicsSession
session = MathicsSession(catch_interrupt=True)

# These are Mathics classes we are going to use.
from mathics.core.expression import Expression, Integer

# Compute 20!
x = Expression("Factorial", Integer(10)
          ).evaluate(session.evaluation).to_python()
print(x) # 2432902008176640000

But it raised an error :

Traceback (most recent call last):
File "c:\Users\ASUS TUF\Documents\ESEO\Stage 
Technique\Dev\geneticSolver\mathics_test.py", line 10, in <module>
).evaluate(session.evaluation).to_python()
File "C:\Users\ASUS TUF\AppData\Local\Programs\Python\Python310\lib\site- 
packages\mathics\core\expression.py", line 441, in evaluate
names.add(expr.get_lookup_name())
File "C:\Users\ASUS TUF\AppData\Local\Programs\Python\Python310\lib\site-
packages\mathics\core\expression.py", line 636, in get_lookup_name   
lookup_symbol = lookup_symbol._head
AttributeError: 'str' object has no attribute '_head'

Does anyone has already worked with Mathics on Python and can explain me how to deal with it ?

  • Please provide the full exception stack trace. – FiddleStix Oct 13 '22 at 17:10
  • Updated, here is the full exception stack. – Tristan Caro Oct 14 '22 at 07:44
  • I have verified that there is either a problem in the docs for this example or a bug in the code (or both, but I suspect a docs issue). The simpler `result = session.evaluate("20!").to_python()` example does work for me. I would open an issue on their GitHub. – FiddleStix Oct 14 '22 at 09:32

0 Answers0