Skip to content

Inductive feature flags of the kernel renovation (lean4#16595) - #24

Draft
nomeata wants to merge 26 commits into
masterfrom
renovation
Draft

nomeata wants to merge 26 commits into
masterfrom
renovation

Conversation

@nomeata

@nomeata nomeata commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

This makes con-leche read the per-inductive feature flags (isImpredicative, isK, hasProjections, hasEta, hasLargeElim) that lean4#16595 adds to the kernel and to the lean4export NDJSON format (3.2.0), as part of the kernel logic renovation (lean4#14977).

When a block's type records carry the flags, the block is checked at them. Each flag must be allowed for the declaration, or the block is rejected, and a flag that is off takes its feature away. A block without flags is checked as before. The format version is not read: whether the keys are present decides.

Reading the flags

  • Both NDJSON decoders read the five keys on inductive.types objects into IndCaps.flags : Option IndFlags; the scanner equivalence proofs are repaired.
  • A record with some but not all of the keys, or a block whose records disagree on carrying them, is rejected. The .olean reader produces records without flags.

The check at the flags

  • Every block gets a complete set of flags (BlockShape.flagsAt): the declared ones, or, without flags, the ones derived from the records and the block's sort (derivedFlags, no inference or equality checks). η, the recursors' K flag, the projection tables and the field bound each read one flag.
  • blockFlagsCheck rejects any declared flag the declaration does not support, following lean4#16595. That covers the rules for the auxiliary types of nested occurrences: an impredicative block nesting a container with projections, the universe bound on the container's constructor fields, and K-like containers.
  • Flags that are off take their feature away:
    • hasEta: no structure η or unit-likeness.
    • hasProjections: no projection table, so Expr.proj of the type is rejected.
    • isK: no K-like reduction.
    • hasLargeElim: the recursors eliminate into Prop only and have no reduction rules. A stream recursor that still lists rules is rejected.
  • A flagged Prop block that is not isImpredicative may only have propositions as fields.

The proofs are repaired, with no new model content, no sorry and no new axioms. A flagged block is a narrowing of what the checker accepted before.

Tests

  • All 91 renovation tests of lean-kernel-arena#391 (49 good, 42 bad, exported with the toolchain of lean4#16595) get the official verdict. They are not in tests/arena.sh yet, since it runs a stored snapshot of the published arena tests.
  • 28 new end-to-end fixtures (tests/e2e/ind_flags_*), one per corner case; e2e 663/663.
  • init-full: +0.003 % instructions, the same declarations accepted.

Departures and what is left for later

  • A container that has the K shape but is declared with isK = false is rejected in a nested position, where the official kernel accepts it (OVERVIEW §14). The installed constants don't keep the flag.
  • For input without flags, small eliminators keep their reduction rules, and the projection guard for Prop structures runs at every use, including for flagged types (where it never fails). Both, together with the old large-elimination criterion and the field-sort exemption for Prop blocks, go away once input without flags is no longer supported (see the DESIGN record of task #630).

🤖 Generated with Claude Code

Claude and others added 16 commits November 22, 2026 17:51
readBlock reads the type records' flags (blockFlagsOf; mixed: reject); blockFlagsCheck
validates them; eta, the projection tables, K and the recursors' rules follow them; a
non-impredicative Prop block's fields take the ordinary bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rt 3.2.0

lean4 PR #16595 has the exporter write five booleans on every inductive
type record: isImpredicative, isK, hasProjections, hasEta, hasLargeElim.
Both recognisers read them as optional slots of the type record (five
new keys; keyAt classifies them with new unrolled compares lit11/13/14),
the scanner-equivalence proof is repaired in its existing shape, and
the parse stores them in the type former's caps (`IndCaps.flags`, new,
with the shared `IndFlags`).  A record with some but not all of them,
or a block whose records disagree on carrying them, is rejected.  The
.olean reader emits none; the checker does not yet read them (the
install lane of #630 does).

Tests: ScanTests guards (decode, order, partial, non-boolean, repeat);
fixtures ind_flags_parse (0) and ind_flags_partial_bad (1).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lean4export 3.2.0 (lean4 PR #16595) writes isImpredicative, isK,
hasProjections, hasEta and hasLargeElim on every inductive type record.
Both NDJSON recognisers now read them as optional keys (equivalence proof
repaired), and the parse stores them as `IndCaps.flags : Option IndFlags`
on the type former's record: all five or none, anything else rejected.
No checker behaviour changes yet; the install lane validates and uses them.

Gates: lake build, lake test warning-free; tests/arena.sh (e2e 637/637,
sweeps clean, self-check both forms, shake, layering, binary-link); the
whitepaper-links and plain-reach gates, which it failed, fixed and re-run green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The flags live on BlockShape (readBlock = readBlockShape + blockFlagsOf), not on the installed
caps. blockFlagsCheck validates them; eta (blockCapsAt), the projection tables (projMembers),
K (recKExpected) and the recursors' rules (noRules: the stream's records compared through
ruleOut, rule-less records rejected in streamKCheck) follow them. A flagged non-impredicative
Prop block without large eliminator re-runs the constructors' stage at the ordinary bound
(checkBlockBound). The model reads every stored-rule fact through a rule's membership, so
rule-less recursors need no new model content.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
23 ind_flags_* fixtures forged by scripts/mk_ind_flags_install.py (8 accept, 15 reject);
OVERVIEW §5 (the declared feature flags), §13 (eta), §14; DESIGN record; the cached tail at
blockIsRecC; the shape helpers allowlisted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…re flags

A block whose type records carry the lean4 PR #16595 flags (isImpredicative, isK,
hasProjections, hasEta, hasLargeElim) is checked at them; without flags, as before.
blockFlagsCheck rejects any flag the declaration does not support (official's rules,
e.g. Acc keeps no large eliminator); a flag that is off withdraws its feature: no
projection table without hasProjections, no structure eta / unit-likeness without
hasEta, no K without isK, no recursor rules without hasLargeElim (a record with rules is
rejected); a non-impredicative Prop block without large eliminator takes the ordinary
field bound. Proofs repaired, no new model content (the model reads stored-rule facts
through rule membership). 23 new e2e fixtures (8 accept, 15 reject).

Gates: lake build, lake test warning-free; tests/arena.sh: everything green (e2e 659/659,
sweeps clean) except whitepaper-links, then fixed (citations re-anchored, gate OK).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…91/91)

Official's auxiliary type for a nested occurrence takes isImpredicative from
the block and hasProjections from the container, and is checked like a
member. Two of its rejects were missing:
* an impredicative block nesting a type with projections (arena
  `091_NPImpTree`): `blockFlagsCheck` takes the container's projection-table
  lookup (`hasProj`);
* at a flagged non-impredicative Prop block without large eliminator, a
  container constructor's field outside Prop (found by a probe with the
  lean4#16595 PR release): `nestFrame` checks the walked constructors'
  field sorts (`nestFrameSorts`, gated on `NestCtx.bound`).

`checkStructFieldSortsI` moved to StructInstall for Positivity's use. Proofs
repaired (cached twin, spec, inversions; Complete's walk completeness assumes
`ctx.bound = false`). Fixtures ind_flags_nest (0), *_impred_proj_bad (1),
*_bound_bad (1) from the new source ind_flags_nest_prop. Gates: build, test
warning-free; arena battery green (e2e 663/663) after a pub-import fallback
for BasisBlock; leanprover/lean-kernel-arena#391's 91 tests 91/91.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ion tests 91/91)

An impredicative block nesting a type with projections, and a flagged
non-impredicative Prop block nesting a container with a field outside Prop,
are rejected as official's auxiliary types are. lean-kernel-arena#391's 91
renovation tests: 91/91 (was 90/91). Arena battery green.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…erived as official did)

BlockShape.flagsAt gives each member its declared flags or, at a block whose
records carry none, the ones official computed from the declaration
(derivedFlags: isImpredicative = the block is a proposition, isK = the K shape,
hasProjections/hasEta = structure-like, hasLargeElim = the records' eliminator).
The readers (eta, K, projection members, the field bound) read one flag each;
the Option readers (flagAt/etaAt/kAllowed) are gone.  No verdict changes.
The aux field-bound reject's message loses its internal prefix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ix lane's import edit and this lane's)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…lags

A block's members are checked at their declared feature flags or, without
them, at the ones the official kernel computed from the declaration
(BlockShape.flagsAt / derivedFlags); η, K, projection tables and the field
bound each read one flag, and the Option readers are gone. No verdict
changes: e2e 663/663, arena renovation 91/91, init-full +0.003 %
instructions:u (259.49 G -> 259.50 G). The auxiliary field-bound reject
says it in plain words.

Not done, by reason (DESIGN record): dropping the small eliminators' rules
for input without flags needs a weaker pinned-basis theorem and simplifies
nothing until that input is dropped; skipping the projection guard at
flagged types needs a new model fact. Also repoints the OVERVIEW and
whitepaper anchors the fix lane's import edit had moved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nomeata added a commit to leanprover/lean-kernel-arena that referenced this pull request Nov 22, 2026
…n tests

leanprover/con-leche#24 reads the inductive flags of export format 3.2.0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
nomeata added a commit to arthur-adjedj/lean4 that referenced this pull request Nov 22, 2026
This reads the inductive feature flags in the export format.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lean4 dropped `isReflexive` from `InductiveVal` (with the renovation PR #16595),
so its exporter stops writing the key; the checker never read it. Both NDJSON
decoders now accept it when present (a boolean; non-boolean or repeated stays a
scan error) and drop it, and no longer require it (required mask 2046 → 2038);
`IndTypeRec` loses the field. Equivalence proofs repaired; ScanTests probes and
the e2e twin `ind_flags_no_reflexive` (0).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude and others added 9 commits November 24, 2026 13:12
lean4#15023 declares `Quot` at `Sort (max 1 u)` and `Quot.sound`'s equation at
`Eq.{max 1 u}`: a quotient of a proposition is a type. A quotient record now
matches either form of its pin and the form it declares is stored, so whether
a quotient is a proposition (and proof irrelevance) follows the stream;
`Quot.sound` in the other form than the stored `Quot` is rejected.

The model builds every quotient constant at a construction level beside its
domain level (`u` released, `max 1 u` lifted), one parametric development; the
pin invariant carries the stored `Quot`'s form (`QuotForm`), and the renaming,
cover-step, modular-context and driver proofs carry it through
(`PinCopy.form_unique`, `RenEnv.pinCopy`, `quotName_read`, `quotAt_name`).

Fixtures from the PR toolchain's export: quot_lifted 0, quot_lifted_rfl_bad 1,
quot_released_rfl 0, quot_lifted_mixed_sound_bad 1, quot_other_sort_bad 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stream may declare `Quot` at `Sort u` (released) or at `Sort (max 1 u)`
with `Quot.sound` at `Eq.{max 1 u}` (lean4#15023, where a quotient of a
proposition is a type). The checker stores the declared form, so proof
irrelevance on quotients follows the stream; a `Quot.sound` in the other form
than the stored `Quot` is rejected, any third form declined as before.

Model: quotients are built at a construction level beside the domain level
(`max 1 u` lifted, `u` released) in one parametric development; the pin
invariant records the stored `Quot`'s form and every consumer (renaming,
cover step, modular context, driver) carries it. No new axioms, no sorry.

Gates: lake build and lake test warning-free; tests/arena.sh: e2e 669/669,
the three sweeps clean, all gates but shake and plain-reach, which pass after
the import and allowlist fix (re-run with build, test, layering, binary-link,
trust-surface, link and quote gates). Arena renovation tests 91/91.
Fixtures: quot_lifted 0, quot_lifted_rfl_bad 1, quot_released_rfl 0,
quot_lifted_mixed_sound_bad 1, quot_other_sort_bad 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A stream with the lifted `Quot` (lean4#15023) that does not use `Quot.sound`
has no `Quot.sound` record: the exporter emits what the stream uses.
`preparePrelude` synthesised it from the built-in prelude, in the released
form, and the form check rejected the pair (arena renovation test
`quotOfPropIsType`, a good test).

The prelude's basis roots are now the four inductive basis blocks; the
regenerated prelude holds six records (`Eq`, `Nat`, `Empty`, `False`, `And`,
`Bool`). Nothing else in it mentions a quotient constant; `Quot` stays a
pinned primitive, checked when the stream declares it. The four pin dumps'
`preludeNames` receipts are regenerated by their pinners.

- Arena renovation suite (pr-release-16595-55bd690, 101 tests): 101/101;
  `quotOfPropNoProofIrrel` rejected as a type mismatch in the theorem.
- New fixtures `quot_lifted_no_sound` (0), `quot_lifted_no_sound_rfl_bad` (1).
- `.olean` gate: UpQuot, UpQuotSol and the `--compare` quot_mismatch case
  move 1 -> 2: their reject came from the prelude's quotient slot moving the
  module's theorem `Quot.lift` ahead of the `True` it reads; now each
  declines at its stand-in `Nat.sub`, like the other upstream ports.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… checker does

OVERVIEW §6 said a nonstandard definition at a structural Nat operation's
name is rejected; `checkDeclKindC` declines it (the fast path cannot be
certified, the official kernel accepts the definition). The olean.sh comment
on the quot_mismatch ports now says why they decline at their stand-in
`Nat.sub` and that upstream's reject is comparator's, on `Quot.lift`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The official kernel's eta_expand_iota_reduce_recursor, in both tiers,
verified: a recursor of a K-like type or of a type with η (IndCaps.eta),
applied to at most its major index's arguments, is η-expanded along its
io-inferred type (each rest head-normalised), the full application
ι-reduced with the existing major rescues, and the result abstracted back
to a λ, which the other side is compared with.  First in the stuck
fallback (stuckIrrel), both orientations, for a side that is no λ, as
official's try_eta_expansion before try_eta_struct.

One addition to official's shape: at the verified mode the reduct's
full-grade type is compared with the codomain at the variables (the λ/η
tax's pattern); without it the reduct's value is unknown where the
application is a proof.

Rules tier: DefEq.recEta and the relation RecEtaTele; soundness in
Model/Rules/RecEtaSound.lean (lamV_eta, the abstraction round trip,
IsTy.eq_of_ne_pt).  Inversions, bridge, fuel, pair monad, shift,
environment extension, cached congruences and the cached simulation
repaired; the stuck fallback's cached specs are now at .verified.

Fixtures: rec_eta (lean4's tests/elab/12520_2.lean, the renovation
arena's etaRecStruct and etaRuleK) and four must-reject controls.  The
vendored bad/tutorial/114_etaRuleK is now accepted, as by the official
kernel since lean4#15374.  Renovation arena suite 129/129 (was 127/129).
init-full +0.07 %, grind-ring-5 +0.007 %.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ons, PERF refresh

Master brings the OVERVIEW §0–§14 rewrite (WRITING.md style), applied
projections compared lazily and the Expr hash mixing (#633, #634), the
concise --help, the slow-check threshold and the PERF.md refresh (#635).
The code merged without conflicts.

Docs: OVERVIEW.md takes master's rewritten text, with renovation's
current facts re-added in its structure: a "Feature flags" subsection in
§5 (validation, withdrawn features, nested auxiliary-type rules, flags
derived for blocks without them, isReflexive ignored); Quot's two
result-sort forms and quotFormOk in §5; recursor η in §3 and §14; the
prelude without quotient records and the decline of a nonstandard
structural Nat operation in §6; §13's structure-η and projection-table
rows under flags; §14 bullets for the flags, the lifted Quot and the
nested-K rejection. Master's anchors repointed to the merged tree, and
README's rotted sorryAx link repointed. DESIGN.md keeps both sides'
records (master's #633–#635, then renovation's #630/#632).

Gates: lake build and lake test warning-free; tests/arena.sh exit 0
(e2e 677/677, olean 560/560, tutorial 90/92 as recorded, sweeps clean);
overview links, quote gate and whitepaper links pass.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…#636)

master brings task #636: a `quot` record that does not match its pin, or
that comes before the records it needs, is rejected (exit 1) instead of
declined, as in official's `add_quot` and the other checkers (arena
bugs/quot-bad-type). A `Quot.sound` off its pin stays a decline.

Conflicts in `checkQuotRecord` and `checkQuotRecordC`: both sides kept,
#636's rejects beside renovation's `quotFormOk` (a `Quot.sound` in another
form than the stored `Quot` is rejected). In tests/e2e-expected.txt,
renovation's `quot_other_sort_bad` (`Quot` at `Sort (u+1)`, off both pin
forms) is #636's case and moves from 2 to 1, with `basis_quot_lift_type_bad`
and `tower_quot`. DESIGN.md keeps both sides' records.

Gates on the merged tree: lake build and lake test warning-free;
tests/arena.sh exit 0 (e2e 677/677, arena tutorial 90/92 as recorded,
sweeps clean).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant