This repository has been archived by the owner on Jan 30, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'public/22802_sympy_abstract_function' of git://trac.sag…
…emath.org/sage into public/22802_sympy_abstract_function
- Loading branch information
Showing
5 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.0.p2 | ||
1.0.p3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters