This is a very nice bit of math! The idea is that we subtract the number of numbers that are either second or third powers, but if we just do this directly, we double-count sixth powers (which are both). Therefore we add back in the sixth powers.
-/ accomplishes this quite nicely by adding the two even-indexed numbers (2 and 3) and subtracting 6 . The reason (g3a 75) is 86 is because it fails to count the perfect square (ie. 81) in between 75 and 87, thus coming up one short. I recommend for this method using g3=: (+ -/@:>.@:(2 6 3&%:))^:_~ which repeatedly takes the value to be added from its current guess rather than the initial number. It will always come up with the lowest inverse of f . Marshall -----Original Message----- From: programming-boun...@jsoftware.com [mailto:programming-boun...@jsoftware.com] On Behalf Of Björn Helgason Sent: Monday, December 27, 2010 9:27 AM To: Programming forum Subject: Re: [Jprogramming] finding number As usual you have a way of coming up with something brilliant that takes some time for me to understand. I get it with the perfect squares and perfect cubes because that is what I was originally after but what has the perfect 6-th power to do with this? And by the way g3a gives me 86 and not 87 f3 =: - -/@:>.@:(2 6 3&%:) f3 87 75 g3a=: + -/@:>.@:(2 6 3&%:) g3a 75 86 2010/12/27 Roger Hui <rhui...@shaw.ca> > A fast inverse for f derives by observing that f is equivalent to: > > f3 =: - -/@:>.@:(2 6 3&%:) > > That is, f3 n is n less the perfect squares and perfect cubes bounded > by n, plus the perfect 6-th powers. The function g3a then is very > near to the inverse to f3 : > > g3a=: + -/@:>.@:(2 6 3&%:) > > For example: > > f3 1e9 > 999967409 > g3a 999967409 > 1000000000 > > However: > g3a 112 > 125 > f3 125 > 111 > > The details of deriving g3, the inverse for f3, are left as an > exercise for the reader. > > > > ----- Original Message ----- > From: Björn Helgason <gos...@gmail.com> > Date: Sunday, December 26, 2010 11:48 > Subject: [Jprogramming] finding number > To: Programming forum <programming@jsoftware.com> > > > I have a small task that looks like this > > > > f=: [: # i. -. (2 ^~ i.) , 3 ^~ i. > > f 87 > > 75 > > > > I want to use tacit to find what number gives me 75 numbers (the > > answerbeing 87) > > > > Could be asking what argument y do I need to find x numbers > > according to the formula above > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > -- Björn Helgason, Verkfræðingur Fornustekkum II 781 Hornafirði, t-póst: gos...@gmail.com gsm: +3546985532 sími: +3544781286 http://groups.google.com/group/J-Programming Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans góður kennari getur stigið á tær án þess að glansinn fari af skónum /|_ .-----------------------------------. ,' .\ / | Með léttri lund verður | ,--' _,' | Dagurinn í dag | / / | Enn betri en gærdagurinn | ( -. | `-----------------------------------' | ) | (\_ _/) (`-. '--.) (='.'=) ♖♘♗♕♔♙ `. )----' (")_(") ☃☠ ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm