diff --git a/build/pkgs/sympy/package-version.txt b/build/pkgs/sympy/package-version.txt index b085a1b8072..12eee38caea 100644 --- a/build/pkgs/sympy/package-version.txt +++ b/build/pkgs/sympy/package-version.txt @@ -1 +1 @@ -1.0.p2 +1.0.p3 diff --git a/build/pkgs/sympy/patches/02_undeffun_sage.patch b/build/pkgs/sympy/patches/02_undeffun_sage.patch new file mode 100644 index 00000000000..ddce2654b52 --- /dev/null +++ b/build/pkgs/sympy/patches/02_undeffun_sage.patch @@ -0,0 +1,59 @@ +diff --git a/sympy/core/function.py b/sympy/core/function.py +index 4c4ce9c..63c52da 100644 +--- a/sympy/core/function.py ++++ b/sympy/core/function.py +@@ -746,8 +746,21 @@ def _eval_as_leading_term(self, x): + def _sage_(self): + import sage.all as sage + fname = self.func.__name__ +- func = getattr(sage, fname) ++ func = getattr(sage, fname,None) + args = [arg._sage_() for arg in self.args] ++ ++ # In the case the function is not known in sage: ++ if func is None: ++ import sympy ++ if getattr(sympy, fname,None) is None: ++ # abstract function ++ return sage.function(fname)(*args) ++ ++ else: ++ # the function defined in sympy is not known in sage ++ # this exception is catched in sage ++ raise AttributeError ++ + return func(*args) + + +diff --git a/sympy/external/tests/test_sage.py b/sympy/external/tests/test_sage.py +index bc404b6..ed41d42 100644 +--- a/sympy/external/tests/test_sage.py ++++ b/sympy/external/tests/test_sage.py +@@ -222,6 +222,19 @@ def test_undefined_function(): + assert bool(sf(sx) == f(x)._sage_()) + #assert bool(f == sympy.sympify(sf)) + ++def test_abstract_function(): ++ from sage.symbolic.expression import Expression ++ x,y = sympy.symbols('x y') ++ f = sympy.Function('f') ++ expr = f(x,y) ++ sexpr = expr._sage_() ++ assert isinstance(sexpr,Expression), "converted expression %r is not sage expression" % sexpr ++ # This test has to be uncommented in the future: it depends on the sage ticket #22802 (https://trac.sagemath.org/ticket/22802) ++ # invexpr = sexpr._sympy_() ++ # assert invexpr == expr, "inverse coversion %r is not correct " % invexpr ++ ++ ++ + # This string contains Sage doctests, that execute all the functions above. + # When you add a new function, please add it here as well. + """ +@@ -244,6 +257,7 @@ def test_undefined_function(): + sage: test_issue_4023() + sage: test_integral() + sage: test_undefined_function() ++ sage test_abstract_function() + + Sage has no symbolic Lucas function at the moment:: + diff --git a/src/sage/symbolic/expression_conversions.py b/src/sage/symbolic/expression_conversions.py index 6220d85c841..af8ab4a8d74 100644 --- a/src/sage/symbolic/expression_conversions.py +++ b/src/sage/symbolic/expression_conversions.py @@ -603,7 +603,7 @@ 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() @@ -611,7 +611,7 @@ def derivative(self, ex, operator): outstr = "diff(%s, %s)"%(f._maxima_init_(), ", ".join(params)) return outstr - + def arithmetic(self, ex, operator): """ EXAMPLES:: @@ -674,7 +674,7 @@ class SympyConverter(Converter): sage: sympy.sympify(x) # indirect doctest x - TESTS: + TESTS:: Make sure we can convert I (:trac:`6424`):: @@ -764,7 +764,61 @@ def composition(self, ex, operator): if f_sympy: return f_sympy(*sympy.sympify(g, evaluate=False)) else: - raise NotImplementedError("SymPy function '%s' doesn't exist" % f) + from sage.symbolic.function_factory import SymbolicFunction + if isinstance(ex.operator(), SymbolicFunction): + return sympy.Function(str(f))(*g, evaluate=False) + + + def derivative(self, ex, operator): + """ + Convert the derivative in sympy + INPUT: + + - ``ex`` -- a symbolic expression + + - ``operator`` -- operator + + TESTS:: + sage: import sympy + + sage: var('x','y') + (x, y) + + sage: f_sage = function('f_sage')(x,y) + sage: f_sympy = f_sage._sympy_() + + sage: df_sage = f_sage.diff(x,2,y,1); df_sage + diff(f_sage(x, y), x, x, y) + sage: df_sympy = df_sage._sympy_(); df_sympy + Derivative(f_sage(x, y), x, x, y) + sage: df_sympy == f_sympy.diff(x,2,y,1) + True + + + """ + import sympy + + # retrive derivated function + f = operator.function() + f_sympy = self.composition(ex,f) + + + + # retrive order + order = operator._parameter_set + # arguments + _args = ex.arguments() + + sympy_arg = [] + for aa in range(len(_args)): + gg = order.count(aa) + if gg > 0 : + sympy_arg.append(_args[aa]) + sympy_arg.append(gg) + + return f_sympy.diff(*sympy_arg) + + sympy = SympyConverter() @@ -1769,7 +1823,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): @@ -2026,4 +2080,3 @@ def composition(self, ex, operator): return operator(*map(self, ex.operands()), hold=True) else: return operator(*map(self, ex.operands())) - diff --git a/src/sage/symbolic/function.pyx b/src/sage/symbolic/function.pyx index 9ceca3576cb..b885ea4cd98 100644 --- a/src/sage/symbolic/function.pyx +++ b/src/sage/symbolic/function.pyx @@ -619,9 +619,7 @@ cdef class Function(SageObject): sage: g._sympy_init_() 'gg' sage: g(x)._sympy_() - Traceback (most recent call last): - ... - NotImplementedError: SymPy function 'gg' doesn't exist + gg(x) """ return self._conversions.get('sympy', self._name) diff --git a/src/sage/tests/french_book/recequadiff.py b/src/sage/tests/french_book/recequadiff.py index 65ee8d16d9d..bb1f925c6dd 100644 --- a/src/sage/tests/french_book/recequadiff.py +++ b/src/sage/tests/french_book/recequadiff.py @@ -378,9 +378,10 @@ sage: from sympy import Function, Symbol sage: u = Function('u'); n = Symbol('n', integer=True) -Sage example in ./recequadiff.tex, line 1208:: +Sage example in ./recequadiff.tex, line 1208 (WARNING: the order of factors is +inverted, see :trac:`23496` ):: - sage: f = u(n+2)-(3/2)*u(n+1)+(1/2)*u(n) + sage: f = u(n+2)-u(n+1)*(3/2)+u(n)*(1/2) Sage example in ./recequadiff.tex, line 1214:: @@ -396,4 +397,3 @@ 2**n*C0 + 2**(n + 2)*(C0 + n/2) """ -