本文整理汇总了Python中sage.symbolic.ring.SR.subs方法的典型用法代码示例。如果您正苦于以下问题:Python SR.subs方法的具体用法?Python SR.subs怎么用?Python SR.subs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.symbolic.ring.SR
的用法示例。
在下文中一共展示了SR.subs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mma_free_integrator
# 需要导入模块: from sage.symbolic.ring import SR [as 别名]
# 或者: from sage.symbolic.ring.SR import subs [as 别名]
def mma_free_integrator(expression, v, a=None, b=None):
"""
sage: from sage.symbolic.integration.external import mma_free_integrator
sage: mma_free_integrator(sin(x), x) # optional - internet
-cos(x)
"""
import urllib, re
# We need to integrate against x
vars = [str(x) for x in expression.variables()]
if any(len(x)>1 for x in vars):
raise NotImplementedError("Mathematica online integrator can only handle single letter variables.")
x = SR.var('x')
if repr(v) != 'x':
for i in range(ord('a'), ord('z')+1):
if chr(i) not in vars:
shadow_x = SR.var(chr(i))
break
expression = expression.subs({x:shadow_x}).subs({dvar: x})
params = urllib.urlencode({'expr': expression._mathematica_init_(), 'random': 'false'})
page = urllib.urlopen("http://integrals.wolfram.com/index.jsp", params).read()
page = page[page.index('"inputForm"'):page.index('"outputForm"')]
page = re.sub("\s", "", page)
mexpr = re.match(r".*Integrate.*==</em><br/>(.*)</p>", page).groups()[0]
try:
ans = SR(mexpr.lower().replace('[', '(').replace(']', ')'))
if repr(v) != 'x':
ans = ans.subs({x:v}).subs({shadow_x:x})
return ans
except TypeError:
raise ValueError("Unable to parse: %s" % mexpr)