for
Declaring variables and universal quantification
Overview
The for command declares atoms (variables and functions) and introduces universal quantification scope. It's one of the most fundamental commands in Formall.
for(atomName: type)for(atomName1, atomName2: type)for(atomName: [argumentType -> resultType])for(atomName: type) { ... }atomName: type- The atoms to declare and their type; several of one type share it (
for(x, y: ℕ)), groups are separated by;(for(x: ℕ; p: [ℕ -> 𝔹])), as in Pascal. A function type is[argumentTypes -> resultType]. Inside the block the atoms are arbitrary: what is proved about them holds for every value (generalize, and a call substitutes them). { … }- The scope of the atoms. Without braces
for(…)is a header of the next command, or with;a declaration to the end of the enclosing block or file.
Command Properties
- Group
- Context
- Produces
- Nothing —
fordeclares atoms but does not produce statements - Delivery & Label
- N/A. Labels are not allowed on
for. - Creates scope
- Yes.
- Mechanism
- Introduces atoms (variables, functions) into scope with specified types.
Basic examples
Simple Values
Declaring values
Functions
Declaring functions
Multi-line Declarations
A single for can declare atoms of different types by separating type groups with commas after their type:
Multi-type declaration
Universal Quantification
A for command introduces a scope where statements proven inside hold "for all" values of the declared variables. Combine with generalize[| …] (a call that takes the for) to lift results out:
Universal proof with generalization
For without Braces
Without braces, for still creates a scope — it just contains only the next command (and its scope). This naturally supports chaining:
Declaration only
Scoping Rules
- Atoms are visible inside the
forscope and cease to exist when it closes - Inner
forcan shadow outer declarations
Unlike programming languages,
for doesn't iterate. It introduces a variable that represents "any" value of its type.