Sagemath 作为守护程序服务 - 未定义名称'e'"



我一直在使用Sagemath作为守护程序服务,遵循这里提供的Python代码:

https://ask.sagemath.org/question/23431/running-sage-from-other-languages-with-higher-performance/

该代码使用python套接字将Sagemath设置为守护进程服务

我通过php套接字调用套接字来连接这个sagemath守护进程,它工作得很好,只是它不识别常量"e",而它识别的是"pi"。

例如,如果我通过套接字调用运行simplify(4*pi^2*pi^3),它将正确执行代数,而如果我运行simplify(4*pi^2*pi^3*e),它将返回错误:

ERROR: <class 'NameError'> name 'e' is not defined

根据我所收集的信息,当以这种方式运行时,Sagemath将需要显式导入库。python守护进程中的导入是:

import sys
from io import StringIO
from sage.all import *
from sage.calculus.predefined import x
from sage.repl.preparse import preparse

一个临时解决方法是对e使用exp(1)

最新更新