(<. + 0 2 {~ 0 0.5 i. 1&|) 1 1.5 2 2.5
1 3 2 4
   (+ 3 * (-<.)) 1 1.5 2 2.5
1 3 2 4
   (+ 3 * 1&|) 1 1.5 2 2.5
1 3 2 4


I think you meant '1.5+S' instead of '2+S' 

Henry Rich

> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Dan Bron
> Sent: Thursday, July 31, 2008 2:04 PM
> To: Programming forum
> Subject: [Jprogramming] Hofstadter-Conway $10,000 Sequence
> 
> I'm looking for a cutesy way to express the following:
> 
>          (<. + 0 2 {~ 0 0.5 i. 1&|)
> 
> The input is a vector of non-negative real numbers, which are 
> either integers or whose fractional part is one-half.  
> Equivalently, the input is  -: V  where  V  is a vector of 
> non-negative integers.
> 
> The output is a vector of non-negative integers, similar to 
> the input, but where each non-integer scalar  S  has been 
> replaced with  2+S  (the integer scalars have been left alone).
> 
> 
> -Dan
> 
> 
> PS:  The application is in the context of the iterated 
> batrachion function  (hcs n) - n%2  where  hcs  is the 
> "Hofstadter-Conway $10,000 Sequence".  See the right graphic 
> in the first figure at 
> 
>      
> http://mathworld.wolfram.com/Hofstadter-Conway10000-DollarSequ
> ence.html
> 
> You can plot it in J with:
> 
>          require 'plot'
>          
>          hcs        =:  1:`((] +&:$: -) $:@:<:)@.(2&<) M.     
>           NB.  Hofstadter-Conway $10,000 Sequence
>          batrachion =:  hcs - -:
> 
>          plot batrachion"0 i. 1000
> 
> While investigating this function, I noticed that  hcs  was 
> in the OEIS (it's A004001 [1]), but  (hcs n) - n%2  is not.  
> I decided to add it (and evangelize J a bit, because I think 
> the verb  hcs  shows J off well), but then I realized why it 
> wasn't in there in the first place:  it contains non-integers.
> 
> So I need to convert the non-integers to integers.  The first 
> thing that popped into my head was to take the sum of the 
> denominators of the egyptian fraction expansion of each 
> scalar.  Adapting Roger's  ef  verb [2] a bit, I came up with:
> 
>          
>          ef         =:  (  ((] , $:@:(- %)) >:)^:((~: %)~) 
> <.@:% ) M.   NB.  Egyptian fraction denominators
>          ib         =:  +/@:ef@:batrachion"0                  
>           NB.  Integer batrachion
> 
>          plot _&=`(,:&0)} ib i. 1000
> 
> But then I realized this was overkill, because each scalar is 
> either an integer (and  N = +/@:ef N  is a tautology for 
> integer  N  ), or halfway between two integers, which means 
> all the denominators but the last are  1  ,  and the last is 
> always  2  .
> 
> So now we have:
> 
>          lef        =:  (<. + 0 2 {~ 0 0.5 i. 1&|)            
>           NB.  "Limited" egyptian fraction
>          ib2        =:  +/@:lef@:batrachion"0
> 
>          plot ib2"0 i. 1000
> 
> But I would really like to show off J, and I feel that  lef  
> is just too "brute force" (imperative).  Further, OEIS has a 
> very mathematical emphasis, and  les  has a programming bent. 
>  So I would really like a cuter, more mathematical replacement.
> 
> If you provide one, the bonus is you get your name 
> immortalized in the OEIS (as a reference and a link to your message).
> 
> [1]  http://www.research.att.com/~njas/sequences/A004001
> [2]  
> http://www.jsoftware.com/pipermail/programming/2005-November/0
> 00064.html
> 
> ----------------------------------------------------------------------
> 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