[Jprogramming] polynomial division

'Michael Day' via Programming programming at jsoftware.com
Sun Feb 20 18:05:24 UTC 2022


I suppose dyad |. !0 is better than dyad }.  by keeping the result in 
place.

Anyway,   although I agree that it seems attractive to ignore those zeros,
your get-around doesn't seem to apply!!! - unless I'm missing something.

I embedded an echo:
...
     if. 0={.y do. j=. j-i=. 0 i.~ 0=y
echo '0={.y';x;y
...

I encountered an error in this mickey mouse test:
    1 0 0 0 0 0 0 0 0 1 pDiv 0 0 0 1 0 1
┌─────┬───────────────────┬───────────────────┐
│0={.y│1 0 0 0 0 0 0 0 0 1│0 0 0 1 0 1 0 0 0 0│
└─────┴───────────────────┴───────────────────┘
┌─────┬───────────────────┬───────────────────┐
│0={.y│0 0 0 0 0 0 0 1 0 0│0 0 0 1 0 1 0 0 0 0│
└─────┴───────────────────┴───────────────────┘
|domain error: pDiv
|   q=.q,j    #0
but maybe these arguments aren't like those for pDiv in the Rosetta Code 
task.

This trick for my div is analogous to allowing for leading decimal zeros
in 1234 % 0.0001 in "ordinary" long division.  I wonder if it's what you
intended.

NB. x % y
div =: 3 : 0    NB. similar result to Ken's dbho
:
q =. ''
NB. allow for leading zeros in quotient
if. 0 = {. y do.
    j =. 0 i.~ 0 = y
    y =. j }. y
    x =. x, 0#~ >: j
end.
yx=. y,:x
assert. 2 <: n =. 2 + x -&# y
while. n =. <: n do.
    q  =. q, r =. %~/ {."1 yx
    yx =. y,: }. -~/ yx * r,1
end.
q
)

    1 2 3 4 div 0 0 0 1
1 2 3 4 0 0 0 0
1234 % 0.0001
12340000

Anyway, my extra echo reports nothing when running this:
     cyclotomic >: i.1000
so I suspect that the check is not necessary here.

Mike

On 20/02/2022 16:35, Raul Miller wrote:
> For what it's worth, here's what I was focusing on:
>
> http://rosettacode.org/wiki/Cyclotomic_polynomial#J
>
> As you can see, I altered your polynomial division algorithm --
> there's enough zeros in the polynomials I was working with, there,
> that iterating through them seemed unwise.
>
> If there's any other significant improvements that you notice -- or
> any errors which I overlooked, of course, please let me know!
>
> Thanks,
>


-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the Programming mailing list