首页 > 解决方案 > 如何将枫树表达式转换为python代码?

问题描述

有没有比 Maple 中提供的 convert 函数更好的方法将 Maple 表达式转换为 Python(这似乎根本不起作用)

convert(9 + x, python)
Error, (in convert/python) cannot convert to python

标签: maple

解决方案


如果您尝试从某个 Maple 表达式生成 python 源代码,请查看CodeGeneration包。

例如,

CodeGeneration[Python]( 9+x );

  cg0 = 9 + x

还有一个,

func := proc(x) local y; y:=9+arcsin(x) end proc:

CodeGeneration[Python]( func );

  import math

  def func (x):
      y = 9 + math.asin(x)
      return(y)

convert(...,python)语法用于将某些类型的 Maple 表达式转换为可与(有限的)python 运行时仿真一起使用的替代内部表示。但是您已经描述了生成python“代码”,我认为它是指用于导出的源代码。


推荐阅读