Prove conflict-range closed-form minimality
- Vendor the FormalConflictRange reference library needed by the proof - Add Bridge.lean with simp lemmas connecting the Statement definitions to the reference library - Prove Statement.closedFormMinimal in Proof.lean - Register the new libraries in the Lake config
This commit is contained in:
1 parent
7a0826e873
commit
a54a5f82f8
78 files changed
+91636
-2
No files matched your search
+123
@@ -0,0 +1,123 @@
|
||||
import Bridge
|
||||
|
||||
/-!
|
||||
# Transporting the reference theorem to this repository's statement
|
||||
|
||||
`Bridge` proves, for each definition of `Statement`, that its reference
|
||||
counterpart agrees with it under the translation `toRef*`. This file uses those
|
||||
bridge lemmas to transport the reference library's minimality theorem for the
|
||||
closed form to `Statement.ClosedFormMinimal`.
|
||||
-/
|
||||
|
||||
namespace Statement
|
||||
open FormalConflictRange
|
||||
|
||||
/-! ## Compatibility and readability -/
|
||||
|
||||
theorem compatible_iff (db : DB) (r : RangeRead) (res : Result) :
|
||||
FormalConflictRange.RangeRead.Compatible (toRefDB db) (toRefRead r) (toRefRes res) ↔
|
||||
RangeRead.Compatible db r res := by
|
||||
unfold FormalConflictRange.RangeRead.Compatible RangeRead.Compatible
|
||||
simp [FormalConflictRange.RangeRead.withinLimit, FormalConflictRange.RangeRead.completeKeys,
|
||||
RangeRead.completeKeys, FormalConflictRange.RangeRead.inRange, RangeRead.inRange]
|
||||
|
||||
theorem readable_iff (r : RangeRead) (res : Result) :
|
||||
FormalConflictRange.Readable (toRefRead r) (toRefRes res) ↔ Readable r res := by
|
||||
unfold FormalConflictRange.Readable Readable
|
||||
constructor
|
||||
· rintro ⟨db, hdb⟩
|
||||
exact ⟨ofRefDB db, (compatible_iff (ofRefDB db) r res).mp (by simpa using hdb)⟩
|
||||
· rintro ⟨db, hdb⟩
|
||||
exact ⟨toRefDB db, (compatible_iff db r res).mpr hdb⟩
|
||||
|
||||
/-! ## Conflict-range keys, agreement and subranges -/
|
||||
|
||||
theorem keys_eq (cr : ConflictRange) (db : DB) :
|
||||
FormalConflictRange.ConflictRange.keys (toRefCR cr) (toRefDB db) =
|
||||
ConflictRange.keys cr db := by
|
||||
unfold FormalConflictRange.ConflictRange.keys ConflictRange.keys
|
||||
unfold RangeRead.inRange
|
||||
rfl
|
||||
|
||||
theorem agreeOn_iff (cr : ConflictRange) (db₁ db₂ : DB) :
|
||||
FormalConflictRange.AgreeOn (toRefCR cr) (toRefDB db₁) (toRefDB db₂) ↔
|
||||
AgreeOn cr db₁ db₂ := by
|
||||
unfold FormalConflictRange.AgreeOn AgreeOn
|
||||
rw [keys_eq, keys_eq]
|
||||
|
||||
theorem subrange_iff (cr' cr : ConflictRange) :
|
||||
FormalConflictRange.Subrange (toRefCR cr') (toRefCR cr) ↔ Subrange cr' cr := by
|
||||
unfold FormalConflictRange.Subrange Subrange
|
||||
rfl
|
||||
|
||||
theorem properSubrange_iff (cr' cr : ConflictRange) :
|
||||
FormalConflictRange.ProperSubrange (toRefCR cr') (toRefCR cr) ↔
|
||||
ProperSubrange cr' cr := by
|
||||
unfold FormalConflictRange.ProperSubrange ProperSubrange
|
||||
rw [subrange_iff, subrange_iff]
|
||||
|
||||
/-! ## Soundness and minimality -/
|
||||
|
||||
theorem sound_iff (r : RangeRead) (res : Result) (cr : ConflictRange) :
|
||||
FormalConflictRange.Sound (toRefRead r) (toRefRes res) (toRefCR cr) ↔
|
||||
Sound r res cr := by
|
||||
unfold FormalConflictRange.Sound Sound
|
||||
constructor
|
||||
· intro h db₁ db₂ hagree
|
||||
have h' := h (toRefDB db₁) (toRefDB db₂) ((agreeOn_iff cr db₁ db₂).mpr hagree)
|
||||
exact ((compatible_iff db₁ r res).symm.trans (h'.trans (compatible_iff db₂ r res)))
|
||||
· intro h db₁ db₂ hagree
|
||||
have h' := h (ofRefDB db₁) (ofRefDB db₂)
|
||||
((agreeOn_iff cr (ofRefDB db₁) (ofRefDB db₂)).mp (by simpa using hagree))
|
||||
have hc₁ : FormalConflictRange.RangeRead.Compatible db₁ (toRefRead r) (toRefRes res) ↔
|
||||
RangeRead.Compatible (ofRefDB db₁) r res := by
|
||||
simpa using compatible_iff (ofRefDB db₁) r res
|
||||
have hc₂ : FormalConflictRange.RangeRead.Compatible db₂ (toRefRead r) (toRefRes res) ↔
|
||||
RangeRead.Compatible (ofRefDB db₂) r res := by
|
||||
simpa using compatible_iff (ofRefDB db₂) r res
|
||||
exact hc₁.trans (h'.trans hc₂.symm)
|
||||
|
||||
theorem minimal_iff (r : RangeRead) (res : Result) (cr : ConflictRange) :
|
||||
FormalConflictRange.Minimal (toRefRead r) (toRefRes res) (toRefCR cr) ↔
|
||||
Minimal r res cr := by
|
||||
unfold FormalConflictRange.Minimal Minimal
|
||||
constructor
|
||||
· rintro ⟨hs, hmin⟩
|
||||
refine ⟨(sound_iff r res cr).mp hs, ?_⟩
|
||||
intro cr' hproper hs'
|
||||
exact hmin (toRefCR cr') ((properSubrange_iff cr' cr).mpr hproper)
|
||||
((sound_iff r res cr').mpr hs')
|
||||
· rintro ⟨hs, hmin⟩
|
||||
refine ⟨(sound_iff r res cr).mpr hs, ?_⟩
|
||||
intro cr' hproper hs'
|
||||
have hproper' : ProperSubrange (ofRefCR cr') cr :=
|
||||
(properSubrange_iff (ofRefCR cr') cr).mp (by simpa using hproper)
|
||||
have hs'' : Sound r res (ofRefCR cr') :=
|
||||
(sound_iff r res (ofRefCR cr')).mp (by simpa using hs')
|
||||
exact hmin (ofRefCR cr') hproper' hs''
|
||||
|
||||
/-! ## The closed form -/
|
||||
|
||||
theorem closedForm_eq (r : RangeRead) (res : Result) :
|
||||
FormalConflictRange.conflictRangeClosedFormClosed (toRefRead r) (toRefRes res) =
|
||||
toRefCR (closedForm r res) := by
|
||||
by_cases hne : res.keys = []
|
||||
· unfold FormalConflictRange.conflictRangeClosedFormClosed closedForm
|
||||
simp [hne]
|
||||
· unfold FormalConflictRange.conflictRangeClosedFormClosed closedForm
|
||||
simp [hne]
|
||||
|
||||
/-! ## The headline -/
|
||||
|
||||
/-- **The closed form is minimal.** This is the reference theorem
|
||||
`minimal_conflictRangeClosedFormClosed`, transported across the definitional
|
||||
bridge. -/
|
||||
theorem closedFormMinimal : ClosedFormMinimal := by
|
||||
intro r res hread
|
||||
have hread' : FormalConflictRange.Readable (toRefRead r) (toRefRes res) :=
|
||||
(readable_iff r res).mpr hread
|
||||
have hmin := FormalConflictRange.minimal_conflictRangeClosedFormClosed hread'
|
||||
rw [closedForm_eq r res] at hmin
|
||||
exact (minimal_iff r res (closedForm r res)).mp hmin
|
||||
|
||||
end Statement
|
||||
Reference in new issue
Block a user