From mniemiec@interserv.com Fri Sep 20 09:29:23 2002 Date: Tue, 17 Sep 2002 01:47:35 -0700 From: Mark D. Niemiec Reply-To: forum@jsoftware.com To: J Forum Subject: Re: Jforum: Caps and Bells! On Mon, 16 Sep 2002, Norman Thomson wrote: > However the main point of this note is to say that, in my view, defining > y=.@] and seeking to pursuing equivalences may not be the right line of > thinking. I see in J two sorts of valence, one of which I think of as > verbal valence (this is just the normal usage of ‘valence’) and the other > which I shall call ‘compositional valence’ for which there is as far as I > am aware no current technical term. By the latter I mean that a fork f g > h normally means (with an obvious notation) g(f,h), that is to say it is > compositionally dyadic, but verbally it may be either monadic or dyadic. > What cap does is to make a fork compositionally monadic, that is g(h), > again with both verbal valences possible. It may help to think of the (verbal) valences of the combining idiom and of the component verbs separately. In each case, some of the combining verbs have a valence (either monadic or dyadic) which is fixed by the combining idiom, and others are ambivalent, having the same valence as the entire idiom. Remembering this makes it easier to choose an appropriate idiom, and can help avoid simple errors. Some examples: fork: ambivalent_f dyadic_g ambivalent_h capped fork: [: monadic_g ambivalent_h (same as g@:h) hook: dyadic_f monadic_g (same as [ f g@]) at, atop: monadic_u @: ambivalent_v (same as [: u v) oppose, appoose: ambivalent_u &: monadic_v under: ambivalent_u &. invertible_monadic_v monad/dyad: monadic_u : dyadic_v determinant, dot: monad_u . dyad_v even, odd: ambivalent_u .. monad_v cut: monad_v ;. noun_n reflexive/passive: dyadic_u ~ insert/table: dyadic_u / prefix/infix, suffix/outfix, oblique/key: monadic_u \ > The advantage of this is that if you have v1=.[:%- it reads ‘take the > reciprocal of the negative/difference’ depending on whether the verbal > valence is monadic/dyadic. If you omit cap, %- is a hook which is > compositionally monadic g(h), but with an abnormal interpretation (from a > mathematical point of view at least) of function composition, which makes > it a bit harder to put into English (viz. either y.%-y. or x.%-y. > depending on verbal monadic/dyadic). Capped fork ([: f g) is equivalent to composition indicated by (f@:g), with f always monadic, so ([:%-) might be called "reciprocal of negative/minus" Hook (f g) is equivalent to for ([ f g@]). f is always dyadic, and g is always monadic. so (%-) when used dyadically would be "x (divided by negative)", and monadically "y (divided by its negative)" You can get similar behaviour as with f above by forcing a verb to be dyadic via (f~) ; this always invokes f dyadically (and reverses its arguments), but uses the same arguments twice if invoked monadically. Doing this twice (f~~) does the same thing without reversing the arguments. This can also be done via ([f]) or (f]), but these change the rank to _ while (f~~) leaves the rank unchanged) > The advantage of cap is that it is possible to generate long verbal trains > without parentheses because fork can be made to manipulate sequencing. > Without cap, sequencing conjunctions (@ and @: ) and parentheses are in > general necessary. In my view, to require explicit sequencing when that > is in fact present is a good thing, but I accept that this is a matter of > personal programming taste. The two trains ([:f[:g[:h[:i[:j) and (f@:g@:h@:i@:j) are equivalent, and neither requires parentheses. Even if forks bind right-to-left, and conjunctions bind left-to-right, this is not a problem, since composition of this kind is associative, as the actual execution of the verbs must be from right-to-left. (f@:g)@:h is the same as f@:(g@:h). This is NOT true in general for (f@g)@h vs. f@(g@h) because the ranks of the intermediate verbs might be different > However, I would urge anyone considering > using cap as of habit to restrict themselves to forks, e.g. v2=. [:-[:%- >(dyadic) means ‘negate the reciprocal of the negative/difference’ which >is fine, e.g. 2 v2 5 is 1/3. However if you omit the leftmost [: you have >to resolve a hook after a fork so that the meaning in the dyadic case is >x. reciprocal of x.-y. , again not so easy to put into English. > A corollary of the above is that cap is NOT a special kind of verb with > zero arguments, but a marker which changes the compositional valence of a > fork. Actually, this is both true and false. Cap has two different uses: 1) it is a normal verb (with infinite rank) that has neither monadic nor dyadic application. It produces a valence error whenever used. This can be useful for explicitly forcing or restricting the valence of an ambivalent verb, for example: reciprocal =: % : [: divide =: [: : % reciprocal 3 0.333333 divide 3 |valence error: divide | divide 3 3 divide 4 0.75 3 reciprocal 4 |valence error: reciprocal | 3 reciprocal 4 2) It is a 'magic' syntactical marker which changes forks (in which g is always dyadic) into capped forks (in which g is always monadic). This is unambiguous, because use of cap as a verb in such a case would yield a fork that always results in a valence error (so it is not something anyone would want to use in a practical situation). Hiding the cap so it looks like another verb illustrates this: ([: % -) 3 _0.333333 ([:"_ % -) 3 |valence error | ([:"_%-)3 -- Mark D. Niemiec -------------------------------------------------------------------------- For information about the J Forum see http://www.jsoftware.com/j_forum.htm