This repository was archived by the owner on Jan 30, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -4872,6 +4872,8 @@ cdef class Expression(CommutativeRingElement):
4872
4872
43/42
4873
4873
sage: ((1+x)/x).subs({x: 42})
4874
4874
43/42
4875
+ sage: (x+1/x+1).subs(1/x==pi)
4876
+ pi + x + 1
4875
4877
"""
4876
4878
from sage.symbolic.ring import SR
4877
4879
cdef dict sdict = {}
@@ -4892,11 +4894,17 @@ cdef class Expression(CommutativeRingElement):
4892
4894
# Check for duplicate
4893
4895
_dict_update_check_duplicate(sdict, varkwds)
4894
4896
4897
+ def is_fraction (e ):
4898
+ return ((e.operator() == operator.pow and e.operands()[1 ]< 0 ) or
4899
+ (e.operator() == operator.mul and
4900
+ any (t.operator()== operator.pow and t.operands()[1 ]< 0
4901
+ for t in e.operands())))
4902
+
4895
4903
cdef GExMap smap, invmap
4896
4904
for k, v in sdict.iteritems():
4897
4905
smap.insert(make_pair((< Expression> self .coerce_in(k))._gobj,
4898
4906
(< Expression> self .coerce_in(v))._gobj))
4899
- if not SR(v).is_trivial_zero():
4907
+ if not SR(v).is_trivial_zero() and not is_fraction(SR(k)) :
4900
4908
invmap.insert(make_pair((< Expression> self .coerce_in(1 / k))._gobj,
4901
4909
(< Expression> self .coerce_in(1 / v))._gobj))
4902
4910
You can’t perform that action at this time.
0 commit comments