Status: Accepted
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 2834 by [email protected]: naive radical removal can lead to multiplying by 0/0
http://code.google.com/p/sympy/issues/detail?id=2834

There is an unguided attempt at removing of a radical from the denominator that leads to an interesting 0/0 situation. A match for a+b*sqrt(c) is made and the sqrt(c) is cleared by multiplying by a - b*sqrt(c). This usually works but not if a = b*sqrt(c) because then you multiply numer and denom by 0 and that leads to weird results. Here is a case where it arose:

p1=Polygon(*RegularPolygon((0,0),1,5).vertices)
x=p1.centroid.x # modified so the point coordinates are not simplified
[w.n() for w in x.as_numer_denom()]
[.0e-128, 3921366368769.96]
[w.n() for w in simplify(x).as_numer_denom()]
[.0e-131, -.0e-120]
# oops! the denominator shouldn't be zero after simplifying
...
n,d=x.as_numer_denom()
a, b, c = map(Wild, 'abc')
r = d.match(a + b*sqrt(c))
a, b, c = r[a], r[b], r[c]
(d-(a+b*sqrt(c))).n() # the match is correct
0
conj_like = a-b*sqrt(c)
(d*conj_like - (a**2-c*b**2)).n() # is the new denom a**2 - c*b**2?
.0e-108
# yep, it is BUT...it is zero!
...
conj_like.n() # this is what the numer and denom were mutliplied by
.0e-123

# and that's the oops. Let's see what a, b and c were
...
a
103079215104*sqrt(10)*sqrt(sqrt(5) + 5) + 206158430208*sqrt(10)*sqrt(-sqrt(5) +
5)
b
515396075520*sqrt(2)
c
sqrt(5) + 5
pprint(d.as_content_primitive()[1])
          ___________               _____________              ___________
  ____   /   ___            ____   /     ___            ___   /   ___
\/ 10 *\/  \/ 5  + 5  + 2*\/ 10 *\/  - \/ 5  + 5  + 5*\/ 2 *\/  \/ 5  + 5
d.args
(206158430208*sqrt(10)*sqrt(-sqrt(5) + 5), 103079215104*sqrt(10)*sqrt(sqrt(5) +
5), 515396075520*sqrt(2)*sqrt(sqrt(5) + 5))
A,B,C=(d.as_content_primitive()[1]).args
A
2*sqrt(10)*sqrt(-sqrt(5) + 5)
B
sqrt(10)*sqrt(sqrt(5) + 5)
C
5*sqrt(2)*sqrt(sqrt(5) + 5)
a=A+B;b=5*sqrt(2);c=sqrt(sqrt(5) + 5);(a**2-c*b**2).n()
227.303696482198

So there is a way to remove a radical without multiplying by 0/0...this part of simplify needs to be smarter so this doesn't happen.


--
You received this message because you are subscribed to the Google Groups 
"sympy-issues" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy-issues?hl=en.

Reply via email to