Scalar: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
m (Text replacement - "{{APL programming language}}" to "{{APL features}}")
m (Text replacement - "langauge" to "language")
 
(4 intermediate revisions by 3 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 languages 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]]

Latest revision as of 22:10, 26 August 2024

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 ×/⍬, or 1. The Enclose function creates scalars: for any array x, its enclose ⊂x is a scalar whose only element is x.

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.

Scalar extension is the process of extending a function to accept a scalar when an array of a specific shape would normally be expected. Since the scalar has only one element, there is only one possibility: the scalar is treated as an array all of whose elements are that 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 cells, since a major cell of a rank 0 array would have rank ¯1, which is impossible. A common convention in array languages 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 ≢'a' 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. Reversing or reducing a scalar yields that scalar with no changes.

Iverson's A Dictionary of APL uses the name "item" for scalars.

External Links

Is a scalar an array?

APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR