Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Merge branch 'public/23496_patch_sympy_abstact_function' of git://tra…
Browse files Browse the repository at this point in the history
…c.sagemath.org/sage into public/23496_patch_sympy_abstact_function
  • Loading branch information
Travis Scrimshaw committed Jul 31, 2017
2 parents 38f662f + e46345b commit 46ebd72
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/pkgs/sympy/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.p2
1.0.p3
59 changes: 59 additions & 0 deletions build/pkgs/sympy/patches/02_undeffun_sage.patch
Original file line number Diff line number Diff line change
@@ -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::

0 comments on commit 46ebd72

Please sign in to comment.