Skip to main content

Superscripts and subscripts

Superscripts and subscripts written after a token, which apply an operation to it or select from it

A superscript, such as ², applies an operation to a number, array or function. A numeric subscript, such as ₁, selects positions from an array or axes for a function. Both bind more tightly than function application. v₁² is the square of item 1 of v:

v←10 20 30
v₁²
400

On an array, an attached script applies to the preceding token. A modifying script on a function applies to the whole function on its left, as an ordinary monadic operator does: f∘g⁻ is (f∘g)⁻. Enclosure ˢ instead applies to the preceding token: f⍣gˢ uses the scalar holding g; (f∘g)ˢ holds the whole composition. A separated script applies to the whole preceding run.

Typing glyphs gives the keys for typing superscripts and subscripts. For bare inverse ⁻, type Alt-6, -, then Space. Alt-6 then -1 gives ⁻¹, a negative power on numbers or a negative Rank on functions.

Superscripts

On an array

On a number or array, a superscript digit is a power:

x←3
≥x²
10

A power of ¯1, written ⁻¹, is the reciprocal:

2⁻¹
0.5

ᵀ swaps rows and columns:

m←[1 2
   3 4]
mᵀ
1 3
2 4

In 2 3², the superscript applies only to the 3:

2 3²
2 9

In [2 3]², it applies to the whole list:

[2 3]²
4 9

After a space, a superscript applies to the whole run on its left:

2 3 ²
4 9

The run can be any expression, such as ≥x:

≥x ²
16

In a strand of names, each name is a separate run, so x y ² applies ² only to y:

y←5
x y ²
3 25

A spaced superscript also needs a space after it:

2 3 ² + 1
5 10

On a function

On a function, numeric superscripts specify cell ranks: f¹ is f⍤1, f⁰ ¹ is f⍤[0 1], and f⁰ ¹ ² is f⍤[0 1 2]. Adjacent digits form one rank, so f¹² means rank 12. Spaces separate ranks. A negative rank counts back from the argument’s rank, so f⁻¹ works on cells with one fewer axis than the argument. Unlike ⍤, a superscript rank needs no separator before a numeric argument: -⁰5.

Here +/¹ sums each row of m, +⁰ ¹ adds one left scalar to each right row, and ⌽⁻¹ reverses each row:

+/¹m
10 20+⁰ ¹m
⌽⁻¹m
3 7
11 12
23 24
2 1
4 3

Bare f⁻ is the inverse of f, the same as f⍣¯1. The minus has no superscript digit immediately after it: f⁻¹ is rank ¯1, while f⁻ ¹ applies the inverse at rank 1. Use f⍣2 to repeat a function twice, because f² means rank 2.

f⁻ Y gives the X for which f X is Y. Inverses follow BQN’s specification of inferred properties. The inverse of the exponential * is the natural logarithm:

*⁻1
0

Monadic Encode ⊤ gives a number’s binary digits. Its inverse reads the digits back into a number:

⊤⁻1 0 1
5

In a dyadic call, X f⁻ Y is the Z for which X f Z is Y. The inverses of 2× and 2* are division by 2 and the base-2 logarithm:

2×⁻10
2*⁻8
5
3

Inverting Replicate puts fill where the mask has zeros:

1 0 1#⁻10 20
10 0 20

+\⁻ turns running sums back into the numbers they came from:

+\⁻1 3 6
1 2 3

The same goes for a derived function such as -¨:

-¨⁻1 2 3
¯1 ¯2 ¯3

A bound function such as 2↣× is inverted as a whole too:

2↣×⁻10
5

Numeric superscripts just after a number remain powers: +↢3⁻¹ adds a third. Bare +↢3⁻ would instead try to invert the number 3, which raises a DOMAIN error. To invert a function that ends in a number, put the function in parentheses:

(+↢3)⁻ 10
7

A space before the superscript applies it to the whole preceding run, so the parentheses can be left out:

+↢3 ⁻ 10
7

With the axis operator ⍠, the inverse can also go before it: #⁻⍠¯1 is the same function as (#⍠¯1)⁻.

Inverses follow the rules of ⍣. A function built with Atop, After, Before, a bound argument, Each, Rank, Commute or a scan has an inverse when its parts do. f⁻←g attaches g as the inverse of the function named by f.

Bitwise ᵇ is a monadic operator that applies a Boolean function to integer bits. For example, 6∧ᵇ3 is 2ₓ.

Unary ᵘ calls a function with its right argument alone: X fᵘ Y is f Y. For example, 10-ᵘ3 is ¯3.

A function as a scalar

fˢ is a scalar holding the function f, as ⊂ encloses a subject. ⊂ can’t enclose a function, because written next to one it forms a train. Power uses a function scalar as a stopping predicate. Like any scalar, +ˢ has an empty shape:

ρ+ˢ
⍬ₓ

Its depth counts the one layer around the function:

≡+ˢ
1ₓ

Errors

  • DOMAIN: a function with no known inverse, ᵀ on a function, or ˢ on an array
  • SYNTAX: a superscript after a space that doesn’t stand alone, as in 2 3 ²+1

Subscripts

On an array, a subscript selects a major cell. v₁ is 1⌷v:

v₁
20

A negative subscript counts from the end:

v₋₁
30

A single subscript selects a matrix row. Numeric subscripts separated by spaces form one coordinate: m₁ ₀ is m.[1 0]. Adjacent digits form one position: v₁₂ selects position 12. Parentheses keep sequential selections separate: (a₁)₂ selects item 2 of item 1:

m₁
m₁ ₀
3 4
3

After a dotted path, a subscript selects from the value at the end of that path:

T←["a":[10 20]]
T.a₁
20

With a space before it, a subscript selects from the whole run on its left:

2 3 ₁
3

As with a superscript, the run can be any expression:

≥v ₁
21

A spaced subscript also needs a space after it.

A subscripted item can be an assignment target:

v₁←5
v
10 5 30

Modified assignment works too:

v₁+←1
v
10 6 30

Use numeric subscripts for literal positions along successive axes. Use Index ⌷ or bracket indexing for computed positions, vectors of positions, keys or whole axes.

After a function, numeric subscripts choose axes, as Axis does. +/₀ is +/⍠0, and +/₀ ₁ is +/⍠[0 1]:

+/₀m
+/₀ ₁m
4 6
10

In f⁝x₁, the subscript indexes x before the call. (f⁝x)₁ indexes the call’s result. An array of functions is still an array: fs₁ selects its item 1.

The subscript letters ₓ, ⱼ, ₑ and ᵣ are parts of numbers, as in 3ₓ and 1ᵣ3. Numbers covers them. Between two items, ⱼ, ₑ and ᵣ form one number: xⱼy is x+y×0ⱼ1, xₑy is x×10*y, and xᵣy constructs a rational from integer components. A trailing ᵣ converts to the unbounded integer/rational domain: 3ᵣ means 3ᵣ1, and a result that is a whole number stays in that domain. ÷ on ordinary integers floors. ÷ᵣ gives the exact rational quotient of the same integers, and ÷ₐ gives a float. After a name or any other item except a number or a list of literals, ₓ floors the value to machine integers. xₓ is ⌊ₓx:

x←3.7 ¯2.5
xₓ
[3 ¯3]ₓ

After a function, ₓ floors its results to ordinary integers under either kinds setting. Numbers gives the static conversion rules.

÷ₓ floors the exact quotient as Python’s // does and gives an ordinary integer, as ¯32768ₓ₂÷ₓ¯1ₓ₂ gives 32768ₓ. ⌊ₓ, ⌈ₓ and ÷ₓ each compute their integers in one pass:

7 ¯7 7.5÷ₓ2
[3 ¯4 3]ₓ

The sized integer markers ₓ₁, ₓ₂, ₓ₄ and ₓ₈ give fixed-width integers occupying 1, 2, 4 or 8 bytes. All the digits after ₓ form the width, so ₓ₁₆ is invalid. Put parentheses around a conversion before indexing it, as in (vₓ₁)₂. Fixed-width integers gives the conversion and promotion rules.

After a function, a sized marker converts the function’s results:

√ₓ₁ 17
4ₓ₁

The float-width markers ₕ, ₛ and ₚ work the same way. After a function it makes the function’s results floats of that width, and after an array it converts the array, as •float does:

-ₛ 3
xₛ
¯3ₛ
[3.7 ¯2.5]ₛ

ₐ (approximate) converts values to real floats. After an array, ₐ takes a complex number’s real part at the width of its parts, converts an exact number or a Boolean to a float of the default width, and keeps a float’s width:

(3j4)ₐ
1r3ₐ
3
0.3333333333

After a pervasive function other than √, ⊛, *, ○ and ○⁻, ₐ converts the arguments to real floats before the call, taking each complex argument’s real part: !ₐ25ₓ computes in floats rather than in overflowing integers. The floats have the width that the arguments’ float promotion gives, which never depends on their values. After a function that isn’t pervasive, such as ≢, ₐ converts the results. ÷ₐ selects float division before computing, rather than converting a floored integer quotient. After √, ⊛, *, ○ or ○⁻, ₐ gives the real part of the principal value, including when the result is outside the real domain. √ₐ¯4 is 0, the real part of 0j2. ¯8*ₐ÷3 is 1, the real part of the principal root 1+i√3. √ₐ, ⊛ₐ and *ₐ each run as one kernel. Under ∂, their slopes are the slopes of their real parts. Numbers gives the rules:

√ₐ¯4 9
¯8*ₐ÷3
0 3
1

Errors

  • SYNTAX: a subscript after a space that doesn’t stand alone, as in 2 3 ₁+1, or that is an assignment target, as in v ₁←5
  • SYNTAX: ₋ with no digit after it
  • SYNTAX: ⱼ or ₑ beside a function or a space, as in f←- ◇ fⱼ1
  • INDEX: the item is a unit, which has no axis to select from
  • DOMAIN: ₓ on a complex number

Differences from APL

BPL also accepts Dyalog’s x*2, f⍣2 and f⍣¯1. BQN writes the inverse as 𝔽⁼. Neither language has subscripts.