Thanks Jose, I am trying to run your code but am getting a syntax error with vrb:
|syntax error: scriptd | >@:(<@:(,^:(0:``:)&6)"0@:[<@:(,^:( 0:``:)&6@:([,(<'+'),]))/ .(((] I was hoping to debug or dissect it to see what it does, but since I can't dissect it I can't figure out what the error is. As for tacit meta-programming, I think this is outside the bounds of my J ability, but am researching it. By the way, my whole motivation for all this is to play around with uses of the d. conjunction, and find the function solution to some problems (ODE problems etc.). (So, for example, I can list different derivatives of a single function/verb, and play around with them). I didn't realize that playing around inside gerunds was this tricky. It is a good learning experience though. Regards, Jon > Date: Sun, 19 Apr 2015 15:58:41 -0400 > From: [email protected] > To: [email protected] > Subject: Re: [Jprogramming] Evaluating a Gerund Array > > (Trying again; fingers crossed) > > Tacit meta-programming is the underground playground. > > First, regarding your original post, the verb process that I posted > recently (see, > http://www.jsoftware.com/pipermail/programming/2015-April/041539.html) > almost produces what you want (the orthodox version or otherwise): > > > process=. < o train o ([ ; (an o >) y)("0) f. > > ( G=. (*:`%: ,. +:`^) ) > ┌──┬──┐ > │*:│+:│ > ├──┼──┤ > │%:│^ │ > └──┴──┘ > ( L=. 1 2 ) > 1 2 > > G process <4 > ┌──┬───────┐ > │16│8 │ > ├──┼───────┤ > │2 │54.5982│ > └──┴───────┘ > G process 1;2 > ┌───────┬───────┐ > │1 │2 │ > ├───────┼───────┤ > │1.41421│7.38906│ > └───────┴───────┘ > > Actually, a simplified version of process produces what you want (I think): > > process=. train o ([ ; an y)("0) f. > > G process 4 > 16 8 > 2 54.5982 > G process L > 1 2 > 1.41421 7.38906 > > Second, regarding, > " > For example, if G =: *:`+:`^ and list =. 3 4 5 > I want an adverb or conjunction that returns a verb of the form (3&*@:*:) + > (4&*@:+:) + (5&*@:^) > " > > The request is similar to the question posed in the post > http://www.jsoftware.com/pipermail/programming/2008-January/009553.html and > an underground answer is also similar to the one posted in > http://www.jsoftware.com/pipermail/programming/2014-November/040108.html : > > The powers of verbs verb ( pv=. (box x (at&>~ / .(power e)) ])f. ) can be > modified as follows: > > plus=. train o ([ , (<'+') , ]) > > STAR=. >@:((box <'*')"_) NB. * boxed > asa=. (] amper STAR) at [ NB. amper star at > > ( vrb=. > o (box x (< o plus/ .(asa e)) ])f. ) > >@:(<@:(,^:(0:``:)&6)"0@:[ <@:(,^:(0:``:)&6@:([ , (<'+') , ]))/ .(((] > ,^:(0:`&) >@:((<*)"_)) ,^:(0:`@:) [)&.>) ]) > > > G vrb L > 3&*@:*: + 4&*@:+: + 5&*@:^ > G vrb L 1 2 3 > 24.5914 64.9453 151.428 > > Note that vrb is a verb; it is an underground solution after all. It is > not difficult to cloak it as an adverb but sadly, because the form (c a) > was removed a long time ago, it is not possible to cloak it as a > conjunction using a current official interpreter. In extended J (see, > http://www.jsoftware.com/pipermail/programming/2013-March/031835.html) , > particularly in a version that is still cooking, is not only possible but > there is a lot more support to make underground tacit meta-programming even > easier. > > I am appalled that you overlooked the significance of my posts... I am, of > course, kidding (I could not resist) ;) > > P.S. > > NB. Collected definitions... > > o=. @: > (x=. o[) (y=. o]) (e=. &.>) > ((o[)(o]))(&.>) > > an=. <@:((,'0') ,&< ]) > > Cloak=. ((5!:1)@:<'Cloak')Cloak=. (0:`)(,^:) > > 'at amper evoke'=. Cloak o < e o ;: '@: & `:' > > train=. evoke&6 f. > box=. < o train "0 > > NB. First... > > ( G=. (*:`%: ,. +:`^) ) > ┌──┬──┐ > │*:│+:│ > ├──┼──┤ > │%:│^ │ > └──┴──┘ > ( L=. 1 2 ) > 1 2 > > process=. train o ([ ; an y)("0) f. > > G process 4 > 16 8 > 2 54.5982 > G process L > 1 2 > 1.41421 7.38906 > > NB. Second... > > plus=. train o ([ , (<'+') , ]) > > STAR=. >@:((box <'*')"_) NB. * boxed > asa=. (] amper STAR) at [ NB. amper star at > > ( vrb=. > o (box x (< o plus/ .(asa e)) ])f. ) > >@:(<@:(,^:(0:``:)&6)"0@:[ <@:(,^:(0:``:)&6@:([ , (<'+') , ]))/ .(((] > ,^:(0:`&) >@:((<*)"_)) ,^:(0:`@:) [)&.>) ]) > > ( G=. *:`+:`^ ) > ┌──┬──┬─┐ > │*:│+:│^│ > └──┴──┴─┘ > ( L=. 3 4 5 ) > 3 4 5 > > G vrb L > 3&*@:*: + 4&*@:+: + 5&*@:^ > G vrb L 1 2 3 > 24.5914 64.9453 151.428 > > > > > On Sun, Apr 19, 2015 at 4:13 AM, Jon Hough <[email protected]> wrote: > > > Roger, Raul, > > Thanks. Raul's answer is essentially what I needed. And I now have > > Learning J Chapter 14 open in my browser . > > I am still unsure about a few things, hopefully someone can clear these up. > > 1. If I have my nxn gerund array and I want to evaluate it on a list of n > > items, such that the first row takes the first item, the second row takes > > the second item etc. > > e.g. (*:`%: ,. +:`^) VRB 1 2 > > should evaluate to > > 1 14 7.38906 > > where VRB is some verb. Learning J, 14.3.1 has a similar example but in > > that case VRB = `:0 and it evaluateseach verb for the whole list. At first > > I thought I could do something like (`:0)"(1 0) but I still get unwanted > > results, namely, in the above case, I get 2x2x2 matrix as output. My > > workaround is just to take only the desired rows from the output. > > 2. This problem is a little bit more abstract. > > If I have a list of gerunds (1D this time), and I want to modify each verb > > in the gerund in some way, and then return the sum of the verbs, I am not > > sure how to do this. > > For example, if G =: *:`+:`^ and list =. 3 4 5 > > I want an adverb or conjunction that returns a verb of the form (3&*@:*:) > > + (4&*@:+:) + (5&*@:^) > > My attempt was to do > > len =: # G output =. '' for_j i. len do. output =. output + > > ((j{list)&*@:(G`:6)) end. output > > This is getting me nowhere however. I am actually not sure why it fails. > > One problem I am guessing exists is in the line output =. '' , which I used > > to 'initialize' the output verb. I am unsure if this is legal though. > > Regards,Jon > > > > > Date: Sun, 19 Apr 2015 08:35:34 +0100 > > > From: [email protected] > > > To: [email protected] > > > Subject: Re: [Jprogramming] Evaluating a Gerund Array > > > > > > Maybe "Learning J" section 14.3.1 might be useful. > > > > > > > > > > > > On 19/04/2015 06:51, Jon Hough wrote: > > > > My problem is slightly more complicated than the one I am giving in > > the example,but in essence the problem is, given a 2x2 array of gerunds, > > and anumber, how can I return a 2x2 array of the gerunds evaluated for the > > number. > > > > e.g. > > > > > > > > arr =: *:`%: > > > > > > > > > > > > > > > > arr2 =: +:`^ > > > > > > > > > > > > mat =. arr ,. arr2 > > > > > > > > > > > > list =. 4 3 > > > > > > > > > > > > I can evaluate individual cells thusly > > > > > > > > > > > > > > > > > > > > ((0{0{mat)`: 6) 4 > > > > > > > > > > > > But would like a single expression that would yield the result, for > > example (input = 4): > > > > > > > > > > > > 16 2 > > > > 8 54.5982 > > > > > > > > > > > > I cannot seem to get an expression that works. To add slightly to the > > complexity, my actual problem involves an > > > > arbitrary nxn matrix. > > > > > > > > > > > > ---------------------------------------------------------------------- > > > > 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 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
