[Jprogramming] Am I understanding m/y ?

Martin Kreuzer info at airkreuzer.com
Tue Jun 14 12:13:19 UTC 2016


Remembering the discussion in the context of 
continued fractions when people (including me) did things like

    +`%/ 100 $ 1
1.61803

I sorted this out for myself as follows:

Given a vector (with number elements) like

    ] v=. >: i.7
1 2 3 4 5 6 7

and a gerund (with verb elements) like

    ] G=. +`+`-`+
+-+-+-+-+
|+|+|-|+|
+-+-+-+-+

I thought of these simply as two (almost form-identical) _patterns_,
the number vector as a paling fence (with gaps),
the gerund as a "verb vector" overlaying the other (and thus filling the gaps).

Until that point there was no left-to-right or 
right-to-left (besides joining the two patterns on the left,
first element of the gerund filling the left 
first gap), as an _overlay_ is simply placed on top of something else:

    G / v
_16

This is the fence with the gaps filled

    1+2+3-4+5+6+7
_16

and now J's right-to-left precedence in working on expressions takes over:

7 + 6 =13
13 + 5 = 18
18 + 4 = 22
[change of sign]
_22
_22 + 3 = _19
_19 + 2 = _17
_17 + 1 = _16  NB. voila

I was at first somehow confused when I saw this:

    +`+`-`+/\ >: i.7
1 3 6 2 _3 _9 _16

which seemed to indicate that something was running in the opposite direction;
but at a closer look that impression proved deceptive.

So the whole discussion is (as I see it) on 
whether to do a left or right join of the two patterns
and I think this simple example shows quite 
clearly how the interpreter thinks about that:

    1+2+3-4+5+6+7   NB. pattern "left join" (correct)
_16

    1-2+3+4+5-6+7  NB. pattern "right join" (giving the wrong answer)
0

Thanks
-M


At 2016-06-14 03:07, you wrote:
>Perhaps easier to see with more 
>formal/expressive verbs:    in =. 1 :'[,'' 
>'',u,'' '',]' NB. String to infix 
>function    ('f0'in)`('f1'in)`('f2'in)/ 'abcde' 
>a f0 b f1 c f2 d f0 e The verbs in the gerund 
>are arranged from left to right starting at the 
>beginning of the array, while application (as in 
>the non-gerund case) proceeds from right to 
>left. I would avoid calling either of these 
>things "unrolling" without further explanation 
>as it's not clear which that would mean. Dan's 
>example has typos, and his wording is vague 
>enough that I can't tell whether it is correct. 
>Marshall On Tue, Jun 14, 2016 at 02:21:37AM 
>+0000, 'Pascal Jasmin' via Programming wrote: > 
>+`-/ 1 2 3 > 0 > +`+`-/ 1 2 3 > 6 > > > I call 
>this as being inserted between items on a right 
>to left basis. > > 1 + 2 - 3 + 4 > > +`-/ 1 2 3 
>4 > _4 > +`-/ 1 2 > 3 > > > > ----- Original 
>Message ----- > From: Dan Bron <j at bron.us> > To: 
>J Programming <programming at jsoftware.com> > 
>Sent: Monday, June 13, 2016 9:04 PM > Subject: 
>Re: [Jprogramming] Am I understanding m/y ? > > 
>Louis wrote: > > > There was some talk a while 
>ago about the ambiguity of the dictionary about 
>the direction of gerund insertion. Reading 
>through the first pages of Iverson's Concrete 
>Math Companion, I stumbled on a snippet of J 
>that dates back to 2002 and was written by 
>Iverson at the bottom of page 6: > > > > 
>http://www.jsoftware.com/books/pdf/cmc.pdf 
><http://www.jsoftware.com/books/pdf/cmc.pdf> > >  
> > > According to this source, gerunds do indeed 
>"unroll" from left to right correctly in the 
>current implementation. > > > I’m also on 
>mobile, so forgive my terse answer and potential 
>misunderstanding of your question, but 
>yes: > > >         v0`v1`v2`v3/ y > > is 
>indeed: > >         
 (_8{y)  v2 (_7{y) v3 
>(_6{y) v0 (_5{y) v1 (_4{y) v2 (_3{y) v1 (_2{y) 
>v0 _1{y > > That is, the insertion of verbs 
>starts at the rightmost (last) elements of y, 
>but the leftmost (first) elements of the gerund 
>G, where  G/y  . > > The rationale for this is 
>left as an exercise for a less lazy respondent 
>(though the right-to-left nature of insertion in 
>y should be familiar to veteran J’ers). > > 
>-Dan > > > > 
>----------------------------------------------------------------------  
> > 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



More information about the Programming mailing list