On Nov 3, 2008, at 7:39 PM, Jason Grout wrote:

> Bill Hart wrote:
>> sage: R.<x>=RDF['t']
>> sage: s=1.0e1*t^3+1.0e-100*t^2+1.01234e-100*t+1.0e1
>> sage: u=1.0e1*t^3-1.0e1*t^2+1.0e1*t-1.0e1
>> sage: s*u
>> 100.0*t^6 - 100.0*t^5 + 100.0*t^4 - 100.0*t^2 + 100.0*t - 100.0
>>
>> What happened to the t^3 term?
>
>
> Isn't it zero in RDF?
>
> sage: a0=RDF(1.0e1)
> sage: a1=RDF(1.01234e-100)
> sage: a2=RDF(1.0e-100)
> sage: a3=RDF(1.0e1)
> sage: b0=RDF(-1.0e1)
> sage: b1=RDF(1.0e1)
> sage: b2=RDF(-1.0e1)
> sage: b3=RDF(1.0e1)
> sage: # the coefficient of t^3
> sage: a0*b3 + a1*b2 + a2*b1 + a3*b0
> 0.0
>
> Note that a0*b3+a3*b0 is zero (both are 100 in magnitude).  However,
>
> sage: a2*b1 - a1*b2
> 2.01234e-99
> sage: a2*b1 - a1*b2 +1 -1
> 0.0
>
> My guess is that adding 100 and subtracting 100 wipes out the  
> precision
> and makes the resulting expression close enough to zero that it is
> considered zero.
>
> Are you sure that RDF provides enough precision to carry out your
> computation?

That's almost certainly what's happening. If you do

sage: sage: (s.change_ring(RealField(400)) * u.change_ring(RealField 
(400)))[3]
-1.233999999999992707276099007932117842977737442427998522647464651126978 
20628822244138099718572056030722800920267941116652e-101

then it gets the correct answer. Even worse is

sage: (t+1e100)^2
1.0*t^2 + 1e+200

because the wrong algorithm is being used. See http:// 
trac.sagemath.org/sage_trac/ticket/4055

- Robert


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to