Cliff's answer is helpful IMO,
^. is a "good" ambivalent verb because it is one that can be imagined where the
monadic version is a "default value" of the dyad.
An alternate to ahk construction, is the expression
(^. inv 1)&$: : (^. +:)
so an alternative to ahk is the double adverb "default adverb"
da =: 1 : '(u&$:) :'
(^. inv 1) da
2.7182818284590451&$: :
(^. +: )(^. inv 1) da
2.7182818284590451&$: :(^. +:)
On Friday, May 10, 2019, 5:25:39 a.m. EDT, Clifford Reiter
<[email protected]> wrote:
Not simpler, but a few remarks. First an example of your u
u=: (^.@+:) : (^. +:)
3 u 4.5
2
u 1r2x1
1
Note that J "thinks" about your two functions quite differently
13 : 'x ^. +: y'
[ ^. [: +: ]
13 : '^. +: y'
[: ^. +:
You can of course define your own conjunction is you want this a lot.
(ahk stands for alternate hook)
ahk=:2 : 'u@:v : (u v)'
3 ^. ahk +: 4.5
2
^. ahk +: 1r2x1
1
One could argue that the definition of monadic hook is wrong.
In part, because if it was defined as in ahk instead,
it would be easy to recover the current behavior with ~
(^. +:) 1r2x1
3.25889
(^. ahk +:)~ 1r2x1 NB. () unneeded here but would be if hook were changed
3.25889
On the other hand the current monadic hook is quite useful and it
maintains the ambivalent property that alternate verbs from the right are
always dyads.
Just a few thoughts. Probably not very useful.
Best, Cliff
On the other hand
On Fri, May 10, 2019 at 1:29 AM Piet de Jong <[email protected]> wrote:
> Am having a mental block about this problem so will appreciate any help.
> The following is a simplified version of the problem. Apologies if this
> is a stupid question.
>
> Take the verb ^. which has both a monad and dyad definition: log_e(y) for
> monad and log_x(y) for dyad
>
> Now suppose I want the verb u which computes log_e (2y) if monad and
> log_x (2y) for dyad.
>
> This can be achieved with the monad/dyad “:” construction as in
>
> u=: (^.@+:) : (^. +:) NB. seems relatively complicated!!
>
> Is there a simpler way? What am I missing??
> ----------------------------------------------------------------------
> 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