File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -2295,15 +2295,22 @@ class Mul(AssocOp):
2295
2295
2296
2296
def as_powers_dict (Basic self ):
2297
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
2298
cdef map_basic_basic m = deref(X).get_dict()
2300
- d = c2py(coef).as_powers_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()
2301
2304
2302
2305
it = m.begin()
2303
2306
it_end = m.end()
2304
2307
while it != it_end:
2305
- d[c2py(< rcp_const_basic> (deref(it).first))] = \
2306
- c2py(< rcp_const_basic> (deref(it).second))
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
2307
2314
inc(it)
2308
2315
2309
2316
return d
@@ -2351,9 +2358,13 @@ class Pow(Expr):
2351
2358
def func (self ):
2352
2359
return self .__class__
2353
2360
2354
- def as_powers_dict (self ):
2361
+ def as_powers_dict (Basic self ):
2355
2362
d = collections.defaultdict(int )
2356
- d[self .base] = self .exp
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
2357
2368
return d
2358
2369
2359
2370
You can’t perform that action at this time.
0 commit comments