Skip to content

[Feature request] Extend Under (&.) #233

@jip

Description

@jip

The following is a proposal to extend Under (&.) to allow various (any, I hope) possible combinations.

Syntax

  u&.(vi`v`ul`ur) y  <-->    {{vi v^:_1 ul u ur}} y
x u&.(vi`v`ul`ur) y  <-->  x {{vi v^:_1 ul u ur}} y

where

  • u - verb to process transformed argument(s)
  • v - verb with assigned obverse to do/undo arguments transformation
  • vi - verb to produce a left argument for v^:_1, is [: if v^:_1 is monadic
  • ul - verb to produce a left argument for u, is [: if u is monadic
  • ur - verb to produce a right argument for u

Model

und=: 2 : 'n@.0 n@.1^:_1 n@.2 u n@.3'

Examples

Implement standard monadic &.:

   %: <: *: 4              NB. sqrt(4^2 - 1)
3.87298
   <:&.*: 4
3.87298
   <: und ([:`*:`[:`*:) 4  NB. the resulting train is ([: *:^:_1 [: <: *:)
3.87298

Implement standard dyadic &.:

   %: (*: 3) + (*: 4)               NB. sqrt(3^2 + 4^2)
5
   3 +&.*: 4
5
   3 + und ([:`*:`(*:@[)`(*:@])) 4  NB. the resulting train is ([: *:^:_1 *:@[ + *:@])
5

Implement standard dyadic &. with semiduals:

   %: 3 + (*: 4)               NB. sqrt(3 + 4^2)
4.3589
   3 +&.(a:`*:) 4
4.3589
   3 + und ([:`*:`[`(*:@])) 4  NB. the resulting train is ([: *:^:_1 [ + *:@])
4.3589

   %: (*: 3) + 4               NB. sqrt(3^2 + 4)
3.60555
   3 +&.(*:`a:) 4
3.60555
   3 + und ([:`*:`(*:@[)`]) 4  NB. the resulting train is ([: *:^:_1 *:@[ + ])
3.60555

Implement non-standard monadic &. with dyadic inversion (say, for some J dictionary jdict):

   upd=: get__jdict :. (put__jdict~)
   NB. a monad to double values corresponding to keys y
   +: und (]`upd`[:`upd)  NB. the resulting train is (] upd^:_1 [: +: upd)

Implement non-standard dyadic &. with dyadic inversion:

   NB. a dyad which passes its left argument x to the left argument of v^:_1
   u und ([`v`ul`ur)  NB. the resulting train is ([ u^:_1 ul u ur)

Implement an extension proposed in #212:

   u und ([:`(m&{)`(m&{@[)`(m&{@]))  NB. the resulting train is ([: m&{^:_1 m&{@[ + m&{@])

Use extrinsic ul and ur not related to v at all:

   u und (vi`v`f`g)  NB. the resulting train is (vi v^:_1 f u g)

Notes

Whether the u, v, v^:_1 verbs need to be ambivalent depends on the train to compose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions