Scalar: Difference between revisions

Jump to navigation Jump to search
117 bytes added ,  21:27, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
m (6 revisions imported: Migrate from miraheze)
m (Text replacement - "<source" to "<syntaxhighlight")
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
In the APL [[array model]], a '''scalar''' is an array with [[rank]] zero, that is, empty [[shape]]. A scalar contains only a single [[element]]: its [[bound]] is the product of the [[empty]] list <source lang=apl inline>×/⍬</source>, or 1. The [[Enclose]] function creates scalars: for any array <source lang=apl inline>x</source>, its enclose <source lang=apl inline>⊂x</source> is a scalar whose only element is <source lang=apl inline>x</source>.
In the APL [[array model]], a '''scalar''' is an array with [[rank]] zero, that is, empty [[shape]]. A scalar contains only a single [[element]]: its [[bound]] is the product of the [[empty]] list <syntaxhighlight lang=apl inline>×/⍬</syntaxhighlight>, or 1. The [[Enclose]] function creates scalars: for any array <syntaxhighlight lang=apl inline>x</syntaxhighlight>, its enclose <syntaxhighlight lang=apl inline>⊂x</syntaxhighlight> is a scalar whose only element is <syntaxhighlight lang=apl inline>x</syntaxhighlight>.


In a language using nested lists for arrays, there is one level of nesting for each [[axis]], so a "scalar" would have zero levels: it is not a list. In APL a scalar is considered an array, and a scalar containing an array is usually distinct from that array.
In a language using nested lists for arrays, there is one level of nesting for each [[axis]], so a "scalar" would have zero levels: it is not a list. In APL a scalar is considered an array, and a scalar containing an array is usually distinct from that array.
Line 7: Line 7:
The [[floating array model]] identifies the enclose of a [[simple scalar]] (that is, a scalar array containing a simple scalar) with the scalar itself. However, the enclose of a non-simple scalar, such as an enclosed matrix, is still distinct from its element.
The [[floating array model]] identifies the enclose of a [[simple scalar]] (that is, a scalar array containing a simple scalar) with the scalar itself. However, the enclose of a non-simple scalar, such as an enclosed matrix, is still distinct from its element.


Under a strict definition a scalar has no [[major cell]]s, since a major cell of a rank 0 array would have rank ¯1, which is impossible. A common convention in array langauges such as [[Dyalog APL]] and [[J]] which define functions in terms of major cells is that a scalar has a single major cell—itself. Thus <source lang=apl inline>≢'a'</source> is equal to 1. Similarly, it is common for functions or operators which act on the axes of an array to act as though the array has an invisible axis of length 1. [[Reverse|Reversing]] or [[Reduce|reducing]] a scalar yields that scalar with no changes.
Under a strict definition a scalar has no [[major cell]]s, since a major cell of a rank 0 array would have rank ¯1, which is impossible. A common convention in array langauges such as [[Dyalog APL]] and [[J]] which define functions in terms of major cells is that a scalar has a single major cell—itself. Thus <syntaxhighlight lang=apl inline>≢'a'</syntaxhighlight> is equal to 1. Similarly, it is common for functions or operators which act on the axes of an array to act as though the array has an invisible axis of length 1. [[Reverse|Reversing]] or [[Reduce|reducing]] a scalar yields that scalar with no changes.


Iverson's [[A Dictionary of APL]] uses the name "item" for scalars.
Iverson's [[A Dictionary of APL]] uses the name "item" for scalars.
Line 14: Line 14:


[https://code.jsoftware.com/wiki/Essays/Scalars Is a scalar an array?]
[https://code.jsoftware.com/wiki/Essays/Scalars Is a scalar an array?]
{{APL features}}
{{APL features}}[[Category:Kinds of array]]

Navigation menu