Good point.

Ok, here's an almost fixed version:

polysN=: 3 :0
  maybe=. monicN y
  keep=. +./"1(9!:18'')>|maybe p."1 rats 2*y
  keep#maybe
)

monicN=: (<1) >@,@{@,~ (<_1 0 1) #~ ]

rats=: 3 : ' ~.r.1p1*,%/~0-.~i:y'

   #@polysN"0 i. 8
0 2 6 12 36 94 276 790

I'm not completely convinced that that is correct, but I think I'm in the
right ballpark.

Thanks,

-- 
Raul



On Mon, Jun 2, 2014 at 6:37 PM, Devon McCormick <[email protected]> wrote:

> You can generate roots of unity with this: ([: r. 2 * (o.@:%~ i.))  .
> EG
> ​​   ([: r. 2 * (o.@:%~ i.)) 3
> ​1 _0.5j0.866025 _0.5j_0.866025​
>
>
> On Mon, Jun 2, 2014 at 6:33 PM, Raul Miller <[email protected]> wrote:
>
> > Proof that I am wrong. (And, that - if it's understandable that the
> > information on the wolfram page leads to my implementation of rootsN that
> > it is significantly incomplete.):
> >
> >    p. 1 1 1
> > ┌─┬────────────────────────────┐
> > │1│_0.5j0.866025 _0.5j_0.866025│
> > └─┴────────────────────────────┘
> >    |1{::p. 1 1 1
> > 1 1
> >
> > Like I said... I'm really good at being wrong. Or, something like that.
> >
> > Thanks,
> >
> > --
> > Raul
> >
> >
> > On Mon, Jun 2, 2014 at 5:55 PM, R.E. Boss <[email protected]> wrote:
> >
> > > http://mathworld.wolfram.com/RootofUnity.html  seem to indicate you
> are
> > > right.
> > >
> > > R.E. Boss
> > >
> > > > Date: Mon, 2 Jun 2014 13:59:10 -0600
> > > > From: [email protected]
> > > > To: [email protected]
> > > > Subject: Re: [Jprogramming] Identifying roots of unity
> > > >
> > > > Is n below a primitive root of unity?
> > > >
> > > >    n=._1^3r8
> > > >
> > > > *./2 x:(12 o. n)%o.2
> > > >
> > > > 48
> > > >
> > > > n^48
> > > >
> > > > 1j_3.9968e_15
> > > >
> > > >
> > > > Yes.
> > > >
> > > >
> > > > On Mon, Jun 2, 2014 at 1:42 PM, Don Guinn <[email protected]>
> wrote:
> > > >
> > > > > I don't think that this is a complete test. If 1~:|n then it it is
> > not
> > > a
> > > > > primitive root of unity. But n must be a complex number when raised
> > to
> > > an
> > > > > *integer* power is 1. Maybe converting the complex number to polar
> > then
> > > > > checking the angle and seeing if it is a rational fraction of a
> > circle.
> > > > >
> > > > > Obviously computers will always find some rational number though it
> > > might
> > > > > require raising n to a very large power. There should be some
> > > reasonable
> > > > > limit as to how large the power may be.
> > > > >
> > > > >
> > > > > On Mon, Jun 2, 2014 at 1:08 PM, Raul Miller <[email protected]
> >
> > > wrote:
> > > > >
> > > > >>    1=|n
> > > > >>
> > > > >> Thanks,
> > > > >>
> > > > >> --
> > > > >> Raul
> > > > >>
> > > > >>
> > > > >> On Mon, Jun 2, 2014 at 2:54 PM, Dan Bron <[email protected]> wrote:
> > > > >> > Given a complex number, how can I determine whether it is a
> > > primitive
> > > > >> root
> > > > >> > of unity?
> > > > >> >
> > > > >> > (This is a subtask of a code golf problem, so the shorter the
> > > better)
> > > > >> >
> > > > >> > -Dan
> > > > >> >
> > > ----------------------------------------------------------------------
> > > > >> > 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
> >
>
>
>
> --
> Devon McCormick, CFA
> ----------------------------------------------------------------------
> 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