It took me some time, but I finally found some improvement on polynomial
division verb that is both tacit and sigtly faster than explicit version.
step=. [ (] -/@,:&}. (* {:)) ] , %&{.~
pw=. >:@-~&#
divmod=:(pw~ ({. ,&< }.) (step^:pw)&.|.~) f.
pw calculates degree of the quotient and step performes one step of "long
division"
divmod assumes x. and y. to be vectors representing polynomials in the order
of increasing powers (usual J convention) with non-zero highes degree
coefficient. and degree of x. is higher than degree of y. It returns boxed
quotient and remainder polynomial.
Fully unfolded (and with redundant ~ removed) divmod looks like
divmod=:>:@-&# ({. ,&< }.) ([ (] -/@,:&}. (* {:)) ] , %&{.~)^:(>:@-~&#)&.|.~
I would appreciate any optimisations in terms of verb size.
Date: Mon, 24 Oct 2005 08:07:26 +0100 From: "Ewart Shaw"
To: [EMAIL PROTECTED]
...
NB. explicit polynomial division with remainder
pde=: 4 : 0
q=. $0 [ r=. |. x. [ n=. # y=. |. y.
while. n <: #r do.
q=. q, q0=. r %&{. y
r=. }. r - q0*(#r){.y
end.
q ;&|. r
)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm