Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
horn: a binding list is data, and two verified kernels stop reading it two ways
FABIOTESS2c3b03ea3870
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 93555ca9..57804dd5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -19,11 +19,18 @@ All notable changes to Open Ontologies are documented here.binding, so the analysis that used to excuse a disagreement is a gate that can fail. Therefusals are strictness withno soundness content: `horn_certificate_sound`, `horn_certificate_sound_fo` and- `SatRuleFO.to_SatRule` are unchanged in statement and in axiom footprint, and what the checks- buy is stated as `OOCert.wellFormed_determines_instantiation` instead. Every total- substitution extending a well-formed binding instantiates the cited rule the same way, so the- certificate has one meaning rather than one per checker. **A binding for a variable the rule- never mentions is still accepted.** The Isabelle is untouched, because it was written from the+ `SatRuleFO.to_SatRule` are unchanged in statement and in axiom footprint, and the new material+ adds no axiom to either, being free of the `Classical.choice` that `horn_certificate_sound`+ uses. What the checks buy is stated as `OOCert.wellFormed_determines_instantiation` instead,+ and it is existence AND uniqueness, one half per refusal. Read the binding as a set of demands,+ "this variable is that term", one per written pair: distinct keys make those demands+ SATISFIABLE, and coverage makes every substitution satisfying them instantiate the rule the+ SAME WAY. So the certificate has one meaning rather than one per checker. The existence half is+ why a repeated key is refused rather than resolved by a normative tie-break: two demands on one+ variable are met by no total substitution at all, so first-wins and last-wins are not two+ readings of such a certificate but two ways of discarding half of it+ (`no_substitution_extends_a_duplicate_key`). **A binding for a variable the rule+ never mentions is still accepted.** No Isabelle theory is touched, because it was written from theW3C sources without reading the Lean and is worth nothing once it is edited to agree.`reason --rules` structurally cannot emit either refused shape, and`no_emitted_binding_is_one_the_format_now_refuses` checks that against the bytes. Seediff --git a/README.md b/README.mdindex ac91661e..c0ce7d28 100644--- a/README.md+++ b/README.md@@ -70,8 +70,9 @@ confidence. A rule that could conclude a triple no serialiser can write, reachabOWL, which left the store non-deterministic: three runs of one input kept 40, 9 and 24 inferences.And two independently verified kernels disagreeing on 47 of 1,718 certificates, all in the safedirection, tracing to a gap in the certificate format that neither proof could see: the format did-not say what a repeated binding key meant, or what an incomplete binding meant, so each kernel-answered from whatever its lookup function happened to do. That gap is closed by+not say what a repeated binding key meant, or what an incomplete binding meant, so one kernel+refused those shapes and the other answered from whatever its lookup function happened to do. That+gap is closed by[decision 0008](docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md), whichrefuses both shapes, and the differential now reports zero divergent rows. Every one of those hadpassed every test that existed before.diff --git a/docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md b/docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.mdindex 71930395..14022aa0 100644--- a/docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md+++ b/docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md@@ -3,14 +3,18 @@- **Status**: implemented · `lean/OOCert/Horn.lean`, where `bindingWellFormed` is a conjunct of`checkHornStep`, and `wellFormed_determines_instantiation` is the theorem that says what itbuys · `horn_certificate_sound`, `horn_certificate_sound_fo` and `SatRuleFO.to_SatRule` are- unchanged in statement and in axiom footprint · `isabelle/OO_Check.thy` is UNTOUCHED, because- it was written independently and that independence is the whole value · the refusal can fail- in Lean+ unchanged in statement and in axiom footprint, and the new material adds no axiom to either:+ it is free of `Classical.choice`, which `horn_certificate_sound` uses · nothing under+ `isabelle/` except its README is touched, and `OO_Check.thy` in particular is UNTOUCHED,+ because it was written independently and that independence is the whole value · the refusal+ can fail in Lean(`rejects_duplicate_binding_key`, `rejects_binding_that_omits_a_rule_variable` in`HornWitness.lean`) and on the real bytes- (`tests/cross_kernel_differential_test.rs::resolved_d1_*`, `::resolved_d2*`) · the producer is- proved unable to emit either shape by- `tests/reason_horn_emit_test.rs::no_emitted_binding_is_one_the_format_now_refuses`+ (`tests/cross_kernel_differential_test.rs::resolved_d1_*`, `::resolved_d2*`) · the producer+ structurally cannot emit either shape, argued from `run_horn`'s construction and checked against+ the emitted bytes by+ `tests/reason_horn_emit_test.rs::no_emitted_binding_is_one_the_format_now_refuses` and+ `::a_head_variable_the_body_never_binds_never_reaches_the_evaluator`- **Written**: 2026-09-14- **Related**: decision 0003 (a rule is data, and an assumption is not a fact), whose format thisamends; decision 0002 (an inference carries a certificate)@@ -65,29 +69,63 @@ repaired.** `checkHornStep` now requires, of the binding and the rule it cites:Both refusals are strictness with no soundness content, and that is the point. What they buy is asentence a soundness theorem cannot say: the certificate means ONE thing.-`wellFormed_determines_instantiation` states it and the kernel checks it. Once the binding is well-formed for the cited rule, every total substitution that extends it instantiates that rule the same-way, so a checker carrying the binding as a partial map and one carrying it as a total function with-a default are reading the same certificate.+`wellFormed_determines_instantiation` states it and the kernel checks it.++The statement is worth reading carefully, because it is EXISTENCE AND UNIQUENESS and the two halves+are what the two refusals separately buy. Read a binding list as what it looks like: a set of+demands, "`v` is `t`", one per written pair. The membership reading, `(v, t) ∈ l → σ v = t`, is+deliberately not a statement about `List.lookup`, so it speaks about a checker carrying a partial+map, a checker carrying a total function with a default, and a checker nobody has written yet. Then+once the binding is well formed for the cited rule:++- **something meets those demands**, and `substOf` is it. This is what DISTINCT KEYS buy, and it is+ `substOf_extends_of_keysDistinct`.+- **everything that meets them instantiates the rule identically.** This is what COVERAGE buys, and+ it is `instantiation_unique_of_covers`.++Neither conjunct of `bindingWellFormed` is decorative, and `HornWitness.lean` refutes each half with+its own hypothesis dropped: `no_substitution_extends_a_duplicate_key` and+`two_extensions_of_an_uncovered_binding_disagree`.### Why refusing, rather than writing the permissive reading into the format-Both questions had a permissive answer available, and both were rejected on the same ground: the-permissive reading costs nothing to give up and buys a second meaning.+Both questions had a permissive answer available, and both were rejected, though not on the same+ground. The repeated key turns out to be the easier of the two.On the **repeated key**, the alternative was to make first-wins normative. One sentence would have-made the format determinate, so this is a real option and not a straw man. It is the wrong one.-First-wins is not "the natural implementation", because there is no such thing. Of the four-association-list primitives an implementer is most likely to reach for, two are first-wins-(`List.lookup` in Lean, `map_of` in Isabelle) and two are last-wins (`dict(pairs)` in Python,-`HashMap::from_iter` in Rust, both of which insert in order and let the later value win). A-normative first-wins rule would therefore be broken by half the primitives on that short list, and-broken SILENTLY, by accepting a certificate that means something else. `distinct` has no such-split: every language has it, and getting it wrong is loud. Against that, a duplicate key carries no-information a producer needs, since there is no certificate writable with one that is not writable-without one, so refusing costs exactly nothing.--On the **incomplete binding**, the argument is sharper, because on the question of ENTAILMENT the+made the format determinate, so this is a real option and not a straw man. It is the wrong one, and+the reason is sharper than a preference between library conventions.++**A repeated key with two different values makes the certificate's own demands unsatisfiable.** The+pair `("x", a)` says `x` is `a` and the pair `("x", b)` says `x` is `b`, and no total substitution+does both. That is `no_substitution_extends_a_duplicate_key`, and it holds for every checker at+once rather than for this one. So first-wins and last-wins are not two readings of such a+certificate. There is no reading of it. They are two conventions for ignoring half of what it says,+and a normative first-wins rule would be a rule about which half to discard. A format should not+have one.++That argument covers a repeated key whose two values DIFFER, which is the case the fixture and the+corpus are made of, and it does not cover a key repeated with the SAME value. `keysDistinct` refuses+that too, and it is worth being honest that the refusal is a different kind there: the demands are+satisfiable, there is exactly one reading, and refusing is tidiness rather than determinacy. It is+still right, for two reasons that are not the one above. The decisive one is that Isabelle's+`distinct (map fst b)` refuses it, so a Lean that admitted it would REINTRODUCE the divergence this+decision exists to close, and the Isabelle is not available to be edited. The other is that+`distinct` is one primitive every language has, while "distinct keys, or repeated keys whose values+agree" is a rule an implementer has to get right on purpose, for a shape no producer needs to emit.++The library split is then the second-order point rather than the argument, and it is why the damage+would be silent. Of the four association-list primitives an implementer is most likely to reach+for, two are first-wins (`List.lookup` in Lean, `map_of` in Isabelle, whose own source comment in+`OO_Check.thy` names this) and two are last-wins (`dict(pairs)` in Python, `HashMap::from_iter` in+Rust, both of which insert in order and let the later value win). A normative first-wins rule would+be broken by half of that short list, and broken by ACCEPTING a certificate that means something+else rather than by failing. `distinct` has no such split: every language has it, and getting it+wrong is loud. Against that, a duplicate key carries no information a producer needs, since there+is no certificate writable with one that is not writable without one, so refusing costs exactly+nothing.++On the **incomplete binding**, the argument is harder, because on the question of ENTAILMENT thepermissive reading was right and Isabelle was the incomplete one. `EntailsR` quantifies over everytotal substitution, so a step whose body instantiates into known triples under SOME totalsubstitution really does entail its conclusion. The refusal is therefore a deliberate choice of@@ -107,6 +145,32 @@ cannot make a step mean two things, and there is no second reading to remove. Retidiness rule dressed as a determinacy one. Both kernels already agreed here(`probe_extrabind`, exit 0 on both) and they still do.+### Can this engine emit what is now refused?++No, and structurally rather than by care, which matters because a producer that could write+certificates its own checker rejects would make the refusal a bug report against ourselves.+`run_horn` in `src/reason.rs` builds a step's binding as `rule.vars.iter().enumerate().map(...)`,+one pair per entry, so the binding is exactly `rule.vars` and the two questions become questions+about that one list.++- **No repeated key.** `rule.vars` is accumulated with `!vars.iter().any(|x| x == v)` guarding every+ push, so it is deduplicated before a single binding is written and a repeat has no way in.+- **No omitted variable.** The same loop runs over `r.atoms()`, which is+ `body.iter().chain(once(&head))`. So `rule.vars` is collected from body AND head, which is exactly+ the set `RulePattern.varList` gives the checker, and coverage holds by construction.+- **And the `expect` between them cannot fire.** `env[i].expect(..)` would panic on a rule variable+ the body never bound. `parse_rules` refuses any table whose head carries a variable that "does not occur+ in the body" before it reaches the evaluator, so that input never arrives.+ `a_head_variable_the_body_never_binds_never_reaches_the_evaluator` runs that refusal through both+ doors, `parse_rules` directly and `Reasoner::run_horn`.++That is the argument. `no_emitted_binding_is_one_the_format_now_refuses` is the check against the+bytes: it re-parses every table the engine wrote, re-derives the wanted variable set the way+`bindsCover` reads it, and asserts distinctness and coverage on every emitted step across three rule+tables and two graphs, with a floor so that a corpus that collapsed to nothing would fail rather+than pass. A structural argument nobody checks against the bytes is how a structural argument goes+stale.+## What this does not claim**This decision does not make a conclusion writable RDF.** Binding `z` to the bare term `z` is now@@ -158,7 +222,14 @@ The 47 moved into rejected-by-both and nowhere else: 857 plus 47 is 904, and theunparseable counts did not move. The 286 is larger than 47 because most rows carrying a malformedbinding were already rejected by both kernels for some other reason; the gate runs on every rowrather than only on the ones that disagree, because a check that ran only on divergences could be-satisfied by silence.+satisfied by silence. It splits 89 D1 and 197 D2.++One detail worth stating rather than rounding off: **all 47 corpus divergences were D1.** D2's+three certificates are committed probes with their own tests and are not members of the generated+corpus, so the corpus never counted them, and the before-run's classification prints only D1 rows.+That does not make D2 the weaker half of this decision. D2b is the case where the silent default+put a term nobody wrote into a conclusion, and D2c was found BY the fuzzer inside this same corpus+machinery before it was committed as a probe.## Since writtendiff --git a/docs/lean-certificates.md b/docs/lean-certificates.mdindex df0c264c..7879121f 100644--- a/docs/lean-certificates.md+++ b/docs/lean-certificates.md@@ -306,7 +306,7 @@ Two shapes are refused, on both checkers:| shape | example | why ||---|---|---|-| a key bound twice | `x <http://ex.org/a> x <http://ex.org/zzz>` | the variable's value would be decided by the tie-break inside whichever lookup function a checker uses: first-wins in Lean's `List.lookup` and Isabelle's `map_of`, last-wins in Python's `dict()` and Rust's `HashMap::from_iter` |+| a key bound twice | `x <http://ex.org/a> x <http://ex.org/zzz>` | the two pairs demand two different values for one variable, so NO substitution satisfies both and there is nothing for a checker to read: first-wins (Lean's `List.lookup`, Isabelle's `map_of`) and last-wins (Python's `dict()`, Rust's `HashMap::from_iter`) are two conventions for discarding half the certificate, not two readings of it || a variable of the cited rule with no binding | binding `s`, `o` for the rule `?s <p> ?o -> ?s <q> ?z` | the checker would otherwise have to invent a value, and the only one available is the variable's NAME, so the conclusion would carry a term nobody wrote |A binding for a variable the cited rule never mentions **is accepted**: it is never consulted, so it@@ -314,8 +314,10 @@ cannot make a certificate mean two things.Both refusals are strictness and neither carries soundness content. What they buy is that acertificate has ONE meaning, which `OOCert.wellFormed_determines_instantiation` states and the Lean-kernel checks: once the binding is well formed for the cited rule, every total substitution that-extends it instantiates that rule the same way. The defect they close was found by running this+kernel checks. Read the binding as a set of demands, "this variable is that term", one per written+pair. Distinct keys make those demands SATISFIABLE and coverage makes every substitution satisfying+them instantiate the cited rule the SAME WAY, so one refusal buys existence and the other buys+uniqueness. The defect they close was found by running thischecker and the independent Isabelle/HOL one in `isabelle/` over 1,718 certificates: 47 rowsdisagreed, all from this one cause. See[decision 0008](decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md).diff --git a/docs/reasoning-systems-inventory.md b/docs/reasoning-systems-inventory.mdindex 87cd7b2d..2d1b686e 100644--- a/docs/reasoning-systems-inventory.md+++ b/docs/reasoning-systems-inventory.md@@ -95,7 +95,7 @@ refused. The defect was in the FORMAT, which never said what a repeated key meanincomplete binding means, and only a second implementation could have surfaced it.That gap is now CLOSED. `docs/decisions/0008-a-binding-is-data-and-evidence-admits-one-reading.md`-refuses both shapes, the Lean moved and the Isabelle was not touched, and the same corpus now+refuses both shapes, the Lean moved and no Isabelle theory was touched, and the same corpus nowreports zero divergent rows: 349 accepted by both, 904 rejected by both, 465 unparseable on both.The 47 moved into rejected-by-both and nowhere else.diff --git a/isabelle/README.md b/isabelle/README.mdindex 6e86ef9d..1cbccbff 100644--- a/isabelle/README.md+++ b/isabelle/README.md@@ -68,9 +68,15 @@ loudly (`common::skip_unless`) when either proof assistant is missing, and## What the differential found, and what it changed-1,718 certificates: 61 base, 1,291 mutated, 366 fuzzed. **Forty-seven rows disagreed, in two-classes.** Nothing was adjusted on either side to make them go away; the FORMAT was changed-instead, and the divergence is now zero.+1,718 certificates: 61 base, 1,291 mutated, 366 fuzzed. **Forty-seven rows disagreed.** Nothing+was adjusted on either side to make them go away; the FORMAT was changed instead, and the+divergence is now zero.++Those 47 corpus rows were ALL of class D1 below, which is worth stating precisely rather than+rounding to "two classes": D2's three certificates are committed probes with their own tests and+are not members of the generated corpus, so the corpus never counted them. The classification the+corpus test prints says so directly, and D2 is not the weaker finding for it: D2c was found BY the+fuzzer, inside the corpus machinery, before it was committed as a probe.Both classes had ONE root cause: **Isabelle validates the binding list as a data structureand Lean did not.** `check_step` requires `distinct (map fst b)` and `binding_covers b r`@@ -146,7 +152,13 @@ disagree: a check that ran only on divergences could be satisfied by silence.A binding for a variable the cited rule never mentions is still ACCEPTED on both sides(`probe_extrabind`). It is never consulted, so there was no second reading to remove.-### What agreement on the other 1,671 rows is evidence of++### What agreement on all 1,718 rows is evidence of++It was 1,671 rows before decision 0008 and it is all 1,718 after, and the increase is worth+exactly nothing on its own: it was bought by making one checker refuse more, which is the+cheapest way there is to buy agreement. What the number is worth is fixed by the floor the+corpus test asserts, that at least twenty certificates are ACCEPTED by both.Checking a Horn certificate is purely syntactic. Neither kernel consults its semantics, sotwo checkers built on contradictory model theories agree on every certificate and everydiff --git a/lean/OOCert/Horn.lean b/lean/OOCert/Horn.leanindex 1536f412..7a86dc3f 100644--- a/lean/OOCert/Horn.lean+++ b/lean/OOCert/Horn.lean@@ -183,14 +183,17 @@ def substOf (l : List (Var × Term)) : Subst := fun v => (List.lookup v l).getDDecision 0008. A binding list is DATA before it is a substitution, and acertificate whose binding is malformed is refused rather than repaired.-Two shapes are refused, and both were found by running this checker and the-independent Isabelle/HOL one over 1,718 certificates and comparing:--* a REPEATED KEY, because the value of the variable would then be decided by- the tie-break inside whatever lookup function a checker happens to use.- `List.lookup` here is first-wins, while `dict()` and `HashMap::from_iter`- elsewhere are last-wins, and a certificate whose meaning depends on that is- not evidence of anything;+Read a binding list as what it looks like: a set of demands, "`v` is `t`", one+per written pair. Two shapes are refused, and both were found by running this+checker and the independent Isabelle/HOL one over 1,718 certificates and+comparing:++* a REPEATED KEY, because two demands on one variable are met by NO total+ substitution, so there is nothing for a checker to read. `List.lookup` here+ is first-wins and `dict()` and `HashMap::from_iter` elsewhere are last-wins,+ but those are two conventions for discarding half of what the certificate+ says rather than two readings of it. See+ `no_substitution_extends_a_duplicate_key` in `HornWitness.lean`;* an INCOMPLETE BINDING, because `substOf`'s default would otherwise mint aterm out of a variable's NAME in the rule file and put it in the conclusion.@@ -239,7 +242,7 @@ theorem lookup_eq_of_mem_of_keysDistinct :∀ {v : Var} {t : Term}, (v, t) ∈ l → List.lookup v l = some t := byintro linduction l with- | nil => intro _ v t hm; simp at hm+ | nil => intro _ v t hm; cases hm| cons p rest ih =>obtain ⟨w, u⟩ := pintro hd v t hm@@ -249,19 +252,65 @@ theorem lookup_eq_of_mem_of_keysDistinct :· have hv : v = w := congrArg Prod.fst heqhave ht : t = u := congrArg Prod.snd heqsubst hv; subst ht- simp [List.lookup]+ -- `cases` on `v == v` rather than `beq_self_eq_true`: the reflexivity lemma+ -- reaches `ReflBEq String` through `Std.LawfulBEqOrd`, which drags+ -- `Classical.choice` into a file that otherwise needs none.+ rw [List.lookup_cons]+ cases hb : v == v with+ | true => rfl+ | false => exact absurd rfl (beq_eq_false_iff_ne.mp hb)· have hvw : ¬ v = w := byintro hsubst h- have := List.all_eq_true.mp hne (v, t) hmem- simp at this+ have hx := List.all_eq_true.mp hne (v, t) hmem+ rw [bne_self_eq_false] at hx+ exact Bool.noConfusion hxhave hbeq : (v == w) = false := bycases hb : v == w with| false => rfl| true => exact absurd (eq_of_beq hb) hvw- simp only [List.lookup, hbeq]+ rw [List.lookup_cons, hbeq]exact ih hrest hmem+/-- The converse direction, and it needs no hypothesis at all: whatever+`List.lookup` returns, it returns a pair that is really in the list. This is what+makes the membership reading below the WEAKER commitment of the two, so a checker+that satisfies it has committed to less than one that mirrors `List.lookup`. -/+theorem mem_of_lookup_eq_some :+ ∀ {l : List (Var × Term)} {v : Var} {t : Term},+ List.lookup v l = some t → (v, t) ∈ l := by+ intro l+ induction l with+ | nil => intro v t h; simp [List.lookup] at h+ | cons p rest ih =>+ obtain ⟨w, u⟩ := p+ intro v t h+ cases hbeq : v == w with+ | true =>+ have hv : v = w := eq_of_beq hbeq+ subst hv+ simp only [List.lookup, hbeq, Option.some.injEq] at h+ subst h+ exact List.Mem.head _+ | false =>+ simp only [List.lookup, hbeq] at h+ exact List.Mem.tail _ (ih h)++/-- **Distinct keys make the certificate's own constraints satisfiable.** Read a+binding list the way a reader does, as a set of demands "`v` is `t`" one per+written pair, and `substOf` satisfies every one of them. That is what a repeated+key destroys, and destroys for every checker at once rather than for this one:+see `no_substitution_extends_a_duplicate_key` in `HornWitness.lean`, where the+demands of a twice-bound variable cannot all be met by ANY total substitution.+So the refusal is not a preference for `List.lookup`'s tie-break over some other+library's. It is a refusal of a certificate that asks for two things at once. -/+theorem substOf_extends_of_keysDistinct {l : List (Var × Term)}+ (h : keysDistinct l = true) : ∀ v t, (v, t) ∈ l → substOf l v = t := by+ intro v t hm+ unfold substOf+ rw [lookup_eq_of_mem_of_keysDistinct h hm]+ rfl+/-- On every variable the rule mentions, the total substitution's value is thevalue the binding list actually supplies. The default is never reached, so`substOf` and a PARTIAL lookup agree everywhere the checker looks. -/@@ -296,27 +345,56 @@ theorem mem_varList_of_mem_head {r : RulePattern} {v : Var} (hv : v ∈ r.head.vv ∈ r.varList :=List.mem_append_right _ hv-/-- **The format decision, as a theorem.** Once the binding list is well formed-for the cited rule, EVERY total substitution that extends it instantiates that-rule the same way. So a checker that carries the binding as a partial map and-one that carries it as a total function with a default are reading the same-certificate, and the certificate has one meaning rather than one per checker.-Nothing below depends on this: it is the statement the differential could not-make for itself. -/-theorem wellFormed_determines_instantiation {r : RulePattern} {l : List (Var × Term)}- (h : bindingWellFormed r l = true) {sigma : Subst}- (hext : ∀ v t, List.lookup v l = some t → sigma v = t) :+/-- **Uniqueness.** Every total substitution that meets the binding's demands+instantiates the cited rule the same way. The hypothesis is the MEMBERSHIP+reading, `(v, t) ∈ l → sigma v = t`, deliberately and not `List.lookup`: it is+what any reader of the pairs commits to whatever it builds them into, so this+speaks about a checker carrying a partial map, a checker carrying a total+function with a default, and a checker that has not been written yet.++Only coverage is used, and the statement says so rather than carrying+`bindingWellFormed` and quietly discarding half of it. Distinctness is what makes+the hypothesis SATISFIABLE, which is the other half and a separate theorem:+`substOf_extends_of_keysDistinct`. -/+theorem instantiation_unique_of_covers {r : RulePattern} {l : List (Var × Term)}+ (h : bindsCover r l = true) {sigma : Subst}+ (hext : ∀ v t, (v, t) ∈ l → sigma v = t) :r.body.map (AtomPat.inst sigma) = r.body.map (AtomPat.inst (substOf l)) ∧AtomPat.inst sigma r.head = AtomPat.inst (substOf l) r.head := by- simp only [bindingWellFormed, Bool.and_eq_true] at hhave agree : ∀ v ∈ r.varList, sigma v = substOf l v := fun v hv =>- hext v _ (lookup_eq_substOf_of_covers h.2 hv)+ hext v _ (mem_of_lookup_eq_some (lookup_eq_substOf_of_covers h hv))refine ⟨List.map_congr_left ?_, AtomPat.inst_congr ?_⟩· intro a haexact AtomPat.inst_congr (fun v hv => agree v (mem_varList_of_mem_body ha hv))· intro v hvexact agree v (mem_varList_of_mem_head hv)+/-- **The format decision, as a theorem: existence and uniqueness.** Read the+binding list as what it looks like, a set of demands "`v` is `t`", one per written+pair. Once it is well formed for the cited rule:++* **something meets those demands**, and `substOf` is it. This is what DISTINCT+ KEYS buy, and it fails outright for a repeated key, where two demands on one+ variable cannot both be met by any total substitution at all;+* **everything that meets them agrees** on how the rule instantiates. This is+ what COVERAGE buys, and it fails for an incomplete binding, where two readers+ meeting every demand can still differ on a variable no demand mentions.++Both conjuncts of `bindingWellFormed` are therefore load-bearing, one in each+half, and `HornWitness.lean` carries a counterexample to each half with its+hypothesis dropped. Together they are the sentence the differential could not+make for itself: the certificate means one thing rather than one thing per+checker. Nothing below depends on this. -/+theorem wellFormed_determines_instantiation {r : RulePattern} {l : List (Var × Term)}+ (h : bindingWellFormed r l = true) :+ (∀ v t, (v, t) ∈ l → substOf l v = t) ∧+ ∀ sigma : Subst, (∀ v t, (v, t) ∈ l → sigma v = t) →+ r.body.map (AtomPat.inst sigma) = r.body.map (AtomPat.inst (substOf l)) ∧+ AtomPat.inst sigma r.head = AtomPat.inst (substOf l) r.head := by+ simp only [bindingWellFormed, Bool.and_eq_true] at h+ exact ⟨substOf_extends_of_keysDistinct h.1, fun _ hext =>+ instantiation_unique_of_covers h.2 hext⟩+/-- Check one Horn step. Three things are contracted, not two.The BINDING must be well formed for the cited rule (decision 0008): distinct@@ -453,14 +531,29 @@ theorem horn_certificate_sound_fo (G : List Triple) (R : List RulePattern) (step#guard_msgs in#print axioms SatRuleFO.to_SatRule+/-! The decision-0008 material adds NO axiom to this file, and in fact sits inside+what was already here: every theorem below is free of `Classical.choice`, which+`horn_certificate_sound` uses. Keeping it that way took one deliberate step, and+the comment in `lookup_eq_of_mem_of_keysDistinct` records it: `beq_self_eq_true`+resolves `ReflBEq String` through `Std.LawfulBEqOrd` and drags choice in, so the+reflexive case is done by `cases` on `v == v` instead. -/+/-- info: 'OOCert.wellFormed_determines_instantiation' depends on axioms: [propext, Quot.sound] -/#guard_msgs in#print axioms wellFormed_determines_instantiation-/-- info: 'OOCert.lookup_eq_of_mem_of_keysDistinct' depends on axioms: [propext, Classical.choice, Quot.sound] -/+/-- info: 'OOCert.lookup_eq_of_mem_of_keysDistinct' depends on axioms: [propext, Quot.sound] -/#guard_msgs in#print axioms lookup_eq_of_mem_of_keysDistinct+/-- info: 'OOCert.substOf_extends_of_keysDistinct' depends on axioms: [propext, Quot.sound] -/+#guard_msgs in+#print axioms substOf_extends_of_keysDistinct++/-- info: 'OOCert.instantiation_unique_of_covers' depends on axioms: [propext, Quot.sound] -/+#guard_msgs in+#print axioms instantiation_unique_of_covers+/-- info: 'OOCert.horn_certificate_sound' depends on axioms: [propext, Classical.choice, Quot.sound] -/#guard_msgs in#print axioms horn_certificate_sounddiff --git a/lean/OOCert/HornWitness.lean b/lean/OOCert/HornWitness.leanindex 7a4144c8..a0b8fa92 100644--- a/lean/OOCert/HornWitness.lean+++ b/lean/OOCert/HornWitness.lean@@ -129,13 +129,56 @@ theorem the_repair_is_accepted :checkHornStep demoR (fun t => decide (t ∈ ⟨uB, uP, "z"⟩ :: demoG)) uncoveredRepaired= true := by decide-/-! ### The hypothesis of `wellFormed_determines_instantiation` is load-bearing+/-! ### Both halves of `wellFormed_determines_instantiation` are load-bearing-That theorem says a well-formed binding leaves nothing for a checker's choice of-representation to decide. It would be worth nothing if the conclusion held-anyway, so here is the counterexample: ONE binding list that is not well formed,-TWO total substitutions that both extend it, and two different conclusions. The-difference is exactly what the two kernels used to disagree about. -/+That theorem has two conjuncts and `bindingWellFormed` has two, and the pairing is+exact: distinct keys buy EXISTENCE and coverage buys UNIQUENESS. A theorem whose+conclusion held with its hypothesis dropped would be worth nothing, so each half is+refuted below with the matching half of the hypothesis removed.++Read a binding list as what it looks like: a set of demands, "`v` is `t`", one per+written pair. -/++/-! #### Drop distinctness and NOTHING meets the demands++This is the argument for refusing a repeated key, and it is stronger than the one+about tie-breaks. A variable bound twice to different values demands two+incompatible things, so no total substitution meets the certificate's own demands.+Not a substitution other than the one `List.lookup` picks: none at all. First-wins+and last-wins are therefore not two readings of this certificate. They are two+ways of ignoring half of it. -/++/-- The binding of `dupKey` above, named on its own so the two facts below can be+stated about the list rather than about the step. -/+def dupBind : List (Var × Term) := [("x", uA), ("y", uB), ("z", uC), ("x", uB)]++theorem dupBind_is_dupKey_binds : dupKey.binds = dupBind := rfl++/-- It COVERS `gpRule`, so the refusal below is distinctness alone and not+coverage wearing its coat. The mirror of `partialBind_keys_are_distinct`. -/+theorem dupBind_covers_the_rule : bindsCover gpRule dupBind = true := by decide++theorem dupBind_is_not_wellFormed : bindingWellFormed gpRule dupBind = false := by decide++theorem no_substitution_extends_a_duplicate_key :+ ¬ ∃ sigma : Subst, ∀ v t, (v, t) ∈ dupBind → sigma v = t := by+ rintro ⟨sigma, h⟩+ have h1 : sigma "x" = uA := h "x" uA (by simp [dupBind])+ have h2 : sigma "x" = uB := h "x" uB (by simp [dupBind])+ rw [h1] at h2+ exact absurd h2 (by decide)++/-- And with the keys distinct, `substOf` meets them, so the existence half is not+vacuously true of a hypothesis nothing satisfies. -/+theorem substOf_meets_the_demands_of_a_distinct_binding :+ ∀ v t, (v, t) ∈ demoStep.binds → substOf demoStep.binds v = t :=+ substOf_extends_of_keysDistinct (by decide)++/-! #### Drop coverage and TWO things meet the demands, disagreeing++One binding list, two total substitutions that both meet every demand it makes, and+two different conclusions. This is exactly what the two kernels used to disagree+about. -/def partialBind : List (Var × Term) := [("x", uA), ("y", uB)]@@ -147,18 +190,22 @@ def otherExt : Subst := fun v => (List.lookup v partialBind).getD uCtheorem partialBind_is_not_wellFormed :bindingWellFormed gpRule partialBind = false := by decide-theorem otherExt_extends_partialBind :- ∀ v t, List.lookup v partialBind = some t → otherExt v = t := by- intro v t h- simp [otherExt, h]+/-- `partialBind` has distinct keys, so the failure below is coverage ALONE. -/+theorem partialBind_keys_are_distinct : keysDistinct partialBind = true := by decide-theorem substOf_extends_partialBind :- ∀ v t, List.lookup v partialBind = some t → substOf partialBind v = t := by+theorem otherExt_meets_the_demands :+ ∀ v t, (v, t) ∈ partialBind → otherExt v = t := byintro v t h- simp [substOf, h]+ simp only [partialBind, List.mem_cons, List.not_mem_nil, or_false, Prod.mk.injEq] at h+ rcases h with ⟨hv, ht⟩ | ⟨hv, ht⟩ <;> subst hv <;> subst ht <;> rfl++theorem substOf_meets_the_demands :+ ∀ v t, (v, t) ∈ partialBind → substOf partialBind v = t :=+ substOf_extends_of_keysDistinct partialBind_keys_are_distinct-/-- Two extensions of one binding list, two conclusions. `wellFormed_determines_-instantiation` rules this out, and only because its hypothesis is not free. -/+/-- Two substitutions meeting the same demands, two conclusions. The uniqueness+half of `wellFormed_determines_instantiation` rules this out, and only because its+coverage hypothesis is not free. -/theorem two_extensions_of_an_uncovered_binding_disagree :AtomPat.inst otherExt gpRule.head ≠ AtomPat.inst (substOf partialBind) gpRule.head := bydecide