NB. I've omitted Jose's rather lengthy original posting to save space.
Re Linda's quoted Fibonacci verb,
13 :',(([:+/\|.)^:2)^:(<`(1,1:))y'
I couldn't understand it until I checked the vocabulary entry for ^:
a) u ^: (<n) does the same as u ^: (i.n)
b) u ^: (v1`v2) y does u^:(v1 y) (v2 y)
The engine of this fibonacci sequence generator is
([:+/\|.)
as in
([:+/\|.) 1 1 NB. f2 f3 given f1 f2 = 1 1
1 2
The rest is controlling the repetition of the engine's application.
So, developing the sequence,
([:+/\|.)^:(0 1 2 3 4) 1 1 NB. generate pairs f2 f3, f3 f4, ... ,f5 f6
1 1
1 2
2 3
3 5
5 8
([:+/\|.)^:2^:(0 1 2) 1 1 NB. only generate "even" pairs
1 1
2 3
5 8
([:+/\|.)^:2^:(<3) 1 1 NB. using ^: property (a), as above,
1 1
2 3
5 8
([:+/\|.)^:2^:(<`(1,1:)) 3 NB. gerund form of power, see (b) above
1 1
2 3
5 8
,([:+/\|.)^:2^:(<`(1,1:)) 3 NB. ravel result
1 1 2 3 5 8
I can't get my head round the Y combinator, but this isn't an
example!
Linda wondered why it stopped at 34 or 89 but not 55.
By its construction , this Fibonacci only does even numbers,
yielding elements 1 to 2*y
We could start from f0 f1, ie 0 1:
,([:+/\|.)^:2^:(<`(0,1:)) 3 NB. odd-number version
0 1 1 2 3 5
Cheers,
Mike
On 12/11/2018 08:20, Linda Alvord wrote:
Sorry about the post in the wrong thread.
There should be some "Y combinator" at work in here.
f=: 13 :',([:+/\|.)^:2^:(<`(0,1:))y'
f 5
0 1 1 2 3 5 8 13 21 34
f 6
0 1 1 2 3 5 8 13 21 34 55 89
I can't seem to stop at 55. Any ideas?
Linda
-----Original Message-----
From: Programming <[email protected]> On Behalf Of Linda
Alvord
Sent: Friday, November 9, 2018 12:56 AM
To: [email protected]
Subject: Re: [Jprogramming] Revisisting the Y combinator
Jose, I'm not sure I'll be able to follow your ideas.
!i.11x
1 1 2 6 24 120 720 5040 40320 362880 3628800
However, Fibohacci would be a nice primitive.
Linda
-----Original Message-----
From: Programming <[email protected]> On Behalf Of
'Pascal Jasmin' via Programming
Sent: Thursday, November 8, 2018 10:41 PM
To: [email protected]
Subject: Re: [Jprogramming] Revisisting the Y combinator
Interesting, thank you Jose.
I'll note that if the argument to Y is not an ar of an adverb then J (806 and
807) will crash when the result verb is called.
________________________________
From: Jose Mario Quintana <[email protected]>
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm