Scalar extension: Difference between revisions

Jump to navigation Jump to search
34 bytes added ,  13:48, 14 November 2019
m
no edit summary
Miraheze>Adám Brudzewsky
m (Text replacement - "</code>" to "</source>")
Miraheze>Marshall
mNo edit summary
Line 1: Line 1:
Scalar extension is a way to apply a function with a [[scalar]] argument when an array of a particular non-empty [[shape]] would be expected. The scalar is ''extended'' to this shape by treating it as an array with each element equal to the scalar's only element. This is equivalent to reshaping the scalar to fit the desired shape.
'''Scalar extension''' is a way to apply a [[function]] with a [[scalar]] argument when an array of a particular non-[[empty]] [[shape]] would be expected. The scalar is ''extended'' to this shape by treating it as an array with each [[element]] equal to the scalar's only element. This is equivalent to [[Reshape|reshaping]] the scalar to fit the desired shape.


== History and terminology ==
== History and terminology ==
Line 8: Line 8:
2 4 6 8
2 4 6 8
</source>
</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 function]]s, so it's unclear when scalar extension as a unified concept was adopted in [[Iverson notation]].


The word "extension" applies to scalar extension in two ways: first, a function is extended by making a case which would have been a [[RANK ERROR]] into a valid application. Second, the application works by conceptually extending the scalar to function as though it were an array of higher rank.
The word "extension" applies to scalar extension in two ways: first, a function is extended by making a case which would have been a [[RANK ERROR]] into a valid application. Second, the application works by conceptually extending the scalar to function as though it were an array of higher rank.
Line 20: Line 20:
=== Singleton extension ===
=== Singleton extension ===


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 ([[singleton]]s) as scalars for the purposes of scalar extension. This practice is referred to as "singleton extension". For example,
<source lang=apl>
<source lang=apl>
       (1 1⍴5) + 10 20
       (1 1⍴5) + 10 20
Anonymous user

Navigation menu