Fix all Lean build warnings
- Update deprecated lemmas (ite_eq_left/right, ENat casts, List.Sublist, ...) - Replace push_neg with push Not and resolve unused-variable warnings - Convert flexible simp/simp_all calls to explicit simp only lists - Remove unscoped maxHeartbeats options, open scoped Classical, and unused tactics - Add missing module docstrings and clean up style linter hits - Wrap over-long lines and flatten the deeply nested minimal_conflictRangeClosedForm_total proof `lake build` now completes with zero warnings.
This commit is contained in:
1 parent
a54a5f82f8
commit
af318a7d32
51 files changed
+2542
-1357
No files matched your search
+1427
-348
File diff suppressed because it is too large.
Load diff
@@ -83,7 +83,6 @@ The resulting definition is total and minimal on every `Readable` pair
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -710,11 +709,13 @@ theorem minimal_conflictRangeClosedForm {r : RangeRead} {res : Result}
|
||||
have hcf : r.begin.key ≤ r.end_.key := not_lt.mp hcross
|
||||
by_cases hrev : r.reverse = true
|
||||
· rw [ite_eq_left hrev]
|
||||
exact minimal_closedForm_of_complete_crossFree_rev hread hmore hrev hempty hbegin hcf
|
||||
exact minimal_closedForm_of_complete_crossFree_rev
|
||||
hread hmore hrev hempty hbegin hcf
|
||||
· rw [ite_eq_right hrev]
|
||||
have hrevf : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
exact minimal_closedForm_of_complete_crossFree hread hmore hrevf hempty hbegin hcf
|
||||
exact minimal_closedForm_of_complete_crossFree
|
||||
hread hmore hrevf hempty hbegin hcf
|
||||
· rw [ite_eq_right hmore]
|
||||
have hm : res.more = true := by
|
||||
cases hm : res.more <;> simp_all
|
||||
@@ -722,7 +723,8 @@ theorem minimal_conflictRangeClosedForm {r : RangeRead} {res : Result}
|
||||
· rw [ite_eq_left hrev]
|
||||
by_cases hle : r.end_.offset ≤ 1
|
||||
· rw [ite_eq_left hle]
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_rev_more hread hm hrev hempty
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_rev_more
|
||||
hread hm hrev hempty
|
||||
(by omega) hle
|
||||
· rw [ite_eq_right hle]
|
||||
have hend2 : 2 ≤ r.end_.offset := by omega
|
||||
@@ -732,9 +734,11 @@ theorem minimal_conflictRangeClosedForm {r : RangeRead} {res : Result}
|
||||
(by omega) hend2 hhi
|
||||
· rw [ite_eq_right hhi]
|
||||
by_cases hfin : r.end_.key < r.begin.key ∧
|
||||
res.keys.length + (r.begin.offset - 1).toNat = (r.end_.offset - 1).toNat
|
||||
res.keys.length + (r.begin.offset - 1).toNat =
|
||||
(r.end_.offset - 1).toNat
|
||||
· rw [ite_eq_left hfin]
|
||||
exact minimal_truncatedRevCrossed_finite_general hread hm hrev hbegin hfin.1
|
||||
exact minimal_truncatedRevCrossed_finite_general
|
||||
hread hm hrev hbegin hfin.1
|
||||
(by omega) hempty hfin.2
|
||||
· rw [ite_eq_right hfin]
|
||||
by_cases hcross : r.end_.key < r.begin.key
|
||||
@@ -753,10 +757,12 @@ theorem minimal_conflictRangeClosedForm {r : RangeRead} {res : Result}
|
||||
(r.end_.offset - 1).toNat := by omega
|
||||
by_cases hcond : crossedResidualCond r res hempty
|
||||
· rw [ite_eq_left hcond]
|
||||
exact minimal_crossedResidual_cond hread' hm hrev (by omega) hcross
|
||||
exact minimal_crossedResidual_cond
|
||||
hread' hm hrev (by omega) hcross
|
||||
(by omega) hempty hlt hcond
|
||||
· rw [ite_eq_right hcond]
|
||||
exact minimal_crossedResidual_not_cond hread' hm hrev (by omega) hcross
|
||||
exact minimal_crossedResidual_not_cond
|
||||
hread' hm hrev (by omega) hcross
|
||||
(by omega) hempty hlt hcond
|
||||
· rw [ite_eq_right hcross]
|
||||
have htpos : 0 < residualT r res := by
|
||||
@@ -772,7 +778,8 @@ theorem minimal_conflictRangeClosedForm {r : RangeRead} {res : Result}
|
||||
by_cases hcross : r.end_.key < r.begin.key
|
||||
· rw [ite_eq_left hcross]
|
||||
have hend := crossed_end_offset_ge_two_truncated hread hm hbegin hcross
|
||||
exact minimal_truncatedForwardCrossedGeneral hread hm hrevf hempty hbegin hcross hend
|
||||
exact minimal_truncatedForwardCrossedGeneral
|
||||
hread hm hrevf hempty hbegin hcross hend
|
||||
· rw [ite_eq_right hcross]
|
||||
have hcf : r.begin.key ≤ r.end_.key := not_lt.mp hcross
|
||||
exact minimal_closedForm_of_truncated_general hread hm hrevf hbegin hcf
|
||||
@@ -947,344 +954,347 @@ theorem minimal_conflictRangeClosedForm_total {r : RangeRead} {res : Result}
|
||||
classical
|
||||
by_cases hpos : 1 ≤ r.begin.offset
|
||||
· exact minimal_conflictRangeClosedForm hread hpos
|
||||
· unfold conflictRangeClosedForm
|
||||
by_cases hempty : res.keys = []
|
||||
· rw [ite_eq_left hempty]
|
||||
exact minimal_emptyValue_of_emptyInference emptyInference hread hempty
|
||||
· rw [ite_eq_right hempty]
|
||||
by_cases hnp : nonposCompleteCrossFree r res
|
||||
· rw [ite_eq_left hnp]
|
||||
exact minimal_closedForm_of_complete_nonpos_crossFree hread hnp
|
||||
· rw [ite_eq_right hnp]
|
||||
by_cases hft : nonposFwdTrunc r res
|
||||
· rw [ite_eq_left hft]
|
||||
exact minimal_closedForm_of_nonpos_fwdTrunc hread hft
|
||||
· rw [ite_eq_right hft]
|
||||
by_cases hftn : nonposFwdTruncNonpos r res
|
||||
· rw [ite_eq_left hftn]
|
||||
exact minimal_closedForm_of_nonpos_fwdTruncNonpos hread hftn
|
||||
· rw [ite_eq_right hftn]
|
||||
by_cases hrt : nonposRevTrunc r res
|
||||
· rw [ite_eq_left hrt]
|
||||
exact minimal_closedForm_of_nonpos_revTrunc hread hrt
|
||||
· rw [ite_eq_right hrt]
|
||||
by_cases hzc : zeroCrossOvershootComplete r res
|
||||
· rw [ite_eq_left hzc]
|
||||
exact minimal_closedForm_of_zeroCross_overshoot hread hzc
|
||||
· rw [ite_eq_right hzc]
|
||||
by_cases hze : zeroCrossEndOne r res
|
||||
· rw [ite_eq_left hze]
|
||||
exact minimal_closedForm_of_zeroCross_endOne hread hze
|
||||
· rw [ite_eq_right hze]
|
||||
by_cases hzel : zeroCrossEndOneLong r res
|
||||
· rw [ite_eq_left hzel]
|
||||
exact minimal_closedForm_of_zeroCross_endOne_long hread hzel
|
||||
· rw [ite_eq_right hzel]
|
||||
by_cases hzn : zeroCrossEndNonpos r res
|
||||
· rw [ite_eq_left hzn]
|
||||
exact minimal_closedForm_of_zeroCross_endNonpos hread hzn
|
||||
· rw [ite_eq_right hzn]
|
||||
by_cases hzu : zeroCrossUnderEnd r res
|
||||
· rw [ite_eq_left hzu]
|
||||
exact minimal_closedForm_of_zeroCross_underEnd hread hzu
|
||||
· rw [ite_eq_right hzu]
|
||||
by_cases hzl : zeroCrossLongTop r res
|
||||
· rw [ite_eq_left hzl]
|
||||
exact minimal_closedForm_of_zeroCross_longTop hread hzl
|
||||
· rw [ite_eq_right hzl]
|
||||
by_cases hzlf : zeroCrossLongFinite r res
|
||||
· rw [ite_eq_left hzlf]
|
||||
exact minimal_closedForm_of_zeroCross_longFinite hread hzlf
|
||||
· rw [ite_eq_right hzlf]
|
||||
by_cases hzcr : zeroCrossCompleteRev r res
|
||||
· rw [ite_eq_left hzcr]
|
||||
exact minimal_closedForm_of_zeroCross_complete_rev hread hzcr.2.2.1
|
||||
hzcr.1 hzcr.2.1 hzcr.2.2.2.1 hzcr.2.2.2.2
|
||||
· rw [ite_eq_right hzcr]
|
||||
by_cases hnc : negCrossOvershoot r res
|
||||
· rw [ite_eq_left hnc]
|
||||
have hcross' : ((res.keys.head hnc.2.2.2.1 : Key) : WithTop Key) <
|
||||
r.begin.key := by
|
||||
have h := hnc.2.2.2.2.2.2
|
||||
rwa [headD_eq_head_of_ne hnc.2.2.2.1] at h
|
||||
exact minimal_closedForm_of_negCross_overshoot hread hnc.1 hnc.2.1
|
||||
hnc.2.2.1 hnc.2.2.2.1 hnc.2.2.2.2.1 hnc.2.2.2.2.2.1 hcross'
|
||||
· rw [ite_eq_right hnc]
|
||||
by_cases hncr : negCrossOvershootRev r res
|
||||
· rw [ite_eq_left hncr]
|
||||
exact minimal_closedForm_of_negCross_overshoot_rev hread hncr
|
||||
· rw [ite_eq_right hncr]
|
||||
by_cases hncl : negCrossLowFwd r res
|
||||
· rw [ite_eq_left hncl]
|
||||
exact minimal_closedForm_of_negCross_lowFwd hread hncl
|
||||
· rw [ite_eq_right hncl]
|
||||
by_cases hnclr : negCrossLowFwdRev r res
|
||||
· rw [ite_eq_left hnclr]
|
||||
exact minimal_closedForm_of_negCross_lowFwd_rev hread hnclr
|
||||
· rw [ite_eq_right hnclr]
|
||||
by_cases hnce : negCrossEndOne r res
|
||||
· rw [ite_eq_left hnce]
|
||||
exact minimal_closedForm_of_negCross_endOne hread hnce
|
||||
· rw [ite_eq_right hnce]
|
||||
by_cases hncer : negCrossEndOneRev r res
|
||||
· rw [ite_eq_left hncer]
|
||||
exact minimal_closedForm_of_negCross_endOne_rev hread hncer
|
||||
· rw [ite_eq_right hncer]
|
||||
by_cases hncel : negCrossEndOneLong r res
|
||||
· rw [ite_eq_left hncel]
|
||||
exact minimal_closedForm_of_negCross_endOne_long hread hncel
|
||||
· rw [ite_eq_right hncel]
|
||||
by_cases hncelr : negCrossEndOneLongRev r res
|
||||
· rw [ite_eq_left hncelr]
|
||||
exact minimal_closedForm_of_negCross_endOne_long_rev hread hncelr
|
||||
· rw [ite_eq_right hncelr]
|
||||
by_cases hncc : negCrossClampEndOne r res
|
||||
· rw [ite_eq_left hncc]
|
||||
exact minimal_closedForm_of_negCross_clampEndOne hread hncc
|
||||
· rw [ite_eq_right hncc]
|
||||
by_cases hnccr : negCrossClampEndOneRev r res
|
||||
· rw [ite_eq_left hnccr]
|
||||
exact minimal_closedForm_of_negCross_clampEndOne_rev hread hnccr
|
||||
· rw [ite_eq_right hnccr]
|
||||
by_cases hnb : negCrossHeadBottom r res
|
||||
· rw [ite_eq_left hnb]
|
||||
exact minimal_closedForm_of_negCross_headBottom hread hnb
|
||||
· rw [ite_eq_right hnb]
|
||||
by_cases hnbr : negCrossHeadBottomRev r res
|
||||
· rw [ite_eq_left hnbr]
|
||||
exact minimal_closedForm_of_negCross_headBottom_rev hread hnbr
|
||||
· rw [ite_eq_right hnbr]
|
||||
by_cases hnci : negCrossClampNonposInfinite r res
|
||||
· rw [ite_eq_left hnci]
|
||||
exact minimal_closedForm_of_negCross_clampNonpos_infinite hread hnci
|
||||
· rw [ite_eq_right hnci]
|
||||
by_cases hncir : negCrossClampNonposInfiniteRev r res
|
||||
· rw [ite_eq_left hncir]
|
||||
exact minimal_closedForm_of_negCross_clampNonpos_infinite_rev hread hncir
|
||||
· rw [ite_eq_right hncir]
|
||||
rw [ite_eq_left (by omega : r.begin.offset ≤ 0)]
|
||||
by_cases hzcrv : zeroCrossTruncRevCrossed r res
|
||||
· rw [ite_eq_left hzcrv]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_revCrossed hread hzcrv
|
||||
· rw [ite_eq_right hzcrv]
|
||||
by_cases hzct : zeroCrossTruncReadAllEnd r res
|
||||
· rw [ite_eq_left hzct]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_readAllEnd hread hzct
|
||||
· rw [ite_eq_right hzct]
|
||||
by_cases hzcb : zeroCrossTruncBelowEnd r res
|
||||
· rw [ite_eq_left hzcb]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_belowEnd hread hzcb
|
||||
· rw [ite_eq_right hzcb]
|
||||
by_cases hzce : zeroCrossTruncEndGeHead r res
|
||||
· rw [ite_eq_left hzce]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_endGeHead hread hzce
|
||||
· rw [ite_eq_right hzce]
|
||||
by_cases hzcl : zeroCrossTruncLowEndSmall r res
|
||||
· rw [ite_eq_left hzcl]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_lowEndSmall hread hzcl
|
||||
· rw [ite_eq_right hzcl]
|
||||
by_cases hzcbg : zeroCrossTruncLowEndBig r res
|
||||
· rw [ite_eq_left hzcbg]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_lowEndBig hread hzcbg
|
||||
· rw [ite_eq_right hzcbg]
|
||||
by_cases hzcn : zeroCrossTruncNonposEnd r res
|
||||
· rw [ite_eq_left hzcn]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_nonposEnd hread hzcn
|
||||
· rw [ite_eq_right hzcn]
|
||||
by_cases hnlg : negCrossClampNonposLastGe r res
|
||||
· rw [ite_eq_left hnlg]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_lastGe hread hnlg
|
||||
· rw [ite_eq_right hnlg]
|
||||
by_cases hnlgrev : negCrossClampNonposLastGeRev r res
|
||||
· rw [ite_eq_left hnlgrev]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_lastGe_rev hread hnlgrev
|
||||
· rw [ite_eq_right hnlgrev]
|
||||
by_cases hncbn : negCrossClampNonposBottom r res
|
||||
· rw [ite_eq_left hncbn]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_bottom hread hncbn
|
||||
· rw [ite_eq_right hncbn]
|
||||
by_cases hncbnr : negCrossClampNonposBottomRev r res
|
||||
· rw [ite_eq_left hncbnr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_bottom_rev hread hncbnr
|
||||
· rw [ite_eq_right hncbnr]
|
||||
by_cases hnc : negCrossNonclampNonpos r res
|
||||
· rw [ite_eq_left hnc]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_nonpos hread hnc
|
||||
· rw [ite_eq_right hnc]
|
||||
by_cases hncr : negCrossNonclampNonposRev r res
|
||||
· rw [ite_eq_left hncr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_nonpos_rev hread hncr
|
||||
· rw [ite_eq_right hncr]
|
||||
by_cases hncl : negCrossNonclampLongNonpos r res
|
||||
· rw [ite_eq_left hncl]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_long_nonpos hread hncl
|
||||
· rw [ite_eq_right hncl]
|
||||
by_cases hnclr : negCrossNonclampLongNonposRev r res
|
||||
· rw [ite_eq_left hnclr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_long_nonpos_rev hread hnclr
|
||||
· rw [ite_eq_right hnclr]
|
||||
by_cases hnclc : negCrossClampLongNonpos r res
|
||||
· rw [ite_eq_left hnclc]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clamp_long_nonpos hread hnclc
|
||||
· rw [ite_eq_right hnclc]
|
||||
by_cases hnclcr : negCrossClampLongNonposRev r res
|
||||
· rw [ite_eq_left hnclcr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clamp_long_nonpos_rev hread hnclcr
|
||||
· rw [ite_eq_right hnclcr]
|
||||
by_cases hhigh : negCrossCompleteHighSmall r res
|
||||
· rw [ite_eq_left hhigh]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_small hread hhigh
|
||||
· rw [ite_eq_right hhigh]
|
||||
by_cases hclampfin : negCrossCompleteHighClampFinite r res
|
||||
· rw [ite_eq_left hclampfin]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_clampFinite hread hclampfin
|
||||
· rw [ite_eq_right hclampfin]
|
||||
by_cases hhighrev : negCrossCompleteHighRev r res
|
||||
· rw [ite_eq_left hhighrev]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_rev hread hhighrev
|
||||
· rw [ite_eq_right hhighrev]
|
||||
by_cases hncres : negCrossCompleteResidual r res
|
||||
· rw [ite_eq_left hncres]
|
||||
exact minimal_closedForm_of_negCross_complete_residual hread hncres
|
||||
· rw [ite_eq_right hncres]
|
||||
by_cases hncresr : negCrossCompleteResidualRev r res
|
||||
· rw [ite_eq_left hncresr]
|
||||
exact minimal_closedForm_of_negCross_complete_residual_rev hread hncresr
|
||||
· rw [ite_eq_right hncresr]
|
||||
by_cases hnb : negCrossTruncNonclampBelowEnd r res
|
||||
· rw [ite_eq_left hnb]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_below hread hnb
|
||||
· rw [ite_eq_right hnb]
|
||||
by_cases heg : negCrossTruncNonclampEndGeHead r res
|
||||
· rw [ite_eq_left heg]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_endGeHead hread heg
|
||||
· rw [ite_eq_right heg]
|
||||
by_cases hne1 : negCrossTruncNonclampEndOne r res
|
||||
· rw [ite_eq_left hne1]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_endOne hread hne1
|
||||
· rw [ite_eq_right hne1]
|
||||
by_cases hnt : negCrossTruncNonclampTop r res
|
||||
· rw [ite_eq_left hnt]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_top hread hnt
|
||||
· rw [ite_eq_right hnt]
|
||||
by_cases hlows : negCrossTruncNonclampLowEndSmall r res
|
||||
· rw [ite_eq_left hlows]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_lowEndSmall hread hlows
|
||||
· rw [ite_eq_right hlows]
|
||||
by_cases hlowb : negCrossTruncNonclampLowEndBig r res
|
||||
· rw [ite_eq_left hlowb]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_lowEndBig hread hlowb
|
||||
· rw [ite_eq_right hlowb]
|
||||
by_cases hgaplow : negCrossTruncClampGapLow r res
|
||||
· rw [ite_eq_left hgaplow]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapLow hread hgaplow
|
||||
· rw [ite_eq_right hgaplow]
|
||||
by_cases hgapbotmid : negCrossTruncClampGapBotMid r res
|
||||
· rw [ite_eq_left hgapbotmid]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapBotMid hread hgapbotmid
|
||||
· rw [ite_eq_right hgapbotmid]
|
||||
by_cases hgaphigh : negCrossTruncClampGapHighBot r res
|
||||
· rw [ite_eq_left hgaphigh]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapHighBot hread hgaphigh
|
||||
· rw [ite_eq_right hgaphigh]
|
||||
by_cases hgaphighgen : negCrossTruncClampGapHigh r res
|
||||
· rw [ite_eq_left hgaphighgen]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapHigh hread hgaphighgen
|
||||
· rw [ite_eq_right hgaphighgen]
|
||||
by_cases hclampgen : negCrossTruncClampNoGap r res
|
||||
· rw [ite_eq_left hclampgen]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_noGap hread hclampgen
|
||||
· rw [ite_eq_right hclampgen]
|
||||
by_cases hrevbelowend : negCrossTruncRevBelowEnd r res
|
||||
· rw [ite_eq_left hrevbelowend]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_belowEnd hread hrevbelowend
|
||||
· rw [ite_eq_right hrevbelowend]
|
||||
by_cases hrevnonposover : negCrossTruncRevNonposOvershoot r res
|
||||
· rw [ite_eq_left hrevnonposover]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_nonposOvershoot hread hrevnonposover
|
||||
· rw [ite_eq_right hrevnonposover]
|
||||
by_cases hrevnonposunder : negCrossTruncRevNonposUnder r res
|
||||
· rw [ite_eq_left hrevnonposunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_nonposUnder hread hrevnonposunder
|
||||
· rw [ite_eq_right hrevnonposunder]
|
||||
by_cases hrevcrosssmall : negCrossTruncRevCrossedSmall r res
|
||||
· rw [ite_eq_left hrevcrosssmall]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedSmall hread hrevcrosssmall
|
||||
· rw [ite_eq_right hrevcrosssmall]
|
||||
by_cases hrevcrosslarge : negCrossTruncRevCrossedLarge r res
|
||||
· rw [ite_eq_left hrevcrosslarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedLarge hread hrevcrosslarge
|
||||
· rw [ite_eq_right hrevcrosslarge]
|
||||
by_cases hrevunder : negCrossTruncRevUnder r res
|
||||
· rw [ite_eq_left hrevunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_under hread hrevunder
|
||||
· rw [ite_eq_right hrevunder]
|
||||
by_cases hrevbegtop : negCrossTruncRevBeginTop r res
|
||||
· rw [ite_eq_left hrevbegtop]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_beginTop hread hrevbegtop
|
||||
· rw [ite_eq_right hrevbegtop]
|
||||
by_cases hrevbegtoptwo : negCrossTruncRevBeginTopGeTwo r res
|
||||
· rw [ite_eq_left hrevbegtoptwo]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_beginTop_ge_two hread hrevbegtoptwo
|
||||
· rw [ite_eq_right hrevbegtoptwo]
|
||||
by_cases hrevtop : negCrossTruncRevTop r res
|
||||
· rw [ite_eq_left hrevtop]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_top hread hrevtop
|
||||
· rw [ite_eq_right hrevtop]
|
||||
by_cases hrevcrossnonpossmall : negCrossTruncRevCrossedNonposSmall r res
|
||||
· rw [ite_eq_left hrevcrossnonpossmall]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedNonpos_small hread hrevcrossnonpossmall
|
||||
· rw [ite_eq_right hrevcrossnonpossmall]
|
||||
by_cases hrevcrossnonposlarge : negCrossTruncRevCrossedNonposLarge r res
|
||||
· rw [ite_eq_left hrevcrossnonposlarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedNonpos_large hread hrevcrossnonposlarge
|
||||
· rw [ite_eq_right hrevcrossnonposlarge]
|
||||
by_cases hrevresroom : negCrossTruncRevResidualRoom r res
|
||||
· rw [ite_eq_left hrevresroom]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_room hread hrevresroom
|
||||
· rw [ite_eq_right hrevresroom]
|
||||
by_cases hrevrestopsmall : negCrossTruncRevResidualTopCrossedSmallGap r res
|
||||
· rw [ite_eq_left hrevrestopsmall]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_crossed_smallGap hread hrevrestopsmall
|
||||
· rw [ite_eq_right hrevrestopsmall]
|
||||
by_cases hrevrestopcrossed : negCrossTruncRevResidualTopCrossed r res
|
||||
· rw [ite_eq_left hrevrestopcrossed]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_crossed hread hrevrestopcrossed
|
||||
· rw [ite_eq_right hrevrestopcrossed]
|
||||
by_cases hrevrestoplarge : negCrossTruncRevResidualTopLargeCrossed r res
|
||||
· rw [ite_eq_left hrevrestoplarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_large_crossed hread hrevrestoplarge
|
||||
· rw [ite_eq_right hrevrestoplarge]
|
||||
by_cases hrevrestopsentinel : negCrossTruncRevResidualTopLargeSentinel r res
|
||||
· rw [ite_eq_left hrevrestopsentinel]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_large_sentinel hread hrevrestopsentinel
|
||||
· rw [ite_eq_right hrevrestopsentinel]
|
||||
by_cases hrevfinunder : negCrossTruncRevResidualFiniteUnderCrossed r res
|
||||
· rw [ite_eq_left hrevfinunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residualFinite_under_crossed hread hrevfinunder
|
||||
· rw [ite_eq_right hrevfinunder]
|
||||
by_cases hrevfinundernc : negCrossTruncRevResidualFiniteUnderNotCrossed r res
|
||||
· rw [ite_eq_left hrevfinundernc]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residualFinite_under_notCrossed hread hrevfinundernc
|
||||
· rw [ite_eq_right hrevfinundernc]
|
||||
by_cases hrevfinover : negCrossTruncRevResidualFiniteOver r res
|
||||
· rw [ite_eq_left hrevfinover]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residualFinite_over hread hrevfinover
|
||||
· rw [ite_eq_right hrevfinover]
|
||||
exact simpleConflictRange_minimal hread
|
||||
unfold conflictRangeClosedForm
|
||||
by_cases hempty : res.keys = []
|
||||
· rw [ite_eq_left hempty]
|
||||
exact minimal_emptyValue_of_emptyInference emptyInference hread hempty
|
||||
rw [ite_eq_right hempty]
|
||||
by_cases hnp : nonposCompleteCrossFree r res
|
||||
· rw [ite_eq_left hnp]
|
||||
exact minimal_closedForm_of_complete_nonpos_crossFree hread hnp
|
||||
rw [ite_eq_right hnp]
|
||||
by_cases hft : nonposFwdTrunc r res
|
||||
· rw [ite_eq_left hft]
|
||||
exact minimal_closedForm_of_nonpos_fwdTrunc hread hft
|
||||
rw [ite_eq_right hft]
|
||||
by_cases hftn : nonposFwdTruncNonpos r res
|
||||
· rw [ite_eq_left hftn]
|
||||
exact minimal_closedForm_of_nonpos_fwdTruncNonpos hread hftn
|
||||
rw [ite_eq_right hftn]
|
||||
by_cases hrt : nonposRevTrunc r res
|
||||
· rw [ite_eq_left hrt]
|
||||
exact minimal_closedForm_of_nonpos_revTrunc hread hrt
|
||||
rw [ite_eq_right hrt]
|
||||
by_cases hzc : zeroCrossOvershootComplete r res
|
||||
· rw [ite_eq_left hzc]
|
||||
exact minimal_closedForm_of_zeroCross_overshoot hread hzc
|
||||
rw [ite_eq_right hzc]
|
||||
by_cases hze : zeroCrossEndOne r res
|
||||
· rw [ite_eq_left hze]
|
||||
exact minimal_closedForm_of_zeroCross_endOne hread hze
|
||||
rw [ite_eq_right hze]
|
||||
by_cases hzel : zeroCrossEndOneLong r res
|
||||
· rw [ite_eq_left hzel]
|
||||
exact minimal_closedForm_of_zeroCross_endOne_long hread hzel
|
||||
rw [ite_eq_right hzel]
|
||||
by_cases hzn : zeroCrossEndNonpos r res
|
||||
· rw [ite_eq_left hzn]
|
||||
exact minimal_closedForm_of_zeroCross_endNonpos hread hzn
|
||||
rw [ite_eq_right hzn]
|
||||
by_cases hzu : zeroCrossUnderEnd r res
|
||||
· rw [ite_eq_left hzu]
|
||||
exact minimal_closedForm_of_zeroCross_underEnd hread hzu
|
||||
rw [ite_eq_right hzu]
|
||||
by_cases hzl : zeroCrossLongTop r res
|
||||
· rw [ite_eq_left hzl]
|
||||
exact minimal_closedForm_of_zeroCross_longTop hread hzl
|
||||
rw [ite_eq_right hzl]
|
||||
by_cases hzlf : zeroCrossLongFinite r res
|
||||
· rw [ite_eq_left hzlf]
|
||||
exact minimal_closedForm_of_zeroCross_longFinite hread hzlf
|
||||
rw [ite_eq_right hzlf]
|
||||
by_cases hzcr : zeroCrossCompleteRev r res
|
||||
· rw [ite_eq_left hzcr]
|
||||
exact minimal_closedForm_of_zeroCross_complete_rev hread hzcr.2.2.1
|
||||
hzcr.1 hzcr.2.1 hzcr.2.2.2.1 hzcr.2.2.2.2
|
||||
rw [ite_eq_right hzcr]
|
||||
by_cases hnc : negCrossOvershoot r res
|
||||
· rw [ite_eq_left hnc]
|
||||
have hcross' : ((res.keys.head hnc.2.2.2.1 : Key) : WithTop Key) <
|
||||
r.begin.key := by
|
||||
have h := hnc.2.2.2.2.2.2
|
||||
rwa [headD_eq_head_of_ne hnc.2.2.2.1] at h
|
||||
exact minimal_closedForm_of_negCross_overshoot hread hnc.1 hnc.2.1
|
||||
hnc.2.2.1 hnc.2.2.2.1 hnc.2.2.2.2.1 hnc.2.2.2.2.2.1 hcross'
|
||||
rw [ite_eq_right hnc]
|
||||
by_cases hncr : negCrossOvershootRev r res
|
||||
· rw [ite_eq_left hncr]
|
||||
exact minimal_closedForm_of_negCross_overshoot_rev hread hncr
|
||||
rw [ite_eq_right hncr]
|
||||
by_cases hncl : negCrossLowFwd r res
|
||||
· rw [ite_eq_left hncl]
|
||||
exact minimal_closedForm_of_negCross_lowFwd hread hncl
|
||||
rw [ite_eq_right hncl]
|
||||
by_cases hnclr : negCrossLowFwdRev r res
|
||||
· rw [ite_eq_left hnclr]
|
||||
exact minimal_closedForm_of_negCross_lowFwd_rev hread hnclr
|
||||
rw [ite_eq_right hnclr]
|
||||
by_cases hnce : negCrossEndOne r res
|
||||
· rw [ite_eq_left hnce]
|
||||
exact minimal_closedForm_of_negCross_endOne hread hnce
|
||||
rw [ite_eq_right hnce]
|
||||
by_cases hncer : negCrossEndOneRev r res
|
||||
· rw [ite_eq_left hncer]
|
||||
exact minimal_closedForm_of_negCross_endOne_rev hread hncer
|
||||
rw [ite_eq_right hncer]
|
||||
by_cases hncel : negCrossEndOneLong r res
|
||||
· rw [ite_eq_left hncel]
|
||||
exact minimal_closedForm_of_negCross_endOne_long hread hncel
|
||||
rw [ite_eq_right hncel]
|
||||
by_cases hncelr : negCrossEndOneLongRev r res
|
||||
· rw [ite_eq_left hncelr]
|
||||
exact minimal_closedForm_of_negCross_endOne_long_rev hread hncelr
|
||||
rw [ite_eq_right hncelr]
|
||||
by_cases hncc : negCrossClampEndOne r res
|
||||
· rw [ite_eq_left hncc]
|
||||
exact minimal_closedForm_of_negCross_clampEndOne hread hncc
|
||||
rw [ite_eq_right hncc]
|
||||
by_cases hnccr : negCrossClampEndOneRev r res
|
||||
· rw [ite_eq_left hnccr]
|
||||
exact minimal_closedForm_of_negCross_clampEndOne_rev hread hnccr
|
||||
rw [ite_eq_right hnccr]
|
||||
by_cases hnb : negCrossHeadBottom r res
|
||||
· rw [ite_eq_left hnb]
|
||||
exact minimal_closedForm_of_negCross_headBottom hread hnb
|
||||
rw [ite_eq_right hnb]
|
||||
by_cases hnbr : negCrossHeadBottomRev r res
|
||||
· rw [ite_eq_left hnbr]
|
||||
exact minimal_closedForm_of_negCross_headBottom_rev hread hnbr
|
||||
rw [ite_eq_right hnbr]
|
||||
by_cases hnci : negCrossClampNonposInfinite r res
|
||||
· rw [ite_eq_left hnci]
|
||||
exact minimal_closedForm_of_negCross_clampNonpos_infinite hread hnci
|
||||
rw [ite_eq_right hnci]
|
||||
by_cases hncir : negCrossClampNonposInfiniteRev r res
|
||||
· rw [ite_eq_left hncir]
|
||||
exact minimal_closedForm_of_negCross_clampNonpos_infinite_rev hread hncir
|
||||
rw [ite_eq_right hncir]
|
||||
rw [ite_eq_left (by omega : r.begin.offset ≤ 0)]
|
||||
by_cases hzcrv : zeroCrossTruncRevCrossed r res
|
||||
· rw [ite_eq_left hzcrv]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_revCrossed hread hzcrv
|
||||
rw [ite_eq_right hzcrv]
|
||||
by_cases hzct : zeroCrossTruncReadAllEnd r res
|
||||
· rw [ite_eq_left hzct]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_readAllEnd hread hzct
|
||||
rw [ite_eq_right hzct]
|
||||
by_cases hzcb : zeroCrossTruncBelowEnd r res
|
||||
· rw [ite_eq_left hzcb]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_belowEnd hread hzcb
|
||||
rw [ite_eq_right hzcb]
|
||||
by_cases hzce : zeroCrossTruncEndGeHead r res
|
||||
· rw [ite_eq_left hzce]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_endGeHead hread hzce
|
||||
rw [ite_eq_right hzce]
|
||||
by_cases hzcl : zeroCrossTruncLowEndSmall r res
|
||||
· rw [ite_eq_left hzcl]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_lowEndSmall hread hzcl
|
||||
rw [ite_eq_right hzcl]
|
||||
by_cases hzcbg : zeroCrossTruncLowEndBig r res
|
||||
· rw [ite_eq_left hzcbg]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_lowEndBig hread hzcbg
|
||||
rw [ite_eq_right hzcbg]
|
||||
by_cases hzcn : zeroCrossTruncNonposEnd r res
|
||||
· rw [ite_eq_left hzcn]
|
||||
exact minimal_closedForm_of_zeroCross_trunc_nonposEnd hread hzcn
|
||||
rw [ite_eq_right hzcn]
|
||||
by_cases hnlg : negCrossClampNonposLastGe r res
|
||||
· rw [ite_eq_left hnlg]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_lastGe hread hnlg
|
||||
rw [ite_eq_right hnlg]
|
||||
by_cases hnlgrev : negCrossClampNonposLastGeRev r res
|
||||
· rw [ite_eq_left hnlgrev]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_lastGe_rev hread hnlgrev
|
||||
rw [ite_eq_right hnlgrev]
|
||||
by_cases hncbn : negCrossClampNonposBottom r res
|
||||
· rw [ite_eq_left hncbn]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_bottom hread hncbn
|
||||
rw [ite_eq_right hncbn]
|
||||
by_cases hncbnr : negCrossClampNonposBottomRev r res
|
||||
· rw [ite_eq_left hncbnr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clampNonpos_bottom_rev hread hncbnr
|
||||
rw [ite_eq_right hncbnr]
|
||||
by_cases hnc : negCrossNonclampNonpos r res
|
||||
· rw [ite_eq_left hnc]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_nonpos hread hnc
|
||||
rw [ite_eq_right hnc]
|
||||
by_cases hncr : negCrossNonclampNonposRev r res
|
||||
· rw [ite_eq_left hncr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_nonpos_rev hread hncr
|
||||
rw [ite_eq_right hncr]
|
||||
by_cases hncl : negCrossNonclampLongNonpos r res
|
||||
· rw [ite_eq_left hncl]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_long_nonpos hread hncl
|
||||
rw [ite_eq_right hncl]
|
||||
by_cases hnclr : negCrossNonclampLongNonposRev r res
|
||||
· rw [ite_eq_left hnclr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_nonclamp_long_nonpos_rev hread hnclr
|
||||
rw [ite_eq_right hnclr]
|
||||
by_cases hnclc : negCrossClampLongNonpos r res
|
||||
· rw [ite_eq_left hnclc]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clamp_long_nonpos hread hnclc
|
||||
rw [ite_eq_right hnclc]
|
||||
by_cases hnclcr : negCrossClampLongNonposRev r res
|
||||
· rw [ite_eq_left hnclcr]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_clamp_long_nonpos_rev hread hnclcr
|
||||
rw [ite_eq_right hnclcr]
|
||||
by_cases hhigh : negCrossCompleteHighSmall r res
|
||||
· rw [ite_eq_left hhigh]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_small hread hhigh
|
||||
rw [ite_eq_right hhigh]
|
||||
by_cases hclampfin : negCrossCompleteHighClampFinite r res
|
||||
· rw [ite_eq_left hclampfin]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_clampFinite hread hclampfin
|
||||
rw [ite_eq_right hclampfin]
|
||||
by_cases hhighrev : negCrossCompleteHighRev r res
|
||||
· rw [ite_eq_left hhighrev]
|
||||
exact
|
||||
minimal_closedForm_of_negCrossCompleteHigh_rev hread hhighrev
|
||||
rw [ite_eq_right hhighrev]
|
||||
by_cases hncres : negCrossCompleteResidual r res
|
||||
· rw [ite_eq_left hncres]
|
||||
exact minimal_closedForm_of_negCross_complete_residual hread hncres
|
||||
rw [ite_eq_right hncres]
|
||||
by_cases hncresr : negCrossCompleteResidualRev r res
|
||||
· rw [ite_eq_left hncresr]
|
||||
exact minimal_closedForm_of_negCross_complete_residual_rev hread hncresr
|
||||
rw [ite_eq_right hncresr]
|
||||
by_cases hnb : negCrossTruncNonclampBelowEnd r res
|
||||
· rw [ite_eq_left hnb]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_below hread hnb
|
||||
rw [ite_eq_right hnb]
|
||||
by_cases heg : negCrossTruncNonclampEndGeHead r res
|
||||
· rw [ite_eq_left heg]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_endGeHead hread heg
|
||||
rw [ite_eq_right heg]
|
||||
by_cases hne1 : negCrossTruncNonclampEndOne r res
|
||||
· rw [ite_eq_left hne1]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_endOne hread hne1
|
||||
rw [ite_eq_right hne1]
|
||||
by_cases hnt : negCrossTruncNonclampTop r res
|
||||
· rw [ite_eq_left hnt]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_top hread hnt
|
||||
rw [ite_eq_right hnt]
|
||||
by_cases hlows : negCrossTruncNonclampLowEndSmall r res
|
||||
· rw [ite_eq_left hlows]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_lowEndSmall hread hlows
|
||||
rw [ite_eq_right hlows]
|
||||
by_cases hlowb : negCrossTruncNonclampLowEndBig r res
|
||||
· rw [ite_eq_left hlowb]
|
||||
exact minimal_closedForm_of_negCross_trunc_nonclamp_lowEndBig hread hlowb
|
||||
rw [ite_eq_right hlowb]
|
||||
by_cases hgaplow : negCrossTruncClampGapLow r res
|
||||
· rw [ite_eq_left hgaplow]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapLow hread hgaplow
|
||||
rw [ite_eq_right hgaplow]
|
||||
by_cases hgapbotmid : negCrossTruncClampGapBotMid r res
|
||||
· rw [ite_eq_left hgapbotmid]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapBotMid hread hgapbotmid
|
||||
rw [ite_eq_right hgapbotmid]
|
||||
by_cases hgaphigh : negCrossTruncClampGapHighBot r res
|
||||
· rw [ite_eq_left hgaphigh]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapHighBot hread hgaphigh
|
||||
rw [ite_eq_right hgaphigh]
|
||||
by_cases hgaphighgen : negCrossTruncClampGapHigh r res
|
||||
· rw [ite_eq_left hgaphighgen]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_gapHigh hread hgaphighgen
|
||||
rw [ite_eq_right hgaphighgen]
|
||||
by_cases hclampgen : negCrossTruncClampNoGap r res
|
||||
· rw [ite_eq_left hclampgen]
|
||||
exact minimal_closedForm_of_negCross_trunc_clamp_noGap hread hclampgen
|
||||
rw [ite_eq_right hclampgen]
|
||||
by_cases hrevbelowend : negCrossTruncRevBelowEnd r res
|
||||
· rw [ite_eq_left hrevbelowend]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_belowEnd hread hrevbelowend
|
||||
rw [ite_eq_right hrevbelowend]
|
||||
by_cases hrevnonposover : negCrossTruncRevNonposOvershoot r res
|
||||
· rw [ite_eq_left hrevnonposover]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_nonposOvershoot hread hrevnonposover
|
||||
rw [ite_eq_right hrevnonposover]
|
||||
by_cases hrevnonposunder : negCrossTruncRevNonposUnder r res
|
||||
· rw [ite_eq_left hrevnonposunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_nonposUnder hread hrevnonposunder
|
||||
rw [ite_eq_right hrevnonposunder]
|
||||
by_cases hrevcrosssmall : negCrossTruncRevCrossedSmall r res
|
||||
· rw [ite_eq_left hrevcrosssmall]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedSmall hread hrevcrosssmall
|
||||
rw [ite_eq_right hrevcrosssmall]
|
||||
by_cases hrevcrosslarge : negCrossTruncRevCrossedLarge r res
|
||||
· rw [ite_eq_left hrevcrosslarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedLarge hread hrevcrosslarge
|
||||
rw [ite_eq_right hrevcrosslarge]
|
||||
by_cases hrevunder : negCrossTruncRevUnder r res
|
||||
· rw [ite_eq_left hrevunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_under hread hrevunder
|
||||
rw [ite_eq_right hrevunder]
|
||||
by_cases hrevbegtop : negCrossTruncRevBeginTop r res
|
||||
· rw [ite_eq_left hrevbegtop]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_beginTop hread hrevbegtop
|
||||
rw [ite_eq_right hrevbegtop]
|
||||
by_cases hrevbegtoptwo : negCrossTruncRevBeginTopGeTwo r res
|
||||
· rw [ite_eq_left hrevbegtoptwo]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_beginTop_ge_two hread hrevbegtoptwo
|
||||
rw [ite_eq_right hrevbegtoptwo]
|
||||
by_cases hrevtop : negCrossTruncRevTop r res
|
||||
· rw [ite_eq_left hrevtop]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_top hread hrevtop
|
||||
rw [ite_eq_right hrevtop]
|
||||
by_cases hrevcrossnonpossmall : negCrossTruncRevCrossedNonposSmall r res
|
||||
· rw [ite_eq_left hrevcrossnonpossmall]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedNonpos_small hread hrevcrossnonpossmall
|
||||
rw [ite_eq_right hrevcrossnonpossmall]
|
||||
by_cases hrevcrossnonposlarge : negCrossTruncRevCrossedNonposLarge r res
|
||||
· rw [ite_eq_left hrevcrossnonposlarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_crossedNonpos_large hread hrevcrossnonposlarge
|
||||
rw [ite_eq_right hrevcrossnonposlarge]
|
||||
by_cases hrevresroom : negCrossTruncRevResidualRoom r res
|
||||
· rw [ite_eq_left hrevresroom]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_room hread hrevresroom
|
||||
rw [ite_eq_right hrevresroom]
|
||||
by_cases hrevrestopsmall : negCrossTruncRevResidualTopCrossedSmallGap r res
|
||||
· rw [ite_eq_left hrevrestopsmall]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_trunc_rev_residual_top_crossed_smallGap hread hrevrestopsmall
|
||||
rw [ite_eq_right hrevrestopsmall]
|
||||
by_cases hrevrestopcrossed : negCrossTruncRevResidualTopCrossed r res
|
||||
· rw [ite_eq_left hrevrestopcrossed]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_crossed hread hrevrestopcrossed
|
||||
rw [ite_eq_right hrevrestopcrossed]
|
||||
by_cases hrevrestoplarge : negCrossTruncRevResidualTopLargeCrossed r res
|
||||
· rw [ite_eq_left hrevrestoplarge]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residual_top_large_crossed hread hrevrestoplarge
|
||||
rw [ite_eq_right hrevrestoplarge]
|
||||
by_cases hrevrestopsentinel : negCrossTruncRevResidualTopLargeSentinel r res
|
||||
· rw [ite_eq_left hrevrestopsentinel]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_trunc_rev_residual_top_large_sentinel hread hrevrestopsentinel
|
||||
rw [ite_eq_right hrevrestopsentinel]
|
||||
by_cases hrevfinunder : negCrossTruncRevResidualFiniteUnderCrossed r res
|
||||
· rw [ite_eq_left hrevfinunder]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residualFinite_under_crossed hread hrevfinunder
|
||||
rw [ite_eq_right hrevfinunder]
|
||||
by_cases hrevfinundernc : negCrossTruncRevResidualFiniteUnderNotCrossed r res
|
||||
· rw [ite_eq_left hrevfinundernc]
|
||||
exact
|
||||
minimal_closedForm_of_negCross_trunc_rev_residualFinite_under_notCrossed hread hrevfinundernc
|
||||
rw [ite_eq_right hrevfinundernc]
|
||||
by_cases hrevfinover : negCrossTruncRevResidualFiniteOver r res
|
||||
· rw [ite_eq_left hrevfinover]
|
||||
exact minimal_closedForm_of_negCross_trunc_rev_residualFinite_over hread hrevfinover
|
||||
rw [ite_eq_right hrevfinover]
|
||||
exact simpleConflictRange_minimal hread
|
||||
|
||||
/-- The total closed form denotes the general conflict range for every readable
|
||||
result. -/
|
||||
|
||||
@@ -60,24 +60,24 @@ theorem minimal_closedForm_of_offset_one_total {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOneTotal r res) := by
|
||||
unfold closedFormOffsetOneTotal
|
||||
by_cases hcross : r.end_.key < r.begin.key
|
||||
· rw [if_pos hcross]
|
||||
· rw [ite_eq_left hcross]
|
||||
by_cases hmore : res.more = true
|
||||
· rw [if_pos hmore]
|
||||
· rw [ite_eq_left hmore]
|
||||
have hend := crossed_end_offset_ge_two_truncated hread hmore (by omega) hcross
|
||||
by_cases hrev : r.reverse = true
|
||||
· rw [if_pos hrev]
|
||||
· rw [ite_eq_left hrev]
|
||||
exact minimal_closedForm_of_offset_one_truncated_rev_fullC_crossed hread hmore
|
||||
hrev hbegin hcross hend
|
||||
· rw [if_neg hrev]
|
||||
· rw [ite_eq_right hrev]
|
||||
have hrevf : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
exact minimal_truncatedForwardClosed_of_crossed hread hmore hrevf hne hbegin
|
||||
hcross hend
|
||||
· rw [if_neg hmore]
|
||||
· rw [ite_eq_right hmore]
|
||||
have hfalse : res.more = false := by
|
||||
cases hm : res.more <;> simp_all
|
||||
exact minimal_completeClosed hread hfalse hne hbegin
|
||||
· rw [if_neg hcross]
|
||||
· rw [ite_eq_right hcross]
|
||||
have hcf : r.begin.key ≤ r.end_.key := not_lt.mp hcross
|
||||
exact minimal_closedForm_of_offset_one_universal hread hne hbegin hcf
|
||||
|
||||
@@ -103,6 +103,6 @@ theorem closedFormOffsetOneTotal_eq_universal {r : RangeRead} {res : Result}
|
||||
(hcross : r.begin.key ≤ r.end_.key) :
|
||||
closedFormOffsetOneTotal r res = closedFormOffsetOneUniversal r res := by
|
||||
unfold closedFormOffsetOneTotal
|
||||
rw [if_neg (not_lt.mpr hcross)]
|
||||
rw [ite_eq_right (not_lt.mpr hcross)]
|
||||
|
||||
end FormalConflictRange
|
||||
@@ -29,7 +29,6 @@ the reversed reported keys.
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -59,7 +58,7 @@ theorem completeKeys_count_ge_eq_general_rev {db : DB} {r : RangeRead}
|
||||
/-- The reversed window count in terms of the begin/end counts and the over/under
|
||||
offsets. -/
|
||||
private theorem completeKeys_count_ge_eq_min_rev {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.begin.key ≤ r.end_.key) (hend : 1 ≤ r.end_.offset) :
|
||||
residualT r res ≤
|
||||
@@ -85,7 +84,7 @@ overshoot. This is the reversed truncation counterpart of
|
||||
`residual_dt_le_e`. -/
|
||||
theorem residualD_add_T_le_E {r : RangeRead} {res : Result} {g : ℕ∞}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hne : res.keys ≠ []) (htpos : 0 < residualT r res)
|
||||
(_hne : res.keys ≠ []) (htpos : 0 < residualT r res)
|
||||
(hbegin : 2 ≤ r.begin.offset) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(hcard : intervalCard r.begin.key r.end_.key = g) :
|
||||
@@ -134,8 +133,8 @@ theorem residualD_add_T_le_E {r : RangeRead} {res : Result} {g : ℕ∞}
|
||||
/-- The deficit plus the reported over-count never exceeds the number of stored keys
|
||||
at or above `end_.key`. -/
|
||||
theorem residualD_add_T_le_count_ge {r : RangeRead} {res : Result} {g : ℕ∞}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hne : res.keys ≠ []) (htpos : 0 < residualT r res)
|
||||
(_hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(_hne : res.keys ≠ []) (htpos : 0 < residualT r res)
|
||||
(hbegin : 2 ≤ r.begin.offset) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(hcard : intervalCard r.begin.key r.end_.key = g)
|
||||
@@ -213,8 +212,7 @@ theorem completeKeys_crossfree_rev_eq {db : DB} {r : RangeRead}
|
||||
rw [completeKeys_rev_eq_reverse db r hrev]
|
||||
rw [completeKeys_eq_filter_ge_drop_take (db := db) (r := { r with reverse := false })
|
||||
(by simp) hbegin hend]
|
||||
simp only [show ({ r with reverse := false } : RangeRead).end_.offset = r.end_.offset from rfl,
|
||||
show ({ r with reverse := false } : RangeRead).begin.offset = r.begin.offset from rfl]
|
||||
simp only []
|
||||
rw [show db.keys.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key))) = above db B
|
||||
from by rw [hB]; rfl]
|
||||
rw [← hB, ← hE, ← hb, ← he]
|
||||
@@ -234,7 +232,7 @@ theorem completeKeys_crossfree_rev_eq {db : DB} {r : RangeRead}
|
||||
/-- Filtering a sorted list at or below the `m`-th element gives its first `m`
|
||||
elements. -/
|
||||
theorem filter_le_eq_take_of_window' {A : List Key} (hs : A.SortedLT)
|
||||
{b m : Nat} (hbm : b < m) (hm : m ≤ A.length) {H : Key}
|
||||
{b m : Nat} (hbm : b < m) (_hm : m ≤ A.length) {H : Key}
|
||||
(hlast : A[m - 1]? = some H) :
|
||||
A.filter (fun k : Key => decide (k ≤ H)) = A.take m := by
|
||||
have hmpos : 0 < m := Nat.lt_of_le_of_lt (Nat.zero_le b) hbm
|
||||
@@ -442,11 +440,11 @@ def crossFreeSlack (r : RangeRead) : ℕ :=
|
||||
keys at or above `end_.key`, and the stored keys at or above the begin key and at or
|
||||
below the reported head are exactly the `g + e` keys consumed by the window. -/
|
||||
theorem finite_consequences {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hend : 1 ≤ r.end_.offset) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hne : res.keys ≠ [])
|
||||
(hHE : r.end_.key ≤ ((res.keys.head hne : Key) : WithTop Key))
|
||||
(_hHE : r.end_.key ≤ ((res.keys.head hne : Key) : WithTop Key))
|
||||
(hfin : crossFreeResidualT r res + crossFreeSlack r ≥ (r.end_.offset - 1).toNat) :
|
||||
(r.end_.offset - 1).toNat ≤ (above db r.end_.key).length ∧
|
||||
((above db r.begin.key).filter
|
||||
@@ -495,7 +493,7 @@ theorem finite_consequences {db : DB} {r : RangeRead} {res : Result}
|
||||
have hle : ((b : ℕ∞) - intervalCard B E) ≤ ((b : ℕ∞) - (g : ℕ∞)) :=
|
||||
tsub_le_tsub_left hgcard (b : ℕ∞)
|
||||
have hto := ENat.toNat_le_toNat hle (by simp)
|
||||
rw [ENat.toNat_sub (by simp : ((g : ℕ∞)) ≠ ⊤), ENat.toNat_coe, ENat.toNat_coe] at hto
|
||||
rw [ENat.toNat_sub (by simp : ((g : ℕ∞)) ≠ ⊤), ENat.toNat_natCast, ENat.toNat_natCast] at hto
|
||||
simpa [hB, hE, hb] using hto
|
||||
have hfin' : e ≤ T + (b - g) :=
|
||||
le_trans hfin (Nat.add_le_add_left hSle T)
|
||||
@@ -557,7 +555,7 @@ theorem crossFreeSlack_eq_residualD (r : RangeRead) :
|
||||
by_cases hg : intervalCard r.begin.key r.end_.key = (⊤ : ℕ∞)
|
||||
· simp [hg]
|
||||
· obtain ⟨n, hn⟩ := ENat.ne_top_iff_exists.mp hg
|
||||
rw [← hn, if_neg (by simp : (↑n : ℕ∞) ≠ ⊤), ENat.toNat_sub (by simp),
|
||||
rw [← hn, ite_eq_right (by simp : (↑n : ℕ∞) ≠ ⊤), ENat.toNat_sub (by simp),
|
||||
ENat.toNat_natCast, ENat.toNat_natCast]
|
||||
rfl
|
||||
|
||||
@@ -694,12 +692,12 @@ theorem chain_filter_lt_length_add_residualD {v E : Key} (b : ℕ) (g : ℕ∞)
|
||||
(if g = ⊤ then 0 else b - g.toNat) = b := by
|
||||
by_cases hg : g = ⊤
|
||||
· rw [hg] at hcard
|
||||
rw [if_pos hg, chain_filter_lt_length_top b hcard]
|
||||
rw [ite_eq_left hg, chain_filter_lt_length_top b hcard]
|
||||
omega
|
||||
· obtain ⟨n, hn⟩ := ENat.ne_top_iff_exists.mp hg
|
||||
have hcard' : intervalCard (↑v : WithTop Key) (↑E : WithTop Key) = (n : ℕ∞) := by
|
||||
rw [hn]; exact hcard
|
||||
rw [if_neg hg, ← hn, ENat.toNat_natCast, chain_filter_lt_length_coe b hcard']
|
||||
rw [ite_eq_right hg, ← hn, ENat.toNat_natCast, chain_filter_lt_length_coe b hcard']
|
||||
omega
|
||||
|
||||
/-! ### Begin-key necessity -/
|
||||
@@ -1259,16 +1257,16 @@ theorem necessary_above_head_crossfree_residual {r : RangeRead} {res : Result}
|
||||
have hp_le_c : ((p : ℕ) : ℕ∞) ≤ c := by
|
||||
rw [hp]
|
||||
by_cases hc' : c = ⊤
|
||||
· rw [if_pos hc']; simp [hc']
|
||||
· rw [if_neg hc']
|
||||
· rw [ite_eq_left hc']; simp [hc']
|
||||
· rw [ite_eq_right hc']
|
||||
obtain ⟨n, hn⟩ := ENat.ne_top_iff_exists.mp hc'
|
||||
rw [← hn, ENat.toNat_natCast]
|
||||
exact_mod_cast Nat.min_le_right b n
|
||||
have hDp_le : (((b - p : ℕ)) : ℕ∞) ≤ intervalCard E (↑L) := by
|
||||
rw [hp]
|
||||
by_cases hc' : c = ⊤
|
||||
· rw [if_pos hc']; simp
|
||||
· rw [if_neg hc']
|
||||
· rw [ite_eq_left hc']; simp
|
||||
· rw [ite_eq_right hc']
|
||||
obtain ⟨n, hn⟩ := ENat.ne_top_iff_exists.mp hc'
|
||||
have hp_eq : min b c.toNat = min b n := by rw [← hn, ENat.toNat_natCast]
|
||||
rw [hp_eq]
|
||||
@@ -1285,7 +1283,7 @@ theorem necessary_above_head_crossfree_residual {r : RangeRead} {res : Result}
|
||||
rw [← hm]
|
||||
have hbm : b ≤ n + m := by
|
||||
rw [← Nat.cast_add] at hbL
|
||||
exact ENat.coe_le_coe.mp hbL
|
||||
exact ENat.natCast_le_natCast.mp hbL
|
||||
exact_mod_cast (by omega : b - min b n ≤ m)
|
||||
obtain ⟨pad1, hpad1In, hpad1len⟩ :=
|
||||
exists_db_keysIn (B := B) (E := E) (m := p) hp_le_c
|
||||
@@ -1308,8 +1306,8 @@ theorem necessary_above_head_crossfree_residual {r : RangeRead} {res : Result}
|
||||
have hpleb : p ≤ b := by
|
||||
rw [hp]
|
||||
by_cases hc' : c = ⊤
|
||||
· simp [hp, hc']
|
||||
· rw [if_neg hc']; exact Nat.min_le_left b _
|
||||
· simp [ hc']
|
||||
· rw [ite_eq_right hc']; exact Nat.min_le_left b _
|
||||
have hPlen : P.length = b := by
|
||||
rw [hPdef, List.length_append, hP1len, hP2len]
|
||||
omega
|
||||
@@ -1382,13 +1380,13 @@ theorem necessary_above_head_crossfree_residual {r : RangeRead} {res : Result}
|
||||
simpa [c, e, B, E, residualE] using htop
|
||||
rw [hp]
|
||||
by_cases hc' : c = ⊤
|
||||
· rw [if_pos hc']
|
||||
rw [residualD, if_pos hc'] at htop'
|
||||
· rw [ite_eq_left hc']
|
||||
rw [residualD, ite_eq_left hc'] at htop'
|
||||
omega
|
||||
· rw [if_neg hc']
|
||||
· rw [ite_eq_right hc']
|
||||
obtain ⟨n, hn⟩ := ENat.ne_top_iff_exists.mp hc'
|
||||
have hD : residualD r c = b - n := by
|
||||
rw [residualD, if_neg hc', ← hn, ENat.toNat_natCast, residualB, ← hb]
|
||||
rw [residualD, ite_eq_right hc', ← hn, ENat.toNat_natCast, residualB, ← hb]
|
||||
rw [hD] at htop'
|
||||
rw [← hn, ENat.toNat_natCast]
|
||||
omega
|
||||
|
||||
@@ -235,7 +235,8 @@ theorem compatible_crossed_iff_endKeyToBegin_of_room {r : RangeRead} {res : Resu
|
||||
have hgap_le : ((db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) -
|
||||
db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)) : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key r.begin.key := by
|
||||
simpa [cnt] using cnt_sub_le_intervalCard (db := db) (w₁ := r.end_.key) (w₂ := r.begin.key) (le_of_lt hcross)
|
||||
simpa [cnt] using cnt_sub_le_intervalCard (db := db) (w₁ := r.end_.key) (w₂ := r.begin.key)
|
||||
(le_of_lt hcross)
|
||||
-- gap plus reported length stays below the end offset budget
|
||||
rw [htlen] at hroom
|
||||
have hgap_lt : (db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) -
|
||||
@@ -547,7 +548,7 @@ theorem necessary_of_mem_interval_crossed_top {r : RangeRead} {res : Result} {k
|
||||
exact le_trans (le_of_lt hcross)
|
||||
(le_trans hlast_ge_B (WithTop.coe_le_coe.mpr hCge))
|
||||
have hp₂ : cnt db₂ r.begin.key = s - 1 := by
|
||||
show (db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key))) = s - 1
|
||||
change (db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key))) = s - 1
|
||||
rw [hdb₂, List.countP_append, List.countP_append]
|
||||
have hHc : dbH.keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = dbH.keys.length :=
|
||||
@@ -761,8 +762,8 @@ theorem minimal_completeForward_of_crossed {r : RangeRead} {res : Result}
|
||||
hend2 (by simpa [reportedAtEnd, endOvershoot] using hte)
|
||||
have hs0 : gapOvershoot r res = 0 := by
|
||||
simp [gapOvershoot, hte]
|
||||
rw [completeForwardClosed, if_neg (by omega : ¬ r.end_.offset ≤ 1), if_pos hte]
|
||||
rw [if_pos (by refine ⟨hcross, ?_⟩; rw [hs0]; simp)]
|
||||
rw [completeForwardClosed, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ite_eq_left hte]
|
||||
rw [ite_eq_left (by refine ⟨hcross, ?_⟩; rw [hs0]; simp)]
|
||||
exact hmin
|
||||
· have htlt : reportedAtEnd r res < endOvershoot r := lt_of_le_of_ne htle hte
|
||||
have htlt' : res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) <
|
||||
@@ -776,18 +777,19 @@ theorem minimal_completeForward_of_crossed {r : RangeRead} {res : Result}
|
||||
have hmin : Minimal r res ⟨r.end_.key, ⊤⟩ :=
|
||||
minimal_topRange_of_crossed_large_room hread hmore hrev hne hbegin hcross hend2
|
||||
htlt' hroom'
|
||||
rw [completeForwardClosed, if_neg (by omega : ¬ r.end_.offset ≤ 1), if_neg hte]
|
||||
rw [if_pos (by refine ⟨hcross, ?_⟩; exact hroom)]
|
||||
rw [completeForwardClosed, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ite_eq_right hte]
|
||||
rw [ite_eq_left (by refine ⟨hcross, ?_⟩; exact hroom)]
|
||||
exact hmin
|
||||
· have hroom' : intervalCard r.end_.key r.begin.key <
|
||||
((((r.end_.offset - 1).toNat -
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) : ℕ) : ℕ∞)) := by
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) : ℕ) : ℕ∞))
|
||||
:= by
|
||||
simpa [gapOvershoot, endOvershoot, reportedAtEnd] using lt_of_not_ge hroom
|
||||
have hmin : Minimal r res ⟨r.begin.key, ⊤⟩ :=
|
||||
minimal_topRange_of_crossed_small_room hread hmore hne hrev hbegin hcross hend2
|
||||
htlt' hroom'
|
||||
rw [completeForwardClosed, if_neg (by omega : ¬ r.end_.offset ≤ 1), if_neg hte]
|
||||
rw [if_neg (by intro h; exact hroom h.2)]
|
||||
rw [completeForwardClosed, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ite_eq_right hte]
|
||||
rw [ite_eq_right (by intro h; exact hroom h.2)]
|
||||
exact hmin
|
||||
|
||||
/-- The reversed-traversal analogue of `completeForwardClosed`: the upper endpoint is
|
||||
@@ -844,10 +846,10 @@ theorem completeForwardClosed_eq_closedFormOffsetOne {r : RangeRead} {res : Resu
|
||||
completeForwardClosed r res = closedFormOffsetOne r res := by
|
||||
unfold completeForwardClosed closedFormOffsetOne
|
||||
by_cases h : r.end_.offset ≤ 1
|
||||
· rw [if_pos h, if_pos h]
|
||||
· rw [if_neg h, if_neg h]
|
||||
· rw [ite_eq_left h, ite_eq_left h]
|
||||
· rw [ite_eq_right h, ite_eq_right h]
|
||||
have hnc : ¬ r.end_.key < r.begin.key := not_lt.mpr hcross
|
||||
simp only [hnc, false_and, if_false]
|
||||
simp only [hnc, false_and, ite_false]
|
||||
rfl
|
||||
|
||||
/-- On cross-free selectors the unified reversed rule is the existing compact
|
||||
@@ -857,10 +859,10 @@ theorem completeReversedClosed_eq_closedFormOffsetOneRev {r : RangeRead} {res :
|
||||
completeReversedClosed r res = closedFormOffsetOneRev r res := by
|
||||
unfold completeReversedClosed closedFormOffsetOneRev
|
||||
by_cases h : r.end_.offset ≤ 1
|
||||
· rw [if_pos h, if_pos h]
|
||||
· rw [if_neg h, if_neg h]
|
||||
· rw [ite_eq_left h, ite_eq_left h]
|
||||
· rw [ite_eq_right h, ite_eq_right h]
|
||||
have hnc : ¬ r.end_.key < r.begin.key := not_lt.mpr hcross
|
||||
simp only [hnc, false_and, if_false]
|
||||
simp only [hnc, false_and, ite_false]
|
||||
rfl
|
||||
|
||||
/-- The complete closed-form rule at begin offset one, dispatching on traversal order. -/
|
||||
@@ -875,13 +877,13 @@ theorem minimal_completeClosed {r : RangeRead} {res : Result}
|
||||
Minimal r res (completeClosed r res) := by
|
||||
unfold completeClosed
|
||||
by_cases hrev : r.reverse = true
|
||||
· rw [if_pos hrev]
|
||||
· rw [ite_eq_left hrev]
|
||||
by_cases hcross : r.end_.key < r.begin.key
|
||||
· exact minimal_completeReversed_of_crossed hread hmore hne hrev hbegin hcross
|
||||
· have hcf : r.begin.key ≤ r.end_.key := not_lt.mp hcross
|
||||
rw [completeReversedClosed_eq_closedFormOffsetOneRev hcf]
|
||||
exact minimal_closedForm_of_offset_one_rev hread hmore hne hrev hbegin hcf
|
||||
· rw [if_neg hrev]
|
||||
· rw [ite_eq_right hrev]
|
||||
have hrevf : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
by_cases hcross : r.end_.key < r.begin.key
|
||||
|
||||
@@ -693,7 +693,7 @@ theorem completeKeys_eq_iff_filter_drop_of_room_general {db : DB} {r : RangeRead
|
||||
without changing compatibility. This is the general-offset form of
|
||||
`compatible_crossed_iff_endKeyToBegin_of_room`. -/
|
||||
theorem compatible_crossed_iff_endKeyToBegin_of_room_general {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(_hread : Readable r res) (hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 2 ≤ r.end_.offset)
|
||||
(htb : res.keys.length + (r.begin.offset - 1).toNat <
|
||||
@@ -762,7 +762,8 @@ theorem compatible_crossed_iff_endKeyToBegin_of_room_general {r : RangeRead} {re
|
||||
· simp [hmore] at hdisj
|
||||
· refine ⟨?_, (completeKeys_eq_iff_filter_drop_of_room_general
|
||||
(db := db) (r := endKeyToBegin r) (res := res) (by simpa [endKeyToBegin] using hrev)
|
||||
(by simpa [endKeyToBegin] using hbegin) (by simpa [endKeyToBegin] using (by omega : 1 ≤ r.end_.offset))
|
||||
(by simpa [endKeyToBegin] using hbegin) (by simpa [endKeyToBegin] using (by omega : 1 ≤
|
||||
r.end_.offset))
|
||||
(by simp [endKeyToBegin]) hne hroom_db').mp heq.symm⟩
|
||||
simpa [endKeyToBegin, RangeRead.withinLimit] using hlim
|
||||
· rintro ⟨hlim, hfil⟩
|
||||
@@ -770,7 +771,8 @@ theorem compatible_crossed_iff_endKeyToBegin_of_room_general {r : RangeRead} {re
|
||||
· simpa [endKeyToBegin, RangeRead.withinLimit] using hlim
|
||||
· exact ((completeKeys_eq_iff_filter_drop_of_room_general
|
||||
(db := db) (r := endKeyToBegin r) (res := res) (by simpa [endKeyToBegin] using hrev)
|
||||
(by simpa [endKeyToBegin] using hbegin) (by simpa [endKeyToBegin] using (by omega : 1 ≤ r.end_.offset))
|
||||
(by simpa [endKeyToBegin] using hbegin) (by simpa [endKeyToBegin] using (by omega : 1 ≤
|
||||
r.end_.offset))
|
||||
(by simp [endKeyToBegin]) hne hroom_db').mpr hfil).symm
|
||||
rw [hbase_r, hbase_r']
|
||||
|
||||
@@ -815,7 +817,7 @@ theorem minimal_topRange_of_crossed_small_room_general {r : RangeRead} {res : Re
|
||||
(by simpa [r', endKeyToBegin] using hend)
|
||||
have hform : closedFormKeyEqComplete r' res = ⟨r.begin.key, ⊤⟩ := by
|
||||
unfold closedFormKeyEqComplete
|
||||
rw [if_neg htne]
|
||||
rw [ite_eq_right htne]
|
||||
simp [topRange, r', endKeyToBegin]
|
||||
rw [hform] at hmin'
|
||||
exact minimal_of_compatible_iff hiff hmin'
|
||||
@@ -826,7 +828,7 @@ stored keys just above `begin.key` and before the first reported key exist, are
|
||||
sorted, lie at or above `begin.key`, and lie strictly below every reported key. -/
|
||||
theorem crossed_pad_general {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(_hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (hres : res.keys = RangeRead.completeKeys db r) :
|
||||
∃ P : List Key, P.length = (r.begin.offset - 1).toNat ∧ P.SortedLT ∧
|
||||
(∀ x ∈ P, r.begin.key ≤ (x : WithTop Key)) ∧
|
||||
@@ -906,11 +908,11 @@ theorem crossed_pad_general {db : DB} {r : RangeRead} {res : Result}
|
||||
/-- Generic complete-window computation for a database of the form `P ++ res` with
|
||||
`P` padding of length `b`, all at or above the begin key and below the reported keys. -/
|
||||
theorem completeKeys_pad_eq_general {r : RangeRead} {res : Result} {P : List Key}
|
||||
(hPs : P.SortedLT) (hresS : res.keys.SortedLT)
|
||||
(_hPs : P.SortedLT) (_hresS : res.keys.SortedLT)
|
||||
(hPlen : P.length = (r.begin.offset - 1).toNat)
|
||||
(hPge : ∀ x ∈ P, r.begin.key ≤ (x : WithTop Key))
|
||||
(hresge : ∀ y ∈ res.keys, r.begin.key ≤ (y : WithTop Key))
|
||||
(hPlt : ∀ x ∈ P, ∀ y ∈ res.keys, x < y)
|
||||
(_hPlt : ∀ x ∈ P, ∀ y ∈ res.keys, x < y)
|
||||
(hsort : (P ++ res.keys).SortedLT)
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
@@ -951,7 +953,7 @@ theorem completeKeys_pad_eq_general {r : RangeRead} {res : Result} {P : List Key
|
||||
|
||||
|
||||
theorem completeKeys_length_pad_general {r : RangeRead} {res : Result} {Q : List Key}
|
||||
(hQs : Q.SortedLT) (hsort : (Q ++ res.keys).SortedLT)
|
||||
(_hQs : Q.SortedLT) (hsort : (Q ++ res.keys).SortedLT)
|
||||
(hQge : ∀ x ∈ Q, r.begin.key ≤ (x : WithTop Key))
|
||||
(hresge : ∀ y ∈ res.keys, r.begin.key ≤ (y : WithTop Key))
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
@@ -1017,7 +1019,7 @@ theorem necessary_of_begin_le_crossed_top_general {r : RangeRead} {res : Result}
|
||||
let dB : DB := dT.erase x
|
||||
have hdBkeys : dB.keys = P.erase x ++ res.keys := by
|
||||
simp only [dB, dT, DB.erase_keys]
|
||||
rw [List.erase_append, if_pos hxP]
|
||||
rw [List.erase_append, ite_eq_left hxP]
|
||||
have hQlen : (P.erase x).length = b - 1 := by
|
||||
rw [List.length_erase_of_mem hxP, hPlen']
|
||||
have hQs : (P.erase x).SortedLT :=
|
||||
@@ -1248,7 +1250,7 @@ theorem necessary_of_mem_interval_crossed_top_general {r : RangeRead} {res : Res
|
||||
exact le_trans (le_of_lt hcross)
|
||||
(le_trans hlast_ge_B (WithTop.coe_le_coe.mpr hCge))
|
||||
have hp₂ : cnt db₂ r.begin.key = s - 1 := by
|
||||
show db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s - 1
|
||||
change db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s - 1
|
||||
rw [hkeys₂, List.countP_append, List.countP_append, List.countP_append]
|
||||
have hHc : dbH.keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = dbH.keys.length :=
|
||||
@@ -1492,7 +1494,8 @@ theorem minimal_completeForwardCrossedGeneral {r : RangeRead} {res : Result}
|
||||
⟨r.end_.key, (keyAfter (res.keys.getLastD ([] : Key)) : WithTop Key)⟩ :=
|
||||
minimal_truncatedRange_of_crossed_finite_general hread hmore hne hrev hbegin hcross
|
||||
hend2 (by simpa [reportedAtEnd, endOvershoot] using hte)
|
||||
rw [completeForwardCrossedGeneral, if_neg (by omega : ¬ r.end_.offset ≤ 1), if_pos hte]
|
||||
rw [completeForwardCrossedGeneral, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ite_eq_left
|
||||
hte]
|
||||
exact hmin
|
||||
· have htlt : reportedAtEnd r res + (r.begin.offset - 1).toNat < endOvershoot r :=
|
||||
lt_of_le_of_ne htle hte
|
||||
@@ -1508,8 +1511,8 @@ theorem minimal_completeForwardCrossedGeneral {r : RangeRead} {res : Result}
|
||||
have hmin : Minimal r res ⟨r.end_.key, ⊤⟩ :=
|
||||
minimal_topRange_of_crossed_large_room_general hread hmore hrev hne hbegin hcross
|
||||
hend2 htb hroom'
|
||||
rw [completeForwardCrossedGeneral, if_neg (by omega : ¬ r.end_.offset ≤ 1),
|
||||
if_neg hte, if_pos hroom]
|
||||
rw [completeForwardCrossedGeneral, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1),
|
||||
ite_eq_right hte, ite_eq_left hroom]
|
||||
exact hmin
|
||||
· have hroom' : intervalCard r.end_.key r.begin.key <
|
||||
(((r.end_.offset - 1).toNat - res.keys.length -
|
||||
@@ -1518,8 +1521,8 @@ theorem minimal_completeForwardCrossedGeneral {r : RangeRead} {res : Result}
|
||||
have hmin : Minimal r res ⟨r.begin.key, ⊤⟩ :=
|
||||
minimal_topRange_of_crossed_small_room_general hread hmore hne hrev hbegin hcross
|
||||
hend2 htb hroom'
|
||||
rw [completeForwardCrossedGeneral, if_neg (by omega : ¬ r.end_.offset ≤ 1),
|
||||
if_neg hte, if_neg hroom]
|
||||
rw [completeForwardCrossedGeneral, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1),
|
||||
ite_eq_right hte, ite_eq_right hroom]
|
||||
exact hmin
|
||||
|
||||
end FormalConflictRange
|
||||
|
||||
@@ -153,7 +153,8 @@ theorem crossed_rev_b_le_capBL {db : DB} {r : RangeRead} {res : Result}
|
||||
rw [← hik, hltake]
|
||||
exact lt_of_lt_of_le hklt hhead_le_L
|
||||
have hbetween : between db B (((L : Key)) : WithTop Key) =
|
||||
lB.filter (fun k : Key => decide (((k : Key) : WithTop Key) < (((L : Key)) : WithTop Key))) := by
|
||||
lB.filter (fun k : Key => decide (((k : Key) : WithTop Key) < (((L : Key)) : WithTop Key)))
|
||||
:= by
|
||||
rw [between_eq_filter_above, ← hlB]
|
||||
have hfilter_len : b ≤ (lB.filter (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < (((L : Key)) : WithTop Key)))).length := by
|
||||
@@ -493,7 +494,7 @@ theorem crossed_residual_above_end_lt_of_agree {db db' : DB} {r : RangeRead} {re
|
||||
calc ((above db' E).length : ℕ∞) ≤ intervalCard E ((L : Key) : WithTop Key) + (t : ℕ∞) :=
|
||||
hsumcast
|
||||
_ < ((e - t : ℕ) : ℕ∞) + (t : ℕ∞) :=
|
||||
WithTop.add_lt_add_right (z := (t : ℕ∞)) (ENat.coe_ne_top t) hnot'
|
||||
WithTop.add_lt_add_right (z := (t : ℕ∞)) (ENat.natCast_ne_top t) hnot'
|
||||
_ = (e : ℕ∞) := by rw [← Nat.cast_add]; congr 1; omega
|
||||
have := ENat.natCast_lt_natCast.mp hlt
|
||||
simpa [E, e] using this
|
||||
@@ -682,7 +683,7 @@ theorem crossed_residual_necessary_below_last_not_cond {r : RangeRead} {res : Re
|
||||
List.drop_eq_nil_of_le (le_of_eq hPlen), List.nil_append, hR, List.reverse_reverse]
|
||||
have hcompFull : RangeRead.Compatible dbfull r res := by
|
||||
refine ⟨hcomp₀.1, Or.inl ⟨hmore, ?_, hne⟩⟩
|
||||
simpa [hckFull] using List.prefix_refl res.keys
|
||||
simp [hckFull]
|
||||
refine necessary_of_toggle ⟨dbfull, hcompFull, ?_⟩
|
||||
have hkFull : k ∈ dbfull.keys := by
|
||||
rw [hfullKeys]
|
||||
@@ -743,7 +744,7 @@ theorem orderedInsert_eq_append_of_forall_lt {l : List Key} {k : Key}
|
||||
| cons a t ih =>
|
||||
rw [List.orderedInsert_cons]
|
||||
have hat : a < k := h a (by simp)
|
||||
rw [if_neg (not_le.mpr hat), ih (fun x hx => h x (by simp [hx]))]
|
||||
rw [ite_eq_right (not_le.mpr hat), ih (fun x hx => h x (by simp [hx]))]
|
||||
rfl
|
||||
|
||||
/-- Under the failure of the capacity condition, every key above the reported head is
|
||||
|
||||
@@ -174,7 +174,7 @@ private theorem keys_lo_keyAfter_eq_filter_le {db : DB} {lo : WithTop Key} {last
|
||||
/-- In the finite branch the candidate range contains exactly the reported keys,
|
||||
reversed. -/
|
||||
theorem crossed_rev_finite_keys_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
@@ -261,8 +261,8 @@ theorem crossed_rev_res_ge_begin {db : DB} {r : RangeRead} {res : Result}
|
||||
the first `e` keys at or above `E` are those reported keys and the gap `[E, B)` is
|
||||
empty. -/
|
||||
theorem take_above_eq_of_range_keys_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(_hrev : r.reverse = true) (_hbegin : r.begin.offset = 1)
|
||||
(hcross : r.end_.key < r.begin.key) (_hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
(ht : res.keys.length = (r.end_.offset - 1).toNat)
|
||||
(hBR : ∀ k ∈ res.keys, r.begin.key ≤ (k : WithTop Key))
|
||||
@@ -577,7 +577,7 @@ theorem crossed_rev_insert_between_incompatible {db : DB} {r : RangeRead} {res :
|
||||
rw [hinskeys, hJeq, List.getElem?_insertIdx]
|
||||
have hlt : ¬ j + 1 < db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
have heq : ¬ j + 1 = db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
rw [if_neg hlt, if_neg heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hj]
|
||||
rw [ite_eq_right hlt, ite_eq_right heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hj]
|
||||
obtain ⟨_, hnewget⟩ := List.getElem?_eq_some_iff.mp hnewget?
|
||||
have hHresolve : resolve (db.insert k hk0) r.end_ = ((H : Key) : WithTop Key) := by
|
||||
rw [resolve_eq_getElem (anchor_nonneg_of_one_le (by omega)) hnewlen]
|
||||
@@ -620,7 +620,8 @@ theorem crossed_rev_no_key_between {db : DB} {r : RangeRead} {res : Result}
|
||||
hcross (by omega) ⟨db, hcomp⟩
|
||||
rw [← hcount]
|
||||
exact ht
|
||||
have hT := crossed_rev_finite_keys_eq (db := db) hcomp hmore hrev hbegin hcross (by omega) hne htlen
|
||||
have hT := crossed_rev_finite_keys_eq (db := db) hcomp hmore hrev hbegin hcross (by omega) hne
|
||||
htlen
|
||||
have hmem : k ∈ (⟨r.end_.key,
|
||||
(keyAfter (res.keys.head hne) : WithTop Key)⟩ : ConflictRange).keys db := by
|
||||
rw [ConflictRange.mem_keys_iff]
|
||||
@@ -724,7 +725,7 @@ theorem completeKeys_filter_ge_crossed_rev_of_room {db : DB} {r : RangeRead}
|
||||
or above `begin.key`. -/
|
||||
theorem completeKeys_crossed_rev_eq_take_above_begin {db : DB} {r : RangeRead}
|
||||
(hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset) :
|
||||
(_hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset) :
|
||||
RangeRead.completeKeys db r =
|
||||
((above db r.begin.key).take
|
||||
(min (cnt db r.end_.key + (r.end_.offset - 1).toNat) db.keys.length -
|
||||
@@ -960,7 +961,7 @@ theorem sound_truncatedRevCrossed_top_last {r : RangeRead} {res : Result}
|
||||
|
||||
theorem crossed_rev_pad_top_necessary {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hbegin : r.begin.offset = 1) (hcross : r.end_.key < r.begin.key)
|
||||
(hbegin : r.begin.offset = 1) (_hcross : r.end_.key < r.begin.key)
|
||||
(hend : 2 ≤ r.end_.offset) (hne : res.keys ≠ [])
|
||||
{E : Key} (hE : r.end_.key = (E : WithTop Key))
|
||||
(hEL : (E : WithTop Key) < ((res.keys.getLast hne : Key) : WithTop Key))
|
||||
@@ -1041,7 +1042,8 @@ theorem crossed_rev_pad_top_necessary {r : RangeRead} {res : Result}
|
||||
have hP_sorted : P.SortedLT := by
|
||||
rw [hPdef]
|
||||
exact List.sortedLT_iff_pairwise.mpr
|
||||
(List.Pairwise.take (i := n) (List.Pairwise.erase k (List.sortedLT_iff_pairwise.mp hS_sorted)))
|
||||
(List.Pairwise.take (i := n) (List.Pairwise.erase k (List.sortedLT_iff_pairwise.mp
|
||||
hS_sorted)))
|
||||
have hP_sub : P ⊆ S := by
|
||||
intro x hx
|
||||
rw [hPdef] at hx
|
||||
@@ -1343,7 +1345,8 @@ theorem minimal_topRevCrossed_begin_last {r : RangeRead} {res : Result}
|
||||
· have hLno : L ≤ keyAfterN n E :=
|
||||
le_trans hLE (keyAfterN_le_self E n)
|
||||
refine (minimal_iff_sound_and_necessary).mpr
|
||||
⟨sound_truncatedRevCrossed_top_last hmore hrev hbegin hcross (by omega) hne hE hL hn' hLno, ?_⟩
|
||||
⟨sound_truncatedRevCrossed_top_last hmore hrev hbegin hcross (by omega) hne hE hL hn' hLno,
|
||||
?_⟩
|
||||
intro k hk
|
||||
have hLk : L ≤ k := WithTop.coe_le_coe.mp hk.1
|
||||
by_cases hkH : k ≤ res.keys.head hne
|
||||
@@ -1421,12 +1424,12 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC_crossed
|
||||
(r.end_.offset - 1).toNat := by
|
||||
rw [hcount]; exact hlen_le_e
|
||||
unfold closedFormOffsetOneTruncatedRevFullC
|
||||
rw [if_neg (by omega : ¬ r.end_.offset ≤ 1)]
|
||||
rw [ite_eq_right (by omega : ¬ r.end_.offset ≤ 1)]
|
||||
dsimp only
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
(r.end_.offset - 1).toNat
|
||||
· rw [if_pos ht]
|
||||
· rw [ite_eq_left ht]
|
||||
have htlen : res.keys.length = (r.end_.offset - 1).toNat := by
|
||||
rw [← hcount]; exact ht
|
||||
have hEL : r.end_.key ≤ ((res.keys.getLastD ([] : Key) : Key) : WithTop Key) := by
|
||||
@@ -1438,7 +1441,7 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC_crossed
|
||||
r.end_.key := min_eq_right hEL
|
||||
rw [hmin_eq]
|
||||
exact minimal_truncatedRevCrossed_finite hread' hmore hrev hbegin hcross hend hne htlen
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_right ht]
|
||||
have hlt : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) <
|
||||
(r.end_.offset - 1).toNat := lt_of_le_of_ne hcount_le ht
|
||||
@@ -1454,14 +1457,14 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC_crossed
|
||||
by_cases hroom : keyAfterN ((r.end_.offset - 1).toNat -
|
||||
res.keys.countP (fun k : Key => decide ((↑E : WithTop Key) ≤ (k : WithTop Key))) - 1)
|
||||
E < res.keys.getLastD ([] : Key)
|
||||
· rw [if_pos hroom]
|
||||
· rw [ite_eq_left hroom]
|
||||
have hroom' : keyAfterN ((r.end_.offset - 1).toNat -
|
||||
res.keys.countP (fun k : Key => decide ((↑E : WithTop Key) ≤ (k : WithTop Key))) - 1)
|
||||
E < res.keys.getLast hne := by
|
||||
rw [← hlast]; exact hroom
|
||||
exact minimal_topRevCrossed_begin_end hread' hmore hrev hbegin hcross hend hne hkey
|
||||
rfl (by rw [hkey]) hlt hroom'
|
||||
· rw [if_neg hroom]
|
||||
· rw [ite_eq_right hroom]
|
||||
have hge : res.keys.getLastD ([] : Key) ≤ keyAfterN ((r.end_.offset - 1).toNat -
|
||||
res.keys.countP (fun k : Key => decide ((↑E : WithTop Key) ≤ (k : WithTop Key))) - 1)
|
||||
E := le_of_not_gt hroom
|
||||
|
||||
@@ -82,8 +82,8 @@ theorem crossed_rev_res_ge_begin_general {db : DB} {r : RangeRead} {res : Result
|
||||
keys at or above `end_.key`. -/
|
||||
theorem crossed_rev_res_ge_end_general {db : DB} {r : RangeRead} {res : Result}
|
||||
(hc : RangeRead.Compatible db r res)
|
||||
(hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset) :
|
||||
(_hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (_hend : 1 ≤ r.end_.offset) :
|
||||
∀ k ∈ res.keys, r.end_.key ≤ (k : WithTop Key) := by
|
||||
intro k hk
|
||||
have hge := crossed_rev_res_ge_begin_general hc hbegin k hk
|
||||
@@ -149,7 +149,7 @@ theorem sound_truncatedRevCrossed_top_general {r : RangeRead} {res : Result}
|
||||
reversed truncated read, the complete keys are exactly the reported keys. -/
|
||||
theorem completeKeys_eq_res_of_crossed_rev_finite_general {db : DB} {r : RangeRead}
|
||||
{res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
@@ -271,7 +271,7 @@ theorem crossed_rev_finite_above_filter_eq_take_general {db : DB} {r : RangeRead
|
||||
|
||||
/-- In the finite branch the gap `[end_.key, begin_.key)` stores no key. -/
|
||||
theorem crossed_rev_finite_gap_eq_zero_general {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
@@ -622,7 +622,7 @@ theorem crossed_rev_insert_between_incompatible_general {db : DB} {r : RangeRead
|
||||
rw [hinskeys, hJeq, List.getElem?_insertIdx]
|
||||
have hlt : ¬ j + 1 < db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
have heq : ¬ j + 1 = db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
rw [if_neg hlt, if_neg heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hjeq]
|
||||
rw [ite_eq_right hlt, ite_eq_right heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hjeq]
|
||||
obtain ⟨_, hnewget⟩ := List.getElem?_eq_some_iff.mp hnewget?
|
||||
have hHresolve : resolve (db.insert k hk0) r.end_ = ((H : Key) : WithTop Key) := by
|
||||
rw [resolve_eq_getElem (anchor_nonneg_of_one_le hend) hnewlen]
|
||||
@@ -710,12 +710,12 @@ theorem crossed_rev_finite_last_lookup_general {db : DB} {r : RangeRead} {res :
|
||||
have hgoal? : lE[b]? = some (res.keys.getLast hne) := by
|
||||
rw [hdecomp]
|
||||
rw [List.getElem?_append]
|
||||
rw [if_pos (by
|
||||
rw [ite_eq_left (by
|
||||
rw [List.length_append, hP_len, List.length_reverse]
|
||||
have htpos : 0 < res.keys.length := List.length_pos_of_ne_nil hne
|
||||
omega)]
|
||||
rw [List.getElem?_append]
|
||||
rw [if_neg (by rw [hP_len]; omega)]
|
||||
rw [ite_eq_right (by rw [hP_len]; omega)]
|
||||
have hidx : b - (lE.take b).length = 0 := by rw [hP_len]; omega
|
||||
rw [hidx]
|
||||
have hpos : 0 < res.keys.length := List.length_pos_of_ne_nil hne
|
||||
@@ -731,7 +731,7 @@ theorem crossed_rev_finite_last_lookup_general {db : DB} {r : RangeRead} {res :
|
||||
/-- Erasing `k` from the database removes it from the keys at or above `E` when it was
|
||||
there. -/
|
||||
theorem above_erase_of_mem (db : DB) (E : WithTop Key) {k : Key}
|
||||
(hk : k ∈ above db E) : above (db.erase k) E = (above db E).erase k := by
|
||||
(_hk : k ∈ above db E) : above (db.erase k) E = (above db E).erase k := by
|
||||
rw [above_eq_filter, above_eq_filter, DB.erase_keys, ← List.erase_filter]
|
||||
|
||||
/-- Erasing `k` from `[E, B)` removes it from the erased database's gap. -/
|
||||
@@ -777,7 +777,7 @@ theorem crossed_rev_finite_mem_take_of_lt_last_general {db : DB} {r : RangeRead}
|
||||
/-- In the finite crossed reversed branch, erasing a reported key makes the result
|
||||
incompatible. -/
|
||||
theorem crossed_rev_erase_reported_incompatible_general {db : DB} {r : RangeRead}
|
||||
{res : Result} {k : Key} (hcomp : RangeRead.Compatible db r res)
|
||||
{res : Result} {k : Key} (_hcomp : RangeRead.Compatible db r res)
|
||||
(hk : k ∈ res.keys) :
|
||||
¬ RangeRead.Compatible (db.erase k) r res := by
|
||||
intro hc
|
||||
@@ -819,7 +819,7 @@ theorem crossed_rev_finite_erase_pad_incompatible_general {db : DB} {r : RangeRe
|
||||
have hcountErase : (lE.erase k).countP (fun x : Key => decide (x < L)) = b - 1 := by
|
||||
rw [List.countP_erase, hcount]
|
||||
have hcond : k ∈ lE ∧ decide (k < L) = true := ⟨hklE, by simp [hklt]⟩
|
||||
rw [if_pos hcond]
|
||||
rw [ite_eq_left hcond]
|
||||
have hLmemErase : L ∈ lE.erase k := by
|
||||
have hLmem : L ∈ lE := hLlookup' ▸ List.getElem_mem hbL
|
||||
exact (List.mem_erase_of_ne (ne_of_gt hklt)).mpr hLmem
|
||||
|
||||
@@ -162,7 +162,7 @@ private theorem keys_lo_keyAfter_eq_filter_le {db : DB} {lo : WithTop Key} {last
|
||||
rw [decide_eq_decide, WithTop.coe_lt_coe, lt_keyAfter_iff]
|
||||
|
||||
private theorem filter_ge_last_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key} {last : Key}
|
||||
(hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
(hEB : E ≤ B) (_hBlast : B ≤ (last : WithTop Key)) :
|
||||
(db.keys.filter (fun k : Key => decide (B ≤ (k : WithTop Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last)) =
|
||||
((⟨E, (keyAfter last : Key)⟩ : ConflictRange).keys db).filter
|
||||
@@ -180,7 +180,7 @@ private theorem filter_ge_last_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key
|
||||
exact ⟨hl, hB⟩
|
||||
|
||||
private theorem between_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key} {last : Key}
|
||||
(hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
(_hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
between db E B =
|
||||
((⟨E, (keyAfter last : Key)⟩ : ConflictRange).keys db).filter
|
||||
(fun k : Key => decide ((k : WithTop Key) < B)) := by
|
||||
@@ -188,7 +188,8 @@ private theorem between_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key} {last
|
||||
simp only [List.filter_filter]
|
||||
unfold between
|
||||
rw [show db.keys.filter (fun k : Key => decide (E ≤ (k : WithTop Key) ∧ (k : WithTop Key) < B)) =
|
||||
db.keys.filter (fun k : Key => decide ((k : WithTop Key) < B) && decide (E ≤ (k : WithTop Key))) from
|
||||
db.keys.filter (fun k : Key => decide ((k : WithTop Key) < B) && decide (E ≤ (k : WithTop
|
||||
Key))) from
|
||||
List.filter_congr fun k _ => by rw [Bool.decide_and, Bool.and_comm]]
|
||||
apply List.filter_congr
|
||||
intro k _
|
||||
@@ -248,7 +249,8 @@ theorem completeKeys_filter_le_eq_of_agree_crossed {r : RangeRead} {last : Key}
|
||||
have hCtake : C = A.take q := by
|
||||
rw [hCdef, hq]
|
||||
exact filter_le_eq_take_countP hAs last
|
||||
have hqC : C.length = q := by rw [hCtake, List.length_take, Nat.min_eq_left (by rw [hq]; exact List.countP_le_length)]
|
||||
have hqC : C.length = q := by rw [hCtake, List.length_take, Nat.min_eq_left (by rw [hq]; exact
|
||||
List.countP_le_length)]
|
||||
have hCAlen : C.length ≤ A.length := by rw [hCtake]; exact (List.take_sublist q A).length_le
|
||||
have hcB : l.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) =
|
||||
l.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)) +
|
||||
@@ -257,7 +259,8 @@ theorem completeKeys_filter_le_eq_of_agree_crossed {r : RangeRead} {last : Key}
|
||||
have hM : min (l.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)) + e)
|
||||
l.length - l.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) =
|
||||
min (e - (between db r.end_.key r.begin.key).length) A.length := by
|
||||
have hA_eq : A = l.drop (l.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key))) := by
|
||||
have hA_eq : A = l.drop (l.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)))
|
||||
:= by
|
||||
rw [hA]
|
||||
have hdrop := filter_not_lt_eq_drop_countP hls r.begin.key
|
||||
rw [← hdrop]
|
||||
@@ -265,7 +268,8 @@ theorem completeKeys_filter_le_eq_of_agree_crossed {r : RangeRead} {last : Key}
|
||||
intro k _
|
||||
rw [decide_eq_decide]
|
||||
exact not_lt.symm
|
||||
have hAlen : A.length = l.length - l.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) := by
|
||||
have hAlen : A.length = l.length - l.countP (fun k : Key => decide ((k : WithTop Key) <
|
||||
r.begin.key)) := by
|
||||
rw [hA_eq, List.length_drop]
|
||||
rw [hcB, hAlen]
|
||||
omega
|
||||
@@ -338,7 +342,7 @@ private theorem enat_succ_le_of_lt {s : ℕ} {h : ℕ∞} (hs : (s : ℕ∞) < h
|
||||
cases h with
|
||||
| top => exact le_top
|
||||
| coe n =>
|
||||
rw [ENat.coe_lt_coe] at hs
|
||||
rw [ENat.natCast_lt_natCast] at hs
|
||||
exact_mod_cast Nat.succ_le_of_lt hs
|
||||
|
||||
/-- **Gap-key necessity for the forward truncated crossed read.** When the gap
|
||||
@@ -471,7 +475,7 @@ theorem necessary_of_mem_gap_crossed_truncated {r : RangeRead} {res : Result} {k
|
||||
exact le_trans (le_of_lt hcross)
|
||||
(le_trans hlast_ge_B (WithTop.coe_le_coe.mpr hCge))
|
||||
have hcB₂ : cnt db₂ r.begin.key = s := by
|
||||
show db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s
|
||||
change db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s
|
||||
rw [hdb₂, List.countP_append, List.countP_append]
|
||||
have hHc : dbH.keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = dbH.keys.length :=
|
||||
@@ -723,9 +727,9 @@ theorem minimal_truncatedForwardClosed_of_crossed {r : RangeRead} {res : Result}
|
||||
unfold truncatedForwardClosed
|
||||
by_cases hbig : intervalCard r.end_.key r.begin.key ≤
|
||||
(((r.end_.offset - 1).toNat - res.keys.length : ℕ) : ℕ∞)
|
||||
· rw [if_pos hbig]
|
||||
· rw [ite_eq_left hbig]
|
||||
exact minimal_truncatedRange_of_crossed_B hread hmore hrev hne hbegin hcross hend hbig
|
||||
· rw [if_neg hbig]
|
||||
· rw [ite_eq_right hbig]
|
||||
exact minimal_truncatedForward_of_crossed hread hmore hrev hne hbegin hcross hend
|
||||
(not_le.mp hbig)
|
||||
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import FormalConflictRange.CrossedGeneral
|
||||
|
||||
/-!
|
||||
# Forward crossed truncated general cells.
|
||||
-/
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
namespace FormalConflictRange
|
||||
@@ -74,7 +78,7 @@ namespace FormalConflictRange
|
||||
/-- In the crossed forward truncated B-branch, agreement on the truncated range
|
||||
forced the reported last to stay strictly below the resolved end. -/
|
||||
theorem crossed_truncated_hlr_of_drop_gap {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset) (hend : 1 ≤ r.end_.offset)
|
||||
(_hrev : r.reverse = false) (_hbegin : 1 ≤ r.begin.offset) (hend : 1 ≤ r.end_.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hne : res.keys ≠ [])
|
||||
(hgap : (between db r.end_.key r.begin.key).length + (r.begin.offset - 1).toNat +
|
||||
res.keys.length ≤ (r.end_.offset - 1).toNat)
|
||||
@@ -164,7 +168,7 @@ namespace FormalConflictRange
|
||||
/-- A compatible crossed truncated result bounds the number of stored keys in the
|
||||
selector gap: `gap + begin-offset-padding + reported-length ≤ end-overshoot`. -/
|
||||
theorem compatible_gap_bound {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hrev : r.reverse = false) (_hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hbegin : 1 ≤ r.begin.offset) (hend : 1 ≤ r.end_.offset)
|
||||
(hcross : r.end_.key < r.begin.key)
|
||||
(hc : RangeRead.Compatible db r res) :
|
||||
@@ -251,7 +255,7 @@ namespace FormalConflictRange
|
||||
/-- General crossed complete keys filtered at or below the last reported key. -/
|
||||
theorem completeKeys_filter_le_eq_crossed_general {db : DB} {r : RangeRead} {last : Key}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset) (hend : 1 ≤ r.end_.offset)
|
||||
(hEB : r.end_.key ≤ r.begin.key) (hBlast : r.begin.key ≤ (last : WithTop Key)) :
|
||||
(hEB : r.end_.key ≤ r.begin.key) (_hBlast : r.begin.key ≤ (last : WithTop Key)) :
|
||||
(RangeRead.completeKeys db r).filter (fun k : Key => decide (k ≤ last)) =
|
||||
(((db.keys.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last))).take
|
||||
@@ -345,7 +349,8 @@ end FormalConflictRange
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
private theorem crossedTrunc_keys_lo_keyAfter_eq_filter_le {db : DB} {lo : WithTop Key} {last : Key} :
|
||||
private theorem crossedTrunc_keys_lo_keyAfter_eq_filter_le {db : DB} {lo : WithTop Key} {last :
|
||||
Key} :
|
||||
(⟨lo, (keyAfter last : Key)⟩ : ConflictRange).keys db =
|
||||
(db.keys.filter (fun k : Key => decide (lo ≤ (k : WithTop Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last)) := by
|
||||
@@ -361,8 +366,9 @@ private theorem crossedTrunc_keys_lo_keyAfter_eq_filter_le {db : DB} {lo : WithT
|
||||
intro k _
|
||||
rw [decide_eq_decide, WithTop.coe_lt_coe, lt_keyAfter_iff]
|
||||
|
||||
private theorem crossedTrunc_filter_ge_last_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key} {last : Key}
|
||||
(hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
private theorem crossedTrunc_filter_ge_last_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key}
|
||||
{last : Key}
|
||||
(hEB : E ≤ B) (_hBlast : B ≤ (last : WithTop Key)) :
|
||||
(db.keys.filter (fun k : Key => decide (B ≤ (k : WithTop Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last)) =
|
||||
((⟨E, (keyAfter last : Key)⟩ : ConflictRange).keys db).filter
|
||||
@@ -380,7 +386,7 @@ private theorem crossedTrunc_filter_ge_last_eq_filter_of_keys_eq {db : DB} {E B
|
||||
exact ⟨hl, hB⟩
|
||||
|
||||
private theorem crossedTrunc_between_eq_filter_of_keys_eq {db : DB} {E B : WithTop Key} {last : Key}
|
||||
(hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
(_hEB : E ≤ B) (hBlast : B ≤ (last : WithTop Key)) :
|
||||
between db E B =
|
||||
((⟨E, (keyAfter last : Key)⟩ : ConflictRange).keys db).filter
|
||||
(fun k : Key => decide ((k : WithTop Key) < B)) := by
|
||||
@@ -388,7 +394,8 @@ private theorem crossedTrunc_between_eq_filter_of_keys_eq {db : DB} {E B : WithT
|
||||
simp only [List.filter_filter]
|
||||
unfold between
|
||||
rw [show db.keys.filter (fun k : Key => decide (E ≤ (k : WithTop Key) ∧ (k : WithTop Key) < B)) =
|
||||
db.keys.filter (fun k : Key => decide ((k : WithTop Key) < B) && decide (E ≤ (k : WithTop Key))) from
|
||||
db.keys.filter (fun k : Key => decide ((k : WithTop Key) < B) && decide (E ≤ (k : WithTop
|
||||
Key))) from
|
||||
List.filter_congr fun k _ => by rw [Bool.decide_and, Bool.and_comm]]
|
||||
apply List.filter_congr
|
||||
intro k _
|
||||
@@ -404,7 +411,7 @@ private theorem crossedTrunc_between_eq_filter_of_keys_eq {db : DB} {E B : WithT
|
||||
/-- A compatible crossed truncated result reports only keys at or above `begin_.key`,
|
||||
at any positive begin offset. -/
|
||||
theorem le_begin_key_of_compatible_crossed_general {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset) (hne : res.keys ≠ [])
|
||||
(_hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset) (hne : res.keys ≠ [])
|
||||
(hc : RangeRead.Compatible db r res) :
|
||||
r.begin.key ≤ (res.keys.getLast hne : WithTop Key) := by
|
||||
have hmem : res.keys.getLast hne ∈ RangeRead.completeKeys db r :=
|
||||
@@ -613,7 +620,7 @@ namespace FormalConflictRange
|
||||
/-- Extract the begin-offset padding `P` from a compatible truncated crossed read. -/
|
||||
theorem crossed_pad_truncated_general {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(_hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (hc : RangeRead.Compatible db r res) :
|
||||
∃ P : List Key, P.length = (r.begin.offset - 1).toNat ∧ P.SortedLT ∧
|
||||
(∀ x ∈ P, r.begin.key ≤ (x : WithTop Key)) ∧
|
||||
@@ -686,7 +693,7 @@ private theorem crossedTrunc_enat_succ_le_of_lt {s : ℕ} {h : ℕ∞} (hs : (s
|
||||
cases h with
|
||||
| top => exact le_top
|
||||
| coe n =>
|
||||
rw [ENat.coe_lt_coe] at hs
|
||||
rw [ENat.natCast_lt_natCast] at hs
|
||||
exact_mod_cast Nat.succ_le_of_lt hs
|
||||
|
||||
/-- **Gap-key necessity for the forward truncated crossed read at any positive begin
|
||||
@@ -823,7 +830,7 @@ theorem necessary_of_mem_gap_crossed_truncated_general {r : RangeRead} {res : Re
|
||||
exact le_trans (le_of_lt hcross)
|
||||
(le_trans hlast_ge_B (WithTop.coe_le_coe.mpr hCge))
|
||||
have hcB₂ : cnt db₂ r.begin.key = s := by
|
||||
show db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s
|
||||
change db₂.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = s
|
||||
rw [hdb₂, List.countP_append, List.countP_append, List.countP_append]
|
||||
have hHc : dbH.keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = dbH.keys.length :=
|
||||
@@ -937,7 +944,8 @@ theorem necessary_of_mem_gap_crossed_truncated_general {r : RangeRead} {res : Re
|
||||
omega
|
||||
have hK' : min (db₁.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.end_.key)) +
|
||||
(r.end_.offset - 1).toNat) db₁.keys.length -
|
||||
(db₁.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) + b) = t - 1 := by
|
||||
(db₁.keys.countP (fun x : Key => decide ((x : WithTop Key) < r.begin.key)) + b) = t - 1 :=
|
||||
by
|
||||
simpa [cnt] using hK
|
||||
rw [hK', List.take_append_of_le_length (by omega : t - 1 ≤ res.keys.length)]
|
||||
have hnot₁ : ¬ RangeRead.Compatible db₁ r res := by
|
||||
|
||||
@@ -45,7 +45,7 @@ theorem countAtWith_eq_pref (base : ℕ) {bounds : List Key} {counts : List ℕ}
|
||||
· exact absurd rfl hkb
|
||||
· exact hkbs
|
||||
rw [List.idxOf_cons_ne bs (fun h => hkb h.symm)]
|
||||
simp only [countAtWith, if_neg hkb]
|
||||
simp only [countAtWith, ite_eq_right hkb]
|
||||
rw [ih (base := base + d) hlen' hkbs]
|
||||
simp [pref, List.take_succ_cons, List.sum_cons]
|
||||
omega
|
||||
@@ -62,7 +62,7 @@ def capEdgesAux (start : Key) (bounds : List Key) (i : ℕ) : List DEdge :=
|
||||
| [] => []
|
||||
| b :: bs =>
|
||||
[⟨i + 1, i, 0⟩] ++
|
||||
(if h : intervalCard (start : WithTop Key) (b : WithTop Key) = ⊤ then []
|
||||
(if _h : intervalCard (start : WithTop Key) (b : WithTop Key) = ⊤ then []
|
||||
else [⟨i, i + 1, ((intervalCard (start : WithTop Key) (b : WithTop Key)).toNat : ℤ)⟩]) ++
|
||||
capEdgesAux b bs (i + 1)
|
||||
|
||||
@@ -169,7 +169,7 @@ theorem length_eq_of_countsFit {start : Key} {bounds : List Key} {counts : List
|
||||
| cons b bs ih =>
|
||||
cases counts with
|
||||
| nil => simp [CountsFit] at h
|
||||
| cons d ds => simp [CountsFit] at h; exact congrArg Nat.succ (ih h.2.2)
|
||||
| cons d ds => simp only [CountsFit] at h; exact congrArg Nat.succ (ih h.2.2)
|
||||
|
||||
/-- Capacity edges hold when the prefix-cumulative assignment comes from a
|
||||
capacity-fitting count list. -/
|
||||
@@ -197,7 +197,8 @@ theorem capEdgesAux_holds_of_countsFit {start : Key} {bounds : List Key}
|
||||
have hnonneg : x i - x (i + 1) ≤ 0 := by linarith [hhead]
|
||||
have hcapEdge : HoldsAll x
|
||||
(if h : intervalCard (start : WithTop Key) (b : WithTop Key) = ⊤ then []
|
||||
else [⟨i, i + 1, ((intervalCard (start : WithTop Key) (b : WithTop Key)).toNat : ℤ)⟩]) := by
|
||||
else [⟨i, i + 1, ((intervalCard (start : WithTop Key) (b : WithTop Key)).toNat :
|
||||
ℤ)⟩]) := by
|
||||
by_cases htop : intervalCard (start : WithTop Key) (b : WithTop Key) = ⊤
|
||||
· simp [htop, HoldsAll]
|
||||
· intro e he
|
||||
@@ -269,7 +270,7 @@ theorem countsFit_of_capEdgesAux {start : Key} {bounds : List Key}
|
||||
/-- Evaluation of the count environment is the corresponding cumulative variable. -/
|
||||
theorem evalCount_eq_countsToX {bounds : List Key} {counts : List ℕ}
|
||||
{topCount : ℕ} (hlen : counts.length = bounds.length)
|
||||
(hnoBot : ([] : Key) ∉ bounds) {e : WithTop Key}
|
||||
(_hnoBot : ([] : Key) ∉ bounds) {e : WithTop Key}
|
||||
(he : EndpointCovered e bounds) :
|
||||
evalCount bounds counts topCount e =
|
||||
countsToX bounds.length counts topCount (endpointIndex bounds e) := by
|
||||
@@ -287,7 +288,7 @@ theorem evalCount_eq_countsToX {bounds : List Key} {counts : List ℕ}
|
||||
have hlook := countAtWith_eq_pref (base := 0) hlen' hk
|
||||
have hne : bounds.idxOf k ≠ bounds.length := by omega
|
||||
have hnot : k ≠ ([] : Key) := hkbot
|
||||
simp [evalCount, countsToX, endpointIndex, hkbot, hnot, hne, hlook]
|
||||
simp [evalCount, countsToX, endpointIndex, hkbot, hne, hlook]
|
||||
|
||||
|
||||
/-- The toggled count environment is the untoggled one plus the toggle coefficient,
|
||||
@@ -308,7 +309,7 @@ theorem evalCountToggled_eq_add_toggleCoeff {bounds : List Key} {counts : List
|
||||
constraint system. -/
|
||||
theorem constraintEdges_holds_iff {bounds : List Key} {counts : List ℕ}
|
||||
{topCount : ℕ} {S : ConstraintSystem}
|
||||
(hlen : counts.length = bounds.length) {x : ℕ → ℤ}
|
||||
(_hlen : counts.length = bounds.length) {x : ℕ → ℤ}
|
||||
(hx : ∀ e : WithTop Key, EndpointCovered e bounds → x (endpointIndex bounds e) =
|
||||
evalCount bounds counts topCount e)
|
||||
(hcover : ∀ c ∈ S, EndpointCovered c.lo bounds ∧ EndpointCovered c.hi bounds) :
|
||||
@@ -406,7 +407,7 @@ theorem prefixCum_diffCounts {x : ℕ → ℤ} (h0 : x 0 = 0) (n : ℕ)
|
||||
intro k hk
|
||||
have hk0 : k = 0 := by simpa [diffCounts] using hk
|
||||
subst k
|
||||
simp [PrefixCum, h0, pref]
|
||||
simp [ h0, pref]
|
||||
| succ n ih =>
|
||||
intro k hk
|
||||
have hk' : k ≤ n + 1 := by simpa [diffCounts_length] using hk
|
||||
@@ -422,7 +423,7 @@ theorem prefixCum_diffCounts {x : ℕ → ℤ} (h0 : x 0 = 0) (n : ℕ)
|
||||
rw [diffCounts_length]]
|
||||
rw [pref_append_singleton_self, pref_length, diffCounts_length]
|
||||
have hprev := ih (fun i hi => hnonneg i (by omega)) n
|
||||
(by simpa [diffCounts_length] using le_refl n)
|
||||
(by simp [diffCounts_length])
|
||||
have hprefsum : pref (diffCounts x n) n = (diffCounts x n).sum :=
|
||||
pref_eq_sum_of_length_le (by rw [diffCounts_length])
|
||||
have hprev' : x n - x 0 = ((diffCounts x n).sum : ℤ) := by
|
||||
@@ -448,7 +449,7 @@ theorem eq_countsToX_of_prefixCum {x : ℕ → ℤ} {counts : List ℕ} {n topCo
|
||||
intro i hi
|
||||
by_cases hin : i = n + 1
|
||||
· subst i
|
||||
simp only [countsToX, if_pos rfl]
|
||||
simp only [countsToX]
|
||||
have hsum : x n = (pref counts n : ℤ) := by
|
||||
have := hpref n (by omega)
|
||||
simpa [h0] using this
|
||||
@@ -467,7 +468,7 @@ theorem eq_countsToX_of_prefixCum {x : ℕ → ℤ} {counts : List ℕ} {n topCo
|
||||
ring
|
||||
· have hi' : i ≤ n := by omega
|
||||
have hne : i ≠ n + 1 := hin
|
||||
simp only [countsToX, if_neg hne]
|
||||
simp only [countsToX, ite_eq_right hne]
|
||||
have := hpref i (by omega)
|
||||
simpa [h0] using this
|
||||
|
||||
@@ -511,8 +512,7 @@ theorem branchEqEdges_holds_iff {bounds : List Key} {counts : List ℕ}
|
||||
simp only [DEdge.Holds] at h1 h2
|
||||
rw [hxi, hxj] at h1 h2
|
||||
linarith
|
||||
· intro h
|
||||
intro e he
|
||||
· intro h e he
|
||||
simp only [List.mem_cons, List.not_mem_nil, or_false] at he
|
||||
rcases he with rfl | rfl
|
||||
· simp only [DEdge.Holds]
|
||||
@@ -537,8 +537,7 @@ theorem branchEqEdges_holds_iff {bounds : List Key} {counts : List ℕ}
|
||||
simp only [DEdge.Holds] at h1 h2
|
||||
rw [hxi, hxj] at h1 h2
|
||||
linarith
|
||||
· intro h
|
||||
intro e he
|
||||
· intro h e he
|
||||
simp only [List.mem_cons, List.not_mem_nil, or_false] at he
|
||||
rcases he with rfl | rfl
|
||||
· simp only [DEdge.Holds]
|
||||
@@ -599,11 +598,11 @@ theorem countFeasibleBranch_iff_diffFeasible
|
||||
simp only [DEdge.Holds]
|
||||
have hxn : x bounds.length = (counts.sum : ℤ) := by
|
||||
dsimp [x]
|
||||
rw [countsToX, if_neg (by omega)]
|
||||
rw [countsToX, ite_eq_right (by omega)]
|
||||
rw [pref_eq_sum_of_length_le (l := counts) (n := bounds.length) (by omega)]
|
||||
have hxt : x (bounds.length + 1) = ((counts.sum + topCount : ℕ) : ℤ) := by
|
||||
dsimp [x]
|
||||
rw [countsToX, if_pos rfl]
|
||||
rw [countsToX, ite_eq_left rfl]
|
||||
push_cast
|
||||
ring
|
||||
rw [hxn, hxt]
|
||||
@@ -695,7 +694,7 @@ theorem countFeasibleBranch_iff_diffFeasible
|
||||
intro hbot
|
||||
exact hnoBot (hbot ▸ ha)
|
||||
have hlt : bounds.idxOf a < bounds.length := List.idxOf_lt_length_iff.mpr ha
|
||||
simp only [endpointIndex, ha', if_false]
|
||||
simp only [endpointIndex, ha', ite_false]
|
||||
omega
|
||||
rw [hyAgree _ hidx]
|
||||
exact (evalCount_eq_countsToX hlen hnoBot he).symm
|
||||
@@ -727,8 +726,8 @@ branches. -/
|
||||
theorem countFeasible_iff_branch_or
|
||||
(bounds : List Key) (k : Key) (S : ConstraintSystem) (bad : List Constraint)
|
||||
(hnoBot : ([] : Key) ∉ bounds)
|
||||
(hcoverS : ∀ c ∈ S, EndpointCovered c.lo bounds ∧ EndpointCovered c.hi bounds)
|
||||
(hcoverBad : ∀ c ∈ bad, EndpointCovered c.lo bounds ∧ EndpointCovered c.hi bounds)
|
||||
(_hcoverS : ∀ c ∈ S, EndpointCovered c.lo bounds ∧ EndpointCovered c.hi bounds)
|
||||
(_hcoverBad : ∀ c ∈ bad, EndpointCovered c.lo bounds ∧ EndpointCovered c.hi bounds)
|
||||
(hk : k = ([] : Key) ∨ k ∈ bounds) (hka : keyAfter k ∈ bounds) :
|
||||
CountFeasible bounds k S bad ↔
|
||||
CountFeasibleBranch bounds k true S bad ∨
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import FormalConflictRange.NegCrossComplete
|
||||
|
||||
/-!
|
||||
# The negative-begin complete bottom cell.
|
||||
-/
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
namespace FormalConflictRange
|
||||
@@ -12,7 +16,7 @@ abbrev negCrossHeadBottom (r : RangeRead) (res : Result) : Prop :=
|
||||
res.keys.headD ([] : Key) = ([] : Key)
|
||||
|
||||
/-- The closed form for the negative-begin complete bottom cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossHeadBottom (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossHeadBottom (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -121,7 +125,7 @@ abbrev negCrossHeadBottomRev (r : RangeRead) (res : Result) : Prop :=
|
||||
res.keys.getLastD ([] : Key) = ([] : Key)
|
||||
|
||||
/-- The closed form for the reversed negative-begin complete bottom cell. -/
|
||||
noncomputable def closedFormNegCrossHeadBottomRev (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossHeadBottomRev (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ theorem clampLong_headD_eq {hne : res.keys ≠ []} :
|
||||
/-- Every reported key lies below `end_.key` in the crossed negative-begin complete
|
||||
long clamp cell. -/
|
||||
theorem clampLong_reported_lt_end (hread : Readable r res)
|
||||
(hrev : r.reverse = false) (hmore : res.more = false) (hend : r.end_.offset ≤ 0) :
|
||||
(_hrev : r.reverse = false) (hmore : res.more = false) (hend : r.end_.offset ≤ 0) :
|
||||
∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key := by
|
||||
obtain ⟨db, hcomp⟩ := hread
|
||||
have hres_eq : res.keys = RangeRead.completeKeys db r := by
|
||||
@@ -351,7 +351,8 @@ theorem exists_clampLong_db {r : RangeRead} {res : Result}
|
||||
omega
|
||||
have hdbk : db.keys = res.keys ++ L := by rw [hdb]
|
||||
have hRE : resolve db r.end_ = ((L.head hLne : Key) : WithTop Key) := by
|
||||
rw [resolve_eq_getElem hanchorE_nonneg (by rw [htoNatE, hdbk]; simp only [List.length_append]; omega)]
|
||||
rw [resolve_eq_getElem hanchorE_nonneg
|
||||
(by rw [htoNatE, hdbk]; simp only [List.length_append]; omega)]
|
||||
simp only [htoNatE, hdbk]
|
||||
rw [List.getElem_append_right (show res.keys.length ≤ res.keys.length by omega)]
|
||||
simp [List.head_eq_getElem]
|
||||
@@ -556,7 +557,8 @@ theorem exists_long_compat_db {r : RangeRead} {res : Result} {db₀ : DB}
|
||||
rw [List.filter_append, hBf, hGf, List.length_append]
|
||||
have hanchorE : r.end_.anchor db = ((H.length + res.keys.length : ℕ) : ℤ) := by
|
||||
unfold Selector.anchor
|
||||
have hc : db.keys.countP (fun k => decide (((k : Key) : WithTop Key) < r.end_.key)) = B.length := by
|
||||
have hc : db.keys.countP (fun k => decide (((k : Key) : WithTop Key) < r.end_.key)) = B.length
|
||||
:= by
|
||||
simpa [cnt] using hcntE
|
||||
rw [hc, hBlength]
|
||||
push_cast
|
||||
|
||||
@@ -29,7 +29,7 @@ abbrev negCrossClampNonposInfinite (r : RangeRead) (res : Result) : Prop :=
|
||||
|
||||
/-- The closed form for the infinite-capacity negative-begin complete clamp cell:
|
||||
`[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossClampNonposInfinite (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposInfinite (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -160,11 +160,11 @@ theorem between_resolve_end_length {db : DB} {r : RangeRead}
|
||||
cases hsome : L.reverse[d]? with
|
||||
| none =>
|
||||
rw [hsome] at hrev
|
||||
simp at hrev
|
||||
change resolve db r.end_ = (([] : Key) : WithTop Key) at hrev
|
||||
exact absurd hrev hne
|
||||
| some qv =>
|
||||
rw [hsome] at hrev
|
||||
simp at hrev
|
||||
change resolve db r.end_ = ((qv : Key) : WithTop Key) at hrev
|
||||
have hqv : resolve db r.end_ = ((qv : Key) : WithTop Key) := hrev
|
||||
obtain ⟨hdlt, hget⟩ := List.getElem?_eq_some_iff.mp hsome
|
||||
have hdlt' : d < L.length := by simpa using hdlt
|
||||
@@ -176,7 +176,8 @@ theorem between_resolve_end_length {db : DB} {r : RangeRead}
|
||||
countP_lt_eq_of_getElem hLsorted hilt higet
|
||||
-- length of the filter of keys at or above qv
|
||||
have hfilt : L.filter (fun k : Key => decide (qv ≤ k)) =
|
||||
L.filter (fun k : Key => decide (¬ (((k : Key) : WithTop Key) < ((qv : Key) : WithTop Key)))) := by
|
||||
L.filter (fun k : Key => decide (¬ (((k : Key) : WithTop Key) < ((qv : Key) : WithTop
|
||||
Key)))) := by
|
||||
apply List.filter_congr
|
||||
intro k _
|
||||
rw [decide_eq_decide]
|
||||
@@ -214,9 +215,9 @@ theorem between_resolve_end_length {db : DB} {r : RangeRead}
|
||||
theorem exists_clamp_compat_nonpos_infinite {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0)
|
||||
(hend : r.end_.offset ≤ 0) (hB_le_E : r.begin.key ≤ r.end_.key)
|
||||
(hend : r.end_.offset ≤ 0) (_hB_le_E : r.begin.key ≤ r.end_.key)
|
||||
(hinf : intervalCard r.begin.key r.end_.key = ⊤)
|
||||
(hcross : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(_hcross : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(hclamp : reportedBelowBegin r res ≤ beginSlack r) :
|
||||
∃ db : DB, RangeRead.Compatible db r res ∧ r.begin.anchor db < 0 := by
|
||||
obtain ⟨db₀, hcomp₀⟩ := hread
|
||||
@@ -322,7 +323,8 @@ theorem exists_clamp_compat_nonpos_infinite {r : RangeRead} {res : Result}
|
||||
have := hclamp; rw [hrepA] at this; exact_mod_cast this
|
||||
omega
|
||||
have hL_A : resolve dbA r.begin = (([] : Key) : WithTop Key) := resolve_eq_nil hanchorA
|
||||
have hfilt_b : dbA.keys.filter (fun k : Key => decide ((k : WithTop Key) < (↑b : WithTop Key))) =
|
||||
have hfilt_b : dbA.keys.filter (fun k : Key => decide ((k : WithTop Key) < (↑b : WithTop
|
||||
Key))) =
|
||||
res.keys := by
|
||||
rw [hdbA]
|
||||
rw [List.filter_append, List.filter_cons]
|
||||
@@ -347,7 +349,7 @@ theorem exists_clamp_compat_nonpos_infinite {r : RangeRead} {res : Result}
|
||||
exact hfilt_b
|
||||
exact ⟨dbA, ⟨hlim, Or.inr ⟨hmore, hckA.symm⟩⟩, hanchorA⟩
|
||||
· -- Option B: the reported last lies at or above `b`. Use the keys of `db₀` above it.
|
||||
push_neg at hlastB
|
||||
push Not at hlastB
|
||||
have hres_eq₀ : res.keys = RangeRead.completeKeys db₀ r := by
|
||||
rcases hcomp₀.2 with ⟨hm, _, _⟩ | ⟨-, heq⟩
|
||||
· simp [hmore] at hm
|
||||
@@ -363,7 +365,8 @@ theorem exists_clamp_compat_nonpos_infinite {r : RangeRead} {res : Result}
|
||||
· exact absurd hn hR_ne_nil
|
||||
· exact absurd ht (resolve_ne_top_of_offset_nonpos hend)
|
||||
· exact ⟨q, hqeq⟩
|
||||
have hlast_lt_r₀ : ((res.keys.getLast hne : Key) : WithTop Key) < ((r₀ : Key) : WithTop Key) := by
|
||||
have hlast_lt_r₀ : ((res.keys.getLast hne : Key) : WithTop Key) < ((r₀ : Key) : WithTop Key)
|
||||
:= by
|
||||
rw [← hr₀]; exact hlast_lt_R₀
|
||||
have hr₀_lt_E : ((r₀ : Key) : WithTop Key) < r.end_.key := by
|
||||
rw [← hr₀]
|
||||
@@ -426,7 +429,8 @@ theorem exists_clamp_compat_nonpos_infinite {r : RangeRead} {res : Result}
|
||||
(k : WithTop Key) ∧ (k : WithTop Key) < r.end_.key)) = L := by
|
||||
rw [hL, ← hr₀]
|
||||
rfl
|
||||
have hqspec : (db₀.keys.filter (fun k : Key => decide ((k : WithTop Key) < r.end_.key))).reverse[
|
||||
have hqspec : (db₀.keys.filter (fun k : Key => decide ((k : WithTop Key) <
|
||||
r.end_.key))).reverse[
|
||||
(-r.end_.offset).toNat]? = some r₀ :=
|
||||
resolve_filter_reverse_eq_some_of_ne_nil hend (by simpa [hr₀] using hR_ne_nil) hr₀
|
||||
have hR_B : resolve dbB r.end_ = ((r₀ : Key) : WithTop Key) := by
|
||||
@@ -495,12 +499,12 @@ theorem minimal_closedForm_of_negCross_clampNonpos_infinite {r : RangeRead} {res
|
||||
intro k hkbot hkE
|
||||
by_cases hkhead : ((k : Key) : WithTop Key) < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· exact necessary_below_head_of_anchor_nonpos_negCross db hcomp hrev hne hanchor hkhead
|
||||
· push_neg at hkhead
|
||||
· push Not at hkhead
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤
|
||||
((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hkhead) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
intro cr hs
|
||||
exact necessary_last_to_end_key hread hrev hmore hne (by omega) cr hs
|
||||
(le_of_lt (WithTop.coe_lt_coe.mp hklast)) hkE
|
||||
@@ -513,7 +517,7 @@ abbrev negCrossClampNonposInfiniteRev (r : RangeRead) (res : Result) : Prop :=
|
||||
reportedBelowBegin r res ≤ beginSlack r
|
||||
|
||||
/-- The closed form for the reversed cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossClampNonposInfiniteRev (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposInfiniteRev (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -559,7 +563,7 @@ abbrev negCrossClampNonposLastGe (r : RangeRead) (res : Result) : Prop :=
|
||||
reportedBelowBegin r res ≤ beginSlack r
|
||||
|
||||
/-- The closed form for the cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossClampNonposLastGe (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposLastGe (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -729,12 +733,12 @@ theorem minimal_closedForm_of_negCross_clampNonpos_lastGe {r : RangeRead} {res :
|
||||
intro k hkbot hkE
|
||||
by_cases hkhead : ((k : Key) : WithTop Key) < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· exact necessary_below_head_of_anchor_nonpos_negCross db hcomp hrev hne hanchor hkhead
|
||||
· push_neg at hkhead
|
||||
· push Not at hkhead
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤
|
||||
((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hkhead) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
intro cr hs
|
||||
exact necessary_last_to_end_key hread hrev hmore hne (by omega) cr hs
|
||||
(le_of_lt (WithTop.coe_lt_coe.mp hklast)) hkE
|
||||
@@ -750,7 +754,7 @@ abbrev negCrossClampNonposLastGeRev (r : RangeRead) (res : Result) : Prop :=
|
||||
reportedBelowBegin r res ≤ beginSlack r
|
||||
|
||||
/-- The closed form for the reversed cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossClampNonposLastGeRev (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposLastGeRev (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -803,7 +807,7 @@ theorem exists_pad_split {n : ℕ} {A C : ℕ∞}
|
||||
· refine ⟨n, 0, by omega, ?_, by simp, ?_⟩
|
||||
· rw [← hCeq]; exact_mod_cast hcn
|
||||
· rw [← hCeq, ← ENat.natCast_sub, Nat.sub_eq_zero_of_le hcn]
|
||||
· push_neg at hcn
|
||||
· push Not at hcn
|
||||
have hble : ((n - C.toNat : ℕ) : ℕ∞) ≤ A := by
|
||||
rw [← hCeq] at h
|
||||
rw [ENat.natCast_sub, tsub_le_iff_left, add_comm]
|
||||
@@ -991,7 +995,7 @@ theorem exists_clamp_compat_nonpos_bottom {r : RangeRead} {res : Result}
|
||||
exact hfilt_head
|
||||
exact ⟨db, ⟨hlim, Or.inr ⟨hmore, hck.symm⟩⟩, hanchor⟩
|
||||
· -- Case 2: pads split between `[X, begin.key)` and `[begin.key, end.key)`.
|
||||
push_neg at hBX
|
||||
push Not at hBX
|
||||
have hXB : ((X : Key) : WithTop Key) < r.begin.key := hBX
|
||||
have hadd : intervalCard ((X : Key) : WithTop Key) r.end_.key =
|
||||
intervalCard ((X : Key) : WithTop Key) r.begin.key +
|
||||
@@ -1149,7 +1153,7 @@ abbrev negCrossClampNonposBottom (r : RangeRead) (res : Result) : Prop :=
|
||||
clampNonposBottom r res
|
||||
|
||||
/-- The closed form for the finite-capacity clamp cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossClampNonposBottom (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposBottom (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -1165,12 +1169,12 @@ theorem minimal_closedForm_of_negCross_clampNonpos_bottom {r : RangeRead} {res :
|
||||
intro k hkbot hkE
|
||||
by_cases hkhead : ((k : Key) : WithTop Key) < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· exact necessary_below_head_of_anchor_nonpos_negCross db hcomp hrev hne hanchor hkhead
|
||||
· push_neg at hkhead
|
||||
· push Not at hkhead
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤
|
||||
((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hkhead) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
intro cr hs
|
||||
exact necessary_last_to_end_key hread hrev hmore hne (by omega) cr hs
|
||||
(le_of_lt (WithTop.coe_lt_coe.mp hklast)) hkE
|
||||
@@ -1183,7 +1187,7 @@ abbrev negCrossClampNonposBottomRev (r : RangeRead) (res : Result) : Prop :=
|
||||
clampNonposBottom r res
|
||||
|
||||
/-- The closed form for the reversed finite-capacity clamp cell. -/
|
||||
noncomputable def closedFormNegCrossClampNonposBottomRev (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossClampNonposBottomRev (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ theorem resolve_begin_eq_head_of_negCross_compat {db : DB} {r : RangeRead} {res
|
||||
(hmore : res.more = false) (hne : res.keys ≠ []) (hbegin : r.begin.offset < 0)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(hhi : ∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key)
|
||||
(hcross : ((res.keys.head hne : Key) : WithTop Key) < r.begin.key)
|
||||
(_hcross : ((res.keys.head hne : Key) : WithTop Key) < r.begin.key)
|
||||
(hnonclamp : beginSlack r < reportedBelowBegin r res) :
|
||||
resolve db r.begin = ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
set head : Key := res.keys.head hne with hhead
|
||||
@@ -633,7 +633,7 @@ theorem minimal_closedForm_of_negCross_overshoot_rev {r : RangeRead} {res : Resu
|
||||
intro k hk
|
||||
exact hhi k (by simpa [res'] using hk)
|
||||
have hhead' : res'.keys.head hne' = res.keys.getLast hne := by
|
||||
simpa [res'] using List.head_reverse (l := res.keys) (by simpa [res'] using hne')
|
||||
simp [res']
|
||||
have hcross' : ((res'.keys.head hne' : Key) : WithTop Key) < r'.begin.key := by
|
||||
rw [hhead']
|
||||
rw [show res.keys.getLastD ([] : Key) = res.keys.getLast hne from
|
||||
|
||||
@@ -59,7 +59,8 @@ theorem countP_lt_eq_add_filter_withTop (l : List Key) (hnd : l.Nodup) {a : Key}
|
||||
((ke : Key) : WithTop Key))) = l.countP (fun k : Key => decide (k < ke)) :=
|
||||
countP_lt_coe ke
|
||||
have hf : (l.filter (fun k : Key => decide ((a : WithTop Key) ≤
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((ke : Key) : WithTop Key)))).length =
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((ke : Key) : WithTop
|
||||
Key)))).length =
|
||||
(l.filter (fun x : Key => decide (a ≤ x ∧ x < ke))).length := by
|
||||
congr 1
|
||||
apply List.filter_congr
|
||||
@@ -450,7 +451,8 @@ theorem minimal_closedForm_of_negCross_lowFwd {r : RangeRead} {res : Result}
|
||||
have hhead_lt_E : ((head : Key) : WithTop Key) < r.end_.key :=
|
||||
lt_of_lt_of_le hhead_lt_res hres_le
|
||||
have hR : resolve db₂ r.end_ = resolve db₁ r.end_ := by
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db₁) (s := r.end_) with hn | ht | ⟨q, hqdb, hqeq⟩
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db₁) (s := r.end_) with hn | ht | ⟨q, hqdb,
|
||||
hqeq⟩
|
||||
· rw [hn] at hhead_lt_res
|
||||
exact absurd hhead_lt_res (not_lt.mpr (coe_nil_le_key_withTop _))
|
||||
· exact absurd ht (resolve_ne_top_of_offset_nonpos hend)
|
||||
@@ -688,20 +690,20 @@ theorem resolve_begin_insert_gt {db : DB} {r : RangeRead} {head k : Key}
|
||||
have hcB' : (db'.keys.countP (fun x : Key => decide (((x : Key) : WithTop Key) <
|
||||
r.begin.key))) = cB + 1 := by
|
||||
rw [hdb']
|
||||
show (db.keys.orderedInsert (· ≤ ·) k).countP _ = cB + 1
|
||||
change (db.keys.orderedInsert (· ≤ ·) k).countP _ = cB + 1
|
||||
rw [List.Perm.countP_eq _ (List.perm_orderedInsert (· ≤ ·) k db.keys)]
|
||||
rw [List.countP_cons]
|
||||
simp only [decide_eq_true_eq, hk_lt, if_true]
|
||||
simp only [decide_eq_true_eq, hk_lt, ite_true]
|
||||
rw [hcB]
|
||||
have hcH' : (db'.keys.countP (fun x : Key => decide (x < head))) = cH := by
|
||||
rw [hdb']
|
||||
show (db.keys.orderedInsert (· ≤ ·) k).countP _ = cH
|
||||
change (db.keys.orderedInsert (· ≤ ·) k).countP _ = cH
|
||||
rw [List.Perm.countP_eq _ (List.perm_orderedInsert (· ≤ ·) k db.keys)]
|
||||
rw [List.countP_cons]
|
||||
have hkf : (decide (k < head)) = false := by
|
||||
rw [decide_eq_false_iff_not]
|
||||
exact not_lt.mpr (le_of_lt hk_gt)
|
||||
simp only [hkf, Bool.false_eq_true, if_false]
|
||||
simp only [hkf, Bool.false_eq_true, ite_false]
|
||||
rw [hcH]
|
||||
omega
|
||||
have hanchor : r.begin.anchor db' = ((cH : ℤ) + 1) := by
|
||||
@@ -1193,10 +1195,10 @@ theorem clampEndOne_end_le_begin_of_upper_begin (hcell : negCrossClampEndOne r r
|
||||
by_cases hc : ((clampEndOneSlack r res : ℕ∞) ≤ clampEndOneCap r) ∧
|
||||
(((clampEndOneSlack r res : ℕ∞) < clampEndOneCap r) ∨
|
||||
res.keys.headD ([] : Key) ≠ [])
|
||||
· rw [if_pos hc] at hupper
|
||||
· rw [ite_eq_left hc] at hupper
|
||||
rw [hzero] at hc
|
||||
exact absurd hc.1 (not_le.mpr (by exact_mod_cast hs))
|
||||
· rw [if_neg hc] at hupper
|
||||
· rw [ite_eq_right hc] at hupper
|
||||
exact absurd hupper (ne_of_lt hlt).symm
|
||||
|
||||
end Structural
|
||||
@@ -1207,7 +1209,7 @@ section CountBounds
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
theorem clampEndOne_reported_eq_length (hcell : negCrossClampEndOne r res)
|
||||
theorem clampEndOne_reported_eq_length (_hcell : negCrossClampEndOne r res)
|
||||
(hEB : r.end_.key ≤ r.begin.key)
|
||||
(hres_lt_E : ∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key) :
|
||||
reportedBelowBegin r res = res.keys.length := by
|
||||
@@ -1220,7 +1222,7 @@ theorem clampEndOne_reported_eq_length (hcell : negCrossClampEndOne r res)
|
||||
theorem clampEndOne_count_le_of_between_bound {db : DB} {r : RangeRead} {res : Result}
|
||||
(hfilter : db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key)) =
|
||||
res.keys)
|
||||
(hm : reportedBelowBegin r res = res.keys.length)
|
||||
(_hm : reportedBelowBegin r res = res.keys.length)
|
||||
(hEB : r.end_.key ≤ r.begin.key) :
|
||||
db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) =
|
||||
res.keys.length +
|
||||
@@ -1231,12 +1233,14 @@ theorem clampEndOne_count_le_of_between_bound {db : DB} {r : RangeRead} {res : R
|
||||
have hEB' : (⊤ : WithTop Key) ≤ r.begin.key := by rw [← hEtop]; exact hEB
|
||||
have hB : r.begin.key = (⊤ : WithTop Key) := le_antisymm le_top hEB'
|
||||
rw [hB]
|
||||
have hcnt : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < (⊤ : WithTop Key))) =
|
||||
have hcnt : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < (⊤ : WithTop
|
||||
Key))) =
|
||||
db.keys.length := countP_lt_top
|
||||
have hlen : res.keys.length = db.keys.length := by
|
||||
conv_rhs => rw [← hcnt]
|
||||
rw [← hfilter, hEtop, List.countP_eq_length_filter]
|
||||
have hempty : db.keys.filter (fun k : Key => decide ((⊤ : WithTop Key) ≤ ((k : Key) : WithTop Key) ∧
|
||||
have hempty : db.keys.filter (fun k : Key => decide ((⊤ : WithTop Key) ≤ ((k : Key) : WithTop
|
||||
Key) ∧
|
||||
((k : Key) : WithTop Key) < (⊤ : WithTop Key))) = [] := by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro k _; simp
|
||||
@@ -1281,7 +1285,8 @@ theorem clampEndOne_count_le_slack_of_cap_lt (hcell : negCrossClampEndOne r res)
|
||||
omega
|
||||
· -- `begin.key < end_.key`: no room above `end_.key`, and all reported keys are below it.
|
||||
have hlt : r.begin.key < r.end_.key := lt_of_not_ge hEB
|
||||
have h₁ : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).filter
|
||||
have h₁ : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
r.end_.key))).filter
|
||||
(fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) =
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) := by
|
||||
rw [List.filter_filter]
|
||||
@@ -1452,7 +1457,7 @@ selector clamps to the empty key, so the complete window is exactly those stored
|
||||
-/
|
||||
theorem clampEndOne_compat_of_filter {r : RangeRead} {res : Result} {db : DB}
|
||||
(hcell : negCrossClampEndOne r res)
|
||||
(hlong : r.end_.key < r.begin.key)
|
||||
(_hlong : r.end_.key < r.begin.key)
|
||||
(hcond : clampEndOneCap r < (clampEndOneSlack r res : ℕ∞) ∨
|
||||
(clampEndOneCap r = (clampEndOneSlack r res : ℕ∞) ∧
|
||||
res.keys.headD ([] : Key) = ([] : Key)))
|
||||
@@ -1545,7 +1550,7 @@ theorem clampEndOne_filter_eq_of_compat {r : RangeRead} {res : Result} {db : DB}
|
||||
| some k' =>
|
||||
rw [h] at hkres
|
||||
have hk' : k' = k := WithTop.coe_inj.mp hkres
|
||||
simpa [hk'] using h
|
||||
simp [hk']
|
||||
have hlt : (r.begin.anchor db).toNat < db.keys.length :=
|
||||
List.getElem?_eq_some_iff.mp hget |>.1
|
||||
have hk_eq : db.keys[(r.begin.anchor db).toNat] = k :=
|
||||
@@ -1637,7 +1642,8 @@ theorem clampEndOne_filter_eq_of_compat {r : RangeRead} {res : Result} {db : DB}
|
||||
have hkE : k < E := WithTop.coe_lt_coe.mp (by rw [hE] at hlt'; exact hlt')
|
||||
exact lt_countP_of_getElem_lt db.sorted hlt (by rw [hk_eq]; exact hkE)
|
||||
have hdropk : D.filter
|
||||
(fun x : Key => decide (((k : Key) : WithTop Key) ≤ ((x : Key) : WithTop Key))) = D.drop a := by
|
||||
(fun x : Key => decide (((k : Key) : WithTop Key) ≤ ((x : Key) : WithTop Key))) = D.drop a
|
||||
:= by
|
||||
have h := filter_not_lt_eq_drop_countP hDsorted ((k : Key) : WithTop Key)
|
||||
rw [hDa] at h
|
||||
rw [← h]
|
||||
@@ -1693,12 +1699,12 @@ theorem clampEndOne_neg_cond {r : RangeRead} {res : Result}
|
||||
· exfalso
|
||||
apply hU
|
||||
unfold clampEndOneUpper
|
||||
rw [if_pos ⟨hle, Or.inl hstrict⟩]
|
||||
rw [ite_eq_left ⟨hle, Or.inl hstrict⟩]
|
||||
· by_cases hhead : res.keys.headD ([] : Key) ≠ ([] : Key)
|
||||
· exfalso
|
||||
apply hU
|
||||
unfold clampEndOneUpper
|
||||
rw [if_pos ⟨hle, Or.inr hhead⟩]
|
||||
rw [ite_eq_left ⟨hle, Or.inr hhead⟩]
|
||||
· exact Or.inr ⟨le_antisymm (not_lt.mp hstrict) hle, not_not.mp hhead⟩
|
||||
· exact Or.inl (not_le.mp hle)
|
||||
|
||||
@@ -1724,9 +1730,9 @@ theorem sound_clampEndOne {r : RangeRead} {res : Result}
|
||||
by_cases hP : (clampEndOneSlack r res : ℕ∞) ≤ clampEndOneCap r ∧
|
||||
((clampEndOneSlack r res : ℕ∞) < clampEndOneCap r ∨
|
||||
res.keys.headD ([] : Key) ≠ ([] : Key))
|
||||
· rw [if_pos hP] at hU
|
||||
· rw [ite_eq_left hP] at hU
|
||||
exact absurd rfl hU
|
||||
· rw [if_neg hP] at hU ⊢
|
||||
· rw [ite_eq_right hP] at hU ⊢
|
||||
have hagree' : AgreeOn ⟨(([] : Key) : WithTop Key), r.end_.key⟩ db₁ db₂ := by
|
||||
simpa [closedFormNegCrossClampEndOne, hU'] using hagree
|
||||
by_cases hshort : r.begin.key ≤ r.end_.key
|
||||
@@ -1786,7 +1792,7 @@ theorem clampEndOne_res_db_compat {r : RangeRead} {res : Result}
|
||||
refine ⟨hcomp.1, Or.inr ⟨hmore, ?_⟩⟩
|
||||
show res.keys = RangeRead.completeKeys ⟨res.keys, hs⟩ r
|
||||
rw [completeKeys_eq_filter_of_end_one hrev hend]
|
||||
show res.keys = (res.keys.filter
|
||||
change res.keys = (res.keys.filter
|
||||
(fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).filter
|
||||
(fun k : Key => decide (resolve ⟨res.keys, hs⟩ r.begin ≤ ((k : Key) : WithTop Key)))
|
||||
rw [hD, hnil]
|
||||
@@ -1894,7 +1900,7 @@ theorem clampEndOne_gap_db {r : RangeRead} {res : Result} {L : List Key}
|
||||
refine ⟨hcomp.1, Or.inr ⟨hmore, ?_⟩⟩
|
||||
show res.keys = RangeRead.completeKeys ⟨res.keys ++ L, hAppSorted⟩ r
|
||||
rw [completeKeys_eq_filter_of_end_one hrev hend]
|
||||
show res.keys = ((res.keys ++ L).filter
|
||||
change res.keys = ((res.keys ++ L).filter
|
||||
(fun x : Key => decide (((x : Key) : WithTop Key) < r.end_.key))).filter
|
||||
(fun x : Key => decide (resolve ⟨res.keys ++ L, hAppSorted⟩ r.begin ≤
|
||||
((x : Key) : WithTop Key)))
|
||||
@@ -2110,7 +2116,7 @@ theorem clampEndOne_gap_db_extra {r : RangeRead} {res : Result} {L : List Key}
|
||||
refine ⟨hcomp.1, Or.inr ⟨hmore, ?_⟩⟩
|
||||
show res.keys = RangeRead.completeKeys ⟨(([] : Key) :: res.keys) ++ L, hAppSorted⟩ r
|
||||
rw [completeKeys_eq_filter_of_end_one hrev hend]
|
||||
show res.keys = (((([] : Key) :: res.keys) ++ L).filter
|
||||
change res.keys = (((([] : Key) :: res.keys) ++ L).filter
|
||||
(fun x : Key => decide (((x : Key) : WithTop Key) < r.end_.key))).filter
|
||||
(fun x : Key => decide (resolve ⟨(([] : Key) :: res.keys) ++ L, hAppSorted⟩ r.begin ≤
|
||||
((x : Key) : WithTop Key)))
|
||||
@@ -2215,7 +2221,7 @@ theorem countP_erase_add_one {l : List Key} {k : Key} {p : Key → Bool}
|
||||
have hpos : 0 < l.countP p :=
|
||||
List.countP_pos_iff.mpr ⟨k, hk, hp⟩
|
||||
have h := List.countP_erase p l k
|
||||
rw [if_pos ⟨hk, hp⟩] at h
|
||||
rw [ite_eq_left ⟨hk, hp⟩] at h
|
||||
omega
|
||||
|
||||
/-- A database with the extra bottom key and the full gap list, compatible with begin
|
||||
@@ -2224,7 +2230,7 @@ to bottom and the extra bottom key enters the complete result. -/
|
||||
theorem clampEndOne_erase_extra_not_compat {r : RangeRead} {res : Result} {dbA : DB}
|
||||
{k : Key} {L : List Key}
|
||||
(hread : Readable r res) (hcell : negCrossClampEndOne r res)
|
||||
(hlong : r.end_.key < r.begin.key)
|
||||
(_hlong : r.end_.key < r.begin.key)
|
||||
(hheadne : res.keys.headD ([] : Key) ≠ ([] : Key))
|
||||
(hAkeys : dbA.keys = (([] : Key) :: res.keys) ++ L)
|
||||
(hLlo : ∀ x ∈ L, r.end_.key ≤ ((x : Key) : WithTop Key))
|
||||
@@ -2420,7 +2426,7 @@ theorem minimal_closedForm_of_negCross_clampEndOne {r : RangeRead} {res : Result
|
||||
((clampEndOneSlack r res : ℕ∞) < clampEndOneCap r ∨
|
||||
res.keys.headD ([] : Key) ≠ ([] : Key))
|
||||
· exact hP
|
||||
· rw [if_neg hP] at hU
|
||||
· rw [ite_eq_right hP] at hU
|
||||
exact absurd hU (ne_of_lt hEB)
|
||||
by_cases hstrict : (clampEndOneSlack r res : ℕ∞) < clampEndOneCap r
|
||||
· exact clampEndOne_necessary_gap_of_cap_lt hread hcell hstrict hkE' hkltB
|
||||
@@ -2436,9 +2442,9 @@ theorem minimal_closedForm_of_negCross_clampEndOne {r : RangeRead} {res : Result
|
||||
by_cases hP : (clampEndOneSlack r res : ℕ∞) ≤ clampEndOneCap r ∧
|
||||
((clampEndOneSlack r res : ℕ∞) < clampEndOneCap r ∨
|
||||
res.keys.headD ([] : Key) ≠ ([] : Key))
|
||||
· rw [if_pos hP] at hU
|
||||
· rw [ite_eq_left hP] at hU
|
||||
exact absurd rfl hU
|
||||
· rw [if_neg hP] at hU ⊢
|
||||
· rw [ite_eq_right hP] at hU ⊢
|
||||
have hkE : (k : WithTop Key) < r.end_.key := by
|
||||
simpa [closedFormNegCrossClampEndOne, hU'] using hhi
|
||||
exact clampEndOne_necessary_below_end hread hcell hkE
|
||||
|
||||
@@ -150,7 +150,8 @@ theorem high_witness_compatible_clamp_low {r : RangeRead} {res : Result}
|
||||
have hdbkeys : db.keys = res.keys := rfl
|
||||
have hgt : ∀ k ∈ res.keys, r.end_.key < ((k : Key) : WithTop Key) :=
|
||||
high_reported_gt_end hsort hne hEH
|
||||
have hcE : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key)) = 0 := by
|
||||
have hcE : db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key)) = 0
|
||||
:= by
|
||||
rw [hdbkeys, List.countP_eq_zero]
|
||||
intro k hk
|
||||
rw [decide_eq_true_eq]
|
||||
@@ -184,7 +185,7 @@ theorem high_witness_compatible_clamp_low {r : RangeRead} {res : Result}
|
||||
have hhi : resolve db r.end_ = (⊤ : WithTop Key) := resolve_eq_top hEi0 hlen
|
||||
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
|
||||
rw [RangeRead.completeKeys, hrev]
|
||||
simp only [Bool.false_eq_true, if_false]
|
||||
simp only [Bool.false_eq_true, ite_false]
|
||||
rw [hlo, hhi]
|
||||
exact (RangeRead.inRange_unbounded res.keys).symm
|
||||
|
||||
@@ -197,9 +198,9 @@ theorem countP_orderedInsert_begin {l : List Key} {B : WithTop Key} (hs : l.Sort
|
||||
(if ((k : Key) : WithTop Key) < B then 1 else 0) := by
|
||||
rw [orderedInsert_eq_insertIdx hs hk]
|
||||
by_cases hkB : ((k : Key) : WithTop Key) < B
|
||||
· rw [if_pos hkB]
|
||||
· rw [ite_eq_left hkB]
|
||||
exact countP_insertIdx_of_lt hs hkB
|
||||
· rw [if_neg hkB]
|
||||
· rw [ite_eq_right hkB]
|
||||
exact countP_insertIdx (fun a : Key => decide (((a : Key) : WithTop Key) < B))
|
||||
(l.countP (fun a => decide (a < k))) k (by simp [hkB])
|
||||
|
||||
@@ -299,7 +300,7 @@ is the full range.** -/
|
||||
theorem minimal_fullRange_of_negCrossHigh_clamp_low {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hbegin : r.begin.offset < 0)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(_hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hclamp : reportedBelowBegin r res ≤ beginSlack r)
|
||||
(hlow : res.keys.length < (r.end_.offset - 1).toNat) :
|
||||
@@ -332,7 +333,6 @@ theorem minimal_closedForm_of_negCrossCompleteHigh_clampLow {r : RangeRead} {res
|
||||
exact hmin
|
||||
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -437,7 +437,7 @@ theorem high_length_le_end {r : RangeRead} {res : Result}
|
||||
have hcnt_hi' : cnt db hi =
|
||||
min (cnt db r.end_.key + (r.end_.offset - 1).toNat) db.keys.length := by
|
||||
rw [hhi]
|
||||
show db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
change db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
resolve db r.end_)) = min (cnt db r.end_.key + (r.end_.offset - 1).toNat)
|
||||
db.keys.length
|
||||
rw [countP_lt_resolve (db := db) (s := r.end_),
|
||||
@@ -572,7 +572,8 @@ theorem high_between_end_head_eq_nil {db : DB} {r : RangeRead} {res : Result}
|
||||
have hsplit := cnt_eq_add_between db (le_of_lt hEH)
|
||||
rw [hcnt, between] at hsplit
|
||||
have hlen : (db.keys.filter (fun k : Key => decide (r.end_.key ≤ ((k : Key) : WithTop Key) ∧
|
||||
((k : Key) : WithTop Key) < ((res.keys.headD ([] : Key) : Key) : WithTop Key)))).length = 0 := by
|
||||
((k : Key) : WithTop Key) < ((res.keys.headD ([] : Key) : Key) : WithTop Key)))).length = 0
|
||||
:= by
|
||||
omega
|
||||
exact List.length_eq_zero_iff.mp hlen
|
||||
|
||||
@@ -592,12 +593,13 @@ above `keyAfter last`, no stored key lies in `[keyAfter last, begin.key)`. -/
|
||||
theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset < 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hbegin : r.begin.offset < 0) (_hend : 2 ≤ r.end_.offset)
|
||||
(_hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(hnonclamp : beginSlack r < reportedBelowBegin r res)
|
||||
(hKleB : ((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key) ≤ r.begin.key) :
|
||||
between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) r.begin.key = [] := by
|
||||
between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) r.begin.key = []
|
||||
:= by
|
||||
set H : Key := res.keys.headD ([] : Key) with hH
|
||||
set L : Key := res.keys.getLastD ([] : Key) with hL
|
||||
set K : Key := keyAfter L with hK
|
||||
@@ -628,7 +630,8 @@ theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Resu
|
||||
rw [WithTop.coe_le_coe]; exact le_trans hHleL (le_of_lt (keyAfter_self_lt L))
|
||||
-- All reported keys below `begin.key` are stored in `[H, K)`.
|
||||
have hsub : ∀ k ∈ res.keys.filter (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < r.begin.key)), k ∈ between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key) := by
|
||||
decide (((k : Key) : WithTop Key) < r.begin.key)), k ∈ between db ((H : Key) : WithTop Key)
|
||||
((K : Key) : WithTop Key) := by
|
||||
intro k hk
|
||||
rw [List.mem_filter] at hk
|
||||
have hkres := hk.1
|
||||
@@ -641,7 +644,8 @@ theorem high_between_keyAfter_begin_eq_nil {db : DB} {r : RangeRead} {res : Resu
|
||||
exact List.mem_filter.mpr ⟨RangeRead.compatible_keys_subset hcomp hkres,
|
||||
by rw [decide_eq_true_eq]; exact ⟨hkH, hkK⟩⟩
|
||||
-- Hence `[H, K)` holds at least `beginSlack + 1` stored keys.
|
||||
have hlenHK_ge : beginSlack r + 1 ≤ (between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key)).length := by
|
||||
have hlenHK_ge : beginSlack r + 1 ≤ (between db ((H : Key) : WithTop Key) ((K : Key) : WithTop
|
||||
Key)).length := by
|
||||
have hfin : (res.keys.filter (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < r.begin.key))).toFinset ⊆
|
||||
(between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key)).toFinset := by
|
||||
@@ -786,8 +790,8 @@ theorem filter_eq_filter_filter_of_imp {α : Type*} {l : List α} {p q : α →
|
||||
apply List.filter_congr
|
||||
intro a _
|
||||
cases hp : p a with
|
||||
| false => simp [hp]
|
||||
| true => simp [hp, h a hp]
|
||||
| false => simp []
|
||||
| true => simp [ h a hp]
|
||||
|
||||
/-- Backward direction: in the crossed negative-begin complete high cell with a finite
|
||||
end and a nonclamping begin, equality of the stored keys in `[end.key, M)` with the
|
||||
@@ -899,7 +903,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
|
||||
exact hr
|
||||
have hhhead : res.keys.head hne ∈ db.keys := by rw [← hHhead]; exact hHmem_db
|
||||
have hresB : resolve db r.begin = ((H : Key) : WithTop Key) := by
|
||||
have hlenFilter' : (db.keys.filter (fun k : Key => decide (((res.keys.head hne : Key) : WithTop Key) ≤
|
||||
have hlenFilter' : (db.keys.filter (fun k : Key => decide (((res.keys.head hne : Key) :
|
||||
WithTop Key) ≤
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < r.begin.key))).length =
|
||||
beginSlack r + 1 := by
|
||||
simpa only [hHhead] using hlenFilter
|
||||
@@ -930,7 +935,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
|
||||
rw [hstep, hkeysHM]
|
||||
have htake : (db.keys.drop (cnt db r.end_.key)).take (res.keys.length) = res.keys := by
|
||||
have hsorted : (db.keys.drop (cnt db r.end_.key)).SortedLT :=
|
||||
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key) db.sorted.pairwise)
|
||||
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key)
|
||||
db.sorted.pairwise)
|
||||
have hcount : (db.keys.drop (cnt db r.end_.key)).countP (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < M)) = res.keys.length := by
|
||||
rw [List.countP_eq_length_filter, hfilterM]
|
||||
@@ -984,7 +990,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
|
||||
have hcountTake : (db.keys.take (cnt db r.end_.key)).countP (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < resolve db r.end_)) = cnt db r.end_.key := by
|
||||
rw [htakeE]
|
||||
have hlen : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).countP
|
||||
have hlen : (db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
r.end_.key))).countP
|
||||
(fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) =
|
||||
(db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < r.end_.key))).length :=
|
||||
List.countP_eq_length.mpr (by
|
||||
@@ -1003,7 +1010,8 @@ theorem high_nonclamp_finite_compatible_of_filter {db : DB} {r : RangeRead} {res
|
||||
omega
|
||||
have hwindow : between db ((H : Key) : WithTop Key) (resolve db r.end_) = res.keys := by
|
||||
have hsorted : (db.keys.drop (cnt db r.end_.key)).SortedLT :=
|
||||
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key) db.sorted.pairwise)
|
||||
List.sortedLT_iff_pairwise.mpr (List.Pairwise.drop (i := cnt db r.end_.key)
|
||||
db.sorted.pairwise)
|
||||
have hstep : between db ((H : Key) : WithTop Key) (resolve db r.end_) =
|
||||
(db.keys.drop (cnt db r.end_.key)).filter (fun k : Key =>
|
||||
decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
|
||||
@@ -1050,7 +1058,7 @@ theorem minimal_closedForm_of_negCrossCompleteHigh_nonclamp_finite {r : RangeRea
|
||||
(hnonclamp : beginSlack r < reportedBelowBegin r res)
|
||||
(hfinite : res.keys.length = (r.end_.offset - 1).toNat) :
|
||||
Minimal r res ⟨r.end_.key, negCrossCompleteHighM r res⟩ :=
|
||||
minimal_of_compatible_iff_filter hread (fun db =>
|
||||
minimal_of_compatible_iff_filter hread (fun _db =>
|
||||
high_nonclamp_finite_compatible_iff_filter hread hrev hmore hne hbegin hend hEH hcrossD
|
||||
hnonclamp hfinite)
|
||||
|
||||
@@ -1172,7 +1180,8 @@ theorem high_nonclamp_low_aboveH_iff {db : DB} {r : RangeRead} {res : Result}
|
||||
(hlow : res.keys.length < (r.end_.offset - 1).toNat)
|
||||
(hno : ¬ (((r.end_.offset - 1).toNat - res.keys.length : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
|
||||
RangeRead.Compatible db r res ↔ above db ((res.keys.headD ([] : Key) : Key) : WithTop Key) = res.keys := by
|
||||
RangeRead.Compatible db r res ↔ above db ((res.keys.headD ([] : Key) : Key) : WithTop Key) =
|
||||
res.keys := by
|
||||
set H : Key := res.keys.headD ([] : Key) with hH
|
||||
set E : WithTop Key := r.end_.key with hE
|
||||
set t : ℕ := res.keys.length with ht
|
||||
@@ -1262,10 +1271,10 @@ theorem high_nonclamp_low_aboveH_iff {db : DB} {r : RangeRead} {res : Result}
|
||||
rw [hanchor]; omega
|
||||
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
|
||||
rw [RangeRead.completeKeys, hrev]
|
||||
simp only [Bool.false_eq_true, if_false]
|
||||
simp only [Bool.false_eq_true, ite_false]
|
||||
rw [hL, htop]
|
||||
-- between H top = above H = res.keys
|
||||
show res.keys = List.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
|
||||
change res.keys = List.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < (⊤ : WithTop Key))) db.keys
|
||||
exact haboveH.symm.trans (filter_le_top_eq_above_aux db ((H : Key) : WithTop Key)).symm
|
||||
|
||||
@@ -1298,7 +1307,7 @@ interval `[end_.key, begin.key)`, the begin resolution (negative offset). The c
|
||||
window then starts at the reported head, which lies at or above `end_.key`, so it too is
|
||||
fixed. -/
|
||||
theorem sound_topRange_endKey_nonclamp_low {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(_hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0)
|
||||
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
@@ -1427,7 +1436,7 @@ theorem high_nonclamp_low_base_compatible {r : RangeRead} {res : Result}
|
||||
have : (0 : ℤ) ≤ r.end_.offset - 1 := by omega
|
||||
simpa using this
|
||||
· rw [hanchor]
|
||||
show res.keys.length ≤ e
|
||||
change res.keys.length ≤ e
|
||||
rw [← ht]
|
||||
omega
|
||||
have hbetween : between (⟨res.keys, hsort⟩ : DB) ((H : Key) : WithTop Key)
|
||||
@@ -1442,7 +1451,7 @@ theorem high_nonclamp_low_base_compatible {r : RangeRead} {res : Result}
|
||||
exact head_le_of_sortedLT' hsort hne hk)
|
||||
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
|
||||
rw [RangeRead.completeKeys, hrev]
|
||||
simp only [Bool.false_eq_true, if_false]
|
||||
simp only [Bool.false_eq_true, ite_false]
|
||||
rw [hL, htop]
|
||||
exact hbetween.symm
|
||||
|
||||
@@ -1714,7 +1723,8 @@ theorem necessary_gap_nonclamp_low_lt_cap {r : RangeRead} {res : Result} {k : Ke
|
||||
simpa [Nat.cast_add, Nat.cast_one] using h
|
||||
set H : Key := res.keys.headD ([] : Key) with hH
|
||||
set E : WithTop Key := r.end_.key with hE
|
||||
have hcap' : (((negCrossHighD r res + 1 : ℕ) : ℕ∞)) ≤ intervalCard E ((H : Key) : WithTop Key) := by
|
||||
have hcap' : (((negCrossHighD r res + 1 : ℕ) : ℕ∞)) ≤ intervalCard E ((H : Key) : WithTop Key)
|
||||
:= by
|
||||
simpa [negCrossHighGapCap, hE, hH] using hcap
|
||||
obtain ⟨dbPad, hdbPadIn, hkpad, hpadlen⟩ :=
|
||||
exists_db_keysIn_avoid (B := E) (E := ((H : Key) : WithTop Key)) (k := k)
|
||||
@@ -1733,7 +1743,7 @@ theorem necessary_gap_nonclamp_low_lt_cap {r : RangeRead} {res : Result} {k : Ke
|
||||
rw [hdb0]
|
||||
simp only
|
||||
rw [List.mem_append]
|
||||
push_neg
|
||||
push Not
|
||||
exact ⟨hkpad, hknot⟩
|
||||
refine necessary_of_toggle ⟨db0, hcomp0, ?_⟩
|
||||
rw [toggle_eq_insert_of_not_mem hknot0]
|
||||
@@ -1941,7 +1951,8 @@ theorem high_nonclamp_low_tail_compatible {r : RangeRead} {res : Result}
|
||||
rw [RangeRead.inRange, hRbeg, hRend]
|
||||
rw [hkeys, List.filter_append, List.filter_append]
|
||||
have hpadf : pad.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = [] := by
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = []
|
||||
:= by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
@@ -1958,7 +1969,8 @@ theorem high_nonclamp_low_tail_compatible {r : RangeRead} {res : Result}
|
||||
exact WithTop.coe_le_coe.mpr (head_le_of_sortedLT' hsort hne hx),
|
||||
WithTop.coe_lt_coe.mpr (hys x hx)⟩
|
||||
have hyf : [y].filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = [] := by
|
||||
((k : Key) : WithTop Key) ∧ ((k : Key) : WithTop Key) < ((y : Key) : WithTop Key))) = []
|
||||
:= by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro x hx
|
||||
rw [List.mem_singleton] at hx
|
||||
@@ -2060,13 +2072,13 @@ theorem necessary_gap_nonclamp_low_eq_cap {r : RangeRead} {res : Result} {k : Ke
|
||||
have hLm : L ≤ m := by
|
||||
rw [hm]
|
||||
by_cases h : L ≤ b
|
||||
· rw [if_pos h]; exact h
|
||||
· rw [if_neg h]
|
||||
· rw [ite_eq_left h]; exact h
|
||||
· rw [ite_eq_right h]
|
||||
have hbm : b ≤ m := by
|
||||
rw [hm]
|
||||
by_cases h : L ≤ b
|
||||
· rw [if_pos h]
|
||||
· rw [if_neg h]; exact le_of_lt (lt_of_not_ge h)
|
||||
· rw [ite_eq_left h]
|
||||
· rw [ite_eq_right h]; exact le_of_lt (lt_of_not_ge h)
|
||||
set y : Key := keyAfter m with hy
|
||||
have hLy : L < y := lt_of_le_of_lt hLm (by rw [hy]; exact keyAfter_self_lt m)
|
||||
have hby : b < y := lt_of_le_of_lt hbm (by rw [hy]; exact keyAfter_self_lt m)
|
||||
@@ -2092,7 +2104,7 @@ theorem necessary_gap_nonclamp_low_eq_cap {r : RangeRead} {res : Result} {k : Ke
|
||||
have hks0 : db0.keys = pad ++ res.keys ++ [y] := rfl
|
||||
have hkrest : k ∉ res.keys ++ [y] := by
|
||||
rw [List.mem_append, List.mem_singleton]
|
||||
push_neg
|
||||
push Not
|
||||
exact ⟨hknot, hk_ne_y⟩
|
||||
have hpadErase : pad.erase k = padk := by
|
||||
have h := DB.erase_insert_keys (⟨padk, hpadks⟩ : DB) k hkpadk
|
||||
@@ -2377,9 +2389,9 @@ theorem high_nonclamp_low_aboveH_iff_top {db : DB} {r : RangeRead} {res : Result
|
||||
exact hlenEnd
|
||||
refine ⟨hwl, Or.inr ⟨hmore, ?_⟩⟩
|
||||
rw [RangeRead.completeKeys, hrev]
|
||||
simp only [Bool.false_eq_true, if_false]
|
||||
simp only [Bool.false_eq_true, ite_false]
|
||||
rw [hL, htop]
|
||||
show res.keys = between db ((H : Key) : WithTop Key) (⊤ : WithTop Key)
|
||||
change res.keys = between db ((H : Key) : WithTop Key) (⊤ : WithTop Key)
|
||||
rw [between_top_eq_above]
|
||||
exact habove.symm
|
||||
|
||||
@@ -2387,7 +2399,7 @@ theorem high_nonclamp_low_aboveH_iff_top {db : DB} {r : RangeRead} {res : Result
|
||||
crossed negative-begin complete high cell when `end.key` is the chosen lower endpoint. -/
|
||||
theorem necessary_topRange_endKey_nonclamp_low {r : RangeRead} {res : Result} {k : Key}
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset < 0) (_hend : 2 ≤ r.end_.offset)
|
||||
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key)
|
||||
(hnonclamp : beginSlack r < reportedBelowBegin r res)
|
||||
|
||||
@@ -29,7 +29,6 @@ soundness. Necessity inside `[K, begin.key)` is shown by inserting one more gap
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db db₁ db₂ : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -38,8 +37,8 @@ resolution is either the empty key or the reported head. -/
|
||||
theorem clamp_begin_resolve_bot_or_head
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset < 0)
|
||||
(hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key) :
|
||||
(_hbegin : r.begin.offset < 0)
|
||||
(_hcrossD : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.begin.key) :
|
||||
resolve db r.begin = (([] : Key) : WithTop Key) ∨
|
||||
resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key) := by
|
||||
set H : Key := res.keys.headD ([] : Key) with hH
|
||||
@@ -59,7 +58,8 @@ theorem clamp_begin_resolve_bot_or_head
|
||||
by_cases hneg : r.begin.anchor db < 0
|
||||
· left; exact resolve_eq_nil hneg
|
||||
· have h0 : 0 ≤ r.begin.anchor db := le_of_not_gt hneg
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hnil | htop | ⟨k, hkdb, hresk⟩
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hnil | htop | ⟨k, hkdb,
|
||||
hresk⟩
|
||||
· left; exact hnil
|
||||
· rw [htop] at hHin
|
||||
exact absurd hHin.2.1 (not_le.mpr (WithTop.coe_lt_top H))
|
||||
@@ -226,7 +226,7 @@ theorem clampHigh_thresh_gt_facts
|
||||
exact ⟨le_of_lt hlt', Or.inl hlt'⟩
|
||||
|
||||
/-- Every reported key lies strictly below `keyAfter (last reported)`. -/
|
||||
theorem clampHigh_reported_lt_keyAfter {r : RangeRead} {res : Result}
|
||||
theorem clampHigh_reported_lt_keyAfter {_r : RangeRead} {res : Result}
|
||||
(hsort : res.keys.SortedLT) (hne : res.keys ≠ []) :
|
||||
∀ k ∈ res.keys, ((k : Key) : WithTop Key) <
|
||||
((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key) := by
|
||||
@@ -286,7 +286,7 @@ theorem clamp_keys_HK_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
rw [hH, headD_eq_head_of_ne hne]
|
||||
exact head_le_of_sortedLT' hsort hne hk)
|
||||
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) :=
|
||||
clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
|
||||
clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
|
||||
exact ⟨hkdb, by rw [decide_eq_true_eq]; exact ⟨hHle, hkK⟩⟩
|
||||
|
||||
/-- No stored key lies in `[keyAfter last, resolve end)` in the crossed negative-begin
|
||||
@@ -371,7 +371,7 @@ theorem clamp_cnt_begin_split {db : DB} {r : RangeRead} {res : Result}
|
||||
/-- If the begin resolution is the reported head, the begin count below `begin.key`
|
||||
equals the count below the head plus the slack plus one. -/
|
||||
theorem clamp_anchor_eq_cnt_head_of_resolve {db : DB} {r : RangeRead} {res : Result}
|
||||
(hbegin : r.begin.offset < 0) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset < 0) (_hne : res.keys ≠ [])
|
||||
(hHne : res.keys.headD ([] : Key) ≠ [])
|
||||
(hhead : resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
|
||||
cnt db r.begin.key = cnt db (((res.keys.headD ([] : Key) : Key) : WithTop Key)) +
|
||||
@@ -411,7 +411,7 @@ theorem clamp_anchor_eq_cnt_head_of_resolve {db : DB} {r : RangeRead} {res : Res
|
||||
the reported head: that would require at least `clampHighC` gap keys, hence capacity at
|
||||
least the threshold. -/
|
||||
theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hcomp : RangeRead.Compatible db r res)
|
||||
(_hread : Readable r res) (hcomp : RangeRead.Compatible db r res)
|
||||
(hcell : negCrossCompleteHighClampFinite r res)
|
||||
(hnotcap : ¬ ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res))
|
||||
(hEbot : r.end_.key ≠ (([] : Key) : WithTop Key)) :
|
||||
@@ -465,7 +465,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
|
||||
have hCpos := clampHigh_C_pos (r := r) (res := res) hclamp
|
||||
omega
|
||||
· -- `K < B`: `t + gap = q + 1`, so `cap ≥ C`
|
||||
push_neg at hBK
|
||||
push Not at hBK
|
||||
have hKleB : ((K : Key) : WithTop Key) ≤ r.begin.key := le_of_lt hBK
|
||||
have hsplit := clamp_cnt_begin_split hcomp hrev hmore hne hcrossD (by rw [← hK]; exact hKleB)
|
||||
have hrb : reportedBelowBegin r res = res.keys.length := by
|
||||
@@ -474,7 +474,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
|
||||
intro k hk
|
||||
rw [decide_eq_true_eq]
|
||||
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) := by
|
||||
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
|
||||
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
|
||||
exact lt_trans hkK hBK
|
||||
have hgap : (between db (((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key))
|
||||
r.begin.key).length = clampHighC r res := by
|
||||
@@ -497,7 +497,7 @@ theorem clampHigh_begin_resolve_ne_head {db : DB} {r : RangeRead} {res : Result}
|
||||
-- `thresh = C` since `E ≠ ⊥`
|
||||
have hth : clampHighThresh r res = clampHighC r res := by
|
||||
unfold clampHighThresh
|
||||
rw [if_neg hEbot]
|
||||
rw [ite_eq_right hEbot]
|
||||
exact Nat.add_zero _
|
||||
apply hnotcap
|
||||
rw [hth]
|
||||
@@ -573,7 +573,8 @@ theorem clampHigh_K_filter_of_compatible {db : DB} {r : RangeRead} {res : Result
|
||||
(by rw [← hH]; exact hcrossD) with hab | hah
|
||||
· exact hab
|
||||
· exact absurd hah
|
||||
(clampHigh_begin_resolve_ne_head hread hcomp hcell hnotcap (by rw [← hE]; exact hEbot))
|
||||
(clampHigh_begin_resolve_ne_head hread hcomp hcell hnotcap (by rw [← hE]; exact
|
||||
hEbot))
|
||||
-- with `a = ⊥`, `k` lies in the window
|
||||
have hxwin : k ∈ between db (resolve db r.begin) (resolve db r.end_) := by
|
||||
rw [between, List.mem_filter]
|
||||
@@ -590,7 +591,7 @@ theorem clampHigh_K_filter_of_compatible {db : DB} {r : RangeRead} {res : Result
|
||||
rw [List.mem_filter]
|
||||
exact ⟨RangeRead.compatible_keys_subset hcomp hk,
|
||||
by rw [decide_eq_true_eq]
|
||||
exact clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk⟩
|
||||
exact clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk⟩
|
||||
|
||||
/-- Filtering at `⊥` is the same as dropping the lower-bound conjunct. -/
|
||||
theorem clampHigh_filter_bot_eq (db : DB) (U : WithTop Key) :
|
||||
@@ -631,7 +632,7 @@ exactly the reported keys. -/
|
||||
theorem clampHigh_between_head_keyAfter_of_filter {db : DB} {res : Result} {H K : Key}
|
||||
(hsort : res.keys.SortedLT) (hne : res.keys ≠ [])
|
||||
(hH : H = res.keys.headD ([] : Key))
|
||||
(hHltK : ((H : Key) : WithTop Key) < ((K : Key) : WithTop Key))
|
||||
(_hHltK : ((H : Key) : WithTop Key) < ((K : Key) : WithTop Key))
|
||||
(hfilter : db.keys.filter (fun k : Key => decide
|
||||
(((k : Key) : WithTop Key) < ((K : Key) : WithTop Key))) = res.keys) :
|
||||
between db ((H : Key) : WithTop Key) ((K : Key) : WithTop Key) = res.keys := by
|
||||
@@ -725,7 +726,7 @@ theorem clampHigh_cnt_begin_le_of_filter {db : DB} {r : RangeRead} {res : Result
|
||||
rw [hsplit, hcntH, hlen]; omega
|
||||
omega
|
||||
· -- `keyAfter last < begin.key`: the gap keys plus the reported keys.
|
||||
push_neg at hBK
|
||||
push Not at hBK
|
||||
have hKleB : ((K : Key) : WithTop Key) ≤ r.begin.key := le_of_lt hBK
|
||||
have hcntK : cnt db ((K : Key) : WithTop Key) = res.keys.length := by
|
||||
rw [cnt_eq_add_between db (le_of_lt hHltK), hcntH, hbetweenHK]
|
||||
@@ -739,7 +740,7 @@ theorem clampHigh_cnt_begin_le_of_filter {db : DB} {r : RangeRead} {res : Result
|
||||
intro k hk
|
||||
rw [decide_eq_true_eq]
|
||||
have hkK : ((k : Key) : WithTop Key) < ((K : Key) : WithTop Key) := by
|
||||
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (r := r) hsort hne k hk
|
||||
simpa [hK, hL] using clampHigh_reported_lt_keyAfter (_r := r) hsort hne k hk
|
||||
exact lt_trans hkK hBK
|
||||
have hcapC : (between db ((K : Key) : WithTop Key) r.begin.key).length ≤
|
||||
clampHighC r res := by
|
||||
@@ -942,7 +943,7 @@ theorem minimal_clampHigh_K {r : RangeRead} {res : Result}
|
||||
(hnotcap : ¬ ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res)) :
|
||||
Minimal r res ⟨(([] : Key) : WithTop Key),
|
||||
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key))⟩ :=
|
||||
minimal_of_compatible_iff_filter hread (fun db =>
|
||||
minimal_of_compatible_iff_filter hread (fun _db =>
|
||||
clampHigh_K_compatible_iff_filter hread hcell hnotcap)
|
||||
|
||||
/-- A database splits into its keys below a threshold and those at or above it. -/
|
||||
@@ -961,7 +962,7 @@ theorem clampHigh_K_lt_begin {r : RangeRead} {res : Result}
|
||||
(hcap : ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res)) :
|
||||
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) < r.begin.key := by
|
||||
by_contra hcon
|
||||
push_neg at hcon
|
||||
push Not at hcon
|
||||
have hzero : clampHighCap r res = 0 := by
|
||||
unfold clampHighCap
|
||||
exact intervalCard_eq_zero_of_le hcon
|
||||
@@ -991,7 +992,6 @@ theorem clampHigh_reported_lt_begin {r : RangeRead} {res : Result}
|
||||
|
||||
section BeginKeyBranch
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1089,7 +1089,7 @@ theorem clampHigh_B_head_pad_lt_end
|
||||
rw [List.mem_filter] at hx
|
||||
have hxH : ((x : Key) : WithTop Key) < ((H : Key) : WithTop Key) := of_decide_eq_true hx.2
|
||||
by_contra hcon
|
||||
push_neg at hcon
|
||||
push Not at hcon
|
||||
have hcntsplit := cnt_eq_add_between db (le_of_lt hEH)
|
||||
rw [← hcH, ← hcE, hceq] at hcntsplit
|
||||
have hlen0 : (between db r.end_.key ((H : Key) : WithTop Key)).length = 0 := by
|
||||
@@ -1105,8 +1105,8 @@ theorem clampHigh_B_head_pad_lt_end
|
||||
/-- In the `U = begin.key` branch, if the begin selector resolves to the empty key,
|
||||
then at most `beginSlack + 1` stored keys lie below `begin.key`. -/
|
||||
theorem clampHigh_B_bot_cnt_le {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(_hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
|
||||
(_hmore : res.more = false) (_hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset < 0)
|
||||
(hbot : resolve db r.begin = (([] : Key) : WithTop Key)) :
|
||||
cnt db r.begin.key ≤ beginSlack r + 1 := by
|
||||
@@ -1117,10 +1117,10 @@ theorem clampHigh_B_bot_cnt_le {db : DB} {r : RangeRead} {res : Result}
|
||||
rfl
|
||||
rw [hanchor] at hneg
|
||||
omega
|
||||
· push_neg at hneg
|
||||
· push Not at hneg
|
||||
have hlt : (r.begin.anchor db).toNat < db.keys.length := by
|
||||
by_contra hcon
|
||||
push_neg at hcon
|
||||
push Not at hcon
|
||||
rw [resolve_eq_top hneg hcon] at hbot
|
||||
exact absurd hbot (by simp)
|
||||
have hget : db.keys[(r.begin.anchor db).toNat] = ([] : Key) := by
|
||||
@@ -1146,7 +1146,6 @@ end BeginKeyBranch
|
||||
|
||||
section BeginKeyDecomp
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1154,8 +1153,8 @@ variable {db : DB} {r : RangeRead} {res : Result}
|
||||
negative-begin complete high cell, the number of stored keys below `begin.key` is the
|
||||
number below the head plus `beginSlack + 1`. -/
|
||||
theorem clampHigh_B_head_cnt_begin
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(_hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
|
||||
(_hmore : res.more = false) (_hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset < 0)
|
||||
(hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key))
|
||||
(hhead : resolve db r.begin = ((res.keys.headD ([] : Key) : Key) : WithTop Key)) :
|
||||
@@ -1203,7 +1202,7 @@ stored keys split as a (possibly empty) pad below `end.key`, the reported keys,
|
||||
`C` when the begin selector resolves onto the reported head, and the pad is empty with a
|
||||
shorter gap when it clamps. -/
|
||||
theorem clampHigh_B_decomp_of_compatible
|
||||
(hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res)
|
||||
(_hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res)
|
||||
(hcap : ((clampHighThresh r res : ℕ∞) ≤ clampHighCap r res))
|
||||
(hcomp : RangeRead.Compatible db r res) :
|
||||
∃ pad gap rest : List Key,
|
||||
@@ -1253,7 +1252,8 @@ theorem clampHigh_B_decomp_of_compatible
|
||||
have hfB : db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
r.begin.key)) =
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
((H : Key) : WithTop Key))) ++ res.keys ++ between db ((K : Key) : WithTop Key) r.begin.key := by
|
||||
((H : Key) : WithTop Key))) ++ res.keys ++ between db ((K : Key) : WithTop Key)
|
||||
r.begin.key := by
|
||||
rw [filter_lt_eq_filter_lt_append_between db.sorted (le_of_lt hKLB), hfK]
|
||||
rfl
|
||||
-- split the database into below and at-or-above `begin.key`
|
||||
@@ -1341,7 +1341,7 @@ theorem clampHigh_B_decomp_of_compatible
|
||||
rw [hq, hr]
|
||||
rw [hC]
|
||||
rw [hcBsplit] at hcnt
|
||||
simp only [List.length_append, ht] at hcnt
|
||||
simp only [ ht] at hcnt
|
||||
omega
|
||||
|
||||
end BeginKeyDecomp
|
||||
@@ -1394,7 +1394,6 @@ end BetweenTools
|
||||
|
||||
section BeginKeyConverse
|
||||
|
||||
open scoped Classical
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
/-- The `U = begin.key` branch, converse direction: a database whose keys below
|
||||
@@ -1451,7 +1450,8 @@ theorem clampHigh_B_compatible_of_shape
|
||||
have hres_sub : ∀ k ∈ res.keys, k ∈ db.keys := by
|
||||
intro k hk
|
||||
rw [hkeys]
|
||||
exact List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inr hk)))))
|
||||
exact List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inl (List.mem_append.mpr (Or.inr
|
||||
hk)))))
|
||||
-- filters below `E` and `B`
|
||||
have hfiltE : db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < E)) = pad := by
|
||||
rw [hkeys, List.filter_append, List.filter_append, List.filter_append]
|
||||
@@ -1573,8 +1573,7 @@ theorem clampHigh_B_compatible_of_shape
|
||||
have hsub : gap.Sublist db.keys := by
|
||||
rw [hkeys]
|
||||
exact (List.sublist_append_left gap rest).trans
|
||||
(by simpa [List.append_assoc] using
|
||||
(List.sublist_append_right (pad ++ res.keys) (gap ++ rest)))
|
||||
(by simp [List.append_assoc])
|
||||
have hgapSorted : gap.SortedLT :=
|
||||
List.sortedLT_iff_pairwise.mpr
|
||||
(List.Pairwise.sublist hsub (List.sortedLT_iff_pairwise.mp db.sorted))
|
||||
@@ -1643,7 +1642,8 @@ theorem clampHigh_B_compatible_of_shape
|
||||
have hbetween : between db (resolve db r.begin) (resolve db r.end_) = res.keys := by
|
||||
rw [haresolve]
|
||||
have hbot : between db (([] : Key) : WithTop Key) (resolve db r.end_) =
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_))
|
||||
:= by
|
||||
unfold between
|
||||
apply List.filter_congr
|
||||
intro k _
|
||||
@@ -1674,7 +1674,6 @@ end BeginKeyConverse
|
||||
|
||||
section BeginKeySound
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1715,7 +1714,6 @@ end BeginKeySound
|
||||
|
||||
section BeginKeyNecessary
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1775,7 +1773,6 @@ end BeginKeyNecessary
|
||||
|
||||
section BeginKeyNecessaryTools
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1784,28 +1781,29 @@ theorem clampHigh_thresh_of_ne_bot
|
||||
(hE : r.end_.key ≠ (([] : Key) : WithTop Key)) :
|
||||
clampHighThresh r res = clampHighC r res := by
|
||||
unfold clampHighThresh
|
||||
rw [if_neg hE]
|
||||
rw [ite_eq_right hE]
|
||||
exact Nat.add_zero _
|
||||
|
||||
theorem clampHigh_thresh_of_bot
|
||||
(hE : r.end_.key = (([] : Key) : WithTop Key)) :
|
||||
clampHighThresh r res = clampHighC r res + 1 := by
|
||||
unfold clampHighThresh
|
||||
rw [if_pos hE]
|
||||
rw [ite_eq_left hE]
|
||||
|
||||
/-- Away from the gap, a key above the last reported key is at or above
|
||||
`keyAfter (last reported)`. -/
|
||||
theorem clampHigh_B_gap_of_not_le_last {k : Key}
|
||||
(hkL : ¬ ((k : Key) : WithTop Key) ≤
|
||||
((res.keys.getLastD ([] : Key) : Key) : WithTop Key)) :
|
||||
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) ≤ ((k : Key) : WithTop Key) := by
|
||||
(((keyAfter (res.keys.getLastD ([] : Key)) : Key) : WithTop Key)) ≤ ((k : Key) : WithTop Key)
|
||||
:= by
|
||||
exact le_of_not_gt (fun h => hkL (WithTop.coe_le_coe.mpr
|
||||
((lt_keyAfter_iff (k := k) (l := res.keys.getLastD ([] : Key))).mp
|
||||
(WithTop.coe_lt_coe.mp h))))
|
||||
|
||||
/-- The begin anchor of the reported-keys database is negative in the clamping branch. -/
|
||||
theorem clampHigh_B_keys_anchor_neg {hsort : res.keys.SortedLT}
|
||||
(hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res) :
|
||||
(_hread : Readable r res) (hcell : negCrossCompleteHighClampFinite r res) :
|
||||
r.begin.anchor (⟨res.keys, hsort⟩ : DB) < 0 := by
|
||||
obtain ⟨hrev, hbegin, hmore, hne, hend, hcrossD, hEH⟩ := hcell.1
|
||||
have hclamp := hcell.2.1
|
||||
@@ -1819,7 +1817,6 @@ end BeginKeyNecessaryTools
|
||||
|
||||
section BeginKeyGapNecessary
|
||||
|
||||
open scoped Classical
|
||||
|
||||
variable {db : DB} {r : RangeRead} {res : Result}
|
||||
|
||||
@@ -1895,7 +1892,9 @@ theorem clampHigh_B_necessary_gap_bot {r : RangeRead} {res : Result} {k : Key}
|
||||
· exact hkB
|
||||
· rw [List.mem_append] at hx
|
||||
rcases hx with hx | hx
|
||||
· exact by simpa [hB] using clampHigh_reported_lt_begin (r := r) (res := res) hsort hne hcell hcap x hx
|
||||
· have hlt :=
|
||||
clampHigh_reported_lt_begin (r := r) (res := res) hsort hne hcell hcap x hx
|
||||
simpa [hB] using hlt
|
||||
· exact hJhi x hx
|
||||
have hcnt1 : db1.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < B)) =
|
||||
t + (C + 1) := by
|
||||
@@ -2169,7 +2168,7 @@ theorem clampHigh_B_necessary_gap_ne_bot {r : RangeRead} {res : Result} {k : Key
|
||||
List.countP_eq_length.mpr (by
|
||||
intro x hx; rw [decide_eq_true_eq]; exact hGrange x hx)
|
||||
rw [hall, hGlen]
|
||||
rw [if_pos ⟨hkG, by rw [decide_eq_true_eq]; exact ⟨hkK, hkB⟩⟩]
|
||||
rw [ite_eq_left ⟨hkG, by rw [decide_eq_true_eq]; exact ⟨hkK, hkB⟩⟩]
|
||||
rw [hnil, hres, hG]
|
||||
omega
|
||||
have hcnt_decomp : (dbA.erase k).keys.countP (fun x : Key => decide
|
||||
|
||||
@@ -40,7 +40,7 @@ theorem clampNonposBottom_of_anchor_neg_long {r : RangeRead} {res : Result} {db
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
|
||||
rcases hcomp.2 with ⟨hm, _, _⟩ | ⟨-, heq⟩
|
||||
· simp [hmore] at hm
|
||||
· rw [heq, RangeRead.completeKeys, if_neg (by simp [hrev])]
|
||||
· rw [heq, RangeRead.completeKeys, ite_eq_right (by simp [hrev])]
|
||||
unfold RangeRead.inRange
|
||||
rw [hL]
|
||||
apply List.filter_congr
|
||||
@@ -142,7 +142,7 @@ theorem minimal_closedForm_of_negCross_nonclamp_long_nonpos {r : RangeRead} {res
|
||||
have hnonclamp : ∀ db, RangeRead.Compatible db r res → 0 ≤ r.begin.anchor db := by
|
||||
intro db hcomp
|
||||
by_contra hneg
|
||||
push_neg at hneg
|
||||
push Not at hneg
|
||||
exact hnotbottom
|
||||
(clampNonposBottom_of_anchor_neg_long hcomp hrev hmore hne hbegin hend hlong hneg)
|
||||
have hread₀ : Readable r res := ⟨db₀, hcomp₀⟩
|
||||
|
||||
@@ -35,7 +35,7 @@ theorem clampNonposBottom_of_anchor_neg {r : RangeRead} {res : Result} {db : DB}
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
|
||||
rcases hcomp.2 with ⟨hm, _, _⟩ | ⟨-, heq⟩
|
||||
· simp [hmore] at hm
|
||||
· rw [heq, RangeRead.completeKeys, if_neg (by simp [hrev])]
|
||||
· rw [heq, RangeRead.completeKeys, ite_eq_right (by simp [hrev])]
|
||||
unfold RangeRead.inRange
|
||||
rw [hL]
|
||||
apply List.filter_congr
|
||||
@@ -292,7 +292,7 @@ theorem minimal_closedForm_of_negCross_nonclamp_nonpos {r : RangeRead} {res : Re
|
||||
have hnonclamp : ∀ db, RangeRead.Compatible db r res → 0 ≤ r.begin.anchor db := by
|
||||
intro db hcomp
|
||||
by_contra hneg
|
||||
push_neg at hneg
|
||||
push Not at hneg
|
||||
exact hnotbottom
|
||||
(clampNonposBottom_of_anchor_neg hcomp hrev hmore hne hbegin hend hB_le_E hneg)
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr ⟨?_, ?_⟩
|
||||
|
||||
@@ -38,7 +38,7 @@ theorem reportedBelowBegin_le_cnt_resolve_end {db : DB} {r : RangeRead} {res : R
|
||||
have hlenle : res.keys.length ≤ (RangeRead.completeKeys db r).length :=
|
||||
hpre.length_le
|
||||
have hck : (RangeRead.completeKeys db r).length ≤ cnt db (resolve db r.end_) := by
|
||||
rw [RangeRead.completeKeys, if_neg (by simp [hrev]), RangeRead.inRange]
|
||||
rw [RangeRead.completeKeys, ite_eq_right (by simp [hrev]), RangeRead.inRange]
|
||||
calc (db.keys.filter
|
||||
(fun k : Key => decide (resolve db r.begin ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_))).length
|
||||
@@ -101,7 +101,7 @@ theorem clampNonposBottom_of_anchor_neg_trunc {r : RangeRead} {res : Result} {db
|
||||
have hL : resolve db r.begin = (([] : Key) : WithTop Key) := resolve_eq_nil hanchor
|
||||
have hck : RangeRead.completeKeys db r =
|
||||
db.keys.filter (fun k : Key => decide (((k : Key) : WithTop Key) < resolve db r.end_)) := by
|
||||
rw [RangeRead.completeKeys, if_neg (by simp [hrev])]
|
||||
rw [RangeRead.completeKeys, ite_eq_right (by simp [hrev])]
|
||||
unfold RangeRead.inRange
|
||||
rw [hL]
|
||||
apply List.filter_congr
|
||||
|
||||
@@ -55,7 +55,7 @@ theorem clampNonposBottom_of_negCross_trunc_bottomGap {r : RangeRead} {res : Res
|
||||
|
||||
/-- The reported last key is the last of the result, and it lies below `begin.key`. -/
|
||||
theorem negCrossTruncBottomGap_last {r : RangeRead} {res : Result}
|
||||
(hne : res.keys ≠ []) (hcell : negCrossTruncBottomGap r res) :
|
||||
(hne : res.keys ≠ []) (_hcell : negCrossTruncBottomGap r res) :
|
||||
res.keys.getLastD ([] : Key) = res.keys.getLast hne := by
|
||||
rw [List.getLastD_eq_getLast?, List.getLast?_eq_some_getLast hne]; rfl
|
||||
|
||||
@@ -193,7 +193,7 @@ theorem exists_padDb_compatible {r : RangeRead} {res : Result}
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (dbF.keys.head hFne) := by
|
||||
change D[res.keys.length]? = some (dbF.keys.head hFne)
|
||||
rw [hD, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((dbF.keys.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor_end]; omega)]
|
||||
@@ -303,7 +303,7 @@ theorem exists_witness_below_head_bottomGap {r : RangeRead} {res : Result} {k :
|
||||
rw [h1, h2, Nat.add_zero]
|
||||
have hcount_ins : (dbw.insert k hk_not_dbw).keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) = res.keys.length + 1 := by
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, if_pos rfl, hrescnt]
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, ite_eq_left rfl, hrescnt]
|
||||
have hreported : reportedBelowBegin r res = res.keys.length := by
|
||||
rw [reportedBelowBegin, List.countP_eq_length]
|
||||
intro x hx
|
||||
@@ -448,7 +448,7 @@ theorem exists_witness_erase_bottomGap {r : RangeRead} {res : Result} {k : Key}
|
||||
rw [decide_eq_true_eq]; exact hkE
|
||||
have h2 : (dbF.keys.erase k).countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.end_.key)) = clampNonposD r := by
|
||||
rw [List.countP_erase, if_pos ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
rw [List.countP_erase, ite_eq_left ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
omega
|
||||
rw [h1, h2]
|
||||
have hd_int : ((clampNonposD r : ℕ) : ℤ) = -r.end_.offset := by
|
||||
@@ -471,7 +471,7 @@ theorem exists_witness_erase_bottomGap {r : RangeRead} {res : Result} {k : Key}
|
||||
((res.keys.getLast hne : Key) : WithTop Key) := by
|
||||
have h0 : 0 ≤ r.end_.anchor (dbw.erase k) := by rw [hanchor_erase]; omega
|
||||
have hlenErase : (dbw.erase k).keys.length = res.keys.length + clampNonposD r := by
|
||||
rw [herase_keys, List.length_append, List.length_erase, if_pos hk_in_F, hFlen]
|
||||
rw [herase_keys, List.length_append, List.length_erase, ite_eq_left hk_in_F, hFlen]
|
||||
omega
|
||||
have hlt : (r.end_.anchor (dbw.erase k)).toNat < (dbw.erase k).keys.length := by
|
||||
rw [hanchor_erase, hlenErase]
|
||||
@@ -523,12 +523,12 @@ theorem minimal_closedForm_of_negCross_trunc_bottomGap {r : RangeRead} {res : Re
|
||||
((res.keys.head hne : Key) : WithTop Key)
|
||||
· exact necessary_of_toggle
|
||||
(exists_witness_below_head_bottomGap hread hcell' hne hkhead)
|
||||
· push_neg at hkhead
|
||||
· push Not at hkhead
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤
|
||||
((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hkhead) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
obtain ⟨dbw, hcompw, hkdbw, hnot⟩ :=
|
||||
exists_witness_erase_bottomGap hread hcell' hne hklast hkE
|
||||
exact necessary_of_toggle ⟨dbw, hcompw, by
|
||||
|
||||
@@ -23,7 +23,6 @@ complete clamping cell) from the reported and intermediate keys (convexity).
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -38,7 +37,7 @@ abbrev negCrossTruncClampNoGapTop (r : RangeRead) (res : Result) : Prop :=
|
||||
reportedBelowBegin r res ≤ beginSlack r
|
||||
|
||||
/-- The closed form for the no-gap clamping cell: `[⊥, begin.key)`. -/
|
||||
noncomputable def closedFormNegCrossTruncClampNoGapTop (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncClampNoGapTop (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((↑([] : Key) : WithTop Key)), r.begin.key⟩
|
||||
|
||||
@@ -114,7 +113,7 @@ theorem necessary_below_head_of_negCross_trunc_clamp {r : RangeRead} {res : Resu
|
||||
hlast_lt_res₁
|
||||
have hcomp₁ : RangeRead.Compatible db₁ r res := by
|
||||
refine ⟨hcomp₀.1, Or.inl ⟨hmore, ?_, hne⟩⟩
|
||||
simpa [hck₁] using (List.prefix_refl (res.keys))
|
||||
simp [hck₁]
|
||||
let db₂ : DB := db₁.insert k hk_not
|
||||
have hagree : AgreeOn cr db₁ db₂ :=
|
||||
(ConflictRange.keys_insert_of_not_mem cr db₁ hk_not hkcr).symm
|
||||
@@ -757,7 +756,7 @@ abbrev negCrossTruncClampNoGap (r : RangeRead) (res : Result) : Prop :=
|
||||
reportedBelowBegin r res ≤ beginSlack r
|
||||
|
||||
/-- The closed form for the arbitrary-end no-gap clamping cell: `[⊥, begin.key)`. -/
|
||||
noncomputable def closedFormNegCrossTruncClampNoGap (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncClampNoGap (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((↑([] : Key) : WithTop Key)), r.begin.key⟩
|
||||
|
||||
@@ -1045,7 +1044,7 @@ theorem compatible_iff_noGapRead_of_gapLow {r : RangeRead} {res : Result}
|
||||
(cnt db (((keyAfter last : Key)) : WithTop Key) : ℤ) - (beginSlack r : ℤ) - 1 := by
|
||||
have hs : beginSlack (noGapRead r res) = beginSlack r := rfl
|
||||
rw [anchor_eq_count_sub_slack db (noGapRead r res) (le_of_lt hbegin), hs]
|
||||
simp [cnt, noGapRead, hlastD, hlastD']
|
||||
simp [cnt, noGapRead, hlastD']
|
||||
have h_eq_r : r.begin.anchor db =
|
||||
(cnt db r.begin.key : ℤ) - (beginSlack r : ℤ) - 1 := by
|
||||
rw [anchor_eq_count_sub_slack db r (le_of_lt hbegin)]
|
||||
@@ -1170,7 +1169,7 @@ theorem compatible_iff_noGapRead_of_gapLow {r : RangeRead} {res : Result}
|
||||
have htg_le : t + (between db (((keyAfter last : Key)) : WithTop Key)
|
||||
r.begin.key).length ≤ beginSlack r := by
|
||||
have hgl : (between db (((keyAfter last : Key)) : WithTop Key)
|
||||
r.begin.key).length < beginSlack r + 1 - t := ENat.coe_lt_coe.mp hg_lt
|
||||
r.begin.key).length < beginSlack r + 1 - t := ENat.natCast_lt_natCast.mp hg_lt
|
||||
omega
|
||||
have hanc_r : r.begin.anchor db < 0 := by
|
||||
have h_eq_r : r.begin.anchor db =
|
||||
@@ -1396,7 +1395,7 @@ theorem compatible_iff_noGapRead_of_gapBotMid {r : RangeRead} {res : Result}
|
||||
(cnt db (((keyAfter last : Key)) : WithTop Key) : ℤ) - (beginSlack r : ℤ) - 1 := by
|
||||
have hs : beginSlack (noGapRead r res) = beginSlack r := rfl
|
||||
rw [anchor_eq_count_sub_slack db (noGapRead r res) (le_of_lt hbegin), hs]
|
||||
simp [cnt, noGapRead, hlastD, hlastD']
|
||||
simp [cnt, noGapRead, hlastD']
|
||||
rw [h_eq, hcntKA']
|
||||
have h1 : (t : ℤ) ≤ (q : ℤ) := by exact_mod_cast htq
|
||||
rw [← hq]; omega
|
||||
@@ -1409,7 +1408,8 @@ theorem compatible_iff_noGapRead_of_gapBotMid {r : RangeRead} {res : Result}
|
||||
simp [noGapRead]
|
||||
rw [compatible_iff_truncated_keys (db := db) (r := noGapRead r res) hrev hmore hne]
|
||||
rw [compatible_iff_truncated_keys (db := db) (r := r) hrev hmore hne] at hcomp
|
||||
exact ⟨by change RangeRead.withinLimit r res.keys; exact hcomp.1, by rw [hck_eq_ng]; exact hcomp.2⟩
|
||||
exact ⟨by change RangeRead.withinLimit r res.keys; exact hcomp.1, by rw [hck_eq_ng]; exact
|
||||
hcomp.2⟩
|
||||
· -- Reverse: the lowered read resolves to `⊥`; the capacity bound keeps `r`'s anchor
|
||||
-- nonpositive, and `⊥` is stored, so `r` resolves to `⊥` too.
|
||||
intro hcompNG
|
||||
@@ -1478,7 +1478,7 @@ theorem compatible_iff_noGapRead_of_gapBotMid {r : RangeRead} {res : Result}
|
||||
rw [hcard_add, hcard_one]
|
||||
exact add_comm _ _
|
||||
_ ≤ (((q + 1 - t) + 1 : ℕ) : ℕ∞) := by simpa [hlastD', hq, ht] using hcap
|
||||
have hg1 : g + 1 ≤ (q + 1 - t) + 1 := ENat.coe_le_coe.mp hcap'
|
||||
have hg1 : g + 1 ≤ (q + 1 - t) + 1 := ENat.natCast_le_natCast.mp hcap'
|
||||
have htg : t + g ≤ q + 1 := by omega
|
||||
have hanchor : r.begin.anchor db =
|
||||
(cnt db r.begin.key : ℤ) - (beginSlack r : ℤ) - 1 := by
|
||||
@@ -1509,7 +1509,7 @@ theorem compatible_iff_noGapRead_of_gapBotMid {r : RangeRead} {res : Result}
|
||||
simp [noGapRead]
|
||||
rw [compatible_iff_truncated_keys (db := db) (r := r) hrev hmore hne]
|
||||
rw [compatible_iff_truncated_keys (db := db) (r := noGapRead r res) hrev hmore hne] at hcompNG
|
||||
exact ⟨by change RangeRead.withinLimit r res.keys; exact hcompNG.1, by rw [← hck_eq]; exact hcompNG.2⟩
|
||||
exact ⟨by exact hcompNG.1, by rw [← hck_eq]; exact hcompNG.2⟩
|
||||
|
||||
/-- The lowered read satisfies the no-gap clamping cell whenever the original read is in
|
||||
the empty-head middle gap cell. -/
|
||||
@@ -1592,7 +1592,7 @@ abbrev negCrossTruncClampGapHighBot (r : RangeRead) (res : Result) : Prop :=
|
||||
intervalCard (((res.keys.getLastD ([] : Key)) : Key) : WithTop Key) r.begin.key
|
||||
|
||||
/-- The closed form for the empty-head high-capacity gap cell: `[⊥, begin.key)`. -/
|
||||
noncomputable def closedFormNegCrossTruncClampGapHighBot (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncClampGapHighBot (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((↑([] : Key) : WithTop Key)), r.begin.key⟩
|
||||
|
||||
@@ -1727,7 +1727,7 @@ theorem compatible_of_append_gapKeys_highBot {r : RangeRead} {res : Result} {db
|
||||
(hlastE : (((res.keys.getLastD ([] : Key)) : Key)) < r.end_.key)
|
||||
(hgap : (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) <
|
||||
r.begin.key)
|
||||
(hsort : res.keys.SortedLT) (hJ : J.SortedLT)
|
||||
(hsort : res.keys.SortedLT) (_hJ : J.SortedLT)
|
||||
(hJrange : ∀ x ∈ J, (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) ≤
|
||||
((x : Key) : WithTop Key) ∧ ((x : Key) : WithTop Key) < r.begin.key)
|
||||
(hJlen : J.length = beginSlack r + 1 - res.keys.length)
|
||||
@@ -1784,7 +1784,6 @@ theorem compatible_of_append_gapKeys_highBot {r : RangeRead} {res : Result} {db
|
||||
rw [anchor_eq_count_sub_slack db r (le_of_lt hbegin)]
|
||||
change ((cnt db r.begin.key : ℕ) : ℤ) - (beginSlack r : ℤ) - 1 = 0
|
||||
rw [hcntB, ← hq]
|
||||
change ((t + T : ℕ) : ℤ) - (q : ℤ) - 1 = 0
|
||||
rw [hT]
|
||||
omega
|
||||
have hbot_mem : ([] : Key) ∈ db.keys := by
|
||||
@@ -2070,7 +2069,7 @@ theorem compatible_of_append_gapKeys_high {r : RangeRead} {res : Result} {db : D
|
||||
(r.end_.offset - 1).toNat)
|
||||
(hgap : (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) <
|
||||
r.begin.key)
|
||||
(hsort : res.keys.SortedLT) (hJ : J.SortedLT)
|
||||
(hsort : res.keys.SortedLT) (_hJ : J.SortedLT)
|
||||
(hJrange : ∀ x ∈ J, (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) ≤
|
||||
((x : Key) : WithTop Key) ∧ ((x : Key) : WithTop Key) < r.begin.key)
|
||||
(hJlen : J.length = beginSlack r + 1 - res.keys.length)
|
||||
@@ -2127,7 +2126,6 @@ theorem compatible_of_append_gapKeys_high {r : RangeRead} {res : Result} {db : D
|
||||
rw [anchor_eq_count_sub_slack db r (le_of_lt hbegin)]
|
||||
change ((cnt db r.begin.key : ℕ) : ℤ) - (beginSlack r : ℤ) - 1 = 0
|
||||
rw [hcntB, ← hq]
|
||||
change ((t + T : ℕ) : ℤ) - (q : ℤ) - 1 = 0
|
||||
rw [hT]
|
||||
omega
|
||||
have hhead_mem : head ∈ res.keys := by rw [hhead]; exact List.head_mem hne
|
||||
@@ -2212,7 +2210,7 @@ abbrev negCrossTruncClampGapHigh (r : RangeRead) (res : Result) : Prop :=
|
||||
intervalCard (((res.keys.getLastD ([] : Key)) : Key) : WithTop Key) r.begin.key
|
||||
|
||||
/-- The closed form for the nonempty-head high-capacity gap cell: `[⊥, begin.key)`. -/
|
||||
noncomputable def closedFormNegCrossTruncClampGapHigh (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncClampGapHigh (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((↑([] : Key) : WithTop Key)), r.begin.key⟩
|
||||
|
||||
@@ -2229,7 +2227,7 @@ theorem compatible_of_nil_cons_gapKeys_high {r : RangeRead} {res : Result} {db :
|
||||
(hlastE : (((res.keys.getLastD ([] : Key)) : Key)) < r.end_.key)
|
||||
(hgap : (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) <
|
||||
r.begin.key)
|
||||
(hsort : res.keys.SortedLT) (hJ : J.SortedLT)
|
||||
(hsort : res.keys.SortedLT) (_hJ : J.SortedLT)
|
||||
(hJrange : ∀ x ∈ J, (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) ≤
|
||||
((x : Key) : WithTop Key) ∧ ((x : Key) : WithTop Key) < r.begin.key)
|
||||
(hJlen : J.length = beginSlack r + 1 - res.keys.length)
|
||||
@@ -2361,7 +2359,7 @@ theorem compatible_of_nil_cons_gapKeys_high {r : RangeRead} {res : Result} {db :
|
||||
rw [Bool.and_eq_true, Bool.and_eq_true] at hcon
|
||||
exact (not_le.mpr (lt_of_le_of_ne (nil_le_key head) (Ne.symm hheadne')))
|
||||
(of_decide_eq_true hcon.2.1)
|
||||
rw [if_neg hnil_pred]
|
||||
rw [ite_eq_right hnil_pred]
|
||||
have h1 : res.keys.filter (fun k : Key => decide (k ≤ last) && (decide (head ≤ k) &&
|
||||
decide (((k : Key) : WithTop Key) < resolve db r.end_))) = res.keys := by
|
||||
rw [List.filter_eq_self]
|
||||
@@ -2715,7 +2713,7 @@ theorem necessary_gap_high {r : RangeRead} {res : Result} {k : Key}
|
||||
· intro x
|
||||
simp only [List.mem_filter, decide_eq_true_eq]
|
||||
have hdbiff : x ∈ db1.keys ↔ x = k ∨ x ∈ db0.keys := by
|
||||
show x ∈ ([] : Key) :: (res.keys ++ J) ↔
|
||||
change x ∈ ([] : Key) :: (res.keys ++ J) ↔
|
||||
x = k ∨ x ∈ ([] : Key) :: (res.keys ++ dbJ.keys)
|
||||
unfold J
|
||||
simp only [List.mem_cons, List.mem_append, List.mem_orderedInsert]
|
||||
|
||||
@@ -18,7 +18,6 @@ head, so the target is necessary regardless of the end key.
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-- Split the half-open interval above a key at its immediate successor. -/
|
||||
theorem intervalCard_last_eq_keyAfter_add_one {last : Key} {B : WithTop Key}
|
||||
@@ -177,7 +176,7 @@ head. Such a key and all reported keys would lie at or below the reported last,
|
||||
the end-count bound forced by `last < resolve end_`. -/
|
||||
theorem not_lt_head_of_mem_of_compatible_saturated {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = true) (hne : res.keys ≠ []) (hendoff : 1 ≤ r.end_.offset)
|
||||
(_hmore : res.more = true) (hne : res.keys ≠ []) (hendoff : 1 ≤ r.end_.offset)
|
||||
(hE : r.end_.key = (([] : Key) : WithTop Key))
|
||||
(hsat : (r.end_.offset - 1).toNat = res.keys.length)
|
||||
{x : Key} (hxdb : x ∈ db.keys) (hxhead : x < res.keys.head hne) : False := by
|
||||
@@ -320,7 +319,7 @@ theorem compatible_of_nil_cons_gapKeys_high_of_end_count {r : RangeRead} {res :
|
||||
(hheadne : res.keys.headD ([] : Key) ≠ ([] : Key))
|
||||
(hgap : (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) <
|
||||
r.begin.key)
|
||||
(hsort : res.keys.SortedLT) (hJ : J.SortedLT)
|
||||
(hsort : res.keys.SortedLT) (_hJ : J.SortedLT)
|
||||
(hJrange : ∀ x ∈ J, (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) ≤
|
||||
((x : Key) : WithTop Key) ∧ ((x : Key) : WithTop Key) < r.begin.key)
|
||||
(hJlen : J.length = beginSlack r + 1 - res.keys.length)
|
||||
@@ -376,7 +375,7 @@ theorem compatible_of_nil_cons_gapKeys_high_of_end_count {r : RangeRead} {res :
|
||||
((([] : Key) : WithTop Key)) < r.begin.key) := by
|
||||
intro h
|
||||
exact (not_le.mpr (WithTop.coe_lt_coe.mpr hnil_lt_head)) h.1
|
||||
rw [if_neg (by simpa only [decide_eq_true_eq] using hnil)]
|
||||
rw [ite_eq_right (by simpa only [decide_eq_true_eq] using hnil)]
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
@@ -410,7 +409,7 @@ theorem compatible_of_nil_cons_gapKeys_high_of_end_count {r : RangeRead} {res :
|
||||
intro hcon
|
||||
rw [Bool.and_eq_true, Bool.and_eq_true] at hcon
|
||||
exact (not_le.mpr hnil_lt_head) (of_decide_eq_true hcon.2.1)
|
||||
rw [if_neg hnil_pred]
|
||||
rw [ite_eq_right hnil_pred]
|
||||
have h1 : res.keys.filter (fun k : Key => decide (k ≤ last) && (decide (head ≤ k) &&
|
||||
decide (((k : Key) : WithTop Key) < resolve db r.end_))) = res.keys := by
|
||||
rw [List.filter_eq_self]
|
||||
@@ -460,7 +459,7 @@ theorem end_count_nil_cons_gapKeys_of_unsaturated {r : RangeRead} {res : Result}
|
||||
([] : Key) :: res.keys := by
|
||||
rw [hkeys, List.filter_cons, List.filter_append]
|
||||
have hnil : decide (([] : Key) ≤ last) = true := by simp [nil_le_key]
|
||||
rw [if_pos hnil]
|
||||
rw [ite_eq_left hnil]
|
||||
have h1 : res.keys.filter (fun k : Key => decide (k ≤ last)) = res.keys := by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
@@ -482,7 +481,7 @@ theorem end_count_nil_cons_gapKeys_of_unsaturated {r : RangeRead} {res : Result}
|
||||
exact coe_nil_le_key_withTop _
|
||||
have hnilE : decide (r.end_.key ≤ ((([] : Key) : WithTop Key))) = true := by
|
||||
rw [decide_eq_true_eq, hE]
|
||||
rw [List.filter_cons, if_pos hnilE, hresE, List.length_cons]
|
||||
rw [List.filter_cons, ite_eq_left hnilE, hresE, List.length_cons]
|
||||
have hbase' : res.keys.length ≤ (r.end_.offset - 1).toNat := by
|
||||
rwa [hresE] at hbase
|
||||
have hne_count := hunsat.resolve_left (not_not.mpr hE)
|
||||
@@ -740,7 +739,7 @@ theorem necessary_gap_padded {r : RangeRead} {res : Result} {k : Key}
|
||||
· intro x
|
||||
simp only [List.mem_filter, decide_eq_true_eq]
|
||||
have hdbiff : x ∈ db1.keys ↔ x = k ∨ x ∈ db0.keys := by
|
||||
show x ∈ ([] : Key) :: (res.keys ++ J) ↔
|
||||
change x ∈ ([] : Key) :: (res.keys ++ J) ↔
|
||||
x = k ∨ x ∈ ([] : Key) :: (res.keys ++ dbJ.keys)
|
||||
unfold J
|
||||
simp only [List.mem_cons, List.mem_append, List.mem_orderedInsert]
|
||||
@@ -870,7 +869,7 @@ theorem compatible_iff_noGapRead_of_gapExactSaturated {r : RangeRead} {res : Res
|
||||
(beginSlack r : ℤ) - 1 := by
|
||||
have hs : beginSlack (noGapRead r res) = beginSlack r := rfl
|
||||
rw [anchor_eq_count_sub_slack db (noGapRead r res) (le_of_lt hbegin), hs]
|
||||
simp [cnt, noGapRead, hlastD, hlastD']
|
||||
simp [cnt, noGapRead, hlastD']
|
||||
rw [h_eq, hcntK]
|
||||
have h1 : (t : ℤ) ≤ (q : ℤ) := by exact_mod_cast htq
|
||||
rw [← hq]
|
||||
@@ -909,7 +908,7 @@ theorem compatible_iff_noGapRead_of_gapExactSaturated {r : RangeRead} {res : Res
|
||||
r.begin.key := by
|
||||
rw [hg]
|
||||
exact between_length_le_intervalCard (db := db) (le_of_lt hgap')
|
||||
exact ENat.coe_le_coe.mp (hgA.trans hcap'.le)
|
||||
exact ENat.natCast_le_natCast.mp (hgA.trans hcap'.le)
|
||||
have htg : t + g ≤ q + 1 := by rw [hT] at hgT; omega
|
||||
have hanchor : r.begin.anchor db ≤ 0 := by
|
||||
have h_eq : r.begin.anchor db =
|
||||
@@ -926,7 +925,7 @@ theorem compatible_iff_noGapRead_of_gapExactSaturated {r : RangeRead} {res : Res
|
||||
have hck := completeKeys_noGapRead_eq_of_no_lt_head hrev hno hbr hbng
|
||||
rw [compatible_iff_truncated_keys hrev hmore hne]
|
||||
rw [compatible_iff_truncated_keys (r := noGapRead r res) hrev hmore hne] at hcompNG
|
||||
exact ⟨by change RangeRead.withinLimit r res.keys; exact hcompNG.1,
|
||||
exact ⟨by exact hcompNG.1,
|
||||
by rw [hck]; exact hcompNG.2⟩
|
||||
|
||||
/-- The lowered read satisfies the arbitrary-end no-gap clamping cell. -/
|
||||
|
||||
@@ -175,7 +175,7 @@ theorem exists_clamp_compat_nonpos_lastGe_prefix {r : RangeRead} {res : Result}
|
||||
exact hfilt_b
|
||||
refine ⟨db, ⟨hlim, ?_⟩, hanchor⟩
|
||||
rcases hcomp₀.2 with ⟨hmore, -, -⟩ | ⟨hmore, -⟩
|
||||
· exact Or.inl ⟨hmore, by simpa [hck] using (List.prefix_refl res.keys), hne⟩
|
||||
· exact Or.inl ⟨hmore, by simp [hck], hne⟩
|
||||
· exact Or.inr ⟨hmore, hck.symm⟩
|
||||
|
||||
/-- **Soundness of `[⊥, end_.key)` for truncated results.** Agreement on every key below
|
||||
@@ -402,7 +402,7 @@ theorem exists_witness_negCross_trunc_clamp_above_last {r : RangeRead} {res : Re
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (F.head hFne) := by
|
||||
change D[res.keys.length]? = some (F.head hFne)
|
||||
rw [hD, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor_end]; omega)]
|
||||
@@ -499,7 +499,7 @@ theorem exists_witness_negCross_trunc_clamp_above_last {r : RangeRead} {res : Re
|
||||
rw [hanchor_end', hEqInt, Int.toNat_natCast]
|
||||
have hD'get? : (dbw.erase k).keys[res.keys.length - 1]? = some last := by
|
||||
rw [hD', List.getElem?_append]
|
||||
rw [if_pos (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [ite_eq_left (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [List.getElem?_eq_getElem (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
congr 1
|
||||
rw [hlast, List.getLast_eq_getElem hne]
|
||||
@@ -520,7 +520,8 @@ theorem exists_witness_negCross_trunc_clamp_above_last {r : RangeRead} {res : Re
|
||||
rw [List.filter_congr hpred, hD', List.filter_append]
|
||||
conv_lhs => rw [← List.dropLast_append_getLast hne, hlast]
|
||||
rw [List.filter_append]
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast := by
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast :=
|
||||
by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
@@ -569,7 +570,7 @@ theorem necessary_negCross_trunc_clamp_above_last {r : RangeRead} {res : Result}
|
||||
exact hnot⟩
|
||||
|
||||
/-- The closed form of the cell: `[⊥, end_.key)`. -/
|
||||
noncomputable def closedFormNegCrossTruncClampLastGe (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncClampLastGe (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩
|
||||
|
||||
@@ -598,11 +599,11 @@ theorem minimal_closedForm_of_negCross_trunc_clamp_lastGe {r : RangeRead} {res :
|
||||
intro k hkbot hkE
|
||||
by_cases hkhead : ((k : Key) : WithTop Key) < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· exact necessary_below_head_of_anchor_nonpos_negCross db hcomp hrev hne hanchor hkhead
|
||||
· push_neg at hkhead
|
||||
· push Not at hkhead
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤ ((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread' (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hkhead) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
exact necessary_negCross_trunc_clamp_above_last hread' hrev hmore hne hbegin hend
|
||||
hclamp hB_le_last (WithTop.coe_lt_coe.mp hklast) hkE
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ necessary by a toggle witness on the reported keys.
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -1242,7 +1241,8 @@ theorem compatible_of_agree_negCross_trunc_nonclamp_lowEndSmall {r : RangeRead}
|
||||
rw [hcr]
|
||||
exact ⟨hk1, hk2⟩
|
||||
obtain ⟨hL2, hpart2⟩ := begin_eq_head_and_window_of_agree_negCross_trunc_nonclamp
|
||||
hrev hmore hne hbegin hcross hnonclamp_eq hc1 (fun k hk1 hk2 => hmk k hk1 (by simpa [hupper] using hk2))
|
||||
hrev hmore hne hbegin hcross hnonclamp_eq hc1 (fun k hk1 hk2 => hmk k hk1 (by simpa [hupper]
|
||||
using hk2))
|
||||
have hEhead' : r.end_.key < ((head : Key) : WithTop Key) := by rw [hhead]; exact hEhead
|
||||
have hsmall' : intervalCard r.end_.key ((head : Key) : WithTop Key) +
|
||||
(res.keys.length : ℕ∞) ≤ (((r.end_.offset - 1).toNat : ℕ) : ℕ∞) := by
|
||||
@@ -1318,7 +1318,8 @@ theorem compatible_of_agree_negCross_trunc_nonclamp_lowEndBig {r : RangeRead} {r
|
||||
intro k hk1 hk2
|
||||
exact hmkE k (le_trans (le_of_lt hEhead') hk1) hk2
|
||||
obtain ⟨hL2, hpart2⟩ := begin_eq_head_and_window_of_agree_negCross_trunc_nonclamp
|
||||
hrev hmore hne hbegin hcross hnonclamp_eq hc1 (fun k hk1 hk2 => hmk k hk1 (by simpa [hupper] using hk2))
|
||||
hrev hmore hne hbegin hcross hnonclamp_eq hc1 (fun k hk1 hk2 => hmk k hk1 (by simpa [hupper]
|
||||
using hk2))
|
||||
have hpart2' : db2.keys.filter (fun k : Key => decide
|
||||
(((head : Key) : WithTop Key) ≤ (k : WithTop Key) ∧ (k : Key) ≤ last)) = res.keys := by
|
||||
simpa [hhead, hlast] using hpart2
|
||||
@@ -1427,12 +1428,12 @@ theorem necessary_negCross_trunc_between_end_head {r : RangeRead} {res : Result}
|
||||
have hlt : e1 < G + rl := by
|
||||
have hb := hbig'
|
||||
rw [← hG] at hb
|
||||
rw [← ENat.coe_add] at hb
|
||||
exact ENat.coe_lt_coe.mp hb
|
||||
rw [← ENat.natCast_add] at hb
|
||||
exact ENat.natCast_lt_natCast.mp hb
|
||||
have hGle : n + 1 ≤ G := by
|
||||
rw [hn]; omega
|
||||
rw [← hG]
|
||||
exact ENat.coe_le_coe.mpr hGle
|
||||
exact ENat.natCast_le_natCast.mpr hGle
|
||||
obtain ⟨dbK, hKrange, hkK, hKlen⟩ :=
|
||||
exists_db_keysIn_avoid (B := r.end_.key) (E := ((head : Key) : WithTop Key))
|
||||
(k := k) (m := n) hcard
|
||||
|
||||
@@ -529,7 +529,7 @@ theorem resolve_begin_eq_head_of_append_ge_begin {db : DB} {r : RangeRead} {res
|
||||
have hlt : (r.begin.anchor db).toNat < db.keys.length := by rw [htoNat]; exact hpos
|
||||
have hopt0 : db.keys[0]? = some (res.keys.head hne) := by
|
||||
rw [hdb, List.getElem?_append]
|
||||
rw [if_pos (List.length_pos_of_ne_nil hne)]
|
||||
rw [ite_eq_left (List.length_pos_of_ne_nil hne)]
|
||||
rw [← List.head?_eq_getElem?]
|
||||
exact List.head?_eq_some_head hne
|
||||
have hopt : db.keys[(r.begin.anchor db).toNat]? = some (res.keys.head hne) := by
|
||||
@@ -696,7 +696,7 @@ theorem exists_witness_negCross_trunc_nonclamp_nonposEnd {r : RangeRead} {res :
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (F.head hFne) := by
|
||||
change D[res.keys.length]? = some (F.head hFne)
|
||||
rw [hD, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor_end]; omega)]
|
||||
@@ -779,7 +779,7 @@ theorem exists_witness_negCross_trunc_nonclamp_nonposEnd {r : RangeRead} {res :
|
||||
rw [hanchor_end', hEqInt, Int.toNat_natCast]
|
||||
have hD'get? : (dbw.erase k).keys[res.keys.length - 1]? = some last := by
|
||||
rw [hD', List.getElem?_append]
|
||||
rw [if_pos (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [ite_eq_left (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [List.getElem?_eq_getElem (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
congr 1
|
||||
rw [hlast, List.getLast_eq_getElem hne]
|
||||
@@ -809,7 +809,8 @@ theorem exists_witness_negCross_trunc_nonclamp_nonposEnd {r : RangeRead} {res :
|
||||
exact ⟨fun h => h.2, fun h => ⟨hhead_le_all x hx, h⟩⟩]
|
||||
conv_lhs => rw [← List.dropLast_append_getLast hne, hlast]
|
||||
rw [List.filter_append]
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast := by
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast :=
|
||||
by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
|
||||
@@ -142,7 +142,8 @@ theorem gap_count_eq_beginSlack_of_resolve_head {db : DB} {r : RangeRead} {head
|
||||
rw [hsplit, ← List.countP_eq_length_filter]
|
||||
have hkey := anchor_eq_count_sub_slack db r (le_of_lt hbegin)
|
||||
rw [hanchor] at hkey
|
||||
have hcast : ((db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) : ℕ) : ℤ) =
|
||||
have hcast : ((db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key))
|
||||
: ℕ) : ℤ) =
|
||||
(db.keys.countP (fun k : Key => decide (k < head)) : ℤ) +
|
||||
((db.keys.filter (fun k : Key => decide
|
||||
(((head : Key) : WithTop Key) ≤ ((k : Key) : WithTop Key) ∧
|
||||
@@ -151,7 +152,8 @@ theorem gap_count_eq_beginSlack_of_resolve_head {db : DB} {r : RangeRead} {head
|
||||
have hG : (db.keys.filter (fun k : Key => decide
|
||||
(((head : Key) : WithTop Key) ≤ ((k : Key) : WithTop Key) ∧
|
||||
((k : Key) : WithTop Key) < r.begin.key))).length = beginSlack r + 1 := by
|
||||
have h1 : ((db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) : ℕ) : ℤ) =
|
||||
have h1 : ((db.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) :
|
||||
ℕ) : ℤ) =
|
||||
(db.keys.countP (fun k : Key => decide (k < head)) : ℤ) + (beginSlack r : ℤ) + 1 := by
|
||||
linarith [hkey]
|
||||
have : ((db.keys.filter (fun k : Key => decide
|
||||
@@ -186,13 +188,15 @@ theorem resolve_begin_eq_head_of_agree_gap
|
||||
(a := head) (B := r.begin.key) (le_of_lt hcross)
|
||||
have hsplit₂ := countP_lt_eq_add_filter_withTop db₂.keys db₂.nodup
|
||||
(a := head) (B := r.begin.key) (le_of_lt hcross)
|
||||
have hsplit₁' : db₁.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) =
|
||||
have hsplit₁' : db₁.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
r.begin.key)) =
|
||||
db₁.keys.countP (fun k : Key => decide (k < head)) +
|
||||
db₁.keys.countP (fun k : Key => decide
|
||||
(((head : Key) : WithTop Key) ≤ ((k : Key) : WithTop Key) ∧
|
||||
((k : Key) : WithTop Key) < r.begin.key)) := by
|
||||
rw [hsplit₁, ← List.countP_eq_length_filter]
|
||||
have hsplit₂' : db₂.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) < r.begin.key)) =
|
||||
have hsplit₂' : db₂.keys.countP (fun k : Key => decide (((k : Key) : WithTop Key) <
|
||||
r.begin.key)) =
|
||||
db₂.keys.countP (fun k : Key => decide (k < head)) +
|
||||
db₂.keys.countP (fun k : Key => decide
|
||||
(((head : Key) : WithTop Key) ≤ ((k : Key) : WithTop Key) ∧
|
||||
@@ -281,7 +285,8 @@ theorem compatible_of_agree_negCross_trunc_nonposGap_nonbottom
|
||||
have hlast_upper : ((last : Key) : WithTop Key) < upper := by
|
||||
have hle := resolve_le_key_of_offset_nonpos (db := db1) (s := r.end_) hend
|
||||
exact lt_of_lt_of_le (lt_of_lt_of_le hlt1 hle) (by rw [hupper]; exact le_max_right _ _)
|
||||
have hmem := (agreeOn_iff (⟨((head : Key) : WithTop Key), upper⟩ : ConflictRange) db1 db2).mp hagree
|
||||
have hmem := (agreeOn_iff (⟨((head : Key) : WithTop Key), upper⟩ : ConflictRange) db1 db2).mp
|
||||
hagree
|
||||
have hmk : ∀ k : Key, ((head : Key) : WithTop Key) ≤ (k : WithTop Key) →
|
||||
(k : WithTop Key) < upper → (k ∈ db1.keys ↔ k ∈ db2.keys) := by
|
||||
intro k hk1 hk2
|
||||
|
||||
@@ -173,7 +173,7 @@ theorem beginSlack_eq_of_A2a_nonbottom {db : DB} {r : RangeRead} {res : Result}
|
||||
(between db (((keyAfter last : Key) : WithTop Key)) r.begin.key).length := by
|
||||
rw [← hbetween_len]
|
||||
apply List.Sublist.length_le
|
||||
show List.Sublist
|
||||
change List.Sublist
|
||||
(db.keys.filter (fun k : Key => decide
|
||||
(resolve db r.end_ ≤ ((k : Key) : WithTop Key) ∧
|
||||
((k : Key) : WithTop Key) < r.end_.key)))
|
||||
@@ -238,7 +238,7 @@ theorem intervalCard_keyAfter_getLast_ge {db : DB} {r : RangeRead} {res : Result
|
||||
have hlen_le : (between db (resolve db r.end_) r.end_.key).length ≤
|
||||
(between db (((keyAfter last : Key) : WithTop Key)) r.end_.key).length := by
|
||||
apply List.Sublist.length_le
|
||||
show List.Sublist
|
||||
change List.Sublist
|
||||
(db.keys.filter (fun k : Key => decide
|
||||
(resolve db r.end_ ≤ ((k : Key) : WithTop Key) ∧
|
||||
((k : Key) : WithTop Key) < r.end_.key)))
|
||||
@@ -536,7 +536,7 @@ theorem exists_witness_erase_A2a {r : RangeRead} {res : Result} {k : Key}
|
||||
rw [decide_eq_true_eq]; exact hkE
|
||||
have h2 : (dbF.keys.erase k).countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.end_.key)) = clampNonposD r := by
|
||||
rw [List.countP_erase, if_pos ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
rw [List.countP_erase, ite_eq_left ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
omega
|
||||
rw [h1, h2]
|
||||
have hoff : r.end_.offset = -(clampNonposD r : ℤ) := by
|
||||
@@ -560,7 +560,7 @@ theorem exists_witness_erase_A2a {r : RangeRead} {res : Result} {k : Key}
|
||||
((res.keys.getLast hne : Key) : WithTop Key) := by
|
||||
have h0 : 0 ≤ r.end_.anchor (dbw.erase k) := by rw [hanchor_erase]; omega
|
||||
have hlenErase : (dbw.erase k).keys.length = res.keys.length + clampNonposD r := by
|
||||
rw [herase_keys, List.length_append, List.length_erase, if_pos hk_in_F, hFlen]
|
||||
rw [herase_keys, List.length_append, List.length_erase, ite_eq_left hk_in_F, hFlen]
|
||||
omega
|
||||
have hlt : (r.end_.anchor (dbw.erase k)).toNat < (dbw.erase k).keys.length := by
|
||||
rw [hanchor_erase, hlenErase]
|
||||
|
||||
@@ -312,7 +312,7 @@ theorem exists_witness_below_head_A2aBottom {r : RangeRead} {res : Result} {k :
|
||||
have hcount_ins : (dbw.insert k hk_not_dbw).keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) =
|
||||
res.keys.length + (clampNonposD r + 1) + 1 := by
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, if_pos rfl, hrescnt]
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, ite_eq_left rfl, hrescnt]
|
||||
have hanchor_ins : r.begin.anchor (dbw.insert k hk_not_dbw) ≤ 0 := by
|
||||
rw [anchor_eq_count_sub_slack _ r (le_of_lt hbegin), hcount_ins]
|
||||
have hcast : (res.keys.length + (clampNonposD r + 1) : ℤ) ≤ (beginSlack r : ℤ) := by
|
||||
@@ -458,7 +458,7 @@ theorem exists_witness_last_end_A2aBottom {r : RangeRead} {res : Result} {k : Ke
|
||||
rw [decide_eq_true_eq]; exact hkE
|
||||
have h2 : (dbF.keys.erase k).countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.end_.key)) = clampNonposD r := by
|
||||
rw [List.countP_erase, if_pos ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
rw [List.countP_erase, ite_eq_left ⟨hk_in_F, hktrue⟩, hFall, hFlen]
|
||||
omega
|
||||
rw [h1, h2]
|
||||
have hoff : r.end_.offset = -(clampNonposD r : ℤ) := by
|
||||
@@ -482,7 +482,7 @@ theorem exists_witness_last_end_A2aBottom {r : RangeRead} {res : Result} {k : Ke
|
||||
((res.keys.getLast hne : Key) : WithTop Key) := by
|
||||
have h0 : 0 ≤ r.end_.anchor (dbw.erase k) := by rw [hanchor_erase]; omega
|
||||
have hlenErase : (dbw.erase k).keys.length = res.keys.length + clampNonposD r := by
|
||||
rw [herase_keys, List.length_append, List.length_erase, if_pos hk_in_F, hFlen]
|
||||
rw [herase_keys, List.length_append, List.length_erase, ite_eq_left hk_in_F, hFlen]
|
||||
omega
|
||||
have hlt : (r.end_.anchor (dbw.erase k)).toNat < (dbw.erase k).keys.length := by
|
||||
rw [hanchor_erase, hlenErase]
|
||||
@@ -513,7 +513,7 @@ theorem exists_witness_last_end_A2aBottom {r : RangeRead} {res : Result} {k : Ke
|
||||
((hsort.pairwise.imp le_of_lt).rel_getLast hx)) hlast_lt_B
|
||||
· exact lt_of_lt_of_le (hFend x (List.mem_of_mem_erase hx)) (le_of_lt hEB)
|
||||
have hlenErase : (dbw.erase k).keys.length = res.keys.length + clampNonposD r := by
|
||||
rw [herase_keys, List.length_append, List.length_erase, if_pos hk_in_F, hFlen]
|
||||
rw [herase_keys, List.length_append, List.length_erase, ite_eq_left hk_in_F, hFlen]
|
||||
omega
|
||||
rw [hcountB, hlenErase]
|
||||
have hcast : (res.keys.length + clampNonposD r : ℤ) ≤ (beginSlack r : ℤ) := by
|
||||
@@ -657,7 +657,7 @@ theorem exists_witness_gap_ne_head_A2aBottom {r : RangeRead} {res : Result} {k :
|
||||
have hcond' : ((beginSlack r + 1 : ℕ) : ℕ∞) ≤ (res.keys.length : ℕ∞) +
|
||||
intervalCard (((keyAfter last : Key)) : WithTop Key) r.begin.key := by
|
||||
have := hcond
|
||||
rw [hheadD, if_neg hhead, Nat.add_zero, hlastD] at this
|
||||
rw [hheadD, ite_eq_right hhead, Nat.add_zero, hlastD] at this
|
||||
exact this
|
||||
-- `t + (D+1) ≤ q`
|
||||
have hBE0 : intervalCard r.begin.key r.end_.key = 0 := intervalCard_eq_zero_of_le (le_of_lt hEB)
|
||||
@@ -716,7 +716,8 @@ theorem exists_witness_gap_ne_head_A2aBottom {r : RangeRead} {res : Result} {k :
|
||||
let dbG : DB := dbB.insert k hBk
|
||||
have hGlen : dbG.keys.length = fa := by
|
||||
rw [DB.insert_keys, List.orderedInsert_length, hBlen]; omega
|
||||
have hGmem : ∀ x ∈ dbG.keys, r.end_.key ≤ (x : WithTop Key) ∧ (x : WithTop Key) < r.begin.key := by
|
||||
have hGmem : ∀ x ∈ dbG.keys, r.end_.key ≤ (x : WithTop Key) ∧ (x : WithTop Key) < r.begin.key :=
|
||||
by
|
||||
intro x hx
|
||||
rw [DB.mem_insert_iff hBk] at hx
|
||||
rcases hx with rfl | hx
|
||||
@@ -833,7 +834,7 @@ theorem exists_witness_gap_ne_head_A2aBottom {r : RangeRead} {res : Result} {k :
|
||||
omega
|
||||
have hlast_eq_D : dbw.keys[t]'(by rw [hDlen]; omega) = last := by
|
||||
rw [List.getElem_of_eq hDkeys, List.getElem_cons]
|
||||
rw [dif_neg (by have : 0 < t := List.length_pos_iff.mpr hne; omega)]
|
||||
rw [dite_eq_right (by have : 0 < t := List.length_pos_iff.mpr hne; omega)]
|
||||
rw [List.getElem_append_left (i := t - 1) (h := by
|
||||
have : 0 < t := List.length_pos_iff.mpr hne
|
||||
omega)]
|
||||
@@ -900,7 +901,8 @@ theorem exists_witness_gap_ne_head_A2aBottom {r : RangeRead} {res : Result} {k :
|
||||
refine ⟨hlim, ?_⟩
|
||||
rw [← hld]
|
||||
exact hfilt_eq
|
||||
· rw [hDkeys]; exact List.mem_cons_of_mem _ (List.mem_append_right _ (List.mem_append_right _ hkG))
|
||||
· rw [hDkeys]; exact List.mem_cons_of_mem _ (List.mem_append_right _ (List.mem_append_right _
|
||||
hkG))
|
||||
· intro hcomp'
|
||||
obtain ⟨-, hfilt'⟩ := (compatible_iff_truncated_keys hrev hmore hne).mp hcomp'
|
||||
have hknil : k ≠ ([] : Key) :=
|
||||
@@ -1436,7 +1438,8 @@ theorem gap_slack_bound_A2aBottom {db : DB} {r : RangeRead} {res : Result}
|
||||
res.keys.length +
|
||||
(between db (((keyAfter last : Key)) : WithTop Key) r.begin.key).length := by
|
||||
rw [← hgap, hkey]
|
||||
have hlen_le : (((between db (((keyAfter last : Key)) : WithTop Key) r.begin.key).length : ℕ) : ℕ∞) ≤
|
||||
have hlen_le : (((between db (((keyAfter last : Key)) : WithTop Key) r.begin.key).length : ℕ) :
|
||||
ℕ∞) ≤
|
||||
intervalCard (((keyAfter last : Key)) : WithTop Key) r.begin.key :=
|
||||
between_length_le_intervalCard (keyAfter_le_of_lt hlastB')
|
||||
calc ((beginSlack r + 1 : ℕ) : ℕ∞)
|
||||
@@ -1492,7 +1495,7 @@ theorem resolve_begin_eq_nil_of_low_A2aBottom {r : RangeRead} {res : Result} {db
|
||||
have hheadD_ne : res.keys.headD ([] : Key) ≠ [] := by
|
||||
rw [List.headD_eq_head?, List.head?_eq_some_head hne]
|
||||
exact hne_head
|
||||
rw [if_neg hheadD_ne] at hnot'
|
||||
rw [ite_eq_right hheadD_ne] at hnot'
|
||||
exact hnot' (by simpa using hbound)
|
||||
rw [hres, hhead_nil]
|
||||
· exact resolve_eq_nil (not_le.mp hanc)
|
||||
@@ -1601,7 +1604,7 @@ theorem sound_bottomEnd_A2aBottom {r : RangeRead} {res : Result}
|
||||
have hheadD : res.keys.headD ([] : Key) = [] := by
|
||||
rw [hδdef] at hδ1
|
||||
by_contra h
|
||||
rw [if_neg h] at hδ1
|
||||
rw [ite_eq_right h] at hδ1
|
||||
omega
|
||||
have hhead_nil : head = [] := by
|
||||
rw [List.headD_eq_head?, List.head?_eq_some_head hne] at hheadD
|
||||
@@ -1674,7 +1677,7 @@ theorem minimal_closedForm_of_negCross_trunc_nonposGap_A2aBottom
|
||||
by_cases hhi : negCrossTruncNonposGapA2aBottomHigh r res
|
||||
· have hclosed : closedFormNegCrossTruncNonposGapA2aBottom r res =
|
||||
⟨(([] : Key) : WithTop Key), r.begin.key⟩ := by
|
||||
unfold closedFormNegCrossTruncNonposGapA2aBottom; rw [if_pos hhi]
|
||||
unfold closedFormNegCrossTruncNonposGapA2aBottom; rw [ite_eq_left hhi]
|
||||
rw [hclosed]
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr ⟨?_, ?_⟩
|
||||
· have hs := sound_bottomLong_of_nonpos (r := r) (res := res) hle_begin hend
|
||||
@@ -1694,7 +1697,7 @@ theorem minimal_closedForm_of_negCross_trunc_nonposGap_A2aBottom
|
||||
by rw [toggle_eq_erase_of_mem hkdbw]; exact hnot⟩
|
||||
· have hclosed : closedFormNegCrossTruncNonposGapA2aBottom r res =
|
||||
⟨(([] : Key) : WithTop Key), r.end_.key⟩ := by
|
||||
unfold closedFormNegCrossTruncNonposGapA2aBottom; rw [if_neg hhi]
|
||||
unfold closedFormNegCrossTruncNonposGapA2aBottom; rw [ite_eq_right hhi]
|
||||
rw [hclosed]
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr ⟨sound_bottomEnd_A2aBottom hcellKeep hhi, ?_⟩
|
||||
intro k _ hkE
|
||||
@@ -1754,7 +1757,7 @@ theorem a2b_high : negCrossTruncNonposGapA2aBottomHigh a2bRead a2bRes := by
|
||||
theorem a2b_clampLongUpper :
|
||||
clampLongUpper a2bRead a2bRes = ((a2bThree : Key) : WithTop Key) := by
|
||||
unfold clampLongUpper
|
||||
rw [if_pos]
|
||||
rw [ite_eq_left]
|
||||
· rfl
|
||||
· decide
|
||||
|
||||
@@ -1763,7 +1766,7 @@ theorem a2b_closedForm :
|
||||
closedFormNegCrossTruncNonposGapA2aBottom a2bRead a2bRes =
|
||||
⟨(([] : Key) : WithTop Key), ((a2bFour : Key) : WithTop Key)⟩ := by
|
||||
unfold closedFormNegCrossTruncNonposGapA2aBottom
|
||||
rw [if_pos a2b_high]
|
||||
rw [ite_eq_left a2b_high]
|
||||
rfl
|
||||
|
||||
/-- The old clamped branch `[⊥, clampLongUpper]` is not the gap-cell closed form on the
|
||||
|
||||
@@ -255,7 +255,6 @@ end FormalConflictRange
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
open scoped Classical
|
||||
|
||||
/-- Padding the reported keys with `f = D + 1 - g` keys in `(last, begin.key)` and the
|
||||
`g` keys of `[begin.key, end_.key)` gives a compatible database: the end selector
|
||||
@@ -380,7 +379,7 @@ theorem exists_padDb_crossFree {r : RangeRead} {res : Result} {dbF1 dbF2 : DB} {
|
||||
exact List.append_ne_nil_of_left_ne_nil hF1ne _
|
||||
have hDget? : (res.keys ++ F)[res.keys.length]? = some (F.head hFne) := by
|
||||
rw [List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hF, List.length_append]; omega),
|
||||
List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
@@ -433,7 +432,7 @@ theorem exists_padDb_crossFree {r : RangeRead} {res : Result} {dbF1 dbF2 : DB} {
|
||||
-- the complete keys are exactly the reported keys
|
||||
have hck : RangeRead.completeKeys dbw r = res.keys := by
|
||||
unfold RangeRead.completeKeys RangeRead.inRange
|
||||
rw [if_neg (by simp [hrev])]
|
||||
rw [ite_eq_right (by simp [hrev])]
|
||||
rw [hkeyw, List.filter_append, List.filter_append]
|
||||
have hres : res.keys.filter (fun k : Key => decide
|
||||
(resolve dbw r.begin ≤ ((k : Key) : WithTop Key) ∧
|
||||
@@ -466,7 +465,6 @@ theorem exists_padDb_crossFree {r : RangeRead} {res : Result} {dbF1 dbF2 : DB} {
|
||||
exact ⟨hlim, Or.inl ⟨hmore, by rw [hck], hne⟩⟩
|
||||
|
||||
|
||||
open scoped Classical
|
||||
|
||||
/-- Padding a compatible database with a list `F` of keys strictly above the reported
|
||||
last and strictly below the end key, whose length is `clampNonposD + 1`, and where the
|
||||
@@ -503,7 +501,7 @@ theorem erase_incompatible_of_pad
|
||||
have hcntErase : cnt (dbw.erase k) r.end_.key = (dbw.erase k).keys.length :=
|
||||
cnt_eq_length_of_forall_lt _ hEraseLt
|
||||
have hlenErase : (dbw.erase k).keys.length = res.keys.length + clampNonposD r := by
|
||||
rw [herase_keys, List.length_append, List.length_erase, if_pos hkF, hFlen]
|
||||
rw [herase_keys, List.length_append, List.length_erase, ite_eq_left hkF, hFlen]
|
||||
omega
|
||||
have hoff : r.end_.offset = -(clampNonposD r : ℤ) := by
|
||||
rw [clampNonposD_eq]
|
||||
@@ -550,7 +548,6 @@ theorem erase_incompatible_of_pad
|
||||
rw [hfilt]; exact List.getLast_mem hne
|
||||
exact hlast_not_ck (List.mem_of_mem_filter hlast_in_filt)
|
||||
|
||||
open scoped Classical
|
||||
|
||||
/-- A database of `f` keys in `(last, begin.key)`. -/
|
||||
theorem exists_dbF1_crossFree {r : RangeRead} {res : Result} {f : ℕ} {b : Key}
|
||||
@@ -576,7 +573,7 @@ theorem exists_dbF1_crossFree {r : RangeRead} {res : Result} {f : ℕ} {b : Key}
|
||||
rw [hb]; exact WithTop.coe_lt_coe.mpr h.2
|
||||
|
||||
/-- A database of `g` keys in `[begin.key, end_.key)`. -/
|
||||
theorem exists_dbF2_crossFree {r : RangeRead} {res : Result} {g : ℕ} {b e : Key}
|
||||
theorem exists_dbF2_crossFree {r : RangeRead} {_res : Result} {g : ℕ} {b e : Key}
|
||||
(hb : r.begin.key = ((b : Key) : WithTop Key))
|
||||
(he : r.end_.key = ((e : Key) : WithTop Key))
|
||||
(hcap : (g : ℕ∞) ≤ intervalCard r.begin.key r.end_.key) :
|
||||
@@ -656,7 +653,7 @@ theorem exists_dbF1_mem_crossFree {r : RangeRead} {res : Result} {f : ℕ} {k b
|
||||
· exact DB.mem_insert_self dbB k hBk
|
||||
|
||||
/-- A database of `g - 1` keys in `[begin.key, end_.key)` avoiding a chosen key. -/
|
||||
theorem exists_dbF2_avoid_crossFree {r : RangeRead} {res : Result} {g : ℕ} {k b e : Key}
|
||||
theorem exists_dbF2_avoid_crossFree {r : RangeRead} {_res : Result} {g : ℕ} {k b e : Key}
|
||||
(hb : r.begin.key = ((b : Key) : WithTop Key))
|
||||
(he : r.end_.key = ((e : Key) : WithTop Key))
|
||||
(hg : 1 ≤ g)
|
||||
@@ -692,7 +689,7 @@ theorem exists_dbF2_mem_crossFree {r : RangeRead} {res : Result} {g : ℕ} {k b
|
||||
(∀ x ∈ dbF2.keys, (x : WithTop Key) < r.end_.key) ∧
|
||||
dbF2.keys.length = g ∧ k ∈ dbF2.keys := by
|
||||
obtain ⟨dbB, hBB, hBE, hBlen, hBk⟩ :=
|
||||
exists_dbF2_avoid_crossFree (r := r) (res := res) (g := g) (k := k) (b := b) (e := e)
|
||||
exists_dbF2_avoid_crossFree (r := r) (_res := res) (g := g) (k := k) (b := b) (e := e)
|
||||
hb he hg hcap
|
||||
let dbF2 : DB := dbB.insert k hBk
|
||||
have hkey : dbF2.keys = dbB.keys.orderedInsert (· ≤ ·) k := DB.insert_keys dbB k hBk
|
||||
@@ -715,7 +712,6 @@ end FormalConflictRange
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
open scoped Classical
|
||||
|
||||
/-- In the cross-free low-capacity gap cell the interval capacity is finite and at most
|
||||
`clampNonposD`. -/
|
||||
@@ -924,7 +920,6 @@ theorem crossFree_pad_hanc0 {r : RangeRead} {res : Result}
|
||||
|
||||
|
||||
|
||||
open scoped Classical
|
||||
|
||||
/-- In the cross-free low-capacity gap cell, a key strictly between the reported last and
|
||||
`end_.key` has an erase witness. -/
|
||||
@@ -1026,7 +1021,7 @@ theorem exists_witness_last_end_crossFree {r : RangeRead} {res : Result} {k : Ke
|
||||
exists_dbF1_mem_crossFree (r := r) (res := res) (f := f) (k := k) (b := b)
|
||||
hne hb hf hroom' hkgt hkB
|
||||
obtain ⟨dbF2, hF2B, hF2E, hF2len⟩ :=
|
||||
exists_dbF2_crossFree (r := r) (res := res) (g := g) (b := b) (e := e) hb he hcap2
|
||||
exists_dbF2_crossFree (r := r) (_res := res) (g := g) (b := b) (e := e) hb he hcap2
|
||||
exact finish dbF1 dbF2 (List.mem_append.mpr (Or.inl hkF1)) hF1gt hF1B hF1len
|
||||
hF2B hF2E hF2len
|
||||
· -- k belongs to the second filler
|
||||
@@ -1128,7 +1123,7 @@ theorem exists_witness_below_head_crossFree {r : RangeRead} {res : Result} {k :
|
||||
obtain ⟨dbF1, hF1gt, hF1B, hF1len⟩ :=
|
||||
exists_dbF1_crossFree (r := r) (res := res) (f := f) (b := b) hne hb hroom'
|
||||
obtain ⟨dbF2, hF2B, hF2E, hF2len⟩ :=
|
||||
exists_dbF2_crossFree (r := r) (res := res) (g := g) (b := b) (e := e) hb he hcap2
|
||||
exists_dbF2_crossFree (r := r) (_res := res) (g := g) (b := b) (e := e) hb he hcap2
|
||||
have hF1len' : dbF1.keys.length = clampNonposD r + 1 - g := by
|
||||
rw [hF1len, hfdef]
|
||||
have hanc0 : res.keys.length + (clampNonposD r + 1 - g) ≤ beginSlack r + 1 := by
|
||||
@@ -1190,7 +1185,7 @@ theorem exists_witness_below_head_crossFree {r : RangeRead} {res : Result} {k :
|
||||
have hcount_ins : (dbw.insert k hk_not_dbw).keys.countP
|
||||
(fun x : Key => decide ((x : WithTop Key) < r.begin.key)) =
|
||||
res.keys.length + f + 1 := by
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, if_pos rfl, hrescnt]
|
||||
rw [hins_keys, List.countP_cons, decide_eq_true_eq.mpr hk_lt_B, ite_eq_left rfl, hrescnt]
|
||||
have hanchor_ins : r.begin.anchor (dbw.insert k hk_not_dbw) ≤ 0 := by
|
||||
rw [anchor_eq_count_sub_slack _ r (le_of_lt hbegin), hcount_ins]
|
||||
have hcast : (res.keys.length + f : ℤ) ≤ (beginSlack r : ℤ) := by
|
||||
@@ -1257,7 +1252,7 @@ theorem minimal_closedForm_of_negCross_trunc_nonposGap_crossFree
|
||||
· have hclosed : closedFormNegCrossTruncNonposGapCrossFree r res =
|
||||
(⟨(([] : Key) : WithTop Key), r.end_.key⟩ : ConflictRange) := by
|
||||
unfold closedFormNegCrossTruncNonposGapCrossFree closedFormNegCrossTruncNonposGap
|
||||
rw [if_pos hbot, max_eq_right hB_le_E]
|
||||
rw [ite_eq_left hbot, max_eq_right hB_le_E]
|
||||
rw [hclosed]
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr
|
||||
⟨sound_bottomEnd_crossFree hbegin hend hB_le_E, ?_⟩
|
||||
@@ -1286,7 +1281,7 @@ theorem minimal_closedForm_of_negCross_trunc_nonposGap_crossFree
|
||||
have hheadD : res.keys.headD ([] : Key) = res.keys.head hne :=
|
||||
list_headD_eq_head hne
|
||||
unfold closedFormNegCrossTruncNonposGapCrossFree closedFormNegCrossTruncNonposGap
|
||||
rw [if_neg hbot, max_eq_right hB_le_E]
|
||||
rw [ite_eq_right hbot, max_eq_right hB_le_E]
|
||||
exact congrArg (fun k : WithTop Key => (⟨k, r.end_.key⟩ : ConflictRange))
|
||||
(congrArg (fun k : Key => ((k : Key) : WithTop Key)) hheadD)
|
||||
rw [hclosed]
|
||||
|
||||
@@ -29,7 +29,6 @@ begin resolution past `L` and breaks the reported prefix.
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-- **The inner double filter of the reversed complete keys is the stored keys in
|
||||
`[L, end_.key)`.** At end offset one, a stored key lies below the end resolution exactly
|
||||
|
||||
@@ -27,7 +27,6 @@ number of stored keys in `[resolve end_, end_.key)`, which the count identity
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-- **The reported keys are the stored keys in `[last, resolve end_)` read backwards.**
|
||||
Unlike the end-offset-one version, this does not simplify the resolved end to `end_.key`;
|
||||
|
||||
@@ -35,7 +35,6 @@ Necessity is identical to the under-end cell: reported keys are necessary by
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-- **The length of `between` splits at an intermediate bound.** For `L ≤ E ≤ B` the
|
||||
stored keys in `[L, B)` are those in `[L, E)` followed by those in `[E, B)`. -/
|
||||
|
||||
@@ -21,7 +21,6 @@ begin resolution at or below the reported last, so the reduction is sound.
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-- **The general filter identity.** If the resolved begin lies at or below `last`,
|
||||
filtering the reversed complete keys at or above `last` is the reversal of the stored
|
||||
|
||||
@@ -24,7 +24,6 @@ of complete keys at or above `end_.key` is at most `end_.offset - 1`, for *every
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
/-! ### Reduction to the offset-one read at the reported last -/
|
||||
|
||||
@@ -151,7 +150,7 @@ theorem closedFormNegCrossTruncRevResidual_begin_le_last {r : RangeRead} {res :
|
||||
|
||||
/-- The residual closed form's end is at or above `begin.key`. -/
|
||||
theorem closedFormNegCrossTruncRevResidual_end_ge_begin {r : RangeRead} {res : Result}
|
||||
(hmore : res.more = true) (hne : res.keys ≠ []) :
|
||||
(_hmore : res.more = true) (_hne : res.keys ≠ []) :
|
||||
r.begin.key ≤ (closedFormNegCrossTruncRevResidual r res).end_ := by
|
||||
unfold closedFormNegCrossTruncRevResidual
|
||||
dsimp only
|
||||
@@ -781,12 +780,12 @@ theorem compatible_iff_topEnd_of_residual_top {db : DB} {r : RangeRead} {res : R
|
||||
have hre : resolve db r.end_ = (⊤ : WithTop Key) :=
|
||||
resolve_end_eq_top_of_count_lt hcomp hmore hrev hne hend hLE hlt
|
||||
have hck : RangeRead.completeKeys db r = RangeRead.completeKeys db r' := by
|
||||
simp [RangeRead.completeKeys, RangeRead.inRange, hrev, hrev', hre, hresEnd', r']
|
||||
simp [RangeRead.completeKeys, RangeRead.inRange, hrev, hre, hresEnd', r']
|
||||
exact (compatible_congr_completeKeys hck hlim').mp hcomp
|
||||
· intro hcomp'
|
||||
by_cases hretop : resolve db r.end_ = (⊤ : WithTop Key)
|
||||
· have hck : RangeRead.completeKeys db r = RangeRead.completeKeys db r' := by
|
||||
simp [RangeRead.completeKeys, RangeRead.inRange, hrev, hrev', hretop, hresEnd', r']
|
||||
simp [RangeRead.completeKeys, RangeRead.inRange, hrev, hretop, hresEnd', r']
|
||||
exact (compatible_congr_completeKeys hck hlim').mpr hcomp'
|
||||
· exfalso
|
||||
set L : Key := res.keys.getLast hne with hL
|
||||
@@ -886,7 +885,7 @@ theorem minimal_closedForm_of_negCross_trunc_rev_residual_begin_le
|
||||
obtain ⟨hmore, hrev, hbeg, hne, _, _⟩ := h
|
||||
refine minimal_closedForm_of_nonpos_revTrunc hread ⟨hmore, hrev, by omega, ?_⟩
|
||||
unfold leastReported
|
||||
rw [if_pos hrev]
|
||||
rw [ite_eq_left hrev]
|
||||
exact hBLE
|
||||
|
||||
/-! ### A bound on the reported keys below the begin selector -/
|
||||
|
||||
@@ -34,7 +34,6 @@ The complementary *over* part (`end_.key < last`) is not covered here.
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1600000
|
||||
|
||||
/-- The finite under cell of the reversed crossed negative-begin truncated residual:
|
||||
the finite branch on the region `last ≤ end_.key < begin.key`. -/
|
||||
|
||||
@@ -35,7 +35,6 @@ holds automatically, so the upper endpoint is `keyAfter head`; when the head lie
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1600000
|
||||
|
||||
/-- A subset of a duplicate-free list is no longer than it. -/
|
||||
theorem length_le_of_nodup_subset {l₁ l₂ : List Key} (h : l₁.Nodup) (hsub : l₁ ⊆ l₂) :
|
||||
@@ -74,7 +73,8 @@ theorem between_end_key_last_eq_nil {db : DB} {r : RangeRead} {res : Result}
|
||||
have hLRle : ((L : Key) : WithTop Key) ≤ resolve db r.end_ := le_of_lt hLR
|
||||
have hoff : 1 ≤ r.end_.offset := by omega
|
||||
have hnsub : res.keys.Nodup :=
|
||||
List.Nodup.sublist (RangeRead.compatible_keys_prefix hcomp).sublist (RangeRead.completeKeys_nodup db r)
|
||||
List.Nodup.sublist (RangeRead.compatible_keys_prefix hcomp).sublist
|
||||
(RangeRead.completeKeys_nodup db r)
|
||||
rcases eq_or_ne (resolve db r.end_) (⊤ : WithTop Key) with hRtop | hRne
|
||||
· -- the end resolution is the sentinel
|
||||
have hresend := resolve_eq_filter_getElem? (db := db) (s := r.end_) hoff
|
||||
@@ -195,7 +195,7 @@ theorem compatible_iff_over_reduce {r : RangeRead} {res : Result}
|
||||
have hres := hresolve hnil
|
||||
unfold RangeRead.completeKeys
|
||||
rw [hr'rev, hrev]
|
||||
simp only [Bool.not_true, ite_false, ite_true]
|
||||
simp only [ ite_true]
|
||||
rw [hres]
|
||||
constructor
|
||||
· intro hcomp
|
||||
@@ -224,7 +224,7 @@ theorem necessary_of_forall_not_mem {r : RangeRead} {res : Result} {k : Key}
|
||||
/-- If one database stores no key in `[E, L)` and two databases agree on `[E, U)` with
|
||||
`L ≤ U`, then neither does the other. -/
|
||||
theorem between_eq_nil_of_agreeOn {db₁ db₂ : DB} {E L U : WithTop Key}
|
||||
(hE : E ≤ L) (hLU : L ≤ U) (hnil : between db₁ E L = [])
|
||||
(_hE : E ≤ L) (hLU : L ≤ U) (hnil : between db₁ E L = [])
|
||||
(hagree : AgreeOn ⟨E, U⟩ db₁ db₂) :
|
||||
between db₂ E L = [] := by
|
||||
rw [List.eq_nil_iff_forall_not_mem]
|
||||
@@ -366,7 +366,8 @@ theorem necessary_of_mem_gap_of_negCross_trunc_rev_residualFiniteOver
|
||||
have hcrossG : ∀ x ∈ res.keys.reverse, ∀ y ∈ G, x < y := by
|
||||
intro x hx y hy
|
||||
have hx' : x ∈ res.keys := List.mem_reverse.mp hx
|
||||
exact WithTop.coe_lt_coe.mp (lt_of_le_of_lt (WithTop.coe_le_coe.mpr (hHge x hx')) (hH_lt_G y hy))
|
||||
exact WithTop.coe_lt_coe.mp (lt_of_le_of_lt (WithTop.coe_le_coe.mpr (hHge x hx')) (hH_lt_G y
|
||||
hy))
|
||||
have hkeysSorted : (res.keys.reverse ++ G).SortedLT :=
|
||||
List.sortedLT_append.mpr ⟨hresSort, hGsorted, hcrossG⟩
|
||||
let db_a : DB := ⟨res.keys.reverse ++ G, hkeysSorted⟩
|
||||
@@ -440,7 +441,8 @@ theorem necessary_of_mem_gap_of_negCross_trunc_rev_residualFiniteOver
|
||||
| nil => exact WithTop.coe_lt_top _
|
||||
| cons g gs =>
|
||||
simp only [List.getElem?_cons_zero]
|
||||
exact lt_of_le_of_lt (WithTop.coe_le_coe.mpr (hHge x hx)) (hH_lt_G g (by rw [hG]; exact List.mem_cons_self))
|
||||
exact lt_of_le_of_lt (WithTop.coe_le_coe.mpr (hHge x hx)) (hH_lt_G g (by rw [hG]; exact
|
||||
List.mem_cons_self))
|
||||
have hG_not_lt_res : ∀ y ∈ G, ¬ ((y : Key) : WithTop Key) < resolve db_a r.end_ := by
|
||||
intro y hy
|
||||
rw [hresEnd]
|
||||
|
||||
@@ -29,7 +29,6 @@ the range must start at `E`.
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 3200000
|
||||
|
||||
/-- The first optional entry of a nonempty list is its head. -/
|
||||
theorem getElem?_zero_eq_head {l : List Key} (hne : l ≠ []) :
|
||||
@@ -572,7 +571,8 @@ theorem necessary_gap_of_sentinel_large_A {r : RangeRead} {res : Result}
|
||||
have hanchorEnd : (r.end_.anchor db_a).toNat = e := by
|
||||
have hanc : r.end_.anchor db_a = r.end_.offset - 1 := by
|
||||
unfold Selector.anchor
|
||||
rw [show List.countP (fun (k : Key) => decide ((↑k : WithTop Key) < r.end_.key)) db_a.keys = 0 from by
|
||||
rw [show List.countP (fun (k : Key) => decide ((↑k : WithTop Key) < r.end_.key)) db_a.keys =
|
||||
0 from by
|
||||
rw [← hE]; exact hcnt0]
|
||||
ring
|
||||
rw [hanc]
|
||||
@@ -659,7 +659,8 @@ theorem necessary_gap_of_sentinel_large_A {r : RangeRead} {res : Result}
|
||||
have hancEnd_b : (r.end_.anchor db_b).toNat = e := by
|
||||
have hanc : r.end_.anchor db_b = r.end_.offset - 1 := by
|
||||
unfold Selector.anchor
|
||||
rw [show List.countP (fun (k : Key) => decide ((↑k : WithTop Key) < r.end_.key)) db_b.keys = 0 from by
|
||||
rw [show List.countP (fun (k : Key) => decide ((↑k : WithTop Key) < r.end_.key)) db_b.keys =
|
||||
0 from by
|
||||
rw [← hE]; exact hb_cnt0]
|
||||
ring
|
||||
rw [hanc]
|
||||
@@ -712,7 +713,7 @@ the witness key above the head enters the complete window, breaking the reported
|
||||
prefix. -/
|
||||
theorem necessary_gap_of_sentinel_large_B {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hbeg : r.begin.offset < 0) (hne : res.keys ≠ [])
|
||||
(_hbeg : r.begin.offset < 0) (hne : res.keys ≠ [])
|
||||
(hbtop : r.begin.key = (⊤ : WithTop Key))
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(hEL : r.end_.key < ((res.keys.getLast hne : Key) : WithTop Key))
|
||||
@@ -1076,7 +1077,7 @@ theorem minimal_closedForm_of_negCross_trunc_rev_residual_top_large_sentinel
|
||||
topOfLast (res.keys.getLast hne) := by
|
||||
unfold closedFormNegCrossTruncRevResidualTopLargeSentinel topOfLast
|
||||
dsimp only
|
||||
rw [if_pos htight]
|
||||
rw [ite_eq_left htight]
|
||||
simp [List.getLast?_eq_some_getLast hne]
|
||||
rw [hcf]
|
||||
exact hmin
|
||||
@@ -1127,7 +1128,7 @@ theorem minimal_closedForm_of_negCross_trunc_rev_residual_top_large_sentinel
|
||||
⟨r.end_.key, ⊤⟩ := by
|
||||
unfold closedFormNegCrossTruncRevResidualTopLargeSentinel
|
||||
dsimp only
|
||||
rw [if_neg htight]
|
||||
rw [ite_eq_right htight]
|
||||
rw [hcf]
|
||||
exact hmin
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ reported last on both databases, so `completeKeys_filter_ge_eq_resolve_end` fini
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1600000
|
||||
|
||||
/-- The large-gap crossed top subcell of the reversed truncated residual. -/
|
||||
abbrev negCrossTruncRevResidualTopLarge (r : RangeRead) (res : Result) : Prop :=
|
||||
@@ -298,7 +297,8 @@ theorem necessary_above_head_of_residual_top_large {r : RangeRead} {res : Result
|
||||
res.keys.countP (fun x => decide (((x : Key) : WithTop Key) < r.begin.key)) :=
|
||||
List.countP_reverse
|
||||
rw [h1]
|
||||
have h2 : ([k].countP (fun x => decide (((x : Key) : WithTop Key) < r.begin.key))) ≤ 1 := by
|
||||
have h2 : ([k].countP (fun x => decide (((x : Key) : WithTop Key) < r.begin.key))) ≤ 1
|
||||
:= by
|
||||
rw [List.countP_singleton]
|
||||
split <;> omega
|
||||
omega
|
||||
@@ -628,11 +628,13 @@ theorem necessary_gap_of_residual_top_large_finite {r : RangeRead} {res : Result
|
||||
rw [hGnil, hRself, hQself]
|
||||
simp
|
||||
rw [hfiltL, List.filter_append, hre]
|
||||
have hRself : List.filter (fun y : Key => decide ((y : WithTop Key) < ((Q : Key) : WithTop Key))) R = R := by
|
||||
have hRself : List.filter (fun y : Key => decide ((y : WithTop Key) < ((Q : Key) : WithTop
|
||||
Key))) R = R := by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
exact decide_eq_true (WithTop.coe_lt_coe.mpr (lt_of_le_of_lt (hRleH x hx) hHQ))
|
||||
have hQnil : List.filter (fun y : Key => decide ((y : WithTop Key) < ((Q : Key) : WithTop Key))) [Q] = [] := by
|
||||
have hQnil : List.filter (fun y : Key => decide ((y : WithTop Key) < ((Q : Key) : WithTop
|
||||
Key))) [Q] = [] := by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro x hx hlt
|
||||
rw [List.mem_singleton] at hx
|
||||
|
||||
@@ -29,7 +29,6 @@ the front of the (reversed) complete keys, so the reported keys are no longer a
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -118,7 +117,8 @@ theorem between_add_offset_le_one {r : RangeRead} {res : Result} {db : DB}
|
||||
rw [cnt_coe]
|
||||
exact countP_lt_eq_of_getElem db.sorted hjlt hjeq
|
||||
have hLleBegin : ((L : Key) : WithTop Key) ≤ r.begin.key := le_of_lt hcross
|
||||
have hcnt_begin : cnt db r.begin.key = j + (between db ((L : Key) : WithTop Key) r.begin.key).length := by
|
||||
have hcnt_begin : cnt db r.begin.key = j + (between db ((L : Key) : WithTop Key)
|
||||
r.begin.key).length := by
|
||||
rw [cnt_eq_add_between db hLleBegin, hcntL]
|
||||
have hanchor : r.begin.anchor db = (j : Int) +
|
||||
((between db ((L : Key) : WithTop Key) r.begin.key).length : Int) +
|
||||
|
||||
@@ -96,7 +96,7 @@ theorem compat_of_pad_top {r : RangeRead} {res : Result} {F : List Key} {m : ℕ
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (F.head hFne) := by
|
||||
change (res.keys ++ F)[res.keys.length]? = some (F.head hFne)
|
||||
rw [List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchorE]; omega)]
|
||||
@@ -217,7 +217,7 @@ theorem exists_witness_below_head_of_negCross_trunc_strict_top {r : RangeRead} {
|
||||
have hD'get? : (dbw.insert k hkdb).keys[res.keys.length + 1]? = some (F.head hFne) := by
|
||||
rw [hins_keys, List.getElem?_cons_succ]
|
||||
rw [List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre' : resolve (dbw.insert k hkdb) r.end_ =
|
||||
((F.head hFne : Key) : WithTop Key) := by
|
||||
@@ -396,7 +396,7 @@ theorem exists_witness_above_begin_of_negCross_trunc_strict_top {r : RangeRead}
|
||||
have hD'get? : (dbw.erase k).keys[res.keys.length - 1]? =
|
||||
some (res.keys.getLast hne) := by
|
||||
rw [hD', List.getElem?_append]
|
||||
rw [if_pos (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [ite_eq_left (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [List.getElem?_eq_getElem (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
congr 1
|
||||
rw [List.getLast_eq_getElem hne]
|
||||
@@ -511,7 +511,7 @@ theorem minimal_fullRange_of_negCross_trunc_strict_top {r : RangeRead} {res : Re
|
||||
rw [toggle_eq_erase_of_mem hkdb]; exact hnot⟩
|
||||
|
||||
/-- The compact closed form for the sentinel-end strict cell. -/
|
||||
noncomputable def closedFormNegCrossTruncStrictTop (r : RangeRead) (_res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncStrictTop (_r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), (⊤ : WithTop Key)⟩
|
||||
|
||||
|
||||
@@ -98,7 +98,7 @@ theorem endPad_cast (h : negCrossTruncTopTop r res) :
|
||||
|
||||
/-- The empty window never reports a truncated nonempty prefix. -/
|
||||
theorem not_compatible_of_resolve_end_nil {db : DB} {r : RangeRead} {res : Result}
|
||||
(hrev : r.reverse = false) (hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(_hrev : r.reverse = false) (_hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hE : resolve db r.end_ = (([] : Key) : WithTop Key)) :
|
||||
¬ RangeRead.Compatible db r res := by
|
||||
intro hc
|
||||
@@ -107,7 +107,7 @@ theorem not_compatible_of_resolve_end_nil {db : DB} {r : RangeRead} {res : Resul
|
||||
obtain ⟨a, ha⟩ : ∃ a, a ∈ RangeRead.completeKeys db r := by
|
||||
cases hW : RangeRead.completeKeys db r with
|
||||
| nil => exact absurd hW hneW
|
||||
| cons a t => exact ⟨a, by simp [hW]⟩
|
||||
| cons a t => exact ⟨a, by simp []⟩
|
||||
have hlt := (RangeRead.mem_completeKeys.mp ha).2.2
|
||||
rw [hE, WithTop.coe_lt_coe] at hlt
|
||||
exact absurd hlt (List.not_lt_nil a)
|
||||
@@ -175,7 +175,7 @@ theorem completeKeys_eq_drop_take {db : DB} {r : RangeRead}
|
||||
rw [hlen]
|
||||
omega
|
||||
rw [RangeRead.completeKeys, ite_eq_right (by simp [hrev])]
|
||||
show l.filter (fun k : Key => decide (resolve db r.begin ≤ (↑k : WithTop Key) ∧
|
||||
change l.filter (fun k : Key => decide (resolve db r.begin ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < resolve db r.end_)) = _
|
||||
have hsplit : l.filter (fun k : Key => decide (resolve db r.begin ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < resolve db r.end_)) =
|
||||
@@ -209,7 +209,7 @@ theorem completeKeys_eq_take_of_size_beginSlack {db : DB} {r : RangeRead} {res :
|
||||
have hanE0 : 0 ≤ r.end_.anchor db := by rw [hanE]; omega
|
||||
have hanE_toNat : (r.end_.anchor db).toNat = q - p := by
|
||||
rw [hanE]
|
||||
rw [show (q : ℤ) - (p : ℤ) = ((q - p : ℕ) : ℤ) by push_cast; omega]
|
||||
rw [show (q : ℤ) - (p : ℤ) = ((q - p : ℕ) : ℤ) by omega]
|
||||
exact Int.toNat_natCast _
|
||||
have hanE_lt : (r.end_.anchor db).toNat < db.keys.length := by
|
||||
rw [hanE_toNat, hN, hq]; omega
|
||||
@@ -245,7 +245,7 @@ theorem completeKeys_length_le_topTop {db : DB} {r : RangeRead}
|
||||
(by rw [← hp, ← hN]; exact hpN) (by rw [← hq, ← hN]; exact hqN)
|
||||
rw [hdt, List.length_take, List.length_drop]
|
||||
omega
|
||||
· push_neg at hqN
|
||||
· push Not at hqN
|
||||
-- `N ≤ q`: the begin clamps to the bottom
|
||||
have hanB : r.begin.anchor db < 0 := by
|
||||
rw [anchor_begin_top hBtop hbo]
|
||||
@@ -258,7 +258,8 @@ theorem completeKeys_length_le_topTop {db : DB} {r : RangeRead}
|
||||
rw [show RangeRead.inRange db.keys (resolve db r.begin) (resolve db r.end_) =
|
||||
db.keys.filter (fun k : Key => decide (resolve db r.begin ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < resolve db r.end_)) from rfl, hresB]
|
||||
rw [show db.keys.filter (fun k : Key => decide (((↑([] : Key)) : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
rw [show db.keys.filter (fun k : Key => decide (((↑([] : Key)) : WithTop Key) ≤ (↑k :
|
||||
WithTop Key) ∧
|
||||
(↑k : WithTop Key) < resolve db r.end_)) =
|
||||
db.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < resolve db r.end_)) from by
|
||||
apply List.filter_congr
|
||||
@@ -269,7 +270,7 @@ theorem completeKeys_length_le_topTop {db : DB} {r : RangeRead}
|
||||
rw [← List.countP_eq_length_filter]
|
||||
rw [hlen, countP_lt_resolve, anchor_end_top hEtop hend, ← hN, ← hp]
|
||||
omega
|
||||
· push_neg at hpN
|
||||
· push Not at hpN
|
||||
-- `p > N`: the end resolves below the bottom, so the window is empty
|
||||
have hanE : r.end_.anchor db < 0 := by
|
||||
rw [anchor_end_top hEtop hend]
|
||||
@@ -304,8 +305,8 @@ theorem completeKeys_eq_nil_of_anchor_end_neg {db : DB} {r : RangeRead}
|
||||
exact not_lt.mpr (WithTop.coe_le_coe.mpr (nil_le_key k))
|
||||
rw [RangeRead.completeKeys]
|
||||
by_cases hrev : r.reverse = true
|
||||
· rw [if_pos hrev]; exact List.reverse_eq_nil_iff.mpr hempty
|
||||
· rw [if_neg hrev]; exact hempty
|
||||
· rw [ite_eq_left hrev]; exact List.reverse_eq_nil_iff.mpr hempty
|
||||
· rw [ite_eq_right hrev]; exact hempty
|
||||
|
||||
/-- Readability forces the both-sentinel counts to fit: `t + p ≤ q + 1`. -/
|
||||
theorem readable_counts_topTop (h : negCrossTruncTopTop r res) (hread : Readable r res) :
|
||||
@@ -391,7 +392,7 @@ theorem exists_filter_head_decomp_of_compatible {db : DB} (h : negCrossTruncTopT
|
||||
· have hb : ¬ (resolve db r.begin ≤ ((k : Key) : WithTop Key)) := by
|
||||
intro hb
|
||||
have hkck : k ∈ RangeRead.completeKeys db r := by
|
||||
rw [RangeRead.completeKeys, if_neg (by simp [h.2.1])]
|
||||
rw [RangeRead.completeKeys, ite_eq_right (by simp [h.2.1])]
|
||||
rw [show RangeRead.inRange db.keys (resolve db r.begin) (resolve db r.end_) =
|
||||
db.keys.filter (fun x : Key => decide (resolve db r.begin ≤ (↑x : WithTop Key) ∧
|
||||
(↑x : WithTop Key) < resolve db r.end_)) from rfl, List.mem_filter]
|
||||
@@ -402,7 +403,7 @@ theorem exists_filter_head_decomp_of_compatible {db : DB} (h : negCrossTruncTopT
|
||||
have hR : db.keys.filter (fun k : Key => decide
|
||||
(resolve db r.begin ≤ (↑k : WithTop Key)) &&
|
||||
decide ((↑k : WithTop Key) < resolve db r.end_)) = res.keys := by
|
||||
rw [hckeq, RangeRead.completeKeys, if_neg (by simp [h.2.1]), RangeRead.inRange]
|
||||
rw [hckeq, RangeRead.completeKeys, ite_eq_right (by simp [h.2.1]), RangeRead.inRange]
|
||||
simp only [Bool.decide_and]
|
||||
exact hcongr.trans hR
|
||||
have hFD : (db.keys.drop (N - p)).filter (fun k : Key => decide
|
||||
@@ -563,7 +564,7 @@ theorem exists_witness_above_last_branchH {r : RangeRead} {res : Result} {k : Ke
|
||||
rw [hdbw_keys]; exact List.mem_append.mpr (Or.inr hGmem)
|
||||
have hk_not_res : k ∉ res.keys := fun hx => absurd (hle_last k hx) (not_le.mpr hkgt)
|
||||
have hkeys' : (dbw.erase k).keys = res.keys ++ G.erase k := by
|
||||
rw [DB.erase_keys, hdbw_keys, List.erase_append, if_neg hk_not_res]
|
||||
rw [DB.erase_keys, hdbw_keys, List.erase_append, ite_eq_right hk_not_res]
|
||||
have hN' : (dbw.erase k).keys.length = t + p - 1 := by
|
||||
rw [hkeys', List.length_append, List.length_erase_of_mem hGmem, hGlen, ← ht]
|
||||
omega
|
||||
@@ -571,7 +572,6 @@ theorem exists_witness_above_last_branchH {r : RangeRead} {res : Result} {k : Ke
|
||||
rw [hN', hq]
|
||||
have hanB' : r.begin.anchor (dbw.erase k) < 0 := by
|
||||
rw [anchor_begin_eq h (dbw.erase k), hNq']
|
||||
push_cast
|
||||
omega
|
||||
have hrb' : resolve (dbw.erase k) r.begin = ((↑([] : Key)) : WithTop Key) :=
|
||||
resolve_eq_nil hanB'
|
||||
@@ -592,7 +592,7 @@ theorem exists_witness_above_last_branchH {r : RangeRead} {res : Result} {k : Ke
|
||||
have hlen : t - 1 < res.keys.length := by rw [← ht]; omega
|
||||
rw [List.getElem?_eq_getElem hlen, hlast, List.getLast_eq_getElem hne]
|
||||
rw [resolve, ite_eq_right (not_lt.mpr h0), hkeys', List.getElem?_append,
|
||||
if_pos (by rw [hidx, ← ht]; omega), hidx, hlastIdx]
|
||||
ite_eq_left (by rw [hidx, ← ht]; omega), hidx, hlastIdx]
|
||||
have hckE : RangeRead.completeKeys (dbw.erase k) r = res.keys.dropLast := by
|
||||
rw [completeKeys_eq_of_resolve_nil_coe (db := dbw.erase k) (w := last) hrev
|
||||
h.2.2.2.2.2.2 hrb' hre', hkeys', List.filter_append]
|
||||
@@ -655,7 +655,7 @@ theorem minimal_top_head_of_branchH {r : RangeRead} {res : Result}
|
||||
by_cases hklast : ((k : Key) : WithTop Key) ≤ ((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_of_between_result hread (List.head_mem hne) (List.getLast_mem hne)
|
||||
(WithTop.coe_le_coe.mp hklo) (WithTop.coe_le_coe.mp hklast)
|
||||
· push_neg at hklast
|
||||
· push Not at hklast
|
||||
exact necessary_above_last_branchH hread h hH (WithTop.coe_lt_coe.mp hklast)
|
||||
|
||||
/-- Inserting a key above every element of the first list distributes over append. -/
|
||||
@@ -666,7 +666,7 @@ theorem orderedInsert_append_of_forall_lt {l₁ l₂ : List Key} {k : Key}
|
||||
| nil => rfl
|
||||
| cons a t ih =>
|
||||
rw [List.cons_append, List.orderedInsert_cons,
|
||||
if_neg (not_le.mpr (h a (List.mem_cons_self ..))),
|
||||
ite_eq_right (not_le.mpr (h a (List.mem_cons_self ..))),
|
||||
ih (fun x hx => h x (List.mem_cons_of_mem a hx))]
|
||||
exact (List.cons_append).symm
|
||||
|
||||
@@ -966,7 +966,7 @@ def negCrossTruncTopTopEq (r : RangeRead) (res : Result) : Prop :=
|
||||
|
||||
/-- The closed form of the equality branch: the reported keys are the complete window, so
|
||||
the minimal range is `[head, ⊤)`. -/
|
||||
noncomputable def closedFormNegCrossTruncTopTopEq (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncTopTopEq (_r : RangeRead) (res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((res.keys.headD ([] : Key) : Key) : WithTop Key), (⊤ : WithTop Key)⟩
|
||||
|
||||
@@ -1009,7 +1009,7 @@ def negCrossTruncTopTopStrict (r : RangeRead) (res : Result) : Prop :=
|
||||
res.keys.length + (1 - r.end_.offset).toNat < beginSlack r + 1
|
||||
|
||||
/-- The closed form of the strict branch: the full range `[⊥, ⊤)`. -/
|
||||
noncomputable def closedFormNegCrossTruncTopTopStrict (r : RangeRead) (_res : Result) :
|
||||
noncomputable def closedFormNegCrossTruncTopTopStrict (_r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨(([] : Key) : WithTop Key), (⊤ : WithTop Key)⟩
|
||||
|
||||
@@ -1028,11 +1028,11 @@ theorem minimal_closedForm_of_negCross_trunc_topTop {r : RangeRead} {res : Resul
|
||||
(hread : Readable r res) (h : negCrossTruncTopTop r res) :
|
||||
Minimal r res (closedFormNegCrossTruncTopTop r res) := by
|
||||
by_cases hH : res.keys.length + (1 - r.end_.offset).toNat = beginSlack r + 1
|
||||
· rw [closedFormNegCrossTruncTopTop, if_pos hH]
|
||||
· rw [closedFormNegCrossTruncTopTop, ite_eq_left hH]
|
||||
exact minimal_closedForm_of_negCross_trunc_topTop_eq hread ⟨h, hH⟩
|
||||
· have hle := NegCrossTruncTopTop.readable_counts_topTop h hread
|
||||
have hF : res.keys.length + (1 - r.end_.offset).toNat < beginSlack r + 1 := by omega
|
||||
rw [closedFormNegCrossTruncTopTop, if_neg hH]
|
||||
rw [closedFormNegCrossTruncTopTop, ite_eq_right hH]
|
||||
exact NegCrossTruncTopTop.minimal_full_of_branchF hread h hF
|
||||
|
||||
end FormalConflictRange
|
||||
@@ -27,7 +27,6 @@ last then keeps that sentinel and adds the key to the complete window.
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
@@ -133,7 +132,7 @@ theorem completeKeys_filter_ge_eq_db_filter {db : DB} {r : RangeRead} {res : Res
|
||||
{last : Key} (hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hlast : last = res.keys.getLast hne)
|
||||
(hbegin : r.begin.offset ≤ 0) (hstart : resolve db r.begin ≤ r.end_.key) :
|
||||
(_hbegin : r.begin.offset ≤ 0) (hstart : resolve db r.begin ≤ r.end_.key) :
|
||||
(RangeRead.completeKeys db r).filter
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
(db.keys.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key)))).filter
|
||||
@@ -305,7 +304,6 @@ theorem completeKeys_eq_res_of_agree_nonpos_complete {db₁ db₂ : DB} {r : Ran
|
||||
k ≤ last)) := by
|
||||
unfold RangeRead.completeKeys RangeRead.inRange
|
||||
rw [hrev]
|
||||
simp only [if_false]
|
||||
rw [hbegineq]
|
||||
apply List.filter_congr
|
||||
intro k hk
|
||||
@@ -377,8 +375,8 @@ nonpositive read with `end.offset ≥ 2`, if the end selector resolves to a genu
|
||||
then the number of reported keys at or above `end_.key` is exactly `end.offset - 1`. -/
|
||||
theorem residualT_eq_residualE_of_resolve_end_ne_top {db : DB} {r : RangeRead}
|
||||
{res : Result} (hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = false) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset ≤ 0) (hstart : resolve db r.begin ≤ r.end_.key)
|
||||
(hmore : res.more = false) (_hne : res.keys ≠ [])
|
||||
(_hbegin : r.begin.offset ≤ 0) (hstart : resolve db r.begin ≤ r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(htop : resolve db r.end_ ≠ (⊤ : WithTop Key)) :
|
||||
residualT r res = residualE r := by
|
||||
@@ -590,7 +588,6 @@ theorem necessary_above_last_of_nonpos_top {r : RangeRead} {res : Result}
|
||||
omega
|
||||
have htlt' : Q.length < (r.end_.offset - 1).toNat := by
|
||||
rw [← hTQ]; exact htlt
|
||||
unfold residualE at htlt'
|
||||
rw [hQlen] at htlt'
|
||||
omega
|
||||
have hEins := resolve_end_eq_top_of_insert_top hx0 hL_lt hend
|
||||
@@ -643,20 +640,20 @@ theorem minimal_completeNonposCrossFree {r : RangeRead} {res : Result}
|
||||
(hlo : r.begin.key ≤ ((res.keys.head hne : Key) : WithTop Key)) :
|
||||
Minimal r res (completeNonposCrossFree r res) := by
|
||||
unfold completeNonposCrossFree
|
||||
rw [if_neg hne]
|
||||
rw [ite_eq_right hne]
|
||||
by_cases hend1 : r.end_.offset ≤ 1
|
||||
· rw [if_pos hend1]
|
||||
· rw [ite_eq_left hend1]
|
||||
exact minimal_bottomRange_of_nonpos_underEnd_nonempty hread hrev hmore hne hbegin hend1 hlo
|
||||
· rw [if_neg hend1]
|
||||
· rw [ite_eq_right hend1]
|
||||
have hend : 2 ≤ r.end_.offset := by omega
|
||||
by_cases hte : residualT r res = residualE r
|
||||
· rw [if_pos hte]
|
||||
· rw [ite_eq_left hte]
|
||||
have hlast : res.keys.getLastD ([] : Key) = res.keys.getLast hne := by
|
||||
rw [List.getLastD_eq_getLast?, List.getLast?_eq_some_getLast hne]; rfl
|
||||
rw [hlast]
|
||||
exact minimal_truncatedRangeBottom_of_nonpos_complete_finite hread hrev hmore hne hbegin
|
||||
hlo hend hte
|
||||
· rw [if_neg hte]
|
||||
· rw [ite_eq_right hte]
|
||||
obtain ⟨db₀, hcomp₀⟩ := hread
|
||||
have hstart₀ : resolve db₀ r.begin ≤ r.end_.key := by
|
||||
rw [resolve_eq_nil_of_complete_begin_le_head hcomp₀ hrev hmore hne hbegin hlo]
|
||||
@@ -713,7 +710,7 @@ theorem minimal_closedForm_of_complete_nonpos_crossFree {r : RangeRead} {res : R
|
||||
unfold closedFormCompleteNonposCrossFree
|
||||
cases hrev : r.reverse with
|
||||
| false =>
|
||||
rw [ite_eq_right (by simp [hrev])]
|
||||
rw [ite_eq_right (by simp [])]
|
||||
have hlo : r.begin.key ≤ ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
have hloD' : r.begin.key ≤
|
||||
((res.keys.headD ([] : Key) : Key) : WithTop Key) := by
|
||||
@@ -723,7 +720,7 @@ theorem minimal_closedForm_of_complete_nonpos_crossFree {r : RangeRead} {res : R
|
||||
rwa [← hhead]
|
||||
exact minimal_completeNonposCrossFree hread hrev hmore hne hbegin hlo
|
||||
| true =>
|
||||
rw [ite_eq_left (by simp [hrev])]
|
||||
rw [ite_eq_left (by simp [])]
|
||||
have hlo : r.begin.key ≤ ((res.keys.getLast hne : Key) : WithTop Key) := by
|
||||
have hloD' : r.begin.key ≤
|
||||
((res.keys.getLastD ([] : Key) : Key) : WithTop Key) := by
|
||||
@@ -903,7 +900,7 @@ abbrev nonposFwdTrunc (r : RangeRead) (res : Result) : Prop :=
|
||||
1 ≤ r.end_.offset
|
||||
|
||||
/-- The cross-free nonpositive-begin forward truncated closed form. -/
|
||||
noncomputable def closedFormNonposFwdTrunc (r : RangeRead) (res : Result) : ConflictRange :=
|
||||
noncomputable def closedFormNonposFwdTrunc (_r : RangeRead) (res : Result) : ConflictRange :=
|
||||
truncatedRangeBottom (res.keys.getLastD ([] : Key))
|
||||
|
||||
/-- **The cross-free nonpositive-begin forward truncated closed form is minimal.** -/
|
||||
@@ -927,7 +924,6 @@ theorem minimal_closedForm_of_nonpos_fwdTrunc {r : RangeRead} {res : Result}
|
||||
exact minimal_truncatedRangeBottom_of_nonpos_more hread' hrev hmore hne hbegin hlo hge
|
||||
|
||||
|
||||
set_option maxHeartbeats 2400000
|
||||
|
||||
/-- Splitting a count below `b` at a threshold `a < b`. -/
|
||||
theorem countP_lt_split {l : List Key} {a b : WithTop Key} (hab : a < b) :
|
||||
@@ -955,9 +951,9 @@ theorem countP_lt_split {l : List Key} {a b : WithTop Key} (hab : a < b) :
|
||||
there are at least `(1 - end_.offset)` stored keys strictly between the reported last
|
||||
and `end_.key`. -/
|
||||
theorem filler_count_nonpos_more_nonpos_end {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset ≤ 0) (hend : r.end_.offset ≤ 0) :
|
||||
(hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
|
||||
(_hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(_hbegin : r.begin.offset ≤ 0) (hend : r.end_.offset ≤ 0) :
|
||||
(1 - r.end_.offset).toNat ≤
|
||||
(db.keys.filter (fun (k : Key) => decide (res.keys.getLast hne < k ∧
|
||||
((k : WithTop Key) < r.end_.key)))).length := by
|
||||
@@ -1212,7 +1208,7 @@ theorem exists_witness_nonpos_more_nonpos_end {db : DB} {r : RangeRead} {res : R
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (F.head hFne) := by
|
||||
change D[res.keys.length]? = some (F.head hFne)
|
||||
rw [hD, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor_end]; omega)]
|
||||
@@ -1304,7 +1300,7 @@ theorem exists_witness_nonpos_more_nonpos_end {db : DB} {r : RangeRead} {res : R
|
||||
rw [hanchor_end', hEqInt, Int.toNat_natCast]
|
||||
have hD'get? : (dbw.erase k).keys[res.keys.length - 1]? = some last := by
|
||||
rw [hD', List.getElem?_append]
|
||||
rw [if_pos (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [ite_eq_left (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [List.getElem?_eq_getElem (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
congr 1
|
||||
rw [hlast, List.getLast_eq_getElem hne]
|
||||
@@ -1413,7 +1409,7 @@ abbrev nonposFwdTruncNonpos (r : RangeRead) (res : Result) : Prop :=
|
||||
r.end_.offset ≤ 0
|
||||
|
||||
/-- The cross-free nonpositive-begin forward truncated nonpositive-end closed form. -/
|
||||
noncomputable def closedFormNonposFwdTruncNonpos (r : RangeRead) (res : Result) :
|
||||
noncomputable def closedFormNonposFwdTruncNonpos (r : RangeRead) (_res : Result) :
|
||||
ConflictRange :=
|
||||
⟨((↑([] : Key) : WithTop Key)), r.end_.key⟩
|
||||
|
||||
|
||||
@@ -23,7 +23,6 @@ and minimality transfer because the two reads have the same compatible databases
|
||||
|
||||
open FormalConflictRange
|
||||
|
||||
set_option maxHeartbeats 1200000
|
||||
|
||||
namespace FormalConflictRange
|
||||
|
||||
|
||||
@@ -600,7 +600,8 @@ private theorem residual_between_begin_head {db₀ : DB} {r : RangeRead} {res :
|
||||
omega
|
||||
|
||||
|
||||
private theorem residual_topWitness_of_D {db₀ : DB} {r : RangeRead} {res : Result} {g n : ℕ} {H : Key}
|
||||
private theorem residual_topWitness_of_D {db₀ : DB} {r : RangeRead} {res : Result} {g n : ℕ} {H :
|
||||
Key}
|
||||
(hcomp : RangeRead.Compatible db₀ r res) (hmore : res.more = false)
|
||||
(hrev : r.reverse = false) (hne : res.keys ≠ [])
|
||||
(hbegin : 1 ≤ r.begin.offset) (hend : 2 ≤ r.end_.offset)
|
||||
|
||||
@@ -138,7 +138,8 @@ theorem compactCompleteForward_eq_crossFree {r : RangeRead} {res : Result}
|
||||
dsimp only
|
||||
rw [ite_eq_right ht']
|
||||
by_cases hbelow : ∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key
|
||||
· simp [closedFormCompleteCrossFree, topRange, hend, hcross, ht, hoff]
|
||||
· simp only [hend, ↓reduceIte, hcross, ht, List.getLastD_eq_getLast?,
|
||||
closedFormCompleteCrossFree, false_or, hoff, topRange]
|
||||
rw [ite_eq_left hbelow, ite_eq_left hbelow]
|
||||
· simpa [closedFormCompleteCrossFree, truncatedRange, topRange, hend, hcross, ht,
|
||||
hbelow] using htail.symm
|
||||
@@ -779,7 +780,7 @@ theorem compactForwardTruncatedNonpos_minimal_bottom {r : RangeRead} {res : Resu
|
||||
exact absurd hhead_res (not_lt.mpr (coe_nil_le_key_withTop _))
|
||||
have hcb : clampNonposBottom r res :=
|
||||
clampNonposBottom_of_le_resolve_end hend hRne hB_le_R hclamp
|
||||
rw [ite_eq_left hend, if_neg (not_lt_of_ge hBE), ite_eq_left hcb]
|
||||
rw [ite_eq_left hend, ite_eq_right (not_lt_of_ge hBE), ite_eq_left hcb]
|
||||
exact minimal_closedForm_of_nonpos_fwdTruncNonpos hread'
|
||||
⟨hmore, hrev, hbegin, hloD, hend⟩
|
||||
· have hendpos : 1 ≤ r.end_.offset := by omega
|
||||
@@ -1254,7 +1255,7 @@ theorem compactForwardTruncatedNonpos_minimal_of_not_residual {r : RangeRead} {r
|
||||
ite_eq_left hend, ite_eq_right hnotlt, ite_eq_left hcb]
|
||||
have hcf : closedFormNegCrossTruncTopTop r res =
|
||||
⟨(([] : Key) : WithTop Key), (⊤ : WithTop Key)⟩ := by
|
||||
rw [closedFormNegCrossTruncTopTop, if_neg hnotH]
|
||||
rw [closedFormNegCrossTruncTopTop, ite_eq_right hnotH]
|
||||
rw [hEq, NegCrossTruncTopTop.hEtop hT, ← hcf]
|
||||
exact minimal_closedForm_of_negCross_trunc_topTop hread hT
|
||||
· by_cases hS : r.end_.key = (⊤ : WithTop Key) ∧
|
||||
@@ -1981,7 +1982,7 @@ theorem closedFormZeroCrossResidual_eq_under {r : RangeRead} {res : Result}
|
||||
/-- In the long cells the shared form is the certified long rule. -/
|
||||
theorem closedFormZeroCrossResidual_eq_long {r : RangeRead} {res : Result}
|
||||
(hnot : ¬ zeroCrossUnderEnd r res)
|
||||
(h : zeroCrossLongTop r res ∨ zeroCrossLongFinite r res) :
|
||||
(_h : zeroCrossLongTop r res ∨ zeroCrossLongFinite r res) :
|
||||
closedFormZeroCrossResidual r res = closedFormZeroCrossLong r res := by
|
||||
unfold closedFormZeroCrossResidual
|
||||
rw [ite_eq_right hnot]
|
||||
@@ -2397,7 +2398,7 @@ theorem nonposCompleteForward_false {r : RangeRead} {res : Result}
|
||||
· exact h_ov ⟨h0, hmore, hrev, ⟨hend2, hne, hhi⟩, hcrossL⟩
|
||||
· have hElast : r.end_.key ≤
|
||||
((res.keys.getLastD ([] : Key) : Key) : WithTop Key) := by
|
||||
push_neg at hhi
|
||||
push Not at hhi
|
||||
obtain ⟨k, hk, hkge⟩ := hhi
|
||||
exact le_trans hkge (hlastle k hk)
|
||||
by_cases hBE : r.begin.key ≤ r.end_.key
|
||||
@@ -2439,7 +2440,7 @@ theorem nonposCompleteForward_false {r : RangeRead} {res : Result}
|
||||
· exact h_ov2 ⟨hrev, hneg, hmore, hne, hend2, hhi, hcross⟩
|
||||
· have hElast : r.end_.key ≤
|
||||
((res.keys.getLastD ([] : Key) : Key) : WithTop Key) := by
|
||||
push_neg at hhi
|
||||
push Not at hhi
|
||||
obtain ⟨k, hk, hkge⟩ := hhi
|
||||
exact le_trans hkge (hlastle k hk)
|
||||
by_cases hEH : r.end_.key < ((res.keys.headD ([] : Key) : Key) : WithTop Key)
|
||||
@@ -2765,6 +2766,7 @@ theorem negCrossTruncRevUnder_or_belowEnd_of_top {r : RangeRead} {res : Result}
|
||||
exact WithTop.coe_lt_top _
|
||||
|
||||
set_option maxHeartbeats 0 in
|
||||
-- This declaration performs an expensive finite case analysis.
|
||||
/-- **The residual dispatcher is minimal on the residual region.** The residual is
|
||||
crossed and either complete or reversed truncated, so all forward-truncated, clamped and
|
||||
cross-free branches have already been discharged by the compact certificates. -/
|
||||
@@ -2872,14 +2874,19 @@ theorem minimal_conflictRangeClosedFormResidualCompleteFwd {r : RangeRead} {res
|
||||
(fun h => h4 (Or.inl h))
|
||||
(fun h => h4 (Or.inr (Or.inl h)))
|
||||
(fun h => h4 (Or.inr (Or.inr h)))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr (Or.inl h))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr
|
||||
(Or.inl h))))))
|
||||
(fun h => h9 (Or.inr (Or.inr (Or.inr (Or.inl h)))))
|
||||
(fun h => h9 (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h))))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr
|
||||
(Or.inr (Or.inr (Or.inl h))))))))
|
||||
(fun h => h9 (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr h))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr h)))))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl h)))))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr
|
||||
(Or.inr (Or.inr (Or.inr (Or.inr h)))))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr
|
||||
(Or.inr (Or.inl h)))))))
|
||||
(fun h => h2 ((crossedCompleteEndLeOne_iff r res).mpr (Or.inr (Or.inr (Or.inr
|
||||
(Or.inr (Or.inr (Or.inr (Or.inl h)))))))))
|
||||
(fun h => h9 (Or.inl h))
|
||||
(fun h => h1 (Or.inr h))
|
||||
(fun h => by
|
||||
@@ -2931,7 +2938,8 @@ theorem minimal_conflictRangeClosedFormResidualRevTruncLeOne {r : RangeRead} {re
|
||||
unfold negCrossTruncRevResidualFiniteUnderCrossed negCrossTruncRevResidualFiniteUnder at h
|
||||
omega
|
||||
have hfunc : ¬ negCrossTruncRevResidualFiniteUnderNotCrossed r res := fun h => by
|
||||
unfold negCrossTruncRevResidualFiniteUnderNotCrossed negCrossTruncRevResidualFiniteUnder at h
|
||||
unfold negCrossTruncRevResidualFiniteUnderNotCrossed negCrossTruncRevResidualFiniteUnder
|
||||
at h
|
||||
omega
|
||||
have hfo : ¬ negCrossTruncRevResidualFiniteOver r res := fun h => by
|
||||
unfold negCrossTruncRevResidualFiniteOver at h
|
||||
@@ -3089,8 +3097,8 @@ theorem compactCrossed_minimal {r : RangeRead} {res : Result}
|
||||
|
||||
/-- The single closed form denotes the same key set as the residual dispatcher. -/
|
||||
theorem compactCrossed_toSet_eq_residual {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hbegin : r.begin.offset ≤ 0) (hempty : res.keys ≠ [])
|
||||
(hcross : ((leastReported r res : Key) : WithTop Key) < r.begin.key) :
|
||||
(_hread : Readable r res) (_hbegin : r.begin.offset ≤ 0) (_hempty : res.keys ≠ [])
|
||||
(_hcross : ((leastReported r res : Key) : WithTop Key) < r.begin.key) :
|
||||
(compactCrossed r res).toSet = (conflictRangeClosedFormResidual r res).toSet := by
|
||||
rw [compactCrossed_eq_residual r res]
|
||||
|
||||
@@ -3142,7 +3150,7 @@ noncomputable def compact (r : RangeRead) (res : Result) : ConflictRange :=
|
||||
|
||||
/-- The residual branch is literally the residual-only dispatcher. -/
|
||||
theorem compact_eq_closedFormClosed_of_residual {r : RangeRead} {res : Result}
|
||||
(h : compactResidual r res) :
|
||||
(_h : compactResidual r res) :
|
||||
compact r res = conflictRangeClosedFormClosed r res :=
|
||||
rfl
|
||||
|
||||
|
||||
+169
-132
@@ -5066,7 +5066,7 @@ theorem completeKeys_count_ge_le_end_offset {db : DB} {r : RangeRead}
|
||||
`(end_.offset - 1).toNat`, for a truncated result and any read whose end offset is
|
||||
positive. -/
|
||||
theorem reported_count_ge_le_end_offset {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hread : Readable r res) (_hmore : res.more = true) (_hne : res.keys ≠ [])
|
||||
(hend : 1 ≤ r.end_.offset) :
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) ≤
|
||||
(r.end_.offset - 1).toNat := by
|
||||
@@ -7393,8 +7393,8 @@ The end resolution is the `(end_.offset)`-th stored key at or above `end_.key`,
|
||||
window contains at most the first `(end_.offset - 1)` such keys; a higher begin
|
||||
resolution only removes more of them. -/
|
||||
theorem completeKeys_count_ge_le_general {db : DB} {r : RangeRead}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.begin.key ≤ r.end_.key) (hend : 1 ≤ r.end_.offset) :
|
||||
(hrev : r.reverse = false) (_hbegin : 1 ≤ r.begin.offset)
|
||||
(_hcross : r.begin.key ≤ r.end_.key) (hend : 1 ≤ r.end_.offset) :
|
||||
(RangeRead.completeKeys db r).countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) ≤
|
||||
(r.end_.offset - 1).toNat := by
|
||||
@@ -7562,7 +7562,8 @@ theorem completeKeys_eq_above_take_drop {db : DB} {r : RangeRead}
|
||||
db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.begin.key)) ≤
|
||||
(r.begin.offset - 1).toNat)
|
||||
(hAle : (r.end_.offset - 1).toNat ≤
|
||||
db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key))) :
|
||||
db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) <
|
||||
r.end_.key))) :
|
||||
RangeRead.completeKeys db r =
|
||||
((db.keys.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key)))).take
|
||||
(r.end_.offset - 1).toNat).drop
|
||||
@@ -7613,7 +7614,8 @@ theorem completeKeys_eq_above_take_drop {db : DB} {r : RangeRead}
|
||||
countP_drop_eq hls (resolve db r.end_) (p + b), ← hd, nat_sub_min_right]
|
||||
have hAE : l.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) = l.drop cE := by
|
||||
have h := filter_not_lt_eq_drop_countP hls r.end_.key
|
||||
rw [show l.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)) = cE from hcE.symm] at h
|
||||
rw [show l.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)) = cE from hcE.symm]
|
||||
at h
|
||||
rw [← h]
|
||||
apply List.filter_congr
|
||||
intro k _
|
||||
@@ -7810,7 +7812,7 @@ theorem minimal_truncatedRange_of_finite_general {r : RangeRead} {res : Result}
|
||||
/-- At begin offset one, the keys of the truncated range `[begin.key, keyAfter last)`
|
||||
are the stored keys at or above `begin.key` followed by those at or below `last`. -/
|
||||
theorem truncatedRange_keys_eq_filter_take {db : DB} {r : RangeRead} {last : Key}
|
||||
(hrev : r.reverse = false) (hbegin : r.begin.offset = 1)
|
||||
(_hrev : r.reverse = false) (_hbegin : r.begin.offset = 1)
|
||||
(hBlelast : r.begin.key ≤ (last : WithTop Key)) :
|
||||
(truncatedRange r last).keys db =
|
||||
(db.keys.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key)))).take
|
||||
@@ -7840,7 +7842,8 @@ theorem truncatedRange_keys_eq_filter_take {db : DB} {r : RangeRead} {last : Key
|
||||
unfold truncatedRange ConflictRange.keys
|
||||
rw [show l.filter (fun (k : Key) => decide (r.begin.key ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < ((keyAfter last : Key) : WithTop Key))) =
|
||||
l.filter (fun (k : Key) => decide ((k : WithTop Key) < ((keyAfter last : Key) : WithTop Key)) &&
|
||||
l.filter (fun (k : Key) => decide ((k : WithTop Key) < ((keyAfter last : Key) : WithTop
|
||||
Key)) &&
|
||||
decide (r.begin.key ≤ (k : WithTop Key))) from
|
||||
List.filter_congr fun k _ => by rw [Bool.decide_and, Bool.and_comm]]
|
||||
rw [← List.filter_filter, ← hAdef]
|
||||
@@ -7849,13 +7852,15 @@ theorem truncatedRange_keys_eq_filter_take {db : DB} {r : RangeRead} {last : Key
|
||||
rw [decide_eq_decide, WithTop.coe_lt_coe, lt_keyAfter_iff]
|
||||
have hK : A.countP (fun k : Key => decide (k ≤ last)) =
|
||||
l.countP (fun k : Key => decide (k ≤ last)) - p := by
|
||||
have hcongr : (fun k : Key => decide ((k : WithTop Key) < ((keyAfter last : Key) : WithTop Key))) =
|
||||
have hcongr : (fun k : Key => decide ((k : WithTop Key) < ((keyAfter last : Key) : WithTop
|
||||
Key))) =
|
||||
(fun k : Key => decide (k ≤ last)) := by
|
||||
funext k
|
||||
rw [decide_eq_decide, WithTop.coe_lt_coe, lt_keyAfter_iff]
|
||||
rw [← hcongr]
|
||||
rw [hA_eq, countP_drop_eq hls ((keyAfter last : Key) : WithTop Key) p]
|
||||
have hpK : p ≤ l.countP (fun k : Key => decide ((k : WithTop Key) < ((keyAfter last : Key) : WithTop Key))) := by
|
||||
have hpK : p ≤ l.countP (fun k : Key => decide ((k : WithTop Key) < ((keyAfter last : Key) :
|
||||
WithTop Key))) := by
|
||||
rw [hp]
|
||||
apply countP_le_countP_of_imp
|
||||
intro k _ hk
|
||||
@@ -7870,7 +7875,7 @@ theorem truncatedRange_keys_eq_filter_take {db : DB} {r : RangeRead} {last : Key
|
||||
private theorem exists_of_countP_pos {l : List Key} {p : Key → Bool}
|
||||
(h : 0 < l.countP p) : ∃ a ∈ l, p a = true := by
|
||||
by_contra hcon
|
||||
push_neg at hcon
|
||||
push Not at hcon
|
||||
have hzero : l.countP p = 0 := by
|
||||
rw [List.countP_eq_zero]
|
||||
intro a ha
|
||||
@@ -8392,7 +8397,8 @@ private theorem completeKeys_count_ge_eq_min {db : DB} {r : RangeRead}
|
||||
(RangeRead.completeKeys db r).countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
min ((r.end_.offset - 1).toNat)
|
||||
(db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key))) := by
|
||||
(db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)))
|
||||
:= by
|
||||
set l := db.keys with hl
|
||||
set A := l.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key))) with hAdef
|
||||
set p := l.countP (fun (k : Key) => decide ((k : WithTop Key) < r.begin.key)) with hp
|
||||
@@ -8478,7 +8484,7 @@ database is the sentinel `⊤`: otherwise the complete window would contain exac
|
||||
inequality defining the branch. -/
|
||||
private theorem resolve_end_eq_top_of_top_branch {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = false)
|
||||
(hrev : r.reverse = false) (hne : res.keys ≠ [])
|
||||
(hrev : r.reverse = false) (_hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset = 1) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(ht : res.keys.countP
|
||||
@@ -8504,8 +8510,8 @@ private theorem countP_lt_insert {db : DB} {x : Key} (hx : x ∉ db.keys) (E : W
|
||||
rw [DB.insert_keys, List.Perm.countP_eq _
|
||||
(List.perm_orderedInsert (· ≤ ·) x db.keys)]
|
||||
by_cases h : ((x : Key) : WithTop Key) < E
|
||||
· rw [List.countP_cons_of_pos (by simpa using h), if_pos h]
|
||||
· rw [List.countP_cons_of_neg (by simpa using h), if_neg h, Nat.add_zero]
|
||||
· rw [List.countP_cons_of_pos (by simpa using h), ite_eq_left h]
|
||||
· rw [List.countP_cons_of_neg (by simpa using h), ite_eq_right h, Nat.add_zero]
|
||||
|
||||
/-- Inserting a fresh key into a database increases its key count by one. -/
|
||||
private theorem insert_keys_length {db : DB} {x : Key} (hx : x ∉ db.keys) :
|
||||
@@ -8527,8 +8533,8 @@ theorem resolve_end_eq_top_of_insert_top {db₀ : DB} {r : RangeRead} {x : Key}
|
||||
rw [anchor_toNat_eq (s := r.end_) (by omega), countP_lt_insert hx0 r.end_.key]
|
||||
rw [insert_keys_length hx0]
|
||||
by_cases h : ((x : Key) : WithTop Key) < r.end_.key
|
||||
· rw [if_pos h]; omega
|
||||
· rw [if_neg h]; omega
|
||||
· rw [ite_eq_left h]; omega
|
||||
· rw [ite_eq_right h]; omega
|
||||
|
||||
/-- **Top-branch necessity above the reported last.** In the top branch of the
|
||||
offset-one closed form, every key at or above the last reported key is necessary.
|
||||
@@ -8678,16 +8684,16 @@ theorem minimal_closedForm_of_offset_one {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOne r res) := by
|
||||
unfold closedFormOffsetOne
|
||||
by_cases hend1 : r.end_.offset ≤ 1
|
||||
· rw [if_pos hend1]
|
||||
· rw [ite_eq_left hend1]
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_general hread hmore hne (by omega) hend1
|
||||
· rw [if_neg hend1]
|
||||
· rw [ite_eq_right hend1]
|
||||
have hend : 2 ≤ r.end_.offset := by omega
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
(r.end_.offset - 1).toNat
|
||||
· rw [if_pos ht]
|
||||
· rw [ite_eq_left ht]
|
||||
exact minimal_truncatedRange_of_finite hread hmore hne hrev hbegin hcross hend ht
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_right ht]
|
||||
obtain ⟨db₀, hcomp⟩ := hread
|
||||
have hres : res.keys = RangeRead.completeKeys db₀ r := by
|
||||
rcases hcomp.2 with ⟨hm, _, _⟩ | ⟨_, heq⟩
|
||||
@@ -8762,9 +8768,9 @@ theorem minimal_closedForm_of_offset_one_any {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOneAny r res) := by
|
||||
unfold closedFormOffsetOneAny
|
||||
by_cases h : r.reverse = true
|
||||
· rw [if_pos h]
|
||||
· rw [ite_eq_left h]
|
||||
exact minimal_closedForm_of_offset_one_rev hread hmore hne h hbegin hcross
|
||||
· rw [if_neg h]
|
||||
· rw [ite_eq_right h]
|
||||
have hf : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
exact minimal_closedForm_of_offset_one hread hmore hne hf hbegin hcross
|
||||
@@ -8779,13 +8785,13 @@ theorem minimal_closedForm_of_end_le_one {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOneAny r res) := by
|
||||
unfold closedFormOffsetOneAny
|
||||
by_cases h : r.reverse = true
|
||||
· rw [if_pos h]
|
||||
· rw [ite_eq_left h]
|
||||
unfold closedFormOffsetOneRev
|
||||
rw [if_pos hend]
|
||||
rw [ite_eq_left hend]
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_general hread hmore hne hbegin hend
|
||||
· rw [if_neg h]
|
||||
· rw [ite_eq_right h]
|
||||
unfold closedFormOffsetOne
|
||||
rw [if_pos hend]
|
||||
rw [ite_eq_left hend]
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_general hread hmore hne hbegin hend
|
||||
|
||||
/-- **The overshoot region whose reported keys lie below `end_.key`.** For a complete
|
||||
@@ -8806,15 +8812,15 @@ theorem minimal_closedForm_of_reported_below {r : RangeRead} {res : Result}
|
||||
have hepos : 0 < (r.end_.offset - 1).toNat := by omega
|
||||
unfold closedFormOffsetOneAny
|
||||
by_cases h : r.reverse = true
|
||||
· rw [if_pos h]
|
||||
· rw [ite_eq_left h]
|
||||
unfold closedFormOffsetOneRev
|
||||
rw [if_neg (by omega : ¬ r.end_.offset ≤ 1), ht0,
|
||||
if_neg (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
rw [ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ht0,
|
||||
ite_eq_right (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
exact minimal_topRange_of_end_offset_ge_two_rev_general hread hmore h hne hbegin hend hhi
|
||||
· rw [if_neg h]
|
||||
· rw [ite_eq_right h]
|
||||
unfold closedFormOffsetOne
|
||||
rw [if_neg (by omega : ¬ r.end_.offset ≤ 1), ht0,
|
||||
if_neg (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
rw [ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ht0,
|
||||
ite_eq_right (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
have hf : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
exact minimal_topRange_of_end_offset_ge_two_general hread hmore hf hne hbegin hend hhi
|
||||
@@ -8837,17 +8843,17 @@ theorem minimal_closedForm_of_complete_general {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOne r res) := by
|
||||
unfold closedFormOffsetOne
|
||||
by_cases hend1 : r.end_.offset ≤ 1
|
||||
· rw [if_pos hend1]
|
||||
· rw [ite_eq_left hend1]
|
||||
exact minimal_canonicalRange_of_end_offset_le_one_general hread hmore hne hbegin hend1
|
||||
· rw [if_neg hend1]
|
||||
· rw [ite_eq_right hend1]
|
||||
have hend : 2 ≤ r.end_.offset := by omega
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
(r.end_.offset - 1).toNat
|
||||
· rw [if_pos ht]
|
||||
· rw [ite_eq_left ht]
|
||||
exact minimal_truncatedRange_of_finite_general hread hmore hne hrev hbegin hcross
|
||||
hend ht
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_right ht]
|
||||
have hhi : ∀ k ∈ res.keys, ((k : Key) : WithTop Key) < r.end_.key := by
|
||||
rcases hcase with h | h | h
|
||||
· exact absurd h hend1
|
||||
@@ -8856,10 +8862,10 @@ theorem minimal_closedForm_of_complete_general {r : RangeRead} {res : Result}
|
||||
have h := minimal_closedForm_of_reported_below hread hmore hne hbegin hend hhi
|
||||
have h' : Minimal r res (topRange r) := by
|
||||
unfold closedFormOffsetOneAny at h
|
||||
rw [if_neg (by simp [hrev])] at h
|
||||
rw [ite_eq_right (by simp [hrev])] at h
|
||||
unfold closedFormOffsetOne at h
|
||||
rw [if_neg hend1] at h
|
||||
rw [if_neg (by
|
||||
rw [ite_eq_right hend1] at h
|
||||
rw [ite_eq_right (by
|
||||
intro hc
|
||||
exact ht (by rw [hc]))] at h
|
||||
exact h
|
||||
@@ -8880,10 +8886,10 @@ theorem minimal_closedForm_of_offset_one_truncated {r : RangeRead} {res : Result
|
||||
Minimal r res (closedFormOffsetOneTruncated r res) := by
|
||||
unfold closedFormOffsetOneTruncated
|
||||
by_cases hle : r.end_.offset ≤ 0
|
||||
· rw [if_pos hle]
|
||||
· rw [ite_eq_left hle]
|
||||
exact minimal_canonicalRange_of_truncated_end_offset_nonpos hread hmore hrev
|
||||
(by omega) hle
|
||||
· rw [if_neg hle]
|
||||
· rw [ite_eq_right hle]
|
||||
exact minimal_truncatedRange_of_offset_one_of_more hread hmore hrev hbegin hcross
|
||||
(by omega)
|
||||
|
||||
@@ -8904,9 +8910,9 @@ theorem minimal_closedForm_of_truncated_general {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormTruncatedGeneral r res) := by
|
||||
unfold closedFormTruncatedGeneral
|
||||
by_cases hle : r.end_.offset ≤ 0
|
||||
· rw [if_pos hle]
|
||||
· rw [ite_eq_left hle]
|
||||
exact minimal_canonicalRange_of_truncated_end_offset_nonpos hread hmore hrev hbegin hle
|
||||
· rw [if_neg hle]
|
||||
· rw [ite_eq_right hle]
|
||||
exact minimal_truncatedRange_of_more_general hread hmore hrev hbegin (by omega) hcross
|
||||
|
||||
/-- **A compact closed form for every result at begin offset one.** For a non-reversed
|
||||
@@ -8926,9 +8932,9 @@ theorem minimal_closedForm_of_offset_one_result {r : RangeRead} {res : Result}
|
||||
Minimal r res (closedFormOffsetOneResult r res) := by
|
||||
unfold closedFormOffsetOneResult
|
||||
by_cases hmore : res.more = true
|
||||
· rw [if_pos hmore]
|
||||
· rw [ite_eq_left hmore]
|
||||
exact minimal_closedForm_of_offset_one_truncated hread hmore hrev hbegin hcross
|
||||
· rw [if_neg hmore]
|
||||
· rw [ite_eq_right hmore]
|
||||
have hfalse : res.more = false := by
|
||||
cases hm : res.more <;> simp_all
|
||||
exact minimal_closedForm_of_offset_one hread hfalse hne hrev hbegin hcross
|
||||
@@ -8952,12 +8958,12 @@ theorem minimal_closedForm_of_offset_one_truncated_rev {r : RangeRead} {res : Re
|
||||
Minimal r res (closedFormOffsetOneTruncatedRev r res) := by
|
||||
unfold closedFormOffsetOneTruncatedRev
|
||||
rcases hcase with hle | ⟨hge, hhi⟩
|
||||
· rw [if_pos hle]
|
||||
· rw [ite_eq_left hle]
|
||||
by_cases h1 : r.end_.offset = 1
|
||||
· exact minimal_truncatedRangeRev_of_offset_one hread hmore hrev hbegin h1
|
||||
· exact minimal_truncatedRangeRev_of_end_offset_nonpos hread hmore hrev hbegin
|
||||
(by omega)
|
||||
· rw [if_neg (by omega)]
|
||||
· rw [ite_eq_right (by omega)]
|
||||
exact minimal_topOfLast_of_end_offset_ge_two_rev hread hmore hrev hbegin hge hhi
|
||||
|
||||
/-- **The earlier full reversed truncated rule at begin offset one.** Read off the
|
||||
@@ -9066,15 +9072,15 @@ theorem filter_sublist_filter_of_imp {α : Type*} {l : List α} {p q : α → Bo
|
||||
| cons a l ih =>
|
||||
rw [List.filter_cons, List.filter_cons]
|
||||
by_cases hp : p a = true
|
||||
· rw [if_pos hp]
|
||||
· rw [ite_eq_left hp]
|
||||
have hq : q a = true := h a hp
|
||||
rw [if_pos hq]
|
||||
exact ih.cons₂ a
|
||||
· rw [if_neg hp]
|
||||
rw [ite_eq_left hq]
|
||||
exact ih.cons_cons a
|
||||
· rw [ite_eq_right hp]
|
||||
by_cases hq : q a = true
|
||||
· rw [if_pos hq]
|
||||
· rw [ite_eq_left hq]
|
||||
exact ih.cons a
|
||||
· rw [if_neg hq]
|
||||
· rw [ite_eq_right hq]
|
||||
exact ih
|
||||
|
||||
/-- If `L ≤ keyAfterN n E`, then a database stores at most `n` keys in `[E, L)`. -/
|
||||
@@ -9147,13 +9153,13 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_full {r : RangeRead} {res
|
||||
(hsort.pairwise.imp le_of_lt).rel_head (List.getLast_mem hne)
|
||||
unfold closedFormOffsetOneTruncatedRevFull
|
||||
by_cases hle : r.end_.offset ≤ 1
|
||||
· rw [if_pos hle]
|
||||
· rw [ite_eq_left hle]
|
||||
by_cases h1 : r.end_.offset = 1
|
||||
· exact minimal_truncatedRangeRev_of_offset_one ⟨db₀, hcomp₀⟩ hmore hrev hbegin h1
|
||||
· exact minimal_truncatedRangeRev_of_end_offset_nonpos ⟨db₀, hcomp₀⟩ hmore hrev hbegin
|
||||
(by omega)
|
||||
· have hge : 2 ≤ r.end_.offset := by omega
|
||||
rw [if_neg hle]
|
||||
rw [ite_eq_right hle]
|
||||
have hHlt : ((res.keys.headD ([] : Key) : Key) : WithTop Key) < r.end_.key := by
|
||||
rcases hcase with h | h
|
||||
· exact absurd h hle
|
||||
@@ -9171,7 +9177,7 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_full {r : RangeRead} {res
|
||||
have hepos : 0 < (r.end_.offset - 1).toNat := by omega
|
||||
dsimp only
|
||||
rw [ht0]
|
||||
rw [if_neg (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
rw [ite_eq_right (by omega : ¬ (0 = (r.end_.offset - 1).toNat))]
|
||||
have hheadLt : ((res.keys.head hne : Key) : WithTop Key) < r.end_.key := by
|
||||
rw [← hhead]; exact hHlt
|
||||
have hLE : ((res.keys.getLastD ([] : Key) : Key) : WithTop Key) < r.end_.key := by
|
||||
@@ -9195,7 +9201,8 @@ private theorem completeKeys_count_ge_eq_min_rev {db : DB} {r : RangeRead}
|
||||
(RangeRead.completeKeys db r).countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
min ((r.end_.offset - 1).toNat)
|
||||
(db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key))) := by
|
||||
(db.keys.length - db.keys.countP (fun k : Key => decide ((k : WithTop Key) < r.end_.key)))
|
||||
:= by
|
||||
have h := completeKeys_count_ge_eq_min (db := db) (r := {r with reverse := false})
|
||||
(by simp) hbegin hcross hend
|
||||
have hck : RangeRead.completeKeys db {r with reverse := false} =
|
||||
@@ -9208,7 +9215,7 @@ private theorem completeKeys_count_ge_eq_min_rev {db : DB} {r : RangeRead}
|
||||
/-- The number of reported keys at or above `end_.key` is at most
|
||||
`(end_.offset - 1)` for a readable truncated reversed result at begin offset one. -/
|
||||
private theorem reported_count_ge_le_offset_sub_one_rev {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hread : Readable r res) (_hmore : res.more = true) (hrev : r.reverse = true)
|
||||
(hbegin : r.begin.offset = 1) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset) :
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) ≤
|
||||
@@ -9287,7 +9294,7 @@ prefix of the descending complete keys; if a complete key sat below the last rep
|
||||
key but at or above `end_.key`, the complete keys would contain strictly more keys at
|
||||
or above `end_.key` than the count bound allows. -/
|
||||
private theorem rev_truncated_no_key_between {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hmore : res.more = true)
|
||||
(hcomp : RangeRead.Compatible db r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.begin.key ≤ r.end_.key) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
@@ -9362,9 +9369,9 @@ private theorem rev_truncated_finite_keys_eq {db : DB} {r : RangeRead} {res : Re
|
||||
rw [List.headD_eq_head?, List.head?_eq_some_head hne]; rfl
|
||||
have hbase := rev_truncated_filter_between (db := db) hcomp hmore hrev hne
|
||||
unfold closedFormOffsetOneTruncatedRevFull
|
||||
rw [if_neg (by omega : ¬ r.end_.offset ≤ 1)]
|
||||
rw [ite_eq_right (by omega : ¬ r.end_.offset ≤ 1)]
|
||||
dsimp only
|
||||
rw [if_pos ht]
|
||||
rw [ite_eq_left ht]
|
||||
rw [hlast, hhead, ← hbase]
|
||||
unfold ConflictRange.keys
|
||||
apply List.filter_congr
|
||||
@@ -9391,7 +9398,7 @@ private theorem rev_truncated_finite_keys_eq {db : DB} {r : RangeRead} {res : Re
|
||||
/-- In the finite reversed-truncated branch, the candidate equality fixes the
|
||||
complete keys at or above the reported last key, hence compatibility. -/
|
||||
private theorem rev_finite_filter_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hmore : res.more = true)
|
||||
(hread : Readable r res) (_hmore : res.more = true)
|
||||
(hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.begin.key ≤ r.end_.key) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ [])
|
||||
@@ -9409,12 +9416,14 @@ private theorem rev_finite_filter_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
let H : Key := res.keys.head hne
|
||||
let E : WithTop Key := r.end_.key
|
||||
let e : Nat := (r.end_.offset - 1).toNat
|
||||
let P : Key → Bool := fun k => decide (E ≤ (k : WithTop Key) ∧ (k : WithTop Key) ≤ ((H : Key) : WithTop Key))
|
||||
let P : Key → Bool := fun k => decide (E ≤ (k : WithTop Key) ∧ (k : WithTop Key) ≤ ((H : Key) :
|
||||
WithTop Key))
|
||||
let Q : Key → Bool := fun k => decide (E ≤ (k : WithTop Key))
|
||||
let BT : Key → Bool := fun k => decide (min ((L : Key) : WithTop Key) E ≤ (k : WithTop Key) ∧ (k : WithTop Key) < ((keyAfter H : Key) : WithTop Key))
|
||||
let BT : Key → Bool := fun k => decide (min ((L : Key) : WithTop Key) E ≤ (k : WithTop Key) ∧ (k
|
||||
: WithTop Key) < ((keyAfter H : Key) : WithTop Key))
|
||||
have hT' : db.keys.filter BT = res.keys.reverse := by
|
||||
simpa only [closedFormOffsetOneTruncatedRevFull, if_neg (by omega : ¬ r.end_.offset ≤ 1),
|
||||
if_pos ht, hlast, hhead, BT, L, H, E, ConflictRange.keys] using hT
|
||||
simpa only [closedFormOffsetOneTruncatedRevFull, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1),
|
||||
ite_eq_left ht, hlast, hhead, BT, L, H, E, ConflictRange.keys] using hT
|
||||
have hresnodup : res.keys.Nodup := by
|
||||
have h := db.nodup.filter BT
|
||||
rw [hT'] at h
|
||||
@@ -9659,7 +9668,6 @@ private theorem rev_finite_filter_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
have hkres : k ∈ res.keys := List.mem_reverse.mp hkC
|
||||
have hLk : L ≤ k := (hsort.pairwise.imp le_of_lt).rel_getLast hkres
|
||||
exact absurd (WithTop.coe_le_coe.mpr hLk) (not_le.mpr hkL)
|
||||
|
||||
-- The complete keys at or above `L` are exactly the reported keys.
|
||||
have hfilter : (RangeRead.completeKeys db r).filter
|
||||
(fun k : Key => decide ((L : Key) ≤ k)) = res.keys := by
|
||||
@@ -9667,7 +9675,7 @@ private theorem rev_finite_filter_eq {db : DB} {r : RangeRead} {res : Result}
|
||||
(k : WithTop Key) < resolve db r.end_)
|
||||
have hW : RangeRead.completeKeys db r = (db.keys.filter W).reverse := by
|
||||
unfold RangeRead.completeKeys RangeRead.inRange
|
||||
rw [if_pos hrev]
|
||||
rw [ite_eq_left hrev]
|
||||
have hstep : (db.keys.filter W).filter (fun k : Key => decide ((L : Key) ≤ k)) =
|
||||
res.keys.reverse := by
|
||||
rw [List.filter_filter, ← hT']
|
||||
@@ -9733,8 +9741,8 @@ private theorem rev_insert_between_incompatible {db : DB} {r : RangeRead} {res :
|
||||
have hT : (closedFormOffsetOneTruncatedRevFull r res).keys db = res.keys.reverse :=
|
||||
rev_truncated_finite_keys_eq (db := db) hcomp hmore hrev hbegin hcross hend hne ht
|
||||
have hT' : db.keys.filter BT = res.keys.reverse := by
|
||||
simpa only [closedFormOffsetOneTruncatedRevFull, if_neg (by omega : ¬ r.end_.offset ≤ 1),
|
||||
if_pos ht, hlast, hhead, BT, L, H, E, ConflictRange.keys] using hT
|
||||
simpa only [closedFormOffsetOneTruncatedRevFull, ite_eq_right (by omega : ¬ r.end_.offset ≤ 1),
|
||||
ite_eq_left ht, hlast, hhead, BT, L, H, E, ConflictRange.keys] using hT
|
||||
have hsort : res.keys.SortedGT := RangeRead.compatible_sortedGT hcomp hrev
|
||||
have hLH : L ≤ H := by
|
||||
dsimp only [L, H]
|
||||
@@ -9876,7 +9884,7 @@ private theorem rev_insert_between_incompatible {db : DB} {r : RangeRead} {res :
|
||||
rw [hinskeys, hJeq, List.getElem?_insertIdx]
|
||||
have hlt : ¬ j + 1 < db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
have heq : ¬ j + 1 = db.keys.countP (fun x => decide (x < k)) := by omega
|
||||
rw [if_neg hlt, if_neg heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hj]
|
||||
rw [ite_eq_right hlt, ite_eq_right heq, Nat.add_sub_cancel, List.getElem?_eq_getElem hjlt, hj]
|
||||
obtain ⟨_, hnewget⟩ := List.getElem?_eq_some_iff.mp hnewget?
|
||||
have hHresolve : resolve (db.insert k hk0) r.end_ = ((H : Key) : WithTop Key) := by
|
||||
rw [resolve_eq_getElem (anchor_nonneg_of_one_le (by omega)) hnewlen]
|
||||
@@ -9960,7 +9968,7 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_full_finite {r : RangeRea
|
||||
have hhead : res.keys.headD ([] : Key) = res.keys.head hne := by
|
||||
rw [List.headD_eq_head?, List.head?_eq_some_head hne]; rfl
|
||||
unfold closedFormOffsetOneTruncatedRevFull at hk
|
||||
rw [if_neg (by omega : ¬ r.end_.offset ≤ 1), if_pos ht] at hk
|
||||
rw [ite_eq_right (by omega : ¬ r.end_.offset ≤ 1), ite_eq_left ht] at hk
|
||||
rw [hlast, hhead] at hk
|
||||
have hkH : k ≤ res.keys.head hne :=
|
||||
(lt_keyAfter_iff k (res.keys.head hne)).mp (WithTop.coe_lt_coe.mp hk.2)
|
||||
@@ -10217,7 +10225,8 @@ private theorem necessary_pad_top_rev {r : RangeRead} {res : Result}
|
||||
have hP_sorted : P.SortedLT := by
|
||||
rw [hPdef]
|
||||
exact List.sortedLT_iff_pairwise.mpr
|
||||
(List.Pairwise.take (i := n) (List.Pairwise.erase k (List.sortedLT_iff_pairwise.mp hS_sorted)))
|
||||
(List.Pairwise.take (i := n) (List.Pairwise.erase k (List.sortedLT_iff_pairwise.mp
|
||||
hS_sorted)))
|
||||
have hP_sub : P ⊆ S := by
|
||||
intro x hx
|
||||
rw [hPdef] at hx
|
||||
@@ -10300,7 +10309,7 @@ private theorem necessary_pad_top_rev {r : RangeRead} {res : Result}
|
||||
have hck_a : RangeRead.completeKeys db_a r = aList.reverse := by
|
||||
unfold RangeRead.completeKeys
|
||||
rw [hrev]
|
||||
simp only [if_true]
|
||||
simp only [ite_true]
|
||||
change (RangeRead.inRange aList (resolve db_a r.begin) (resolve db_a r.end_)).reverse =
|
||||
aList.reverse
|
||||
rw [hin_a]
|
||||
@@ -10565,7 +10574,7 @@ theorem necessary_above_head_top_rev {r : RangeRead} {res : Result}
|
||||
WithTop.coe_lt_top x⟩
|
||||
unfold RangeRead.completeKeys
|
||||
rw [hrev]
|
||||
simp only [if_true]
|
||||
simp only [ite_true]
|
||||
rw [hin, hdb₁_keys, List.reverse_reverse]
|
||||
have hcomp₁ : RangeRead.Compatible db₁ r res := by
|
||||
refine (compatible_iff_truncated_keys_rev (db := db₁) hrev hmore hne).mpr
|
||||
@@ -10634,7 +10643,8 @@ theorem necessary_above_head_top_rev {r : RangeRead} {res : Result}
|
||||
= (db₁.keys ++ [k])[0] := List.getElem_of_eq hkeys₂ hpos'
|
||||
_ = db₁.keys[0] := List.getElem_append_left (i := 0) hlen₁
|
||||
_ = L := hbase
|
||||
have hkey : (db₁.insert k hk_notin).keys[(r.begin.anchor (db₁.insert k hk_notin)).toNat] = L := by
|
||||
have hkey : (db₁.insert k hk_notin).keys[(r.begin.anchor (db₁.insert k hk_notin)).toNat] = L
|
||||
:= by
|
||||
rw [List.getElem_eq_iff hidx, hanc, List.getElem?_eq_getElem hpos, hget0₂]
|
||||
rw [resolve_eq_getElem h0 hidx, hkey]
|
||||
have hcount₁₂ : db₁.keys.countP
|
||||
@@ -10686,7 +10696,7 @@ theorem necessary_above_head_top_rev {r : RangeRead} {res : Result}
|
||||
exact WithTop.coe_le_coe.mpr (le_of_lt (lt_of_le_of_lt hLH hkH))
|
||||
unfold RangeRead.completeKeys
|
||||
rw [hrev]
|
||||
simp only [if_true]
|
||||
simp only [ite_true]
|
||||
rw [hin, hkeys₂, List.reverse_append, List.reverse_singleton, hdb₁_keys,
|
||||
List.reverse_reverse]
|
||||
rfl
|
||||
@@ -10732,7 +10742,7 @@ private theorem completeKeys_filter_length_le {db : DB} {r : RangeRead}
|
||||
rw [hqf] at ha
|
||||
simp at ha
|
||||
rw [RangeRead.completeKeys, hrev]
|
||||
simp only [if_true]
|
||||
simp only [ite_true]
|
||||
rw [List.filter_reverse, List.length_reverse]
|
||||
exact hwin.length_le
|
||||
|
||||
@@ -10870,8 +10880,8 @@ the same keys at or above the last; the strict top-branch inequality then bounds
|
||||
keys at or above `end_.key` by `e - 1`, so its end is also unbounded. -/
|
||||
private theorem resolve_end_eq_top_of_agree_begin_last {db db' : DB} {r : RangeRead}
|
||||
{res : Result} {E L : Key} {n : Nat}
|
||||
(hmore : res.more = true) (hrev : r.reverse = true) (hbegin : r.begin.offset = 1)
|
||||
(hcross : r.begin.key ≤ r.end_.key) (hend : 2 ≤ r.end_.offset) (hne : res.keys ≠ [])
|
||||
(hmore : res.more = true) (hrev : r.reverse = true) (_hbegin : r.begin.offset = 1)
|
||||
(_hcross : r.begin.key ≤ r.end_.key) (hend : 2 ≤ r.end_.offset) (hne : res.keys ≠ [])
|
||||
(hE : r.end_.key = (E : WithTop Key)) (hL : L = res.keys.getLast hne)
|
||||
(hn : n = (r.end_.offset - 1).toNat -
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) - 1)
|
||||
@@ -11181,9 +11191,9 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC {r : RangeRead} {re
|
||||
· have h := minimal_closedForm_of_offset_one_truncated_rev_full hread' hmore hrev hbegin
|
||||
(Or.inl hle)
|
||||
unfold closedFormOffsetOneTruncatedRevFull at h
|
||||
rw [if_pos hle] at h
|
||||
rw [ite_eq_left hle] at h
|
||||
unfold closedFormOffsetOneTruncatedRevFullC
|
||||
rw [if_pos hle]
|
||||
rw [ite_eq_left hle]
|
||||
exact h
|
||||
· have hcount_le : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) ≤
|
||||
@@ -11196,11 +11206,11 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC {r : RangeRead} {re
|
||||
· have h := minimal_closedForm_of_offset_one_truncated_rev_full_finite hread' hmore hrev
|
||||
hbegin hcross (by omega : 2 ≤ r.end_.offset) ht
|
||||
unfold closedFormOffsetOneTruncatedRevFull at h
|
||||
rw [if_neg hle, if_pos ht] at h
|
||||
rw [ite_eq_right hle, ite_eq_left ht] at h
|
||||
unfold closedFormOffsetOneTruncatedRevFullC
|
||||
rw [if_neg hle]
|
||||
rw [ite_eq_right hle]
|
||||
dsimp only
|
||||
rw [if_pos ht]
|
||||
rw [ite_eq_left ht]
|
||||
simpa only [hlast, hhead] using h
|
||||
· have hlt : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) <
|
||||
@@ -11212,9 +11222,9 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC {r : RangeRead} {re
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) - 1 :=
|
||||
hn_def
|
||||
unfold closedFormOffsetOneTruncatedRevFullC
|
||||
rw [if_neg hle]
|
||||
rw [ite_eq_right hle]
|
||||
dsimp only
|
||||
rw [if_neg ht]
|
||||
rw [ite_eq_right ht]
|
||||
by_cases htop : r.end_.key = (⊤ : WithTop Key)
|
||||
· rw [htop]
|
||||
have h := minimal_topOfLast_of_end_offset_ge_two_rev hread' hmore hrev hbegin
|
||||
@@ -11236,14 +11246,14 @@ theorem minimal_closedForm_of_offset_one_truncated_rev_fullC {r : RangeRead} {re
|
||||
rw [← hlast]; exact hroom
|
||||
have h := minimal_topRev_begin_end hread' hmore hrev hbegin hcross
|
||||
(by omega : 2 ≤ r.end_.offset) hne hE.symm rfl hn hlt hroom'
|
||||
rw [if_pos hroom]
|
||||
rw [ite_eq_left hroom]
|
||||
exact h
|
||||
· have hge : res.keys.getLast hne ≤ keyAfterN n E := by
|
||||
rw [← hlast]
|
||||
exact le_of_not_gt hroom
|
||||
have h := minimal_topRev_begin_last hread' hmore hrev hbegin hcross
|
||||
(by omega : 2 ≤ r.end_.offset) hE.symm hne rfl hn hlt (Or.inr hge)
|
||||
rw [if_neg hroom]
|
||||
rw [ite_eq_right hroom]
|
||||
simpa only [← hlast] using h
|
||||
|
||||
/-- **One compact rule for every result at begin offset one.** Dispatch on `res.more`
|
||||
@@ -11264,16 +11274,16 @@ theorem minimal_closedForm_of_offset_one_universal {r : RangeRead} {res : Result
|
||||
Minimal r res (closedFormOffsetOneUniversal r res) := by
|
||||
unfold closedFormOffsetOneUniversal
|
||||
by_cases hmore : res.more = true
|
||||
· rw [if_pos hmore]
|
||||
· rw [ite_eq_left hmore]
|
||||
by_cases hrev : r.reverse = true
|
||||
· rw [if_pos hrev]
|
||||
· rw [ite_eq_left hrev]
|
||||
exact minimal_closedForm_of_offset_one_truncated_rev_fullC hread hmore hrev
|
||||
hbegin hcross
|
||||
· rw [if_neg hrev]
|
||||
· rw [ite_eq_right hrev]
|
||||
have hfalse : r.reverse = false := by
|
||||
cases hr : r.reverse <;> simp_all
|
||||
exact minimal_closedForm_of_offset_one_truncated hread hmore hfalse hbegin hcross
|
||||
· rw [if_neg hmore]
|
||||
· rw [ite_eq_right hmore]
|
||||
have hfalse : res.more = false := by
|
||||
cases hm : res.more <;> simp_all
|
||||
exact minimal_closedForm_of_offset_one_any hread hfalse hne hbegin hcross
|
||||
@@ -11283,7 +11293,7 @@ hypothesis is retained for compatibility with earlier statements. -/
|
||||
theorem minimal_closedForm_of_offset_one_universal_of_auto {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset = 1) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hauto : r.reverse = false ∨ res.more = false ∨ r.end_.offset ≤ 1 ∨
|
||||
(_hauto : r.reverse = false ∨ res.more = false ∨ r.end_.offset ≤ 1 ∨
|
||||
r.end_.key = (⊤ : WithTop Key)) :
|
||||
Minimal r res (closedFormOffsetOneUniversal r res) :=
|
||||
minimal_closedForm_of_offset_one_universal hread hne hbegin hcross
|
||||
@@ -11294,7 +11304,7 @@ theorem minimal_closedForm_of_offset_one_universal_of_not_cell {r : RangeRead}
|
||||
{res : Result}
|
||||
(hread : Readable r res) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset = 1) (hcross : r.begin.key ≤ r.end_.key)
|
||||
(hcell : ¬ (r.reverse = true ∧ res.more = true ∧ 2 ≤ r.end_.offset ∧
|
||||
(_hcell : ¬ (r.reverse = true ∧ res.more = true ∧ 2 ≤ r.end_.offset ∧
|
||||
r.end_.key ≤ ((res.keys.headD ([] : Key) : Key) : WithTop Key))) :
|
||||
Minimal r res (closedFormOffsetOneUniversal r res) :=
|
||||
minimal_closedForm_of_offset_one_universal hread hne hbegin hcross
|
||||
@@ -11492,8 +11502,8 @@ theorem completeKeys_eq_drop_take_general {db : DB} {r : RangeRead}
|
||||
/-- **In the crossed case every complete key lies at or above `end_.key` at any
|
||||
positive begin offset.** -/
|
||||
theorem completeKeys_count_ge_eq_length_of_crossed_general {db : DB} {r : RangeRead}
|
||||
(hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (hend : 1 ≤ r.end_.offset) :
|
||||
(_hrev : r.reverse = false) (hbegin : 1 ≤ r.begin.offset)
|
||||
(hcross : r.end_.key < r.begin.key) (_hend : 1 ≤ r.end_.offset) :
|
||||
(RangeRead.completeKeys db r).countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) =
|
||||
(RangeRead.completeKeys db r).length := by
|
||||
@@ -11688,7 +11698,8 @@ theorem compatible_crossed_iff_crossFree {r : RangeRead} {res : Result}
|
||||
unfold Selector.anchor crossFreeAnchor
|
||||
simp only
|
||||
omega
|
||||
have hresolve : resolve db r.begin = resolve db ({ key := r.end_.key, offset := 1 } : Selector) := by
|
||||
have hresolve : resolve db r.begin = resolve db ({ key := r.end_.key, offset := 1 } :
|
||||
Selector) := by
|
||||
unfold resolve
|
||||
rw [hanchor]
|
||||
rfl
|
||||
@@ -11726,7 +11737,8 @@ theorem compatible_crossed_iff_crossFree {r : RangeRead} {res : Result}
|
||||
exact le_trans (key_le_resolve_of_one_le (db := db₀) (s := r.begin) (by omega))
|
||||
(RangeRead.mem_completeKeys.mp hk₀).2.1
|
||||
-- show no stored key lies in [E, B)
|
||||
have hno : ∀ k ∈ db.keys, ¬ (r.end_.key ≤ (k : WithTop Key) ∧ (k : WithTop Key) < r.begin.key) := by
|
||||
have hno : ∀ k ∈ db.keys, ¬ (r.end_.key ≤ (k : WithTop Key) ∧ (k : WithTop Key) < r.begin.key)
|
||||
:= by
|
||||
intro k hk hkb
|
||||
have hkwin : k ∈ RangeRead.completeKeys db (crossFreeAnchor r) := by
|
||||
refine RangeRead.mem_completeKeys.mpr ⟨hk, ?_, ?_⟩
|
||||
@@ -11758,13 +11770,13 @@ theorem compatible_crossed_iff_crossFree {r : RangeRead} {res : Result}
|
||||
unfold Selector.anchor crossFreeAnchor
|
||||
simp only
|
||||
omega
|
||||
have hresolve : resolve db r.begin = resolve db ({ key := r.end_.key, offset := 1 } : Selector) := by
|
||||
have hresolve : resolve db r.begin = resolve db ({ key := r.end_.key, offset := 1 } :
|
||||
Selector) := by
|
||||
unfold resolve
|
||||
rw [hanchor]
|
||||
rfl
|
||||
refine ⟨?_, ?_⟩
|
||||
· change r.withinLimit res.keys
|
||||
exact hcomp.1
|
||||
· exact hcomp.1
|
||||
· right
|
||||
refine ⟨by simp [hmore], ?_⟩
|
||||
have hck : RangeRead.completeKeys db r = RangeRead.completeKeys db (crossFreeAnchor r) := by
|
||||
@@ -11933,7 +11945,8 @@ private theorem completeKeys_eq_drop_take_of_key_eq {db : DB} {r : RangeRead}
|
||||
have hAlen : (l.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key)))).length =
|
||||
l.length - c := by rw [hA, List.length_drop]
|
||||
have hle : c + e ≤ l.length := by
|
||||
have hlen' : e ≤ (l.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key)))).length := by
|
||||
have hlen' : e ≤ (l.filter (fun k : Key => decide (r.begin.key ≤ (k : WithTop Key)))).length
|
||||
:= by
|
||||
simpa [hl] using hlen
|
||||
rw [hAlen] at hlen'
|
||||
have hc_le : c ≤ l.length := by
|
||||
@@ -12081,7 +12094,8 @@ private theorem sound_truncatedRange_of_key_eq_finite_general {r : RangeRead} {r
|
||||
rw [← truncatedRange_keys_eq_filter_le (db := db₂) (r := r) (last := last), hTlen₂]
|
||||
have hfil := filter_le_eq_take_countP hAsort₂ last
|
||||
rw [hq] at hfil
|
||||
exact hfil.symm.trans (truncatedRange_keys_eq_filter_le (db := db₂) (r := r) (last := last)).symm
|
||||
exact hfil.symm.trans (truncatedRange_keys_eq_filter_le (db := db₂) (r := r) (last :=
|
||||
last)).symm
|
||||
-- Assemble the complete window of `db₂`.
|
||||
have hck₂ : RangeRead.completeKeys db₂ r = res.keys := by
|
||||
rw [completeKeys_eq_drop_take_of_key_eq (db := db₂) hrev hbegin hkey (by omega) hlenA₂]
|
||||
@@ -12134,7 +12148,7 @@ database is the sentinel. Otherwise the complete window would be the rank interv
|
||||
would number exactly `e - b`. -/
|
||||
private theorem resolve_end_eq_top_of_key_eq_top_general {db : DB} {r : RangeRead}
|
||||
{res : Result} (hcomp : RangeRead.Compatible db r res) (hmore : res.more = false)
|
||||
(hrev : r.reverse = false) (hne : res.keys ≠ [])
|
||||
(hrev : r.reverse = false) (_hne : res.keys ≠ [])
|
||||
(hbegin : 1 ≤ r.begin.offset) (hkey : r.begin.key = r.end_.key)
|
||||
(hend : 2 ≤ r.end_.offset)
|
||||
(ht : res.keys.countP
|
||||
@@ -12520,10 +12534,10 @@ theorem minimal_closedForm_of_key_eq_complete_general {r : RangeRead} {res : Res
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) +
|
||||
(r.begin.offset - 1).toNat = (r.end_.offset - 1).toNat
|
||||
· rw [if_pos ht]
|
||||
· rw [ite_eq_left ht]
|
||||
exact minimal_truncatedRange_of_key_eq_finite_general hread' hmore hne hrev hbegin
|
||||
hkey hend ht
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_right ht]
|
||||
have hle := key_eq_count_add_le (db := db₀) hcomp hmore hrev hne hbegin hkey
|
||||
(by omega)
|
||||
exact minimal_topRange_of_key_eq_top_general hread' hmore hrev hne hbegin hkey hend
|
||||
@@ -12557,7 +12571,8 @@ theorem resolve_eq_filter_lt_reverse {db : DB} {s : Selector} (hoff : s.offset
|
||||
set c := db.keys.countP (fun (k : Key) => decide ((↑k : WithTop Key) < s.key)) with hc
|
||||
have hanchor : s.anchor db = (c : ℤ) - (m : ℤ) - 1 := by
|
||||
unfold Selector.anchor; rw [← hc, hoff']; ring
|
||||
have hflen : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) < s.key))).length = c := by
|
||||
have hflen : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) < s.key))).length = c
|
||||
:= by
|
||||
rw [← List.countP_eq_length_filter, ← hc]
|
||||
have hclen : c ≤ db.keys.length := by rw [hc]; exact List.countP_le_length
|
||||
by_cases hmc : m < c
|
||||
@@ -12573,7 +12588,8 @@ theorem resolve_eq_filter_lt_reverse {db : DB} {s : Selector} (hoff : s.offset
|
||||
rw [resolve_eq_getElem h0 hlen]
|
||||
apply WithTop.coe_inj.mp
|
||||
simp only [hidx]
|
||||
have hsome : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) < s.key))).reverse[m]? =
|
||||
have hsome : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) <
|
||||
s.key))).reverse[m]? =
|
||||
some (db.keys[c - 1 - m]'(by omega)) := by
|
||||
rw [List.getElem?_reverse (by rw [hflen]; omega)]
|
||||
rw [hflen]
|
||||
@@ -12583,7 +12599,8 @@ theorem resolve_eq_filter_lt_reverse {db : DB} {s : Selector} (hoff : s.offset
|
||||
· have hle : c ≤ m := by omega
|
||||
have hneg : s.anchor db < 0 := by rw [hanchor]; omega
|
||||
rw [resolve_eq_nil hneg]
|
||||
have hnone : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) < s.key))).reverse[m]? = none :=
|
||||
have hnone : (db.keys.filter (fun (k : Key) => decide ((↑k : WithTop Key) <
|
||||
s.key))).reverse[m]? = none :=
|
||||
List.getElem?_eq_none (by rw [List.length_reverse, hflen]; exact hle)
|
||||
rw [hnone]
|
||||
|
||||
@@ -12608,34 +12625,44 @@ theorem filter_lt_eq_filter_lt_append_between {l : List Key} (hs : l.SortedLT)
|
||||
List.filter_cons_of_pos (p := fun k : Key => decide ((↑k : WithTop Key) < E)) (a := x)
|
||||
(decide_eq_true hxE)
|
||||
by_cases hxa : ((x : Key) : WithTop Key) < ((a : Key) : WithTop Key)
|
||||
· have hFa_pos : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) =
|
||||
· have hFa_pos : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) =
|
||||
x :: xs.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) :=
|
||||
List.filter_cons_of_pos (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) (a := x)
|
||||
List.filter_cons_of_pos (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) (a := x)
|
||||
(decide_eq_true hxa)
|
||||
have hG_neg : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
have hG_neg : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) =
|
||||
xs.filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < E)) :=
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) (a := x) (by simp [not_le.mpr hxa])
|
||||
rw [hFE_pos, hFa_pos, hG_neg, hih]
|
||||
rfl
|
||||
· have hax : ((a : Key) : WithTop Key) ≤ ((x : Key) : WithTop Key) := le_of_not_gt hxa
|
||||
have hFa_nil : xs.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) = [] := by
|
||||
have hFa_nil : xs.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key)))
|
||||
= [] := by
|
||||
rw [List.filter_eq_nil_iff]
|
||||
intro k hk
|
||||
have hxk : ((x : Key) : WithTop Key) < (k : WithTop Key) := WithTop.coe_lt_coe.mpr (hx_le k hk)
|
||||
have hxk : ((x : Key) : WithTop Key) < (k : WithTop Key) := WithTop.coe_lt_coe.mpr
|
||||
(hx_le k hk)
|
||||
simp only [decide_eq_true_eq]
|
||||
exact not_lt.mpr (le_trans hax (le_of_lt hxk))
|
||||
have hFa_neg : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) =
|
||||
have hFa_neg : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) =
|
||||
xs.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) :=
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) (a := x)
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) (a := x)
|
||||
(by simp [hxa])
|
||||
have hG_pos : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
have hG_pos : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) =
|
||||
x :: xs.filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < E)) :=
|
||||
List.filter_cons_of_pos (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
List.filter_cons_of_pos (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) (a := x) (decide_eq_true ⟨hax, hxE⟩)
|
||||
rw [hFE_pos, hFa_neg, hG_pos, hFa_nil, List.nil_append, hih, hFa_nil, List.nil_append]
|
||||
· have hEx : E ≤ ((x : Key) : WithTop Key) := le_of_not_gt hxE
|
||||
@@ -12647,15 +12674,19 @@ theorem filter_lt_eq_filter_lt_append_between {l : List Key} (hs : l.SortedLT)
|
||||
xs.filter (fun k : Key => decide ((↑k : WithTop Key) < E)) :=
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((↑k : WithTop Key) < E)) (a := x)
|
||||
(by simp [hxE])
|
||||
have hFa_neg : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) =
|
||||
have hFa_neg : (x :: xs).filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) =
|
||||
xs.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) :=
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) (a := x)
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop
|
||||
Key))) (a := x)
|
||||
(by simp [hnot_a])
|
||||
have hG_neg : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
have hG_neg : (x :: xs).filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) =
|
||||
xs.filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < E)) :=
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
List.filter_cons_of_neg (p := fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop
|
||||
Key) ∧
|
||||
(↑k : WithTop Key) < E)) (a := x) (by simp [hxE])
|
||||
rw [hFE_neg, hFa_neg, hG_neg, hih]
|
||||
|
||||
@@ -12674,7 +12705,8 @@ theorem resolve_eq_of_agree_between {db₁ db₂ : DB} {s : Selector}
|
||||
(hqa : (a : WithTop Key) ≤ ((q : Key) : WithTop Key)) :
|
||||
resolve db₂ s = ((q : Key) : WithTop Key) := by
|
||||
set m := (-s.offset).toNat with hm
|
||||
set A₁ := db₁.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) with hA₁
|
||||
set A₁ := db₁.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) with
|
||||
hA₁
|
||||
set B₁ := db₁.keys.filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < E)) with hB₁
|
||||
set F₁ := db₁.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < E)) with hF₁
|
||||
@@ -12707,7 +12739,8 @@ theorem resolve_eq_of_agree_between {db₁ db₂ : DB} {s : Selector}
|
||||
exact List.getElem?_append_left (l₁ := B₁.reverse) (l₂ := A₁.reverse) (i := m)
|
||||
(by rwa [List.length_reverse])
|
||||
rwa [hleft] at hq
|
||||
set A₂ := db₂.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) with hA₂
|
||||
set A₂ := db₂.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < (a : WithTop Key))) with
|
||||
hA₂
|
||||
set B₂ := db₂.keys.filter (fun k : Key => decide ((a : WithTop Key) ≤ (↑k : WithTop Key) ∧
|
||||
(↑k : WithTop Key) < E)) with hB₂
|
||||
set F₂ := db₂.keys.filter (fun k : Key => decide ((↑k : WithTop Key) < E)) with hF₂
|
||||
@@ -12808,14 +12841,16 @@ theorem minimal_headToEnd_of_zero_begin_crossed_endNonpos {r : RangeRead} {res :
|
||||
have hB_le_E : r.begin.key ≤ r.end_.key := by
|
||||
by_contra hcon
|
||||
have hEB : r.end_.key < r.begin.key := lt_of_not_ge hcon
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.end_) with hn | ht | ⟨k, hkdb, hkres⟩
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.end_) with hn | ht | ⟨k, hkdb,
|
||||
hkres⟩
|
||||
· rw [hn] at hhead_lt_res
|
||||
exact absurd hhead_lt_res (not_lt.mpr (coe_nil_le _))
|
||||
· exact absurd ht (resolve_ne_top_of_offset_nonpos hend)
|
||||
· have hk_lt_B : (k : WithTop Key) < r.begin.key :=
|
||||
lt_of_le_of_lt (by rw [← hkres]; exact hres_le_E) hEB
|
||||
have hk_le_head : (k : WithTop Key) ≤ ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
have hb := resolve_zero_begin_le_of_mem_below (db := db) hbegin hhead_stored hcross k hkdb hk_lt_B
|
||||
have hb := resolve_zero_begin_le_of_mem_below (db := db) hbegin hhead_stored hcross k
|
||||
hkdb hk_lt_B
|
||||
rwa [hL] at hb
|
||||
have hhead_lt_k : ((res.keys.head hne : Key) : WithTop Key) < (k : WithTop Key) := by
|
||||
rw [← hkres]; exact hhead_lt_res
|
||||
@@ -12853,7 +12888,8 @@ theorem minimal_headToEnd_of_zero_begin_crossed_endNonpos {r : RangeRead} {res :
|
||||
exact hno k (List.mem_of_mem_filter hk_in) hheadk hkB
|
||||
have hL' : resolve db' r.begin = ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
apply le_antisymm
|
||||
· rcases resolve_eq_nil_or_eq_top_or_mem (db := db') (s := r.begin) with hn | ht | ⟨k, hkdb', hkres⟩
|
||||
· rcases resolve_eq_nil_or_eq_top_or_mem (db := db') (s := r.begin) with hn | ht | ⟨k,
|
||||
hkdb', hkres⟩
|
||||
· rw [hn]; exact coe_nil_le _
|
||||
· exact absurd ht (resolve_ne_top_of_offset_nonpos (by rw [hbegin]))
|
||||
· rw [hkres]
|
||||
@@ -13032,7 +13068,7 @@ theorem compatible_zero_crossed_iff_anchor {r : RangeRead} {res : Result}
|
||||
rw [hL]
|
||||
congr 1
|
||||
funext k
|
||||
show decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
change decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_) =
|
||||
decide (resolve db (zeroBeginAnchor r res).begin ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_)
|
||||
@@ -13065,7 +13101,8 @@ theorem compatible_zero_crossed_iff_anchor {r : RangeRead} {res : Result}
|
||||
exact hres_avoid k hkck hkb
|
||||
have hL : resolve db r.begin = ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
apply le_antisymm
|
||||
· rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hn | ht | ⟨q, hq, hqeq⟩
|
||||
· rcases resolve_eq_nil_or_eq_top_or_mem (db := db) (s := r.begin) with hn | ht | ⟨q, hq,
|
||||
hqeq⟩
|
||||
· rw [hn]
|
||||
exact coe_nil_le _
|
||||
· exact absurd ht (resolve_ne_top_of_offset_nonpos (by rw [hbegin]))
|
||||
@@ -13091,7 +13128,7 @@ theorem compatible_zero_crossed_iff_anchor {r : RangeRead} {res : Result}
|
||||
rw [hL]
|
||||
congr 1
|
||||
funext k
|
||||
show decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
change decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_) =
|
||||
decide (resolve db (zeroBeginAnchor r res).begin ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_)
|
||||
|
||||
@@ -241,7 +241,7 @@ theorem compatible_anchor_of_zero_crossed {db : DB} {r : RangeRead} {res : Resul
|
||||
rw [hL]
|
||||
congr 1
|
||||
funext k
|
||||
show decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
change decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_) =
|
||||
decide (resolve db (zeroBeginAnchor r res).begin ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_)
|
||||
@@ -285,7 +285,7 @@ theorem compatible_of_anchor_of_no_between {db : DB} {r : RangeRead} {res : Resu
|
||||
rw [hL]
|
||||
congr 1
|
||||
funext k
|
||||
show decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
change decide (((res.keys.head hne : Key) : WithTop Key) ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_) =
|
||||
decide (resolve db (zeroBeginAnchor r res).begin ≤ (k : WithTop Key) ∧
|
||||
(k : WithTop Key) < resolve db r.end_)
|
||||
@@ -328,7 +328,8 @@ theorem sound_of_anchor_sound {r : RangeRead} {res : Result} {cr crA : ConflictR
|
||||
intro k hk hkb
|
||||
have hno_db := no_stored_between_head_begin_of_zero_crossed hc hrev hmore hne
|
||||
hbegin hcross
|
||||
have hkbd : k ∈ db.keys := ((agreeOn_iff cr db db').mp hag) k (hmem_cr k hkb.1 hkb.2) |>.mpr hk
|
||||
have hkbd : k ∈ db.keys := ((agreeOn_iff cr db db').mp hag) k (hmem_cr k hkb.1 hkb.2) |>.mpr
|
||||
hk
|
||||
exact hno_db k hkbd hkb
|
||||
exact compatible_of_anchor_of_no_between hcA' hrev hmore hne hbegin hcross hno
|
||||
constructor
|
||||
@@ -387,7 +388,7 @@ theorem minimal_zeroCrossLongAnchor {r : RangeRead} {res : Result}
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0)
|
||||
(hcross : ((res.keys.head hne : Key) : WithTop Key) < r.begin.key)
|
||||
(hend : 2 ≤ r.end_.offset) :
|
||||
(_hend : 2 ≤ r.end_.offset) :
|
||||
Minimal (zeroBeginAnchor r res) res (zeroCrossLongAnchor r res) := by
|
||||
obtain ⟨db₀, hcomp₀⟩ := hread
|
||||
have hH : res.keys.headD ([] : Key) = res.keys.head hne := headD_eq_head_sound hne
|
||||
@@ -398,13 +399,13 @@ theorem minimal_zeroCrossLongAnchor {r : RangeRead} {res : Result}
|
||||
unfold zeroCrossLongAnchor
|
||||
rw [hH]
|
||||
by_cases hE : r.end_.key < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· rw [if_pos hE]
|
||||
· rw [ite_eq_left hE]
|
||||
have hEA : (zeroBeginAnchor r res).end_.key < (zeroBeginAnchor r res).begin.key := by
|
||||
change r.end_.key < (zeroBeginAnchor r res).begin.key
|
||||
rw [zeroBeginAnchor_begin_zero_cross_long r res hne]
|
||||
exact hE
|
||||
exact minimal_completeForwardCrossedGeneral hreadA hmore hne hrevA (by omega) hEA
|
||||
· rw [if_neg hE]
|
||||
· rw [ite_eq_right hE]
|
||||
have hle : ((res.keys.head hne : Key) : WithTop Key) ≤ r.end_.key := not_lt.mp hE
|
||||
have hleA : (zeroBeginAnchor r res).begin.key ≤ (zeroBeginAnchor r res).end_.key := by
|
||||
change (zeroBeginAnchor r res).begin.key ≤ r.end_.key
|
||||
@@ -444,7 +445,7 @@ theorem zeroBeginAnchor_begin_offset_eq (r : RangeRead) (res : Result) :
|
||||
|
||||
/-- The begin endpoint of the long-cell anchor, with `E < H`. -/
|
||||
theorem zeroCrossLongAnchor_begin_crossed {r : RangeRead} {res : Result}
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (_hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hEH : r.end_.key < ((res.keys.head hne : Key) : WithTop Key)) :
|
||||
(zeroCrossLongAnchor r res).begin =
|
||||
if reportedAtEnd r res = endOvershoot r ∨
|
||||
@@ -452,17 +453,17 @@ theorem zeroCrossLongAnchor_begin_crossed {r : RangeRead} {res : Result}
|
||||
intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key))
|
||||
then r.end_.key else ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
unfold zeroCrossLongAnchor
|
||||
rw [headD_eq_head_sound hne, if_pos hEH]
|
||||
rw [headD_eq_head_sound hne, ite_eq_left hEH]
|
||||
show (completeForwardCrossedGeneral (zeroBeginAnchor r res) res).begin = _
|
||||
unfold completeForwardCrossedGeneral
|
||||
rw [if_neg (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [ite_eq_right (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [zeroBeginAnchor_reported_eq, zeroBeginAnchor_overshoot_eq,
|
||||
zeroBeginAnchor_begin_offset_eq, show (((1 : ℤ) - 1).toNat) = 0 by norm_num,
|
||||
Nat.add_zero, zeroBeginAnchor_begin_key_eq r res hne]
|
||||
rw [zeroBeginAnchor_interval_eq]
|
||||
by_cases ht : reportedAtEnd r res = endOvershoot r
|
||||
· rw [if_pos ht, if_pos (Or.inl ht), zeroBeginAnchor_end_key_eq]
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_left ht, ite_eq_left (Or.inl ht), zeroBeginAnchor_end_key_eq]
|
||||
· rw [ite_eq_right ht]
|
||||
have hso : crossedOvershootGeneral (zeroBeginAnchor r res) res =
|
||||
endOvershoot r - reportedAtEnd r res := by
|
||||
unfold crossedOvershootGeneral
|
||||
@@ -472,58 +473,58 @@ theorem zeroCrossLongAnchor_begin_crossed {r : RangeRead} {res : Result}
|
||||
rw [hso]
|
||||
by_cases hc : (((endOvershoot r - reportedAtEnd r res : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key))
|
||||
· rw [if_pos hc, if_pos (Or.inr hc), zeroBeginAnchor_end_key_eq]
|
||||
· rw [if_neg hc, if_neg (fun h => h.elim ht hc)]
|
||||
· rw [ite_eq_left hc, ite_eq_left (Or.inr hc), zeroBeginAnchor_end_key_eq]
|
||||
· rw [ite_eq_right hc, ite_eq_right (fun h => h.elim ht hc)]
|
||||
|
||||
/-- The end endpoint of the long-cell anchor, with `E < H`. -/
|
||||
theorem zeroCrossLongAnchor_end_crossed {r : RangeRead} {res : Result}
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (_hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hEH : r.end_.key < ((res.keys.head hne : Key) : WithTop Key)) :
|
||||
(zeroCrossLongAnchor r res).end_ =
|
||||
if reportedAtEnd r res = endOvershoot r
|
||||
then (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) else ⊤ := by
|
||||
unfold zeroCrossLongAnchor
|
||||
rw [headD_eq_head_sound hne, if_pos hEH]
|
||||
rw [headD_eq_head_sound hne, ite_eq_left hEH]
|
||||
show (completeForwardCrossedGeneral (zeroBeginAnchor r res) res).end_ = _
|
||||
unfold completeForwardCrossedGeneral
|
||||
rw [if_neg (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [ite_eq_right (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [zeroBeginAnchor_reported_eq, zeroBeginAnchor_overshoot_eq,
|
||||
zeroBeginAnchor_begin_offset_eq, show (((1 : ℤ) - 1).toNat) = 0 by norm_num,
|
||||
Nat.add_zero]
|
||||
by_cases ht : reportedAtEnd r res = endOvershoot r
|
||||
· rw [if_pos ht, if_pos ht]
|
||||
· rw [if_neg ht, if_neg ht]
|
||||
· rw [ite_eq_left ht, ite_eq_left ht]
|
||||
· rw [ite_eq_right ht, ite_eq_right ht]
|
||||
|
||||
/-- The begin endpoint of the long-cell anchor, with `H ≤ E`. -/
|
||||
theorem zeroCrossLongAnchor_begin_crossfree {r : RangeRead} {res : Result}
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (_hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hEH : ¬ (r.end_.key < ((res.keys.head hne : Key) : WithTop Key))) :
|
||||
(zeroCrossLongAnchor r res).begin = (((res.keys.head hne : Key)) : WithTop Key) := by
|
||||
unfold zeroCrossLongAnchor
|
||||
rw [headD_eq_head_sound hne, if_neg hEH]
|
||||
rw [headD_eq_head_sound hne, ite_eq_right hEH]
|
||||
show (closedFormOffsetOne (zeroBeginAnchor r res) res).begin = _
|
||||
unfold closedFormOffsetOne
|
||||
rw [if_neg (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [ite_eq_right (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide ((zeroBeginAnchor r res).end_.key ≤ (k : WithTop Key))) =
|
||||
((zeroBeginAnchor r res).end_.offset - 1).toNat
|
||||
· rw [if_pos ht]
|
||||
· rw [ite_eq_left ht]
|
||||
simp [truncatedRange, zeroBeginAnchor_begin_key_eq r res hne]
|
||||
· rw [if_neg ht]
|
||||
· rw [ite_eq_right ht]
|
||||
simp [topRange, zeroBeginAnchor_begin_key_eq r res hne]
|
||||
|
||||
/-- The end endpoint of the long-cell anchor, with `H ≤ E`. -/
|
||||
theorem zeroCrossLongAnchor_end_crossfree {r : RangeRead} {res : Result}
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hne : res.keys ≠ []) (_hbegin : r.begin.offset = 0) (hend : 2 ≤ r.end_.offset)
|
||||
(hEH : ¬ (r.end_.key < ((res.keys.head hne : Key) : WithTop Key))) :
|
||||
(zeroCrossLongAnchor r res).end_ =
|
||||
if reportedAtEnd r res = endOvershoot r
|
||||
then (((keyAfter (res.keys.getLastD ([] : Key)) : Key)) : WithTop Key) else ⊤ := by
|
||||
unfold zeroCrossLongAnchor
|
||||
rw [headD_eq_head_sound hne, if_neg hEH]
|
||||
rw [headD_eq_head_sound hne, ite_eq_right hEH]
|
||||
show (closedFormOffsetOne (zeroBeginAnchor r res) res).end_ = _
|
||||
unfold closedFormOffsetOne
|
||||
rw [if_neg (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
rw [ite_eq_right (by rw [zeroBeginAnchor_end_offset_eq]; omega)]
|
||||
have hcnt : res.keys.countP
|
||||
(fun k : Key => decide ((zeroBeginAnchor r res).end_.key ≤ (k : WithTop Key))) =
|
||||
res.keys.countP (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) := by
|
||||
@@ -533,9 +534,9 @@ theorem zeroCrossLongAnchor_end_crossfree {r : RangeRead} {res : Result}
|
||||
by_cases ht : res.keys.countP
|
||||
(fun k : Key => decide ((zeroBeginAnchor r res).end_.key ≤ (k : WithTop Key))) =
|
||||
((zeroBeginAnchor r res).end_.offset - 1).toNat
|
||||
· rw [if_pos ht, if_pos (by unfold reportedAtEnd; rw [← hcnt, ← hoff]; exact ht)]
|
||||
· rw [ite_eq_left ht, ite_eq_left (by unfold reportedAtEnd; rw [← hcnt, ← hoff]; exact ht)]
|
||||
simp [truncatedRange]
|
||||
· rw [if_neg ht, if_neg (by unfold reportedAtEnd; rw [← hcnt, ← hoff]; exact ht)]
|
||||
· rw [ite_eq_right ht, ite_eq_right (by unfold reportedAtEnd; rw [← hcnt, ← hoff]; exact ht)]
|
||||
simp [topRange]
|
||||
|
||||
/-- At `begin.offset = 0` and `begin.key = ⊤`, the begin selector resolves to the
|
||||
@@ -1043,14 +1044,14 @@ theorem minimal_closedForm_of_zero_cross_long_top {r : RangeRead} {res : Result}
|
||||
conv_lhs => rw [hsingle]
|
||||
by_cases hEH : r.end_.key ≤ ((res.keys.head hne : Key) : WithTop Key) <;> simp [hEH]
|
||||
unfold closedFormZeroCrossLong
|
||||
rw [if_pos htop, hHd]
|
||||
rw [ite_eq_left htop, hHd]
|
||||
dsimp only
|
||||
rw [ht]
|
||||
by_cases hcond : r.end_.key < ((res.keys.head hne : Key) : WithTop Key) ∧
|
||||
(((r.end_.offset - 1).toNat : ℕ∞) -
|
||||
((if r.end_.key ≤ ((res.keys.head hne : Key) : WithTop Key) then 1 else 0 : ℕ) : ℕ∞))
|
||||
< intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key)
|
||||
· rw [if_pos hcond]
|
||||
· rw [ite_eq_left hcond]
|
||||
have hcle : r.end_.key ≤ ((res.keys.head hne : Key) : WithTop Key) := le_of_lt hcond.1
|
||||
have ht1 : res.keys.countP
|
||||
(fun k : Key => decide (r.end_.key ≤ (k : WithTop Key))) = 1 := by
|
||||
@@ -1065,7 +1066,7 @@ theorem minimal_closedForm_of_zero_cross_long_top {r : RangeRead} {res : Result}
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr
|
||||
⟨sound_zero_cross_long_top_E hread hrev hmore hne hbegin htop hend hcond.1,
|
||||
necessary_zero_cross_long_top_E hread hrev hmore hne hbegin htop hend hcond.1 hcond'⟩
|
||||
· rw [if_neg hcond]
|
||||
· rw [ite_eq_right hcond]
|
||||
have hepos : 1 ≤ (r.end_.offset - 1).toNat := by omega
|
||||
have hbound : intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key) + 1 ≤
|
||||
(((r.end_.offset - 1).toNat : ℕ) : ℕ∞) := by
|
||||
@@ -1333,7 +1334,7 @@ theorem necessary_zero_cross_long_below_head_eq {r : RangeRead} {res : Result} {
|
||||
(hread : Readable r res) (hrev : r.reverse = false) (hmore : res.more = false)
|
||||
(hne : res.keys ≠ []) (hbegin : r.begin.offset = 0)
|
||||
(hcross : ((res.keys.head hne : Key) : WithTop Key) < r.begin.key)
|
||||
(hlong : r.end_.key < r.begin.key) (hend : 2 ≤ r.end_.offset)
|
||||
(_hlong : r.end_.key < r.begin.key) (hend : 2 ≤ r.end_.offset)
|
||||
(hte : reportedAtEnd r res = endOvershoot r)
|
||||
(hEH : r.end_.key < ((res.keys.head hne : Key) : WithTop Key))
|
||||
(hkE : r.end_.key ≤ (k : WithTop Key))
|
||||
@@ -1344,7 +1345,8 @@ theorem necessary_zero_cross_long_below_head_eq {r : RangeRead} {res : Result} {
|
||||
let db : DB := ⟨res.keys, hsort⟩
|
||||
have hcompR : RangeRead.Compatible db r res :=
|
||||
compatible_res_keys_zero_cross_long hsort hread' hrev hmore hne hbegin hcross hend
|
||||
have hhead_le : ∀ q ∈ res.keys, ((res.keys.head hne : Key) : WithTop Key) ≤ (q : WithTop Key) := by
|
||||
have hhead_le : ∀ q ∈ res.keys, ((res.keys.head hne : Key) : WithTop Key) ≤ (q : WithTop Key) :=
|
||||
by
|
||||
intro q hq
|
||||
have := (hsort.pairwise.imp le_of_lt).rel_head hq
|
||||
simpa using this
|
||||
@@ -1415,7 +1417,8 @@ theorem necessary_zero_cross_long_below_head_eq {r : RangeRead} {res : Result} {
|
||||
exact htlen.symm.trans hte
|
||||
omega
|
||||
have hresle : resolve (toggle db k) r.end_ ≤ ((res.keys.getLast hne : Key) : WithTop Key) := by
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := toggle db k) (s := r.end_) with hn | ht' | ⟨q, hq, hqe⟩
|
||||
rcases resolve_eq_nil_or_eq_top_or_mem (db := toggle db k) (s := r.end_) with hn | ht' | ⟨q,
|
||||
hq, hqe⟩
|
||||
· rw [hn]; exact coe_nil_le_zero_cross_long _
|
||||
· exact absurd ht' hnot_top
|
||||
· rw [hqe]; exact WithTop.coe_le_coe.mpr (hmax q hq)
|
||||
@@ -1679,7 +1682,7 @@ theorem necessary_zero_cross_long_below_head_lt {r : RangeRead} {res : Result} {
|
||||
· exact hHnotin_res k ((hmem_dbH k).mpr (Or.inl rfl)) hkr
|
||||
· exact absurd hkC (lt_irrefl k)
|
||||
rw [List.append_assoc, List.erase_append,
|
||||
if_pos ((hmem_dbH k).mpr (Or.inl rfl)), hHerase]
|
||||
ite_eq_left ((hmem_dbH k).mpr (Or.inl rfl)), hHerase]
|
||||
simp [List.append_assoc]
|
||||
let dbErase : DB := dbBig.erase k
|
||||
have hkeysErase : dbErase.keys = dbH0.keys ++ res.keys ++ [C] := hEraseKeys
|
||||
@@ -1816,22 +1819,22 @@ theorem minimal_closedForm_of_zero_cross_long_finite {r : RangeRead} {res : Resu
|
||||
subrange_of_le le_rfl (le_max_left _ _)
|
||||
have hsound : Sound r res (closedFormZeroCrossLong r res) := by
|
||||
unfold closedFormZeroCrossLong
|
||||
rw [if_neg hB]
|
||||
rw [ite_eq_right hB]
|
||||
refine sound_of_anchor_sound hrev hmore hne hbegin hcross ?_ ?_ hsub hsoundA
|
||||
· by_cases hEH : r.end_.key < ((res.keys.head hne : Key) : WithTop Key)
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH]
|
||||
by_cases hc : (reportedAtEnd r res = endOvershoot r ∨
|
||||
(((endOvershoot r - reportedAtEnd r res : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key)))
|
||||
· rw [if_pos hc]
|
||||
· rw [ite_eq_left hc]
|
||||
exact le_of_lt hEH
|
||||
· rw [if_neg hc]
|
||||
· rw [ite_eq_right hc]
|
||||
· rw [zeroCrossLongAnchor_begin_crossfree hne hbegin hend hEH]
|
||||
· exact le_max_right _ _
|
||||
refine minimal_iff_sound_and_necessaryRange.mpr ⟨hsound, ?_⟩
|
||||
intro k hklo hkhi
|
||||
unfold closedFormZeroCrossLong at hklo hkhi
|
||||
rw [if_neg hB] at hklo hkhi
|
||||
rw [ite_eq_right hB] at hklo hkhi
|
||||
dsimp only at hklo hkhi
|
||||
have htle := reportedAtEnd_le_endOvershoot_zero_cross_long hread hrev hmore hne hbegin
|
||||
hcross hend
|
||||
@@ -1845,9 +1848,9 @@ theorem minimal_closedForm_of_zero_cross_long_finite {r : RangeRead} {res : Resu
|
||||
by_cases hc : (reportedAtEnd r res = endOvershoot r ∨
|
||||
(((endOvershoot r - reportedAtEnd r res : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key)))
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, if_pos hc] at hklo
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, ite_eq_left hc] at hklo
|
||||
exact hklo
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, if_neg hc] at hklo
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, ite_eq_right hc] at hklo
|
||||
exact absurd hklo (not_le.mpr hkH)
|
||||
by_cases hte : reportedAtEnd r res = endOvershoot r
|
||||
· exact necessary_zero_cross_long_below_head_eq hsort hread hrev hmore hne hbegin
|
||||
@@ -1858,11 +1861,11 @@ theorem minimal_closedForm_of_zero_cross_long_finite {r : RangeRead} {res : Resu
|
||||
(((endOvershoot r - reportedAtEnd r res : ℕ) : ℕ∞) ≤
|
||||
intervalCard r.end_.key ((res.keys.head hne : Key) : WithTop Key)))
|
||||
· exact hc.resolve_left hte
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, if_neg hc] at hklo
|
||||
· rw [zeroCrossLongAnchor_begin_crossed hne hbegin hend hEH, ite_eq_right hc] at hklo
|
||||
exact absurd hklo (not_le.mpr hkH)
|
||||
exact necessary_zero_cross_long_below_head_lt hsort hread hrev hmore hne hbegin
|
||||
hcross hend (lt_of_le_of_ne htle hte) hEH hroom hB hkE hkH
|
||||
· push_neg at hkH
|
||||
· push Not at hkH
|
||||
by_cases hkB : (k : WithTop Key) < r.begin.key
|
||||
· by_cases hkHeq : ((res.keys.head hne : Key) : WithTop Key) = (k : WithTop Key)
|
||||
· have hkEq : k = res.keys.head hne := WithTop.coe_injective hkHeq.symm
|
||||
@@ -1871,20 +1874,20 @@ theorem minimal_closedForm_of_zero_cross_long_finite {r : RangeRead} {res : Resu
|
||||
lt_of_le_of_ne hkH hkHeq
|
||||
exact necessary_zero_cross_long_gap hsort hread hrev hmore hne hbegin hcross
|
||||
hend hHlt hkB
|
||||
· push_neg at hkB
|
||||
· push Not at hkB
|
||||
by_cases hkL : (k : WithTop Key) ≤
|
||||
((res.keys.getLast hne : Key) : WithTop Key)
|
||||
· exact necessary_zero_cross_long_between_last hread hne hcross hkB
|
||||
(WithTop.coe_le_coe.mp hkL)
|
||||
· push_neg at hkL
|
||||
· push Not at hkL
|
||||
have ht : reportedAtEnd r res < endOvershoot r := by
|
||||
by_contra hcon
|
||||
push_neg at hcon
|
||||
push Not at hcon
|
||||
have hte : reportedAtEnd r res = endOvershoot r := le_antisymm htle hcon
|
||||
have hltmax := hkhi
|
||||
rw [lt_max_iff] at hltmax
|
||||
rcases hltmax with hlt | hlt
|
||||
· rw [zeroCrossLongAnchor_end_eq r res hne hbegin hend, if_pos hte] at hlt
|
||||
· rw [zeroCrossLongAnchor_end_eq r res hne hbegin hend, ite_eq_left hte] at hlt
|
||||
exact absurd (lt_keyAfter_iff k (res.keys.getLast hne) |>.mp
|
||||
(WithTop.coe_lt_coe.mp hlt)) (not_le.mpr (WithTop.coe_lt_coe.mp hkL))
|
||||
· exact absurd hlt (not_lt.mpr hkB)
|
||||
|
||||
@@ -124,8 +124,8 @@ theorem headD_eq_head_zero_cross_trunc {l : List Key} (h : l ≠ []) :
|
||||
/-- At begin offset zero, a compatible crossed truncated read resolves its begin
|
||||
selector onto the reported head. -/
|
||||
theorem resolve_begin_eq_head_of_zero_crossed_more {db : DB} {r : RangeRead} {res : Result}
|
||||
(hcomp : RangeRead.Compatible db r res) (hrev : r.reverse = false)
|
||||
(hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hcomp : RangeRead.Compatible db r res) (_hrev : r.reverse = false)
|
||||
(_hmore : res.more = true) (hne : res.keys ≠ [])
|
||||
(hbegin : r.begin.offset = 0)
|
||||
(hcross : ((res.keys.head hne : Key) : WithTop Key) < r.begin.key) :
|
||||
resolve db r.begin = ((res.keys.head hne : Key) : WithTop Key) := by
|
||||
@@ -182,7 +182,8 @@ theorem completeKeys_filter_le_of_end_top {db : DB} {r : RangeRead} {H last : Ke
|
||||
(hbegin : resolve db r.begin = ((H : Key) : WithTop Key)) :
|
||||
(RangeRead.completeKeys db r).filter
|
||||
(fun k : Key => decide (k ≤ last)) =
|
||||
(db.keys.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤ (k : WithTop Key)))).filter
|
||||
(db.keys.filter (fun k : Key => decide (((H : Key) : WithTop Key) ≤ (k : WithTop
|
||||
Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last)) := by
|
||||
rw [completeKeys_eq_filter_ge_of_end_top (db := db) hrev hendkey hendoff hbegin]
|
||||
|
||||
@@ -263,7 +264,8 @@ theorem filter_end_le_split_between {db : DB} {E : WithTop Key} {head last : Key
|
||||
simp only [List.mem_filter, decide_eq_true_eq] at hy
|
||||
exact lt_of_lt_of_le (WithTop.coe_lt_coe.mp hx.2.2) (WithTop.coe_le_coe.mp hy.2.1)
|
||||
· intro k
|
||||
rw [List.mem_filter, List.mem_filter, List.mem_append, between, List.mem_filter, List.mem_filter]
|
||||
rw [List.mem_filter, List.mem_filter, List.mem_append, between, List.mem_filter,
|
||||
List.mem_filter]
|
||||
simp only [decide_eq_true_eq]
|
||||
constructor
|
||||
· rintro ⟨⟨hkdb, hEk⟩, hklast⟩
|
||||
@@ -340,7 +342,8 @@ theorem compatible_of_agree_zeroCrossTrunc {r : RangeRead} {res : Result}
|
||||
lt_end_key_of_lt_resolve_end_offset_one hend hlast_db1 hlt1
|
||||
have hcnt : ((db2.keys.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last))).length ≤ (r.end_.offset - 1).toNat := by
|
||||
have hzero : ((db2.keys.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop Key)))).filter
|
||||
have hzero : ((db2.keys.filter (fun k : Key => decide (r.end_.key ≤ (k : WithTop
|
||||
Key)))).filter
|
||||
(fun k : Key => decide (k ≤ last))).length = 0 := by
|
||||
rw [List.length_eq_zero_iff, List.filter_eq_nil_iff]
|
||||
intro k hk
|
||||
@@ -1124,7 +1127,8 @@ theorem compatible_of_agree_zeroCrossTruncNonposEnd {r : RangeRead} {res : Resul
|
||||
(k : WithTop Key) < r.begin.key) := by
|
||||
intro k hk2 hkb
|
||||
have hk1 : k ∈ db1.keys :=
|
||||
(hmk k (le_of_lt hkb.1) (lt_of_lt_of_le hkb.2 (by rw [hupper]; exact le_max_left _ _))).mpr hk2
|
||||
(hmk k (le_of_lt hkb.1) (lt_of_lt_of_le hkb.2 (by rw [hupper]; exact le_max_left _ _))).mpr
|
||||
hk2
|
||||
exact hno1 k hk1 hkb
|
||||
have hres2 : resolve db2 r.begin = ((head : Key) : WithTop Key) :=
|
||||
resolve_begin_eq_of_no_between_zero hbegin hhead_db2 hcross' hno2
|
||||
@@ -1402,12 +1406,12 @@ theorem necessary_zeroCross_trunc_between_end_head {r : RangeRead} {res : Result
|
||||
have hlt : e1 < G + rl := by
|
||||
have hb := hbig'
|
||||
rw [← hG] at hb
|
||||
rw [← ENat.coe_add] at hb
|
||||
exact ENat.coe_lt_coe.mp hb
|
||||
rw [← ENat.natCast_add] at hb
|
||||
exact ENat.natCast_lt_natCast.mp hb
|
||||
have hGle : n + 1 ≤ G := by
|
||||
rw [hn]; omega
|
||||
rw [← hG]
|
||||
exact ENat.coe_le_coe.mpr hGle
|
||||
exact ENat.natCast_le_natCast.mpr hGle
|
||||
obtain ⟨dbK, hKrange, hkK, hKlen⟩ :=
|
||||
exists_db_keysIn_avoid (B := r.end_.key) (E := ((head : Key) : WithTop Key))
|
||||
(k := k) (m := n) hcard
|
||||
@@ -1710,7 +1714,8 @@ theorem necessary_zeroCross_trunc_above_begin {r : RangeRead} {res : Result} {k
|
||||
set head : Key := res.keys.head hne with hhead
|
||||
set last : Key := res.keys.getLast hne with hlast
|
||||
have hsort : res.keys.SortedLT := RangeRead.compatible_sortedLT hcomp₀ hrev
|
||||
have hle_last : ∀ x ∈ res.keys, x ≤ last := fun x hx => (hsort.pairwise.imp le_of_lt).rel_getLast hx
|
||||
have hle_last : ∀ x ∈ res.keys, x ≤ last := fun x hx => (hsort.pairwise.imp
|
||||
le_of_lt).rel_getLast hx
|
||||
have hcross' : ((head : Key) : WithTop Key) < r.begin.key := by
|
||||
rw [hhead]; exact hcross
|
||||
have hk_notmem : k ∉ res.keys := by
|
||||
@@ -1778,7 +1783,7 @@ theorem necessary_zeroCross_trunc_above_begin {r : RangeRead} {res : Result} {k
|
||||
ring
|
||||
have hget : dbw.keys[res.keys.length]? = some k := by
|
||||
rw [hdbw, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
simp
|
||||
have hre : resolve dbw r.end_ = ((k : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor]; omega)]
|
||||
@@ -1825,7 +1830,6 @@ theorem necessary_zeroCross_trunc_above_begin {r : RangeRead} {res : Result} {k
|
||||
cases hE : r.end_.key with
|
||||
| top =>
|
||||
rw [anchor_of_top (s := r.end_) hE, hlen']
|
||||
push_cast
|
||||
rw [hend]
|
||||
ring
|
||||
| coe e =>
|
||||
@@ -1834,7 +1838,6 @@ theorem necessary_zeroCross_trunc_above_begin {r : RangeRead} {res : Result} {k
|
||||
rw [← countP_lt_coe (l := (dbw.erase k).keys) e, ← hE]
|
||||
exact hcount_end'
|
||||
rw [anchor_of_coe (s := r.end_) (v := e) hE, hce, hlen']
|
||||
push_cast
|
||||
rw [hend]
|
||||
ring
|
||||
have ht1 : 1 ≤ res.keys.length := List.length_pos_of_ne_nil hne
|
||||
@@ -1883,7 +1886,8 @@ theorem necessary_zeroCross_trunc_above_begin {r : RangeRead} {res : Result} {k
|
||||
exact ⟨fun h => h.2, fun h => ⟨hhead_le_all x hx, h⟩⟩]
|
||||
conv_lhs => rw [← List.dropLast_append_getLast hne, hlast]
|
||||
rw [List.filter_append]
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast := by
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast :=
|
||||
by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
@@ -2069,7 +2073,7 @@ theorem exists_witness_zeroCross_trunc_nonposEnd {r : RangeRead} {res : Result}
|
||||
have hDget? : dbw.keys[res.keys.length]? = some (F.head hFne) := by
|
||||
change D[res.keys.length]? = some (F.head hFne)
|
||||
rw [hD, List.getElem?_append]
|
||||
rw [if_neg (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [ite_eq_right (not_lt.mpr (le_refl _)), Nat.sub_self]
|
||||
rw [List.getElem?_eq_getElem (by rw [hFlen]; omega), List.head_eq_getElem hFne]
|
||||
have hre : resolve dbw r.end_ = ((F.head hFne : Key) : WithTop Key) := by
|
||||
rw [resolve, ite_eq_right (by rw [hanchor_end]; omega)]
|
||||
@@ -2158,7 +2162,7 @@ theorem exists_witness_zeroCross_trunc_nonposEnd {r : RangeRead} {res : Result}
|
||||
rw [hanchor_end', hEqInt, Int.toNat_natCast]
|
||||
have hD'get? : (dbw.erase k).keys[res.keys.length - 1]? = some last := by
|
||||
rw [hD', List.getElem?_append]
|
||||
rw [if_pos (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [ite_eq_left (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
rw [List.getElem?_eq_getElem (by omega : res.keys.length - 1 < res.keys.length)]
|
||||
congr 1
|
||||
rw [hlast, List.getLast_eq_getElem hne]
|
||||
@@ -2188,7 +2192,8 @@ theorem exists_witness_zeroCross_trunc_nonposEnd {r : RangeRead} {res : Result}
|
||||
exact ⟨fun h => h.2, fun h => ⟨hhead_le_all x hx, h⟩⟩]
|
||||
conv_lhs => rw [← List.dropLast_append_getLast hne, hlast]
|
||||
rw [List.filter_append]
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast := by
|
||||
have hfil : res.keys.dropLast.filter (fun x : Key => decide (x < last)) = res.keys.dropLast :=
|
||||
by
|
||||
rw [List.filter_eq_self]
|
||||
intro x hx
|
||||
rw [decide_eq_true_eq]
|
||||
|
||||
Reference in new issue
Block a user