Oh, bleah... of course.
y does not change. So that should be a test on {.x -- and that reveals
that I was using the wrong values throughout that section of code.
Here's a fixed version:
pDiv=: {{
q=. $j=. 2 + x -&# y
'x y'=. x,:y
while. j=. j-1 do.
if. 0={.x do. j=. j-<:i=. 0 i.~ 0=x
q=. q,i#0
x=. i |.!.0 x
else.
q=. q, r=. x %&{. y
x=. 1 |.!.0 x - y*r
end.
end.q
}}
Thanks,
--
Raul
On Sun, Feb 20, 2022 at 1:05 PM 'Michael Day' via Programming
<[email protected]> wrote:
>
> 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
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm