Scalar extension: Difference between revisions
Jump to navigation
Jump to search
→History and terminology
Miraheze>Adám Brudzewsky m (→Examples) |
Miraheze>Adám Brudzewsky |
||
Line 4: | Line 4: | ||
The concept of scalar extension has been around since [[APL\360]]. An example which extends the scalar <code>2</code> is: | The concept of scalar extension has been around since [[APL\360]]. An example which extends the scalar <code>2</code> is: | ||
< | <source lang=apl> | ||
2 × 1 2 3 4 | 2 × 1 2 3 4 | ||
2 4 6 8 | 2 4 6 8 | ||
</ | </source> | ||
[[A Programming Language]] describes the above computation as a "scalar multiple" but does not generalise it to arbitrary [[scalar functions]], so it's unclear when scalar extension as a unified concept was adopted in [[Iverson notation]]. | [[A Programming Language]] describes the above computation as a "scalar multiple" but does not generalise it to arbitrary [[scalar functions]], so it's unclear when scalar extension as a unified concept was adopted in [[Iverson notation]]. | ||
Line 21: | Line 21: | ||
Some APLs, such as [[Dyalog APL]], treat arrays with one element (singletons) as scalars for the purposes of scalar extension. This practice is referred to as "singleton extension". For example, | Some APLs, such as [[Dyalog APL]], treat arrays with one element (singletons) as scalars for the purposes of scalar extension. This practice is referred to as "singleton extension". For example, | ||
< | <source lang=apl> | ||
(1 1⍴5) + 10 20 | (1 1⍴5) + 10 20 | ||
15 25 | 15 25 | ||
⍴ (1 1⍴5) + 10 20 | ⍴ (1 1⍴5) + 10 20 | ||
2 | 2 | ||
</ | </source> | ||
{{Works in|[[Dyalog APL]], [[APLX]]}} | {{Works in|[[Dyalog APL]], [[APLX]]}} | ||
In this case addition accepts a singleton, and discards its shape. If two singletons are used as arguments, they are still considered to [[Conformability|conform]]; the shape of the result is taken from the argument with higher rank. | In this case addition accepts a singleton, and discards its shape. If two singletons are used as arguments, they are still considered to [[Conformability|conform]]; the shape of the result is taken from the argument with higher rank. |