Skip to content

Commit

Permalink
Small change towards symbolic=>sympy conversion of generic functions
Browse files Browse the repository at this point in the history
  • Loading branch information
man74cio committed Apr 14, 2017
1 parent 89e6ef4 commit ff2c44d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/sage/symbolic/expression_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,15 +603,15 @@ def derivative(self, ex, operator):
subs = ["%s = %s"%(t._maxima_init_(),a._maxima_init_()) for t,a in zip(temp_args,args)]
outstr = "at(diff(%s, %s), [%s])"%(f._maxima_init_(),
", ".join(params),
", ".join(subs))
", ".join(subs))
else:
f = operator.function()(*args)
params = operator.parameter_set()
params = ["%s, %s"%(args[i]._maxima_init_(), params.count(i)) for i in set(params)]
outstr = "diff(%s, %s)"%(f._maxima_init_(),
", ".join(params))
return outstr

def arithmetic(self, ex, operator):
"""
EXAMPLES::
Expand Down Expand Up @@ -756,15 +756,23 @@ def composition(self, ex, operator):
sage: s.composition(f, f.operator())
asin(2)
"""
# print('--- ex',ex)
# print('--- operator',operator)
f = operator._sympy_init_()
# print('--- f',f)
# print('diff f operator:',type(f),type(operator))
g = ex.operands()
# print('--- g',g)
import sympy

f_sympy = getattr(sympy, f, None)
if f_sympy:
return f_sympy(*sympy.sympify(g, evaluate=False))
else:
raise NotImplementedError("SymPy function '%s' doesn't exist" % f)
# MARCO MDIFS
# create generic function with nargs equal to initial function
return sympy.Function(f)(*tuple(g))
#raise NotImplementedError("SymPy function '%s' doesn't exist" % f)

sympy = SympyConverter()

Expand Down Expand Up @@ -1763,7 +1771,7 @@ def arithmetic(self, ex, operator):
if operator == add_vararg:
operator = _operator.add
elif operator == mul_vararg:
operator = _operator.mul
operator = _operator.mul
return reduce(operator, map(self, operands))

def composition(self, ex, operator):
Expand Down Expand Up @@ -2018,4 +2026,3 @@ def composition(self, ex, operator):
return operator(*map(self, ex.operands()), hold=True)
else:
return operator(*map(self, ex.operands()))

0 comments on commit ff2c44d

Please sign in to comment.