Skip to content

Metalogic

A. Arda UZAN edited this page Nov 24, 2026 · 1 revision

As of v1.0.0

This section presents the mechanized Lean 4 formalization (lean/, pinned at leanprover/lean4:v4.36.0) for a facts-only declaration-line fragment of Typify v1, together with the page-to-proof verification gate (scripts/metalogic-check.py).

Registered laws

  1. Formality — equivalence of the declarative line-denotation judgment and the executable recognizer, uniqueness of emitted fact terms, and decidable line acceptance.
  2. Conservative language extension — preservation of every accepted program's ordered fact terms under a fresh, verb-disjoint Typify declaration extension, together with a strict extension witness.
  3. Ontology representation — exact round-trip decoding and second-order satisfaction preservation and reflection for ground unary class assertions and directed binary relation assertions across every nonempty domain and interpretation, together with an asymmetric relation model.

Modeled fragment and lexical boundary

The Lean model operates directly on raw source lines (SourceLine := String) and ordered lists of raw source lines (SourceProgram := List SourceLine), rather than pre-tokenized syntax trees:

  • Characters and line classification (src/syntax.rkt:blank?, trim, classify; see Language): a legal fragment line uses printable ASCII code points (0x20..0x7E) and horizontal tabs (0x09), with no carriage returns (\r), embedded newlines (\n), or other control characters (isLegalChar). Leading and trailing spaces and tabs are stripped (trimChars). Blank lines and #-prefixed lines (isBlankOrCommentLine) emit no term; reserved ?-prefixed question lines (isQuestionChars; see Questions) are outside the modeled facts-only fragment; every other legal line is a content line (FragmentLine) and is split at its first : into a trimmed non-empty verb and a trimmed right-hand side (splitColonLine and HasColonShape).
  • Object-language declarations as Typify declaration data (Decl and DeclData := List MetaLine, corresponding to declare-class, declare-constructor, declare-form, and declare-meaning in src/meta.rkt, and the checks in src/language.rkt and src/classes.rkt; see Classes and Terms and counts):
    • is : <name> = "<lit_1>" | ... | "<lit_k>" (MetaLine.isClass): unreserved identifier <name> (isNameToken, excluding reserved meta, built-in class, and library names) over a non-empty duplicate-free finite list of outer-trimmed non-comment printable ASCII tokens free of horizontal tabs, ", and \ (isLegalToken);
    • term : <ctor> : <c_1> and term : <ctor> : <c_1> <c_2> (MetaLine.termUnary, MetaLine.termBinary): first-order fact constructors of arity 1 or 2 over declared classes;
    • form : <verb> : <<slot>> with does : <ctor> <<slot>> (unary) and form : <verb> : <<slot_1>><sep><<slot_2>> with does : <ctor> <<d_1>> <<d_2>> (binary): distinct verb-headed forms (noDupKeys FormDecl.verb, preventing E_FORM_SHADOW), distinct placeholder names (slot_1 != slot_2) naming declared classes, capture-only does matching the declared constructor parameter classes (E_TERM_CLASS), printable ASCII non-empty separator <sep> free of horizontal tabs, <, and > (isLegalSeparator), and the syntactic delimiter-unambiguity condition noEarlySepMatch requiring that for every literal u of <slot_1>'s class, <sep> does not match inside u ++ sep prior to |u| (E_CLASS_OVERLAP in src/classes.rkt:class-delimiter-witness).
  • Observation scope: declaration well-formedness (compileMeta / WellFormedDecl), line and program acceptance (recognizeLine, readProgram), and the exact ordered list of emitted FactTerm records. Concrete declarations (witnessBaseDecl and witnessExtDecl / ontologyDecl) are included directly in the statements so no universal claim is vacuous.

Sorts, quantifier domains, and symbol key

Every law page displays a single complete many-sorted second-order formula mechanically reflected from the kernel Expr of its designated Lean Prop definition.

Sorts and quantifier domains

Displayed sort Qualified Lean type Quantifier domain
$\mathsf{Decl}$ TypifyMetalogic.Decl Compiled object-language declarations (classes, terms, forms)
$\mathsf{DeclData}$ TypifyMetalogic.DeclData Finite sequences of Typify meta-language clauses (List MetaLine)
$\mathsf{Line}$ TypifyMetalogic.SourceLine Raw source lines (String)
$\mathsf{Prog}$ TypifyMetalogic.SourceProgram Ordered lists of raw source lines (List SourceLine)
$\mathsf{Term}$ TypifyMetalogic.FactTerm Ground first-order emitted fact terms (ctor and args)
$\mathsf{TermList}$ TypifyMetalogic.TermList Ordered lists of emitted fact terms (List FactTerm)
$\mathsf{Name}$ TypifyMetalogic.IndName Individual constant names (String)
$\mathsf{AssertList}$ TypifyMetalogic.AssertionList Finite lists of ground unary and directed binary assertions (List Assertion)
$\mathsf{Type}$ Type (Sort 1) Arbitrary carrier types $D$ (restricted to nonempty domains by $\mathsf{Nonempty}(D)$)
$\mathsf{Name} \to D$ TypifyMetalogic.IndName -> D Interpretations $\mathsf{val}$ assigning an element of $D$ to each individual name
$D \to \mathsf{Prop}$ D -> Prop Second-order unary predicates $P$ over carrier domain $D$
$D \to D \to \mathsf{Prop}$ D -> D -> Prop Second-order directed binary relations $R$ over carrier domain $D$

Catalogue of definitions, assumptions, and proved laws

No project-specific axiom or opaque declarations exist anywhere in lean/. Every proved law depends exclusively on Lean's standard foundational axioms (propext, Classical.choice, Quot.sound).

Symbol / Entry Kind Qualified Lean declaration & argument order Meaning
$\mathsf{d}_{\mathsf{base}}$ Primitive definition TypifyMetalogic.witnessBaseDecl (0-ary) Concrete base declaration (person, peer, unary member)
$\mathsf{d}_{\mathsf{ont}}$ Primitive definition TypifyMetalogic.ontologyDecl (0-ary) Concrete ontology dialect extending $\mathsf{d}_{\mathsf{base}}$ with binary knows (=)
$\mathsf{t}_{\mathsf{knows}}$ Primitive definition TypifyMetalogic.witnessKnowsTerm (0-ary) Ground fact term ["knows", "ada", "ben"]
$\mathsf{ada}, \mathsf{ben}$ Primitive definitions TypifyMetalogic.nameAda, TypifyMetalogic.nameBen (0-ary) Admissible individual names "ada" and "ben"
$\mathsf{WFDecl}(d)$ Primitive definition TypifyMetalogic.WellFormedDecl d Checkable syntactic well-formedness of declaration $d$
$\mathsf{FragLine}(\ell)$ Primitive definition TypifyMetalogic.FragmentLine l Legal non-blank, non-comment raw source line $\ell$
$\mathsf{recognize}(d, \ell)$ Primitive definition TypifyMetalogic.recognizeLine d l Deterministic executable line recognizer returning Option FactTerm
$\mathsf{Derives}(d, \ell, t)$ Primitive definition TypifyMetalogic.DerivesLine d l t Inductive line-denotation judgment built from colon shape, form capture, class membership, and constructor typing
$\mathsf{Accepts}(d, \ell)$ Primitive definition TypifyMetalogic.AcceptsLine d l Executable boolean line-acceptance predicate
$\mathsf{compileMeta}(m)$ Primitive definition TypifyMetalogic.compileMeta m Compiles Typify meta-language clause list $m$ to Option Decl
$\mathsf{extend}(m_1, m_2)$ Primitive definition TypifyMetalogic.appendDeclData m1 m2 Concatenates base declaration clauses $m_1$ and extension clauses $m_2$
$\mathsf{FreshExt}(m_1, m_2)$ Primitive definition TypifyMetalogic.FreshExtension m1 m2 Checkable freshness of extension classes, constructors, and form verbs
$\mathsf{readProg}(d, p)$ Primitive definition TypifyMetalogic.readProgram d p Evaluates program $p$ under $d$ to Option TermList
$\mathsf{Admissible}(A)$ Primitive definition TypifyMetalogic.AdmissibleAssertions A Every individual name in assertion list $A$ belongs to ${\mathsf{ada}, \mathsf{ben}}$
$\mathsf{encode}(A)$ Primitive definition TypifyMetalogic.encodeAssertions A Encodes assertion list $A$ as Typify program lines (member : x, knows : x = y)
$\mathsf{decode}(T)$ Primitive definition TypifyMetalogic.decodeTerms T Partial inverse decoding emitted fact terms $T$ back to Option AssertionList
$\mathsf{singleRel}(x, y)$ Primitive definition TypifyMetalogic.singleBinary x y Singleton assertion list [Assertion.binary x y]
$\mathsf{SatSrc}(D, \mathsf{val}, P, R, A)$ Primitive definition TypifyMetalogic.SatisfiesSource D val P R A Independent model-theoretic satisfaction of source assertions $A$ in $(D, \mathsf{val}, P, R)$
$\mathsf{SatOut}(D, \mathsf{val}, P, R, O)$ Primitive definition TypifyMetalogic.SatisfiesOutput D val P R O Independent model-theoretic satisfaction of reader output $O$ in $(D, \mathsf{val}, P, R)$
External assumptions Assumption inventory (none) Zero unchecked axiom or opaque declarations
formality_law Proved law TypifyMetalogic.formality_law : TypifyMetalogic.FormalityLaw Inhabits FormalityLaw
extension_law Proved law TypifyMetalogic.extension_law : TypifyMetalogic.ExtensionLaw Inhabits ExtensionLaw
ontology_law Proved law TypifyMetalogic.ontology_law : TypifyMetalogic.OntologyLaw Inhabits OntologyLaw

Meaning of the hypotheses

  • $\mathsf{WFDecl}(d)$ requires duplicate-free class, constructor, and form-verb tables, non-empty legal literal sets, declared parameter classes, distinct binary placeholder names, and noEarlySepMatch separator non-overlap (E_CLASS_OVERLAP and E_FORM_SHADOW fail closed when violated).
  • $\mathsf{FragLine}(\ell)$ restricts single-line Formality claims to legal facts-only content lines (blank and #-comment lines are handled at the program level by $\mathsf{readProg}$, and ?-prefixed question lines are outside the modeled fragment).
  • $\mathsf{compileMeta}(\mathit{base}) = \mathsf{some}(d_{\mathsf{base}})$, $\mathsf{compileMeta}(\mathsf{extend}(\mathit{base}, \mathit{ext})) = \mathsf{some}(d_{\mathsf{ext}})$, and $\mathsf{FreshExt}(\mathit{base}, \mathit{ext})$ require both the base declaration data and the extended declaration data to compile cleanly while keeping old classes, constructors, and form verbs disjoint from the extension's additions, with no new program-level count obligations.
  • $\mathsf{Nonempty}(D)$ and $\mathsf{Admissible}(A)$ restrict ontology satisfaction equivalence to nonempty interpretation domains and assertion lists over the dialect's declared individual vocabulary ({"ada", "ben"}; out-of-vocabulary lines such as member : unknown are rejected with E_CLASS).

How to reproduce the check

With Racket 9.3 CS and Lean v4.36.0 on PATH:

cd lean && lake build
cd ..
python3 -B scripts/metalogic-check.py --mode ci --repo-dir .

To verify the full page-to-proof correspondence and link inventory against a checkout of this wiki:

python3 -B scripts/metalogic-check.py --mode full --repo-dir . --wiki-dir ../typify-wiki

In CI, the release-blocking job Lean / zero sorry runs scripts/metalogic-check.py --mode ci on pull requests, on main, and on the packaged release candidate before tag attestation.

What a green result establishes

A passing run establishes:

  1. Inventory bijection: the three frozen v1 law identifiers match the four Metalogic wiki pages (N + 1) and the six tracked .lean files (2N), with no orphan files, reused paths, or unindexed section pages.
  2. Kernel-checked proofs without placeholders: every tracked .lean file compiles under leanprover/lean4:v4.36.0 with zero comments, zero sorry/admit tokens (including unused helpers), zero user axioms, and no transitive kernel dependencies outside propext, Classical.choice, and Quot.sound; each proof module directly imports its paired statement module and proves that exact named Prop.
  3. Mechanical formula correspondence: each law page's $$ ... $$ display-math formula equals the canonical TeX mechanically reflected from the elaborated Lean Prop over the symbol table above, and its Statement and Proof links resolve to the exact verified source commit.
  4. Finite cross-reader conformance: all positive and negative declaration and program fixtures in test/metalogic-conformance.json produce identical verdicts and ordered fact terms in both the Lean executable model and the Typify reader.

Passing does not establish a formal verification of the Racket reader implementation beyond the finite conformance suite, ontology entailment or OWL compatibility, unrestricted reflection outside the admissible ground vocabulary, or tautologicity under arbitrary reinterpretations of the Typify-specific definitions.

Clone this wiki locally