Identity and first-argument projection
id returns its argument unchanged. keep takes two arguments of the same type and returns the first (the value passed earlier).
symbol A : Type;
def id (x : A) : A := x;
theorem keep (x y : A) : A := x;
Loading…
Proofglyph .pg files express types and proof terms using a minimal symbol sequence. The checker reads these symbols and verifies that each proof term has its declared type. Its type system is the λΠ calculus (dependent lambda calculus), the type theory of LF (Logical Framework).
LF is a metalanguage for representing and checking the syntax, inference rules, and proofs of different logics in a common dependently typed lambda calculus. Robert Harper, Furio Honsell, and Gordon Plotkin introduced it in A Framework for Defining Logics (1987 / 1993).
Symbols and inference rules differ between systems such as natural deduction, sequent calculus, and set theory. LF defines them as sequences of constant declarations called signatures. Using these declarations, the checker determines function argument/result types, variable scope, and type equivalence.
For example, Hieratic declares the proposition type Prop and the mapping Prf from propositions to their proof types (of kind Prop -> Type) as follows. A proposition P has type Prop; its proof is a term of type Prf P. Compile this code and check it in Proofglyph form.
symbol Prop : Type;
symbol Prf : Prop -> Type;
symbol P : Prop;
theorem identity (p : Prf P) : Prf P := p;
Compiling this code produces the following .pg:
*:
#0*>:
#0:
#1#2@#1#2@>#1#2@$0\!
Here, #0 refers to Prop, #1 to Prf, and #2 to P. The : operator registers assumptions (axioms); the final ! checks and registers the type and proof term of identity.
The theorem identity takes a proof of P and returns it unchanged. Since it requires a proof of P as input, it is a conditional proof corresponding to P → P, rather than an unconditional proof of P. Introducing and discharging assumptions in natural deduction corresponds to function parameters and lambda abstraction.
Prf P is a type depending on the value of proposition P (a dependent type / type family). forall (P : Prop), Prf P -> Prf P takes any proposition and its proof and returns a proof of the same proposition. Hieratic uses forall for dependent function types (Π types), whose results depend on argument values.
| Role | Examples |
|---|---|
| Object | P : Prop、p : Prf P |
| Type / type family | Prop : Type、Prf P : Type |
| Kind | Type and Prop -> Type are classified by Kind. Kind itself has no type. |
Declare an object-logic universal quantifier as All : (U -> Prop) -> Prop; “F x for every x” becomes All (fun (x : U) => F x). Representing object-language binding through LF lambda binding is called HOAS (Higher-Order Abstract Syntax). Proofglyph internally uses de Bruijn indices to account for variable renaming (α equivalence) and perform deterministic, capture-avoiding substitution.
The checker mechanically verifies that a proof term has the specified type under the declared assumptions. It does not establish consistency of those assumptions or that the encoded rules accurately represent the intended object logic. The original LF paper proves “adequacy”: a one-to-one correspondence between object-language syntax/derivation trees and canonical LF terms.
The kernel handles only Π types, λ terms, application, sorts (Type / Kind), variables, and opaque constants. Type equivalence uses only β reduction. Logical rules and axioms are declared as assumptions; proof terms are explicit. There is no automatic proof search, tactics, or implicit arguments.
Hieratic (.ht) is a high-level language using variable and constant names for readability. Proofglyph (.pg) is a stack-oriented intermediate language expressing types and proof terms with minimal symbols. Hieratic compiles to Proofglyph for kernel type checking. You can also enter and check Proofglyph directly.
Proofglyph scans symbols in order, building expressions on a stack. Binary operators >, \, and @ pop two elements and push a new type or term. In A B and f x below, the rightmost element is the stack top.
| Symbol | Operation |
|---|---|
* | Push Type |
^ | Push Kind |
$n | Variable (de Bruijn index; $0 is the innermost parameter) |
#n | Registered constant (numbered from zero) |
> | Pop A and B; push a dependent function type (Π) with domain A and result B. The parameter can occur inside B. |
\ | Pop A and b; push a function (λ term) taking a parameter of type A and returning b. |
@ | Pop f and x; push the application of function f to argument x. |
: | With exactly [type] on the stack, register an assumption (axiom) constant of that type and empty the stack. |
! | With exactly [type, term] on the stack, check the term's type, register a proven constant, and empty the stack. |
Assume types A, B, and function f : A -> B. Write a function applying f to an argument x : A.
*:
*:
#0#1>:
#0#1>#0#2$0@\!
The first two *: sequences register A (#0) and B (#1). #0#1>: constructs A -> B and registers assumption f (#2) of that type. Its stack evolves as follows:
The stack top is at the top of the diagram. > constructs a function type from two terms; : registers an assumption of that type and empties the stack.
The final line first pushes the result type A -> B using #0#1>. The following #0#2$0@\ represents fun (x : A) => f x. #2$0@ applies f to x; \ constructs a function taking an A parameter. The final ! checks type and body and, on success, registers proven constant #3.
$0 is the innermost bound parameter; $1 is the next outer parameter. This numbering uses de Bruijn indices. For example, #0#0$1\\ takes two arguments of type #0 and returns the first (the value passed earlier).
Constants #0, #1, … are numbered from zero in registration order. Only previously registered constants can be referenced; forward and self-references are forbidden.
Spaces and newlines may be inserted or omitted between tokens, but cannot separate prefixes and digits as in $ 0 or # 12. Write $0 or #12 instead. Proofglyph has no comment syntax.
Type checking occurs when : or ! registers a constant. Stack underflow, extra terms at registration, and a nonempty stack at EOF are syntax errors.
Hieratic uses identifiers (variable/constant names) instead of numeric indices for readability. Function types use A -> B, and application uses f x. Compilation resolves names into indices.
| Syntax | Description |
|---|---|
symbol name : type; | Declare an undefined type or symbol |
axiom name : type; | Declare a trusted axiom or logical rule |
def name : type := term; | Register a definition |
theorem name : type := proof_term; | Prove an opaque theorem |
| Syntax | Description |
|---|---|
Type / Kind | Type is the sort of ordinary types; Type : Kind. Kind itself has no type. |
f x y | Application (left-associative: (f x) y) |
A -> B | Function type (right-associative: A -> (B -> C)) |
forall (x : A), B | Dependent function type (Π) |
fun (x : A) => b | Lambda abstraction (λ) |
symbol A : Type;
def id (x : A) : A := x;
This compiles to *:#0#0>#0$0\!. A corresponds to constant #0 and parameter x to variable $0. Constant name id does not appear in the symbols.
Declaration parameters desugar to forall in the type and fun in the body. The definition above is equivalent to:
def id : A -> A := fun (x : A) => x;
Application f x y associates left ((f x) y); arrows A -> B -> C associate right (A -> (B -> C)). In forall (x : A), B, the result type B may reference parameter x.
Examples use Prop for propositions and Prf P for proofs of P. theorem name : Prf P := term; checks that the proof term has type Prf P. Basic logical rules and Peano axioms are assumptions (axiom); rules derived from definitions are proved as theorem.
def checks its body and expands subsequent references at compile time. theorem checks a proof and retains opaque references. Both use Proofglyph ! for checking/registration; the kernel never unfolds constant bodies. symbol declares undefined types/symbols; axiom declares trusted logical rules/mathematical axioms. Both count as kernel assumptions.
“Check passed” means the proof terms are well-typed under the input's assumptions. It does not establish correctness or consistency of the axioms themselves.
Identifiers match [A-Za-z_][A-Za-z0-9_']*. symbol, axiom, def, theorem, import, forall, fun, Type, and Kind are reserved. Underscore _ is an ordinary identifier, not an inference hole. Numeric literals and infix arithmetic operators such as + and * are not built in.
Name resolution searches parameters from innermost to outermost, then preceding global declarations. Local shadowing is allowed. Duplicate global names, forward references, and self-reference (recursion) are errors. Grouped parameters (x y : A) expand to (x : A) (y : A).
import "commons/logic/propositional.ht";
CLI compile resolves paths relative to the importing file and inlines dependency declarations at that position. Each canonical file is loaded once. Cycles, missing files, and duplicate names after import expansion are errors. There are no namespaces or aliases.
// starts a comment until the end of the line. All arguments must be explicit; there are no inference holes or tactics. This demo keeps import statements visible and lets you edit dependencies in horizontally scrollable tabs. Compilation loads dependencies including your tab edits.
After editing Hieratic, use “Compile and check”; after editing Proofglyph directly, use “Check symbols”. Direct checking has no source map, so constants display as c0, c1, ….
| Construct | Conditions / type |
|---|---|
Type | Has type Kind. Kind itself has no type. |
forall (x : A), B | Requires A : Type and well-formed B : Type or B : Kind under x : A. |
fun (x : A) => b | If b : B, has type forall (x : A), B, provided that type can be formed. |
f u | If f : forall (x : A), B and u : A, its type is B with u substituted for x. |
Bound variables must range over a type of sort Type (first-order dependent types). Since Type : Kind, kind abstraction such as forall (A : Type), A -> A is rejected. An identity function over a specific assumed A : Type is allowed.
Type equivalence uses full β reduction. η equivalence, constant unfolding, proof irrelevance, and user-defined rewriting are unsupported. Natural numbers and inductive types are not built in; they are axiomatized as signature assumptions.
Type checking has a computational budget (fuel) for reduction. Exhausting it interrupts checking; this means the budget was reached, not necessarily that the proof is invalid. The CLI budget can be changed with --fuel N.
Each example runs independently. “Try in editor” replaces the editor contents with the example and compiles and checks it.
id returns its argument unchanged. keep takes two arguments of the same type and returns the first (the value passed earlier).
symbol A : Type;
def id (x : A) : A := x;
theorem keep (x y : A) : A := x;
ab x has type B; applying bc gives bc (ab x) of type C. Taking propositional proofs as arguments derives implication transitivity (syllogism) with the same structure.
symbol A : Type;
symbol B : Type;
symbol C : Type;
theorem compose (ab : A -> B) (bc : B -> C)
(x : A) : C := bc (ab x);
Type family B has kind A -> Type; for an argument x : A, B x is a concrete type. dependent_id takes y : B x and returns it unchanged.
symbol A : Type;
symbol B : A -> Type;
theorem dependent_id (x : A) (y : B x) : B x := y;
Imp P Q is object-logic implication; Prf P -> Prf Q is an LF function mapping a proof of P to a proof of Q. imp_i derives an implication proof from this transformation (introduction); imp_e derives the conclusion from proofs of the implication and premise (elimination / modus ponens).
symbol Prop : Type;
symbol Prf : Prop -> Type;
symbol Imp : Prop -> Prop -> Prop;
axiom imp_i (P Q : Prop) :
(Prf P -> Prf Q) -> Prf (Imp P Q);
axiom imp_e (P Q : Prop) :
Prf (Imp P Q) -> Prf P -> Prf Q;
theorem self_imp (P : Prop) : Prf (Imp P P) :=
imp_i P P (fun (p : Prf P) => p);
theorem apply_self (P : Prop) (p : Prf P) : Prf P :=
imp_e P P (self_imp P) p;
Result type (fun (x : A) => B x) a is β-equivalent to B a, so b of type B a can be returned directly as the body.
symbol A : Type;
symbol B : A -> Type;
symbol a : A;
symbol b : B a;
theorem beta : (fun (x : A) => B x) a := b;
The “Proof examples” dropdown includes propositional logic, equality, natural numbers (Peano axioms), divisibility, the binomial theorem, infinitely many primes, irrationality of √2, Fermat's little theorem, and Russell's paradox (no universal set). Dependencies include the required assumptions; selected main theorems appear first in the results.
Use symbol for undefined types/symbols, axiom for trusted logical rules/mathematical axioms, def for definitions, and theorem for proved rules/conclusions. Divides and Prime are definitions whose rules are proved from existing logical rules. Registering a conclusion with axiom makes it an assumption rather than a proof.
symbol A : Type;
symbol B : Type;
To construct a term of type A -> B -> A, take x : A and y : B and return a term of type A. Returning x satisfies this type.
theorem first (x : A) (y : B) : A := x;
// The same declaration without parameter shorthand:
// theorem first : A -> B -> A :=
// fun (x : A) (y : B) => x;
Given f : A -> B, application f x for x : A yields a term of type B. Rules in dependent type theory also require explicit proposition/object arguments. In the Examples tab, imp_e P P (self_imp P) p passes propositions P, P, implication proof self_imp P, and premise proof p, in that order.
After editing Hieratic, press “Compile and check”. Successfully checked declarations can be referenced by name in later proofs. Split complex proofs into theorem lemmas in dependency (topological) order. Editing clears previous results; check again when finished.
| Error | What to check |
|---|---|
| Syntax error | Check declaration-ending semicolons ;, annotation colons :, definition-body :=, and matching parentheses (). |
| Name not found | Check identifier spelling and declaration order. Undeclared constants, later declarations, and self-reference (recursion) are unavailable. |
| Argument type mismatch | Read the rule's type from the beginning and check argument count, order, and types. There are no implicit arguments; proposition arguments must also be explicit. |
| Proof type mismatch | Compare the declared conclusion with the body's inferred type. The kernel does not unfold registered constants, so type matching cannot rely on unfolding their bodies. |
| Cannot form a Π type | Check that the parameter type has sort Type. Binding the kind Type itself as (A : Type) is not allowed. |
| Proofglyph stack error | : (assumption registration) needs exactly one type; ! (theorem checking) needs exactly a type and term. Check for extra or missing elements. |
After def id (x : A) : A := x;, the compiler expands and β-reduces id a to a. Self/forward references are forbidden. Use theorem to retain a named opaque proof. Both pre-reduction terms and generated Proofglyph are checked.