As I said earlier, if you’re content with restriction to positive integers, you
can use the (temporary) sign as a parity flag.
Here’s an explicit form:
fe =: 4 : '|(-@<:@+:)^:(<y)x'
4 fe 10
4 7 15 29 59 117 235 469 939 1877
_4 fe 10 NB. Force other parity with negative sign
4 9 17 35 69 139 277 555 1109 2219
This tacit version is a little bit more complicated, using monodic gerund power
on x,y :
fi =: |@(-@<:@+:^:(<@{:`{.)@,)
_4 fi 10
4 9 17 35 69 139 277 555 1109 2219
Not as compact as Raul’s suggestions,
Cheers,
Mike
Please reply to [email protected].
Sent from my iPad
> On 27 Nov 2018, at 15:25, Raul Miller <[email protected]> wrote:
>
> It's more like this, actually:
>
> seqodd=: +: - 1:
> seqevn=: +: + 1:
> (,seqevn@{:)@(,seqodd@{:)^:8]4
> 4 7 15 29 59 117 235 469 939 1877 3755 7509 15019 30037 60075 120149 240299
>
> More generally, either:
>
> a) you keep explicit track of which position in the sequence you are
> generating, so you can choose between the odd or the even method, or
>
> b) you generate the numbers in pairs
>
> If you generate the numbers in pairs, you can rearrange things in a
> variety of ways.
>
> Thanks,
>
> --
> Raul
>
>
> On Tue, Nov 27, 2018 at 7:37 AM 'Pascal Jasmin' via Programming
> <[email protected]> wrote:
>>
>> If the verb you want is repetitive double - 1 then
>>
>> 5 (1 -~ +:@])^:(<@[) 4
>> 4 7 13 25 49
>>
>> Otherwise, Mike's 2 at a time approach is the way to go.
>>
>> ________________________________
>> From: Skip Cave <[email protected]>
>> To: "[email protected]" <[email protected]>
>> Sent: Tuesday, November 27, 2018 2:10 AM
>> Subject: [Jprogramming] Recursive verbs
>>
>>
>>
>> How would you write an implicit or explicit recursive verb for this
>>
>> sequence formula?
>>
>>
>> a1=.4
>>
>>
>> a1 , (a2=.1-~2*a1) , (a3=.1+~2*a2) , (a4=.1-~2*a3) , (a5=.1+~2*a4) ...
>>
>> (an=.1(+-)~2*an-1
>>
>>
>>
>> The verb would be specified as x f y, where x is the starting integer a1,
>>
>> and y is the number of terms (n) - or vice versa.
>>
>>
>> The result will be a vector n items long. Note the alternating sign in each
>>
>> term
>>
>>
>>
>> Example:
>>
>>
>> 4 f 5
>>
>>
>> 4 7 15 29 59
>>
>>
>>
>> Skip
>>
>> ----------------------------------------------------------------------
>>
>> 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