Calls T[…]
Applying a theorem or a fact to concrete values
Overview
A call T[a, b | J] applies a proved statement where it is needed. Before the bar come the values of its parameters, after it the proofs it rests on — facts for its conditions and realizations of its lock axioms. T is a label, the result of a command (decide(X)[n]), a proof (<…>[x]) or another call (T[b][a]). The result is the instance of each statement of T, delivered into the current scope.
theoremLabel[]theoremLabel[| factLabel1, factLabel2, …]theoremLabel[argumentExpression1, argumentExpression2, … | factLabel1, …]theoremLabel[parameterName := argumentExpression, … | factLabel1, …]theoremLabel[argumentExpression1, …; | factLabel1, …;]theoremLabel- The theorem: a label whose statements are its conclusions. Everything between a statement and the place where the label is declared is the theorem's contract:
foratoms andtypeparameters to substitute,ifconditions to meet, locks whose axioms need realizations — among them the schemas of the rules the theorem was proved under (below). Also the result of a command, a proof or a call. factLabel1, …- Optional: facts for the theorem's
ifconditions and realizations of its lock axioms — labels, or what gives statements in place: a proofT[| <… |>], a command, a call. Each must be used by some condition or axiom. Conditions not given are met by visible facts;;at the end — only these. argumentExpression1, …- Optional: values of the theorem's parameters in their order — its
foratoms from the first (_skips an atom, which is then inferred), then the quantifiers of its conclusion. Positional values take the parameters not given by name. parameterName := …- Optional, mixed with positional values in any order: values by name — an atom of the theorem's
for(x := S(0)) or a type parameter (D := nat). Every atom not given is inferred from the conditions and facts (an atom that is itself in scope at the call stays itself, implicit);;after the values — all are given, none is inferred.
Properties
- Produces
- Statements (the theorem instantiated with concrete values)
- Delivery & Label
- Into the current scope. A label on the call (
R: T[a]) holds the instantiated statements at this scope. - Creates scope
- No.
- Mechanism
- Walks the path from each theorem statement's definition scope up to the label's declaration scope. Along this path:
•fornodes: collects declared atoms; these are substituted with the given expressions (by name or by position, types must agree). Atoms not given are inferred from the theorem'sifconditions, facts and realizations; an atom that is itself in scope at the call is implicit — it stays itself; another atom of the same name is never taken
•ifnodes: checks that each assumption (with atoms substituted) holds as a statement in the current scope
•type()nodes: collects declared type parameters; they are given by name (D := nat) or inferred from the types of the atom arguments
•rulenodes: a rule is its schemas, axioms of its lock (Apply, Distinct, …); they are realized like the axioms of any lock, by labels passed to the call — the label of the declaration holds its schemas (Rules on the theorem's path)
•lock()nodes: for each axiom registered in the lock, finds a realization among the labels passed to the call by comparing signatures — the lists offor,ifandruleconditions surrounding the axiom in the theorem and the realization, respectively. See Lock axioms: signature matching below.
Every label passed must be used: one of its statements satisfies a condition or realizes an axiom. In the journal of the interpreter and in the source map of the certificate the step is namedcall.
Basic examples
Call a theorem with values for the atoms of its for:
Applying a theorem
Details
The parameters of a statement are what lies between it and the declaration of its label: the atoms of for and the types of type() to substitute, the conditions of if to meet, the locks whose axioms need realizations — then the quantifiers of its conclusion. A theorem proved inside for(x: T) is called on values of x; a quantified fact ∀{x: T | P} -> true has no for of its own and is called on values of its quantifier (calls on facts). It is the one way to use what was proved: from the call of a lemma to the instance of an axiom of a theory at another structure.
Locks make a call more than substitution: a theorem proved under axioms can only be applied where those axioms are honestly supplied. The bulk of this page, from Lock axioms: signature matching onward, explains exactly how realizations are checked.
Arguments inferred from conditions and facts
Most arguments would only repeat formulas already written in the statements the theorem needs, so they are inferred. Each if condition of the theorem becomes a pattern whose unknowns are the atoms not given, and it is matched against the statements visible at the call. Matching is first-order with two higher-order cases: an atom-function applied to bound variables, like p(x) inside {x: nat | …}, receives a lambda (a Miller pattern); an atom-function applied to a term with bound variables, like
P(ι(n)) inside ∀{n: ℕℝ | …}, receives the lambda in which every occurrence of that term is
replaced by its variable — the only solution, since P cannot see n (if n remains
elsewhere, there is none); otherwise p(a, b) against h(c, d) takes p := h. The instantiation is printed in the log (// Arguments: P := A (inferred), Q := B) and then checked as usual.
When the conditions can be satisfied in several ways that give different results, shadowing decides, as in a proof: the later and the inner hide the earlier and the outer. A fact of a label passed to the call comes first, then the statements of the current block from its end, then the enclosing blocks outward. One instantiation shadows another when each of its conditions is met by the same or a nearer statement, and at least one by a nearer one; so closed facts at the top level of an imported module, or of the model in an interpretation, do not disturb inference inside a proof. If the instantiations no one shadows give different results — each is nearer in one condition and farther in another — the call stops with an error showing two of them. The names of the theorem's parameters play no part: with if(P(A)) if(P(B)) at the call, both conditions P(A), P(B) of a uniqueness theorem take the nearer P(B), and the visible A, B are passed as arguments. A label passed to the call is used first — a condition that one of its statements fits is matched only against the label, and every solution must use every label. A condition whose left side is a bare atom (P -> true) fits almost any statement; a fact label or P := … settles it. Inference only chooses the instantiation; soundness does not depend on it, because all conditions, rules and lock axioms are checked afterwards.
Inferred arguments and a fact label
Implicit atoms and type inference
A theorem whose label is declared above a type() and its for atoms is generic: it can be applied to any type. Its outer atoms work like the variables of a Lean section: inside the theory they are the very atoms in scope and stay themselves; elsewhere they are inferred from the conditions, the facts and the realizations given, or written (f := g, or in order), and the types are inferred by matching. An atom of the call site is never taken for a parameter because it has the same name: the names of a lemma's own parameters (P, Q, a) are short and common, and a Q: 𝕊 in scope is not the Q: 𝔹 of the lemma. What the conditions do not determine is written. All conditions of the theorem are checked as usual.
Implicit atoms and inferred type
The full forms Twice[f, zero] and Twice[f := f, x := zero, D := nat] mean the same.
An atom of the same name is not taken
The last call has no condition to infer a and b from, and the atoms a, b of its for are other atoms than the theorem's: they are written, Swap[a, b].
Expected error: Cannot infer argument 'a: nat
Closing a side with ;
Both sides of a call follow one rule: what is written is taken, and whatever the theorem still needs is found by itself — the values of its atoms from its conditions, the facts for its conditions among the visible statements. A ; at the end of a side says «that is all»: nothing on that side is found, and what is missing is an error, not a search.
T[a, b; | …]— everyforatom of the theorem is given, by position or by name; none is inferred or taken by name from the call site. Types still follow from the values. The constants of a definition move with their definition and are not given.T[… | H, G;]— the conditions of the theorem are met only by the facts ofHandG; a visible fact that would meet one is named in the error. Lock axioms are realized only by the proofs written in any case; a lock already in force at the call site, with its axioms unchanged, is the context, not a fact.
Closing never changes what is proved: it only narrows where the call looks. A call that passes closed passes open with the same result. Use it where the visible facts are many or contradict each other, and where a reader should see every premise in the text. The same ; closes decide, and a hint by a theorem closes inside its call: <e | T[| H;]>. Inference and what it chose are printed in the log either way.
Closed sides of a call
The last call is closed by ;: its condition P -> true at P := A is visible, but not given.
Expected error: The proofs of the call are closed by ';', and none of them meets the condition
Strictness for a whole file: --explicit
A project that wants every premise in its text runs the interpreter with --explicit. Then every call is checked as if both its sides ended with ;, every decide takes only the facts written after |, and every rewrite of a proof names its hint (<e | H>, a hint by a theorem as a call with its values and proofs). The errors name the visible fact that was found and the label to write for it. The option only forbids: a text it accepts means the same without it, because a call that gets everything written finds nothing else — the proofs written come first, and the values written are not inferred. So a strict file needs no ; anywhere, and it reads the same in any project. The option checks the text of the file itself, not the text that commands write (the proofs of decide, the schemas of rules) and not its modules.
Theorem with Conditions
When the theorem lies under an if, the call checks that the condition, with the values substituted, holds in the current scope:
Theorem with conditions
A call without arguments
If the theorem has no for atoms of its own, the call has no values: T[]. The theorem's if conditions are still checked in the current scope. (T[] is not T: the bare label stands for its statements as they are, where they were proved.)
This means you can prove something once and reuse it in any scope where the same condition holds — regardless of how you arrived there:
A call without arguments
The theorem AndImpliesOr is proved once. Then AndImpliesOr[] is called in two different scopes — each arrives at and(P, Q) -> true by a different route, but the theorem applies in both without repeating the proof. With for atoms the same call instantiates the theorem at any concrete values too.
A label of several theorems
A label may hold several theorems. A call applies each of them that the arguments and the labels fit here, and skips the others — the log says why each was skipped. At least one must apply; otherwise the error lists the reason for each theorem. The same rule holds for every place that takes a label: a hint tries all statements of its label and takes their result, if they agree.
Only the fitting theorems apply
Arguments for the quantifiers of the conclusion
The parameters of a theorem are its for atoms, then the quantifiers of its conclusion — those the theorem of a visible notation("apply" | …) removes. Values after the for atoms go to the quantifiers, outermost first: T[f, n] for a theorem T over f whose conclusion is ∀{n: ℕ | …} -> true states the instance at n at once (the chain T[f][n] — a call on the result of a call — gives the same: calls are curried), and delivers only that statement. A fact is a statement without for atoms, so H[a] on a quantified fact H is its instance at a (below). A quantifier always takes its value explicitly and by position: the name of a bound variable belongs to the formula, not to the call.
A theorem applied at the quantifiers of its conclusion
Calls on facts
A fact ∀{x: ℕ | P(x)} -> ✔ has no for atoms of its own, so its parameters are the quantifiers of its conclusion: H[c] is its instance P(c) -> ✔. The quantifier is removed by a visible rule("apply", ∀, ✔, ✔) — the rule says which atom is a quantifier and that its value ✔ carries over to the instance. The values go to the bound atoms in their order: as many as the quantifier binds at once, or more for nested quantifiers over one atom each — H[a, b] on ∀{x | ∀{y | P}} removes both. Their types fix the type variables of a polymorphic statement. A quantified fact can also be used without a call, as a hint of a proof.
A call on an axiom
Two quantified atoms
A value may be any expression of the bound atom's type, a lambda among them:
A lambda as the value
A call on a fact removes the quantifier through the theorem named by notation("apply" | A∀Apply) visible at the call: the nearest declaration for the quantifier and value is taken.
Realizations: labels for lock axioms
When a theorem uses lock() with axioms, the caller must supply a realization of each axiom — a proof that the axiom's conclusion holds in the current context. The label holding that proof is passed after the theorem, like a fact.
The realization lives outside the lock, in the calling scope, and is passed after the bar by name.
A realization passed to a call
AxiomAB is the realization: it proves that A -> false leads to B -> true in this specific context. Passing AxiomAB after the bar tells the call to use it as the realization for axiom AxiomPQ inside the lock. The same theorem FastOr can be applied with a different realization label in a different context.
A realization also tells the values of the parameters, as a fact tells them through a condition. The axiom is a pattern: its own for atoms are matched, in order, with the realization's own atoms as bound variables, and its own if conditions with the realization's, so a parameter applied to them is a Miller pattern — an axiom P(S(n)) -> true against a step proved for c gives P the lambda over c. A value is taken only when every match that gives it agrees. A lambda that only applies an atom to its own variables is that atom: {x, y: T | q(x, y)} gives q. The realization is then checked as before.
Values from the realization
A block of proof in an argument
After | a proof may be a block: headers for(…), if(…), type(…) and one statement, T[| for (y: T) S]. It proves what a label declared before the call and defined inside the block would hold — +B; for (y: T) B: S; — a theorem over y, or under the condition of the if. Nothing it proves enters the block of the call. So a lemma whose lock axiom has its own for or if is a command of its own: the block is its argument, and the result stands where the call is, outside the block's headers — as generalize stands outside its for and contradict outside its if.
A command of one's own with blocks as arguments
The values Q := a, P := a ∨ ¬a are inferred from the realizations: the blocks are theorems under a and under a -> ❌.
A call that leaves its blocks
The library names such lemmas by the step they make, in lowercase: contradict, generalize,
deduce, obtain, witness, refute. A command is word(…),
a theorem word[…]; the call reads as the step.
A lock axiom asks for a proof with blocks of its own: generalize asks for p(x) -> ✔ under for (x), deduce for Q -> ✔ under if (P), the library's obtain for a statement under for (x) if (p(x)). A proof written at a point inside such blocks — a label declared where it is defined, or a proof written in the call — is taken with the blocks it stands in, as many as the axiom asks for, and the call then stands above them: its result lies outside the for or if, which the step discharged. This is how the library introduces a quantifier (generalize[| H]), an implication (deduce[| H]) or eliminates an existential (obtain[| H]) — the commands generalize, deduce and obtain are these calls (step 189б). A label declared outside the block it is defined in holds that block (labels): the blocks it holds count too, and the call stands at the label's place.
Quantifier and implication introduced by calls
The reading with the blocks comes first: the call stands as high as it can. When the axiom's obligations cannot be met that way, the call is read as written, in its own block. Without a proof given (contradict[] inside if (Q)), the call takes the blocks it stands in itself and looks for the obligations among the facts there.
Three rules shape the result:
- Where the result stands. At the exit, above the blocks taken — when the call is written inside them. A call written beside them, in a block of its own under the exit (
if (q -> ❌) F: obtain[…, q | G]beside theforthatGleaves), keeps its result at its own place, wherecontradictcan then close thatif. - Which blocks are taken. As many as the axiom's own shape asks for, counted from the proof outwards:
foratoms andifhypotheses, never alock,typeorrule. Several atoms of oneforat once: the library'sgeneralize2 … generalize8(logic/quantifiers.fl), the quantifiers nested in the order of the atoms, each with a type of its own. - Names of the variables. A quantifier variable the theorem applies the predicate to takes the predicate's own name:
generalize2[| S]underfor (a, b)states∀{a, b | …}, not the lemma's∀{x1, x2 | …}; a name already used elsewhere in the statement is not taken, and a variable the inference invented for a term that is no atom gives no name.
Rules on the theorem's path
A theorem proved inside an enumeration type(T = a | b) or rule("bijective", f) rests on their schemas — Distinct, Cases, Injective, Column: the declaration generates them as axioms of a lock (enumerated types, rule("bijective")). Outside, they are realized like any lock axioms: the call is given the labels that realize them. Usually these are the schemas of the same kind of declaration at the call site; any statement of the same form will do — an axiom of the caller's lock, a proved theorem. A call never takes a schema by itself. The same holds for an enumeration replaced by an enumeration of the call site: its schemas of distinct values and of cases are given by a label.
The schemas have no names of their own: the language names nothing. A label on the declaration holds all the schemas it generates — a package, +ColorSchemas: type(Color = red | green) or +ABijective: rule("bijective", color) — and the call takes from a given package the schema each axiom needs. Two schemas of a package that both fit would be an error, as two fitting facts are; the schemas of one declaration never do. The axioms of a quantifier are ordinary axioms of a lock the file writes (A∀Apply, generalize of logic/quantifiers.fl): a theorem proved under them is called under the same lock, or realizes them like any lock axioms.
A rule's schema realized by the call site's rule
R is the call H[x] on a quantified fact, so it rests on the Apply schema of the rule for Q. The call site declares the same rule for G; the label GSchemas on it holds its schemas and is passed to the call like any realization. Without it the call stops with “Axiom realization not found”.
…or by any statement of the same form
No rule at the call site: the axiom GApply of the caller's own lock states the schema for G, for every predicate p, and realizes it. An axiom about one predicate only would not: the schema is about all of them.
Lock axioms: signature matching
The simple case shown above — one axiom realized by one search label — hides what a call actually checks when locks are involved. This section spells out the rule precisely. It matters when realizations contain if, for, nested locks, or when the theorem's lock axioms have their own surrounding conditions.
Which locks require realizations
Only locks that lie on the theorem's path — the parent chain from the theorem statement's definition point up to the scope where the theorem label was declared — oblige the caller. Each axiom of each such lock needs a realization. Locks that merely exist nearby — siblings of the theorem statement, locks in other branches of the tree — do not participate: the theorem was not proved under their axioms, so the call ignores them.
Sibling lock off the path
The lock L sits next to the theorem statement, not above it. The path of T runs from its axiom command through for(a, c) up to the scope where T is declared, inside Scope - it crosses neither L nor Scope, so the call needs no realization at all. A realization label passed here would be an error: every label given to a call must be used.
The signature of a path
Every statement in Formall — a theorem statement, a lock axiom, a realization — sits at some place in the tree, and has a path from that place up to where its label was declared. Along this path, three kinds of blocks add to the local world:
forblocks introduce atoms;ifblocks introduce conditions;typeblocks introduce types;ruleblocks (define,bijective) introduce rules.
The signature of a path is the multiset of these contributions across the path, organized by category. The order in which if and rule commands appear inside a single category does not matter — they are conjunctive — and neither does the relative order of for blocks of different types. What does matter is the order of for-atoms of the same type (used positionally) and the total number of contributions in each category.
What a call compares
For each axiom inside a lock on the theorem's path, the call finds its full path — from where the axiom is declared up to the theorem label's declaration scope. The same is done for the candidate realization — from where its statement is assigned up to where the realization label is declared. The call then matches these two signatures by the following rule of contraction:
The realization's signature must be no wider than the theorem's. Concretely:
for: per type, the realization must have at most as many atoms as the theorem, and atoms are matched positionally (the realization's first atom of a type pairs with the theorem's first atom of that type, etc.). The realization may declare fewer atoms; trailing theorem atoms simply go unused.if: everyif-condition in the realization's signature must appear in the theorem's signature. The realization may use fewer.rule: every rule in the realization must appear in the theorem.typedeclarations are bounded the same way — the realization may not introduce more of them than the theorem's path carries (they are compared by count: type-parameter names are placeholders bound positionally by the call, so the names themselves never matter).
The axiom statement itself is matched after the for-atom mapping is built. Nothing in the realization beyond what the theorem already assumed may appear.
The intent is single and simple: the realization must not give itself more power than the theorem allowed. If it did — by adding an extra if, an extra atom, an extra rule — it could prove things the theorem never could, and the result of the call would be unsound.
Realizations may contain locks
A realization is allowed to cross lock() nodes on its path. Each lock contributes its axioms to the realization's signature, and each such axiom must, in turn, correspond to an axiom of some lock on the theorem's path (the inner match uses equality of signatures, since lock axioms are what the realization provides — they must be exactly as strong as the theorem expects, neither more nor less).
Lock in the realization, matched by signature
The theorem's axiom c -> false is registered in lock L, with a sub-lock Inner contributing a -> true. The realization is the plain label R: its proof sits inside lock RInner, so the realization's signature includes a nested-lock axiom not(y) -> true. After substitution a -> not(y), c -> not(not(y)), the realization's nested axiom matches Inner's axiom exactly. Sound and accepted.
How the realization's locks are nested or grouped does not matter — only the multiset of axioms across all of them does. The realization may split one theorem-lock into several, merge several into one, reorder them, or change the surrounding ifs — as long as the resulting signature stays inside what the theorem allows.
Shared context between the axiom and the theorem
The lock determines which parameters belong to an axiom schema. Values declared above the lock are replaced by the theorem arguments. Parameters declared inside the lock remain universally bound in the axiom, even when the result was proved under the same for block.
Place instance parameters and conditions above the lock when the intended contract depends on those particular values. The following realization supplies the complete schema below L.
Parameters above and below the lock
The parameters a,c and the condition c -> true are above L. The call substitutes them and checks the condition. The parameters m,n and condition a -> true are inside L and remain part of its complete axiom schema.
Permutations and grouping
Because signatures are compared as multisets per category, the textual layout of the proof is free in every way that does not change the multiset:
forof different types may be reordered. A template pathfor(m: bool) for(p: nat)is matched by a realization pathfor(N: nat) for(M: bool)— grouping by type happens before comparison. Only the order of atoms within one type is positional.ifblocks may be reordered and regrouped — two nestedifs, oneifwith two conditions, or any permutation thereof contribute the same set of conditions.- Locks may be split or merged. Two sibling locks with one axiom each, or one lock with two axioms, contribute the same multiset of lock axioms. The realization need not mirror the theorem's lock structure — only its total contract.
- Multi-statement axioms are flattened.
axiom(s1; s2 | L)registers two independent axioms, exactly as two separateaxiom(s1 | L); axiom(s2 | L)commands would. A template written one way is matched by a realization written the other way.
Reordered for-types in a nested lock axiom
The template's nested axiom carries for(m: bool) then for(p: nat); the realization's mirror carries for(N: nat) then for(M: bool). Grouped by type, both are one bool-atom plus one nat-atom — the signatures agree.
Why this is sound
The whole construction rests on a single guarantee: a call delivers a theorem's conclusion only when the realization honestly supplies every premise the theorem was proved under, up to the call's substitution. Nothing weaker is accepted, and nothing the theorem did not assume can sneak in. Three facts together close the loop:
- Requirements may only shrink. An
if-condition, afor-atom, or arulerule on the realization's path is something the realization demands of its context. Demanding less means the realization proved its statement under stricter circumstances — always safe. Demanding more is rejected, because the theorem never sanctioned that extra leverage. - Provided facts match pairwise-exactly, and never exceed the template. A nested lock axiom is something the realization hands back as established. The realization's set of nested axioms must be a subset of the template's — relying on fewer local assumptions is a stronger proof and is accepted (this weakening is what makes derived theorems possible); an extra nested axiom the theorem never sanctioned is rejected. Each nested axiom that is present must match a template one exactly — statement,
for-atoms,if-conditions,rulerules and the count ofruletype parameters on its own chain: handing back a stronger or weaker variant of an expected assumption would silently change what the theorem relied on. - Shared premises are never skipped. The theorem's conditions are checked against the calling scope. Conditions inside an axiom's lock also remain in that axiom's schema. A theorem with an unmet shared
ifis refused outright, even if the realization itself looks fine.
An axiom holds under its own lock. It can supply a realization there because the result stays under that lock. Outside a closed lock, its axiom remains an assumption of the realization's contract and cannot be discarded. A theorem may cross a lock only when its full contract matches the required scheme; an unconditional conclusion requires a proof of every premise.
Type Parameters
Types in Formall form their own small language, separate from expressions. A type is either a declared primary type (like bool, or a parameter introduced by type()) or a function type built from types, like [bool -> bool]. There are no operations on types — they are never computed, compared by value, or produced by expressions; the only things that ever happen to a type are declaration, substitution, and structural equality checking. A type parameter is an atomic placeholder name: it has no content of its own, so a parameter is given by its name among the values (U := bool) or, usually, inferred from the types of the atom arguments. A type argument may be a full type tree, not just primary names — [bool -> bool] is a valid instantiation of U, and the substitution rewrites every occurrence inside atom types structurally, so [U -> bool] becomes [[bool -> bool] -> bool].
When a theorem uses type() to declare a type parameter, the concrete type is inferred from the arguments, or given by name (T := ℕ):
Type parameters
The type parameter T is matched to ℕ. All atoms declared with type T (like =, x, y) are substituted with atoms of the matching concrete type.
Type parameters and lock axioms together
Type substitution composes with signature matching. If a lock axiom's own path declares for-atoms whose types mention a type parameter, those types are substituted by the call's types (inferred or named) before the for-categories are compared. A realization written directly in the concrete type matches a template written in the parameter:
Type parameter in a lock axiom
The template axiom f(u) -> true is parameterized over U both in the function type [U -> bool] and in the atom type of u. The call substitutes U -> bool, f -> not, u -> y; the expected realization becomes not(y) -> true, which the lock-label RL provides. Atom types on the axiom's own path are compared after the same substitution, so a realization declared over the concrete type lines up with a template declared over the parameter.
A theory as a block
A theory is a block whose parameters are its signature and whose assumptions are its axioms: type(M) for(op: [M, M -> M]; e: M) if(…) if(…) { … }. A theorem labelled T:: inside the block is declared outside it, so the type, the atoms and the axioms are its parameters and conditions. Inside the block the theorems serve as hints as usual (the parameters are the atoms in scope); outside, a call applies a theorem to another structure: the axioms of that structure, passed as labels, determine the type and the operations. This is a locale in Isabelle or a structure with an instance in Lean; in the repository, library/algebra/group.fl is the group theory written this way and z2.fl applies it to the integers modulo 2.