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

Commit 5b93a06

Browse files
committed
20179: interface to Pynac's ex::free_symbols()
1 parent 7d3fd60 commit 5b93a06

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/sage/libs/pynac/pynac.pxd

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,15 @@ cdef extern from "sage/libs/pynac/wrap.h":
8686
GExListIter end()
8787
GExList append_sym "append" (GSymbol e)
8888

89+
cdef cppclass GSymbolSetIter "GiNaC::symbolset::const_iterator":
90+
void inc "operator++" ()
91+
GEx obj "operator*" ()
92+
bint operator!=(GSymbolSetIter i)
93+
94+
cdef cppclass GSymbolSet "GiNaC::symbolset":
95+
GSymbolSetIter begin()
96+
GSymbolSetIter end()
97+
8998
cdef cppclass GEx "ex":
9099
GEx()
91100
GEx(GSymbol m)
@@ -105,6 +114,7 @@ cdef extern from "sage/libs/pynac/wrap.h":
105114
bint is_polynomial(GEx vars) except +
106115
bint match(GEx pattern, GExList s) except +
107116
bint find(GEx pattern, GExList s) except +
117+
GSymbolSet free_symbols() except +
108118
bint has(GEx pattern) except +
109119
GEx subs(GEx expr) except +
110120
GEx subs_map "subs" (GExMap map, unsigned options) except +

src/sage/symbolic/expression.pyx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5104,6 +5104,40 @@ cdef class Expression(CommutativeRingElement):
51045104
res = print_sorted(res)[::-1]
51055105
return tuple(res)
51065106

5107+
def free_variables(self):
5108+
"""
5109+
Return sorted tuple of unbound variables that occur in this
5110+
expression.
5111+
5112+
EXAMPLES::
5113+
5114+
sage: (x,y,z) = var('x,y,z')
5115+
sage: (x+y).free_variables()
5116+
(x, y)
5117+
sage: (2*x).free_variables()
5118+
(x,)
5119+
sage: (x^y).free_variables()
5120+
(x, y)
5121+
sage: sin(x+y^z).free_variables()
5122+
(x, y, z)
5123+
sage: _ = function('f')
5124+
sage: e = limit( f(x,y), x=0 ); e
5125+
limit(f(x, y), x, 0)
5126+
sage: e.free_variables()
5127+
(y,)
5128+
"""
5129+
from sage.symbolic.ring import SR
5130+
from sage.symbolic.comparison import print_sorted
5131+
cdef GSymbolSet sym_set
5132+
sym_set = self._gobj.free_symbols()
5133+
res = []
5134+
cdef GSymbolSetIter itr = sym_set.begin()
5135+
while itr != sym_set.end():
5136+
res.append(new_Expression_from_GEx(SR, GEx(itr.obj())))
5137+
itr.inc()
5138+
res = print_sorted(res)[::-1]
5139+
return tuple(res)
5140+
51075141
def arguments(self):
51085142
"""
51095143
EXAMPLES::

0 commit comments

Comments
 (0)