Skip to content

8.2) Metapredicates

Julien Cumin edited this page Jan 24, 2022 · 24 revisions

Metapredicates are built-in predicates that are applied on predicates. They are represented by superscript letters and directly follow the predicate on which you want to apply them.

Just like built-in predicates, metapredicates also have an additional parameter called the superscript that directly follows the metapredicate name. It can either be a series of superscript digits or one of and to indicate that the first/last element of the input must be used as superscript (like built-in predicates and subscripts).

For example, the code pᶠ⁴² can be read as "find the first 42 permutations of the input".

Metapredicates can be applied to inline predicates and predicate compositions as well. For example {p}ᶠ⁴² would work as well.

Superscript arrow

You can use the subscript arrow to pass the immediately following variable as a superscript to a metapredicate (like and , in a shorter way that does not require the input to contain that variable).

For example, 13+₁ⁱ↖7 will output 20.

Note that if you want to use both subscript and superscript arrows, they must both be used after the predicate and metapredicate combo.

For example, 13+ⁱ↙2↖7 or 13+ⁱ↖7↙2 will output 27.

List of built-in metapredicates

Symbol Name Superscript Description
Accumulate Default = 1
I
Same as but the Input at each step is the list of accumulated results.
Bagof Default
I
Same as but uses bagof instead of findall under the hood
Count Default = 0
1
Count all outputs of the predicate for ?
Count all unique outputs of the predicate for ?
Declare Default
0
1
2
? = [A,B], . = B, call the pred. with A as input and B as output
? = . = [A,B], call the pred. with A as input and B as output
? = [A,B], . = A, call the pred. with B as input and A as output
? = . = [A,B], call the pred. with B as input and A as output
Existence Default
I
The output of the pred. for at least one element of ? is .
The output of the pred. for at least one element of ? = . is I
Find Default
I
Find all outputs of the predicate for ?
Find the first I outputs of the predicate for ?
Group by Default Groups elements of ? together into . if they generate the same output to the predicate.
ʰ Head Default = 1
I
Apply the predicate only to the head of ?
Apply the predicate only to the first I elements of ?
Iterate Default
I
Same as with superscript I with I > 0 not set
Apply I times the predicate to ?
ʲ Default
Default
ˡ Left fold Default . is the left fold of the predicate on ?
Map Default = 1
I
Map the predicate to each element of ?
Nested map I times on ?
Nonexistence Default
I
The output of the pred. for each element of ? is never .
The output of the pred. for each element of ? = . is never I
Order by Default = 0
1
2
3
. is ? ordered asc. by mapping the predicate
. is ? ordered desc. by mapping the predicate
Same as 0 but . contains the elements of the map
Same as 1 but . contains the elements of the map
Default
ʳ Right fold Default Not implemented
ˢ Select Default Find outputs of the predicate for each element of ?
Tail Default = 1
I
Apply the predicate only to the tail of ?
Apply the predicate only to the last I elements of ?
Unique Default
I
Find all unique outputs of the pred. for ?
Find the first I unique outputs of the pred. for ?
Verify Default
I
The output of the pred. for each element of ? is always .
The output of the pred. for each element of ? = . is always I
ʷ Default
ˣ Default
ʸ Default
Zip Default
0
1
2
Zip the input with the result of on the pred.
Zip the input with the result of on the pred.
Zip the result of on the pred. with the input
Zip the result of on the pred. with the input