notation
How text is read and printed: operators, abbreviations, default values, steps read through theorems
Overview
notation("kind", …) collects everything that changes only how the text is read: writing atoms as operators, names for formulas, the default right-hand side of a statement, and which theorems a step of a proof — a call that removes a quantifier, generalize, deduce, witness, obtain, a hint by a fact of a relation — is read as calling. A notation never makes anything true.
notation("infixl" | "infixr" | "infix" | "prefix" | "postfix", operatorAtomNames, precedenceInteger)notation("abbreviation", abbreviationName := expression)notation("default", defaultExpressions)notation("alias", shortName := Namespace.Prefix)notation("apply" | applyTheorem) notation("generalize" | generalizeTheorem)notation("deduce" | deduceTheorem) notation("witness" | witnessTheorem) notation("obtain" | obtainTheorem1, …)notation("hint" | rewriteTheorem, rewriteBackTheorem, reflexiveTheorem)kind- What the notation is: an operator (
infixl,infixr,infix,prefix,postfix), a name for a formula (abbreviation), the default right side of statements (default), a short name for a namespace (alias). operatorAtomNames- Atoms (comma-separated) to write as operators — two-argument for infix kinds, one-argument for prefix and postfix. Infix operators need spaces around them:
a ∘ b. precedenceInteger- The binding strength, as in Lean: a higher number binds tighter (
+65,×70,=50,¬40, postfix 1024). abbreviationName, expression- The name and the formula it stands for; a function is written as a constructor
{x: T | e}. See below. defaultExpressions- Values, at most one per type: a statement without
->inif/axiomgets the value of its type. See below. shortName, Namespace.Prefix- Write
shortName.xforNamespace.Prefix.x. See below. | theorems- For a step: the labels of the theorems the step calls. The quantifier, implication or relation and its values are read from their forms. See below.
Command Properties
- Group
- Transparent headers
- Produces
- Nothing; no label can be put on it
- Creates scope
- Operators — wherever the atom is visible, from this point on; abbreviations and default values — in the enclosing block after the command
- Mechanism
- A transparent header: it can stand in a chain (
for(∘: [G, G -> G]) notation("infixl", ∘, 70) if(…) { … }) or end with;
Basic examples
Any visible atom of two arguments can be written between its arguments, and an atom of one argument before or after it. notation("infixl", ∘, 70) makes a ∘ b ∘ c mean ∘(∘(a, b), c); statements are then also printed this way, with parentheses only where they are needed. The notation is pure syntax: the parser turns a ∘ b into ∘(a, b), so proofs, the journal and the independent checker do not change. The prefix form ∘(a, b) stays valid, and an operator can still be passed as an argument: f(=, x).
notation("infixl", ∘, 70) // left-associative: a ∘ b ∘ c = (a ∘ b) ∘ cnotation("infixr", ⇒, 25) // right-associative: a ⇒ b ⇒ c = a ⇒ (b ⇒ c)notation("infix", =, 50) // non-associative: a = b = c is an errornotation("prefix", ¬, 40) // ¬ anotation("postfix", ⁻¹, 1024) // a⁻¹notation("infixl", ∪, ➕, 65) // several operatorAtomNames with the same fixityCommand Properties
- Group
- Transparent headers
- Produces
- Nothing; the atoms are written as operators wherever they are visible, from this point on
- Mechanism
- The expression parser reads operators by precedence (Pratt parsing) and passes the prefix form to the core parser.
Spaces
An operator is separated by spaces, as in Agda: a ∘ b is three names, a∘b is a single name. This keeps names like L➕1 or ∀𝔹 intact and lets an editor split the text into tokens without knowing the declarations. Parentheses need no spaces: (a ∘ b) ∘ c, ¬(a ∧ b).
Prefix and postfix operators may be glued to their operand: a⁻¹, ¬¬p, −a!, f(x)⁻¹⁻¹. A name that is not a visible atom is split into prefixes, a core and postfixes; the core is a visible atom without notation or a bound variable, and the result is parsed by precedence as if spaces were there. The split happens only where the name would otherwise be unknown: a declared atom a⁻¹ stays one name. If a name splits in more than one way (postfixes ! and !!, text a!!!) it is an error, and spaces decide. Infix operators are never split. The interpreter prints a prefix or postfix glued — a⁻¹, −ε, n!, (a ∘ b)⁻¹, ¬¬p — when the glued text reads back the same: the operand has no spaces outside parentheses (otherwise ¬ ι(p) ≤ x would look like (¬ι(p)) ≤ x), the glued piece is not a visible atom, it splits in exactly one way, and the junction does not spell another operator of the same kind (with an atom c! and postfixes !, !! the term c! ! is not printed c!!). Otherwise it keeps the space: a !!. Infix operators are always printed with spaces.
Precedence
The precedence is an integer 0–1024; the greater binds tighter. The scale is the one of Lean 4 and Isabelle, so that the same numbers can be used: ⇔ 20, ⇒ 25, ∨ 30, ∧ 35, ¬ 40, = ∈ ⊂ 50, ∪ + 65, ∩ * 70, ^ 75, ⁻¹ 1024. Application f(x) binds tighter than any operator. A prefix operator takes as its operand everything that binds at least as tight as itself: with ¬ 40, ¬ a ∧ b is (¬ a) ∧ b and ¬ a = b is ¬ (a = b), as in Lean.
Example
A group in operator notation
The library of the repository (tests/08_corpus/library) is written this way: in its expressions there are 2.5 times fewer parentheses than in the prefix form, and the proved statements are exactly the same.
Details
None of it is logic — the core, the journal and the independent checker never see it. That is why notation is transparent: it may stand in a chain of headers or end with ;, but unlike rule, type, lock, for and if it is not a context — calls pass through it, and theorems get no parameters or conditions from it. Rules of logic, which generate axiom schemes and are part of what you trust, are declared separately with rule.
Steps read through theorems: notation("apply" | …), notation("hint" | …)
A call on a fact H[a] removes a quantifier, a fact a = b rewrites a to b. Neither step is built into the language: each is a call of a theorem, and the file says which. notation("apply" | A∀Apply) reads «a call removes ∀ through A∀Apply»; the quantifier ∀ and the values come from the form of the theorem, not from arguments. The declaration states nothing, so it is a notation, not a rule: a theorem of another form is an error that names it. The other steps name their theorem themselves: the introduction of a quantifier or an implication, the elimination of an existential and the closing of an assumption are calls that take the blocks their proof stands in — generalize[| H], deduce[| H], obtain[| H], witness[t | L], contradict[| H] (logic/quantifiers.fl, logic/propositional.fl, logic/bool.fl); nothing is generated (Command Reducibility).
| Notation | The theorem | The step it reads |
|---|---|---|
notation("apply" | Apply) | p(x…) -> c under if(Q(p) -> d), over p, x… | H[a] on a fact Q(p) -> d: p(a) -> c; a hint <e | H> by such a fact |
notation("hint" | Rewrite, RewriteBack, Reflexive) | a -> b and b -> a under if(R(a, b) -> v); R(x, x) -> v | a fact R(l, r) -> v as a hint (notation("hint")) |
The steps of a theory named by its own theorems
The library (logic/quantifiers.fl, logic/propositional.fl, logic/equality.fl) is written this way: notation("apply" | A∀Apply), notation("hint" | A=Rewrite, L=RewriteBack, A=Reflexive), and the calls generalize[| H], deduce[| H], obtain[| H], witness[t | L]. Its only rules are rule("define", ∃!, ✔) and rule("bijective", …).
A theorem of the wrong form
Without the condition ∀(p) -> true the axiom would say p(x) -> true for every p, much more than Apply, so the notation refuses it.
Expected error: notation("apply"): the theorem 'Wrong' must lie under one if(Q(p) -> d), Q a quantifier
Abbreviations: notation("abbreviation")
Long formulas often repeat: "t is empty" is ∀{z: set | not(in(z, t))}, written a hundred times in a proof. notation("abbreviation", empty := {t: set | ∀{z: set | not(in(z, t))}}) gives it a name. Wherever empty(x) is written afterwards, the parser puts the expression in its place (the lambda is applied to the arguments, with fresh bound variables). No atom and no axiom appear: statements are exactly the same as with the formula written out, so nothing has to be unfolded in proofs. This is abbreviation in Isabelle and notation in Lean. Unlike define, which introduces a new atom with a defining theorem, an abbreviation is pure syntax.
notation("abbreviation", abbreviationName := {boundAtomName: type | expression});notation("abbreviation", abbreviationName := expression);abbreviationName- The new name:
name(a)(or justnamefor a term) is replaced by the formula while the text is read. {boundAtomName: type | expression}- A formula with arguments: the bound atoms are its parameters, the expression its body. A formula without arguments is written as an expression.
Command Properties
- Group
- Transparent headers
- Produces
- Nothing; the name is visible in the enclosing block after the command, like an atom declared by
for - Mechanism
- Expanded by the expression parser:
name(a)becomes the lambda applied toaand is β-reduced. Statements are printed expanded.
Example
Naming a formula
In library/sets/pairs.fl of the repository two abbreviations replaced 169 occurrences of these formulas: the file became a quarter shorter, and its statements did not change.
Printing folds abbreviations back. The checker sees only the expanded formula, but statements, messages and show print it with the name: an expression that matches the body of a visible abbreviation is printed as name(arguments), as Isabelle prints abbreviations. A parameter-function applied to bound variables is matched as a Miller pattern: with notation("abbreviation", everywhere := {f: [T -> T] | ∀{i: T | p(f(i))}}) the formula ∀{i: T | p(g(i))} prints as everywhere(g) and ∀{i: T | p(g(s(i)))} as everywhere{i: T | g(s(i))}. An abbreviation declared in a block folds only inside that block. The interpreter flag --no-fold prints everything expanded.
An abbreviation written as an operator
An abbreviation of one or two arguments can be given an operator notation like an atom. Strict order defined
through ≤ is the typical case: a < b is then literally ¬ b ≤ a, so
decide and the rules see through it, and no lemmas «from < to
¬ ≤ and back» are needed. With define instead, a < b would be a new atom and
every passage between the two forms a rewriting by the definition.
Strict order as an abbreviation
Statements are printed with the abbreviation expanded: ¬ z ≤ x -> true. In the real numbers and limits of the repository (library/reals/, library/analysis/) this replaced two lemmas and 25 of their uses.
Default values: notation("default")
Most assumptions and axioms say that something is true: if(x ∘ y = e -> true). notation("default", true) lets you write just if(x ∘ y = e): in if and axiom a statement without -> gets the default value of its own type as the right-hand side.
notation("default", defaultExpression1, defaultExpression2, …)defaultExpression1, …- One value per type (
✔;true, ∅): the right side given to a statement of that type written without->.
- Each value is the default of its type, at most one per type in one block:
notation("default", true, ∅)makesif(p)meanp -> trueforp: boolandif(a ∪ b)meana ∪ b -> ∅for sets. - It acts in the enclosing block after the command; the nearest declaration with a value of the type wins.
- It is notation only: the statement is
P -> true, and it is printed that way. - The arrow is searched up to the end of its group, so lists keep their meaning:
if(p, q -> r)is stillp -> randq -> r, whileif(p -> r; q)isp -> randq -> true. - Without a default value of the type a statement without
->is an error.
In the repository library the rule stands next to the booleans, in logic/bool.fl: notation("default", ✔).
Example
Assumptions without -> true
Commands that check statements, such as expect(), are not affected: there a string without an arrow already means «the statement with this left-hand side».
Short names for namespaces: notation("alias")
Nested namespaces make long names: a construction imported as
Reals that itself imports pairs as PairClasses and classes as Classes gives the type
Reals.PairClasses.Classes.Class. notation("alias", R := Reals.PairClasses.Classes) lets the
file write R.Class, R.classEmbed, R.SomeTheorem instead — for types, atoms and labels,
in code and inside strings — like import … as R in Python.
notation("alias", shortName := Namespace.Prefix)shortName- The short prefix to write (
R). Namespace.Prefix- The long prefix it stands for — a namespace of an import, possibly nested (
Reals.PairClasses.Classes).
- The alias is expanded while the text is read:
R.xis the nameReals.PairClasses.Classes.x. Statements, the journal and the output show the full names. - It belongs to this file: imported files and files importing this one do not see it. Inside the file it acts in the enclosing block after the command, like an abbreviation.
- The prefix must have visible names, and the short name must not already be a visible namespace.
- The first argument of
import, the file path, is left as written; the substitution string of an interpretation may use the alias.
import("real_numbers.fl");
notation("alias", R := Reals.PairClasses.Classes);
import(RealSpace := "../../geometry/coordinates/space.fl", Number := R.Class, + := Reals.⊕, …);
for(a: R.Class) { … }
In the repository library: sets/numbers/real_numbers.fl, sets/constructions/*.fl
(C for PairClasses.Classes). A block that opens a namespace, so that its names need no prefix
at all, is not part of the language.