Pervasion: Difference between revisions

Jump to navigation Jump to search
183 bytes added ,  21:06, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
'''Pervasion''' during function application is the concept of a function being defined in terms of the [[simple scalar]]s in [[nested array]]s. It is a feature of [[Nested array model|nested]] array languages, while [[Flat array model|flat]] array languages usually do have function pervade into [[boxes]]. Pervasion can be seen [[recursion|recursing]] into all nested elements.
'''Pervasion''' during function application is the concept of a function being defined in terms of the [[simple scalar]]s in [[nested array]]s. It is a feature of [[Nested array model|nested]] array languages, while [[Flat array model|flat]] array languages usually do have function pervade into [[boxes]]. Pervasion can be seen as and modelled by [[recursion|recursing]] into all nested elements until the function can be applied to all simple scalars.


[[Scalar function]]s exhibit pervasion by default, whereas [[mixed functions]] and [[Function#Function definition|user defined function]]s do not. The pervading behaviour can be obtained for any function by using enough consecutive [[Each]] operators <source lang=apl inline>¨</source> to reach the simple scalars at the deepest point of nesting in any argument.
[[Scalar function]]s exhibit pervasion by default, whereas [[mixed functions]] and [[Function#Function definition|user defined function]]s do not. The pervading behaviour can be obtained for any function by using enough consecutive [[Each]] operators <syntaxhighlight lang=apl inline>¨</syntaxhighlight> to reach the simple scalars at the deepest point of nesting in any argument.


In dialects with the [[Depth (operator)|Depth]] operator (<source lang=apl inline>⍥</source>), a function can be used as a scalar function (that is, be applied to all simple scalars) using the <source lang=apl inline>⍥0</source>:
In dialects with the [[Depth (operator)|Depth]] operator (<syntaxhighlight lang=apl inline>⍥</syntaxhighlight>), a function can be made pervasive with <syntaxhighlight lang=apl inline>⍥0</syntaxhighlight>:


[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKPtUduE6kd9U4HUo56mlMzigke9u2ofdbcAxYJdgUR4sLprWWpeibqGenBqcXFmfl5AUSaQq6AO1KyuyfWoo70CqNk5PyVVoeK/X35ecHJiTmKRWx7Y4N6tVupAtUDzFNTT1Gu5NJAV9C410FTQMFAw1FQwVNB41NVkqGCgCXRTOxfItEe9a/4DAA Try it online!]
[https://tio.run/##SyzI0U2pTMzJT9dNrShJzUtJTfn/qKPtUduE6kd9U4HUo56mlMzigke9u2ofdbcAxYJdgUR4sLprWWpeibqGenBqcXFmfl5AUSaQq6AO1KyuyfWoo70CqNk5PyVVoeK/X35ecHJiTmKRWx7Y4N6tVupAtUDzFNTT1Gu5NJAV9C410FTQMFAw1FQwVNB41NVkqGCgCXRTOxfItEe9a/4DAA Try it online!]
<source lang=apl>
<syntaxhighlight lang=apl>
       NonScalarFn←{⍵:'t' ⋄ 'f'}
       NonScalarFn←{⍵:'t' ⋄ 'f'}
       (NonScalarFn⍥0) (0 1) 1 (⊂1 0)
       (NonScalarFn⍥0) (0 1) 1 (⊂1 0)
Line 14: Line 14:
│  │ │└──┘│
│  │ │└──┘│
└──┴─┴────┘
└──┴─┴────┘
</source>
</syntaxhighlight>
{{Works in|[[Extended Dyalog APL]], [[dzaima/APL]] since 2020-03-01}}
{{Works in|[[Extended Dyalog APL]], [[dzaima/APL]] since 2020-03-01}}
In [[dzaima/APL]] the [[dyadic]] form of Depth is not yet implemented, so this definition will only work for [[monadic function]] application
In [[dzaima/APL]] the [[dyadic]] form of Depth is not yet implemented, so this definition will only work for [[monadic function]] application
Line 21: Line 21:


<!-- [https://tio.run/##VZGxTsMwEIb3PMVtlwygZo3EVJURIWVAjFbsQKTItpwQFaEuCCUhKKgLIwOwMLB26cij@EXSc6IIasn23e@77@wz0/kJv2e5uhlsW9t6@2Bf32jjWaFtv7fdFzoTSV1eI09lgRv78kRuvKLlKsZVJWSJPsaiKDIlL01GLiDRMPBs26yJtlRcwHrQwlRjCQLXW9t9wvGw/TvECcuZARfKHM9zB@GZff6gLIrYuRlN9n6W5mTfCUzyYFS50OUtLCJQRCMVUglM6zxLWDmT/9UmVNv8fs@8P6AyM08QKAIjkjtTZJWA0rBKmILlp97Gu1Byuvy5nB65i5A6Qd0CTPHofHwe@AsIAwipSPcYwiKgH2g81yrb/wwH Try it online!] -->
<!-- [https://tio.run/##VZGxTsMwEIb3PMVtlwygZo3EVJURIWVAjFbsQKTItpwQFaEuCCUhKKgLIwOwMLB26cij@EXSc6IIasn23e@77@wz0/kJv2e5uhlsW9t6@2Bf32jjWaFtv7fdFzoTSV1eI09lgRv78kRuvKLlKsZVJWSJPsaiKDIlL01GLiDRMPBs26yJtlRcwHrQwlRjCQLXW9t9wvGw/TvECcuZARfKHM9zB@GZff6gLIrYuRlN9n6W5mTfCUzyYFS50OUtLCJQRCMVUglM6zxLWDmT/9UmVNv8fs@8P6AyM08QKAIjkjtTZJWA0rBKmILlp97Gu1Byuvy5nB65i5A6Qd0CTPHofHwe@AsIAwipSPcYwiKgH2g81yrb/wwH Try it online!] -->
<source lang=apl>
<syntaxhighlight lang=apl>
perv←{⍺←⊢              ⍝ Scalar pervasion
perv←{⍺←⊢              ⍝ Scalar pervasion
     1=≡⍺ ⍵ ⍵:⍺ ⍺⍺ ⍵    ⍝ (⍺ and) ⍵ depth 0: operand fn application
     1=≡⍺ ⍵ ⍵:⍺ ⍺⍺ ⍵    ⍝ (⍺ and) ⍵ depth 0: operand fn application
             ⍺ ∇¨⍵      ⍝ (⍺ or) ⍵ deeper: recursive traversal.
             ⍺ ∇¨⍵      ⍝ (⍺ or) ⍵ deeper: recursive traversal.
}
}
</source>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{Works in|[[Dyalog APL]]}}
In all dialects that support user defined [[tradop]]s, the operator for monadic function application can be defined as:
In all dialects that support user defined [[tradop]]s, the operator for monadic function application can be defined as:
<source lang=apl>
<syntaxhighlight lang=apl>
  R←(f perv)Y
  R←(f perv)Y
  →(0=≡Y)/APPLY
  →(0=≡Y)/APPLY
Line 35: Line 35:
  →0
  →0
APPLY:R←f Y
APPLY:R←f Y
</source>
</syntaxhighlight>
{{Works in|[[APL2]], [[APLX]], [[GNU APL]], [[Dyalog APL]]}}
{{Works in|[[APL2]], [[APLX]], [[GNU APL]], [[Dyalog APL]]}}
{{APL features}}
 
== References ==
<references />
{{APL features}}[[Category:Conformability]]

Navigation menu