How to convert Math Formula to Python code?

☆樱花仙子☆ 提交于 2019-12-20 16:49:20

问题


Are there any easy ways to convert mathematical formulas to Python code? Perhaps translators, web reference, specific book chapters, anything ~

For regular expressions there are programs such as Kodos and sites such as pythonregex.com, so I was hoping there would be something similar for formula notation and Python.


回答1:


No, this isn't possible in general. There are mathematical functions that aren't computable (for example, see wikipedia/Halting_problem). There are other mathematical functions where it's just not obvious how to code them up (consider a difficult integral or differential equations). There are many books written on finding numerical solutions to these sorts of problems (you can find some links here: wikipedia/Numerical_analysis).

For simple cases, you can transcribe mathematical formulae directly, but any automated means of translation would require a formal language for writing mathematical formulae in what would be a programming language in itself. This would beg the question, since you would be trading writing mathematical formulae in one language with writing them in another.




回答2:


You could try to make your own with sympy and pyparsing.



来源:https://stackoverflow.com/questions/4912457/how-to-convert-math-formula-to-python-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!