round=: [ * [: <. 0.5 + %~

R.E. Boss


-----Original Message-----
From: Programming <programming-boun...@forums.jsoftware.com> On Behalf Of Raul 
Miller
Sent: maandag 21 februari 2022 17:42
To: Programming forum <programm...@jsoftware.com>
Subject: Re: [Jprogramming] polynomial division

Ok, ... I'm tempted to put that into the rosettacode entry.

What definition are you using for 'round'?

When I try
   round=: [: <. 0.5 + ]

it works up through cyclotomicREB 69 but when I use
   round=: [ * [: <. 0.5 + %~

it only works up through cyclotomicREB 65.

Thanks,


--
Raul

On Mon, Feb 21, 2022 at 11:25 AM R.E. Boss <r.e.b...@outlook.com> wrote:
>
> There was a mistake in taskfmt, but cyclotomic 6 was correct.
> cyclotomicREB=:{{{."1 [0.01 round +. p. 1;^j.+:pi* y%~ >:I.1=y +. 
> >:i.y}}  taskfmt=:{{rplc&'_-' rplc&('^1)';')';'x^0';'1') ' 
> >'-.~}:,|.')+',~"1'(',"1('1'-.~"1 ":,.0-.~y),"1 'x^',"1":,.I.|y}}
>    (cyclotomic"0 -: cyclotomicREB"0) >:i.30
> 1
>
>
> R.E. Boss
>
>
> -----Original Message-----
> From: Programming <programming-boun...@forums.jsoftware.com> On Behalf 
> Of Raul Miller
> Sent: maandag 21 februari 2022 16:54
> To: Programming forum <programm...@jsoftware.com>
> Subject: Re: [Jprogramming] polynomial division
>
> That was the first thing I tried.
>
> cyclotomic 6 should return 1 _1 1
>
> Thanks,
>
> --
> Raul
>
> On Mon, Feb 21, 2022 at 8:55 AM R.E. Boss <r.e.b...@outlook.com> wrote:
> >
> > From the hip.
> >
> > cyclotomic=:{{{."1 [0.01 round +. p. 1;^j.+:pi* y%~ >:I.1=y +. 
> > >:i.y}} taskfmt=:{{rplc&'_-' rplc&('^1';'';'x^0';'1') ' 
> > >'-.~}:,|.')+',~"1'(',"1('1'-.~"1 ":,.0-.~y),"1 'x^',"1":,.I.|y}}
> >       ([: taskfmt cyclotomic)"0 >:i.30
> > (x)+(-1)
> > (x)+(1)
> > (x^2)+(x)+(1)
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5)+(x^4)+(-x^3)+(x^2)+
> > (-
> > x)+(1)
> > (x8)+(x^9)+(1)
> > (x2)+(-x0)+(x^8)+(-x^6)+(x^4)+(-x^2)+(1)
> > (x^28)+(x^27)+(x^26)+(x^25)+(x^24)+(x^23)+(x^22)+(x^21)+(x^20)+(x9)+
> > (x 
> > 8)+(x7)+(x6)+(x5)+(x4)+(x3)+(x2)+(x1)+(x0)+(x^9)+(x^8)+(x^7)+(x^6)+(
> > x^
> > 5)+(x^4)+(x^3)+(x^2)+(x)+(1)
> > (x^8)+(x^7)+(-x^5)+(-x^4)+(-x^3)+(x)+(1)
> >
> >
> > R.E. Boss
> >
> > -----Original Message-----
> > From: Programming <programming-boun...@forums.jsoftware.com> On 
> > Behalf Of Raul Miller
> > Sent: zondag 20 februari 2022 17:35
> > To: Programming forum <programm...@jsoftware.com>
> > Subject: Re: [Jprogramming] polynomial division
> >
> > 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,
> >
> > --
> > Raul
> >
> > On Sun, Feb 20, 2022 at 11:27 AM 'Michael Day' via Programming 
> > <programm...@jsoftware.com> wrote:
> > >
> > > I wrote binc as a monad,  just as a quick way of conjuring up sets 
> > > of binomial coefficients:
> > >
> > >     binc 5
> > > 1 5 10 10 5 1
> > >
> > >     3 binc 5 NB. does work, but not as intended!
> > > 1 3 3 1 0 0
> > > NB. as does its commute:
> > >     5 binc 3
> > > 1 5 10 10
> > > ... but again, not as I intended.
> > >
> > > div is what does the division;  div&binc a,b just does (binc a) 
> > > div binc b
> > >
> > >
> > > I wasn't particularly interested in the performance of binc, as 
> > > Raul was seeking a division algortithm,  and binc was just easier 
> > > than typing 1 5 10 10 5 1 or whatever.
> > >
> > > I do agree that your definition improves on mine when it matters,  eg
> > >     ts'binc 500x'
> > > 0.0392271 460640
> > >     ts'1, */\ 500x (- % >:@]) i.500x' NB. x=y for my examples
> > > 0.001463 504032
> > >
> > > I suppose it's now worth investigating the performance of div cf 
> > > dbho and divlo cf dblo excluding the overhead of binc:
> > >
> > >     'a b' =: binc 50 20
> > >     a (dbho-:div) b
> > > 1
> > >     ts'a div b'
> > > 1.21e_5 5952
> > >     ts'a dbho b'
> > > 2.63e_5 6496
> > >     a (dblo-:divlo) b
> > > 1
> > >     ts'a divlo b'
> > > 1.06e_5 6976
> > >     ts'a dblo b'
> > > 1.75e_5 6496
> > >
> > > Thanks for pointing out the overheads imposed by binc,
> > >
> > > Mike
> > >
> > > On 20/02/2022 16:01, Hauke Rehr wrote:
> > > > On my machine, I get
> > > >
> > > >    100 timespacex '1000x binc 500x'
> > > > 0.101916 957376
> > > >    100 timespacex '1, */\ 1000x (- % >:@]) i.500x'
> > > > 0.00247977 680320
> > > >
> > > >
> > > > Am 20.02.22 um 13:30 schrieb 'Michael Day' via Programming:
> > > >>     ts'1000x div&binc 500x'
> > > >> 2.1598005 4815264
> > > >
> > >
> > >
> > > --
> > > 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
> > --------------------------------------------------------------------
> > -- For information about J forums see 
> > http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to