Prompt file imported from petervdonovan/eagerdt-proofs (
.github/prompts/plan-strengthenedModelsImpDesign.prompt.md). Copyright stays with the author.
Plan: Strengthened ModelsImp Design
Recommended direction: keep copyLeftToRight unchanged, keep bare containsDatatypes as the base notion, and introduce a new strengthened models_imp-style interface carrying the ANF-specific hypothesis only where that extra strength is needed.
Steps
0. Define Anf.hasIntendedInterpretation (struct : L.Anf.Structure M) : Prop that says:
for every ground term t : L.GroundTerm, the ANF constant symbol .inr t : L.Anf.Functions 0
is interpreted as the realization of t (as an L-term) in the L-reduct of struct.
Concretely:
∀ (t : L.GroundTerm),
struct.funMap (.inr t) default =
@FirstOrder.Language.Term.realize L M (Anf.anfModel2Model struct) Empty default t
Note: Anf.anfModel2Model struct is the L-reduct defined in R3_Flatten.lean using .inl
functions only. This is what model2AnfModel preserves (it sets .inr t to t.realize), and
hasIntendedInterpretation states that the converse holds for a general structure.
-
Define
Anf.containsDatatypesAnf (ϕ : (QF_DT.Language G) →ᴸ L) (struct : L.Anf.Dup.Structure M) : Propthat bundles: (a)struct.containsDatatypes (ϕ.anf).dupL— the QF_DT embedding exists in the reduct (b)Anf.hasIntendedInterpretationfor the left copy of the ANF constants:∀ (t : L.GroundTerm), struct.funMap (.inl (.inr t : L.Anf.Functions 0)) default = @FirstOrder.Language.Term.realize L M struct_L Empty default twherestruct_L : L.Structure Mis the L-reduct obtained by composing the.inl (.inl ·)embedding (i.e.,Anf.canonicalEmbedding.dupLreduct ofstruct). Condition (b) is what enables the key step incopied_model_rewriteSentence_constructor_iff: aftercopyLeftToRight, the right-copy constant.inr (.inr t)is mapped to.inl (.inr t)(by definition of copyLeftToRight), so if (b) holds forstruct, thencopyLeftToRight structsatisfies the same ANF constant equations for both copies. -
Update
models_impin Dup.lean to usecontainsDatatypesAnfin place of barecontainsDatatypes:def models_imp (Γ : L.Anf.Dup.Theory) (ϕ : (QF_DT.Language G) →ᴸ L) : Prop := ∀ (M : Type w) (struct : L.Anf.Dup.Structure M), (Anf.containsDatatypesAnf ϕ struct ∧ struct ⊨ Γ) → copyLeftToRight struct ⊨ ΓThe hypothesis
containsDatatypesin the old definition is now replaced by the strongercontainsDatatypesAnf. All call sites that construct a proof ofmodels_impwill need to supply condition (b); all call sites that consume it will gain access to it.R5_0_Embed.preserves_consistentLhs_imp_consistentRhswill need to verify (b) holds for the lift embedding (it should:lift_theoryencodes exactly the ANF flattening equations that force the constant interpretations).R5B_SelectorElimandR6_1_R6_2_TesterElimusemodels_imponly as an opaque hypothesis; their axiom stubs need their signatures updated but no new proof work.
-
Thread
containsDatatypesAnfthrough the equisatisfiability chain as follows.Background:
containsDatatypesAnf ϕ structis strictly stronger thanstruct.containsDatatypes (ϕ.anf).dupL(it adds the ANF constant interpretation condition). Downgrading (forgetting condition b) is free; upgrading from barecontainsDatatypestocontainsDatatypesAnfrequires a proof that condition (b) holds, which in general requires knowing thatstructsatisfies the ANF flattening equations (i.e.struct ⊨ Γfor some Γ that includes those equations). Thelift_theoryin R5_0_Embed is exactly such a theory.Axiom stubs (free to update, no proof to break):
R5B_SelectorElim.strongEquisatisfiabilityandequisatisfiability: replacestruct.containsDatatypes (ϕ.anf).dupLwithAnf.containsDatatypesAnf ϕ structon both sides of the iff.R6_1_6_2_TesterElim.strongEquisatisfiabilityandequisatisfiability: same replacement.R6_2_2_Reduct.strongEquisatisfiabilityNoEmbedding: on the RHS, replacestruct.containsDatatypes (ϕ.anf).dupLwithAnf.containsDatatypesAnf ϕ struct.
R5A_ConstructorElim.lean (real proof structure, handle carefully):
- Change the existentials in
strongEquisatisfiabilityandequisatisfiabilityfromstruct.containsDatatypes (ϕ.anf).dupLtoAnf.containsDatatypesAnf ϕ struct. - Change
copyLeftToRight_containsDatatypesconclusion fromcontainsDatatypestocontainsDatatypesAnf, and add asorryfor the new condition (b) component; the existingcontainsDatatypessubproof stays intact as the proof of (a). - In the proof body of
strongEquisatisfiability, at each site that callshconsistent' _ _ ⟨hleft, hsat⟩wherehleft : containsDatatypes ..., insert:
and passhave hAnf : Anf.containsDatatypesAnf ϕ struct := by sorry -- TODO: derive from hleft + struct ⊨ Γ using ANF equations in ΓhAnfinstead ofhleft.
R5_0_Embed.lean (real proof, boundary theorem):
strongEquisatisfiabilityis the boundary between the L.Anf.Dup world and the L world. Its LHS currently statesstruct.containsDatatypes (lift_lhom ϕ)(i.e.struct.containsDatatypes (ϕ.anf).dupL). Change this toAnf.containsDatatypesAnf ϕ struct.- In the ← direction of the proof (lifting from L to L.Anf.Dup via
expandAlong): after constructing the expanded struct, add asorryfor the newcontainsDatatypesAnfobligation. The existingcontainsDatatypesproof for (a) survives unchanged. - In the → direction (projecting from L.Anf.Dup to L):
containsDatatypesAnfimpliescontainsDatatypes, so the existing proof of the L-sidecontainsDatatypes ϕstill works by projecting out component (a) ofcontainsDatatypesAnf.
Main.lean:
- Replace
struct.containsDatatypes ϕ'withAnf.containsDatatypesAnf ϕ structin all intermediatehavestatements (reduct_noemb,tester_elim,selector_elim,constructor_elim,embed_equiv). The final goal and the initialrewrite ϕ Γside are unchanged; only the intermediate Dup-world witnesses change predicate.
-
Annotate the unproved lemmas in Eagerdt/R5A_ConstructorElim.lean with brief comments stating how they should leverage the strengthened invariant, or questions if it seems like there is something wrong with how they are stated.
-
Add lemmas as needed to make the existing unproved lemmas easier to prove.
-
Fill in sorries in Eagerdt/R5A_ConstructorElim.lean, prioritizing work that is likely to uncover problems with the existing proof structure. Focus on copied_model_rewriteSentence_constructor_iff and preserves_consistentLhs_imp_consistentRhs
-
After the constructor slice is stabilized, revisit Eagerdt/Main.lean so that it compiles (with the existing sorries)
Relevant files
- /home/peter/school/219c/eagerdt/Eagerdt/Dup.lean — keep copyLeftToRight unchanged; add the strengthened models_imp-style abstraction here.
- /home/peter/school/219c/eagerdt/Eagerdt/R5A_ConstructorElim.lean — primary consumer of the stronger hypothesis; current proof gaps are here.
- /home/peter/school/219c/eagerdt/Eagerdt/Main.lean — top-level composition point that will need any interface split reflected cleanly.
- /home/peter/school/219c/eagerdt/Eagerdt/R5B_SelectorElim.lean
- /home/peter/school/219c/eagerdt/Eagerdt/R6_1_R6_2_TesterElim.lean
- /home/peter/school/219c/eagerdt/Eagerdt/R3_Flatten.lean — likely reference point for the meaning of ANF-generated constants when defining the stronger hypothesis.
- /home/peter/school/219c/eagerdt/Eagerdt/Basic.lean — supports the interpretation of dupL/dupR used in the copy semantics.
Verification
- Files should type-check using Problems tool or
lake build - Strengthened invariant should be used in place of current invariant
- Summarize progress or roadblocks proving copied_model_rewriteSentence_constructor_iff and preserves_consistentLhs_imp_consistentRhs
Working Notes (added during steps 4–6)
Status of the sorries
-
copyLeftToRight_containsDatatypespart (b): PROVED. The hard-coded L-reduct incontainsDatatypesAnfonly references.inl (.inl ·)symbols, andcopyLeftToRightis the identity on.inl _. BothfunMap (.inl (.inr t))and the inline L-reduct used in (b) are unchanged when passing throughcopyLeftToRight; the proof issimpafromhleft.2 t. -
preserves_consistentLhs_imp_consistentRhs: BLOCKED on the same root cause as the constructor iff. The theorem hypothesis giveshsat : struct ⊨ rewrite ϕ Γ, NOTstruct ⊨ Γ. Thereforehconsistentcannot be applied tostructdirectly — its precondition isstruct' ⊨ Γ. The natural workaround would be to usecopied_model_rewrite_iff.1 : copyLeftToRight struct ⊨ rewrite Γ ↔ copyLeftToRight struct ⊨ Γto transport from rewrite to Γ, but that lemma's input side is the very goal of this theorem (circular). Furthermore,copied_model_rewrite_iffis itself derived from the BLOCKEDcopied_model_rewriteSentence_constructor_iff. So the two sorries here are genuinely blocked, not just unfilled. ONE of the two (hcopycopyΓ) becomes trivial ifhcopyΓis established (it then just applieshconsistenttocopyLeftToRight structusingcopyLeftToRight_containsDatatypes); we annotated this in code. NOTE: this also required adding an explicit universe annotationDup.models_imp.{w}on both occurrences in the theorem signature; otherwise Lean infers two distinct universe variables andhconsistentcannot be applied to the localM.
Roadblock: copied_model_rewriteSentence_constructor_iff
The statement is, for a sentence equal const (.func (.inl (.inl f)) ts) whose RHS head
function f : L.Functions l is a QF_DT-constructor (i.e. f = ϕ.onFunction (.inl f') for
some f' : G.Functions l), modulo copyLeftToRight:
... ⊨ rewriteSentence ϕ (...) ↔ ... ⊨ .equal const (constructor application)
where rewriteSentence introduces tester(f', const), the constructor equation, and selectors.
-
→direction: provable but tedious. Reduces to extracting the constructor clause from the rewritten conjunction and applyingcopyLeftToRight_models_dupR_eqto convert from dupR to dupL. (Type-elaboration noise around.inr f/.inl fcoercions throughL.Anf.Dup.Functionsmakes the proof fiddly but mechanical.) Currently subsumed under the single outersorryfor the whole iff. -
←direction: BLOCKED. Must derive: (i)tester(f', const)and (ii)selectors_i(const) = ts ifor each i, given onlyconst = f(ts)(in the copy structure).The QF_DT.Structure G satisfies (i) and (ii) for every term of the form
f(t1,...,tn), butcontainsDatatypesonly states thatQF_DT.Structure Gembeds into the L-reduct; the embedding is not necessarily surjective. Concretely: we need to know that the valuem := struct.funMap f (eval ts)lies in the image of the embedding. Without that, the embedding tells us nothing aboutRelMap (Tester f') m.containsDatatypesAnf(condition (b)) only constrains values of ANF constants.inl (.inr t)for groundt : L.GroundTerm. It says nothing about constructor applications to arbitrary termsts. In particular, ifconstis not an ANF constant (which it generally is not in the constructor-elimination phase, because R5A operates onlift_theory Γwhich has no ANF constants — see Main.lean and R5_0_Embed.lift_theory), then condition (b) does not apply.Conclusion: the
←direction ofcopied_model_rewriteSentence_constructor_iffis not provable fromcontainsDatatypesAnfalone. To make it provable, one of the following must change:- Strengthen the embedding hypothesis to a strict equality on the constructor
fragment (e.g.
reduct(struct, ϕ) = QF_DT.Structure Gup to surjective embedding). Equivalently, restrict consideration to term-generated L-structures. - Restrict the rewrite phase so that
constis always a fresh ANF constant, and extend condition (b) to cover all constructor applications (not just constants). This effectively requires a prior ANF-flattening pass before R5A. The currentR5_0_Embed.lift_theorydoes not flatten — see Main.lean for the order of transformations, which skips R3 entirely. - Allow R5A to thread a syntactic side-condition (e.g. "every equation has the form
equal anfConstant (constructorApp anfConstants)") and rely on (b) to compute the value of every subterm. This moves the term-model coverage from a semantic hypothesis to a syntactic invariant of the rewrite.
Refinement after rereading the proof obligations: (2) and (3) are not really competing fixes in the current design. They operate at different levels:
- (2) is the architectural / semantic repair. It changes the pipeline so that R5A is fed an ANF-shaped theory in the first place, with enough intended-interpretation coverage to compute constructor/selectors on the relevant terms.
- (3) is the proof-level interface needed to use (2). Even if the pipeline is changed
so R5A only ever receives ANF-shaped equations, the R5A lemmas are currently stated for
arbitrary
γ : L.Anf.Dup.Sentence. The proofs still need a threaded syntactic invariant saying that the specificγunder consideration has the ANF shape needed for condition (b) to apply.
So the practical repair is probably: implement (2), then express its local consequence as (3). In other words, (2) supplies the missing truth of the statement; (3) supplies the missing hypothesis in the theorem statement/proof. Option (3) without (2) would only be enough if some earlier phase already guaranteed the ANF-shape invariant, which the current
lift_theorypipeline does not. - Strengthen the embedding hypothesis to a strict equality on the constructor
fragment (e.g.
Decision (going forward)
- Step 4 (annotation): DONE in-code.
- Step 5 (helper lemmas): no new lemmas needed yet; the existing
@[simp]family ofcopyLeftToRight_*lemmas is sufficient for the parts that ARE provable. - Step 6 (fill sorries): partially done.
copyLeftToRight_containsDatatypespart (b): proved.preserves_consistentLhs_imp_consistentRhs: blocked (analysis above). One of two sorries reduces trivially given the other; both annotated in-code with the cycle.copied_model_rewriteSentence_constructor_iff: blocked (analysis above). The subgoals are collapsed to a single outersorrywith detailed comment explaining the obstruction; previously they were 4 separate sorries with vague TODOs.
- Step 7 (Main.lean): no work required at this time. Main.lean already type-checks against the existing sorries, and no new sorry was introduced. Nothing to do until R5A is unblocked by a structural change to one of (1)/(2)/(3) above.
Verification
lake buildsucceeds.- R5A sorry count went from 4 to 3 (closed part (b) of
copyLeftToRight_containsDatatypes). - All other modules unchanged.
Recommended next step (out of scope for this turn)
Choose between (1)/(2)/(3) above. Option (2) is the most invasive but matches what the
plan originally envisioned with Anf.hasIntendedInterpretation. Option (1) is the
cleanest semantically but requires changing containsDatatypes itself, which would
ripple across R5_0_Embed and beyond. Option (3) is the most conservative but requires
proving (and threading) a new syntactic invariant on the output of lift_theory and
each subsequent rewrite phase.
Update: after closer inspection, the likely viable path is not "choose exactly one" but "do (2), then expose the usable consequence as (3)". Option (1) remains a separate, stronger semantic alternative.
Next Steps
-
Introduce an explicit ANF-shape precondition for the constructor-elimination slice. The precondition should capture exactly the shape needed by condition (b): equations whose left side is an ANF constant and whose right side is either a constructor application to ANF constants or a sentence form preserved by the downstream rewrites. Do this at the sentence/theory level, not just informally in comments.
-
Rework the pipeline so R5A consumes ANF-shaped input rather than raw
lift_theory Γ. Concretely, insert or expose the flattening information that guarantees the equations seen by R5A satisfy the predicate from step 1. This is the substantive implementation of (2). The current blocker is thatR5_0_Embed.lift_theorypreserves syntax but does not enforce ANF shape. -
Thread the ANF-shape invariant through the R5A theorem statements. General lemmas like
copied_model_rewriteSentence_constructor_iffare currently quantified over arbitraryγ : L.Anf.Dup.Sentence; that is too weak. Add the predicate from step 1 either as an explicit hypothesis or by restricting the theorem domain so the proofs can legally invokecontainsDatatypesAnfcondition (b). -
Split
copied_model_rewriteSentence_constructor_iffinto two lemmas after step 3: one for the easy→projection direction, and one for the←reconstruction direction under the new ANF-shape hypothesis. This will keep the proof obligations local and make it obvious which direction uses the stronger invariant. -
Once the constructor iff is restated, revisit
preserves_consistentLhs_imp_consistentRhs. At that point the circularity should disappear:copyLeftToRight struct ⊨ rewrite ϕ Γcan be converted tocopyLeftToRight struct ⊨ Γusing the now-provable iff, and then the second application ofhconsistentgoes through withcopyLeftToRight_containsDatatypes.
Progress on Next Steps (this turn)
Step 1 — DONE. Added in Eagerdt/R5A_ConstructorElim.lean:
isAnfConst : L.Anf.Dup.Term (Empty ⊕ Fin 0) → Prop— "is.func (.inl (.inr c)) defaultfor somec : L.GroundTerm".isAnfShapedSentence : L.Anf.Dup.Sentence → Prop— requires ANF constants on both sides of constructor-application equations; vacuously true on other sentence shapes (whichrewriteSentencepasses through).isAnfShapedTheory ϕ Γ : Prop— pointwise lift.
Step 3 — DONE. Threaded the predicate through R5A theorem statements:
copied_model_rewriteSentence_iffnow takes(hshape : isAnfShapedSentence γ).copied_model_rewrite_iffnow takes(hshape : isAnfShapedTheory Γ).preserves_consistentLhs_imp_consistentRhsnow takes the theory-level hypothesis.strongEquisatisfiabilityandequisatisfiabilitypropagate it.Eagerdt/Main.leanupdated: introduceshave hshape_embed : ... := sorry(a single new sorry, marked with the formal step-2 obligation in a comment).
Step 4 — DONE. Split copied_model_rewriteSentence_constructor_iff into:
copied_model_rewriteSentence_constructor_to(the easy→, no shape hypothesis needed).copied_model_rewriteSentence_constructor_from(the hard←, takeshconst+hts).- The original
_iffis now a thin wrapper combining the two halves. Both_toand_fromare currentlysorrywith detailed comments; the previous single sorry is now decomposed into two strictly-smaller obligations.
Step 5 — PARTIAL. preserves_consistentLhs_imp_consistentRhs was rewritten to use the new shape hypothesis. The previous double-sorry (with explicit cycle annotation) is now a single sorry (hcopyrew). The remaining obstruction is finer: even with the shape-strengthened iff, recovering struct ⊨ Γ from struct ⊨ rewrite ϕ Γ requires a models_rewrite_iff for an arbitrary struct (not just copyLeftToRight-image structures). This may decompose into another targeted lemma; recorded as a remaining obligation in-code.
Step 2 — DEFERRED. Pipeline integration (replacing/augmenting R5_0_Embed.lift_theory so it produces ANF-shaped theories, and likely restricting ground-term constants to the ϕ-image). This is the most invasive change and was scoped out for this turn. The hypothesis hshape_embed in Main.lean is the formal obligation that step 2 must discharge.
Step 6 — N/A. With step 2 deferred, no need to revisit Main's pipeline composition this turn.
Verification
lake buildsucceeds.- R5A sorry count: previously 3 (constructor_iff, hcopyΓ, plus old constructorElimination). Now 5 (constructorElimination, _to, _from, rewrite_preserves_anfShape, hcopyrew). The increase is by design: each new sorry is a smaller, more specific obligation than the lumped ones it replaced.
- Main.lean has 1 new sorry (
hshape_embed) — the explicit pipeline-integration obligation (step 2).
Historical notes below are outdated
The notes in the next two sections are kept for history, but they predate two important corrections:
- the selector clauses in
R5A.rewriteSentencenow usedupL, notdupR; - the missing hypothesis is no longer understood as a strengthened "G-fragment" version of
isAnfConst, but as a theory-relative side-condition on admissible models.
As a result, any statements below about strengthening isAnfConst or needing a separate new obstruction for hcopyrew should be read as superseded.
Remaining hard work (outdated)
(a) StrengthenisAnfConstto the G-fragment (requirec = ϕ.onTerm c'for some G-ground termc'). This is what enables the← (_from)direction to actually invokecontainsDatatypes's embedding.- (b) Discharge
hshape_embed. Requires changingR5_0_Embed.lift_theoryto produce ANF-flattened, G-fragment-restricted equations, possibly by composing with a variant ofR3_Flatten.rewrite. This is the substantive content of step 2. (c) Dischargehcopyrew. Likely needs a new lemmamodels_rewrite_iff_arbitrary(i.e., the iff for arbitrary structures, not justcopyLeftToRightimages), or a different proof strategy that avoids it.
Update: more sorries closed (followup turn)
Filled in by direct proof:
R5A.copied_model_rewriteSentence_constructor_to— the easy→direction. Proof: extractϕ.onFunction (.inl f') = ffromconstructorPreimage? = some f'viaClassical.choose_spec; thensimptheTheory.Modelof the rewritten union (which uses the @[simp] lemmacopyLeftToRight_models_dupR_eqto convert dupR → dupL); apply the resulting universal to the constructor clause viaOr.inl (Or.inr rfl); finally rewrite the dupL function symbol to.inl (.inl f)using the equation derived fromhpre.R5A.rewrite_preserves_anfShape— by case-analysis on each clause produced byrewriteSentence. The pass-through cases trivially preserve shape; the constructor case produces only tester (rel — vacuously shaped), dupR-equal (head.inr ..., vacuously shaped), and selector equations (head.inr ..., vacuously shaped).
Added in R3_Flatten:
Anf.isAnfConst,Anf.isAnfShapedSentence,Anf.isAnfShapedTheory— the L.Anf-level analogs of the L.Anf.Dup-level predicates in R5A. (At the L.Anf level the constructor head is.inl _, vs.inl (.inl _)after lifting.)Anf.isAnfConst_fromGroundTerm_asConst— helper showingfromGroundTerm (asConst t)is canonically ANF-constant.Anf.flatten_term_isAnfShaped— by induction on the ground term, withflatten_term's inductive structure folded out bysimp.Anf.flatten_sentence_head_isAnfShaped— case-analysis on sentence shape; equality cases produce ANF-constants on both sides, so the constructor pattern ofisAnfShapedSentence(which requires a.inl _head on the RHS) does not fire.Anf.rewrite_sentence_isAnfShapedandAnf.rewrite_isAnfShaped— these glue together via membership unfolding.
Remaining R5A sorries (outdated wording)
constructorElimination(line ~125) — preexisting, unrelated.copied_model_rewriteSentence_constructor_from— the hard←direction.hcopyrewinsidepreserves_consistentLhs_imp_consistentRhs— same structural blocker as_from.
The diagnosis in these bullets is outdated: after the selector change to dupL, the
remaining local obstruction is better phrased as a theory-relative side-condition on
models saying that the relevant ANF constants denote elements in the embedding image.
hcopyrew no longer appears to need a separate idea beyond whatever is needed to
prove _from under that side-condition.
Bridge work still owed (outdated ordering)
- Bridge lemma in R5A:
Anf.isAnfShapedTheory Γ → R5A.isAnfShapedTheory ϕ ((LHom.id L.Anf).dupL.onTheory Γ). The L.Anf-level shape lifts cleanly throughdupLbecausedupL.onTermonly adds.inlwrappers without touching the function-symbol structure thatisAnfShapedSentenceinspects. - Pipeline change in
Eagerdt/Main.lean: insert R3 flattening betweenR5_0_Embed.lift_theory(or a refactored variant) andR5_A_ConstructorElim.rewrite. This will dischargehshape_embed(the only sorry in Main.lean).
Update: what we learned after revisiting the obstruction
- The earlier phrase "the ANF constants' underlying ground terms must lie in the ϕ-image" was too strong and not quite the right invariant. It would push too much syntax into the QF_DT fragment and would conflict with the role of uninterpreted constants in satisfiability.
- The real gap is semantic, not purely syntactic.
containsDatatypesonly constrains the reduct on tuples already lying in the image of the embeddingQF_DT.Structure G ↪ reduct(struct, ϕ). The blocked R5A proofs need to know that the specific values touched by constructor equations are in that image. - Condition (b) of
containsDatatypesAnfis still useful, but only for identifying the denotations of ANF constants with realizations of L-ground terms. By itself it does not imply that those denotations lie in the embedding image. - So the missing hypothesis is better understood as a well-formedness / image-closure side-condition on the models we care about: for the relevant ANF constants occurring in the theory slice under consideration, their interpretations land in the image of the chosen embedding. Once that holds, constructor applications on those values also stay in the image by homomorphism preservation, and the tester/selector clauses can be derived inside the embedded QF_DT fragment.
- This new condition is theory-relative. It should probably not be folded directly into
containsDatatypesAnf, which is currently a pure model-side predicate. Instead it should be threaded separately through the R5A lemmas that actually need it, as a side-condition refining which models of the theory are admissible for the constructor-elimination argument.
Current completion plan for R5A_ConstructorElim
These are the steps that now seem specifically necessary to complete Eagerdt/R5A_ConstructorElim.lean, as opposed to later integrating it back into Main.lean.
-
Define a theory- or sentence-relative side-condition on models expressing image membership for the relevant ANF constants. The minimal useful form is: given a witness embedding for
containsDatatypes, every ANF constant appearing in the sentence/theory slice under analysis denotes an element in the range of that embedding. -
Thread that side-condition through the local R5A lemmas that actually need it. At minimum,
copied_model_rewriteSentence_constructor_fromshould take it explicitly.preserves_consistentLhs_imp_consistentRhsshould then depend on the same side-condition only through that local reconstruction lemma, not through a separate new hypothesis about right-copy symbols. -
Prove
copied_model_rewriteSentence_constructor_fromunder that side-condition. This is now the main semantic proof obligation: use condition (b) ofcontainsDatatypesAnfto identify the ANF-constant denotations, use the side-condition to place those denotations in the embedding image, and then use the QF_DT constructor/tester/selector semantics in the embedded fragment to derive the rewritten clauses. -
Reuse that local proof to finish
preserves_consistentLhs_imp_consistentRhs. After switching selector clauses todupL,hcopyrewno longer appears to require a separate counterexample-avoiding argument. It should collapse once_fromis available under the right side-condition. -
Prove
constructorEliminationas the remaining separate structural theorem about the syntax ofrewrite. This theorem is orthogonal to the semantic side-condition work above.
Later integration work
The following items are likely still needed for the full pipeline, but they are not part of the minimal set of steps required to complete R5A_ConstructorElim itself.
-
Add the ANF-shape bridge from
R3_Flatteninto the R5A input. This is the existing bridge lemma about liftingAnf.isAnfShapedTheorythroughdupL. -
Add the bridge from the flattening output to the new theory-relative side-condition. This should be phrased carefully: flattening outputs a theory, not a structure, so it should characterize an admissible class of models rather than directly define denotations.
-
Revisit
Main.rewriteonce both bridges exist. At that point the pipeline should thread both:
- an ANF-shape bridge from R3 into R5A, and
- the new side-condition on admissible models needed by the remaining R5A semantic lemmas.
Progress update on later integration work
-
Step 1 is now implemented in
Eagerdt/R5A_ConstructorElim.leanvia:dupL_preserves_isAnfConstdupL_preserves_isAnfShapedSentencedupL_preserves_isAnfShapedTheory
-
Step 2 is blocked under the current global definition of
Dup.anfConstsInImage/Dup.containsDatatypesAnfWellSorted. The issue is semantic, not proof-search noise:R3_Flatten.rewriteintroduces ANF constants for arbitraryL.GroundTerms coming from subterms ofΓ, while thecontainsDatatypes ϕembedding only controls the QF_DT fragment. There is no reason, in general, that every ANF constant produced by flattening should denote an element in the image of that embedding. -
Consequence:
Maincannot yet replace the old unflattened R5A input with a flattened one and still discharge the stronger R5A/R5A-adjacent witness obligations by a generic bridge fromstruct.containsDatatypes ϕ. -
To resume integration cleanly, one of these design changes is needed:
- Relax
anfConstsInImageback to a theory-relative/image-on-relevant-constants condition. - Restrict the flattened constants to a syntactically identified ϕ-image fragment.
- Strengthen the semantic boundary theorem so it assumes/proves a genuinely global image
closure property, which is stronger than the current
containsDatatypes ϕinterface.
- Relax
Plan for threading a non-Anf well-sortedness condition through the pipeline
If Main.equisatisfiability should stay free of Anf-specific predicates, the cleanest
way to thread the stronger invariant is to move the image-closure statement to the L
boundary and then prove that R5_0_Embed preserves/reflects it.
Proposed boundary predicate on L.Structure
Define an L-side well-sortedness predicate that does not mention ANF constants:
def FirstOrder.Language.Structure.groundTermsInEmbeddingImage
(ϕ : (QF_DT.Language G) →ᴸ L) (struct : L.Structure M) : Prop :=
∃ e : (QF_DT.Structure G) ↪[QF_DT.Language G] @FirstOrder.Language.LHom.reduct _ L ϕ M struct,
∀ t : L.GroundTerm, ∃ g : G.GroundTerm, e g = struct.realize default t
This is the L-structure analogue of the current global Dup.anfConstsInImage:
- on the
Dupside, left-copy ANF constants denote realizations ofL.GroundTerms; - on the
Lside, the same information is stated directly as image-membership of ground-term realizations.
The key advantage is that Main.equisatisfiability can mention this predicate without
mentioning Anf or L.Anf.Dup in its statement.
Refactor steps
-
Add the new
L-side predicate in a boundary-appropriate file. Most likelyEagerdt/QF_DT.lean,Eagerdt/Reduct.lean, orEagerdt/R5_0_Embed.lean. It should live nearcontainsDatatypes, since it is a strengthening of the same semantic embedding interface. -
Prove the two conversion lemmas in
R5_0_Embed.lean.
Dup.containsDatatypesAnfWellSorted ϕ struct_dup -> groundTermsInEmbeddingImage ϕ (lhom.reduct M)struct.containsDatatypes ϕ -> groundTermsInEmbeddingImage ϕ struct -> Dup.containsDatatypesAnfWellSorted ϕ struct_dup
The first direction should use:
- component (a) of
containsDatatypesAnfWellSortedfor the embedding witness; - component (b) of
containsDatatypesAnfto identify left-copy ANF constants withL.GroundTermrealizations; anfConstsInImageto place those left-copy ANF constant values in the embedding image.
The second direction should use the existing struct_dup construction from
R5_0_Embed.strongEquisatisfiability:
- component (a) of
Dup.containsDatatypesAnfWellSortedcomes from the existingcontainsDatatypesproof; - component (b) is already proved via
Anf.model2AnfModel; - the new
anfConstsInImagecomponent should follow from theL-side well-sortedness hypothesis because ANF constants instruct_duprealize exactly the underlying ground terms instruct.
- Update
R5_0_Embed.strongEquisatisfiabilityandequisatisfiability. Replace the current RHSstruct.containsDatatypes ϕ ∧ struct ⊨ Γwithstruct.containsDatatypes ϕ ∧ groundTermsInEmbeddingImage ϕ struct ∧ struct ⊨ Γ.
On the LHS, replace Dup.containsDatatypesAnf with Dup.containsDatatypesAnfWellSorted.
- Thread the stronger duplicated-language witness through the post-R5A pipeline. Update the intermediate existentials in:
R5B_SelectorElimR6_1_R6_2_TesterElimR6_2_2_ReductMain
so that the duplicated-language side carries
Dup.containsDatatypesAnfWellSorted ϕ struct
instead of only Dup.containsDatatypesAnf ϕ struct.
These files mostly use the predicate opaquely, so this should be interface work rather than new semantic proof work.
- Update
Main.equisatisfiabilityto use the strongerL-side boundary condition. Its RHS should become:
∃ struct : L.Structure M,
struct.containsDatatypes ϕ ∧
groundTermsInEmbeddingImage ϕ struct ∧
struct ⊨ Γ
This keeps Main free of Anf, while making explicit the exact global well-sortedness
assumption needed to justify the stronger duplicated-language witnesses.
- Only after that, revisit whether
Dup.anfConstsInImageshould stay global. If the global version becomes too strong for the eventual flattening-based pipeline, we can still relax it later to a theory-relative condition. But the threading work above cleanly exposes whether the current global notion is actually what the end-to-end theorem wants.
Expected outcome of this plan
Mainstates the stronger semantic contract inL-language terms.R5_0_Embedbecomes the only file responsible for translating that contract into the duplicated-language invariant.- The post-R5A stages carry a single strengthened duplicated-language witness shape.
- If a remaining obstruction persists, it will be localized to whether the global image
condition is the right boundary theorem, rather than hidden inside
Main's chaining proof.