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:
1 parent
6cfdb13da1
commit
6559cc582b
2 files changed
+350
-307
No files matched your search
+27
-75
@@ -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
|
||||
|
||||
Reference in new issue
Block a user