Generic Lean 4 library for algebraic organization of code repositories — pairs with Pantograph
Find a file
Maximus Gorog 8733a6ff89 Universal round-trip theorems at the token level
Proves four ∀-quantified, structurally-inductive round-trip theorems:

  · nameFromTokens?_round_trip      : ∀ n,   fromTokens? (toTokens n) = some n
  · classifierFromTokens?_round_trip: ∀ φ,   fromTokens? φ.toTokens = some φ
  · cTermFromTokens?_round_trip     : ∀ t,   fromTokens? t.toTokens = some t
  · artifactFromTokens?_round_trip  : ∀ a,   a.supported → fromTokens? a.toTokens = some a

These are the canonical universal round-trips — the parser
inverts the canonical token form on every meta-mirror value.
No `decide`, no `native_decide`, no kernel-depth tricks: pure
structural induction on the meta-mirror type, with sufficient
fuel guaranteed by the per-type length-vs-depth lemma.

Implementation:

(1) Fixed latent double-paren bug in `nameToLeanSource`: dropped
    extra parens around recursive sub-name calls (consistent
    with classifier/cterm renderers).  Pre-fix, 3-level deep
    names like `eq0.i` (FaceFormula.eq0 encoding) failed to
    round-trip silently — no test exercised them.  Added a
    `set_option maxRecDepth 4000 in theorem … decide`-based
    regression test.

(2) Refactored parsers to fuel-based.  `parseName?Aux`,
    `parseClassifier?Aux`, `parseMetaCTerm?Aux`, `parseArtifact?Aux`
    each take a Nat fuel that decreases on every recursive call,
    so they're total without `partial`.  Top-level wrappers pass
    `tokens.length + 1`, always sufficient.

(3) Added canonical token forms `nameToTokens`,
    `MetaClassifier.toTokens`, `MetaCTerm.toTokens`,
    `MetaArtifact.toTokens` — direct value→[Token] mappings,
    parallel to the renderers but at the token level.

(4) Phase 2 (parser correctness on toTokens): four mutual-induction
    theorems, one per meta-mirror type.  Each proves
    `parser?Aux fuel (value.toTokens ++ rest) = some (value, rest)`
    when fuel ≥ value.depth.

(5) Length-vs-depth lemmas: nameToTokens_length_bound,
    classifierToTokens_length_bound, cTermToTokens_length_bound.
    Each by induction.

(6) Token-level universal round-trip theorems: composed from (4)
    and (5) by setting rest = [].  These are the headline results.

Phase 3 (tokenize ∘ render = toTokens, the String-level extension)
is documented but unproven — substantial String/List reasoning
required.  The kernel-rooted decide tests for closed instances
(MetaCTerm.empty, sym, app, etc.) provide empirical evidence.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 12:50:31 -06:00
Infoductor Universal round-trip theorems at the token level 2026-05-01 12:50:31 -06:00
.gitignore Phase A: Foundation lib — meta-mirror, Edit/Context, restructure, registries 2026-05-01 07:20:36 -06:00
Infoductor.lean Add MetaCTerm structural mirror, .cterm artifact arm, MetaPosition.binder 2026-05-01 09:08:01 -06:00
lake-manifest.json Phase B: Comonad sub-library — proof-pattern detection ported from mm-lean 2026-05-01 07:39:36 -06:00
lakefile.toml Phase B: Comonad sub-library — proof-pattern detection ported from mm-lean 2026-05-01 07:39:36 -06:00
lean-toolchain Phase A: Foundation lib — meta-mirror, Edit/Context, restructure, registries 2026-05-01 07:20:36 -06:00
LICENSE Phase A: Foundation lib — meta-mirror, Edit/Context, restructure, registries 2026-05-01 07:20:36 -06:00
NOTICE Phase A: Foundation lib — meta-mirror, Edit/Context, restructure, registries 2026-05-01 07:20:36 -06:00
README.md Phase A: Foundation lib — meta-mirror, Edit/Context, restructure, registries 2026-05-01 07:20:36 -06:00

Infoductor

Generic Lean 4 library + tooling for algebraic organization of code repositories. Provides the mechanism for declaring methodologies that organize a Lean codebase — registries, attributes, the universal restructure operation, the Edit monad / Context comonad pair — without committing to which methodology a downstream project uses.

Pairs naturally with the Pantograph project (the conductor of an electric train sits atop the pantograph hardware). "Info-ductor" — it conducts information (structure, classifications, methodology) through your codebase.

Status

Phase A: Foundation lib landed (2026-05-01). Tactics, Pantograph plugin, and headless Runner sub-libs are planned but not yet present.

Sub-libraries

Library Status Role
Infoductor.Foundation landed Pure algebra: meta-mirror types, Edit monad, Context comonad, restructure, @[macroAlias] / @[methodology] / @[metaPath] attributes + registries. No domain commitments.
Infoductor.Tactics planned Reference dispatcher tactics (cubical_search-shaped) built on Foundation primitives.
Infoductor.Pantograph planned Plugin routing Pantograph commands into Foundation registries.
Infoductor.Runner planned Headless deployment surface for Edit.runHeadless etc. Lands when concrete deployment need arises.

Foundation API

Meta-mirror types (Infoductor.Foundation.Meta)

  • MetaCType — the meta-types of source artifacts (theorem, definition, instance, structure, …).
  • MetaClassifier — a lattice of "where in the codebase" predicates (always, never, atDecl n, inFile p, underAttribute a, dependencyOf n, inNamespace n, plus meet / join).
  • MetaArtifact — what gets placed at a meta-position (source / declAt / refTo / empty).
  • MetaPosition(declName, filePath, range?) addressing.

Edit / Context (Infoductor.Foundation.Edit)

  • Edit α — monad of source mutations. result : α paired with ops : List EditOp.
  • Context α — comonad of "what's around here": focal artifact, position, siblings. extract / extend operations.
  • contextualEdit — distributive law lifting context-aware decisions into edits.

Restructure (Infoductor.Foundation.Restructure)

  • restructure (i ctx φ witness fallback) — the universal source- mutation operation. Same five-field shape as cubical comp, promoted to source-code level.
  • Frozen aliases: transport_artifact, relocate_invariant, rename_throughout, define_question_shape, compose_proof_fragments, materialize.
  • Headless interpreter: EditOp.apply, Edit.runHeadless.
  • Structural soundness: Edit.brokenRefs, Edit.selfConsistent, Edit.guarded.

Registries

  • @[macroAlias] (Infoductor.Foundation.MacroAlias) — register a def as a frozen restructure alias.
  • @[methodology Classifier] (Infoductor.Foundation.Methodology) — register a theorem as a proof methodology indexed by classifier name.
  • @[metaPath Source Target] (Infoductor.Foundation.MetaPath) — declare a structural Path between two classifiers; powers deriveByTransport.
  • tryEntryAsClosed primitive — try a methodology entry as a goal closer; restores tactic state on failure.

Inspecting registries

#eval inside a Lean session:

#eval Infoductor.printAliases
#eval Infoductor.printMethodologies
#eval Infoductor.printMetaPaths

Building

lake build

Forgejo

http://maxgit.wg:3000/max/infoductor

License

See LICENSE.