Polynomial long division: Difference between revisions
Content added Content deleted
(→{{header|Tcl}}: ++ smalltalk) |
(added Ursala) |
||
Line 815: | Line 815: | ||
puts [list Q = $Q] |
puts [list Q = $Q] |
||
puts [list R = $R]</lang> |
puts [list R = $R]</lang> |
||
=={{header|Ursala}}== |
|||
The input is a pair of lists of coefficients in order of increasing degree. |
|||
Trailing zeros can be omitted. The output is a pair of lists (q,r), the quotient |
|||
and remainder polynomial coefficients. This is a straightforward implementation |
|||
of the algorithm in terms of list operations (fold, zip, map, distribute, etc.) instead |
|||
of array indexing, hence not unnecessarily verbose. |
|||
<lang>#import std |
|||
#import flo |
|||
polydiv = |
|||
zeroid~-l~~; leql?rlX\~&NlX ^H\(@rNrNSPXlHDlS |\ :/0.) @NlX //=> ?( |
|||
@lrrPX ==!| zipp0.; @x not zeroid+ ==@h->hr ~&t, |
|||
(^lryPX/~&lrrl2C minus^*p/~&rrr times*lrlPD)^/div@bzPrrPlXO ~&, |
|||
@r ^|\~& ~&i&& :/0.)</lang> |
|||
test program: |
|||
<lang Ursala>#cast %eLW |
|||
example = polydiv(<-42.,0.,-12.,1.>,<-3.,1.,0.,0.>)</lang> |
|||
output: |
|||
<pre>( |
|||
<-2.700000e+01,-9.000000e+00,1.000000e+00>, |
|||
<-1.230000e+02>)</pre> |