Superscripts and subscripts

Marks after a token that apply an operation to it or select from it

A superscript, such as ², is a mark written straight after a token that applies an operation to it. A subscript, such as ₁, selects from it instead. Both bind more tightly than any function. v₁² is the square of item 1 of v:

v←10 20 30
v₁²
400

Typing glyphs gives their keys.

Superscripts

On an array

On an 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 touches only the 3:

2 3²
2 9

In [2 3]², it touches 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

A strand of names is several runs, one for each name:

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, a superscript digit is a repeat count, as in Power. f² is f⍣2:

inc←≥
inc² 5
7

f⁻¹ is the inverse of f, the same as f⍣¯1. 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

A superscript applies to the whole function on its left, as a monadic operator does. +\⁻¹ 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↣× inverts as a whole too:

2↣×⁻¹10
5

A superscript just after a number applies to the number, as a power. Without parentheses, +↢3⁻¹ adds a third. To invert a function that ends in a number, put the function in parentheses:

(+↢3)⁻¹ 10
7

A space before the superscript also works:

+↢3 ⁻¹ 10
7

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

Inverses follow the rules of Power. They pass through bound arguments, Each, Rank and the other compositions that Power lists. f⁻¹←g attaches an inverse to any function that a name holds.

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

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. 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

A subscript selects a major cell of the item just before it. v₁ is 1⌷v:

v₁
20

A negative subscript counts from the end:

v₋₁
30

On a matrix, a subscript selects a row:

m₁
3 4

After a dotted path, a subscript selects from the whole 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 a subscript for one literal position on the leading axis. Use Index, ⌷, for a computed position, several positions, a key or another axis.

The subscript letters ₓ, ⱼ, ₑ and ᵣ are parts of numbers, as in 3ₓ and 1ᵣ3. Numbers covers them. Between two other items, such as names, ⱼ, ₑ and ᵣ join the items into one number: xⱼy is x+y×0ⱼ1, and xᵣy is the exact quotient of xₓ by yₓ, under static kinds too. After a name, or any item but a number or a list of literals, ₓ floors the item’s numbers to exact 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.

⌊ₓ, ⌈ₓ and dyadic ÷ₓ, which divides and floors as Python’s // does, each compute their integers in one pass:

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

The sized integer markers ₓ₁, ₓ₂, ₓ₄ and ₓ₈ give fixed integers occupying 1, 2, 4 or 8 bytes. The full digit run after ₓ is the width: ₓ₁₆ is invalid. Parenthesize a conversion before indexing, 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ₓ₁

A float width’s marker, ₕ, ₛ or ₚ, works 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]ₛ

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 position is outside the leading axis
  • LENGTH: the item is a unit, which has no axis to select from
  • DOMAIN: ₓ on a complex number, or under dynamic kinds on an infinity or NaN, as in 1÷ₓ0

Differences from APL

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