diff --git a/Bridge.lean b/Bridge.lean index 063efba..48e658c 100644 --- a/Bridge.lean +++ b/Bridge.lean @@ -2047,56 +2047,6 @@ attribute [simp] normalizeCompleteResult_keys_ne all_goals (try (exfalso; omega)) all_goals (try rfl) -@[simp] theorem tr_nonposRevReduced (r : RangeRead) (res : Result) (hne : res.keys ≠ []) : - FormalConflictRange.nonposRevReduced (toRefRead r) (toRefRes res) = toRefRead - (Statement.nonposRevReduced (r) (res)) := by - unfold FormalConflictRange.nonposRevReduced Statement.nonposRevReduced - simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last, - Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range, - Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin, - Statement.completeClosedWith, Statement.closedFormOffsetOneWith, Statement.closedFormSplit, - Statement.residualE, Statement.residualT, Statement.residualB, Statement.residualD, - FormalConflictRange.compactSplit, FormalConflictRange.residualE, - FormalConflictRange.residualT, FormalConflictRange.residualB, FormalConflictRange.residualD, - FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne] - all_goals (try rfl) - all_goals (try (intros; rfl)) - all_goals (try (intros; exact Iff.rfl)) - all_goals (try (intros; simp_all)) - all_goals (try (split_ifs <;> simp_all)) - all_goals (try (split <;> simp_all)) - all_goals (try order) - all_goals (try omega) - all_goals (try contradiction) - all_goals (try (exfalso; order)) - all_goals (try (exfalso; omega)) - all_goals (try rfl) - -@[simp] theorem tr_closedFormNonposRevTrunc (r : RangeRead) (res : Result) (hne : res.keys ≠ []) : - FormalConflictRange.closedFormNonposRevTrunc (toRefRead r) (toRefRes res) = toRefCR - (Statement.closedFormNonposRevTrunc (r) (res)) := by - unfold FormalConflictRange.closedFormNonposRevTrunc Statement.closedFormNonposRevTrunc - simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last, - Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range, - Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin, - Statement.completeClosedWith, Statement.closedFormOffsetOneWith, Statement.closedFormSplit, - Statement.residualE, Statement.residualT, Statement.residualB, Statement.residualD, - FormalConflictRange.compactSplit, FormalConflictRange.residualE, - FormalConflictRange.residualT, FormalConflictRange.residualB, FormalConflictRange.residualD, - FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne] - all_goals (try rfl) - all_goals (try (intros; rfl)) - all_goals (try (intros; exact Iff.rfl)) - all_goals (try (intros; simp_all)) - all_goals (try (split_ifs <;> simp_all)) - all_goals (try (split <;> simp_all)) - all_goals (try order) - all_goals (try omega) - all_goals (try contradiction) - all_goals (try (exfalso; order)) - all_goals (try (exfalso; omega)) - all_goals (try rfl) - @[simp] theorem tr_closedFormZeroCrossEndOneLong (r : RangeRead) (res : Result) (hne : res.keys ≠ []) : FormalConflictRange.closedFormZeroCrossEndOneLong (toRefRead r) (toRefRes res) = toRefCR @@ -2786,31 +2736,6 @@ attribute [simp] normalizeCompleteResult_keys_ne all_goals (try (exfalso; omega)) all_goals (try rfl) -@[simp] theorem tr_closedFormClamped (r : RangeRead) (res : Result) (hne : res.keys ≠ []) : - FormalConflictRange.compactClamped (toRefRead r) (toRefRes res) = toRefCR - (Statement.closedFormClamped (r) (res)) := by - unfold FormalConflictRange.compactClamped Statement.closedFormClamped - simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last, - Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range, - Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin, - Statement.completeClosedWith, Statement.closedFormOffsetOneWith, Statement.closedFormSplit, - Statement.residualE, Statement.residualT, Statement.residualB, Statement.residualD, - FormalConflictRange.compactSplit, FormalConflictRange.residualE, - FormalConflictRange.residualT, FormalConflictRange.residualB, FormalConflictRange.residualD, - FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne] - all_goals (try rfl) - all_goals (try (intros; rfl)) - all_goals (try (intros; exact Iff.rfl)) - all_goals (try (intros; simp_all)) - all_goals (try (split_ifs <;> simp_all)) - all_goals (try (split <;> simp_all)) - all_goals (try order) - all_goals (try omega) - all_goals (try contradiction) - all_goals (try (exfalso; order)) - all_goals (try (exfalso; omega)) - all_goals (try rfl) - @[simp] theorem tr_zeroCrossOvershootComplete (r : RangeRead) (res : Result) (hne : res.keys ≠ []) : FormalConflictRange.zeroCrossOvershootComplete (toRefRead r) (toRefRes res) ↔ Statement.zeroCrossOvershootComplete (r) (res) := by diff --git a/Proof.lean b/Proof.lean index 12d0baf..0627950 100644 --- a/Proof.lean +++ b/Proof.lean @@ -101,14 +101,62 @@ theorem minimal_iff (r : RangeRead) (res : Result) (cr : ConflictRange) : /-! ## The closed form -/ +/-- At a nonpositive begin offset the reversed-truncated rule with no begin skip +agrees with the clamped reference rule: both reduce to `compactReverseTruncatedZero`. -/ +theorem ref_closedFormNonposRevTrunc_eq (r : FormalConflictRange.RangeRead) + (res : FormalConflictRange.Result) (h : r.begin.offset ≤ 0) + (hm : res.more = true) (hr : r.reverse = true) : + FormalConflictRange.closedFormNonposRevTrunc r res = + FormalConflictRange.compactReverseTruncated r res := by + have hB : FormalConflictRange.residualB r = 0 := by + unfold FormalConflictRange.residualB + rw [Int.toNat_eq_zero] + omega + simp only [FormalConflictRange.closedFormNonposRevTrunc, + FormalConflictRange.compactReverseTruncated, hB, ite_true, + FormalConflictRange.closedFormOffsetOneTotal, + FormalConflictRange.nonposRevReduced, + FormalConflictRange.closedFormOffsetOneUniversal, hm, hr] + split <;> rfl + +/-- On a clamped nonpositive read the reference positive and clamped rules are the +same function: `compactClamped` differs from `compactPositive` only in the +reversed-truncated branch, where the begin offset is nonpositive and the clamp +makes the two rules coincide. -/ +theorem ref_compactClamped_eq_compactPositive (r : FormalConflictRange.RangeRead) + (res : FormalConflictRange.Result) (h : FormalConflictRange.clampedNonpos r res) : + FormalConflictRange.compactClamped r res = + FormalConflictRange.compactPositive r res := by + obtain ⟨hne, hbegin, _hlo⟩ := h + unfold FormalConflictRange.compactClamped FormalConflictRange.compactPositive + FormalConflictRange.compactSplit + by_cases hm : res.more = false + · simp [hm, hne] + · have hm' : res.more = true := by cases h : res.more <;> simp_all + simp only [hm] + by_cases hr : r.reverse = false + · simp [hr, hne] + · have hr' : r.reverse = true := by cases h : r.reverse <;> simp_all + simp [hr, hne, ref_closedFormNonposRevTrunc_eq r res hbegin hm' hr'] + 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] + · by_cases hpos : 1 ≤ r.begin.offset + · unfold FormalConflictRange.conflictRangeClosedFormClosed closedForm + simp [hne, hpos] + · by_cases hclamp : clampedNonpos r res + · have hclampRef : FormalConflictRange.clampedNonpos (toRefRead r) (toRefRes res) := by + obtain ⟨hb, hk⟩ := hclamp + exact ⟨hne, hb, hk⟩ + unfold FormalConflictRange.conflictRangeClosedFormClosed closedForm + rw [ref_compactClamped_eq_compactPositive _ _ hclampRef] + simp [hne, hpos, hclamp, FormalConflictRange.clampedNonpos, Statement.clampedNonpos] + · unfold FormalConflictRange.conflictRangeClosedFormClosed closedForm + simp [hne, hpos, hclamp] /-! ## The headlines -/ diff --git a/Statement.lean b/Statement.lean index eee8d11..29b96bd 100644 --- a/Statement.lean +++ b/Statement.lean @@ -26,18 +26,18 @@ The closed form is a total, result-aware dispatch: ``` closedForm r res = - if res.keys = [] then emptyValue r - else if 1 ≤ r.begin.offset then closedFormPositive r res - else if clampedNonpos r res then closedFormClamped r res - else closedFormCrossed r res + if res.keys = [] then emptyValue r + else if 1 ≤ r.begin.offset ∨ clampedNonpos r res then closedFormPositive r res + else closedFormCrossed r res ``` -`emptyValue` handles the empty result. `closedFormPositive` and -`closedFormClamped` dispatch through `closedFormSplit` on whether the result is -complete and, when it is not, on the direction. `closedFormCrossed` is the -residual: nonempty, nonpositive-begin reads outside the clamped case, handled by -a priority table over complete results and the two `more = true` cases (forward -and reversed), split by `reverse`, `end_.offset ≤ 1` and a few capacity tests. +`emptyValue` handles the empty result. Positive begin offsets and clamped +nonpositive begin offsets share one rule, `closedFormPositive`, which dispatches +through `closedFormSplit` on whether the result is complete and, when it is not, +on the direction. `closedFormCrossed` is the residual: nonempty, +nonpositive-begin reads outside the clamped case, handled by a priority table +over complete results and the two `more = true` cases (forward and reversed), +split by `reverse`, `end_.offset ≤ 1` and a few capacity tests. Every leaf of the table is a literal half-open interval built from `begin.key`, `end_.key`, the reported head or last key, `keyAfter`, or `⊤`; there is no search and no oracle. That is the sense in which it is a *closed form*. @@ -686,12 +686,6 @@ def closedFormOffsetOneTotal (r : RangeRead) (res : Result) : ConflictRange := else completeClosed r res else closedFormOffsetOneUniversal r res -def nonposRevReduced (r : RangeRead) (res : Result) : RangeRead := - { r with begin := { key := last res, offset := 1 } } - -def closedFormNonposRevTrunc (r : RangeRead) (res : Result) : ConflictRange := - closedFormOffsetOneTotal (nonposRevReduced r res) res - def closedFormZeroCrossEndOneLong (r : RangeRead) (res : Result) : ConflictRange := range (↑(leastReported r res)) r.begin.key @@ -885,12 +879,12 @@ def closedFormReverseTruncated (r : RangeRead) (res : Result) : ConflictRange := /-! ### Positive and clamped branches -/ +/-- The non-crossed rule. It covers every nonempty result at a positive begin +offset, and also every clamped nonpositive begin offset, where the begin clamps +to the empty key and the reversed-truncated rule reduces to the no-skip case. -/ def closedFormPositive (r : RangeRead) (res : Result) : ConflictRange := closedFormSplit closedFormReverseTruncated r res -def closedFormClamped (r : RangeRead) (res : Result) : ConflictRange := - closedFormSplit closedFormNonposRevTrunc r res - /-! ### Crossed table -/ @[reducible] def overshoot (r : RangeRead) (res : Result) : Prop := @@ -1111,11 +1105,11 @@ def closedFormCrossed (r : RangeRead) (res : Result) : ConflictRange := /-! ### Dispatch -/ /-- The closed form. The empty result is handled first, so every branch below -is reached only with `res.keys ≠ []`. -/ +is reached only with `res.keys ≠ []`. Positive and clamped nonpositive begin +offsets share the one rule `closedFormPositive`. -/ def closedForm (r : RangeRead) (res : Result) : ConflictRange := if res.keys = [] then emptyValue r - else if 1 ≤ r.begin.offset then closedFormPositive r res - else if clampedNonpos r res then closedFormClamped r res + else if 1 ≤ r.begin.offset ∨ clampedNonpos r res then closedFormPositive r res else closedFormCrossed r res /-! ## The headlines -/