@@ -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,28 @@ 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 map_basic_basic m = deref(X).get_dict()
2299
+ coef = c2py(< rcp_const_basic> (deref(X).get_coef()))
2300
+ if coef == 1 :
2301
+ d = collections.defaultdict(int )
2302
+ else :
2303
+ d = coef.as_powers_dict()
2304
+
2305
+ it = m.begin()
2306
+ it_end = m.end()
2307
+ while it != it_end:
2308
+ base = c2py(< rcp_const_basic> (deref(it).first))
2309
+ exp = c2py(< rcp_const_basic> (deref(it).second))
2310
+ if base.is_Rational and base.p < base.q and base.p > 0 :
2311
+ d[1 / base] -= exp
2312
+ else :
2313
+ d[base] += exp
2314
+ inc(it)
2315
+
2316
+ return d
2317
+
2279
2318
2280
2319
class Pow (Expr ):
2281
2320
@@ -2319,6 +2358,15 @@ class Pow(Expr):
2319
2358
def func (self ):
2320
2359
return self .__class__
2321
2360
2361
+ def as_powers_dict (Basic self ):
2362
+ d = collections.defaultdict(int )
2363
+ base, exp = self .as_base_exp()
2364
+ if base.is_Rational and base.p < base.q and base.p > 0 :
2365
+ d[1 / base] = - exp
2366
+ else :
2367
+ d[base] = exp
2368
+ return d
2369
+
2322
2370
2323
2371
class Function (Expr ):
2324
2372
0 commit comments