#6229: efficiency in Lagrange polynomial interpolation (easy fix...)
----------------------+-----------------------------------------------------
 Reporter:  ylchapuy  |       Owner:  tbd       
     Type:  defect    |      Status:  new       
 Priority:  minor     |   Milestone:  sage-4.0.1
Component:  algebra   |    Keywords:            
----------------------+-----------------------------------------------------
Description changed by ylchapuy:

Old description:

> This is a follow-up to #6043.
>
> This nested loop is useless:
> {{
>         P = 0
>         for i in xrange(n):
>             prod = 1
>             for j in xrange(i):
>                 prod *= (x - points[j][0])
>             P += (F[i] * prod)
>         return P
>
> }}
>
> and should be replaced with (something like)
>
> {{
>         P = F[n-1]
>         for i in xrange(n-2,-1,-1):
>             P *= (x - points[i][0])
>             P += F[i]
>         return P
> }}

New description:

 This is a follow-up to #6043.

 This nested loop is useless:
 {{{
         P = 0
         for i in xrange(n):
             prod = 1
             for j in xrange(i):
                 prod *= (x - points[j][0])
             P += (F[i] * prod)
         return P

 }}}

 and should be replaced with (something like)

 {{{
         P = F[n-1]
         for i in xrange(n-2,-1,-1):
             P *= (x - points[i][0])
             P += F[i]
         return P
 }}}

--

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/6229#comment:1>
Sage <http://sagemath.org/>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" 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/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to