@@ -1169,6 +1169,11 @@ cdef class Basic(object):
1169
1169
raise TypeError (" Can't convert expression to float" )
1170
1170
return complex (f)
1171
1171
1172
+ def as_powers_dict (self ):
1173
+ d = collections.defaultdict(int )
1174
+ d[self ] = 1
1175
+ return d
1176
+
1172
1177
1173
1178
def series (ex , x = None , x0 = 0 , n = 6 , as_deg_coef_pair = False ):
1174
1179
# TODO: check for x0 an infinity, see sympy/core/expr.py
@@ -1345,6 +1350,11 @@ cdef class ImaginaryUnit(Complex):
1345
1350
def __cinit__ (Basic self ):
1346
1351
self .thisptr = symengine.I
1347
1352
1353
+ def as_powers_dict (self ):
1354
+ d = collections.defaultdict(int )
1355
+ d[minus_one] = half
1356
+ return d
1357
+
1348
1358
I = ImaginaryUnit()
1349
1359
1350
1360
@@ -2078,6 +2088,13 @@ cdef class NegativeInfinity(Number):
2078
2088
import sage.all as sage
2079
2089
return - sage.oo
2080
2090
2091
+ def as_powers_dict (self ):
2092
+ d = collections.defaultdict(int )
2093
+ d[minus_one] = 1
2094
+ d[oo] = 1
2095
+ return d
2096
+
2097
+
2081
2098
minus_oo = NegativeInfinity()
2082
2099
2083
2100
@@ -2276,6 +2293,21 @@ class Mul(AssocOp):
2276
2293
c2py(< rcp_const_basic> deref(X).get_coef())
2277
2294
return d
2278
2295
2296
+ def as_powers_dict (Basic self ):
2297
+ cdef RCP[const symengine.Mul] X = symengine.rcp_static_cast_Mul(self .thisptr)
2298
+ cdef rcp_const_basic coef = < rcp_const_basic> (deref(X).get_coef())
2299
+ cdef map_basic_basic m = deref(X).get_dict()
2300
+ d = c2py(coef).as_powers_dict()
2301
+
2302
+ it = m.begin()
2303
+ it_end = m.end()
2304
+ while it != it_end:
2305
+ d[c2py(< rcp_const_basic> (deref(it).first))] = \
2306
+ c2py(< rcp_const_basic> (deref(it).second))
2307
+ inc(it)
2308
+
2309
+ return d
2310
+
2279
2311
2280
2312
class Pow (Expr ):
2281
2313
@@ -2319,6 +2351,11 @@ class Pow(Expr):
2319
2351
def func (self ):
2320
2352
return self .__class__
2321
2353
2354
+ def as_powers_dict (self ):
2355
+ d = collections.defaultdict(int )
2356
+ d[self .base] = self .exp
2357
+ return d
2358
+
2322
2359
2323
2360
class Function (Expr ):
2324
2361
0 commit comments