sdiv8 is a worthy counterpart to totient=: (- ~:)&.q: >:@#.~/.~&.q: NB. sum of divisors of n (- ~:)&.q: NB. number of numbers < n co-prime to n
On Tue, Jun 10, 2014 at 6:36 PM, Henry Rich <[email protected]> wrote: > Last version along this path: > > sdiv8 =: >:@#.~/.~&.q: > (sdiv5 -: sdiv8) !20x > 1 > > Henry Rich > > On 6/10/2014 9:09 PM, Henry Rich wrote: > >> Better implementation: >> >> sdiv5 =: (*//.~ (* %&<: ]) ~.)&.q: >> sdiv7 =: >:@(#. {.)/.~&.q: >> (sdiv5 -: sdiv7) !20x >> 1 >> >> >> On 6/10/2014 8:56 PM, Henry Rich wrote: >> >>> Back to adding powers then: >>> >>> sdiv5 =: (*//.~ (* %&<: ]) ~.)&.q: >>> sdiv6 =: (#. %~)@(,{.)/.~&.q: >>> (sdiv5 -: sdiv6) !20x >>> 1 >>> >>> Henry Rich >>> >>> On 6/10/2014 8:08 PM, Roger Hui wrote: >>> >>>> Since */ and q: are an inverse pair, >>>> >>>> sdiv4 =: (*//.~ (* */@:%&:<: ]) ~.)@q: >>>> sdiv5 =: (*//.~ (* %&<: ]) ~.)&.q: >>>> >>>> (sdiv -: sdiv5) !20x >>>> 1 >>>> >>>> >>>> >>>> >>>> >>>> On Tue, Jun 10, 2014 at 3:33 PM, Roger Hui <[email protected]> >>>> wrote: >>>> >>>> sdiv =: */ @: (((^>:) %&<: [)/) @: (__&q:) >>>>> sdiv1 =: */ @ (%~/) @: <: @ ((^>:)/\) @ (__&q:) >>>>> sdiv2 =: (((^>:) */@:%&:<: [)/) @: (__&q:) >>>>> sdiv3 =: __ ((^>:) */@:%&:<: [)/@q: ] >>>>> sdiv4 =: (*//.~ (* */@:%&:<: ]) ~.)@q: >>>>> >>>>> (sdiv -: sdiv1) !20x >>>>> 1 >>>>> (sdiv -: sdiv2) !20x >>>>> 1 >>>>> (sdiv -: sdiv3) !20x >>>>> 1 >>>>> (sdiv -: sdiv4) !20x >>>>> 1 >>>>> >>>>> >>>>> >>>>> >>>>> On Tue, Jun 10, 2014 at 1:54 PM, Henry Rich <[email protected]> >>>>> wrote: >>>>> >>>>> Shorter version: >>>>>> >>>>>> sdiv =. */@(%~/)@:<:@((^ >:)/\)@(__&q:) >>>>>> >>>>>> spdiv =. (-~ sdiv) >>>>>> spdiv 12 >>>>>> 16 >>>>>> >>>>>> Henry Rich >>>>>> On 6/10/2014 3:09 PM, Henry Rich wrote: >>>>>> >>>>>> NB. sum of divisors >>>>>>> sdiv =. (*/) @: (((^ >:) %&<: [)/) @: (__&q:) >>>>>>> NB. sum of proper divisors >>>>>>> spdiv =. (-~ sdiv) >>>>>>> spdiv 12 >>>>>>> 16 >>>>>>> >>>>>>> Henry Rich >>>>>>> >>>>>>> On 6/10/2014 1:18 PM, Roger Hui wrote: >>>>>>> >>>>>>> From http://www.jsoftware.com/jwiki/Essays/Divisors >>>>>>>> >>>>>>>>> >>>>>>>>> >>>>>>>> div=: /:~ @: , @: > @: (*/&.>/) @: ((^ i.@>:)&.>/) @: (__&q:) >>>>>>>> div 360 >>>>>>>> 1 2 3 4 5 6 8 9 10 12 15 18 20 24 30 36 40 45 60 72 90 120 180 360 >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> On Tue, Jun 10, 2014 at 10:10 AM, Jon Hough <[email protected]> >>>>>>>> wrote: >>>>>>>> >>>>>>>> My attempt at making a verb that finds the total of all proper >>>>>>>> >>>>>>>>> divisors of >>>>>>>>> an integer seems to work. >>>>>>>>> e.g. if n = 12, the sum of proper divisors is 1 +2 +3+4+6 = 16 >>>>>>>>> (note >>>>>>>>> 12 is >>>>>>>>> not included) >>>>>>>>> This verb is actually equal to the "sigma function" minus >>>>>>>>> n.Wikipedia >>>>>>>>> explanation: http://en.wikipedia.org/wiki/Divisor_function >>>>>>>>> (I essentially used the equation for sigma_x(n) where x = 1) >>>>>>>>> my verb: >>>>>>>>> >>>>>>>>> sum =.(((*/@:-&1@:{.)%~(*/@:-&1@:({.^(1&+@:,@:}.))))@:(2&p:))-] >>>>>>>>> This seems ok, but is not aesthetically pleasing, and seems to be >>>>>>>>> very >>>>>>>>> bracketty, and given that the mathematical equation is pretty >>>>>>>>> concise >>>>>>>>> I am >>>>>>>>> surprised the J verb is so long. If anyone knows a nicer way of >>>>>>>>> doing >>>>>>>>> this >>>>>>>>> I would be grateful to see it. >>>>>>>>> Regards. >>>>>>>>> ------------------------------------------------------------ >>>>>>>>> ---------- >>>>>>>>> >>>>>>>>> >>>>>>>>> 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 >> >> ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
