Simplify the closed-form statement

Collapse duplicated cells and share their conditions:

- Merge the crossed complete clamp cells.  They all fall through to
  `end_.key`, and only the bottom / infinite / head-bottom / last-ge cells
  conflict with the long nonpositive cell, so test `negCrossClampNonposLastGe`
  explicitly and let the rest share the fall-through.
- Allow `r.end_.offset ≤ 1` in the crossed truncated nonpositive cell and
  merge it with the old `...Small` cell into `negCrossTruncRevCrossedLow`.
- Use `overshoot r res` in `negCrossOvershoot` and
  `negCrossTruncRevBelowEnd` instead of spelling out the same key bound.
- Drop the `r.begin.key ≤ r.end_.key` shortcut in `emptyValue`; the
  cardinality branch below already returns `bottom..end_.key` in that case.
- Inline the single-use helpers: `...TruncRevBelowEnd`,
  `...TruncRevCrossedNonposLarge`, `...ResidualFiniteUnder`,
  `...ResidualTopLargeSentinel`, `...TruncRevUnder` and
  `...TruncTopTopEq`.

`Bridge.lean` follows the removed cells, keeping the deleted reference
predicate as a private legacy abbreviation for the bridge proof.
`lake build` is clean.
This commit is contained in:
andrew committed 2026-11-17 16:05:43 -05:00
1 parent 6cfdb13da1
commit 6559cc582b
2 files changed
+350 -307

No files matched your search

+323 -232
View File
@@ -719,11 +719,22 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_negCrossClampNonposInfinite (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
private abbrev negCrossClampNonposInfiniteLegacy (r : RangeRead) (res : Result) : Prop :=
r.reverse = false ∧
r.begin.offset < 0 ∧
res.more = false ∧
r.end_.offset ≤ 0 ∧
r.begin.key ≤ r.end_.key ∧
intervalCard r.begin.key r.end_.key = ⊤ ∧
first res < r.begin.key ∧
reportedBelowBegin r res ≤ beginSlack r
@[simp] private theorem tr_negCrossClampNonposInfiniteLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.negCrossClampNonposInfinite (toRefRead r) (toRefRes res) ↔
Statement.negCrossClampNonposInfinite (r) (res) := by
unfold FormalConflictRange.negCrossClampNonposInfinite Statement.negCrossClampNonposInfinite
negCrossClampNonposInfiniteLegacy (r) (res) := by
unfold FormalConflictRange.negCrossClampNonposInfinite
negCrossClampNonposInfiniteLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -820,11 +831,77 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossClampUnified (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
FormalConflictRange.closedFormNegCrossClampUnified (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossClampUnified (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossClampUnified Statement.closedFormNegCrossClampUnified
theorem not_negCrossHeadBottom_of_negCrossClampLongNonpos (r : RangeRead) (res : Result)
(hL : negCrossClampLongNonpos r res) : ¬ negCrossHeadBottom r res := by
intro h
unfold negCrossHeadBottom at h
unfold negCrossClampLongNonpos at hL
obtain ⟨_, _, _, _, hBE, _⟩ := h
obtain ⟨_, _, _, _, _, _, _, hEB⟩ := hL
exact (not_lt_of_ge hBE) hEB
theorem not_negCrossClampNonposInfiniteLegacy_of_negCrossClampLongNonpos (r : RangeRead)
(res : Result) (hL : negCrossClampLongNonpos r res) :
¬ negCrossClampNonposInfiniteLegacy r res := by
intro h
unfold negCrossClampNonposInfiniteLegacy at h
unfold negCrossClampLongNonpos at hL
obtain ⟨_, _, _, _, hBE, _, _, _⟩ := h
obtain ⟨_, _, _, _, _, _, _, hEB⟩ := hL
exact (not_lt_of_ge hBE) hEB
theorem not_negCrossClampNonposBottom_of_negCrossClampLongNonpos (r : RangeRead)
(res : Result) (hL : negCrossClampLongNonpos r res) :
¬ negCrossClampNonposBottom r res := by
intro h
unfold negCrossClampNonposBottom at h
unfold negCrossClampLongNonpos at hL
obtain ⟨_, _, _, _, hBE, _, _⟩ := h
obtain ⟨_, _, _, _, _, _, _, hEB⟩ := hL
exact (not_lt_of_ge hBE) hEB
/-- The legacy priority-table shape of the clamping rule, matching the reference
`closedFormNegCrossClampUnified`. It is kept as one shared expression so the bridge
proof can rewrite to it before applying `closedFormNegCrossClampUnifiedLegacy_eq`. -/
private def closedFormNegCrossClampUnifiedLegacy (r : RangeRead) (res : Result) :
ConflictRange :=
let end_ :=
if negCrossClampEndOne r res then clampEndOneUpper r res
else if
negCrossHeadBottom r res ∨
negCrossClampNonposInfiniteLegacy r res ∨
negCrossClampNonposLastGe r res ∨
negCrossClampNonposBottom r res then
r.end_.key
else if negCrossClampLongNonpos r res then clampLongUpper r res
else r.end_.key
range bottom end_
/-- The legacy clamped-unified rule can drop the three middle cases that simply return
`r.end_.key`: each of them contradicts `negCrossClampLongNonpos` by the ordering of the
two selector keys. `negCrossClampNonposLastGe` has no such key-order field, so it alone
can overlap the long cell and remains as a guard. -/
private theorem closedFormNegCrossClampUnifiedLegacy_eq (r : RangeRead) (res : Result) :
closedFormNegCrossClampUnifiedLegacy r res = closedFormNegCrossClampUnified r res := by
unfold closedFormNegCrossClampUnifiedLegacy closedFormNegCrossClampUnified
dsimp only
by_cases hE : negCrossClampEndOne r res
· rw [ite_eq_left hE, ite_eq_left hE]
· by_cases hL : negCrossClampLongNonpos r res
· have hB1 := not_negCrossHeadBottom_of_negCrossClampLongNonpos r res hL
have hB2 := not_negCrossClampNonposInfiniteLegacy_of_negCrossClampLongNonpos r res hL
have hB4 := not_negCrossClampNonposBottom_of_negCrossClampLongNonpos r res hL
by_cases hB3 : negCrossClampNonposLastGe r res <;>
simp [hE, hL, hB1, hB2, hB3, hB4]
· simp [hE, hL]
/-- The legacy shape is the reference shape, so this is the original bridge lemma. -/
private theorem tr_closedFormNegCrossClampUnifiedLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossClampUnified (toRefRead r) (toRefRes res) =
toRefCR (closedFormNegCrossClampUnifiedLegacy r res) := by
unfold FormalConflictRange.closedFormNegCrossClampUnified
closedFormNegCrossClampUnifiedLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -846,6 +923,13 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossClampUnified (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
FormalConflictRange.closedFormNegCrossClampUnified (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossClampUnified (r) (res)) := by
rw [tr_closedFormNegCrossClampUnifiedLegacy r res hne]
exact congrArg toRefCR (closedFormNegCrossClampUnifiedLegacy_eq r res)
@[simp] theorem tr_negCrossCompleteHighM (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.negCrossCompleteHighM (toRefRead r) (toRefRes res) =
Statement.negCrossCompleteHighM (r) (res) := by
@@ -1116,8 +1200,8 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossEndOneLong (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
@[simp] theorem tr_closedFormNegCrossEndOneLong (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossEndOneLong (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossEndOneLong (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossEndOneLong Statement.closedFormNegCrossEndOneLong
@@ -1355,60 +1439,6 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossTruncRevBelowEnd (_r : RangeRead) (res : Result) (hne :
res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossTruncRevBelowEnd (toRefRead _r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossTruncRevBelowEnd (_r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevBelowEnd
Statement.closedFormNegCrossTruncRevBelowEnd
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_closedFormNegCrossTruncRevCrossedNonposLarge (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossTruncRevCrossedNonposLarge (toRefRead r) (toRefRes res)
= toRefCR (Statement.closedFormNegCrossTruncRevCrossedNonposLarge (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevCrossedNonposLarge
Statement.closedFormNegCrossTruncRevCrossedNonposLarge
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_finiteUnderCond (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.finiteUnderCond (toRefRead r) (toRefRes res) ↔ Statement.finiteUnderCond
(r) (res) := by
@@ -1434,33 +1464,6 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossTruncRevResidualFiniteUnder (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossTruncRevResidualFiniteUnder (toRefRead r) (toRefRes res)
= toRefCR (Statement.closedFormNegCrossTruncRevResidualFiniteUnder (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevResidualFiniteUnder
Statement.closedFormNegCrossTruncRevResidualFiniteUnder
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_negCrossTruncRevResidualFiniteOver (r : RangeRead) (res : Result) (hne :
res.keys ≠ []) :
FormalConflictRange.negCrossTruncRevResidualFiniteOver (toRefRead r) (toRefRes res) ↔
@@ -1489,6 +1492,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
FormalConflictRange.closedFormNegCrossTruncRevResidualFiniteUnified (toRefRead r) (toRefRes
res) = toRefCR (Statement.closedFormNegCrossTruncRevResidualFiniteUnified (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevResidualFiniteUnified
FormalConflictRange.closedFormNegCrossTruncRevResidualFiniteUnder
Statement.closedFormNegCrossTruncRevResidualFiniteUnified
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
@@ -1536,33 +1540,6 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossTruncRevResidualTopLargeSentinel (r : RangeRead) (res :
Result) (hne : res.keys ≠ []) :
FormalConflictRange.closedFormNegCrossTruncRevResidualTopLargeSentinel (toRefRead r) (toRefRes
res) = toRefCR (Statement.closedFormNegCrossTruncRevResidualTopLargeSentinel (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevResidualTopLargeSentinel
Statement.closedFormNegCrossTruncRevResidualTopLargeSentinel
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_negCrossTruncRevResidualTopLarge (r : RangeRead) (res : Result) (hne : res.keys
≠ []) :
FormalConflictRange.negCrossTruncRevResidualTopLarge (toRefRead r) (toRefRes res) ↔
@@ -1619,27 +1596,12 @@ attribute [simp] normalizeCompleteResult_keys_ne
FormalConflictRange.closedFormNegCrossTruncRevResidualTopLargeUnified (toRefRead r) (toRefRes
res) = toRefCR (Statement.closedFormNegCrossTruncRevResidualTopLargeUnified (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevResidualTopLargeUnified
FormalConflictRange.closedFormNegCrossTruncRevResidualTopLargeSentinel
Statement.closedFormNegCrossTruncRevResidualTopLargeUnified
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)
have hS := tr_negCrossTruncRevResidualTopLargeSentinel r res hne
have hT := tr_sentinelLargeTight r res hne
simp only [hS, hT, Statement.last]
split_ifs <;> simp_all
@[simp] theorem tr_truncatedRangeRev (r : RangeRead) (last : Key) :
FormalConflictRange.truncatedRangeRev (toRefRead r) (last) = toRefCR
@@ -1666,60 +1628,6 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_closedFormNegCrossTruncRevUnder (r : RangeRead) (res : Result) (hne : res.keys
≠ []) :
FormalConflictRange.closedFormNegCrossTruncRevUnder (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossTruncRevUnder (r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncRevUnder
Statement.closedFormNegCrossTruncRevUnder
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_closedFormNegCrossTruncTopTopEq (_r : RangeRead) (res : Result) (hne : res.keys
≠ []) :
FormalConflictRange.closedFormNegCrossTruncTopTopEq (toRefRead _r) (toRefRes res) = toRefCR
(Statement.closedFormNegCrossTruncTopTopEq (_r) (res)) := by
unfold FormalConflictRange.closedFormNegCrossTruncTopTopEq
Statement.closedFormNegCrossTruncTopTopEq
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_closedFormReverseTruncatedZero (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
FormalConflictRange.closedFormOffsetOneTruncatedRevFullC (toRefRead r) (toRefRes res) =
@@ -2424,9 +2332,39 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_emptyValue (r : RangeRead) :
FormalConflictRange.emptyValue (toRefRead r) = toRefCR (Statement.emptyValue (r)) := by
unfold FormalConflictRange.emptyValue Statement.emptyValue
private def emptyValueLegacy (r : RangeRead) : ConflictRange :=
if AlwaysEmpty r then emptyRange r
else if r.begin.offset ≤ 0 then
if 2 ≤ r.end_.offset then range bottom ⊤
else if r.begin.key ≤ r.end_.key then range bottom r.end_.key
else if intervalCard r.end_.key r.begin.key < ↑(r.end_.offset - r.begin.offset).toNat then
range bottom r.end_.key
else range bottom (max r.begin.key r.end_.key)
else if r.end_.offset ≤ 1 then canonicalRange r
else if r.begin.key ≤ r.end_.key then topRange r else crossedRangeGeneral r
/-- The explicit `begin.key ≤ end_.key` branch is redundant: when it holds, the
capacity test below returns the same bottom-to-`end_.key` range on both sides, and when
the capacity test fails the fallback's `max` is just `end_.key`. -/
private theorem emptyValueLegacy_eq (r : RangeRead) : emptyValueLegacy r = emptyValue r := by
rw [emptyValueLegacy, emptyValue]
by_cases hA : AlwaysEmpty r
· rw [ite_eq_left hA, ite_eq_left hA]
· rw [ite_eq_right hA, ite_eq_right hA]
by_cases hb : r.begin.offset ≤ 0
· by_cases h2 : 2 ≤ r.end_.offset
· simp [hb, h2]
· by_cases hle : r.begin.key ≤ r.end_.key
· by_cases hcap : intervalCard r.end_.key r.begin.key <
↑(r.end_.offset - r.begin.offset).toNat
· simp [hb, h2, hle, hcap]
· simp [hb, h2, hle, hcap, max_eq_right hle]
· simp [hb, h2, hle]
· simp [hb]
private theorem tr_emptyValueLegacy (r : RangeRead) :
FormalConflictRange.emptyValue (toRefRead r) = toRefCR (emptyValueLegacy r) := by
unfold FormalConflictRange.emptyValue emptyValueLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -2448,6 +2386,11 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_emptyValue (r : RangeRead) :
FormalConflictRange.emptyValue (toRefRead r) = toRefCR (Statement.emptyValue (r)) := by
rw [tr_emptyValueLegacy r]
exact congrArg toRefCR (emptyValueLegacy_eq r)
@[simp] theorem tr_closedFormBegin (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.compactBegin (toRefRead r) (toRefRes res) = Statement.closedFormBegin (r)
(res) := by
@@ -2765,6 +2708,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
FormalConflictRange.negCrossOvershoot (toRefRead r) (toRefRes res) ↔
Statement.negCrossOvershoot (r) (res) := by
unfold FormalConflictRange.negCrossOvershoot Statement.negCrossOvershoot
unfold Statement.overshoot
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -2772,7 +2716,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
Statement.residualE, Statement.residualT, Statement.residualB, Statement.residualD,
FormalConflictRange.compactSplit, FormalConflictRange.residualE,
FormalConflictRange.residualT, FormalConflictRange.residualB, FormalConflictRange.residualD,
FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne]
FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne, and_assoc]
all_goals (try rfl)
all_goals (try (intros; rfl))
all_goals (try (intros; exact Iff.rfl))
@@ -2911,10 +2855,52 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_crossedCompleteClamp (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
/-- The head-bottom, infinite and bottom predicates each imply `begin.key ≤ end_.key`,
while the long nonpositive cell requires `end_.key < begin.key`. Hence the infinite
cell is covered by either the earlier `crossedCompleteEndLeOne` branch or by the bottom
cell. -/
private theorem infinite_subsumed_of_not_endLeOne (r : RangeRead) (res : Result)
(hE : ¬ crossedCompleteEndLeOne r res)
(h : negCrossClampNonposInfiniteLegacy r res) : negCrossClampNonposBottom r res := by
unfold negCrossClampNonposInfiniteLegacy at h
obtain ⟨hr, hb, hm, hend, hBE, _hcap, hfb, _hrep⟩ := h
refine ⟨hr, hb, hm, hend, hBE, hfb, ?_⟩
by_contra hbot
exact hE ⟨hr, hm, by omega, hfb, Or.inr ⟨hend, by
rintro ⟨_, hb'⟩
exact hbot hb'⟩⟩
/-- The last-ge clamp cell is covered by the earlier end-le-one branch unless the
bottom clamp holds; in that case `begin.key ≤ end_.key` gives the bottom cell and
`end_.key < begin.key` gives the long nonpositive cell. -/
private theorem lastGe_subsumed_of_not_endLeOne (r : RangeRead) (res : Result)
(hE : ¬ crossedCompleteEndLeOne r res)
(h : negCrossClampNonposLastGe r res) :
negCrossClampNonposBottom r res ∨ negCrossClampLongNonpos r res := by
unfold negCrossClampNonposLastGe at h
obtain ⟨hr, hb, hm, hend, hfb, _hlast, hrep⟩ := h
have hbot : clampNonposBottom r res := by
by_contra hbot
exact hE ⟨hr, hm, by omega, hfb, Or.inr ⟨hend, by
rintro ⟨_, hb'⟩
exact hbot hb'⟩⟩
by_cases hBE : r.begin.key ≤ r.end_.key
· exact Or.inl ⟨hr, hb, hm, hend, hBE, hfb, hbot⟩
· exact Or.inr ⟨hr, hb, hm, hend, hfb, hrep, hbot, not_le.mp hBE⟩
/-- The legacy six-way clamping predicate used by the reference dispatcher. -/
private abbrev crossedCompleteClampLegacy (r : RangeRead) (res : Result) : Prop :=
negCrossClampEndOne r res ∨
negCrossHeadBottom r res ∨
negCrossClampNonposInfiniteLegacy r res ∨
negCrossClampNonposLastGe r res ∨
negCrossClampNonposBottom r res ∨ negCrossClampLongNonpos r res
private theorem tr_crossedCompleteClampLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.crossedCompleteClamp (toRefRead r) (toRefRes res) ↔
Statement.crossedCompleteClamp (r) (res) := by
unfold FormalConflictRange.crossedCompleteClamp Statement.crossedCompleteClamp
crossedCompleteClampLegacy r res := by
unfold FormalConflictRange.crossedCompleteClamp crossedCompleteClampLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -2936,30 +2922,90 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
set_option synthInstance.maxSize 10000 in
private def closedFormCrossedCompleteLegacy (r : RangeRead) (res : Result) : ConflictRange :=
if crossedCompleteOvershoot r res then closedFormNegCrossTopUnified r res
else if crossedCompleteEndLeOne r res then
closedFormNegCrossNonclampUnified r res
else if crossedCompleteBeginZero r res then closedFormZeroCrossResidual r res
else if crossedCompleteClampLegacy r res then closedFormNegCrossClampUnified r res
else closedFormNegCrossCompleteHighResidual r res
/-- Removing the two clamp cells covered by the earlier end-le-one branch does not
change the crossed-complete dispatcher. -/
private theorem closedFormCrossedCompleteLegacy_eq (r : RangeRead) (res : Result) :
closedFormCrossedCompleteLegacy r res = closedFormCrossedComplete r res := by
unfold closedFormCrossedCompleteLegacy closedFormCrossedComplete
by_cases hO : crossedCompleteOvershoot r res
· rw [ite_eq_left hO, ite_eq_left hO]
· rw [ite_eq_right hO, ite_eq_right hO]
by_cases hE : crossedCompleteEndLeOne r res
· rw [ite_eq_left hE, ite_eq_left hE]
· rw [ite_eq_right hE, ite_eq_right hE]
by_cases hB : crossedCompleteBeginZero r res
· rw [ite_eq_left hB, ite_eq_left hB]
· rw [ite_eq_right hB, ite_eq_right hB]
have hclamp : crossedCompleteClampLegacy r res ↔ crossedCompleteClamp r res := by
constructor
· intro hL
unfold crossedCompleteClampLegacy at hL
unfold crossedCompleteClamp
rcases hL with h | h | h | h | h | h
· exact Or.inl h
· exact Or.inr (Or.inl h)
· exact Or.inr (Or.inr (Or.inl
(infinite_subsumed_of_not_endLeOne r res hE h)))
· rcases lastGe_subsumed_of_not_endLeOne r res hE h with h' | h'
· exact Or.inr (Or.inr (Or.inl h'))
· exact Or.inr (Or.inr (Or.inr h'))
· exact Or.inr (Or.inr (Or.inl h))
· exact Or.inr (Or.inr (Or.inr h))
· intro hC
unfold crossedCompleteClampLegacy
unfold crossedCompleteClamp at hC
rcases hC with h | h | h | h
· exact Or.inl h
· exact Or.inr (Or.inl h)
· exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))
· exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr h))))
by_cases hC : crossedCompleteClamp r res
· have hCL : crossedCompleteClampLegacy r res := hclamp.mpr hC
simp [hO, hE, hB, hC, hCL]
· have hCL : ¬ crossedCompleteClampLegacy r res := fun h => hC (hclamp.mp h)
simp [hO, hE, hB, hC, hCL]
private theorem tr_closedFormCrossedCompleteLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.compactCrossedComplete (toRefRead r) (toRefRes res) =
toRefCR (closedFormCrossedCompleteLegacy r res) := by
unfold FormalConflictRange.compactCrossedComplete closedFormCrossedCompleteLegacy
simp [tr_crossedCompleteClampLegacy r res hne,
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_closedFormCrossedComplete (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.compactCrossedComplete (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormCrossedComplete (r) (res)) := by
unfold FormalConflictRange.compactCrossedComplete Statement.closedFormCrossedComplete
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)
rw [tr_closedFormCrossedCompleteLegacy r res hne]
exact congrArg toRefCR (closedFormCrossedCompleteLegacy_eq r res)
@[simp] theorem tr_zeroCrossTruncRevCrossed (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.zeroCrossTruncRevCrossed (toRefRead r) (toRefRes res) ↔
@@ -3011,12 +3057,33 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_negCrossTruncRevCrossedNonposSmall (r : RangeRead) (res : Result) (hne :
res.keys ≠ []) :
private abbrev negCrossTruncRevCrossedNonposSmallLegacy (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
r.begin.offset < 0 ∧
last res < r.begin.key ∧
r.end_.key < r.begin.key ∧
r.end_.offset ≤ 0 ∧
intervalCard r.end_.key r.begin.key + ↑res.keys.length +
↑(1 - r.end_.offset).toNat ≤
↑(beginSlack r) + 1
private abbrev negCrossTruncRevCrossedSmallLegacy (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
r.begin.offset < 0 ∧
last res < r.begin.key ∧
r.end_.key < r.begin.key ∧
r.end_.offset = 1 ∧
intervalCard r.end_.key r.begin.key + ↑res.keys.length ≤
↑(beginSlack r) + 1
@[simp] private theorem tr_negCrossTruncRevCrossedNonposSmallLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.negCrossTruncRevCrossedNonposSmall (toRefRead r) (toRefRes res) ↔
Statement.negCrossTruncRevCrossedNonposSmall (r) (res) := by
negCrossTruncRevCrossedNonposSmallLegacy (r) (res) := by
unfold FormalConflictRange.negCrossTruncRevCrossedNonposSmall
Statement.negCrossTruncRevCrossedNonposSmall
negCrossTruncRevCrossedNonposSmallLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -3038,11 +3105,12 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
@[simp] theorem tr_negCrossTruncRevCrossedSmall (r : RangeRead) (res : Result) (hne : res.keys ≠
[]) :
@[simp] private theorem tr_negCrossTruncRevCrossedSmallLegacy (r : RangeRead) (res : Result)
(hne : res.keys ≠ []) :
FormalConflictRange.negCrossTruncRevCrossedSmall (toRefRead r) (toRefRes res) ↔
Statement.negCrossTruncRevCrossedSmall (r) (res) := by
unfold FormalConflictRange.negCrossTruncRevCrossedSmall Statement.negCrossTruncRevCrossedSmall
negCrossTruncRevCrossedSmallLegacy (r) (res) := by
unfold FormalConflictRange.negCrossTruncRevCrossedSmall
negCrossTruncRevCrossedSmallLegacy
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -3064,11 +3132,28 @@ attribute [simp] normalizeCompleteResult_keys_ne
all_goals (try (exfalso; omega))
all_goals (try rfl)
private theorem negCrossTruncRevCrossedLowLegacy_iff (r : RangeRead) (res : Result) :
(negCrossTruncRevCrossedNonposSmallLegacy r res ∨
negCrossTruncRevCrossedSmallLegacy r res) ↔
negCrossTruncRevCrossedLow r res := by
unfold negCrossTruncRevCrossedNonposSmallLegacy negCrossTruncRevCrossedSmallLegacy
negCrossTruncRevCrossedLow
constructor
· rintro (⟨hm, hr, hb, hl, he, h0, hcap⟩ | ⟨hm, hr, hb, hl, he, h1, hcap⟩)
· exact ⟨hm, hr, hb, hl, he, by omega, hcap⟩
· exact ⟨hm, hr, hb, hl, he, by omega, by simpa [h1] using hcap⟩
· rintro ⟨hm, hr, hb, hl, he, hle, hcap⟩
by_cases h0 : r.end_.offset ≤ 0
· exact Or.inl ⟨hm, hr, hb, hl, he, h0, hcap⟩
· have h1 : r.end_.offset = 1 := by omega
exact Or.inr ⟨hm, hr, hb, hl, he, h1, by simpa [h1] using hcap⟩
@[simp] theorem tr_revTruncLeOneLow (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.revTruncLeOneLow (toRefRead r) (toRefRes res) ↔ Statement.revTruncLeOneLow
(r) (res) := by
unfold FormalConflictRange.revTruncLeOneLow Statement.revTruncLeOneLow
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
simp [negCrossTruncRevCrossedLowLegacy_iff r res, 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,
@@ -3093,6 +3178,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
FormalConflictRange.negCrossTruncRevBelowEnd (toRefRead r) (toRefRes res) ↔
Statement.negCrossTruncRevBelowEnd (r) (res) := by
unfold FormalConflictRange.negCrossTruncRevBelowEnd Statement.negCrossTruncRevBelowEnd
unfold Statement.overshoot
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
@@ -3100,7 +3186,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
Statement.residualE, Statement.residualT, Statement.residualB, Statement.residualD,
FormalConflictRange.compactSplit, FormalConflictRange.residualE,
FormalConflictRange.residualT, FormalConflictRange.residualB, FormalConflictRange.residualD,
FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne]
FormalConflictRange.endOvershoot, FormalConflictRange.reportedAtEnd, hne, and_assoc]
all_goals (try rfl)
all_goals (try (intros; rfl))
all_goals (try (intros; exact Iff.rfl))
@@ -3474,6 +3560,7 @@ attribute [simp] normalizeCompleteResult_keys_ne
FormalConflictRange.compactForwardTruncatedNonpos (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormForwardTruncatedNonpos (r) (res)) := by
unfold FormalConflictRange.compactForwardTruncatedNonpos
FormalConflictRange.closedFormNegCrossTruncTopTopEq
Statement.closedFormForwardTruncatedNonpos
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
@@ -3499,7 +3586,11 @@ attribute [simp] normalizeCompleteResult_keys_ne
@[simp] theorem tr_closedFormCrossed (r : RangeRead) (res : Result) (hne : res.keys ≠ []) :
FormalConflictRange.compactCrossed (toRefRead r) (toRefRes res) = toRefCR
(Statement.closedFormCrossed (r) (res)) := by
unfold FormalConflictRange.compactCrossed Statement.closedFormCrossed
unfold FormalConflictRange.compactCrossed
FormalConflictRange.closedFormNegCrossTruncRevUnder
FormalConflictRange.closedFormNegCrossTruncRevCrossedNonposLarge
FormalConflictRange.closedFormNegCrossTruncRevBelowEnd
Statement.closedFormCrossed
simp [Statement.firstKey, Statement.lastKey, Statement.first, Statement.last,
Statement.afterFirst, Statement.afterLast, Statement.bottom, Statement.range,
Statement.forwardRead, Statement.reversedResult, Statement.crossedBegin,
+27 -75
View File
@@ -47,7 +47,7 @@ The names below use "truncated" as shorthand for the `more = true` cases; a
Many of the `Prop`-valued helpers below are `@[reducible]` so that `Decidable`
synthesis can unfold them in `if` conditions; the `synthInstance.maxSize` bump
before `closedFormCrossedComplete` is for the six-way clamp disjunction.
before `closedFormCrossedComplete` is for the clamp disjunction.
The definitions are in dependency order, so the dispatcher comes last, right
before the headline.
@@ -372,16 +372,6 @@ def closedFormNegCrossClampEndOne (r : RangeRead) (res : Result) : ConflictRange
res.more = false ∧ r.end_.offset ≤ 0 ∧ r.begin.key ≤ r.end_.key ∧
first res = bottom
@[reducible] def negCrossClampNonposInfinite (r : RangeRead) (res : Result) : Prop :=
r.reverse = false ∧
r.begin.offset < 0 ∧
res.more = false ∧
r.end_.offset ≤ 0 ∧
r.begin.key ≤ r.end_.key ∧
intervalCard r.begin.key r.end_.key = ⊤ ∧
first res < r.begin.key ∧
reportedBelowBegin r res ≤ beginSlack r
@[reducible] def negCrossClampNonposLastGe (r : RangeRead) (res : Result) : Prop :=
r.reverse = false ∧
r.begin.offset < 0 ∧
@@ -407,16 +397,17 @@ def closedFormNegCrossClampEndOne (r : RangeRead) (res : Result) : ConflictRange
reportedBelowBegin r res ≤ beginSlack r ∧
clampNonposBottom r res ∧ r.end_.key < r.begin.key
/-- The clamping cells all share the bottom endpoint. The offset-one cell can raise the
upper endpoint to `begin.key`; the bottom group ends at `end_.key`; and the long
nonpositive cell can also raise the upper endpoint to `begin.key`. The head-bottom,
infinite and bottom cells are incompatible with the long cell (their key order is
opposite); `negCrossClampNonposLastGe` carries no key-order constraint, so it alone needs
a separate check before the long cell. -/
def closedFormNegCrossClampUnified (r : RangeRead) (res : Result) : ConflictRange :=
let end_ :=
if negCrossClampEndOne r res then clampEndOneUpper r res
else if
negCrossHeadBottom r res ∨
negCrossClampNonposInfinite r res ∨
negCrossClampNonposLastGe r res ∨
negCrossClampNonposBottom r res then
r.end_.key
else if negCrossClampLongNonpos r res then clampLongUpper r res
else if negCrossClampLongNonpos r res ∧ ¬ negCrossClampNonposLastGe r res then
clampLongUpper r res
else r.end_.key
range bottom end_
@@ -523,24 +514,11 @@ def closedFormNegCrossTruncNonposGapA2aBottom (r : RangeRead) (res : Result) : C
if negCrossTruncNonposGapA2aBottomHigh r res then range bottom r.begin.key
else range bottom r.end_.key
def closedFormNegCrossTruncRevBelowEnd (_r : RangeRead) (res : Result) : ConflictRange :=
topOfLast (lastKey res)
def closedFormNegCrossTruncRevCrossedNonposLarge (r : RangeRead) (res : Result) : ConflictRange :=
range (last res) r.begin.key
@[reducible] def finiteUnderCond (r : RangeRead) (res : Result) : Prop :=
↑(reportedBelowBegin r res - 1) +
intervalCard (afterFirst res) r.begin.key ≤
↑(beginSlack r)
def closedFormNegCrossTruncRevResidualFiniteUnder (r : RangeRead) (res : Result) : ConflictRange :=
let L := last res
let U :=
if finiteUnderCond r res then afterFirst res
else r.begin.key
range L U
@[reducible] def negCrossTruncRevResidualFiniteOver (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
@@ -552,20 +530,16 @@ def closedFormNegCrossTruncRevResidualFiniteUnder (r : RangeRead) (res : Result)
def closedFormNegCrossTruncRevResidualFiniteUnified (r : RangeRead) (res : Result) :
ConflictRange :=
let under := closedFormNegCrossTruncRevResidualFiniteUnder r res
if negCrossTruncRevResidualFiniteOver r res then range r.end_.key under.end_
else under
let L := last res
let U := if finiteUnderCond r res then afterFirst res else r.begin.key
if negCrossTruncRevResidualFiniteOver r res then range r.end_.key U
else range L U
@[reducible] def sentinelLargeTight (r : RangeRead) (res : Result) : Prop :=
let L := last res
residualE r = intervalCard r.end_.key L + ↑res.keys.length ∧
↑res.keys.length + r.begin.offset = 1
def closedFormNegCrossTruncRevResidualTopLargeSentinel (r : RangeRead) (res : Result) :
ConflictRange :=
let L := last res
if sentinelLargeTight r res then range L ⊤ else range r.end_.key ⊤
@[reducible] def negCrossTruncRevResidualTopLarge (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
@@ -581,19 +555,14 @@ def closedFormNegCrossTruncRevResidualTopLargeSentinel (r : RangeRead) (res : Re
def closedFormNegCrossTruncRevResidualTopLargeUnified (r : RangeRead) (res : Result) :
ConflictRange :=
if negCrossTruncRevResidualTopLargeSentinel r res then
closedFormNegCrossTruncRevResidualTopLargeSentinel r res
let L := last res
if negCrossTruncRevResidualTopLargeSentinel r res ∧ sentinelLargeTight r res then
range L ⊤
else range r.end_.key ⊤
def truncatedRangeRev (r : RangeRead) (last : Key) : ConflictRange :=
range ↑last r.end_.key
def closedFormNegCrossTruncRevUnder (r : RangeRead) (res : Result) : ConflictRange :=
truncatedRangeRev r (lastKey res)
def closedFormNegCrossTruncTopTopEq (_r : RangeRead) (res : Result) : ConflictRange :=
range (first res) ⊤
/-! ### Complete and offset-one cases -/
/-- Iterating the successor `keyAfter`. -/
@@ -801,7 +770,6 @@ def emptyValue (r : RangeRead) : ConflictRange :=
if AlwaysEmpty r then emptyRange r
else if r.begin.offset ≤ 0 then
if 2 ≤ r.end_.offset then range bottom ⊤
else if r.begin.key ≤ r.end_.key then range bottom r.end_.key
else if intervalCard r.end_.key r.begin.key < ↑(r.end_.offset - r.begin.offset).toNat then
range bottom r.end_.key
else range bottom (max r.begin.key r.end_.key)
@@ -898,8 +866,7 @@ def closedFormPositive (r : RangeRead) (res : Result) : ConflictRange :=
@[reducible] def negCrossOvershoot (r : RangeRead) (res : Result) : Prop :=
r.reverse = false ∧
r.begin.offset < 0 ∧
res.more = false ∧
2 ≤ r.end_.offset ∧ (∀ k ∈ res.keys, ↑k < r.end_.key) ∧
res.more = false ∧ overshoot r res ∧
first res < r.begin.key
@[reducible] def crossedCompleteOvershoot (r : RangeRead) (res : Result) : Prop :=
@@ -933,12 +900,10 @@ def closedFormPositive (r : RangeRead) (res : Result) : ConflictRange :=
@[reducible] def crossedCompleteClamp (r : RangeRead) (res : Result) : Prop :=
negCrossClampEndOne r res ∨
negCrossHeadBottom r res ∨
negCrossClampNonposInfinite r res ∨
negCrossClampNonposLastGe r res ∨
negCrossClampNonposBottom r res ∨ negCrossClampLongNonpos r res
/- The six-way disjunction in `crossedCompleteClamp` exceeds the default
instance-search budget. -/
/- The disjunction in `crossedCompleteClamp` exceeds the default instance-search
budget. -/
set_option synthInstance.maxSize 10000 in
def closedFormCrossedComplete (r : RangeRead) (res : Result) : ConflictRange :=
if crossedCompleteOvershoot r res then closedFormNegCrossTopUnified r res
@@ -959,38 +924,25 @@ def closedFormCrossedComplete (r : RangeRead) (res : Result) : ConflictRange :=
last res < r.begin.key ∧ r.begin.key ≤ r.end_.key ∧
r.end_.offset ≤ 1
@[reducible] def negCrossTruncRevCrossedNonposSmall (r : RangeRead) (res : Result) : Prop :=
@[reducible] def negCrossTruncRevCrossedLow (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
r.begin.offset < 0 ∧
last res < r.begin.key ∧
r.end_.key < r.begin.key ∧
r.end_.offset ≤ 0 ∧
r.end_.offset ≤ 1 ∧
intervalCard r.end_.key r.begin.key + ↑res.keys.length +
↑(1 - r.end_.offset).toNat ≤
↑(beginSlack r) + 1
@[reducible] def negCrossTruncRevCrossedSmall (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
r.begin.offset < 0 ∧
last res < r.begin.key ∧
r.end_.key < r.begin.key ∧
r.end_.offset = 1 ∧
intervalCard r.end_.key r.begin.key + ↑res.keys.length ≤
↑(beginSlack r) + 1
@[reducible] def revTruncLeOneLow (r : RangeRead) (res : Result) : Prop :=
negCrossTruncRevUnder r res ∨
negCrossTruncRevCrossedNonposSmall r res ∨
negCrossTruncRevCrossedSmall r res
negCrossTruncRevUnder r res ∨ negCrossTruncRevCrossedLow r res
@[reducible] def negCrossTruncRevBelowEnd (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
r.reverse = true ∧
r.begin.offset < 0 ∧
last res < r.begin.key ∧ 2 ≤ r.end_.offset ∧
∀ k ∈ res.keys, ↑k < r.end_.key
last res < r.begin.key ∧ overshoot r res
@[reducible] def negCrossTruncRevResidualRoom (r : RangeRead) (res : Result) : Prop :=
res.more = true ∧
@@ -1076,7 +1028,7 @@ def closedFormForwardTruncatedNonpos (r : RangeRead) (res : Result) : ConflictRa
else range bottom (clampLongUpper r res)
else range (first res) r.begin.key
else if negCrossTruncTopTopEq r res then
closedFormNegCrossTruncTopTopEq r res
range (first res) ⊤
else if clampNonposBottom r res then range bottom r.end_.key
else range (first res) r.end_.key
else range bottom (closedFormClampUpper r res)
@@ -1093,10 +1045,10 @@ def closedFormCrossed (r : RangeRead) (res : Result) : ConflictRange :=
else if r.reverse = true then
if zeroCrossTruncRevCrossed r res then
closedFormZeroCrossTruncRevCrossed r res
else if revTruncLeOneLow r res then closedFormNegCrossTruncRevUnder r res
else if r.end_.offset ≤ 1 then closedFormNegCrossTruncRevCrossedNonposLarge r res
else if revTruncLeOneLow r res then truncatedRangeRev r (lastKey res)
else if r.end_.offset ≤ 1 then range (last res) r.begin.key
else if revTruncGeTwoTop r res then
closedFormNegCrossTruncRevBelowEnd r res
topOfLast (lastKey res)
else if revTruncGeTwoLarge r res then
closedFormNegCrossTruncRevResidualTopLargeUnified r res
else closedFormNegCrossTruncRevResidualFiniteUnified r res