File tree Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Expand file tree Collapse file tree 2 files changed +27
-12
lines changed Original file line number Diff line number Diff line change @@ -585,12 +585,15 @@ cdef class Basic(object):
585
585
return ring(self ._sage_())
586
586
587
587
def atoms (self , *types ):
588
- s = set ()
589
- if (isinstance (self , types)):
590
- s.add(self )
591
- for arg in self .args:
592
- s.update(arg.atoms(* types))
593
- return s
588
+ if types:
589
+ s = set ()
590
+ if (isinstance (self , types)):
591
+ s.add(self )
592
+ for arg in self .args:
593
+ s.update(arg.atoms(* types))
594
+ return s
595
+ else :
596
+ return self .free_symbols
594
597
595
598
def simplify (self , *args , **kwargs ):
596
599
return sympify(self ._sympy_().simplify(* args, ** kwargs))
@@ -1969,12 +1972,15 @@ cdef class DenseMatrix(MatrixBase):
1969
1972
return self [:]
1970
1973
1971
1974
def atoms (self , *types ):
1972
- s = set ()
1973
- if (isinstance (self , types)):
1974
- s.add(self )
1975
- for arg in self .tolist():
1976
- s.update(arg.atoms(* types))
1977
- return s
1975
+ if types:
1976
+ s = set ()
1977
+ if (isinstance (self , types)):
1978
+ s.add(self )
1979
+ for arg in self .tolist():
1980
+ s.update(arg.atoms(* types))
1981
+ return s
1982
+ else :
1983
+ return self .free_symbols
1978
1984
1979
1985
def simplify (self , *args , **kwargs ):
1980
1986
return self ._applyfunc(lambda x : x.simplify(* args, ** kwargs))
Original file line number Diff line number Diff line change @@ -119,6 +119,15 @@ def test_args():
119
119
assert (2 * x ** 2 ).args == (2 , x ** 2 )
120
120
assert set ((2 * x ** 2 * y ).args ) == set ((Integer (2 ), x ** 2 , y ))
121
121
122
+ def test_atoms ():
123
+ x = Symbol ("x" )
124
+ y = Symbol ("y" )
125
+ z = Symbol ("z" )
126
+ assert (x ** 2 ).atoms () == set ([x ])
127
+ assert (x ** 2 ).atoms (Symbol ) == set ([x ])
128
+ assert (x ** y + z ).atoms () == set ([x , y , z ])
129
+ assert (x ** y + z ).atoms (Symbol ) == set ([x , y , z ])
130
+
122
131
def test_free_symbols ():
123
132
x = Symbol ("x" )
124
133
y = Symbol ("y" )
You can’t perform that action at this time.
0 commit comments