Jsoftware
High-Performance Development Platform

totient

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown totient

by Andrew Nikitin :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I came up with cute expression for totient, which in addition to being cute, also seems faster than 5&p. (in j601)

Here it is:

   tot=:(- ~:)&.q:

   (5&p: -: tot) 2+i.100000x
1


   6!:2 '5 p: 2+i.100000x'
2.51881
   6!:2 '(- ~:)&.q: 2+i.100000x'
0.676987
   6!:2 '5 p: 2+i.100000'
0.409061
   6!:2 '(- ~:)&.q: 2+i.100000'
0.195733

     
_________________________________________________________________
Hotmail: Trusted email with Microsoft's powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/
http://clk.atdmt.com/GBL/go/177141664/direct/01/
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: totient

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Neat.  Thanks for the note.



----- Original Message -----
From: Andrew Nikitin <nsg21@...>
Date: Tuesday, November 3, 2009 13:02
Subject: [Jprogramming] totient
To: J programming <programming@...>

>
> I came up with cute expression for totient, which in addition to
> being cute, also seems faster than 5&p. (in j601)
>
> Here it is:
>
>    tot=:(- ~:)&.q:
>
>    (5&p: -: tot) 2+i.100000x
> 1
>
>
>    6!:2 '5 p: 2+i.100000x'
> 2.51881
>    6!:2 '(- ~:)&.q: 2+i.100000x'
> 0.676987
>    6!:2 '5 p: 2+i.100000'
> 0.409061
>    6!:2 '(- ~:)&.q: 2+i.100000'
> 0.195733
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Re: totient

by Roger Hui :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

By the way, using Andrew Nikitin's idea, together with removing
an unnecessary use of rank in the implementation,

   timer=: 6!:2
   y=: 2x+i.1e5

   timer '5 p: y'  NB. J7.01
0.796005

   timer '5 p: y'  NB. J6.02
2.7178



----- Original Message -----
From: Roger Hui <rhui000@...>
Date: Wednesday, November 4, 2009 2:02
Subject: Re: [Jprogramming] totient
To: Programming forum <programming@...>

> Neat.  Thanks for the note.
>
>
>
> ----- Original Message -----
> From: Andrew Nikitin <nsg21@...>
> Date: Tuesday, November 3, 2009 13:02
> Subject: [Jprogramming] totient
> To: J programming <programming@...>
>
> >
> > I came up with cute expression for totient, which in addition
> to
> > being cute, also seems faster than 5&p. (in j601)
> >
> > Here it is:
> >
> >    tot=:(- ~:)&.q:
> >
> >    (5&p: -: tot) 2+i.100000x
> > 1
> >
> >
> >    6!:2 '5 p: 2+i.100000x'
> > 2.51881
> >    6!:2 '(- ~:)&.q: 2+i.100000x'
> > 0.676987
> >    6!:2 '5 p: 2+i.100000'
> > 0.409061
> >    6!:2 '(- ~:)&.q: 2+i.100000'
> > 0.195733
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm