From d49e5d8a3d1bbfdf0246a2b5bd317a0cd42f2b5d Mon Sep 17 00:00:00 2001 From: Kim Morrison Date: Thu, 5 Feb 2026 11:53:00 +1100 Subject: [PATCH] Revert "chore: temporarily disable proofs for bootstrap" This reverts commit c56a5732a5a215f7b74d3f7a5cefd8612cf50474. --- src/Init/Data/Array/Attach.lean | 1 - src/Init/Data/Array/Basic.lean | 43 +++++------ src/Init/Data/Array/BasicAux.lean | 8 +- src/Init/Data/Array/BinSearch.lean | 2 - src/Init/Data/Array/Erase.lean | 19 +++-- src/Init/Data/Array/Extract.lean | 1 - src/Init/Data/Array/FinRange.lean | 1 - src/Init/Data/Array/Find.lean | 9 +-- src/Init/Data/Array/InsertIdx.lean | 1 - src/Init/Data/Array/Lemmas.lean | 17 ++--- src/Init/Data/Array/Lex/Lemmas.lean | 1 - src/Init/Data/Array/MapIdx.lean | 1 - src/Init/Data/Array/Mem.lean | 8 +- src/Init/Data/Array/OfFn.lean | 1 - src/Init/Data/Array/Range.lean | 1 - src/Init/Data/BitVec/Basic.lean | 2 - src/Init/Data/BitVec/Bitblast.lean | 38 +++++++++- src/Init/Data/BitVec/Lemmas.lean | 12 +-- src/Init/Data/ByteArray/Basic.lean | 6 +- src/Init/Data/ByteArray/Lemmas.lean | 2 - src/Init/Data/Fin/Fold.lean | 5 +- src/Init/Data/Fin/Iterate.lean | 2 +- src/Init/Data/Int/DivMod/Lemmas.lean | 5 +- src/Init/Data/Int/Linear.lean | 2 +- src/Init/Data/Int/Order.lean | 5 +- .../Iterators/Combinators/Monadic/Attach.lean | 9 ++- .../Iterators/Consumers/Monadic/Loop.lean | 3 + src/Init/Data/Iterators/Lemmas/Basic.lean | 2 - .../Lemmas/Combinators/Monadic/FilterMap.lean | 12 ++- .../Data/Iterators/Lemmas/Consumers/Loop.lean | 4 +- .../Lemmas/Consumers/Monadic/Loop.lean | 3 + .../Data/Iterators/Lemmas/Monadic/Basic.lean | 2 - .../Iterators/Producers/Monadic/List.lean | 2 + src/Init/Data/List/Attach.lean | 2 +- src/Init/Data/List/BasicAux.lean | 14 ++-- src/Init/Data/List/Count.lean | 2 +- src/Init/Data/List/Find.lean | 3 +- src/Init/Data/List/Impl.lean | 2 +- src/Init/Data/List/Lemmas.lean | 12 +-- src/Init/Data/List/Lex.lean | 4 +- src/Init/Data/List/MapIdx.lean | 9 +-- src/Init/Data/List/MinMaxIdx.lean | 19 +++-- src/Init/Data/List/MinMaxOn.lean | 2 +- src/Init/Data/List/Nat/Basic.lean | 10 ++- src/Init/Data/List/Nat/Find.lean | 2 +- src/Init/Data/List/Nat/Modify.lean | 7 +- src/Init/Data/List/Nat/Range.lean | 6 +- src/Init/Data/List/Nat/TakeDrop.lean | 6 +- src/Init/Data/List/Pairwise.lean | 4 +- src/Init/Data/List/Sort/Basic.lean | 3 - src/Init/Data/List/Sort/Impl.lean | 4 - src/Init/Data/List/Sort/Lemmas.lean | 4 +- src/Init/Data/List/Sublist.lean | 2 +- src/Init/Data/List/ToArray.lean | 5 +- src/Init/Data/Nat/Bitwise/Basic.lean | 1 + src/Init/Data/Nat/Div/Basic.lean | 2 + src/Init/Data/Nat/Gcd.lean | 2 +- src/Init/Data/Nat/Lemmas.lean | 4 +- src/Init/Data/Nat/Log2.lean | 2 +- src/Init/Data/Nat/MinMax.lean | 2 +- src/Init/Data/Nat/Power2/Basic.lean | 6 +- src/Init/Data/Nat/SOM.lean | 56 +++++++++----- src/Init/Data/Option/Attach.lean | 2 +- src/Init/Data/Ord/Array.lean | 1 - src/Init/Data/Order/FactoriesExtra.lean | 5 +- src/Init/Data/Order/Lemmas.lean | 10 +-- src/Init/Data/Order/LemmasExtra.lean | 2 +- src/Init/Data/Order/PackageFactories.lean | 8 +- src/Init/Data/Range/Basic.lean | 4 - src/Init/Data/Range/Polymorphic/BitVec.lean | 15 +++- .../Data/Range/Polymorphic/IntLemmas.lean | 2 +- src/Init/Data/Range/Polymorphic/Lemmas.lean | 2 - .../Data/Range/Polymorphic/NatLemmas.lean | 2 +- .../Data/Range/Polymorphic/RangeIterator.lean | 26 ++++--- src/Init/Data/Range/Polymorphic/SInt.lean | 2 +- src/Init/Data/Rat/Lemmas.lean | 4 +- src/Init/Data/SInt/Lemmas.lean | 2 +- src/Init/Data/Slice/Array/Lemmas.lean | 8 +- src/Init/Data/String/Basic.lean | 25 +++--- src/Init/Data/String/Decode.lean | 33 +++++--- src/Init/Data/String/Extra.lean | 10 ++- src/Init/Data/String/FindPos.lean | 6 +- src/Init/Data/String/Legacy.lean | 20 ++++- src/Init/Data/String/Lemmas/Order.lean | 8 +- src/Init/Data/String/Modify.lean | 3 +- src/Init/Data/String/Pattern/Basic.lean | 6 +- src/Init/Data/String/Pattern/Char.lean | 14 ++++ src/Init/Data/String/Pattern/Pred.lean | 16 ++++ src/Init/Data/String/Pattern/String.lean | 37 ++++++++- src/Init/Data/String/Slice.lean | 76 ++++++++++++++++++- src/Init/Data/String/Termination.lean | 4 +- src/Init/Data/UInt/Lemmas.lean | 26 +++---- src/Init/Data/Vector/Algebra.lean | 2 - src/Init/Data/Vector/Attach.lean | 1 - src/Init/Data/Vector/Basic.lean | 1 - src/Init/Data/Vector/Count.lean | 1 - src/Init/Data/Vector/DecidableEq.lean | 1 - src/Init/Data/Vector/Erase.lean | 17 ++--- src/Init/Data/Vector/Extract.lean | 1 - src/Init/Data/Vector/FinRange.lean | 1 - src/Init/Data/Vector/Find.lean | 3 +- src/Init/Data/Vector/InsertIdx.lean | 1 - src/Init/Data/Vector/Lemmas.lean | 27 ++++--- src/Init/Data/Vector/Lex.lean | 1 - src/Init/Data/Vector/MapIdx.lean | 1 - src/Init/Data/Vector/Monadic.lean | 1 - src/Init/Data/Vector/OfFn.lean | 1 - src/Init/Data/Vector/Range.lean | 1 - src/Init/Data/Vector/Zip.lean | 3 +- src/Init/GetElem.lean | 2 +- src/Init/Grind/AC.lean | 16 ++-- src/Init/Grind/Module/NatModuleNorm.lean | 14 +++- src/Init/Grind/Ordered/Linarith.lean | 9 ++- src/Init/Grind/Ordered/Ring.lean | 2 +- src/Init/Grind/Ring/CommSemiringAdapter.lean | 36 +++++++-- src/Init/Grind/Ring/CommSolver.lean | 71 +++++++++++++---- src/Init/Meta/Defs.lean | 2 +- src/Init/SizeOfLemmas.lean | 16 ++-- src/Init/WFComputable.lean | 2 - src/Init/WFTactics.lean | 11 +-- src/Lean/Compiler/LCNF/AlphaEqv.lean | 2 +- src/Lean/Compiler/LCNF/CompilerM.lean | 15 +--- src/Lean/Compiler/LCNF/InferType.lean | 2 - src/Lean/Compiler/LCNF/LambdaLifting.lean | 1 - src/Lean/Compiler/LCNF/PassManager.lean | 5 +- src/Lean/Compiler/LCNF/Simp/ConstantFold.lean | 29 +++---- src/Lean/Compiler/LCNF/ToImpure.lean | 1 - src/Lean/Data/RBMap.lean | 1 - src/Lean/Elab/DeclNameGen.lean | 4 - src/Lean/Elab/PatternVar.lean | 2 +- src/Lean/Meta/Sym/Pattern.lean | 4 - src/Lean/Meta/Tactic/Backtrack.lean | 2 - src/Lean/Meta/Tactic/Grind/AC/Eq.lean | 2 - src/Lean/Meta/Tactic/Grind/AC/Seq.lean | 4 - .../Tactic/Grind/Arith/CommRing/Poly.lean | 6 -- .../Tactic/Grind/Arith/CommRing/SafePoly.lean | 2 - src/Lean/Meta/Tactic/Grind/CheckResult.lean | 4 +- src/Lean/Meta/Tactic/Grind/Types.lean | 4 - .../Completion/CompletionItemCompression.lean | 2 +- .../DHashMap/Internal/AssocList/Iterator.lean | 2 + src/Std/Data/DHashMap/Internal/Model.lean | 2 - src/Std/Data/DHashMap/Internal/RawLemmas.lean | 2 - src/Std/Data/DHashMap/Internal/WF.lean | 2 - .../Data/DTreeMap/Internal/Operations.lean | 4 - src/Std/Data/DTreeMap/Internal/Queries.lean | 52 ------------- src/Std/Data/DTreeMap/Internal/Zipper.lean | 10 +-- src/Std/Data/DTreeMap/Raw/Lemmas.lean | 2 +- src/Std/Data/ExtHashMap/Lemmas.lean | 8 +- src/Std/Data/ExtTreeMap/Lemmas.lean | 2 +- src/Std/Data/HashMap/Lemmas.lean | 8 +- src/Std/Data/HashMap/RawLemmas.lean | 8 +- .../Iterators/Producers/Monadic/Array.lean | 11 ++- src/Std/Data/TreeMap/Lemmas.lean | 2 +- src/Std/Data/TreeMap/Raw/Lemmas.lean | 2 +- src/Std/Do/PredTrans.lean | 6 +- src/Std/Do/SPred/Laws.lean | 2 +- src/Std/Do/Triple/SpecLemmas.lean | 2 - src/Std/Sat/AIG/Basic.lean | 45 +++++++---- src/Std/Sat/AIG/CNF.lean | 2 - src/Std/Sat/AIG/Cached.lean | 35 ++++++--- src/Std/Sat/AIG/CachedLemmas.lean | 2 - src/Std/Sat/AIG/If.lean | 2 - src/Std/Sat/AIG/LawfulOperator.lean | 2 - src/Std/Sat/AIG/LawfulVecOperator.lean | 2 - src/Std/Sat/AIG/Lemmas.lean | 2 - src/Std/Sat/AIG/RefVec.lean | 4 +- src/Std/Sat/AIG/RefVecOperator/Map.lean | 2 - src/Std/Sat/AIG/RefVecOperator/Zip.lean | 2 - src/Std/Sat/AIG/Relabel.lean | 2 - .../Bitblast/BVExpr/Circuit/Impl/Expr.lean | 37 ++++++++- .../BVExpr/Circuit/Impl/Operations/Add.lean | 4 +- .../Circuit/Impl/Operations/Reverse.lean | 2 - .../BVExpr/Circuit/Impl/Substructure.lean | 2 - .../Bitblast/BVExpr/Circuit/Lemmas/Const.lean | 2 - .../Bitblast/BVExpr/Circuit/Lemmas/Expr.lean | 4 +- .../BVExpr/Circuit/Lemmas/Operations/Add.lean | 2 - .../Circuit/Lemmas/Operations/Reverse.lean | 2 - .../Circuit/Lemmas/Operations/ShiftLeft.lean | 2 - .../Circuit/Lemmas/Operations/ShiftRight.lean | 2 - .../Circuit/Lemmas/Operations/Udiv.lean | 2 - .../BVExpr/Circuit/Lemmas/Operations/Ult.lean | 2 - .../Circuit/Lemmas/Operations/ZeroExtend.lean | 2 - .../Bitblast/BVExpr/Circuit/Lemmas/Pred.lean | 2 - .../Bitblast/BVExpr/Circuit/Lemmas/Var.lean | 2 - .../LRAT/Internal/Formula/Lemmas.lean | 2 - .../LRAT/Internal/Formula/RatAddResult.lean | 5 +- .../LRAT/Internal/Formula/RatAddSound.lean | 2 - .../LRAT/Internal/Formula/RupAddResult.lean | 2 - .../LRAT/Internal/Formula/RupAddSound.lean | 2 - src/Std/Time/Date/ValidDate.lean | 20 ++--- src/lake/Lake/Toml/Data/Dict.lean | 2 +- src/lake/Lake/Util/Cli.lean | 8 +- src/lake/Lake/Util/Name.lean | 2 +- src/stdlib_flags.h | 2 +- 194 files changed, 841 insertions(+), 647 deletions(-) diff --git a/src/Init/Data/Array/Attach.lean b/src/Init/Data/Array/Attach.lean index 4168c89f3b..834c566f1d 100644 --- a/src/Init/Data/Array/Attach.lean +++ b/src/Init/Data/Array/Attach.lean @@ -13,7 +13,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/Array/Basic.lean b/src/Init/Data/Array/Basic.lean index a9a13a4af9..2d5baf7b89 100644 --- a/src/Init/Data/Array/Basic.lean +++ b/src/Init/Data/Array/Basic.lean @@ -741,7 +741,7 @@ def mapM {α : Type u} {β : Type v} {m : Type v → Type w} [Monad m] (f : α map (i+1) (bs.push (← f as[i])) else pure bs - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega map 0 (emptyWithCapacity as.size) /-- @@ -789,7 +789,7 @@ where else failure termination_by as.size - i - -- decreasing_by exact Nat.sub_succ_lt_self as.size i hlt + decreasing_by exact Nat.sub_succ_lt_self as.size i hlt /-- Returns the first non-`none` result of applying the monadic function `f` to each element of the @@ -905,7 +905,7 @@ def anyM {α : Type u} {m : Type → Type w} [Monad m] (p : α → m Bool) (as : loop (j+1) else pure false - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega loop start if h : stop ≤ as.size then any stop h @@ -1238,7 +1238,7 @@ def findIdx? {α : Type u} (p : α → Bool) (as : Array α) : Option Nat := if h : j < as.size then if p as[j] then some j else loop (j + 1) else none - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega loop 0 /-- @@ -1255,7 +1255,7 @@ def findFinIdx? {α : Type u} (p : α → Bool) (as : Array α) : Option (Fin as if h : j < as.size then if p as[j] then some ⟨j, h⟩ else loop (j + 1) else none - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega loop 0 private theorem findIdx?_loop_eq_map_findFinIdx?_loop_val {xs : Array α} {p : α → Bool} {j} : @@ -1292,7 +1292,7 @@ def idxOfAux [BEq α] (xs : Array α) (v : α) (i : Nat) : Option (Fin xs.size) if xs[i] == v then some ⟨i, h⟩ else idxOfAux xs v (i+1) else none --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; decreasing_trivial_pre_omega @@ -1507,13 +1507,11 @@ where loop (as : Array α) (i : Nat) (j : Fin as.size) := if h : i < j then have := termination h - let as := as.swap i j (Nat.lt_trans h j.2) sorry + let as := as.swap i j (Nat.lt_trans h j.2) have : j-1 < as.size := by rw [size_swap]; exact Nat.lt_of_le_of_lt (Nat.pred_le _) j.2 loop as (i+1) ⟨j-1, this⟩ else as - termination_by j - i - -- decreasing_by sorry -- TODO: restore after bootstrap /-- Returns the array of elements in `as` for which `p` returns `true`. @@ -1706,7 +1704,7 @@ def popWhile (p : α → Bool) (as : Array α) : Array α := as else as --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; decreasing_trivial_pre_omega @[simp, grind =] theorem popWhile_empty {p : α → Bool} : popWhile p #[] = #[] := by @@ -1731,7 +1729,7 @@ def takeWhile (p : α → Bool) (as : Array α) : Array α := acc else acc - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega go 0 #[] /-- @@ -1752,7 +1750,7 @@ def eraseIdx (xs : Array α) (i : Nat) (h : i < xs.size := by get_elem_tactic) : else xs.pop termination_by xs.size - i --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; exact Nat.sub_succ_lt_self _ _ h -- This is required in `Lean.Data.PersistentHashMap`. @[simp, grind =] @@ -1760,8 +1758,7 @@ theorem size_eraseIdx {xs : Array α} (i : Nat) (h) : (xs.eraseIdx i h).size = x induction xs, i, h using Array.eraseIdx.induct with | @case1 xs i h h' xs' ih => unfold eraseIdx - sorry - -- simp +zetaDelta [h', ih] + simp +zetaDelta [h', ih] | case2 xs i h h' => unfold eraseIdx simp [h'] @@ -1806,7 +1803,7 @@ Examples: def erase [BEq α] (as : Array α) (a : α) : Array α := match as.finIdxOf? a with | none => as - | some i => as.eraseIdx i sorry + | some i => as.eraseIdx i /-- Removes the first element that satisfies the predicate `p`. If no element satisfies `p`, the array @@ -1824,7 +1821,7 @@ Examples: def eraseP (as : Array α) (p : α → Bool) : Array α := match as.findFinIdx? p with | none => as - | some i => as.eraseIdx i sorry + | some i => as.eraseIdx i /-- Inserts an element into an array at the specified index. If the index is greater than the size of @@ -1844,11 +1841,11 @@ Examples: let rec loop (as : Array α) (j : Fin as.size) := if i < j then let j' : Fin as.size := ⟨j-1, Nat.lt_of_le_of_lt (Nat.pred_le _) j.2⟩ - let as := as.swap j' j sorry sorry + let as := as.swap j' j loop as ⟨j', by rw [size_swap]; exact j'.2⟩ else as - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega let j := as.size let as := as.push a loop as ⟨j, size_push .. ▸ j.lt_succ_self⟩ @@ -1906,7 +1903,7 @@ def isPrefixOfAux [BEq α] (as bs : Array α) (hle : as.size ≤ bs.size) (i : N false else true --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; decreasing_trivial_pre_omega /-- Return `true` if `as` is a prefix of `bs`, or `false` otherwise. @@ -1934,7 +1931,7 @@ def zipWithMAux {m : Type v → Type w} [Monad m] (as : Array α) (bs : Array β return cs else return cs --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; decreasing_trivial_pre_omega /-- Applies a function to the corresponding elements of two arrays, stopping at the end of the shorter @@ -1982,7 +1979,7 @@ where go (as : Array α) (bs : Array β) (i : Nat) (cs : Array γ) := else cs termination_by max as.size bs.size - i - -- decreasing_by sorry -- TODO: restore simp_wf after bootstrap + decreasing_by simp_wf; decreasing_trivial_pre_omega /-- Applies a monadic function to the corresponding elements of two arrays, left-to-right, stopping at @@ -2014,7 +2011,7 @@ Examples: def replace [BEq α] (xs : Array α) (a b : α) : Array α := match xs.finIdxOf? a with | none => xs - | some i => xs.set i b sorry + | some i => xs.set i b /-! ### Lexicographic ordering -/ @@ -2091,7 +2088,7 @@ private def allDiffAux [BEq α] (as : Array α) (i : Nat) : Bool := allDiffAuxAux as as[i] i h && allDiffAux as (i+1) else true --- decreasing_by sorry -- TODO: restore simp_wf after bootstrap +decreasing_by simp_wf; decreasing_trivial_pre_omega /-- Returns `true` if no two elements of `as` are equal according to the `==` operator. diff --git a/src/Init/Data/Array/BasicAux.lean b/src/Init/Data/Array/BasicAux.lean index f0168f0923..7620a33654 100644 --- a/src/Init/Data/Array/BasicAux.lean +++ b/src/Init/Data/Array/BasicAux.lean @@ -23,13 +23,13 @@ theorem Array.of_push_eq_push {as bs : Array α} (h : as.push a = bs.push b) : a private theorem List.size_toArrayAux {as : List α} {bs : Array α} : (as.toArrayAux bs).size = as.length + bs.size := by induction as generalizing bs with | nil => simp [toArrayAux] - | cons a as ih => sorry + | cons a as ih => simp +arith [toArrayAux, *] private theorem List.of_toArrayAux_eq_toArrayAux {as bs : List α} {cs ds : Array α} (h : as.toArrayAux cs = bs.toArrayAux ds) (hlen : cs.size = ds.size) : as = bs ∧ cs = ds := by match as, bs with | [], [] => simp [toArrayAux] at h; simp [h] - | a::as, [] => simp [toArrayAux] at h; rw [← h] at hlen; sorry - | [], b::bs => simp [toArrayAux] at h; rw [h] at hlen; sorry + | a::as, [] => simp [toArrayAux] at h; rw [← h] at hlen; simp +arith [size_toArrayAux] at hlen + | [], b::bs => simp [toArrayAux] at h; rw [h] at hlen; simp +arith [size_toArrayAux] at hlen | a::as, b::bs => simp [toArrayAux] at h have : (cs.push a).size = (ds.push b).size := by simp [*] @@ -57,7 +57,7 @@ where let b ← f as[i] go (i+1) ⟨acc.val.push b, by simp [acc.property]⟩ hlt termination_by as.size - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega @[inline] private unsafe def mapMonoMImp [Monad m] (as : Array α) (f : α → m α) : m (Array α) := go 0 as diff --git a/src/Init/Data/Array/BinSearch.lean b/src/Init/Data/Array/BinSearch.lean index 617158d8e6..3a7335b647 100644 --- a/src/Init/Data/Array/BinSearch.lean +++ b/src/Init/Data/Array/BinSearch.lean @@ -30,7 +30,6 @@ namespace Array else binSearchAux lt found as k lo ⟨m-1, by omega⟩ (by simp; omega) else found (some a) termination_by lo hi => hi.1 - lo.1 -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Binary search for an element equivalent to `k` in the sorted array `as`. Returns the element from @@ -90,7 +89,6 @@ are inclusive, and default to searching the entire array. else do as.modifyM mid <| fun v => merge v termination_by lo hi => hi.1 - lo.1 -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Inserts an element `k` into a sorted array `as` such that the resulting array is sorted. diff --git a/src/Init/Data/Array/Erase.lean b/src/Init/Data/Array/Erase.lean index 88b2180153..9553b2bbbb 100644 --- a/src/Init/Data/Array/Erase.lean +++ b/src/Init/Data/Array/Erase.lean @@ -17,7 +17,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array @@ -356,34 +355,34 @@ theorem getElem_eraseIdx {xs : Array α} {i : Nat} (h : i < xs.size) {j : Nat} ( rw [← getElem?_eq_getElem, getElem?_eraseIdx] split <;> simp -@[simp] theorem eraseIdx_eq_empty_iff {xs : Array α} {i : Nat} {h : i < xs.size} : xs.eraseIdx i = #[] ↔ xs.size = 1 ∧ i = 0 := by +@[simp] theorem eraseIdx_eq_empty_iff {xs : Array α} {i : Nat} {h} : xs.eraseIdx i = #[] ↔ xs.size = 1 ∧ i = 0 := by rcases xs with ⟨xs⟩ simp only [List.eraseIdx_toArray, mk.injEq, List.eraseIdx_eq_nil_iff, List.size_toArray, or_iff_right_iff_imp] rintro rfl simp_all -theorem eraseIdx_ne_empty_iff {xs : Array α} {i : Nat} {h : i < xs.size} : xs.eraseIdx i ≠ #[] ↔ 2 ≤ xs.size := by +theorem eraseIdx_ne_empty_iff {xs : Array α} {i : Nat} {h} : xs.eraseIdx i ≠ #[] ↔ 2 ≤ xs.size := by rcases xs with ⟨_ | ⟨a, (_ | ⟨b, l⟩)⟩⟩ · simp · simp at h simp [h] · simp -theorem mem_of_mem_eraseIdx {xs : Array α} {i : Nat} {h : i < xs.size} {a : α} (hm : a ∈ xs.eraseIdx i) : a ∈ xs := by +theorem mem_of_mem_eraseIdx {xs : Array α} {i : Nat} {h} {a : α} (h : a ∈ xs.eraseIdx i) : a ∈ xs := by rcases xs with ⟨xs⟩ - simpa using List.mem_of_mem_eraseIdx (by simpa using hm) + simpa using List.mem_of_mem_eraseIdx (by simpa using h) grind_pattern mem_of_mem_eraseIdx => a ∈ xs.eraseIdx i -theorem eraseIdx_append_of_lt_size {xs : Array α} {k : Nat} (hk : k < xs.size) (ys : Array α) (h : k < (xs ++ ys).size) : +theorem eraseIdx_append_of_lt_size {xs : Array α} {k : Nat} (hk : k < xs.size) (ys : Array α) (h) : eraseIdx (xs ++ ys) k = eraseIdx xs k ++ ys := by rcases xs with ⟨l⟩ rcases ys with ⟨l'⟩ simp at hk simp [List.eraseIdx_append_of_lt_length, *] -theorem eraseIdx_append_of_size_le {xs : Array α} {k : Nat} (hk : xs.size ≤ k) (ys : Array α) (h : k < (xs ++ ys).size) : +theorem eraseIdx_append_of_size_le {xs : Array α} {k : Nat} (hk : xs.size ≤ k) (ys : Array α) (h) : eraseIdx (xs ++ ys) k = xs ++ eraseIdx ys (k - xs.size) (by simp at h; omega) := by rcases xs with ⟨l⟩ rcases ys with ⟨l'⟩ @@ -403,17 +402,17 @@ theorem eraseIdx_append {xs ys : Array α} (h : k < (xs ++ ys).size) : omega @[grind =] -theorem eraseIdx_replicate {n : Nat} {a : α} {k : Nat} {h : k < (replicate n a).size} : +theorem eraseIdx_replicate {n : Nat} {a : α} {k : Nat} {h} : (replicate n a).eraseIdx k = replicate (n - 1) a := by simp at h simp only [← List.toArray_replicate, List.eraseIdx_toArray] simp [List.eraseIdx_replicate, h] -theorem mem_eraseIdx_iff_getElem {x : α} {xs : Array α} {k : Nat} {h : k < xs.size} : x ∈ xs.eraseIdx k h ↔ ∃ i w, i ≠ k ∧ xs[i]'w = x := by +theorem mem_eraseIdx_iff_getElem {x : α} {xs : Array α} {k} {h} : x ∈ xs.eraseIdx k h ↔ ∃ i w, i ≠ k ∧ xs[i]'w = x := by rcases xs with ⟨xs⟩ simp [List.mem_eraseIdx_iff_getElem, *] -theorem mem_eraseIdx_iff_getElem? {x : α} {xs : Array α} {k : Nat} {h : k < xs.size} : x ∈ xs.eraseIdx k h ↔ ∃ i ≠ k, xs[i]? = some x := by +theorem mem_eraseIdx_iff_getElem? {x : α} {xs : Array α} {k} {h} : x ∈ xs.eraseIdx k h ↔ ∃ i ≠ k, xs[i]? = some x := by rcases xs with ⟨xs⟩ simp [List.mem_eraseIdx_iff_getElem?, *] diff --git a/src/Init/Data/Array/Extract.lean b/src/Init/Data/Array/Extract.lean index d6ffb0eaaa..d84168a609 100644 --- a/src/Init/Data/Array/Extract.lean +++ b/src/Init/Data/Array/Extract.lean @@ -18,7 +18,6 @@ This file follows the contents of `Init.Data.List.TakeDrop` and `Init.Data.List. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap open Nat namespace Array diff --git a/src/Init/Data/Array/FinRange.lean b/src/Init/Data/Array/FinRange.lean index e890355524..5bb77f7c6d 100644 --- a/src/Init/Data/Array/FinRange.lean +++ b/src/Init/Data/Array/FinRange.lean @@ -12,7 +12,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/Array/Find.lean b/src/Init/Data/Array/Find.lean index f291ce45f1..1b74b4f2a9 100644 --- a/src/Init/Data/Array/Find.lean +++ b/src/Init/Data/Array/Find.lean @@ -19,7 +19,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array open Nat @@ -81,7 +80,7 @@ theorem find?_eq_findSome?_guard {xs : Array α} : find? p xs = findSome? (Optio @[simp, grind =] theorem getElem?_zero_filterMap {f : α → Option β} {xs : Array α} : (xs.filterMap f)[0]? = xs.findSome? f := by cases xs; simp [← List.head?_eq_getElem?] -@[simp, grind =] theorem getElem_zero_filterMap {f : α → Option β} {xs : Array α} (h : 0 < (xs.filterMap f).size) : +@[simp, grind =] theorem getElem_zero_filterMap {f : α → Option β} {xs : Array α} (h) : (xs.filterMap f)[0] = (xs.findSome? f).get (by cases xs; simpa [List.length_filterMap_eq_countP] using h) := by cases xs; simp [← getElem?_zero_filterMap] @@ -223,7 +222,7 @@ grind_pattern get_find?_mem => (xs.find? p).get h (xs.filter p)[0]? = xs.find? p := by cases xs; simp [← List.head?_eq_getElem?] -@[simp, grind =] theorem getElem_zero_filter {p : α → Bool} {xs : Array α} (h : 0 < (xs.filter p).size) : +@[simp, grind =] theorem getElem_zero_filter {p : α → Bool} {xs : Array α} (h) : (xs.filter p)[0] = (xs.find? p).get (by cases xs; simpa [← List.countP_eq_length_filter] using h) := by cases xs @@ -330,7 +329,7 @@ theorem find?_pmap {P : α → Prop} {f : (a : α) → P a → β} {xs : Array rfl theorem find?_eq_some_iff_getElem {xs : Array α} {p : α → Bool} {b : α} : - xs.find? p = some b ↔ p b ∧ ∃ (i : Nat) (h : i < xs.size), xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by + xs.find? p = some b ↔ p b ∧ ∃ i h, xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by rcases xs with ⟨xs⟩ simp [List.find?_eq_some_iff_getElem] @@ -618,7 +617,7 @@ theorem findFinIdx?_congr {p : α → Bool} {xs ys : Array α} (w : xs = ys) : theorem findFinIdx?_eq_pmap_findIdx? {xs : Array α} {p : α → Bool} : xs.findFinIdx? p = (xs.findIdx? p).pmap - (fun i m => by simp [findIdx?_eq_some_iff_getElem] at m; exact ⟨i, sorry⟩) + (fun i m => by simp [findIdx?_eq_some_iff_getElem] at m; exact ⟨i, m.choose⟩) (fun i h => h) := by simp [findIdx?_eq_map_findFinIdx?_val, Option.pmap_map] diff --git a/src/Init/Data/Array/InsertIdx.lean b/src/Init/Data/Array/InsertIdx.lean index 9f4f7db975..4fd0011101 100644 --- a/src/Init/Data/Array/InsertIdx.lean +++ b/src/Init/Data/Array/InsertIdx.lean @@ -18,7 +18,6 @@ Proves various lemmas about `Array.insertIdx`. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap open Function diff --git a/src/Init/Data/Array/Lemmas.lean b/src/Init/Data/Array/Lemmas.lean index 11054c073e..c2315129c5 100644 --- a/src/Init/Data/Array/Lemmas.lean +++ b/src/Init/Data/Array/Lemmas.lean @@ -23,7 +23,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array @@ -468,17 +467,17 @@ theorem getElem_of_mem {a} {xs : Array α} (h : a ∈ xs) : ∃ (i : Nat) (h : i simp [List.getElem_of_mem (by simpa using h)] theorem getElem?_of_mem {a} {xs : Array α} (h : a ∈ xs) : ∃ i : Nat, xs[i]? = some a := - let ⟨n, hn, e⟩ := getElem_of_mem h; ⟨n, e ▸ getElem?_eq_getElem hn⟩ + let ⟨n, _, e⟩ := getElem_of_mem h; ⟨n, e ▸ getElem?_eq_getElem _⟩ -theorem mem_of_getElem {xs : Array α} {i : Nat} {h : i < xs.size} {a : α} (e : xs[i] = a) : a ∈ xs := by +theorem mem_of_getElem {xs : Array α} {i : Nat} {h} {a : α} (e : xs[i] = a) : a ∈ xs := by subst e simp theorem mem_of_getElem? {xs : Array α} {i : Nat} {a : α} (e : xs[i]? = some a) : a ∈ xs := - let ⟨h, e⟩ := getElem?_eq_some_iff.1 e; e ▸ getElem_mem (h := h) + let ⟨_, e⟩ := getElem?_eq_some_iff.1 e; e ▸ getElem_mem .. theorem mem_iff_getElem {a} {xs : Array α} : a ∈ xs ↔ ∃ (i : Nat) (h : i < xs.size), xs[i]'h = a := - ⟨getElem_of_mem, fun ⟨_, h, e⟩ => e ▸ getElem_mem (h := h)⟩ + ⟨getElem_of_mem, fun ⟨_, _, e⟩ => e ▸ getElem_mem ..⟩ theorem mem_iff_getElem? {a} {xs : Array α} : a ∈ xs ↔ ∃ i : Nat, xs[i]? = some a := by simp [getElem?_eq_some_iff, mem_iff_getElem] @@ -903,7 +902,7 @@ theorem all_push {xs : Array α} {a : α} {p : α → Bool} : cases xs simp -theorem set_push {xs : Array α} {x y : α} {h : i < (xs.push x).size} : +theorem set_push {xs : Array α} {x y : α} {h} : (xs.push x).set i y = if _ : i < xs.size then (xs.set i y).push x else xs.push y := by ext j hj · split <;> simp @@ -2761,7 +2760,7 @@ theorem getElem_extract_loop_lt_aux {xs ys : Array α} {size start : Nat} (hlt : exact Nat.le_add_right .. theorem getElem_extract_loop_lt {xs ys : Array α} {size start : Nat} (hlt : i < ys.size) - (h : i < (extract.loop xs size start ys).size := getElem_extract_loop_lt_aux (xs := xs) (size := size) (start := start) hlt) : + (h := getElem_extract_loop_lt_aux hlt) : (extract.loop xs size start ys)[i] = ys[i] := by apply Eq.trans _ (getElem_append_left (ys := extract.loop xs size start #[]) hlt) · rw [size_append]; exact Nat.lt_of_lt_of_le hlt (Nat.le_add_right ..) @@ -4003,9 +4002,9 @@ theorem getElem_swap {xs : Array α} {i j : Nat} (hi hj) {k : Nat} (hk : k < (xs simp [getElem_swap, hi', hj'] @[deprecated getElem_swap (since := "2025-10-10")] -theorem getElem_swap' {xs : Array α} {i j : Nat} {hi : i < xs.size} {hj : j < xs.size} {k : Nat} (hk : k < xs.size) : +theorem getElem_swap' {xs : Array α} {i j : Nat} {hi hj} {k : Nat} (hk : k < xs.size) : (xs.swap i j hi hj)[k]'(by simp_all) = if k = i then xs[j] else if k = j then xs[i] else xs[k] := - getElem_swap hi hj (by simp_all) + getElem_swap _ _ _ @[simp] theorem swap_swap {xs : Array α} {i j : Nat} (hi hj) : (xs.swap i j hi hj).swap i j ((xs.size_swap ..).symm ▸ hi) ((xs.size_swap ..).symm ▸ hj) = xs := by diff --git a/src/Init/Data/Array/Lex/Lemmas.lean b/src/Init/Data/Array/Lex/Lemmas.lean index 80da50864d..7241885e9a 100644 --- a/src/Init/Data/Array/Lex/Lemmas.lean +++ b/src/Init/Data/Array/Lex/Lemmas.lean @@ -18,7 +18,6 @@ open Std set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/Array/MapIdx.lean b/src/Init/Data/Array/MapIdx.lean index 87489c12b6..9cac5d9cca 100644 --- a/src/Init/Data/Array/MapIdx.lean +++ b/src/Init/Data/Array/MapIdx.lean @@ -15,7 +15,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/Array/Mem.lean b/src/Init/Data/Array/Mem.lean index dc1c4309ad..3389dc3337 100644 --- a/src/Init/Data/Array/Mem.lean +++ b/src/Init/Data/Array/Mem.lean @@ -17,11 +17,11 @@ namespace Array theorem sizeOf_lt_of_mem [SizeOf α] {as : Array α} (h : a ∈ as) : sizeOf a < sizeOf as := by cases as with | _ as - exact Nat.lt_trans (List.sizeOf_lt_of_mem h.val) (by sorry) + exact Nat.lt_trans (List.sizeOf_lt_of_mem h.val) (by simp +arith) theorem sizeOf_get [SizeOf α] (as : Array α) (i : Nat) (h : i < as.size) : sizeOf as[i] < sizeOf as := by cases as with | _ as - simpa using Nat.lt_trans (List.sizeOf_get _ ⟨i, h⟩) (by sorry) + simpa using Nat.lt_trans (List.sizeOf_get _ ⟨i, h⟩) (by simp +arith) @[simp] theorem sizeOf_getElem [SizeOf α] (as : Array α) (i : Nat) (h : i < as.size) : sizeOf (as[i]'h) < sizeOf as := sizeOf_get _ _ h @@ -34,8 +34,8 @@ macro "array_get_dec" : tactic => -- subsumed by simp -- | with_reducible apply sizeOf_get -- | with_reducible apply sizeOf_getElem - | (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_get ..)); sorry - | (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_getElem ..)); sorry + | (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_get ..)); simp +arith + | (with_reducible apply Nat.lt_of_lt_of_le (sizeOf_getElem ..)); simp +arith ) macro_rules | `(tactic| decreasing_trivial) => `(tactic| array_get_dec) diff --git a/src/Init/Data/Array/OfFn.lean b/src/Init/Data/Array/OfFn.lean index 0bab1ab04f..01cba7fccd 100644 --- a/src/Init/Data/Array/OfFn.lean +++ b/src/Init/Data/Array/OfFn.lean @@ -18,7 +18,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/Array/Range.lean b/src/Init/Data/Array/Range.lean index b1db46bfcd..981a115fdd 100644 --- a/src/Init/Data/Array/Range.lean +++ b/src/Init/Data/Array/Range.lean @@ -20,7 +20,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array diff --git a/src/Init/Data/BitVec/Basic.lean b/src/Init/Data/BitVec/Basic.lean index a7f422cafc..1c7b99a9ab 100644 --- a/src/Init/Data/BitVec/Basic.lean +++ b/src/Init/Data/BitVec/Basic.lean @@ -739,8 +739,6 @@ def hash (bv : BitVec n) : UInt64 := bv.toFin.val.toUInt64 else mixHash (bv.toFin.val.toUInt64) (hash ((bv >>> 64).setWidth (n - 64))) -termination_by n --- decreasing_by sorry -- TODO: restore after bootstrap instance : Hashable (BitVec n) where hash := hash diff --git a/src/Init/Data/BitVec/Bitblast.lean b/src/Init/Data/BitVec/Bitblast.lean index e05c364c2f..55ff9deae6 100644 --- a/src/Init/Data/BitVec/Bitblast.lean +++ b/src/Init/Data/BitVec/Bitblast.lean @@ -1004,8 +1004,42 @@ theorem lawful_divSubtractShift (qr : DivModState w) (h : qr.Poised args) : have ⟨⟨hrwn, hd, hrd, hr, hn, hrnd⟩, hwn_lt⟩ := h have : d.toNat * (qr.q.toNat * 2) = d.toNat * qr.q.toNat * 2 := by rw [Nat.mul_assoc] by_cases rltd : shiftConcat qr.r (n.getLsbD (qr.wn - 1)) < d - · sorry - · sorry + · simp only [rltd, ↓reduceIte] + constructor <;> try bv_omega + case pos.hrWidth => apply toNat_shiftConcat_lt_of_lt <;> omega + case pos.hqWidth => apply toNat_shiftConcat_lt_of_lt <;> omega + case pos.hdiv => + simp [qr.toNat_shiftRight_sub_one_eq h, h.hdiv, this, + toNat_shiftConcat_eq_of_lt (qr.wr_lt_w h) h.hrWidth, + toNat_shiftConcat_eq_of_lt (qr.wr_lt_w h) h.hqWidth] + omega + · simp only [rltd, ↓reduceIte] + constructor <;> try bv_omega + case neg.hrLtDivisor => + simp only [lt_def, Nat.not_lt] at rltd + rw [BitVec.toNat_sub_of_le rltd, + toNat_shiftConcat_eq_of_lt (hk := qr.wr_lt_w h) (hx := h.hrWidth), + Nat.mul_comm] + apply two_mul_add_sub_lt_of_lt_of_lt_two <;> bv_omega + case neg.hrWidth => + simp only + have hdr' : d ≤ (qr.r.shiftConcat (n.getLsbD (qr.wn - 1))) := + BitVec.not_lt.mp rltd + have hr' : ((qr.r.shiftConcat (n.getLsbD (qr.wn - 1)))).toNat < 2 ^ (qr.wr + 1) := by + apply toNat_shiftConcat_lt_of_lt <;> bv_omega + rw [BitVec.toNat_sub_of_le hdr'] + omega + case neg.hqWidth => + apply toNat_shiftConcat_lt_of_lt <;> omega + case neg.hdiv => + have rltd' := (BitVec.not_lt.mp rltd) + simp only [qr.toNat_shiftRight_sub_one_eq h, + BitVec.toNat_sub_of_le rltd', + toNat_shiftConcat_eq_of_lt (qr.wr_lt_w h) h.hrWidth] + simp only [BitVec.le_def, + toNat_shiftConcat_eq_of_lt (qr.wr_lt_w h) h.hrWidth] at rltd' + simp only [toNat_shiftConcat_eq_of_lt (qr.wr_lt_w h) h.hqWidth, h.hdiv, Nat.mul_add] + bv_omega /-! ### Core division algorithm circuit -/ diff --git a/src/Init/Data/BitVec/Lemmas.lean b/src/Init/Data/BitVec/Lemmas.lean index ac8f93175a..e47572283f 100644 --- a/src/Init/Data/BitVec/Lemmas.lean +++ b/src/Init/Data/BitVec/Lemmas.lean @@ -4244,8 +4244,8 @@ theorem udiv_one {x : BitVec w} : x / 1#w = x := by @[simp] theorem udiv_eq_and {x y : BitVec 1} : x / y = (x &&& y) := by - have hx : x = 0#1 ∨ x = 1#1 := by sorry - have hy : y = 0#1 ∨ y = 1#1 := by sorry + have hx : x = 0#1 ∨ x = 1#1 := by bv_omega + have hy : y = 0#1 ∨ y = 1#1 := by bv_omega rcases hx with rfl | rfl <;> rcases hy with rfl | rfl <;> rfl @@ -4347,8 +4347,8 @@ theorem umod_self {x : BitVec w} : x % x = 0#w := by @[simp] theorem umod_eq_and {x y : BitVec 1} : x % y = x &&& (~~~y) := by - have hx : x = 0#1 ∨ x = 1#1 := by sorry - have hy : y = 0#1 ∨ y = 1#1 := by sorry + have hx : x = 0#1 ∨ x = 1#1 := by bv_omega + have hy : y = 0#1 ∨ y = 1#1 := by bv_omega rcases hx with rfl | rfl <;> rcases hy with rfl | rfl <;> rfl @@ -4469,8 +4469,8 @@ theorem sdiv_one {x : BitVec w} : x.sdiv 1#w = x := by · rcases x.msb with msb | msb <;> simp [h] theorem sdiv_eq_and (x y : BitVec 1) : x.sdiv y = x &&& y := by - have hx : x = 0#1 ∨ x = 1#1 := by sorry - have hy : y = 0#1 ∨ y = 1#1 := by sorry + have hx : x = 0#1 ∨ x = 1#1 := by bv_omega + have hy : y = 0#1 ∨ y = 1#1 := by bv_omega rcases hx with rfl | rfl <;> rcases hy with rfl | rfl <;> simp diff --git a/src/Init/Data/ByteArray/Basic.lean b/src/Init/Data/ByteArray/Basic.lean index f399e7e571..32f11f7e80 100644 --- a/src/Init/Data/ByteArray/Basic.lean +++ b/src/Init/Data/ByteArray/Basic.lean @@ -174,7 +174,7 @@ def toList (bs : ByteArray) : List UInt8 := else r.reverse termination_by bs.size - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega loop 0 [] /-- @@ -190,7 +190,7 @@ The index is returned along with a proof that it is a valid index in the array. else none termination_by a.size - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega loop start /-- @@ -206,7 +206,7 @@ The variant {name}`findFinIdx?` additionally returns a proof that the found inde else none termination_by a.size - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega loop start /-- diff --git a/src/Init/Data/ByteArray/Lemmas.lean b/src/Init/Data/ByteArray/Lemmas.lean index 0a40428710..8f1202d344 100644 --- a/src/Init/Data/ByteArray/Lemmas.lean +++ b/src/Init/Data/ByteArray/Lemmas.lean @@ -10,8 +10,6 @@ public import Init.Data.ByteArray.Basic public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace ByteArray -- At present the preferred normal form for empty byte arrays is `ByteArray.empty` diff --git a/src/Init/Data/Fin/Fold.lean b/src/Init/Data/Fin/Fold.lean index 34c4c2b4d0..047900ff98 100644 --- a/src/Init/Data/Fin/Fold.lean +++ b/src/Init/Data/Fin/Fold.lean @@ -25,7 +25,6 @@ Example: @[specialize] loop (x : α) (i : Nat) : α := if h : i < n then loop (f x ⟨i, h⟩) (i+1) else x termination_by n - i - -- decreasing_by sorry -- TODO: restore after bootstrap /-- Combine all the values that can be represented by `Fin n` with an initial value, starting at `n - 1` @@ -68,7 +67,7 @@ Fin.foldlM n f x₀ = do @[specialize] loop (x : α) (i : Nat) : m α := do if h : i < n then f x ⟨i, h⟩ >>= (loop · (i+1)) else pure x termination_by n - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega /-- Folds a monadic function over `Fin n` from right to left, starting with `n-1`. @@ -99,8 +98,6 @@ Fin.foldrM n f xₙ = do @[specialize] loop : {i // i ≤ n} → α → m α | ⟨0, _⟩, x => pure x | ⟨i+1, h⟩, x => f ⟨i, h⟩ x >>= loop ⟨i, Nat.le_of_lt h⟩ - termination_by i => i.val - -- decreasing_by sorry -- TODO: restore after bootstrap /-! ### foldlM -/ diff --git a/src/Init/Data/Fin/Iterate.lean b/src/Init/Data/Fin/Iterate.lean index 70c89002ec..f62034e22e 100644 --- a/src/Init/Data/Fin/Iterate.lean +++ b/src/Init/Data/Fin/Iterate.lean @@ -34,7 +34,7 @@ def hIterateFrom (P : Nat → Sort _) {n} (f : ∀(i : Fin n), P i.val → P (i. have p : i = n := (or_iff_left g).mp (Nat.eq_or_lt_of_le ubnd) _root_.cast (congrArg P p) a termination_by n - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega /-- Applies an index-dependent function to all the values less than the given bound `n`, starting at diff --git a/src/Init/Data/Int/DivMod/Lemmas.lean b/src/Init/Data/Int/DivMod/Lemmas.lean index bed25402ac..83d3cdca5a 100644 --- a/src/Init/Data/Int/DivMod/Lemmas.lean +++ b/src/Init/Data/Int/DivMod/Lemmas.lean @@ -2787,7 +2787,10 @@ theorem bmod_le {x : Int} {m : Nat} (h : 0 < m) : bmod x m ≤ (m - 1) / 2 := by _ = ((m + 1 - 2) + 2)/2 := by simp _ = (m - 1) / 2 + 1 := by rw [add_ediv_of_dvd_right] - · sorry + · simp +decide only [Int.ediv_self] + congr 2 + rw [Int.add_sub_assoc, ← Int.sub_neg] + congr · trivial theorem bmod_natAbs_add_one (x : Int) (w : x ≠ -1) : x.bmod (x.natAbs + 1) = -x.sign := by diff --git a/src/Init/Data/Int/Linear.lean b/src/Init/Data/Int/Linear.lean index b9141f066c..f0f7ac34e2 100644 --- a/src/Init/Data/Int/Linear.lean +++ b/src/Init/Data/Int/Linear.lean @@ -414,7 +414,7 @@ attribute [local simp] Poly.denote_append theorem Poly.denote_combine' (ctx : Context) (fuel : Nat) (p₁ p₂ : Poly) : (p₁.combine' fuel p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by fun_induction p₁.combine' fuel p₂ <;> - sorry + simp_all +zetaDelta [denote, ← Int.add_mul] theorem Poly.denote_combine (ctx : Context) (p₁ p₂ : Poly) : (p₁.combine p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by simp [combine, denote_combine'] diff --git a/src/Init/Data/Int/Order.lean b/src/Init/Data/Int/Order.lean index 17337d268d..b68238129b 100644 --- a/src/Init/Data/Int/Order.lean +++ b/src/Init/Data/Int/Order.lean @@ -1343,8 +1343,9 @@ theorem neg_of_sign_eq_neg_one : ∀ {a : Int}, sign a = -1 → a < 0 match x with | 0 => rfl | .ofNat (_ + 1) => - sorry - | .negSucc _ => sorry + simp +decide only [sign, true_iff] + exact Int.le_add_one (natCast_nonneg _) + | .negSucc _ => simp +decide [sign] @[simp] theorem sign_pos_iff : 0 < sign x ↔ 0 < x := by match x with diff --git a/src/Init/Data/Iterators/Combinators/Monadic/Attach.lean b/src/Init/Data/Iterators/Combinators/Monadic/Attach.lean index 8ff7822696..60b7040b49 100644 --- a/src/Init/Data/Iterators/Combinators/Monadic/Attach.lean +++ b/src/Init/Data/Iterators/Combinators/Monadic/Attach.lean @@ -71,7 +71,14 @@ def Attach.instProductivenessRelation {α β : Type w} {m : Type w → Type w'} wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by apply Relation.TransGen.single - sorry + simp_wf + obtain ⟨step, hs⟩ := h + cases step using PlausibleIterStep.casesOn + · simp [Monadic.modifyStep] at hs + · simp only [Monadic.modifyStep, IterStep.skip.injEq] at hs + simp only [← hs] + assumption + · simp [Monadic.modifyStep] at hs instance Attach.instProductive {α β : Type w} {m : Type w → Type w'} [Monad m] [Iterator α m β] [Productive α m] {P : β → Prop} : diff --git a/src/Init/Data/Iterators/Consumers/Monadic/Loop.lean b/src/Init/Data/Iterators/Consumers/Monadic/Loop.lean index a1098322fe..2cb67bf4bf 100644 --- a/src/Init/Data/Iterators/Consumers/Monadic/Loop.lean +++ b/src/Init/Data/Iterators/Consumers/Monadic/Loop.lean @@ -149,6 +149,9 @@ def IterM.DefaultConsumers.forIn'.wf {m : Type w → Type w'} {α : Type w} {β (fun _ h' => hP _ <| .indirect ⟨_, rfl, h⟩ h') f | .done _ => return init termination_by IteratorLoop.WithWF.mk it init (hwf := wf) +decreasing_by + · exact Or.inl ⟨out, ‹_›, ‹_›⟩ + · exact Or.inr ⟨‹_›, rfl⟩ /-- This is the default implementation of the `IteratorLoop` class. diff --git a/src/Init/Data/Iterators/Lemmas/Basic.lean b/src/Init/Data/Iterators/Lemmas/Basic.lean index cb06415a2f..1e19f181e1 100644 --- a/src/Init/Data/Iterators/Lemmas/Basic.lean +++ b/src/Init/Data/Iterators/Lemmas/Basic.lean @@ -31,7 +31,6 @@ def Iter.inductSteps {α β} [Iterator α Id β] [Finite α Id] (fun {it' _} _ => inductSteps motive step it') (fun {it'} _ => inductSteps motive step it') termination_by it.finitelyManySteps -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Induction principle for productive iterators: One can define a function `f` that maps every @@ -47,6 +46,5 @@ def Iter.inductSkips {α β} [Iterator α Id β] [Productive α Id] (it : Iter (α := α) β) : motive it := step it (fun {it'} _ => inductSkips motive step it') termination_by it.finitelyManySkips -decreasing_by all_goals sorry -- TODO: restore after bootstrap end Std diff --git a/src/Init/Data/Iterators/Lemmas/Combinators/Monadic/FilterMap.lean b/src/Init/Data/Iterators/Lemmas/Combinators/Monadic/FilterMap.lean index de2ca6ce1e..f5d32b4ed4 100644 --- a/src/Init/Data/Iterators/Lemmas/Combinators/Monadic/FilterMap.lean +++ b/src/Init/Data/Iterators/Lemmas/Combinators/Monadic/FilterMap.lean @@ -403,7 +403,17 @@ private theorem IterM.toList_filterMapWithPostcondition_filterMapWithPostconditi rw [bind_eq_bind_subtypeCasesOn'_optionPelim' (x := (fg _).operation)] simp only [pure_bind, Shrink.inflate_deflate] rw [bind_subtypeCasesOn'_eq_map_bind] - sorry + conv => + lhs + rw [bind_eq_bind_subtypeCasesOn'_optionPelim'] + simp only [liftM_pure, pure_bind, Shrink.inflate_deflate, bind_assoc] + simp +singlePass only [bind_eq_bind_subtypeCasesOn'_optionPelim' (x := (g _).operation)] + simp only [pure_bind, Shrink.inflate_deflate] + simp only [bind_subtypeCasesOn'_eq_map_bind] + rw [← liftM_map] + simp only [← PostconditionT.run_eq_map, h, bind_assoc, optionPelim'] + apply bind_congr; intro fx + split <;> simp [ihy ‹_›] · simp [ihs ‹_›] · simp diff --git a/src/Init/Data/Iterators/Lemmas/Consumers/Loop.lean b/src/Init/Data/Iterators/Lemmas/Consumers/Loop.lean index e242f308e5..f7f8cfccf4 100644 --- a/src/Init/Data/Iterators/Lemmas/Consumers/Loop.lean +++ b/src/Init/Data/Iterators/Lemmas/Consumers/Loop.lean @@ -29,7 +29,9 @@ theorem Iter.forIn'_eq {α β : Type w} [Iterator α Id β] [Finite α Id] (fun out h acc => return ⟨← f out (Iter.isPlausibleIndirectOutput_iff_isPlausibleIndirectOutput_toIterM.mpr h) acc, trivial⟩) := by simp only [instForIn', ForIn'.forIn', IteratorLoop.finiteForIn'] have : ∀ a b c, f a b c = (Subtype.val <$> (⟨·, trivial⟩) <$> f a b c) := by simp - sorry + simp +singlePass only [this] + rw [hl.lawful (fun _ _ f x => f x.run) (wf := IteratorLoop.wellFounded_of_finite)] + simp [IteratorLoop.defaultImplementation] theorem Iter.forIn_eq {α β : Type w} [Iterator α Id β] [Finite α Id] {m : Type x → Type x'} [Monad m] [LawfulMonad m] [IteratorLoop α Id m] diff --git a/src/Init/Data/Iterators/Lemmas/Consumers/Monadic/Loop.lean b/src/Init/Data/Iterators/Lemmas/Consumers/Monadic/Loop.lean index 34c5469107..9dc61c46b3 100644 --- a/src/Init/Data/Iterators/Lemmas/Consumers/Monadic/Loop.lean +++ b/src/Init/Data/Iterators/Lemmas/Consumers/Monadic/Loop.lean @@ -172,6 +172,9 @@ theorem IterM.DefaultConsumers.forIn'_eq_forIn' {m : Type w → Type w'} {α : T · apply IterM.DefaultConsumers.forIn'_eq_forIn' <;> assumption · rfl termination_by IteratorLoop.WithWF.mk it init (hwf := wf) +decreasing_by + · exact Or.inl ⟨_, ‹_›, ‹_›⟩ + · exact Or.inr ⟨‹_›, rfl⟩ theorem IterM.forIn'_eq_match_step {α β : Type w} {m : Type w → Type w'} [Iterator α m β] [Finite α m] {n : Type w → Type w''} [Monad m] [Monad n] [LawfulMonad n] diff --git a/src/Init/Data/Iterators/Lemmas/Monadic/Basic.lean b/src/Init/Data/Iterators/Lemmas/Monadic/Basic.lean index 05e0dfff8e..289875005f 100644 --- a/src/Init/Data/Iterators/Lemmas/Monadic/Basic.lean +++ b/src/Init/Data/Iterators/Lemmas/Monadic/Basic.lean @@ -31,7 +31,6 @@ def IterM.inductSteps {α m β} [Iterator α m β] [Finite α m] (fun {it' _} _ => inductSteps motive step it') (fun {it'} _ => inductSteps motive step it') termination_by it.finitelyManySteps -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Induction principle for productive monadic iterators: One can define a function `f` that maps every @@ -47,6 +46,5 @@ def IterM.inductSkips {α m β} [Iterator α m β] [Productive α m] (it : IterM (α := α) m β) : motive it := step it (fun {it'} _ => inductSkips motive step it') termination_by it.finitelyManySkips -decreasing_by all_goals sorry -- TODO: restore after bootstrap end Std diff --git a/src/Init/Data/Iterators/Producers/Monadic/List.lean b/src/Init/Data/Iterators/Producers/Monadic/List.lean index 3108cad6bc..b8db65e64e 100644 --- a/src/Init/Data/Iterators/Producers/Monadic/List.lean +++ b/src/Init/Data/Iterators/Producers/Monadic/List.lean @@ -68,6 +68,8 @@ private def ListIterator.instFinitenessRelation [Pure m] : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step <;> simp_all [IterStep.successor, IterM.IsPlausibleStep, Iterator.IsPlausibleStep] instance ListIterator.instFinite [Pure m] : Finite (ListIterator α) m := by exact Finite.of_finitenessRelation ListIterator.instFinitenessRelation diff --git a/src/Init/Data/List/Attach.lean b/src/Init/Data/List/Attach.lean index f2eccb7701..b1b5bb5973 100644 --- a/src/Init/Data/List/Attach.lean +++ b/src/Init/Data/List/Attach.lean @@ -274,7 +274,7 @@ theorem getElem?_attach {xs : List α} {i : Nat} : theorem getElem_attachWith {xs : List α} {P : α → Prop} {H : ∀ a ∈ xs, P a} {i : Nat} (h : i < (xs.attachWith P H).length) : (xs.attachWith P H)[i] = ⟨xs[i]'(by simpa using h), H _ (getElem_mem (by simpa using h))⟩ := - getElem_pmap (hn := h) .. + getElem_pmap .. @[simp, grind =] theorem getElem_attach {xs : List α} {i : Nat} (h : i < xs.attach.length) : diff --git a/src/Init/Data/List/BasicAux.lean b/src/Init/Data/List/BasicAux.lean index a4b10c9145..123f322713 100644 --- a/src/Init/Data/List/BasicAux.lean +++ b/src/Init/Data/List/BasicAux.lean @@ -224,8 +224,8 @@ theorem getElem_append_right {as bs : List α} {i : Nat} (h₁ : as.length ≤ i theorem sizeOf_lt_of_mem [SizeOf α] {as : List α} (h : a ∈ as) : sizeOf a < sizeOf as := by induction h with - | head => sorry - | tail _ _ ih => exact Nat.lt_trans ih (by sorry) + | head => simp +arith + | tail _ _ ih => exact Nat.lt_trans ih (by simp +arith) /-- This tactic, added to the `decreasing_trivial` toolbox, proves that `sizeOf a < sizeOf as` when `a ∈ as`, which is useful for well founded recursions @@ -236,7 +236,7 @@ macro "sizeOf_list_dec" : tactic => | with_reducible apply Nat.lt_of_lt_of_le (sizeOf_lt_of_mem ?h) case' h => assumption - sorry) + simp +arith) macro_rules | `(tactic| decreasing_trivial) => `(tactic| sizeOf_list_dec) @@ -250,8 +250,8 @@ theorem append_cancel_left {as bs cs : List α} (h : as ++ bs = as ++ cs) : bs = theorem append_cancel_right {as bs cs : List α} (h : as ++ bs = cs ++ bs) : as = cs := by match as, cs with | [], [] => rfl - | [], c::cs => have aux := congrArg length h; sorry - | a::as, [] => have aux := congrArg length h; sorry + | [], c::cs => have aux := congrArg length h; simp +arith at aux + | a::as, [] => have aux := congrArg length h; simp +arith at aux | a::as, c::cs => injection h with h₁ h₂; subst h₁; rw [append_cancel_right h₂] @[simp] theorem append_cancel_left_eq (as bs cs : List α) : (as ++ bs = as ++ cs) = (bs = cs) := by @@ -266,11 +266,11 @@ theorem append_cancel_right {as bs cs : List α} (h : as ++ bs = cs ++ bs) : as theorem sizeOf_get [SizeOf α] (as : List α) (i : Fin as.length) : sizeOf (as.get i) < sizeOf as := by match as, i with - | a::as, ⟨0, _⟩ => sorry + | a::as, ⟨0, _⟩ => simp +arith [get] | a::as, ⟨i+1, h⟩ => have ih := sizeOf_get as ⟨i, Nat.le_of_succ_le_succ h⟩ apply Nat.lt_trans ih - sorry + simp +arith theorem lex_trichotomous [DecidableEq α] {r : α → α → Prop} [DecidableRel r] (trichotomous : ∀ x y : α, ¬ r x y → ¬ r y x → x = y) diff --git a/src/Init/Data/List/Count.lean b/src/Init/Data/List/Count.lean index be4ec3bf7d..4cd2cf5477 100644 --- a/src/Init/Data/List/Count.lean +++ b/src/Init/Data/List/Count.lean @@ -376,7 +376,7 @@ theorem replicate_count_eq_of_count_eq_length {l : List α} (h : count a l = len theorem count_le_count_map {β} [BEq β] [LawfulBEq β] {l : List α} {f : α → β} {x : α} : count x l ≤ count (f x) (map f l) := by rw [count, count, countP_map] - apply countP_mono_left; sorry + apply countP_mono_left; simp +contextual theorem count_filterMap {α} [BEq β] {b : β} {f : α → Option β} {l : List α} : count b (filterMap f l) = countP (fun a => f a == some b) l := by diff --git a/src/Init/Data/List/Find.lean b/src/Init/Data/List/Find.lean index 394bbe7f70..1db28dac46 100644 --- a/src/Init/Data/List/Find.lean +++ b/src/Init/Data/List/Find.lean @@ -21,7 +21,6 @@ and `List.lookup`. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace List @@ -1006,7 +1005,7 @@ theorem findIdx?_eq_map_findFinIdx?_val {xs : List α} {p : α → Bool} : theorem findFinIdx?_eq_pmap_findIdx? {xs : List α} {p : α → Bool} : xs.findFinIdx? p = (xs.findIdx? p).pmap - (fun i m => ⟨i, sorry⟩) -- TODO: restore proof after bootstrap: by simp [findIdx?_eq_some_iff_getElem] at m; exact ⟨i, m.choose⟩ + (fun i m => by simp [findIdx?_eq_some_iff_getElem] at m; exact ⟨i, m.choose⟩) (fun i h => h) := by simp [findIdx?_eq_map_findFinIdx?_val, Option.pmap_map] diff --git a/src/Init/Data/List/Impl.lean b/src/Init/Data/List/Impl.lean index eed4dd07a2..6b85759293 100644 --- a/src/Init/Data/List/Impl.lean +++ b/src/Init/Data/List/Impl.lean @@ -560,7 +560,7 @@ def zipIdxTR (l : List α) (n : Nat := 0) : List (α × Nat) := rw [← show _ + as.length = n + (a::as).length from Nat.succ_add .., foldr, go as] simp [zipIdx, f] rw [← Array.foldr_toList] - sorry + simp +zetaDelta [go] /-! ### enumFrom -/ diff --git a/src/Init/Data/List/Lemmas.lean b/src/Init/Data/List/Lemmas.lean index cb1fee4aaa..4acb754599 100644 --- a/src/Init/Data/List/Lemmas.lean +++ b/src/Init/Data/List/Lemmas.lean @@ -309,7 +309,7 @@ theorem ext_getElem {l₁ l₂ : List α} (hl : length l₁ = length l₂) theorem ext_getElem_iff {l₁ l₂ : List α} : l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ (i : Nat) (h₁ : i < l₁.length) (h₂ : i < l₂.length), l₁[i]'h₁ = l₂[i]'h₂ := by constructor - · sorry + · simp +contextual · exact fun h => ext_getElem h.1 h.2 @[simp] theorem getElem_concat_length {l : List α} {a : α} {i : Nat} (h : i = l.length) (w) : @@ -469,7 +469,7 @@ theorem getElem?_of_mem {a} {l : List α} (h : a ∈ l) : ∃ i : Nat, l[i]? = s let ⟨n, _, e⟩ := getElem_of_mem h exact ⟨n, e ▸ getElem?_eq_getElem _⟩ -theorem mem_of_getElem {l : List α} {i : Nat} {h : i < l.length} {a : α} (e : l[i] = a) : a ∈ l := by +theorem mem_of_getElem {l : List α} {i : Nat} {h} {a : α} (e : l[i] = a) : a ∈ l := by subst e simp @@ -755,7 +755,7 @@ theorem length_eq_of_beq [BEq α] {l₁ l₂ : List α} (h : l₁ == l₂) : l | succ n => rw [replicate_succ, replicate_succ, cons_beq_cons, replicate_beq_replicate] rw [Bool.eq_iff_iff] - sorry + simp +contextual @[simp] theorem reflBEq_iff [BEq α] : ReflBEq (List α) ↔ ReflBEq α := by constructor @@ -1144,7 +1144,7 @@ theorem map_inj_right {f : α → β} (w : ∀ x y, f x = f y → x = y) : map f intro h constructor · apply w - · sorry + · simp +contextual theorem map_congr_left (h : ∀ a ∈ l, f a = g a) : map f l = map g l := map_inj_left.2 h @@ -1622,7 +1622,7 @@ theorem getElem_append_right' (l₁ : List α) {l₂ : List α} {i : Nat} (hi : rw [getElem_append_right] <;> simp [*, le_add_left] theorem getElem_of_append {l : List α} (eq : l = l₁ ++ a :: l₂) (h : l₁.length = i) : - l[i]'(eq ▸ h ▸ by sorry) = a := Option.some.inj <| by + l[i]'(eq ▸ h ▸ by simp +arith) = a := Option.some.inj <| by rw [← getElem?_eq_getElem, eq, getElem?_append_right (h ▸ Nat.le_refl _), h] simp @@ -3289,7 +3289,7 @@ theorem all_eq_not_any_not {l : List α} {p : α → Bool} : l.all p = !l.any (! @[simp] theorem all_replicate {n : Nat} {a : α} : (replicate n a).all f = if n = 0 then true else f a := by - cases n <;> sorry + cases n <;> simp +contextual [replicate_succ] theorem any_congr {l₁ l₂ : List α} (w : l₁ = l₂) {p q : α → Bool} (h : ∀ a, p a = q a) : l₁.any p = l₂.any q := by diff --git a/src/Init/Data/List/Lex.lean b/src/Init/Data/List/Lex.lean index 4b6a9dd16b..60d4c1beb9 100644 --- a/src/Init/Data/List/Lex.lean +++ b/src/Init/Data/List/Lex.lean @@ -494,7 +494,7 @@ protected theorem le_iff_exists [LT α] rw [← lex_eq_false_iff_ge, lex_eq_false_iff_exists] · simp only [isEqv_eq, beq_iff_eq, decide_eq_true_eq] simp only [eq_comm] - sorry + conv => lhs; simp +singlePass [exists_comm] · simpa using Std.Irrefl.irrefl · simpa using Std.Asymm.asymm · simpa using Std.Trichotomous.trichotomous @@ -552,7 +552,7 @@ protected theorem map_le [LT α] [LT β] simp · right refine ⟨i, by simpa using h₁, by simpa using h₂, ?_, ?_⟩ - · sorry + · simp +contextual [w₁] · simpa using w _ _ w₂ end List diff --git a/src/Init/Data/List/MapIdx.lean b/src/Init/Data/List/MapIdx.lean index 90c2033013..8c406d192c 100644 --- a/src/Init/Data/List/MapIdx.lean +++ b/src/Init/Data/List/MapIdx.lean @@ -14,7 +14,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace List @@ -105,15 +104,15 @@ theorem mapFinIdx_nil {f : (i : Nat) → α → (h : i < 0) → β} : mapFinIdx (as.mapFinIdx f).length = as.length := by simp [mapFinIdx, length_mapFinIdx_go] -theorem getElem_mapFinIdx_go {as : List α} {f : (i : Nat) → α → (h : i < as.length) → β} {i : Nat} {heq : bs.length + acc.size = as.length} {w : i < (mapFinIdx.go as f bs acc heq).length} : - (mapFinIdx.go as f bs acc heq)[i] = +theorem getElem_mapFinIdx_go {as : List α} {f : (i : Nat) → α → (h : i < as.length) → β} {i : Nat} {h} {w} : + (mapFinIdx.go as f bs acc h)[i] = if w' : i < acc.size then acc[i] else f i (bs[i - acc.size]'(by simp at w; omega)) (by simp at w; omega) := by induction bs generalizing acc with | nil => - simp only [length_mapFinIdx_go, length_nil, Nat.zero_add] at w heq + simp only [length_mapFinIdx_go, length_nil, Nat.zero_add] at w h simp only [mapFinIdx.go, Array.getElem_toList] rw [dif_pos] | cons _ _ ih => @@ -129,7 +128,7 @@ theorem getElem_mapFinIdx_go {as : List α} {f : (i : Nat) → α → (h : i < a · have h₃ : i - acc.size = (i - (acc.size + 1)) + 1 := by omega simp [h₃] -@[simp, grind =] theorem getElem_mapFinIdx {as : List α} {f : (i : Nat) → α → (h : i < as.length) → β} {i : Nat} {h : i < (as.mapFinIdx f).length} : +@[simp, grind =] theorem getElem_mapFinIdx {as : List α} {f : (i : Nat) → α → (h : i < as.length) → β} {i : Nat} {h} : (as.mapFinIdx f)[i] = f i (as[i]'(by simp at h; omega)) (by simp at h; omega) := by simp [mapFinIdx, getElem_mapFinIdx_go] diff --git a/src/Init/Data/List/MinMaxIdx.lean b/src/Init/Data/List/MinMaxIdx.lean index ade8f49046..12d813c800 100644 --- a/src/Init/Data/List/MinMaxIdx.lean +++ b/src/Init/Data/List/MinMaxIdx.lean @@ -123,7 +123,9 @@ private theorem exists_getElem_eq_of_drop_eq_cons {xs : List α} {k : Nat} {y : refine ⟨hlt, ?_⟩ have := take_append_drop k xs rw [h] at this - sorry + simp +singlePass only [← this] + rw [getElem_append_right (length_take_le _ _)] + simp [length_take_of_le (Nat.le_of_lt hlt)] private theorem take_succ_eq_append_of_drop_eq_cons {xs : List α} {k : Nat} {y : α} {ys : List α} (h : xs.drop k = y :: ys) : xs.take (k + 1) = xs.take k ++ [y] := by @@ -209,7 +211,7 @@ protected theorem apply_minOn_lt_apply_getElem_of_lt_minIdxOn [LE β] [Decidable @[simp] protected theorem getElem_minIdxOn [LE β] [DecidableLE β] [IsLinearPreorder β] {f : α → β} {xs : List α} (h : xs ≠ []) : - xs[xs.minIdxOn f h]'sorry = xs.minOn f h := by + xs[xs.minIdxOn f h] = xs.minOn f h := by obtain ⟨i, hlt, hi, heq, h'⟩ := minIdxOn_eq_go_drop (f := f) h (k := xs.length) simp only [drop_eq_nil_of_le (as := xs) (i := xs.length + 1) (by omega), minIdxOn.go] at h' simp [h', heq, take_of_length_le (l := xs) (i := xs.length + 1) (by omega)] @@ -409,7 +411,9 @@ private theorem minIdxOn_append_aux [LE β] [DecidableLE β] match xs with | [] => simp [minIdxOn_cons_aux (xs := ys) ‹_›] | z :: zs => - sorry + simp +singlePass only [cons_append] + simp only [minIdxOn_cons_aux (xs := z :: zs ++ ys) (by simp), ih (by simp), + minIdxOn_cons_aux (xs := z :: zs) (by simp), combineMinIdxOn_assoc] protected theorem minIdxOn_append [LE β] [DecidableLE β] [IsLinearPreorder β] {xs ys : List α} {f : α → β} (hxs : xs ≠ []) (hys : ys ≠ []) : @@ -437,7 +441,8 @@ protected theorem minIdxOn_take_le [LE β] [DecidableLE β] [IsLinearPreorder β {xs : List α} {f : α → β} {i : Nat} (h : xs.take i ≠ []) : (xs.take i).minIdxOn f h ≤ xs.minIdxOn f (List.ne_nil_of_take_ne_nil h) := by have := take_append_drop i xs - sorry + conv => rhs; simp +singlePass only [← this] + apply List.left_le_minIdxOn_append @[simp] protected theorem minIdxOn_replicate [LE β] [DecidableLE β] [Refl (α := β) (· ≤ ·)] @@ -498,7 +503,7 @@ protected theorem apply_maxOn_lt_apply_getElem_of_lt_maxIdxOn [LE β] [Decidable @[simp] protected theorem getElem_maxIdxOn [LE β] [DecidableLE β] [IsLinearPreorder β] {f : α → β} {xs : List α} (h : xs ≠ []) : - xs[xs.maxIdxOn f h]'sorry = xs.maxOn f h := by + xs[xs.maxIdxOn f h] = xs.maxOn f h := by simp only [List.maxIdxOn_eq_minIdxOn, List.maxOn_eq_minOn] letI : LE β := (inferInstanceAs (LE β)).opposite exact List.getElem_minIdxOn h @@ -678,7 +683,7 @@ protected theorem get_minIdxOn?_lt_length [LE β] [DecidableLE β] {f : α → @[simp] protected theorem getElem_get_minIdxOn? [LE β] [DecidableLE β] [IsLinearPreorder β] {f : α → β} {xs : List α} (h : (xs.minIdxOn? f).isSome) : - xs[(xs.minIdxOn? f).get h]'sorry = xs.minOn f (List.isSome_minIdxOn?_iff.mp h) := by + xs[(xs.minIdxOn? f).get h] = xs.minOn f (List.isSome_minIdxOn?_iff.mp h) := by rw [getElem_congr rfl (List.get_minIdxOn?_eq_minIdxOn _), List.getElem_minIdxOn] protected theorem minIdxOn?_eq_some_zero_iff [LE β] [DecidableLE β] [IsLinearPreorder β] @@ -797,7 +802,7 @@ protected theorem get_maxIdxOn?_lt_length [LE β] [DecidableLE β] {f : α → @[simp] protected theorem getElem_get_maxIdxOn? [LE β] [DecidableLE β] [IsLinearPreorder β] {f : α → β} {xs : List α} (h : (xs.maxIdxOn? f).isSome) : - xs[(xs.maxIdxOn? f).get h]'sorry = xs.maxOn f (List.isSome_maxIdxOn?_iff.mp h) := by + xs[(xs.maxIdxOn? f).get h] = xs.maxOn f (List.isSome_maxIdxOn?_iff.mp h) := by simp only [List.maxIdxOn?_eq_minIdxOn?, List.maxOn_eq_minOn] letI : LE β := LE.opposite inferInstance exact List.getElem_get_minIdxOn? h diff --git a/src/Init/Data/List/MinMaxOn.lean b/src/Init/Data/List/MinMaxOn.lean index 27fe2015f7..e7f2df6428 100644 --- a/src/Init/Data/List/MinMaxOn.lean +++ b/src/Init/Data/List/MinMaxOn.lean @@ -249,7 +249,7 @@ protected theorem minOn_replicate [LE β] [DecidableLE β] [IsLinearPreorder β] · simp at h · rename_i n ih simp only [ne_eq, replicate_eq_nil_iff] at ih - sorry + simp +contextual [List.replicate, List.minOn_cons, ih] /-! ### maxOn -/ diff --git a/src/Init/Data/List/Nat/Basic.lean b/src/Init/Data/List/Nat/Basic.lean index 956c47fedf..15e6a068f7 100644 --- a/src/Init/Data/List/Nat/Basic.lean +++ b/src/Init/Data/List/Nat/Basic.lean @@ -130,7 +130,7 @@ theorem getElem?_intersperse_two_mul_add_one (h : i + 1 < l.length) : · contradiction · rename_i hn _ have ⟨_, tl, _⟩ := ne_nil_iff_exists_cons.mp hn - cases tl <;> cases i <;> sorry + cases tl <;> cases i <;> simp_all +arith @[grind =] theorem getElem?_intersperse : @@ -164,14 +164,16 @@ theorem getElem?_intersperse : omega @[grind =] -theorem getElem_intersperse (h : i < (l.intersperse sep).length) : +theorem getElem_intersperse (h) : (l.intersperse sep)[i] = if i % 2 = 0 then l[i / 2]'(by simp at h; omega) else sep := by split · have p : i = 2 * (i / 2) := by omega - sorry + conv => lhs; simp +singlePass only [p] + rw [getElem_intersperse_two_mul] · have p : i = 2 * (i / 2) + 1 := by omega - sorry + conv => lhs; simp +singlePass only [p] + rw [getElem_intersperse_two_mul_add_one] theorem getElem_eq_getElem_intersperse_two_mul (h : i < l.length) : l[i] = (l.intersperse sep)[2 * i]'(by rw [length_intersperse]; omega) := by diff --git a/src/Init/Data/List/Nat/Find.lean b/src/Init/Data/List/Nat/Find.lean index ee55d51fa7..c7c71cada7 100644 --- a/src/Init/Data/List/Nat/Find.lean +++ b/src/Init/Data/List/Nat/Find.lean @@ -20,7 +20,7 @@ open Nat /-! ### Results about `List.sum` specialized to `Nat` -/ theorem find?_eq_some_iff_getElem {xs : List α} {p : α → Bool} {b : α} : - xs.find? p = some b ↔ p b ∧ ∃ (i : Nat) (h : i < xs.length), xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by + xs.find? p = some b ↔ p b ∧ ∃ i h, xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by rw [find?_eq_some_iff_append] simp only [Bool.not_eq_eq_eq_not, Bool.not_true, exists_and_right, and_congr_right_iff] intro w diff --git a/src/Init/Data/List/Nat/Modify.lean b/src/Init/Data/List/Nat/Modify.lean index 6cb41a3797..df4737c5a5 100644 --- a/src/Init/Data/List/Nat/Modify.lean +++ b/src/Init/Data/List/Nat/Modify.lean @@ -13,7 +13,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace List @@ -38,7 +37,7 @@ theorem getElem_modifyHead {l : List α} {f : α → α} {i} (h : i < (l.modifyH | nil => simp at h | cons hd tl => cases i <;> simp -@[simp] theorem getElem_modifyHead_zero {l : List α} {f : α → α} {h : 0 < (l.modifyHead f).length} : +@[simp] theorem getElem_modifyHead_zero {l : List α} {f : α → α} {h} : (l.modifyHead f)[0] = f (l[0]'(by simpa using h)) := by simp [getElem_modifyHead] @[simp] theorem getElem_modifyHead_succ {l : List α} {f : α → α} {n} (h : n + 1 < (l.modifyHead f).length) : @@ -204,10 +203,10 @@ theorem modifyHead_eq_modify_zero (f : α → α) (l : List α) : simp at h simp [h] -@[simp] theorem getElem_modify_eq (f : α → α) (i) (l : List α) (h : i < (l.modify i f).length) : +@[simp] theorem getElem_modify_eq (f : α → α) (i) (l : List α) (h) : (l.modify i f)[i] = f (l[i]'(by simpa using h)) := by simp [getElem_modify] -@[simp] theorem getElem_modify_ne (f : α → α) {i j} (l : List α) (h : i ≠ j) (h' : j < (l.modify i f).length) : +@[simp] theorem getElem_modify_ne (f : α → α) {i j} (l : List α) (h : i ≠ j) (h') : (l.modify i f)[j] = l[j]'(by simpa using h') := by simp [getElem_modify, h] theorem modify_eq_self {f : α → α} {i} {l : List α} (h : l.length ≤ i) : diff --git a/src/Init/Data/List/Nat/Range.lean b/src/Init/Data/List/Nat/Range.lean index 800b69b5c2..f27fbbf6b3 100644 --- a/src/Init/Data/List/Nat/Range.lean +++ b/src/Init/Data/List/Nat/Range.lean @@ -238,7 +238,7 @@ theorem not_mem_range_self {n : Nat} : n ∉ range n := by simp theorem self_mem_range_succ {n : Nat} : n ∈ range (n + 1) := by simp theorem pairwise_lt_range {n : Nat} : Pairwise (· < ·) (range n) := by - sorry + simp +decide only [range_eq_range', pairwise_lt_range'] theorem pairwise_le_range {n : Nat} : Pairwise (· ≤ ·) (range n) := Pairwise.imp Nat.le_of_lt pairwise_lt_range @@ -246,10 +246,10 @@ theorem pairwise_le_range {n : Nat} : Pairwise (· ≤ ·) (range n) := @[simp, grind =] theorem take_range {i n : Nat} : take i (range n) = range (min i n) := by apply List.ext_getElem · simp - · sorry + · simp +contextual [getElem_take, Nat.lt_min] theorem nodup_range {n : Nat} : Nodup (range n) := by - sorry + simp +decide only [range_eq_range', nodup_range'] @[simp] theorem find?_range_eq_some {n : Nat} {i : Nat} {p : Nat → Bool} : (range n).find? p = some i ↔ p i ∧ i ∈ range n ∧ ∀ j, j < i → !p j := by diff --git a/src/Init/Data/List/Nat/TakeDrop.lean b/src/Init/Data/List/Nat/TakeDrop.lean index 2b9f32c744..14b5738e6a 100644 --- a/src/Init/Data/List/Nat/TakeDrop.lean +++ b/src/Init/Data/List/Nat/TakeDrop.lean @@ -19,7 +19,6 @@ as they required importing more lemmas about natural numbers, and use `omega`. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace List @@ -43,10 +42,7 @@ theorem length_take_of_le (h : i ≤ length l) : length (take i l) = i := by sim length `> i`. Version designed to rewrite from the big list to the small list. -/ theorem getElem_take' {xs : List α} {i j : Nat} (hi : i < xs.length) (hj : i < j) : xs[i] = (xs.take j)[i]'(length_take .. ▸ Nat.lt_min.mpr ⟨hj, hi⟩) := - -- TODO: restore proof after bootstrap: - -- by have h' : i < (xs.take j).length := length_take .. ▸ Nat.lt_min.mpr ⟨hj, hi⟩ - -- exact getElem_of_eq (take_append_drop j xs).symm _ ▸ getElem_append_left (h' := h') - sorry + getElem_of_eq (take_append_drop j xs).symm _ ▸ getElem_append_left .. /-- The `i`-th element of a list coincides with the `i`-th element of any of its prefixes of length `> i`. Version designed to rewrite from the small list to the big list. -/ diff --git a/src/Init/Data/List/Pairwise.lean b/src/Init/Data/List/Pairwise.lean index 7f99fef276..b8323894a4 100644 --- a/src/Init/Data/List/Pairwise.lean +++ b/src/Init/Data/List/Pairwise.lean @@ -83,11 +83,11 @@ theorem pairwise_of_forall {l : List α} (H : ∀ x y, R x y) : Pairwise R l := theorem Pairwise.and_mem {l : List α} : Pairwise R l ↔ Pairwise (fun x y => x ∈ l ∧ y ∈ l ∧ R x y) l := - Pairwise.iff_of_mem <| by sorry + Pairwise.iff_of_mem <| by simp +contextual theorem Pairwise.imp_mem {l : List α} : Pairwise R l ↔ Pairwise (fun x y => x ∈ l → y ∈ l → R x y) l := - Pairwise.iff_of_mem <| by sorry + Pairwise.iff_of_mem <| by simp +contextual theorem Pairwise.forall_of_forall_of_flip (h₁ : ∀ x ∈ l, R x x) (h₂ : Pairwise R l) (h₃ : l.Pairwise (flip R)) : ∀ ⦃x⦄, x ∈ l → ∀ ⦃y⦄, y ∈ l → R x y := by diff --git a/src/Init/Data/List/Sort/Basic.lean b/src/Init/Data/List/Sort/Basic.lean index 799965e796..c71d2aa8b7 100644 --- a/src/Init/Data/List/Sort/Basic.lean +++ b/src/Init/Data/List/Sort/Basic.lean @@ -41,8 +41,6 @@ def merge (xs ys : List α) (le : α → α → Bool := by exact fun a b => a x :: merge xs (y :: ys) le else y :: merge (x :: xs) ys le -termination_by xs.length + ys.length -decreasing_by all_goals sorry -- TODO: restore after bootstrap @[simp] theorem nil_merge (ys : List α) : merge [] ys le = ys := by simp [merge] @[simp] theorem merge_right (xs : List α) : merge xs [] le = xs := by @@ -82,7 +80,6 @@ def mergeSort : ∀ (xs : List α) (le : α → α → Bool := by exact fun a b have := by simpa using lr.1.2 merge (mergeSort lr.1 le) (mergeSort lr.2 le) le termination_by xs => xs.length -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Given an ordering relation `le : α → α → Bool`, diff --git a/src/Init/Data/List/Sort/Impl.lean b/src/Init/Data/List/Sort/Impl.lean index 5ce84886b9..11b3ae0cc8 100644 --- a/src/Init/Data/List/Sort/Impl.lean +++ b/src/Init/Data/List/Sort/Impl.lean @@ -56,8 +56,6 @@ where go : List α → List α → List α → List α go xs (y :: ys) (x :: acc) else go (x :: xs) ys (y :: acc) - termination_by l₁ l₂ _ => l₁.length + l₂.length - decreasing_by all_goals sorry -- TODO: restore after bootstrap private theorem mergeTR_go_eq : mergeTR.go le l₁ l₂ acc = acc.reverse ++ merge l₁ l₂ le := by induction l₁ generalizing l₂ acc with @@ -115,8 +113,6 @@ where run : {n : Nat} → { l : List α // l.length = n } → List α | _+2, xs => let (l, r) := splitInTwo xs mergeTR (run l) (run r) le - termination_by n _ => n - decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Split a list in two equal parts, reversing the first part. diff --git a/src/Init/Data/List/Sort/Lemmas.lean b/src/Init/Data/List/Sort/Lemmas.lean index 04ea81a2ac..6342e83918 100644 --- a/src/Init/Data/List/Sort/Lemmas.lean +++ b/src/Init/Data/List/Sort/Lemmas.lean @@ -165,8 +165,8 @@ theorem cons_merge_cons (s : α → α → Bool) (a b l r) : | a::l, b::r => rw [cons_merge_cons] split - · sorry - · sorry + · simp +arith [length_merge s l (b::r)] + · simp +arith [length_merge s (a::l) r] /-- The elements of `merge le xs ys` are exactly the elements of `xs` and `ys`. diff --git a/src/Init/Data/List/Sublist.lean b/src/Init/Data/List/Sublist.lean index 6e7949cbf4..0649d5c7fd 100644 --- a/src/Init/Data/List/Sublist.lean +++ b/src/Init/Data/List/Sublist.lean @@ -139,7 +139,7 @@ fun s => Subset.trans s <| subset_append_right _ _ theorem replicate_subset {n : Nat} {a : α} {l : List α} : replicate n a ⊆ l ↔ n = 0 ∨ a ∈ l := by induction n with | zero => simp - | succ n ih => sorry + | succ n ih => simp +contextual [replicate_succ, ih, cons_subset] theorem subset_replicate {n : Nat} {a : α} {l : List α} (h : n ≠ 0) : l ⊆ replicate n a ↔ ∀ x ∈ l, x = a := by induction l with diff --git a/src/Init/Data/List/ToArray.lean b/src/Init/Data/List/ToArray.lean index 31a72604dc..ccf17cd8ed 100644 --- a/src/Init/Data/List/ToArray.lean +++ b/src/Init/Data/List/ToArray.lean @@ -21,11 +21,10 @@ We prefer to pull `List.toArray` outwards past `Array` operations. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array -@[simp] theorem toList_set (xs : Array α) (i x) (h : i < xs.size) : +@[simp] theorem toList_set (xs : Array α) (i x h) : (xs.set i x).toList = xs.toList.set i x := rfl theorem swap_def (xs : Array α) (i j : Nat) (hi hj) : @@ -88,7 +87,7 @@ theorem toArray_cons (a : α) (l : List α) : (a :: l).toArray = #[a] ++ l.toArr @[simp, grind =] theorem back?_toArray (l : List α) : l.toArray.back? = l.getLast? := by simp [back?, List.getLast?_eq_getElem?] -@[simp, grind =] theorem back_toArray (l : List α) (h : 0 < l.toArray.size) : +@[simp, grind =] theorem back_toArray (l : List α) (h) : l.toArray.back = l.getLast (by simp at h; exact ne_nil_of_length_pos h) := by simp [back, List.getLast_eq_getElem] diff --git a/src/Init/Data/Nat/Bitwise/Basic.lean b/src/Init/Data/Nat/Bitwise/Basic.lean index 46cdcfb52c..b62018dec0 100644 --- a/src/Init/Data/Nat/Bitwise/Basic.lean +++ b/src/Init/Data/Nat/Bitwise/Basic.lean @@ -36,6 +36,7 @@ def bitwise (f : Bool → Bool → Bool) (n m : Nat) : Nat := r+r+1 else r+r +decreasing_by apply bitwise_rec_lemma; assumption /-- Bitwise and. Usually accessed via the `&&&` operator. diff --git a/src/Init/Data/Nat/Div/Basic.lean b/src/Init/Data/Nat/Div/Basic.lean index b0e56226ab..98a7f0f358 100644 --- a/src/Init/Data/Nat/Div/Basic.lean +++ b/src/Init/Data/Nat/Div/Basic.lean @@ -64,6 +64,7 @@ def div.inductionOn.{u} ind x y h (inductionOn (x - y) y ind base) else base x y h +decreasing_by apply div_rec_lemma; assumption theorem div_le_self (n k : Nat) : n / k ≤ n := by induction n using Nat.strongRecOn with @@ -236,6 +237,7 @@ theorem div_add_mod (m n : Nat) : n * (m / n) + m % n = m := by simp [h] have ih := div_add_mod (m - n) n rw [Nat.left_distrib, Nat.mul_one, Nat.add_assoc, Nat.add_left_comm, ih, Nat.add_comm, Nat.sub_add_cancel h.2] +decreasing_by apply div_rec_lemma; assumption theorem div_eq_sub_div (h₁ : 0 < b) (h₂ : b ≤ a) : a / b = (a - b) / b + 1 := by rw [div_eq a, if_pos]; constructor <;> assumption diff --git a/src/Init/Data/Nat/Gcd.lean b/src/Init/Data/Nat/Gcd.lean index 8ac80cee96..60ef917ea4 100644 --- a/src/Init/Data/Nat/Gcd.lean +++ b/src/Init/Data/Nat/Gcd.lean @@ -36,7 +36,7 @@ def gcd (m n : @& Nat) : Nat := else gcd (n % m) m termination_by m - -- decreasing_by simp_wf; apply mod_lt _ (zero_lt_of_ne_zero _); assumption + decreasing_by simp_wf; apply mod_lt _ (zero_lt_of_ne_zero _); assumption @[simp] theorem gcd_zero_left (y : Nat) : gcd 0 y = y := by rw [gcd]; rfl diff --git a/src/Init/Data/Nat/Lemmas.lean b/src/Init/Data/Nat/Lemmas.lean index 672a99cb12..1b7ebe8a5d 100644 --- a/src/Init/Data/Nat/Lemmas.lean +++ b/src/Init/Data/Nat/Lemmas.lean @@ -867,7 +867,7 @@ theorem div_eq_self {m n : Nat} : m / n = m ↔ m = 0 ∨ n = 1 := by · simp simp only [hb, false_or] rw [← Nat.mul_right_inj hb, ← Nat.add_left_cancel_iff, mod_add_div] - sorry + simp +contextual [mod_eq_of_lt] protected theorem div_ne_zero_iff : a / b ≠ 0 ↔ b ≠ 0 ∧ b ≤ a := by simp @@ -1559,7 +1559,7 @@ theorem mul_add_div {m : Nat} (m_pos : m > 0) (x y : Nat) : (m * x + y) / m = x | 0 => simp | x + 1 => rw [Nat.mul_succ, Nat.add_assoc _ m, mul_add_div m_pos x (m+y), div_eq] - sorry + simp +arith [m_pos] theorem mul_add_mod (m x y : Nat) : (m * x + y) % m = y % m := by match x with diff --git a/src/Init/Data/Nat/Log2.lean b/src/Init/Data/Nat/Log2.lean index dbd38a1edf..59162e7775 100644 --- a/src/Init/Data/Nat/Log2.lean +++ b/src/Init/Data/Nat/Log2.lean @@ -73,4 +73,4 @@ theorem log2_le_self (n : Nat) : Nat.log2 n ≤ n := by have := log2_le_self (n / 2) exact Nat.lt_of_le_of_lt this (Nat.div_lt_self (Nat.le_of_lt h) (by decide)) · apply Nat.zero_le --- decreasing_by exact Nat.log2_terminates _ ‹_› +decreasing_by exact Nat.log2_terminates _ ‹_› diff --git a/src/Init/Data/Nat/MinMax.lean b/src/Init/Data/Nat/MinMax.lean index 279a5bfa61..7a50036c05 100644 --- a/src/Init/Data/Nat/MinMax.lean +++ b/src/Init/Data/Nat/MinMax.lean @@ -79,7 +79,7 @@ protected theorem max_eq_max (a : Nat) : Nat.max a b = max a b := rfl simp [Nat.max_def] @[simp] protected theorem max_zero (a : Nat) : max a 0 = a := by - sorry + simp +contextual [Nat.max_def] @[simp] protected theorem add_max_add_right (a b c : Nat) : max (a + c) (b + c) = max a b + c := by rw [Nat.max_def, Nat.max_def] diff --git a/src/Init/Data/Nat/Power2/Basic.lean b/src/Init/Data/Nat/Power2/Basic.lean index 668ec7255c..fa89e03949 100644 --- a/src/Init/Data/Nat/Power2/Basic.lean +++ b/src/Init/Data/Nat/Power2/Basic.lean @@ -13,7 +13,7 @@ public section namespace Nat theorem nextPowerOfTwo_dec {n power : Nat} (h₁ : power > 0) (h₂ : power < n) : n - power * 2 < n - power := by - have : power * 2 = power + power := by sorry + have : power * 2 = power + power := by simp +arith rw [this, Nat.sub_add_eq] exact Nat.sub_lt (Nat.zero_lt_sub_of_lt h₂) h₁ @@ -36,7 +36,7 @@ where else power termination_by n - power - -- decreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption + decreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption /-- A natural number `n` is a power of two if there exists some `k : Nat` such that `n = 2 ^ k`. @@ -66,6 +66,6 @@ where . exact isPowerOfTwo_go (power*2) (Nat.mul_pos h₁ (by decide)) (Nat.isPowerOfTwo_mul_two_of_isPowerOfTwo h₂) . assumption termination_by n - power - -- decreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption + decreasing_by simp_wf; apply nextPowerOfTwo_dec <;> assumption end Nat diff --git a/src/Init/Data/Nat/SOM.lean b/src/Init/Data/Nat/SOM.lean index 6418229e3a..483bc62d22 100644 --- a/src/Init/Data/Nat/SOM.lean +++ b/src/Init/Data/Nat/SOM.lean @@ -109,63 +109,79 @@ def Expr.toPoly : Expr → Poly theorem Mon.append_denote (ctx : Context) (m₁ m₂ : Mon) : (m₁ ++ m₂).denote ctx = m₁.denote ctx * m₂.denote ctx := by match m₁ with - | [] => sorry - | v :: m₁ => sorry + | [] => simp! [Nat.one_mul] + | v :: m₁ => simp! [append_denote ctx m₁ m₂, Nat.mul_assoc] theorem Mon.mul_denote (ctx : Context) (m₁ m₂ : Mon) : (m₁.mul m₂).denote ctx = m₁.denote ctx * m₂.denote ctx := go hugeFuel m₁ m₂ where go (fuel : Nat) (m₁ m₂ : Mon) : (Mon.mul.go fuel m₁ m₂).denote ctx = m₁.denote ctx * m₂.denote ctx := by induction fuel generalizing m₁ m₂ with - | zero => sorry + | zero => simp! [append_denote] | succ _ ih => - sorry + simp! + split <;> simp! + next v₁ m₁ v₂ m₂ => + by_cases hlt : Nat.blt v₁ v₂ <;> simp! [hlt, Nat.mul_assoc, ih] + by_cases hgt : Nat.blt v₂ v₁ <;> simp! [hgt, Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm, ih] theorem Poly.append_denote (ctx : Context) (p₁ p₂ : Poly) : (p₁ ++ p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by match p₁ with - | [] => sorry - | v :: p₁ => sorry + | [] => simp! + | v :: p₁ => simp! [append_denote _ p₁ p₂, Nat.add_assoc] theorem Poly.add_denote (ctx : Context) (p₁ p₂ : Poly) : (p₁.add p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := go hugeFuel p₁ p₂ where go (fuel : Nat) (p₁ p₂ : Poly) : (Poly.add.go fuel p₁ p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by induction fuel generalizing p₁ p₂ with - | zero => sorry + | zero => simp! [append_denote] | succ _ ih => - sorry + simp! + split <;> simp! + next k₁ m₁ p₁ k₂ m₂ p₂ => + by_cases hlt : m₁ < m₂ <;> simp! [hlt, Nat.add_assoc, ih] + by_cases hgt : m₂ < m₁ <;> simp! [hgt, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm, ih] + have : m₁ = m₂ := List.le_antisymm hgt hlt + subst m₂ + by_cases heq : k₁ + k₂ == 0 <;> simp! [heq, ih] + · simp [← Nat.add_assoc, ← Nat.right_distrib, eq_of_beq heq] + · simp [Nat.right_distrib, Nat.add_assoc] theorem Poly.denote_insertSorted (ctx : Context) (k : Nat) (m : Mon) (p : Poly) : (p.insertSorted k m).denote ctx = p.denote ctx + k * m.denote ctx := by match p with - | [] => sorry + | [] => simp! | (k', m') :: p => - by_cases h : m < m' <;> sorry + by_cases h : m < m' <;> simp! [h, denote_insertSorted ctx k m p, Nat.add_assoc, Nat.add_comm, Nat.add_left_comm] theorem Poly.mulMon_denote (ctx : Context) (p : Poly) (k : Nat) (m : Mon) : (p.mulMon k m).denote ctx = p.denote ctx * k * m.denote ctx := by - simp [mulMon, go]; sorry + simp [mulMon, go]; simp! where go (p : Poly) (acc : Poly) : (mulMon.go k m p acc).denote ctx = acc.denote ctx + p.denote ctx * k * m.denote ctx := by match p with - | [] => sorry + | [] => simp! | (k', m') :: p => - sorry + simp! [go p, Nat.left_distrib, denote_insertSorted, Mon.mul_denote, Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm, Nat.add_assoc] theorem Poly.mul_denote (ctx : Context) (p₁ p₂ : Poly) : (p₁.mul p₂).denote ctx = p₁.denote ctx * p₂.denote ctx := by - simp [mul, go]; sorry + simp [mul, go]; simp! where go (p₁ : Poly) (acc : Poly) : (mul.go p₂ p₁ acc).denote ctx = acc.denote ctx + p₁.denote ctx * p₂.denote ctx := by match p₁ with - | [] => sorry + | [] => simp! | (k, m) :: p₁ => - sorry + simp! [go p₁, Nat.left_distrib, add_denote, mulMon_denote, + Nat.add_assoc, Nat.add_comm, Nat.add_left_comm, + Nat.mul_assoc, Nat.mul_comm, Nat.mul_left_comm] theorem Expr.toPoly_denote (ctx : Context) (e : Expr) : e.toPoly.denote ctx = e.denote ctx := by induction e with | num k => - sorry - | var v => sorry - | add a b => sorry - | mul a b => sorry + simp!; by_cases h : k == 0 <;> simp! [*] + simp [eq_of_beq h] + | var v => simp! + | add a b => simp! [Poly.add_denote, *] + | mul a b => simp! [Poly.mul_denote, *] theorem Expr.eq_of_toPoly_eq (ctx : Context) (a b : Expr) (h : a.toPoly == b.toPoly) : a.denote ctx = b.denote ctx := by have h := congrArg (Poly.denote ctx) (eq_of_beq h) diff --git a/src/Init/Data/Option/Attach.lean b/src/Init/Data/Option/Attach.lean index 1a2a9222c2..f3d731a302 100644 --- a/src/Init/Data/Option/Attach.lean +++ b/src/Init/Data/Option/Attach.lean @@ -445,7 +445,7 @@ public instance : LawfulMonadAttach Option where canReturn_map_imp {α P x a} := by cases x · simp [MonadAttach.CanReturn] - · sorry + · simp +contextual [MonadAttach.CanReturn, eq_comm, Subtype.property] end Option diff --git a/src/Init/Data/Ord/Array.lean b/src/Init/Data/Ord/Array.lean index 81b250869c..6450aec3cf 100644 --- a/src/Init/Data/Ord/Array.lean +++ b/src/Init/Data/Ord/Array.lean @@ -27,7 +27,6 @@ where go i := | .eq => go (i + 1) | .gt => .gt termination_by a₁.size - i --- decreasing_by sorry -- TODO: restore after bootstrap instance {α} [Ord α] : Ord (Array α) where compare := Array.compareLex compare diff --git a/src/Init/Data/Order/FactoriesExtra.lean b/src/Init/Data/Order/FactoriesExtra.lean index d9f55f705e..34b8cf69f2 100644 --- a/src/Init/Data/Order/FactoriesExtra.lean +++ b/src/Init/Data/Order/FactoriesExtra.lean @@ -106,7 +106,7 @@ instance if `Ord α` is compatible with it. public instance instLawfulOrderLT_ofOrd {α : Type u} [Ord α] [LE α] [LawfulOrderOrd α] : LawfulOrderLT α where lt_iff {a b} := by - sorry + simp +contextual [LT.lt, ← Std.isLE_compare (a := a), ← Std.isGE_compare (a := a)] attribute [local instance] BEq.ofOrd in /-- @@ -116,6 +116,7 @@ instance if `Ord α` is compatible with it. public instance instLawfulOrderBEq_ofOrd {α : Type u} [Ord α] [LE α] [LawfulOrderOrd α] : LawfulOrderBEq α where beq_iff_le_and_ge {a b} := by - sorry + simp +contextual [BEq.beq, ← Std.isLE_compare (a := a), ← Std.isGE_compare (a := a), + Ordering.eq_eq_iff_isLE_and_isGE] end Std diff --git a/src/Init/Data/Order/Lemmas.lean b/src/Init/Data/Order/Lemmas.lean index 392f2c16de..d06a6253a8 100644 --- a/src/Init/Data/Order/Lemmas.lean +++ b/src/Init/Data/Order/Lemmas.lean @@ -103,7 +103,7 @@ public theorem le_antisymm {α : Type u} [LE α] [Std.Antisymm (α := α) (· public theorem le_antisymm_iff {α : Type u} [LE α] [Antisymm (α := α) (· ≤ ·)] [Refl (α := α) (· ≤ ·)] {a b : α} : a ≤ b ∧ b ≤ a ↔ a = b := - ⟨fun | ⟨hab, hba⟩ => le_antisymm hab hba, by sorry⟩ + ⟨fun | ⟨hab, hba⟩ => le_antisymm hab hba, by simp +contextual [le_refl]⟩ public theorem le_trans {α : Type u} [LE α] [Trans (α := α) (· ≤ ·) (· ≤ ·) (· ≤ ·)] {a b c : α} (hab : a ≤ b) (hbc : b ≤ c) : a ≤ c := @@ -401,8 +401,8 @@ public instance {α : Type u} [LE α] [Min α] [IsLinearOrder α] [LawfulOrderIn public theorem LawfulOrderLeftLeaningMin.of_eq {α : Type u} [LE α] [Min α] [DecidableLE α] (min_eq : ∀ a b : α, min a b = if a ≤ b then a else b) : LawfulOrderLeftLeaningMin α where - min_eq_left a b := by sorry - min_eq_right a b := by sorry + min_eq_left a b := by simp +contextual [min_eq] + min_eq_right a b := by simp +contextual [min_eq] attribute [local instance] Min.leftLeaningOfLE public instance [LE α] [DecidableLE α] : LawfulOrderLeftLeaningMin α := @@ -538,8 +538,8 @@ public instance {α : Type u} [LE α] [Max α] [IsLinearOrder α] [LawfulOrderSu public theorem LawfulOrderLeftLeaningMax.of_eq {α : Type u} [LE α] [Max α] [DecidableLE α] (min_eq : ∀ a b : α, max a b = if b ≤ a then a else b) : LawfulOrderLeftLeaningMax α where - max_eq_left a b := by sorry - max_eq_right a b := by sorry + max_eq_left a b := by simp +contextual [min_eq] + max_eq_right a b := by simp +contextual [min_eq] attribute [local instance] Max.leftLeaningOfLE public instance [LE α] [DecidableLE α] : LawfulOrderLeftLeaningMax α := diff --git a/src/Init/Data/Order/LemmasExtra.lean b/src/Init/Data/Order/LemmasExtra.lean index c25fc5bd11..370a100935 100644 --- a/src/Init/Data/Order/LemmasExtra.lean +++ b/src/Init/Data/Order/LemmasExtra.lean @@ -86,7 +86,7 @@ public instance LawfulOrderLT.of_ord (α : Type u) [Ord α] [LT α] [LE α] [Law (lt_iff_compare_eq_lt : ∀ a b : α, a < b ↔ compare a b = .lt) : LawfulOrderLT α where lt_iff a b := by - sorry + simp +contextual [lt_iff_compare_eq_lt, ← isLE_compare (a := a), ← isGE_compare (a := a)] /-- This lemma derives a `LawfulOrderBEq α` instance from a property involving an `Ord α` instance. diff --git a/src/Init/Data/Order/PackageFactories.lean b/src/Init/Data/Order/PackageFactories.lean index dbbd608dbd..502c259808 100644 --- a/src/Init/Data/Order/PackageFactories.lean +++ b/src/Init/Data/Order/PackageFactories.lean @@ -683,15 +683,15 @@ public scoped instance instMaxOfOrd {α : Type u} [Ord α] : public instance instLawfulOrderLeftLeaningMinOfOrd {α : Type u} [Ord α] [LE α] [LawfulOrderOrd α] : LawfulOrderLeftLeaningMin α where - min_eq_left a b := by sorry + min_eq_left a b := by simp +contextual only [← Std.isLE_compare, min, ↑reduceIte, implies_true] min_eq_right a b := by - sorry + simp +contextual only [← Std.isLE_compare, min, Bool.false_eq_true, ↑reduceIte, implies_true] public instance instLawfulOrderLeftLeaningMaxOfOrd {α : Type u} [Ord α] [LE α] [LawfulOrderOrd α] : LawfulOrderLeftLeaningMax α where - max_eq_left a b := by sorry + max_eq_left a b := by simp +contextual only [← Std.isLE_compare, max, ↑reduceIte, implies_true] max_eq_right a b := by - sorry + simp +contextual only [← Std.isLE_compare, max, Bool.false_eq_true, ↑reduceIte, implies_true] end FactoryInstances diff --git a/src/Init/Data/Range/Basic.lean b/src/Init/Data/Range/Basic.lean index b04d41a7d2..1ca1e8dc80 100644 --- a/src/Init/Data/Range/Basic.lean +++ b/src/Init/Data/Range/Basic.lean @@ -40,8 +40,6 @@ universe u v loop b (i + range.step) (by rwa [Nat.add_comm, Nat.add_sub_assoc hl, Nat.add_mod_left]) else pure b - termination_by range.stop - i - -- decreasing_by sorry -- TODO: restore after bootstrap have := range.step_pos loop init range.start (by simp) @@ -58,8 +56,6 @@ instance [Monad m] : ForIn' m Range Nat inferInstance where loop (i + range.step) else pure ⟨⟩ - termination_by range.stop - i - -- decreasing_by sorry -- TODO: restore after bootstrap have := range.step_pos loop range.start diff --git a/src/Init/Data/Range/Polymorphic/BitVec.lean b/src/Init/Data/Range/Polymorphic/BitVec.lean index f7976ad2f2..0fca919d0d 100644 --- a/src/Init/Data/Range/Polymorphic/BitVec.lean +++ b/src/Init/Data/Range/Polymorphic/BitVec.lean @@ -30,7 +30,7 @@ theorem succ?_eq_none {x : BitVec n} : · refine fun h => Classical.not_not.mp fun _ => ?_ simp [Nat.mod_eq_of_lt (a := x.toNat + 1) (b := 2 ^ n) (by omega)] at h · have := Nat.two_pow_pos n - sorry + simp +contextual [show 2 ^ n - 1 + 1 = 2 ^ n by omega] theorem succ?_eq_some {x y : BitVec n} : succ? x = some y ↔ x.toNat < 2 ^ n - 1 ∧ y.toNat = x.toNat + 1 := by @@ -56,10 +56,19 @@ theorem succ?_eq_some {x y : BitVec n} : instance : LawfulUpwardEnumerable (BitVec n) where ne_of_lt := by - sorry + simp +contextual [UpwardEnumerable.LT, ← BitVec.toNat_inj, succMany?] at ⊢ + omega succMany?_zero := by simp [UpwardEnumerable.succMany?, BitVec.toNat_lt_twoPow_of_le] succMany?_add_one a b := by - sorry + simp +contextual [← BitVec.toNat_inj, succMany?, succ?] + split <;> split + · rename_i h + simp [← BitVec.toNat_inj, Nat.mod_eq_of_lt (a := b.toNat + a + 1) ‹_›] + all_goals omega + · omega + · have : b.toNat + a + 1 = 2 ^ n := by omega + simp [this] + · simp instance : LawfulUpwardEnumerableLE (BitVec n) where le_iff x y := by diff --git a/src/Init/Data/Range/Polymorphic/IntLemmas.lean b/src/Init/Data/Range/Polymorphic/IntLemmas.lean index ba67dcf877..c02f372f77 100644 --- a/src/Init/Data/Range/Polymorphic/IntLemmas.lean +++ b/src/Init/Data/Range/Polymorphic/IntLemmas.lean @@ -147,7 +147,7 @@ theorem toList_rco_eq_singleton {m n : Int} (h : n = m + 1) : theorem toList_rco_eq_cons_iff {m n a : Int} : (m...n).toList = a :: xs ↔ m = a ∧ m < n ∧ ((m + 1)...n).toList = xs := by rw [Rco.toList_eq_if_roo] - split <;> sorry + split <;> simp +contextual [*, Roo.toList_eq_match_rco, eq_comm] theorem toList_rco_eq_cons {m n : Int} (h : m < n) : (m...n).toList = m :: ((m + 1)...n).toList := by diff --git a/src/Init/Data/Range/Polymorphic/Lemmas.lean b/src/Init/Data/Range/Polymorphic/Lemmas.lean index 822b4f6620..abca192c4d 100644 --- a/src/Init/Data/Range/Polymorphic/Lemmas.lean +++ b/src/Init/Data/Range/Polymorphic/Lemmas.lean @@ -17,8 +17,6 @@ import Init.Data.Array.Monadic public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! # Lemmas about ranges diff --git a/src/Init/Data/Range/Polymorphic/NatLemmas.lean b/src/Init/Data/Range/Polymorphic/NatLemmas.lean index 9c55b21721..1956d2120b 100644 --- a/src/Init/Data/Range/Polymorphic/NatLemmas.lean +++ b/src/Init/Data/Range/Polymorphic/NatLemmas.lean @@ -222,7 +222,7 @@ theorem toList_rco_eq_singleton {m n : Nat} (h : n = m + 1) : theorem toList_rco_eq_cons_iff {m n a : Nat} : (m...n).toList = a :: xs ↔ m = a ∧ m < n ∧ ((m + 1)...n).toList = xs := by rw [Rco.toList_eq_if_roo] - split <;> sorry + split <;> simp +contextual [*, Roo.toList_eq_match_rco, eq_comm] theorem toList_rco_eq_cons {m n : Nat} (h : m < n) : (m...n).toList = m :: ((m + 1)...n).toList := by diff --git a/src/Init/Data/Range/Polymorphic/RangeIterator.lean b/src/Init/Data/Range/Polymorphic/RangeIterator.lean index 51d52f27f8..1a2193e6e1 100644 --- a/src/Init/Data/Range/Polymorphic/RangeIterator.lean +++ b/src/Init/Data/Range/Polymorphic/RangeIterator.lean @@ -480,6 +480,7 @@ instance Iterator.instIteratorLoop [UpwardEnumerable α] [LE α] [DecidableLE α exact UpwardEnumerable.le_iff.mpr (UpwardEnumerable.le_refl _) case decreasing => simp_wf + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α] [LE α] [DecidableLE α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α] @@ -501,7 +502,8 @@ private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α else return acc termination_by IteratorLoop.WithWF.mk ⟨⟨some next, upperBound⟩⟩ acc (hwf := wf) -decreasing_by all_goals sorry -- TODO: restore after bootstrap +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] where finally case hle => simp only [UpwardEnumerable.le_iff] @@ -577,8 +579,8 @@ private theorem Iterator.instIteratorLoop.loopWf_eq [UpwardEnumerable α] [LE α simp [Monadic.step_eq_step, Monadic.step, instLawfulMonadLiftFunction.liftBind_pure, *] · simp termination_by IteratorLoop.WithWF.mk ⟨⟨some next, upperBound⟩⟩ acc (hwf := wf) --- decreasing_by --- simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] instance Iterator.instLawfulIteratorLoop [UpwardEnumerable α] [LE α] [DecidableLE α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLE α] @@ -1051,7 +1053,7 @@ instance Iterator.instIteratorLoop [UpwardEnumerable α] [LT α] [DecidableLT α case hle'' => exact UpwardEnumerable.le_refl _ case decreasing => - simp_wf + simp_wf; simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α] [LT α] [DecidableLT α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α] @@ -1073,7 +1075,8 @@ private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α else return acc termination_by IteratorLoop.WithWF.mk ⟨⟨some next, upperBound⟩⟩ acc (hwf := wf) -decreasing_by all_goals sorry -- TODO: restore after bootstrap +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] where finally case hle => refine ⟨1, ?_⟩ @@ -1148,8 +1151,8 @@ private theorem Iterator.instIteratorLoop.loopWf_eq [UpwardEnumerable α] [LT α simp [Monadic.step_eq_step, Monadic.step, instLawfulMonadLiftFunction.liftBind_pure, *] · simp termination_by IteratorLoop.WithWF.mk ⟨⟨some next, upperBound⟩⟩ acc (hwf := wf) --- decreasing_by --- simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] instance Iterator.instLawfulIteratorLoop [UpwardEnumerable α] [LT α] [DecidableLT α] [LawfulUpwardEnumerable α] [LawfulUpwardEnumerableLT α] @@ -1530,7 +1533,7 @@ instance Iterator.instIteratorLoop [UpwardEnumerable α] [LawfulUpwardEnumerable case hle'' => exact UpwardEnumerable.le_refl _ case decreasing => - simp_wf + simp_wf; simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α] [LawfulUpwardEnumerable α] @@ -1549,7 +1552,8 @@ private noncomputable def Iterator.instIteratorLoop.loop.wf [UpwardEnumerable α | none => return acc' | ⟨.done acc', _⟩ => return acc' termination_by IteratorLoop.WithWF.mk ⟨⟨some next⟩⟩ acc (hwf := wf) -decreasing_by all_goals sorry -- TODO: restore after bootstrap +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] where finally case hle => refine ⟨1, ?_⟩ @@ -1613,8 +1617,8 @@ private theorem Iterator.instIteratorLoop.loopWf_eq [UpwardEnumerable α] simp [Monadic.step_eq_step, Monadic.step, instLawfulMonadLiftFunction.liftBind_pure, *] · simp termination_by IteratorLoop.WithWF.mk ⟨⟨some next⟩⟩ acc (hwf := wf) --- decreasing_by --- simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] +decreasing_by + simp [IteratorLoop.rel, Monadic.isPlausibleStep_iff, Monadic.step, *] instance Iterator.instLawfulIteratorLoop [UpwardEnumerable α] [LawfulUpwardEnumerable α] diff --git a/src/Init/Data/Range/Polymorphic/SInt.lean b/src/Init/Data/Range/Polymorphic/SInt.lean index 25997c2fac..82c894cf5e 100644 --- a/src/Init/Data/Range/Polymorphic/SInt.lean +++ b/src/Init/Data/Range/Polymorphic/SInt.lean @@ -64,7 +64,7 @@ theorem eq_of_encode_eq [m : HasModel α β] (x y : α) : theorem encode_inj [m : HasModel α β] {x y : α} : m.encode x = m.encode y ↔ x = y := by - exact ⟨m.eq_of_encode_eq x y, by sorry⟩ + exact ⟨m.eq_of_encode_eq x y, by simp +contextual⟩ theorem le_iff [m : HasModel α β] {x y : α} : UpwardEnumerable.LE x y ↔ UpwardEnumerable.LE (m.encode x) (m.encode y) := by diff --git a/src/Init/Data/Rat/Lemmas.lean b/src/Init/Data/Rat/Lemmas.lean index 07e55ed877..7889aa8e46 100644 --- a/src/Init/Data/Rat/Lemmas.lean +++ b/src/Init/Data/Rat/Lemmas.lean @@ -520,7 +520,7 @@ protected theorem inv_mul_cancel (a : Rat) (h : a ≠ 0) : a⁻¹ * a = 1 := Eq.trans (Rat.mul_comm _ _) (Rat.mul_inv_cancel _ h) protected theorem inv_eq_of_mul_eq_one {a b : Rat} (h : a * b = 1) : a⁻¹ = b := by - have : a ≠ 0 := by intro h; sorry + have : a ≠ 0 := by intro h; simp_all +decide simpa [← Rat.mul_assoc, Rat.inv_mul_cancel _ this, eq_comm] using congrArg (a⁻¹ * ·) h protected theorem inv_inv (a : Rat) : a⁻¹⁻¹ = a := @@ -864,7 +864,7 @@ protected theorem inv_pos {a : Rat} : 0 < a⁻¹ ↔ 0 < a := by protected theorem pow_pos {a : Rat} {n : Nat} (h : 0 < a) : 0 < a ^ n := by induction n with - | zero => sorry + | zero => simp +decide | succ k ih => rw [Rat.pow_succ]; exact Rat.mul_pos ih h protected theorem pow_nonneg {a : Rat} {n : Nat} (h : 0 ≤ a) : 0 ≤ a ^ n := by diff --git a/src/Init/Data/SInt/Lemmas.lean b/src/Init/Data/SInt/Lemmas.lean index df52f74dd3..58807a1bb4 100644 --- a/src/Init/Data/SInt/Lemmas.lean +++ b/src/Init/Data/SInt/Lemmas.lean @@ -102,7 +102,7 @@ theorem ISize.toBitVec_one : (1 : ISize).toBitVec = 1#System.Platform.numBits := theorem ISize.toNat_toBitVec_ofNat_of_lt {n : Nat} (h : n < 2^32) : (ofNat n).toBitVec.toNat = n := - Nat.mod_eq_of_lt (Nat.lt_of_lt_of_le h (by cases USize.size_eq <;> sorry)) + Nat.mod_eq_of_lt (Nat.lt_of_lt_of_le h (by cases USize.size_eq <;> simp_all +decide)) @[simp] theorem Int8.toInt_ofInt {n : Int} : toInt (ofInt n) = n.bmod Int8.size := by rw [toInt, toBitVec_ofInt, BitVec.toInt_ofInt] diff --git a/src/Init/Data/Slice/Array/Lemmas.lean b/src/Init/Data/Slice/Array/Lemmas.lean index 94a9bada63..8549aed766 100644 --- a/src/Init/Data/Slice/Array/Lemmas.lean +++ b/src/Init/Data/Slice/Array/Lemmas.lean @@ -24,7 +24,6 @@ open Std Std.Iterators Std.PRange Std.Slice namespace SubarrayIterator -set_option debug.byAsSorry true -- TODO: remove after bootstrap theorem step_eq {it : Iter (α := SubarrayIterator α) α} : it.step = if h : it.1.xs.start < it.1.xs.stop then haveI := it.1.xs.start_le_stop @@ -97,7 +96,6 @@ end SubarrayIterator namespace Subarray -set_option debug.byAsSorry true -- TODO: remove after bootstrap theorem internalIter_eq {α : Type u} {s : Subarray α} : Internal.iter s = ⟨⟨s⟩⟩ := rfl @@ -207,8 +205,8 @@ public theorem Subarray.toList_eq {xs : Subarray α} : apply List.ext_getElem · have : stop - start ≤ array.size - start := by omega simp [Subarray.start, Subarray.stop, *, Subarray.array] - · -- TODO: restore after bootstrap: intros; simp [Subarray.array, Subarray.start, Subarray.stop] - sorry + · intros + simp [Subarray.array, Subarray.start, Subarray.stop] simp [this, ListSlice.toList_eq, lslice] @[grind =] @@ -240,7 +238,6 @@ public theorem Subarray.size_toArray {xs : Subarray α} : namespace Array -set_option debug.byAsSorry true -- TODO: remove after bootstrap @[simp, grind =] public theorem array_mkSlice_rco {xs : Array α} {lo hi : Nat} : xs[lo...hi].array = xs := by @@ -633,7 +630,6 @@ section SubarraySlices namespace Subarray -set_option debug.byAsSorry true -- TODO: remove after bootstrap @[simp, grind =] public theorem toList_mkSlice_rco {xs : Subarray α} {lo hi : Nat} : xs[lo...hi].toList = (xs.toList.take hi).drop lo := by diff --git a/src/Init/Data/String/Basic.lean b/src/Init/Data/String/Basic.lean index d04fde8a20..5624cf033e 100644 --- a/src/Init/Data/String/Basic.lean +++ b/src/Init/Data/String/Basic.lean @@ -25,8 +25,6 @@ basis for all further verification for strings. public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - universe u section @@ -77,7 +75,7 @@ where else some acc termination_by b.size - i - -- decreasing_by sorry -- TODO: restore after bootstrap + decreasing_by have := c.utf8Size_pos; omega @[expose, extern "lean_string_validate_utf8"] def ByteArray.validateUTF8 (b : @& ByteArray) : Bool := @@ -92,7 +90,8 @@ where else true termination_by b.size - i - -- decreasing_by sorry -- TODO: restore after bootstrap + decreasing_by + have := b[i].utf8ByteSize_pos (isUTF8FirstByte_of_validateUTF8At h); omega finally all_goals rw [ByteArray.validateUTF8At_eq_isSome_utf8DecodeChar?] at h · rw [← ByteArray.utf8Size_utf8DecodeChar (h := h)] @@ -738,8 +737,8 @@ theorem _root_.ByteArray.IsValidUTF8.isUTF8FirstByte_getElem_zero {b : ByteArray · exact List.isUTF8FirstByte_getElem_utf8Encode_singleton.2 rfl · simp [List.utf8Encode_singleton, Char.utf8Size_pos] -theorem isUTF8FirstByte_getUTF8Byte_zero {b : String} {h : 0 < b.utf8ByteSize} : (b.getUTF8Byte 0 h).IsUTF8FirstByte := - b.isValidUTF8.isUTF8FirstByte_getElem_zero (by simp [String.utf8ByteSize] at h; exact h) +theorem isUTF8FirstByte_getUTF8Byte_zero {b : String} {h} : (b.getUTF8Byte 0 h).IsUTF8FirstByte := + b.isValidUTF8.isUTF8FirstByte_getElem_zero _ theorem Pos.Raw.isValidUTF8_extract_iff {s : String} (p₁ p₂ : Pos.Raw) (hle : p₁ ≤ p₂) (hle' : p₂ ≤ s.rawEndPos) : (s.toByteArray.extract p₁.byteIdx p₂.byteIdx).IsValidUTF8 ↔ p₁ = p₂ ∨ (p₁.IsValid s ∧ p₂.IsValid s) := by @@ -2683,14 +2682,16 @@ Examples: * `"teas".firstDiffPos "tea" = ⟨3⟩` -/ @[expose] -partial def firstDiffPos (a b : String) : Pos.Raw := +def firstDiffPos (a b : String) : Pos.Raw := let stopPos := a.rawEndPos.min b.rawEndPos let rec loop (i : Pos.Raw) : Pos.Raw := if h : i < stopPos then if i.get a != i.get b then i else + have := Nat.sub_lt_sub_left h (Pos.Raw.lt_next a i) loop (i.next a) else i + termination_by stopPos.1 - i.1 loop 0 /-- @@ -2724,12 +2725,14 @@ where | [], _, _ => [] | c::cs, i, e => if i = e then [] else c :: go₂ cs (i + c) e -partial def Pos.Raw.offsetOfPosAux (s : String) (pos : Pos.Raw) (i : Pos.Raw) (offset : Nat) : Nat := +def Pos.Raw.offsetOfPosAux (s : String) (pos : Pos.Raw) (i : Pos.Raw) (offset : Nat) : Nat := if i >= pos then offset else if h : i.atEnd s then offset else + have := Nat.sub_lt_sub_left (Nat.gt_of_not_le (mt decide_eq_true h)) (Pos.Raw.lt_next s _) offsetOfPosAux s pos (i.next s) (offset+1) +termination_by s.rawEndPos.1 - i.1 /-- Returns the character index that corresponds to the provided position (i.e. UTF-8 byte index) in a @@ -2772,7 +2775,7 @@ either string. This is a legacy function. The recommended alternative is to construct slices representing the strings to be compared and use the `BEq` instance of `String.Slice`. -/ -partial def Pos.Raw.substrEq (s1 : String) (pos1 : String.Pos.Raw) (s2 : String) (pos2 : String.Pos.Raw) (sz : Nat) : Bool := +def Pos.Raw.substrEq (s1 : String) (pos1 : String.Pos.Raw) (s2 : String) (pos2 : String.Pos.Raw) (sz : Nat) : Bool := pos1.byteIdx + sz ≤ s1.rawEndPos.byteIdx && pos2.byteIdx + sz ≤ s2.rawEndPos.byteIdx && loop pos1 pos2 { byteIdx := pos1.byteIdx + sz } where loop (off1 off2 stop1 : Pos.Raw) := @@ -2781,6 +2784,10 @@ where let c₂ := off2.get s2 c₁ == c₂ && loop (off1 + c₁) (off2 + c₂) stop1 else true + termination_by stop1.1 - off1.1 + decreasing_by + have := Nat.sub_lt_sub_left _h (Nat.add_lt_add_left c₁.utf8Size_pos off1.1) + decreasing_tactic @[deprecated Pos.Raw.substrEq (since := "2025-10-10")] def substrEq (s1 : String) (pos1 : String.Pos.Raw) (s2 : String) (pos2 : String.Pos.Raw) (sz : Nat) : Bool := diff --git a/src/Init/Data/String/Decode.lean b/src/Init/Data/String/Decode.lean index 311cd6dc54..0bddf82383 100644 --- a/src/Init/Data/String/Decode.lean +++ b/src/Init/Data/String/Decode.lean @@ -236,7 +236,6 @@ theorem String.toBitVec_getElem_utf8EncodeChar_three_of_utf8Size_eq_four {c : Ch namespace ByteArray.utf8DecodeChar? -set_option debug.byAsSorry true -- TODO: remove after bootstrap /-! # `parseFirstByte` -/ /-! ## `parseFirstByte` definition -/ @@ -1139,16 +1138,31 @@ theorem utf8DecodeChar?_eq_assemble₄ {b : ByteArray} (hb : 4 ≤ b.size) (h : all_goals omega theorem utf8DecodeChar?_append_eq_assemble₁ {l : List UInt8} {b : ByteArray} (hl : l.length = 1) (h : parseFirstByte l[0] = .done) : - (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₁ l[0] h := sorry + (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₁ l[0] h := by + have : (l.toByteArray ++ b)[0]'(by simp [hl]; omega) = l[0] := by + rw [ByteArray.getElem_append_left (by simp [hl]), List.getElem_toByteArray] + rw [utf8DecodeChar?_eq_assemble₁ (by simp [hl])] <;> simp [this, h] theorem utf8DecodeChar?_append_eq_assemble₂ {l : List UInt8} {b : ByteArray} (hl : l.length = 2) (h : parseFirstByte l[0] = .oneMore) : - (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₂ l[0] l[1] := sorry + (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₂ l[0] l[1] := by + rw [utf8DecodeChar?_eq_assemble₂ (by simp [hl])] + all_goals repeat rw [ByteArray.getElem_append_left (by simp [hl])] + all_goals repeat rw [List.getElem_toByteArray] + assumption theorem utf8DecodeChar?_append_eq_assemble₃ {l : List UInt8} {b : ByteArray} (hl : l.length = 3) (h : parseFirstByte l[0] = .twoMore) : - (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₃ l[0] l[1] l[2] := sorry + (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₃ l[0] l[1] l[2] := by + rw [utf8DecodeChar?_eq_assemble₃ (by simp [hl])] + all_goals repeat rw [ByteArray.getElem_append_left (by simp [hl])] + all_goals repeat rw [List.getElem_toByteArray] + assumption theorem utf8DecodeChar?_append_eq_assemble₄ {l : List UInt8} {b : ByteArray} (hl : l.length = 4) (h : parseFirstByte l[0] = .threeMore) : - (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₄ l[0] l[1] l[2] l[3] := sorry + (l.toByteArray ++ b).utf8DecodeChar? 0 = assemble₄ l[0] l[1] l[2] l[3] := by + rw [utf8DecodeChar?_eq_assemble₄ (by simp [hl])] + all_goals repeat rw [ByteArray.getElem_append_left (by simp [hl])] + all_goals repeat rw [List.getElem_toByteArray] + assumption /-! # Main theorems @@ -1374,7 +1388,6 @@ public theorem List.utf8DecodeChar_utf8Encode_cons {l : List Char} {c : Char} {h namespace UInt8 -set_option debug.byAsSorry true -- TODO: remove after bootstrap /-- Predicate for whether a byte can appear as the first byte of the UTF-8 encoding of a Unicode scalar value. @@ -1457,11 +1470,9 @@ theorem utf8ByteSize_eq_utf8ByteSize_parseFirstByte {c : UInt8} {h : c.IsUTF8Fir end UInt8 public theorem ByteArray.isUTF8FirstByte_getElem_zero_utf8EncodeChar_append {c : Char} {b : ByteArray} : - (((String.utf8EncodeChar c).toByteArray ++ b)[0]'(by simp; have := c.utf8Size_pos; omega)).IsUTF8FirstByte := - -- TODO: restore proof after bootstrap: - -- by rw [ByteArray.getElem_append_left (by simp [c.utf8Size_pos]), - -- List.getElem_toByteArray, UInt8.isUTF8FirstByte_getElem_utf8EncodeChar] - sorry + (((String.utf8EncodeChar c).toByteArray ++ b)[0]'(by simp; have := c.utf8Size_pos; omega)).IsUTF8FirstByte := by + rw [ByteArray.getElem_append_left (by simp [c.utf8Size_pos]), + List.getElem_toByteArray, UInt8.isUTF8FirstByte_getElem_utf8EncodeChar] public theorem ByteArray.isUTF8FirstByte_of_isSome_utf8DecodeChar? {b : ByteArray} {i : Nat} (h : (utf8DecodeChar? b i).isSome) : (b[i]'(lt_size_of_isSome_utf8DecodeChar? h)).IsUTF8FirstByte := by diff --git a/src/Init/Data/String/Extra.lean b/src/Init/Data/String/Extra.lean index 94990be4f4..27eef7986c 100644 --- a/src/Init/Data/String/Extra.lean +++ b/src/Init/Data/String/Extra.lean @@ -108,6 +108,14 @@ where else go acc accStop pos' termination_by text.utf8ByteSize - pos.byteIdx - decreasing_by all_goals sorry -- TODO: restore after bootstrap + decreasing_by + decreasing_with + change text.utf8ByteSize - ((pos.next text).next text).byteIdx < text.utf8ByteSize - pos.byteIdx + have k := Nat.gt_of_not_le <| mt decide_eq_true h + exact Nat.sub_lt_sub_left k (Nat.lt_trans (String.Pos.Raw.lt_next text pos) (String.Pos.Raw.lt_next _ _)) + decreasing_with + change text.utf8ByteSize - (pos.next text).byteIdx < text.utf8ByteSize - pos.byteIdx + have k := Nat.gt_of_not_le <| mt decide_eq_true h + exact Nat.sub_lt_sub_left k (String.Pos.Raw.lt_next _ _) end String diff --git a/src/Init/Data/String/FindPos.lean b/src/Init/Data/String/FindPos.lean index ec6d0bec81..4a887afd50 100644 --- a/src/Init/Data/String/FindPos.lean +++ b/src/Init/Data/String/FindPos.lean @@ -30,9 +30,9 @@ def Slice.posGE (s : Slice) (offset : String.Pos.Raw) (_h : offset ≤ s.rawEnd else s.endPos termination_by s.utf8ByteSize - offset.byteIdx --- decreasing_by --- simp only [Pos.Raw.lt_iff, byteIdx_rawEndPos, utf8ByteSize_eq, Pos.Raw.byteIdx_inc] at h ⊢ --- omega +decreasing_by + simp only [Pos.Raw.lt_iff, byteIdx_rawEndPos, utf8ByteSize_eq, Pos.Raw.byteIdx_inc] at h ⊢ + omega /-- Obtains the smallest valid position that is strictly greater than the given byte position. diff --git a/src/Init/Data/String/Legacy.lean b/src/Init/Data/String/Legacy.lean index f331ced212..9e9b79341a 100644 --- a/src/Init/Data/String/Legacy.lean +++ b/src/Init/Data/String/Legacy.lean @@ -73,7 +73,25 @@ def splitOnAux (s sep : String) (b : Pos.Raw) (i : Pos.Raw) (j : Pos.Raw) (r : L else splitOnAux s sep b ((i.unoffsetBy j).next s) 0 r termination_by (s.rawEndPos.1 - (j.byteDistance i), sep.rawEndPos.1 - j.1) -decreasing_by all_goals sorry -- TODO: restore after bootstrap +decreasing_by + focus + rename_i h _ _ + left; exact Nat.sub_lt_sub_left + (Nat.lt_of_le_of_lt (Nat.sub_le ..) (Nat.gt_of_not_le (mt decide_eq_true h))) + (Nat.lt_of_le_of_lt (Nat.sub_le ..) (Pos.Raw.lt_next s _)) + focus + rename_i i₀ j₀ _ eq h' + rw [show (j₀.next sep).byteDistance (i₀.next s) = j₀.byteDistance i₀ by + change (_ + Char.utf8Size _) - (_ + Char.utf8Size _) = _ + rw [(beq_iff_eq ..).1 eq, Nat.add_sub_add_right]; rfl] + right; exact Nat.sub_lt_sub_left + (Nat.lt_of_le_of_lt (Nat.le_add_right ..) (Nat.gt_of_not_le (mt decide_eq_true h'))) + (Pos.Raw.lt_next sep _) + focus + rename_i h _ + left; exact Nat.sub_lt_sub_left + (Nat.lt_of_le_of_lt (Nat.sub_le ..) (Nat.gt_of_not_le (mt decide_eq_true h))) + (Pos.Raw.lt_next s _) /-- Splits a string `s` on occurrences of the separator string `sep`. The default separator is `" "`. diff --git a/src/Init/Data/String/Lemmas/Order.lean b/src/Init/Data/String/Lemmas/Order.lean index 1d8d754f0c..a19d9e490c 100644 --- a/src/Init/Data/String/Lemmas/Order.lean +++ b/src/Init/Data/String/Lemmas/Order.lean @@ -29,7 +29,7 @@ theorem Pos.next_le_iff_lt {s : String} {p q : s.Pos} {h} : p.next h ≤ q ↔ p @[simp] theorem Slice.Pos.le_startPos {s : Slice} (p : s.Pos) : p ≤ s.startPos ↔ p = s.startPos := - ⟨fun h => Std.le_antisymm h (startPos_le _), by sorry⟩ + ⟨fun h => Std.le_antisymm h (startPos_le _), by simp +contextual⟩ @[simp] theorem Slice.Pos.startPos_lt_iff {s : Slice} (p : s.Pos) : s.startPos < p ↔ p ≠ s.startPos := by @@ -37,15 +37,15 @@ theorem Slice.Pos.startPos_lt_iff {s : Slice} (p : s.Pos) : s.startPos < p ↔ p @[simp] theorem Slice.Pos.endPos_le {s : Slice} (p : s.Pos) : s.endPos ≤ p ↔ p = s.endPos := - ⟨fun h => Std.le_antisymm (le_endPos _) h, by sorry⟩ + ⟨fun h => Std.le_antisymm (le_endPos _) h, by simp +contextual⟩ @[simp] theorem Pos.le_startPos {s : String} (p : s.Pos) : p ≤ s.startPos ↔ p = s.startPos := - ⟨fun h => Std.le_antisymm h (startPos_le _), by sorry⟩ + ⟨fun h => Std.le_antisymm h (startPos_le _), by simp +contextual⟩ @[simp] theorem Pos.endPos_le {s : String} (p : s.Pos) : s.endPos ≤ p ↔ p = s.endPos := - ⟨fun h => Std.le_antisymm (le_endPos _) h, by sorry⟩ + ⟨fun h => Std.le_antisymm (le_endPos _) h, by simp +contextual [Std.le_refl]⟩ @[simp] theorem Slice.Pos.not_lt_startPos {s : Slice} {p : s.Pos} : ¬ p < s.startPos := diff --git a/src/Init/Data/String/Modify.lean b/src/Init/Data/String/Modify.lean index a04ab21a2a..49db60be06 100644 --- a/src/Init/Data/String/Modify.lean +++ b/src/Init/Data/String/Modify.lean @@ -194,7 +194,8 @@ def modify (s : String) (i : Pos.Raw) (f : Char → Char) : String := else mapAux f (p.modify f h) (p.pastModify f h) termination_by p.remainingBytes -decreasing_by all_goals sorry -- TODO: restore after bootstrap +decreasing_by + simp [remainingBytes_pastModify, ← Pos.lt_iff_remainingBytes_lt] /-- Applies the function `f` to every character in a string, returning a string that contains the diff --git a/src/Init/Data/String/Pattern/Basic.lean b/src/Init/Data/String/Pattern/Basic.lean index dc1bed5d3e..c8d7f7d553 100644 --- a/src/Init/Data/String/Pattern/Basic.lean +++ b/src/Init/Data/String/Pattern/Basic.lean @@ -96,9 +96,9 @@ where else true termination_by len.byteIdx - curr.byteIdx - -- decreasing_by - -- simp [Pos.Raw.lt_iff] at h ⊢ - -- omega + decreasing_by + simp [Pos.Raw.lt_iff] at h ⊢ + omega @[inline] def memcmpSlice (lhs rhs : Slice) (lstart : String.Pos.Raw) (rstart : String.Pos.Raw) diff --git a/src/Init/Data/String/Pattern/Char.lean b/src/Init/Data/String/Pattern/Char.lean index 9567fbfe2e..aa3059c5d9 100644 --- a/src/Init/Data/String/Pattern/Char.lean +++ b/src/Init/Data/String/Pattern/Char.lean @@ -62,6 +62,13 @@ def finitenessRelation : Std.Iterators.FinitenessRelation (ForwardCharSearcher s wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨_, h2, _⟩ := h' + simp [h2] + · cases h' + · cases h instance : Std.Iterators.Finite (ForwardCharSearcher s c) Id := .of_finitenessRelation finitenessRelation @@ -120,6 +127,13 @@ def finitenessRelation : Std.Iterators.FinitenessRelation (BackwardCharSearcher wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨_, h1, h2, _⟩ := h' + simp [h2] + · cases h' + · cases h instance : Std.Iterators.Finite (BackwardCharSearcher s) Id := .of_finitenessRelation finitenessRelation diff --git a/src/Init/Data/String/Pattern/Pred.lean b/src/Init/Data/String/Pattern/Pred.lean index fe87d35841..43a0c772e6 100644 --- a/src/Init/Data/String/Pattern/Pred.lean +++ b/src/Init/Data/String/Pattern/Pred.lean @@ -64,6 +64,13 @@ def finitenessRelation : Std.Iterators.FinitenessRelation (ForwardCharPredSearch wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨_, h2, _⟩ := h' + simp [h2] + · cases h' + · cases h instance : Std.Iterators.Finite (ForwardCharPredSearcher p s) Id := .of_finitenessRelation finitenessRelation @@ -131,6 +138,15 @@ def finitenessRelation : Std.Iterators.FinitenessRelation (BackwardCharPredSearc wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨_, h1, h2, _⟩ := h' + have h3 := Pos.offset_prev_lt_offset (h := h1) + simp [Pos.ext_iff, String.Pos.Raw.ext_iff, String.Pos.Raw.lt_iff] at h2 h3 + omega + · cases h' + · cases h instance : Std.Iterators.Finite (BackwardCharPredSearcher s) Id := .of_finitenessRelation finitenessRelation diff --git a/src/Init/Data/String/Pattern/String.lean b/src/Init/Data/String/Pattern/String.lean index 74338009f2..1d7fe24d67 100644 --- a/src/Init/Data/String/Pattern/String.lean +++ b/src/Init/Data/String/Pattern/String.lean @@ -40,12 +40,20 @@ where let patByte := pat.getUTF8Byte ⟨table.size⟩ hs let dist := computeDistance patByte table ht h (table[table.size - 1]) (by have := h (table.size - 1) (by omega); omega) - let dist' := if pat.getUTF8Byte ⟨dist.1⟩ (by sorry) = patByte then dist.1 + 1 else dist - go (table.push dist') (by sorry) (by sorry) (by sorry) + let dist' := if pat.getUTF8Byte ⟨dist.1⟩ (by simp [Pos.Raw.lt_iff]; omega) = patByte then dist.1 + 1 else dist + go (table.push dist') (by simp) (by simp; omega) (by + intro i hi + by_cases hi' : i = table.size + · subst hi' + simp [dist'] + have := dist.2 + split <;> omega + · rw [Array.getElem_push_lt] + · apply h + · simp at hi + omega) else Vector.mk table (by omega) - termination_by pat.utf8ByteSize - table.size - decreasing_by all_goals sorry -- TODO: restore after bootstrap computeDistance (patByte : UInt8) (table : Array Nat) (ht : table.size ≤ pat.utf8ByteSize) @@ -217,6 +225,27 @@ private def finitenessRelation : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + all_goals try + cases h + revert h' + simp only [Std.IterM.IsPlausibleStep, Std.Iterator.IsPlausibleStep] + match it.internalState with + | .emptyBefore pos => + rintro (⟨h, h'⟩|h') <;> simp [h', ForwardSliceSearcher.toOption, Option.lt, Prod.lex_def] + | .emptyAt pos h => + simp only [forall_exists_index, and_imp] + intro x hx h + simpa [h, ForwardSliceSearcher.toOption, Option.lt, Prod.lex_def, + ← Pos.lt_iff_remainingBytes_lt] + | .proper needle table ht stackPos needlePos hn => + rintro (⟨newStackPos, newNeedlePos, h₁, h₂, (h|⟨rfl, h⟩)⟩|h) + · simp [h₂, ForwardSliceSearcher.toOption, Option.lt, Prod.lex_def, h] + · simpa [h₂, ForwardSliceSearcher.toOption, Option.lt, Prod.lex_def, Pos.Raw.lt_iff] + · simp [h, ForwardSliceSearcher.toOption, Option.lt] + | .atEnd .. => simp + · cases h @[no_expose] instance : Std.Iterators.Finite (ForwardSliceSearcher s) Id := diff --git a/src/Init/Data/String/Slice.lean b/src/Init/Data/String/Slice.lean index c9e728bca5..4820bbb957 100644 --- a/src/Init/Data/String/Slice.lean +++ b/src/Init/Data/String/Slice.lean @@ -170,6 +170,16 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] : wf := InvImage.wf _ (Option.wellFounded_lt Std.Iterators.Finite.wf_of_id) subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + match step with + | .yield it'' out | .skip it'' => + obtain rfl : it' = it'' := by simpa using h.symm + simp only [Std.IterM.IsPlausibleStep, Std.Iterator.IsPlausibleStep] at h' + revert h' + match it, it' with + | ⟨.operating _ searcher⟩, ⟨.operating _ searcher'⟩ => simp [SplitIterator.toOption, Option.lt] + | ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitIterator.toOption, Option.lt] + | ⟨.atEnd⟩, _ => simp @[no_expose] instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (SplitIterator pat s) Id := @@ -251,6 +261,16 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] : wf := InvImage.wf _ (Option.wellFounded_lt Std.Iterators.Finite.wf_of_id) subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + match step with + | .yield it'' out | .skip it'' => + obtain rfl : it' = it'' := by simpa using h.symm + simp only [Std.IterM.IsPlausibleStep, Std.Iterator.IsPlausibleStep] at h' + revert h' + match it, it' with + | ⟨.operating _ searcher⟩, ⟨.operating _ searcher'⟩ => simp [SplitInclusiveIterator.toOption, Option.lt] + | ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [SplitInclusiveIterator.toOption, Option.lt] + | ⟨.atEnd⟩, _ => simp @[no_expose] instance [Std.Iterators.Finite (σ s) Id] : @@ -581,6 +601,16 @@ private def finitenessRelation [Std.Iterators.Finite (σ s) Id] : wf := InvImage.wf _ (Option.wellFounded_lt Std.Iterators.Finite.wf_of_id) subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + match step with + | .yield it'' out | .skip it'' => + obtain rfl : it' = it'' := by simpa using h.symm + simp only [Std.IterM.IsPlausibleStep, Std.Iterator.IsPlausibleStep] at h' + revert h' + match it, it' with + | ⟨.operating _ searcher⟩, ⟨.operating _ searcher'⟩ => simp [RevSplitIterator.toOption, Option.lt] + | ⟨.operating _ searcher⟩, ⟨.atEnd⟩ => simp [RevSplitIterator.toOption, Option.lt] + | ⟨.atEnd⟩, _ => simp @[no_expose] instance [Std.Iterators.Finite (σ s) Id] : Std.Iterators.Finite (RevSplitIterator ρ s) Id := @@ -795,9 +825,9 @@ where else s1Curr == s1.rawEndPos && s2Curr == s2.rawEndPos termination_by s1.endPos.offset.byteIdx - s1Curr.byteIdx - -- decreasing_by - -- simp [String.Pos.Raw.lt_iff] at h ⊢ - -- omega + decreasing_by + simp [String.Pos.Raw.lt_iff] at h ⊢ + omega structure PosIterator (s : Slice) where currPos : s.Pos @@ -842,6 +872,17 @@ private def finitenessRelation [Pure m] : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨h1, h2, _⟩ := h' + have h3 := Char.utf8Size_pos (it.internalState.currPos.get h1) + have h4 := it.internalState.currPos.isValidForSlice.le_utf8ByteSize + simp [Pos.ext_iff, String.Pos.Raw.ext_iff] at h1 h2 h4 + omega + · cases h' + · cases h + @[no_expose] instance [Pure m] : Std.Iterators.Finite (PosIterator s) m := .of_finitenessRelation finitenessRelation @@ -913,6 +954,15 @@ private def finitenessRelation [Pure m] : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨h1, h2, _⟩ := h' + have h3 := Pos.offset_prev_lt_offset (h := h1) + simp [Pos.ext_iff, String.Pos.Raw.ext_iff, String.Pos.Raw.lt_iff] at h2 h3 + omega + · cases h' + · cases h @[no_expose] instance [Pure m] : Std.Iterators.Finite (RevPosIterator s) m := @@ -979,6 +1029,17 @@ private def finitenessRelation [Pure m] : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨h1, h2, h3, h4⟩ := h' + clear h4 + generalize it'.internalState.s = s at * + cases h2 + simp [String.Pos.Raw.ext_iff, String.Pos.Raw.lt_iff] at h1 h3 + omega + · cases h' + · cases h @[no_expose] instance [Pure m] : Std.Iterators.Finite ByteIterator m := @@ -1048,6 +1109,15 @@ private def finitenessRelation [Pure m] : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨h1, h2, h3, h4, h5⟩ := h' + rw [h4] + simp at h1 h3 ⊢ + omega + · cases h' + · cases h @[no_expose] instance [Pure m] : Std.Iterators.Finite RevByteIterator m := diff --git a/src/Init/Data/String/Termination.lean b/src/Init/Data/String/Termination.lean index f056be6b4d..fae1fdb997 100644 --- a/src/Init/Data/String/Termination.lean +++ b/src/Init/Data/String/Termination.lean @@ -181,7 +181,7 @@ theorem map_toSlice_prev? {s : String} {p : s.Pos} : theorem ne_endPos_of_next?_eq_some {s : String} {p q : s.Pos} (h : p.next? = some q) : p ≠ s.endPos := - ne_of_apply_ne Pos.toSlice (Slice.Pos.ne_endPos_of_next?_eq_some (q := q.toSlice) + ne_of_apply_ne Pos.toSlice (Slice.Pos.ne_endPos_of_next?_eq_some (by simpa only [Pos.map_toSlice_next?, Option.map_some] using congrArg (·.map toSlice) h)) theorem eq_next_of_next?_eq_some {s : String} {p q : s.Pos} (h : p.next? = some q) : @@ -191,7 +191,7 @@ theorem eq_next_of_next?_eq_some {s : String} {p q : s.Pos} (h : p.next? = some theorem ne_startPos_of_prev?_eq_some {s : String} {p q : s.Pos} (h : p.prev? = some q) : p ≠ s.startPos := - ne_of_apply_ne Pos.toSlice (Slice.Pos.ne_startPos_of_prev?_eq_some (q := q.toSlice) + ne_of_apply_ne Pos.toSlice (Slice.Pos.ne_startPos_of_prev?_eq_some (by simpa only [Pos.map_toSlice_prev?, Option.map_some] using congrArg (·.map toSlice) h)) theorem eq_prev_of_prev?_eq_some {s : String} {p q : s.Pos} (h : p.prev? = some q) : diff --git a/src/Init/Data/UInt/Lemmas.lean b/src/Init/Data/UInt/Lemmas.lean index 52d455e740..544fb83ae0 100644 --- a/src/Init/Data/UInt/Lemmas.lean +++ b/src/Init/Data/UInt/Lemmas.lean @@ -328,20 +328,20 @@ protected theorem USize.mod_eq_of_lt {a b : USize} (h : a < b) : a % b = a := US @[simp] theorem UInt64.toNat_lt (n : UInt64) : n.toNat < 2 ^ 64 := n.toFin.isLt theorem UInt8.size_lt_usizeSize : UInt8.size < USize.size := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide theorem UInt8.size_le_usizeSize : UInt8.size ≤ USize.size := Nat.le_of_lt UInt8.size_lt_usizeSize theorem UInt16.size_lt_usizeSize : UInt16.size < USize.size := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide theorem UInt16.size_le_usizeSize : UInt16.size ≤ USize.size := Nat.le_of_lt UInt16.size_lt_usizeSize theorem UInt32.size_le_usizeSize : UInt32.size ≤ USize.size := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide theorem USize.size_eq_two_pow : USize.size = 2 ^ System.Platform.numBits := (rfl) theorem USize.toNat_lt_two_pow_numBits (n : USize) : n.toNat < 2 ^ System.Platform.numBits := n.toFin.isLt @[simp] theorem USize.toNat_lt (n : USize) : n.toNat < 2 ^ 64 := Nat.lt_of_lt_of_le n.toFin.isLt size_le theorem USize.size_le_uint64Size : USize.size ≤ UInt64.size := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide theorem UInt8.toNat_lt_usizeSize (n : UInt8) : n.toNat < USize.size := Nat.lt_of_lt_of_le n.toNat_lt (by cases USize.size_eq <;> simp_all) @@ -350,10 +350,10 @@ theorem UInt16.toNat_lt_usizeSize (n : UInt16) : n.toNat < USize.size := theorem UInt32.toNat_lt_usizeSize (n : UInt32) : n.toNat < USize.size := Nat.lt_of_lt_of_le n.toNat_lt (by cases USize.size_eq <;> simp_all) -theorem UInt8.size_dvd_usizeSize : UInt8.size ∣ USize.size := by cases USize.size_eq <;> sorry -theorem UInt16.size_dvd_usizeSize : UInt16.size ∣ USize.size := by cases USize.size_eq <;> sorry -theorem UInt32.size_dvd_usizeSize : UInt32.size ∣ USize.size := by cases USize.size_eq <;> sorry -theorem USize.size_dvd_uInt64Size : USize.size ∣ UInt64.size := by cases USize.size_eq <;> sorry +theorem UInt8.size_dvd_usizeSize : UInt8.size ∣ USize.size := by cases USize.size_eq <;> simp_all +decide +theorem UInt16.size_dvd_usizeSize : UInt16.size ∣ USize.size := by cases USize.size_eq <;> simp_all +decide +theorem UInt32.size_dvd_usizeSize : UInt32.size ∣ USize.size := by cases USize.size_eq <;> simp_all +decide +theorem USize.size_dvd_uInt64Size : USize.size ∣ UInt64.size := by cases USize.size_eq <;> simp_all +decide @[simp] theorem mod_usizeSize_uInt8Size (n : Nat) : n % USize.size % UInt8.size = n % UInt8.size := Nat.mod_mod_of_dvd _ UInt8.size_dvd_usizeSize @@ -365,13 +365,13 @@ theorem USize.size_dvd_uInt64Size : USize.size ∣ UInt64.size := by cases USize Nat.mod_mod_of_dvd _ USize.size_dvd_uInt64Size @[simp] theorem USize.size_sub_one_mod_uint8Size : (USize.size - 1) % UInt8.size = UInt8.size - 1 := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide @[simp] theorem USize.size_sub_one_mod_uint16Size : (USize.size - 1) % UInt16.size = UInt16.size - 1 := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide @[simp] theorem USize.size_sub_one_mod_uint32Size : (USize.size - 1) % UInt32.size = UInt32.size - 1 := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide @[simp] theorem UInt64.size_sub_one_mod_uSizeSize : 18446744073709551615 % USize.size = USize.size - 1 := by - cases USize.size_eq <;> sorry + cases USize.size_eq <;> simp_all +decide @[simp] theorem UInt8.toNat_mod_size (n : UInt8) : n.toNat % UInt8.size = n.toNat := Nat.mod_eq_of_lt n.toNat_lt @[simp] theorem UInt8.toNat_mod_uInt16Size (n : UInt8) : n.toNat % UInt16.size = n.toNat := Nat.mod_eq_of_lt (Nat.lt_trans n.toNat_lt (by decide)) @@ -1257,7 +1257,7 @@ theorem USize.toUInt64_ofNatTruncate_of_lt {n : Nat} (hn : n < USize.size) : UInt64.toNat.inj (by simp [toNat_ofNatTruncate_of_lt hn]) theorem USize.toUInt64_ofNatTruncate_of_le {n : Nat} (hn : USize.size ≤ n) : - (USize.ofNatTruncate n).toUInt64 = UInt64.ofNatLT (USize.size - 1) (by cases USize.size_eq <;> sorry) := + (USize.ofNatTruncate n).toUInt64 = UInt64.ofNatLT (USize.size - 1) (by cases USize.size_eq <;> simp_all +decide) := UInt64.toNat.inj (by simp [toNat_ofNatTruncate_of_le hn]) @[simp] theorem UInt8.toUInt16_ofNat' {n : Nat} (hn : n < UInt8.size) : (UInt8.ofNat n).toUInt16 = UInt16.ofNat n := by diff --git a/src/Init/Data/Vector/Algebra.lean b/src/Init/Data/Vector/Algebra.lean index 0cc9ac5d7c..6abc8e4c6f 100644 --- a/src/Init/Data/Vector/Algebra.lean +++ b/src/Init/Data/Vector/Algebra.lean @@ -15,8 +15,6 @@ public import Init.Grind public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Vector /-- The zero vector. -/ diff --git a/src/Init/Data/Vector/Attach.lean b/src/Init/Data/Vector/Attach.lean index 323dd741a5..c6c40701e6 100644 --- a/src/Init/Data/Vector/Attach.lean +++ b/src/Init/Data/Vector/Attach.lean @@ -13,7 +13,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Basic.lean b/src/Init/Data/Vector/Basic.lean index 461aff7027..1fb44b248b 100644 --- a/src/Init/Data/Vector/Basic.lean +++ b/src/Init/Data/Vector/Basic.lean @@ -24,7 +24,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap /-- `Vector α n` is an `Array α` with size `n`. -/ structure Vector (α : Type u) (n : Nat) where diff --git a/src/Init/Data/Vector/Count.lean b/src/Init/Data/Vector/Count.lean index c57d2d5f29..d8100d7e96 100644 --- a/src/Init/Data/Vector/Count.lean +++ b/src/Init/Data/Vector/Count.lean @@ -18,7 +18,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/DecidableEq.lean b/src/Init/Data/Vector/DecidableEq.lean index 9228ecb242..f29fc8fb2b 100644 --- a/src/Init/Data/Vector/DecidableEq.lean +++ b/src/Init/Data/Vector/DecidableEq.lean @@ -12,7 +12,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Erase.lean b/src/Init/Data/Vector/Erase.lean index b23660d303..9662cd74fb 100644 --- a/src/Init/Data/Vector/Erase.lean +++ b/src/Init/Data/Vector/Erase.lean @@ -17,7 +17,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector @@ -26,7 +25,7 @@ open Nat /-! ### eraseIdx -/ @[grind =] -theorem eraseIdx_eq_take_drop_succ {xs : Vector α n} {i : Nat} (h : i < n) : +theorem eraseIdx_eq_take_drop_succ {xs : Vector α n} {i : Nat} (h) : xs.eraseIdx i = (xs.take i ++ xs.drop (i + 1)).cast (by omega) := by rcases xs with ⟨xs, rfl⟩ simp [Array.eraseIdx_eq_take_drop_succ, *] @@ -56,19 +55,19 @@ theorem getElem_eraseIdx {xs : Vector α n} {i : Nat} (h : i < n) {j : Nat} (h' rw [← getElem?_eq_getElem, getElem?_eraseIdx] split <;> simp -theorem mem_of_mem_eraseIdx {xs : Vector α n} {i : Nat} {h : i < n} {a : α} (hm : a ∈ xs.eraseIdx i) : a ∈ xs := by +theorem mem_of_mem_eraseIdx {xs : Vector α n} {i : Nat} {h} {a : α} (h : a ∈ xs.eraseIdx i) : a ∈ xs := by rcases xs with ⟨xs, rfl⟩ - simpa using Array.mem_of_mem_eraseIdx (by simpa using hm) + simpa using Array.mem_of_mem_eraseIdx (by simpa using h) grind_pattern mem_of_mem_eraseIdx => a ∈ xs.eraseIdx i -theorem eraseIdx_append_of_lt_size {xs : Vector α n} {k : Nat} (hk : k < n) (xs' : Vector α n) (h : k < n + n) : +theorem eraseIdx_append_of_lt_size {xs : Vector α n} {k : Nat} (hk : k < n) (xs' : Vector α n) (h) : eraseIdx (xs ++ xs') k = (eraseIdx xs k ++ xs').cast (by omega) := by rcases xs with ⟨xs⟩ rcases xs' with ⟨xs'⟩ simp [Array.eraseIdx_append_of_lt_size, *] -theorem eraseIdx_append_of_length_le {xs : Vector α n} {k : Nat} (hk : n ≤ k) (xs' : Vector α n) (h : k < n + n) : +theorem eraseIdx_append_of_length_le {xs : Vector α n} {k : Nat} (hk : n ≤ k) (xs' : Vector α n) (h) : eraseIdx (xs ++ xs') k = (xs ++ eraseIdx xs' (k - n)).cast (by omega) := by rcases xs with ⟨xs⟩ rcases xs' with ⟨xs'⟩ @@ -89,16 +88,16 @@ theorem eraseIdx_cast {xs : Vector α n} {k : Nat} (h : k < m) : simp @[grind =] -theorem eraseIdx_replicate {n : Nat} {a : α} {k : Nat} {h : k < n} : +theorem eraseIdx_replicate {n : Nat} {a : α} {k : Nat} {h} : (replicate n a).eraseIdx k = replicate (n - 1) a := by rw [replicate_eq_mk_replicate, eraseIdx_mk] simp [Array.eraseIdx_replicate, *] -theorem mem_eraseIdx_iff_getElem {x : α} {xs : Vector α n} {k : Nat} {h : k < n} : x ∈ xs.eraseIdx k h ↔ ∃ i w, i ≠ k ∧ xs[i]'w = x := by +theorem mem_eraseIdx_iff_getElem {x : α} {xs : Vector α n} {k} {h} : x ∈ xs.eraseIdx k h ↔ ∃ i w, i ≠ k ∧ xs[i]'w = x := by rcases xs with ⟨xs⟩ simp [Array.mem_eraseIdx_iff_getElem, *] -theorem mem_eraseIdx_iff_getElem? {x : α} {xs : Vector α n} {k : Nat} {h : k < n} : x ∈ xs.eraseIdx k h ↔ ∃ i ≠ k, xs[i]? = some x := by +theorem mem_eraseIdx_iff_getElem? {x : α} {xs : Vector α n} {k} {h} : x ∈ xs.eraseIdx k h ↔ ∃ i ≠ k, xs[i]? = some x := by rcases xs with ⟨xs⟩ simp [Array.mem_eraseIdx_iff_getElem?, *] diff --git a/src/Init/Data/Vector/Extract.lean b/src/Init/Data/Vector/Extract.lean index 65e94addc1..39b2ae7723 100644 --- a/src/Init/Data/Vector/Extract.lean +++ b/src/Init/Data/Vector/Extract.lean @@ -17,7 +17,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap open Nat diff --git a/src/Init/Data/Vector/FinRange.lean b/src/Init/Data/Vector/FinRange.lean index 9e248fc70a..25c23f7217 100644 --- a/src/Init/Data/Vector/FinRange.lean +++ b/src/Init/Data/Vector/FinRange.lean @@ -13,7 +13,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Find.lean b/src/Init/Data/Vector/Find.lean index b5f28796a8..aeb211aaec 100644 --- a/src/Init/Data/Vector/Find.lean +++ b/src/Init/Data/Vector/Find.lean @@ -20,7 +20,6 @@ We are still missing results about `idxOf?`, `findIdx`, and `findIdx?`. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector @@ -283,7 +282,7 @@ theorem find?_pmap {P : α → Prop} {f : (a : α) → P a → β} {xs : Vector rfl theorem find?_eq_some_iff_getElem {xs : Vector α n} {p : α → Bool} {b : α} : - xs.find? p = some b ↔ p b ∧ ∃ (i : Nat) (h : i < n), xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by + xs.find? p = some b ↔ p b ∧ ∃ i h, xs[i] = b ∧ ∀ j : Nat, (hj : j < i) → !p xs[j] := by rcases xs with ⟨xs, rfl⟩ simp [Array.find?_eq_some_iff_getElem] diff --git a/src/Init/Data/Vector/InsertIdx.lean b/src/Init/Data/Vector/InsertIdx.lean index cb3094b1b1..c9fbcdee0c 100644 --- a/src/Init/Data/Vector/InsertIdx.lean +++ b/src/Init/Data/Vector/InsertIdx.lean @@ -18,7 +18,6 @@ Proves various lemmas about `Vector.insertIdx`. set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap open Function Nat diff --git a/src/Init/Data/Vector/Lemmas.lean b/src/Init/Data/Vector/Lemmas.lean index 5f7a3a2f1a..2beeda5cdb 100644 --- a/src/Init/Data/Vector/Lemmas.lean +++ b/src/Init/Data/Vector/Lemmas.lean @@ -20,7 +20,6 @@ Lemmas about `Vector α n` set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Array @@ -186,7 +185,7 @@ theorem toArray_mk {xs : Array α} (h : xs.size = n) : (Vector.mk xs h).toArray @[simp] theorem reverse_mk {xs : Array α} (h : xs.size = n) : (Vector.mk xs h).reverse = Vector.mk xs.reverse (by simp [h]) := rfl -@[simp] theorem set_mk {xs : Array α} (h : xs.size = n) {i x} (w : i < n) : +@[simp] theorem set_mk {xs : Array α} (h : xs.size = n) {i x} (w) : (Vector.mk xs h).set i x = Vector.mk (xs.set i x) (by simp [h]) := rfl @[simp] theorem set!_mk {xs : Array α} (h : xs.size = n) {i x} : @@ -195,14 +194,14 @@ theorem toArray_mk {xs : Array α} (h : xs.size = n) : (Vector.mk xs h).toArray @[simp] theorem setIfInBounds_mk {xs : Array α} (h : xs.size = n) {i x} : (Vector.mk xs h).setIfInBounds i x = Vector.mk (xs.setIfInBounds i x) (by simp [h]) := rfl -@[simp] theorem swap_mk {xs : Array α} (h : xs.size = n) {i j} (hi : i < n) (hj : j < n) : +@[simp] theorem swap_mk {xs : Array α} (h : xs.size = n) {i j} (hi hj) : (Vector.mk xs h).swap i j = Vector.mk (xs.swap i j) (by simp [h]) := rfl @[simp] theorem swapIfInBounds_mk {xs : Array α} (h : xs.size = n) {i j} : (Vector.mk xs h).swapIfInBounds i j = Vector.mk (xs.swapIfInBounds i j) (by simp [h]) := rfl -@[simp] theorem swapAt_mk {xs : Array α} (h : xs.size = n) {i x} (hi : i < n) : +@[simp] theorem swapAt_mk {xs : Array α} (h : xs.size = n) {i x} (hi) : (Vector.mk xs h).swapAt i x = ((xs.swapAt i x).fst, Vector.mk (xs.swapAt i x).snd (by simp [h])) := rfl @@ -356,7 +355,7 @@ private theorem toArray_mapM_go [Monad m] [LawfulMonad m] {f : α → m β} {xs @[simp, grind =] theorem toArray_reverse (xs : Vector α n) : xs.reverse.toArray = xs.toArray.reverse := rfl -@[simp, grind =] theorem toArray_set {xs : Vector α n} {i x} (h : i < n) : +@[simp, grind =] theorem toArray_set {xs : Vector α n} {i x} (h) : (xs.set i x).toArray = xs.toArray.set i x (by simpa using h):= rfl @[simp, grind =] theorem toArray_set! {xs : Vector α n} {i x} : @@ -367,13 +366,13 @@ private theorem toArray_mapM_go [Monad m] [LawfulMonad m] {f : α → m β} {xs @[simp, grind =] theorem toArray_singleton {x : α} : (Vector.singleton x).toArray = #[x] := rfl -@[simp, grind =] theorem toArray_swap {xs : Vector α n} {i j} (hi : i < n) (hj : j < n) : (xs.swap i j).toArray = +@[simp, grind =] theorem toArray_swap {xs : Vector α n} {i j} (hi hj) : (xs.swap i j).toArray = xs.toArray.swap i j (by simp [hj]) (by simp [hi]) := rfl @[simp, grind =] theorem toArray_swapIfInBounds {xs : Vector α n} {i j} : (xs.swapIfInBounds i j).toArray = xs.toArray.swapIfInBounds i j := rfl -theorem toArray_swapAt {xs : Vector α n} {i x} (h : i < n) : +theorem toArray_swapAt {xs : Vector α n} {i x} (h) : ((xs.swapAt i x).fst, (xs.swapAt i x).snd.toArray) = ((xs.toArray.swapAt i x (by simpa using h)).fst, (xs.toArray.swapAt i x (by simpa using h)).snd) := rfl @@ -585,7 +584,7 @@ theorem toList_range : (Vector.range n).toList = List.range n := by simp [toList @[simp] theorem toList_reverse {xs : Vector α n} : xs.reverse.toList = xs.toList.reverse := by simp [toList] -theorem toList_set {xs : Vector α n} {i x} (h : i < n) : +theorem toList_set {xs : Vector α n} {i x} (h) : (xs.set i x).toList = xs.toList.set i x := rfl @[simp] theorem toList_setIfInBounds {xs : Vector α n} {i x} : @@ -594,7 +593,7 @@ theorem toList_set {xs : Vector α n} {i x} (h : i < n) : theorem toList_singleton {x : α} : (Vector.singleton x).toList = [x] := rfl -theorem toList_swap {xs : Vector α n} {i j} (hi : i < n) (hj : j < n) : +theorem toList_swap {xs : Vector α n} {i j} (hi hj) : (xs.swap i j).toList = (xs.toList.set i xs[j]).set j xs[i] := rfl @[simp] theorem toList_take {xs : Vector α n} {i} : (xs.take i).toList = xs.toList.take i := by @@ -1023,21 +1022,21 @@ theorem getElem_of_mem {a} {xs : Vector α n} (h : a ∈ xs) : ∃ (i : Nat) (h simpa using Array.getElem_of_mem (by simpa using h) theorem getElem?_of_mem {a} {xs : Vector α n} (h : a ∈ xs) : ∃ i : Nat, xs[i]? = some a := - let ⟨n, hn, e⟩ := getElem_of_mem h; ⟨n, e ▸ getElem?_eq_getElem hn⟩ + let ⟨n, _, e⟩ := getElem_of_mem h; ⟨n, e ▸ getElem?_eq_getElem _⟩ -theorem mem_of_getElem {xs : Vector α n} {i : Nat} {h : i < n} {a : α} (e : xs[i] = a) : a ∈ xs := by +theorem mem_of_getElem {xs : Vector α n} {i : Nat} {h} {a : α} (e : xs[i] = a) : a ∈ xs := by subst e simp theorem mem_of_getElem? {xs : Vector α n} {i : Nat} {a : α} (e : xs[i]? = some a) : a ∈ xs := - let ⟨h, e⟩ := getElem?_eq_some_iff.1 e; e ▸ getElem_mem h + let ⟨_, e⟩ := getElem?_eq_some_iff.1 e; e ▸ getElem_mem .. theorem mem_of_back? {xs : Vector α n} {a : α} (h : xs.back? = some a) : a ∈ xs := by cases xs simpa using Array.mem_of_back? (by simpa using h) theorem mem_iff_getElem {a} {xs : Vector α n} : a ∈ xs ↔ ∃ (i : Nat) (h : i < n), xs[i]'h = a := - ⟨getElem_of_mem, fun ⟨_, h, e⟩ => e ▸ getElem_mem h⟩ + ⟨getElem_of_mem, fun ⟨_, _, e⟩ => e ▸ getElem_mem ..⟩ theorem mem_iff_getElem? {a} {xs : Vector α n} : a ∈ xs ↔ ∃ i : Nat, xs[i]? = some a := by simp [getElem?_eq_some_iff, mem_iff_getElem] @@ -1275,7 +1274,7 @@ instance [BEq α] [LawfulBEq α] (a : α) (as : Vector α n) : Decidable (a ∈ cases xs simp -theorem set_push {xs : Vector α n} {x y : α} {h : i < n + 1} : +theorem set_push {xs : Vector α n} {x y : α} {h} : (xs.push x).set i y = if _ : i < n then (xs.set i y).push x else xs.push y := by rcases xs with ⟨xs, rfl⟩ simp only [push_mk, set_mk, Array.set_push] diff --git a/src/Init/Data/Vector/Lex.lean b/src/Init/Data/Vector/Lex.lean index 843d503051..990821753a 100644 --- a/src/Init/Data/Vector/Lex.lean +++ b/src/Init/Data/Vector/Lex.lean @@ -18,7 +18,6 @@ open Std set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/MapIdx.lean b/src/Init/Data/Vector/MapIdx.lean index 01605d2917..dba66e46c2 100644 --- a/src/Init/Data/Vector/MapIdx.lean +++ b/src/Init/Data/Vector/MapIdx.lean @@ -14,7 +14,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Monadic.lean b/src/Init/Data/Vector/Monadic.lean index 4316e3862e..ffed339a1e 100644 --- a/src/Init/Data/Vector/Monadic.lean +++ b/src/Init/Data/Vector/Monadic.lean @@ -17,7 +17,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/OfFn.lean b/src/Init/Data/Vector/OfFn.lean index e5f4898213..79751b71ed 100644 --- a/src/Init/Data/Vector/OfFn.lean +++ b/src/Init/Data/Vector/OfFn.lean @@ -17,7 +17,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Range.lean b/src/Init/Data/Vector/Range.lean index 777702358e..95c83f1f22 100644 --- a/src/Init/Data/Vector/Range.lean +++ b/src/Init/Data/Vector/Range.lean @@ -20,7 +20,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector diff --git a/src/Init/Data/Vector/Zip.lean b/src/Init/Data/Vector/Zip.lean index f13010942a..44f31aa9ff 100644 --- a/src/Init/Data/Vector/Zip.lean +++ b/src/Init/Data/Vector/Zip.lean @@ -18,7 +18,6 @@ public section set_option linter.listVariables true -- Enforce naming conventions for `List`/`Array`/`Vector` variables. set_option linter.indexVariables true -- Enforce naming conventions for index variables. -set_option debug.byAsSorry true -- TODO: remove after bootstrap namespace Vector @@ -188,7 +187,7 @@ theorem reverse_zipWith {f : α → β → γ} {as : Vector α n} {bs : Vector @[simp, grind =] theorem getElem_zip {as : Vector α n} {bs : Vector β n} {i : Nat} {h : i < n} : (zip as bs)[i] = (as[i], bs[i]) := - getElem_zipWith h + getElem_zipWith .. theorem zip_eq_zipWith {as : Vector α n} {bs : Vector β n} : zip as bs = zipWith Prod.mk as bs := by rcases as with ⟨as, rfl⟩ diff --git a/src/Init/GetElem.lean b/src/Init/GetElem.lean index c81290176a..8c440891e0 100644 --- a/src/Init/GetElem.lean +++ b/src/Init/GetElem.lean @@ -244,7 +244,7 @@ theorem getElem_of_getElem? [GetElem? cont idx elem dom] [LawfulGetElem cont idx getElem?_eq_some_iff.mp h theorem of_getElem_eq [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom] - {c : cont} {i : idx} [Decidable (dom c i)] {h : dom c i} (_ : c[i] = e) : dom c i := h + {c : cont} {i : idx} [Decidable (dom c i)] {h} (_ : c[i] = e) : dom c i := h @[simp] theorem some_getElem_eq_getElem?_iff [GetElem? cont idx elem dom] [LawfulGetElem cont idx elem dom] {c : cont} {i : idx} [Decidable (dom c i)] (h : dom c i): diff --git a/src/Init/Grind/AC.lean b/src/Init/Grind/AC.lean index 3c8b19332c..ede4fc5e78 100644 --- a/src/Init/Grind/AC.lean +++ b/src/Init/Grind/AC.lean @@ -140,19 +140,23 @@ attribute [local simp] Seq.erase0_k_var Seq.erase0_k_cons theorem Seq.erase0_k_eq_erase0 (s : Seq) : s.erase0_k = s.erase0 := by fun_induction erase0 s <;> simp - next h ih => simp at h; sorry + next h ih => simp at h; simp +zetaDelta; simp [← ih, h] next x _ _ h₁ h₂ ih => replace h₁ : Nat.beq x 0 = false := by rw [← Bool.not_eq_true, Nat.beq_eq]; simp at h₁; assumption - sorry + simp +zetaDelta [← Seq.beq'_eq, ← ih] at h₂ + simp [h₁, h₂] next x _ _ h₁ h₂ ih => replace h₁ : Nat.beq x 0 = false := by rw [← Bool.not_eq_true, Nat.beq_eq]; simp at h₁; assumption - sorry + simp +zetaDelta [← Seq.beq'_eq, ← ih] at h₂ + simp +zetaDelta [h₁, h₂, ← ih] attribute [local simp] Seq.erase0_k_eq_erase0 theorem Seq.denote_erase0 {α} (ctx : Context α) {inst : Std.LawfulIdentity ctx.op (Var.denote ctx 0)} (s : Seq) : s.erase0.denote ctx = s.denote ctx := by - fun_induction erase0 s <;> sorry + fun_induction erase0 s <;> simp_all +zetaDelta + next => rw [Std.LawfulLeftIdentity.left_id (self := inst.toLawfulLeftIdentity)] + next => rw [Std.LawfulRightIdentity.right_id (self := inst.toLawfulRightIdentity)] attribute [local simp] Seq.denote_erase0 @@ -265,7 +269,9 @@ attribute [local simp] Seq.eraseDup_k_eq_eraseDup theorem Seq.denote_eraseDup {α} (ctx : Context α) {inst₁ : Std.Associative ctx.op} {inst₂ : Std.IdempotentOp ctx.op} (s : Seq) : s.eraseDup.denote ctx = s.denote ctx := by - fun_induction eraseDup s <;> sorry + fun_induction eraseDup s <;> simp_all +zetaDelta + next ih => simp [← ih, Std.IdempotentOp.idempotent] + next ih => simp [← ih, ← Std.Associative.assoc (self := inst₁), Std.IdempotentOp.idempotent] attribute [local simp] Seq.denote_eraseDup diff --git a/src/Init/Grind/Module/NatModuleNorm.lean b/src/Init/Grind/Module/NatModuleNorm.lean index 826dde9135..6a1bbb93ff 100644 --- a/src/Init/Grind/Module/NatModuleNorm.lean +++ b/src/Init/Grind/Module/NatModuleNorm.lean @@ -84,12 +84,18 @@ theorem Poly.denoteN_combine {α} [NatModule α] (ctx : Context α) (p₁ p₂ : fun_induction p₁.combine p₂ <;> intro h₁ h₂ <;> try simp [*, zero_add, add_zero] next hx _ h ih => simp at hx - sorry + simp +zetaDelta at h + cases h₁; cases h₂ + next h₁ _ h₂ => + simp [ih h₁ h₂, *] + rw [add_left_comm, add_assoc, ← add_assoc, ← add_nsmul, ← Int.toNat_add, Int.add_comm, h, + Int.toNat_zero, zero_nsmul, zero_add] <;> assumption next hx _ h ih => simp at hx cases h₁; cases h₂ next hp₁ h₁ hp₂ h₂ => - sorry + simp +zetaDelta [*] + rw [denoteN_add, ih h₁ h₂, Int.toNat_add hp₁ hp₂, add_nsmul]; ac_rfl; omega next ih => cases h₁; next h₁ => simp [ih h₁ h₂, *]; ac_rfl @@ -150,11 +156,11 @@ theorem Poly.combine_Nonneg (p₁ p₂ : Poly) : p₁.NonnegCoeffs → p₂.Nonn apply ih <;> assumption next h ih => intro h₁ h₂; cases h₁; cases h₂ - constructor; sorry + constructor; simp +zetaDelta; omega apply ih <;> assumption next ih => intro h₁ h₂; cases h₁; cases h₂ - constructor; sorry + constructor; simp +zetaDelta; omega apply ih; assumption; constructor; assumption; assumption next ih => intro h₁ h₂; cases h₁; cases h₂ diff --git a/src/Init/Grind/Ordered/Linarith.lean b/src/Init/Grind/Ordered/Linarith.lean index e603dbfa98..1239955158 100644 --- a/src/Init/Grind/Ordered/Linarith.lean +++ b/src/Init/Grind/Ordered/Linarith.lean @@ -139,7 +139,6 @@ def Poly.combine (p₁ p₂ : Poly) : Poly := else .add a₂ x₂ (combine (.add a₁ x₁ p₁) p₂) termination_by sizeOf p₁ + sizeOf p₂ - decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Converts the given expression into a polynomial. -/ def Expr.toPoly' (e : Expr) : Poly := @@ -203,7 +202,13 @@ theorem Poly.denote_append {α} [IntModule α] (ctx : Context α) (p₁ p₂ : P attribute [local simp] Poly.denote_append theorem Poly.denote_combine {α} [IntModule α] (ctx : Context α) (p₁ p₂ : Poly) : (p₁.combine p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by - fun_induction p₁.combine p₂ <;> sorry + fun_induction p₁.combine p₂ <;> + simp_all +zetaDelta [denote] + next h _ => + rw [Int.add_comm] at h + rw [add_left_comm, add_assoc, ← add_assoc, ← add_zsmul, h, zero_zsmul, zero_add] + next => rw [add_zsmul]; ac_rfl + all_goals ac_rfl attribute [local simp] Poly.denote_combine diff --git a/src/Init/Grind/Ordered/Ring.lean b/src/Init/Grind/Ordered/Ring.lean index 31b342bc1f..9dbeac9ac7 100644 --- a/src/Init/Grind/Ordered/Ring.lean +++ b/src/Init/Grind/Ordered/Ring.lean @@ -175,7 +175,7 @@ theorem pos_natCast_of_pos (a : Nat) : 0 < a → 0 < (a : R) := by next => simp next n ih => simp; cases n - next => sorry + next => simp +arith; rw [Semiring.natCast_one]; apply zero_lt_one next => simp at ih replace ih := OrderedAdd.add_lt_add ih zero_lt_one diff --git a/src/Init/Grind/Ring/CommSemiringAdapter.lean b/src/Init/Grind/Ring/CommSemiringAdapter.lean index 952650308a..1d958a08e8 100644 --- a/src/Init/Grind/Ring/CommSemiringAdapter.lean +++ b/src/Init/Grind/Ring/CommSemiringAdapter.lean @@ -124,7 +124,22 @@ theorem Poly.denoteS_insert {α} [Semiring α] (ctx : Context α) (k : Int) (m : intro _ hn simp at h <;> simp [*, Mon.denote, denoteS_addConst, add_comm] next => - fun_induction insert.go <;> sorry + fun_induction insert.go <;> simp_all +zetaDelta [denoteS] + next a m p _ _ h₁ h₂ => + intro hk hn + cases hn; rename_i hn₁ hn₂ + replace h₂ : k.toNat + a.toNat = 0 := by + apply Int.ofNat_inj.mp + rw [Int.natCast_add, Int.toNat_of_nonneg hn₁, + Int.toNat_of_nonneg hk, h₂]; rfl + rw [← add_assoc, Mon.eq_of_grevlex h₁, ← right_distrib, ← natCast_add, h₂] + simp + next h₁ _ => + intro _ hn; cases hn + rw [Int.toNat_add, natCast_add, right_distrib, add_assoc, Mon.eq_of_grevlex h₁] <;> assumption + next ih => + intro hk hn; cases hn; rename_i hn₁ hn₂ + rw [ih hk hn₂, add_left_comm] theorem Poly.denoteS_concat {α} [Semiring α] (ctx : Context α) (p₁ p₂ : Poly) : p₁.NonnegCoeffs → p₂.NonnegCoeffs → (concat p₁ p₂).denoteS ctx = p₁.denoteS ctx + p₂.denoteS ctx := by @@ -157,11 +172,19 @@ theorem Poly.denoteS_combine {α} [Semiring α] (ctx : Context α) (p₁ p₂ : case case5 k₁ _ _ k₂ _ _ hg _ h ih => intro h₁ h₂ cases h₁; cases h₂ - sorry + simp +zetaDelta at h + rename_i h₁ h₂ h₃ h₄ + simp [ih h₂ h₄, denoteS, Mon.eq_of_grevlex hg] + replace h : k₂.toNat + k₁.toNat = 0 := by + rw [← Int.toNat_add, Int.add_comm, h]; rfl; assumption; assumption + rw [add_left_comm, ← add_assoc, ← add_assoc, ← right_distrib, ← natCast_add, h] + simp case case6 hg k h ih => intro h₁ h₂ cases h₁; cases h₂ - sorry + simp +zetaDelta + simp [denoteS, Int.toNat_add, natCast_add, right_distrib, Mon.eq_of_grevlex hg, + add_left_comm, add_assoc, *] case case7 ih => intro h₁ h₂; cases h₁ rename_i h₁ @@ -182,7 +205,7 @@ theorem Poly.denoteS_mulMon {α} [CommSemiring α] (ctx : Context α) (k : Int) simp at h; simp [*, Mon.denote, denoteS_mulConst _ _ _ h₁ h₂] next => fun_induction mulMon.go <;> simp [denoteS, *] - next h => sorry + next h => simp +zetaDelta at h; simp [*] next => intro h₁ h₂; cases h₂ rw [Int.toNat_mul] @@ -210,7 +233,7 @@ theorem Poly.insert_Nonneg (k : Int) (m : Mon) (p : Poly) : k ≥ 0 → p.Nonneg fun_induction Poly.insert.go next => constructor <;> assumption next => cases h₂; assumption - next => sorry + next => simp +zetaDelta; cases h₂; constructor; omega; assumption next => constructor <;> assumption next ih => cases h₂; constructor @@ -322,7 +345,8 @@ theorem Poly.combine_NonnegCoeffs {p₁ p₂ : Poly} : p₁.NonnegCoeffs → p next => intro h₁ h₂; apply addConst_NonnegCoeffs; cases h₂; assumption; assumption next ih => intro h₁ h₂; cases h₁; cases h₂; apply ih <;> assumption next ih => - sorry + simp +zetaDelta; intro h₁ h₂; cases h₁; cases h₂; constructor; apply Int.add_nonneg <;> assumption + apply ih <;> assumption next ih => intro h₁ h₂; cases h₁; cases h₂; constructor; assumption apply ih; assumption diff --git a/src/Init/Grind/Ring/CommSolver.lean b/src/Init/Grind/Ring/CommSolver.lean index 93bd8c4fe8..59557b1436 100644 --- a/src/Init/Grind/Ring/CommSolver.lean +++ b/src/Init/Grind/Ring/CommSolver.lean @@ -291,8 +291,6 @@ def Mon.revlexWF (m₁ m₂ : Mon) : Ordering := revlexWF m₁ (.mult pw₂ m₂) |>.then .lt else revlexWF (.mult pw₁ m₁) m₂ |>.then .gt -termination_by (m₁.length, m₂.length) -decreasing_by all_goals sorry -- TODO: restore after bootstrap def Mon.revlexFuel (fuel : Nat) (m₁ m₂ : Mon) : Ordering := match fuel with @@ -1130,7 +1128,13 @@ theorem Poly.denote_insert {α} [Ring α] (ctx : Context α) (k : Int) (m : Mon) next h => simp at h <;> simp [*, Mon.denote, denote_addConst, mul_one, add_comm] next => - fun_induction insert.go <;> sorry + fun_induction insert.go <;> simp_all +zetaDelta [denote, zsmul_eq_intCast_mul] + next h₁ h₂ => + rw [← add_assoc, Mon.eq_of_grevlex h₁, ← right_distrib, ← intCast_add, h₂, intCast_zero, zero_mul, zero_add] + next h₁ _ => + rw [intCast_add, right_distrib, add_assoc, Mon.eq_of_grevlex h₁] + next => + rw [add_left_comm] theorem Poly.denote_concat {α} [Ring α] (ctx : Context α) (p₁ p₂ : Poly) : (concat p₁ p₂).denote ctx = p₁.denote ctx + p₂.denote ctx := by @@ -1158,7 +1162,7 @@ theorem Poly.denote_mulMon {α} [CommRing α] (ctx : Context α) (k : Int) (m : simp at h; simp [*, Mon.denote, mul_one, denote_mulConst] next => fun_induction mulMon.go <;> simp [denote, zsmul_eq_intCast_mul, *] - next h => sorry + next h => simp +zetaDelta at h; simp [*, intCast_zero, mul_zero] next => simp [intCast_mul, intCast_zero, add_zero, mul_comm, mul_left_comm, mul_assoc] next => simp [Mon.denote_mul, intCast_mul, left_distrib, mul_left_comm, mul_assoc] @@ -1189,9 +1193,11 @@ theorem Poly.denote_combine {α} [Ring α] (ctx : Context α) (p₁ p₂ : Poly) fun_induction combine.go <;> simp [*, denote_concat, denote_addConst, denote, intCast_add, add_comm, add_left_comm, add_assoc, zsmul_eq_intCast_mul] case case5 hg _ h _ => - sorry + simp +zetaDelta at h + rw [← add_assoc, Mon.eq_of_grevlex hg, ← right_distrib, ← intCast_add, h, intCast_zero, zero_mul, zero_add] case case6 hg k h _ => - sorry + simp +zetaDelta [intCast_add] + rw [right_distrib, Mon.eq_of_grevlex hg, add_assoc] theorem Poly.denote_mul_go {α} [CommRing α] (ctx : Context α) (p₁ p₂ acc : Poly) : (mul.go p₂ p₁ acc).denote ctx = acc.denote ctx + p₁.denote ctx * p₂.denote ctx := by @@ -1280,7 +1286,15 @@ theorem Poly.denote_cancelVar' {α} [CommRing α] (ctx : Context α) (p : Poly) congr 1 rw [Semiring.add_comm, Ring.zsmul_eq_intCast_mul,] congr 1 - sorry + simp +zetaDelta [Int.dvd_def] at h + have ⟨d, h⟩ := h.2 + simp +zetaDelta [h] + rw [Int.mul_ediv_cancel_left _ (Int.pow_ne_zero h₁)] + rw [Ring.intCast_mul] + conv => rhs; lhs; rw [CommSemiring.mul_comm] + rw [Semiring.mul_assoc, Ring.intCast_pow] + congr 1 + rw [← Semiring.mul_assoc, ← CommSemiring.mul_pow, h₂, Semiring.one_pow, Semiring.one_mul] next ih => simp [ih, denote_insert, denote, Ring.zsmul_eq_intCast_mul, Semiring.add_assoc, Semiring.add_comm, add_left_comm] @@ -1329,9 +1343,17 @@ theorem Poly.denote_insertC {α c} [Ring α] [IsCharP α c] (ctx : Context α) ( simp [insertC, cond_eq_ite] <;> split next => rw [← IsCharP.intCast_emod (p := c)] - sorry + simp +zetaDelta [*, intCast_zero, zero_mul, zero_add] next => - fun_induction insertC.go <;> sorry + fun_induction insertC.go <;> simp_all +zetaDelta [denote, zsmul_eq_intCast_mul] + next h₁ _ h₂ => rw [IsCharP.intCast_emod] + next h₁ _ h₂ => + rw [← add_assoc, Mon.eq_of_grevlex h₁, ← right_distrib, ← intCast_add, ← IsCharP.intCast_emod (p := c), h₂, + intCast_zero, zero_mul, zero_add] + next h₁ _ _ => + rw [IsCharP.intCast_emod, intCast_add, right_distrib, add_assoc, Mon.eq_of_grevlex h₁] + next => rw [IsCharP.intCast_emod] + next => rw [add_left_comm] theorem Poly.denote_mulConstC {α c} [Ring α] [IsCharP α c] (ctx : Context α) (k : Int) (p : Poly) : (mulConstC k p c).denote ctx = k * p.denote ctx := by @@ -1348,9 +1370,11 @@ theorem Poly.denote_mulConstC {α c} [Ring α] [IsCharP α c] (ctx : Context α) fun_induction mulConstC.go <;> simp [denote, IsCharP.intCast_emod, *] next => rw [intCast_mul] next h _ => - sorry + simp +zetaDelta at h + rw [left_distrib, zsmul_eq_intCast_mul, ← mul_assoc, ← intCast_mul, ← IsCharP.intCast_emod (x := k * _) (p := c), + h, intCast_zero, zero_mul, zero_add] next h _ => - sorry + simp +zetaDelta [IsCharP.intCast_emod, intCast_mul, mul_assoc, left_distrib, zsmul_eq_intCast_mul] theorem Poly.denote_mulMonC {α c} [CommRing α] [IsCharP α c] (ctx : Context α) (k : Int) (m : Mon) (p : Poly) : (mulMonC k m p c).denote ctx = k * m.denote ctx * p.denote ctx := by @@ -1363,7 +1387,22 @@ theorem Poly.denote_mulMonC {α c} [CommRing α] [IsCharP α c] (ctx : Context next h => simp at h; simp [*, Mon.denote, mul_one, denote_mulConstC, IsCharP.intCast_emod] next => - fun_induction mulMonC.go <;> sorry + fun_induction mulMonC.go <;> simp [denote] + next h => + simp +zetaDelta at h + rw [mul_assoc, mul_left_comm, ← intCast_mul, ← IsCharP.intCast_emod (x := k * _) (p := c), h] + simp [intCast_zero, mul_zero] + next h => + simp +zetaDelta [IsCharP.intCast_emod, intCast_mul, intCast_zero, add_zero, mul_comm, mul_left_comm, mul_assoc, zsmul_eq_intCast_mul] + next h _ => + simp +zetaDelta at h; simp [*, left_distrib, zsmul_eq_intCast_mul] + rw [mul_left_comm] + conv => rhs; rw [← mul_assoc, ← mul_assoc, ← intCast_mul, ← IsCharP.intCast_emod (p := c)] + rw [Int.mul_comm] at h + simp [h, intCast_zero, zero_mul, zero_add] + next h _ => + simp +zetaDelta [*, IsCharP.intCast_emod, Mon.denote_mul, intCast_mul, left_distrib, + mul_left_comm, mul_assoc, zsmul_eq_intCast_mul] theorem Poly.denote_mulMonC_nc_go {α c} [Ring α] [IsCharP α c] (ctx : Context α) (k : Int) (m : Mon) (p acc : Poly) : (mulMonC_nc.go k m c p acc).denote ctx = k * m.denote ctx * p.denote ctx + acc.denote ctx := by @@ -1393,9 +1432,13 @@ theorem Poly.denote_combineC {α c} [Ring α] [IsCharP α c] (ctx : Context α) <;> simp [*, denote_addConstC, denote, intCast_add, add_comm, add_left_comm, add_assoc, IsCharP.intCast_emod, zsmul_eq_intCast_mul] next hg _ h _ => - sorry + simp +zetaDelta at h + rw [← add_assoc, Mon.eq_of_grevlex hg, ← right_distrib, ← intCast_add, + ← IsCharP.intCast_emod (p := c), + h, intCast_zero, zero_mul, zero_add] next hg _ h _ => - sorry + simp +zetaDelta only [IsCharP.intCast_emod, intCast_add] + rw [right_distrib, Mon.eq_of_grevlex hg, add_assoc] theorem Poly.denote_mulC_go {α c} [CommRing α] [IsCharP α c] (ctx : Context α) (p₁ p₂ acc : Poly) : (mulC.go p₂ c p₁ acc).denote ctx = acc.denote ctx + p₁.denote ctx * p₂.denote ctx := by diff --git a/src/Init/Meta/Defs.lean b/src/Init/Meta/Defs.lean index b2f27fd7b1..f51a86b2a9 100644 --- a/src/Init/Meta/Defs.lean +++ b/src/Init/Meta/Defs.lean @@ -1449,7 +1449,7 @@ where else Syntax.mkCApp (Name.mkStr2 "Array" (String.Internal.append "mkArray" (toString xs.size))) args termination_by xs.size - i - -- decreasing_by decreasing_trivial_pre_omega + decreasing_by decreasing_trivial_pre_omega instance [Quote α `term] : Quote (Array α) `term where quote := private quoteArray diff --git a/src/Init/SizeOfLemmas.lean b/src/Init/SizeOfLemmas.lean index df715c31bc..8df46ee705 100644 --- a/src/Init/SizeOfLemmas.lean +++ b/src/Init/SizeOfLemmas.lean @@ -13,28 +13,28 @@ public import Init.Data.Nat.Linear public section @[simp] protected theorem Fin.sizeOf (a : Fin n) : sizeOf a = a.val + 1 := by - cases a; sorry + cases a; simp +arith @[simp] protected theorem BitVec.sizeOf (a : BitVec w) : sizeOf a = sizeOf a.toFin + 1 := by - cases a; sorry + cases a; simp +arith @[simp] protected theorem UInt8.sizeOf (a : UInt8) : sizeOf a = a.toNat + 3 := by - cases a; sorry + cases a; simp +arith [UInt8.toNat, BitVec.toNat] @[simp] protected theorem UInt16.sizeOf (a : UInt16) : sizeOf a = a.toNat + 3 := by - cases a; sorry + cases a; simp +arith [UInt16.toNat, BitVec.toNat] @[simp] protected theorem UInt32.sizeOf (a : UInt32) : sizeOf a = a.toNat + 3 := by - cases a; sorry + cases a; simp +arith [UInt32.toNat, BitVec.toNat] @[simp] protected theorem UInt64.sizeOf (a : UInt64) : sizeOf a = a.toNat + 3 := by - cases a; sorry + cases a; simp +arith [UInt64.toNat, BitVec.toNat] @[simp] protected theorem USize.sizeOf (a : USize) : sizeOf a = a.toNat + 3 := by - cases a; sorry + cases a; simp +arith [USize.toNat, BitVec.toNat] @[simp] protected theorem Char.sizeOf (a : Char) : sizeOf a = a.toNat + 4 := by - cases a; sorry + cases a; simp +arith [Char.toNat] @[simp] protected theorem Subtype.sizeOf {α : Sort u_1} {p : α → Prop} (s : Subtype p) : sizeOf s = sizeOf s.val + 1 := by cases s; simp diff --git a/src/Init/WFComputable.lean b/src/Init/WFComputable.lean index f4726cb1b3..61749f6412 100644 --- a/src/Init/WFComputable.lean +++ b/src/Init/WFComputable.lean @@ -41,7 +41,6 @@ public instance wfRel {r : α → α → Prop} : WellFoundedRelation { val // Ac {a : α} (t : Acc r a) : motive a t := intro a (fun _ h => t.inv h) (fun _ hr => recC intro (t.inv hr)) termination_by Subtype.mk a t --- decreasing_by sorry -- TODO: restore after bootstrap @[csimp] public theorem rec_eq_recC : @Acc.rec = @Acc.recC := by funext α r motive intro a t @@ -89,7 +88,6 @@ namespace WellFounded (hwf : WellFounded r) (F : ∀ x, (∀ y, r y x → C y) → C x) (x : α) : C x := F x (fun y _ => fixC hwf F y) termination_by hwf.wrap x --- decreasing_by sorry -- TODO: restore after bootstrap unseal fixC diff --git a/src/Init/WFTactics.lean b/src/Init/WFTactics.lean index c0dd19b58e..403d802244 100644 --- a/src/Init/WFTactics.lean +++ b/src/Init/WFTactics.lean @@ -19,14 +19,16 @@ user, and this tactic should no longer be necessary. Calls to `simp_wf` can be r by plain calls to `simp`. -/ macro "simp_wf" : tactic => - `(tactic| sorry) + `(tactic| try simp +unfoldPartialApp +zetaDelta [invImage, InvImage, Prod.lex, sizeOfWFRel, measure, Nat.lt_wfRel, WellFoundedRelation.rel]) /-- This tactic is used internally by lean before presenting the proof obligations from a well-founded definition to the user via `decreasing_by`. It is not necessary to use this tactic manually. -/ macro "clean_wf" : tactic => - `(tactic| sorry) + `(tactic| simp +unfoldPartialApp +zetaDelta -failIfUnchanged + only [invImage, InvImage, Prod.lex, sizeOfWFRel, measure, Nat.lt_wfRel, + WellFoundedRelation.rel, sizeOf_nat, reduceCtorEq]) /-- Extensible helper tactic for `decreasing_tactic`. This handles the "base case" reasoning after applying lexicographic order lemmas. @@ -37,7 +39,7 @@ macro_rules | `(tactic| decreasing_trivial) => `(tactic| linarith) -/ syntax "decreasing_trivial" : tactic --- macro_rules | `(tactic| decreasing_trivial) => `(tactic| (simp +arith -failIfUnchanged) <;> done) +macro_rules | `(tactic| decreasing_trivial) => `(tactic| (simp +arith -failIfUnchanged) <;> done) macro_rules | `(tactic| decreasing_trivial) => `(tactic| omega) macro_rules | `(tactic| decreasing_trivial) => `(tactic| assumption) @@ -75,5 +77,4 @@ on the recursive definition, and it can also be globally extended by adding more definitions for `decreasing_tactic` (or `decreasing_trivial`, which this tactic calls). -/ macro "decreasing_tactic" : tactic => - -- TODO: restore after bootstrap: `(tactic| decreasing_with first | decreasing_trivial | subst_vars; decreasing_trivial) - `(tactic| all_goals sorry) + `(tactic| decreasing_with first | decreasing_trivial | subst_vars; decreasing_trivial) diff --git a/src/Lean/Compiler/LCNF/AlphaEqv.lean b/src/Lean/Compiler/LCNF/AlphaEqv.lean index d3858e76ab..ca7f153408 100644 --- a/src/Lean/Compiler/LCNF/AlphaEqv.lean +++ b/src/Lean/Compiler/LCNF/AlphaEqv.lean @@ -73,7 +73,7 @@ def eqvLetValue (e₁ e₂ : LetValue pu) : EqvM Bool := do let rec @[specialize] go (i : Nat) : EqvM Bool := do if h : i < params₁.size then let p₁ := params₁[i] - have : i < params₂.size := by sorry + have : i < params₂.size := by simp_all +arith let p₂ := params₂[i] unless (← eqvType p₁.type p₂.type) do return false withFVar p₁.fvarId p₂.fvarId do diff --git a/src/Lean/Compiler/LCNF/CompilerM.lean b/src/Lean/Compiler/LCNF/CompilerM.lean index f932523805..39a16c4a36 100644 --- a/src/Lean/Compiler/LCNF/CompilerM.lean +++ b/src/Lean/Compiler/LCNF/CompilerM.lean @@ -107,18 +107,9 @@ def findLetValue? (fvarId : FVarId) : CompilerM (Option (LetValue pu)) := do let some { value, .. } ← findLetDecl? fvarId | return none return some value -private unsafe def isConstructorAppImpl (fvarId : FVarId) : CompilerM Bool := do - let some v ← findLetValue? (pu := .pure) fvarId | return false - match v with - | .const declName _ _ => - let env ← getEnv - match env.find? declName with - | some (.ctorInfo ..) => return true - | _ => return false - | _ => return false - -@[implemented_by isConstructorAppImpl] -opaque isConstructorApp (fvarId : FVarId) : CompilerM Bool +def isConstructorApp (fvarId : FVarId) : CompilerM Bool := do + let some (.const declName _ _) ← findLetValue? fvarId | return false + return (← getEnv).find? declName matches some (.ctorInfo ..) def Arg.isConstructorApp (arg : Arg pu) : CompilerM Bool := do let .fvar fvarId := arg | return false diff --git a/src/Lean/Compiler/LCNF/InferType.lean b/src/Lean/Compiler/LCNF/InferType.lean index eaf77a1485..e7968ff36f 100644 --- a/src/Lean/Compiler/LCNF/InferType.lean +++ b/src/Lean/Compiler/LCNF/InferType.lean @@ -276,8 +276,6 @@ def Code.inferType (code : Code pu) : CompilerM Expr := do | .unreach type => return type | .cases c => return c.resultType | .impure => panic! "Infer type for impure unimplemented" -- TODO -termination_by sizeOf code -decreasing_by all_goals sorry -- TODO: restore after bootstrap def Code.inferParamType (params : Array (Param pu)) (code : Code pu) : CompilerM Expr := do let type ← code.inferType diff --git a/src/Lean/Compiler/LCNF/LambdaLifting.lean b/src/Lean/Compiler/LCNF/LambdaLifting.lean index 71d91ce71d..b7e83a0689 100644 --- a/src/Lean/Compiler/LCNF/LambdaLifting.lean +++ b/src/Lean/Compiler/LCNF/LambdaLifting.lean @@ -203,7 +203,6 @@ def lambdaLifting : Pass where run := fun decls => do decls.foldlM (init := #[]) fun decls decl => return decls ++ (← decl.lambdaLifting false true (suffix := `_lam)) - phaseInv := sorry /-- During eager lambda lifting, we inspect declarations that are not inlineable or instances (doing it diff --git a/src/Lean/Compiler/LCNF/PassManager.lean b/src/Lean/Compiler/LCNF/PassManager.lean index 0a4d25a8cb..94db22088e 100644 --- a/src/Lean/Compiler/LCNF/PassManager.lean +++ b/src/Lean/Compiler/LCNF/PassManager.lean @@ -61,7 +61,7 @@ structure Pass where Resulting phase. -/ phaseOut : Phase := phase - phaseInv : phaseOut ≥ phase := by sorry + phaseInv : phaseOut ≥ phase := by simp +arith +decide /-- Whether IR validation checks should always run after this pass, regardless of configuration options. @@ -77,7 +77,7 @@ structure Pass where run : Array (Decl phase.toPurity) → CompilerM (Array (Decl phaseOut.toPurity)) instance : Inhabited Pass where - default := { phase := .base, name := default, run := fun decls => return decls, phaseInv := sorry } + default := { phase := .base, name := default, run := fun decls => return decls } /-- Can be used to install, remove, replace etc. passes by tagging a declaration @@ -113,7 +113,6 @@ def mkPerDeclaration (name : Name) (phase : Phase) phase := phase name := name run := fun xs => xs.mapM run - phaseInv := sorry end Pass diff --git a/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean b/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean index dd90bb6e8a..dcee2451ba 100644 --- a/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean +++ b/src/Lean/Compiler/LCNF/Simp/ConstantFold.lean @@ -87,14 +87,9 @@ instance : Literal String where getLit := getStringLit mkLit := mkStringLit -private unsafe def getBoolLitImpl (fvarId : FVarId) : CompilerM (Option Bool) := do - let some v ← findLetValue? (pu := .pure) fvarId | return none - match v with - | .const ctor [] #[] => return ctor == ``Bool.true - | _ => return none - -@[implemented_by getBoolLitImpl] -opaque getBoolLit (fvarId : FVarId) : CompilerM (Option Bool) +def getBoolLit (fvarId : FVarId) : CompilerM (Option Bool) := do + let some (.const ctor [] #[]) ← findLetValue? fvarId | return none + return ctor == ``Bool.true def mkBoolLit (b : Bool) : FolderM (LetValue .pure) := let ctor := if b then ``Bool.true else ``Bool.false @@ -104,17 +99,11 @@ instance : Literal Bool where getLit := getBoolLit mkLit := mkBoolLit -private unsafe def getLitAuxImpl (fvarId : FVarId) (ofNat : Nat → α) (ofNatName : Name) : CompilerM (Option α) := do - let some v ← findLetValue? (pu := .pure) fvarId | return none - match v with - | .const declName _ #[.fvar fvarId] => - unless declName == ofNatName do return none - let some natLit ← getLit fvarId | return none - return ofNat natLit - | _ => return none - -@[implemented_by getLitAuxImpl] -private opaque getLitAux (fvarId : FVarId) (ofNat : Nat → α) (ofNatName : Name) : CompilerM (Option α) +private def getLitAux (fvarId : FVarId) (ofNat : Nat → α) (ofNatName : Name) : CompilerM (Option α) := do + let some (.const declName _ #[.fvar fvarId]) ← findLetValue? fvarId | return none + unless declName == ofNatName do return none + let some natLit ← getLit fvarId | return none + return ofNat natLit def mkNatWrapperInstance (ofNat : Nat → α) (ofNatName : Name) (toNat : α → Nat) : Literal α where getLit := (getLitAux · ofNat ofNatName) @@ -154,7 +143,7 @@ partial def getPseudoListLiteral (fvarId : FVarId) : CompilerM (Option (List FVa go fvarId [] where go (fvarId : FVarId) (fvarIds : List FVarId) : CompilerM (Option (List FVarId × Expr × Level)) := do - let some e ← findLetValue? (pu := .pure) fvarId | return none + let some e ← findLetValue? fvarId | return none match e with | .const ``List.nil [u] #[.type α] => return some (fvarIds.reverse, α, u) diff --git a/src/Lean/Compiler/LCNF/ToImpure.lean b/src/Lean/Compiler/LCNF/ToImpure.lean index 13974b4a52..5f1a3f827d 100644 --- a/src/Lean/Compiler/LCNF/ToImpure.lean +++ b/src/Lean/Compiler/LCNF/ToImpure.lean @@ -319,7 +319,6 @@ public def toImpure : Pass where phase := .mono phaseOut := .impure shouldAlwaysRunCheck := true - phaseInv := sorry builtin_initialize registerTraceClass `Compiler.toImpure (inherited := true) diff --git a/src/Lean/Data/RBMap.lean b/src/Lean/Data/RBMap.lean index bab3ff88d7..4fe7a63777 100644 --- a/src/Lean/Data/RBMap.lean +++ b/src/Lean/Data/RBMap.lean @@ -172,7 +172,6 @@ def appendTrees : RBNode α β → RBNode α β → RBNode α β | a, node red b kx vx c => node red (appendTrees a b) kx vx c | node red a kx vx b, c => node red a kx vx (appendTrees b c) termination_by x y => x.size + y.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap section Erase diff --git a/src/Lean/Elab/DeclNameGen.lean b/src/Lean/Elab/DeclNameGen.lean index a9cb734a20..8649dbaf06 100644 --- a/src/Lean/Elab/DeclNameGen.lean +++ b/src/Lean/Elab/DeclNameGen.lean @@ -130,8 +130,6 @@ where let s ← visit' e omitTopForall modify fun st => {st with seen := st.seen.insert e} return s - termination_by e - decreasing_by all_goals sorry -- TODO: restore after bootstrap visit' (e : Expr) (omitTopForall : Bool) : MkNameM String := do match e with | .const name .. => @@ -150,8 +148,6 @@ where | .sort (.succ _) => return "Type" | .sort _ => return "Sort" | _ => return "" - termination_by e - decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Generate a name, while naming the top-level foralls using "Of". diff --git a/src/Lean/Elab/PatternVar.lean b/src/Lean/Elab/PatternVar.lean index fe0fd277ec..2e2ccde173 100644 --- a/src/Lean/Elab/PatternVar.lean +++ b/src/Lean/Elab/PatternVar.lean @@ -156,7 +156,7 @@ where let ((name, _), ctx') := getNextParam ctx ctx := ctx' if let some idx := ctx'.namedArgs.findFinIdx? fun namedArg => namedArg.name == name then - ctx := { ctx with namedArgs := ctx.namedArgs.eraseIdx idx sorry + ctx := { ctx with namedArgs := ctx.namedArgs.eraseIdx idx usedNames := ctx.usedNames.insert name } if h : !ctx.namedArgs.isEmpty then throwInvalidNamedArgs ctx h diff --git a/src/Lean/Meta/Sym/Pattern.lean b/src/Lean/Meta/Sym/Pattern.lean index a86e60f608..741ed18caa 100644 --- a/src/Lean/Meta/Sym/Pattern.lean +++ b/src/Lean/Meta/Sym/Pattern.lean @@ -325,8 +325,6 @@ def processLevel (u : Level) (v : Level) : UnifyM Bool := do else return false | _, _ => return false -termination_by (u, v) -decreasing_by all_goals sorry -- TODO: restore after bootstrap def processLevels (us : List Level) (vs : List Level) : UnifyM Bool := do match us, vs with @@ -492,8 +490,6 @@ def isLevelDefEqS (u : Level) (v : Level) : MetaM Bool := do | .max u₁ u₂, .max v₁ v₂ => isLevelDefEqS u₁ v₁ <&&> isLevelDefEqS u₂ v₂ | .imax u₁ u₂, .imax v₁ v₂ => isLevelDefEqS u₁ v₁ <&&> isLevelDefEqS u₂ v₂ | _, _ => tryAssignLevelMVar u v <||> tryAssignLevelMVar v u -termination_by (u, v) -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Structural definitional equality for lists of universe levels. diff --git a/src/Lean/Meta/Tactic/Backtrack.lean b/src/Lean/Meta/Tactic/Backtrack.lean index 1691acf5cd..8bd55219f0 100644 --- a/src/Lean/Meta/Tactic/Backtrack.lean +++ b/src/Lean/Meta/Tactic/Backtrack.lean @@ -147,8 +147,6 @@ private def run (goals : List MVarId) (n : Nat) (curr acc : List MVarId) : MetaM | some l => (withTraceNode trace (fun _ => return m!"⏬ discharger generated new subgoals") do run goals n (l ++ gs) acc) - termination_by n - decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- A wrapper around `run`, which works on "independent" goals separately first, diff --git a/src/Lean/Meta/Tactic/Grind/AC/Eq.lean b/src/Lean/Meta/Tactic/Grind/AC/Eq.lean index 6ee2c3974d..c22faad095 100644 --- a/src/Lean/Meta/Tactic/Grind/AC/Eq.lean +++ b/src/Lean/Meta/Tactic/Grind/AC/Eq.lean @@ -31,8 +31,6 @@ where go ids₁ (id₂::ids₂) else go (id₁::ids₁) ids₂ - termination_by l₁ l₂ => (l₁.length, l₂.length) - decreasing_by all_goals sorry -- TODO: restore after bootstrap def asACExpr (e : Expr) : ACM AC.Expr := do if let some e' := (← getStruct).denote.find? { expr := e } then diff --git a/src/Lean/Meta/Tactic/Grind/AC/Seq.lean b/src/Lean/Meta/Tactic/Grind/AC/Seq.lean index 4b37005806..265806f568 100644 --- a/src/Lean/Meta/Tactic/Grind/AC/Seq.lean +++ b/src/Lean/Meta/Tactic/Grind/AC/Seq.lean @@ -231,8 +231,6 @@ def Seq.sharesVar (s₁ s₂ : Seq) : Bool := if x == y then true else if x < y then s₁.sharesVar (.cons y s₂) else sharesVar (.cons x s₁) s₂ -termination_by (s₁.length, s₂.length) -decreasing_by all_goals sorry -- TODO: restore after bootstrap example : Seq.sharesVar 0 0 = true := by simp [Seq.sharesVar, OfNat.ofNat] example : Seq.sharesVar (0::1::2) (2::3) = true := by simp [Seq.sharesVar, OfNat.ofNat] @@ -293,8 +291,6 @@ where if x == y then go s₁ s₂ r₁ (push c x) r₂ else if x < y then go s₁ (.cons y s₂) (push r₁ x) c r₂ else go (.cons x s₁) s₂ r₁ c (push r₂ y) - termination_by (s₁.length, s₂.length) - decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Returns `some (p, c, s)` if `s₁ == p ++ c` and `s₂ == c ++ s` diff --git a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Poly.lean b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Poly.lean index 7f40cca7b8..69726f7b7a 100644 --- a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Poly.lean +++ b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/Poly.lean @@ -18,8 +18,6 @@ def Mon.sharesVar : Mon → Mon → Bool | .eq => true | .lt => sharesVar m₁ (.mult pw₂ m₂) | .gt => sharesVar (.mult pw₁ m₁) m₂ -termination_by m₁ m₂ => (m₁.length, m₂.length) -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- `lcm m₁ m₂` returns the least common multiple of the given monomials. -/ def Mon.lcm : Mon → Mon → Mon @@ -30,8 +28,6 @@ def Mon.lcm : Mon → Mon → Mon | .eq => .mult { x := pw₁.x, k := max pw₁.k pw₂.k } (lcm m₁ m₂) | .lt => .mult pw₁ (lcm m₁ (.mult pw₂ m₂)) | .gt => .mult pw₂ (lcm (.mult pw₁ m₁) m₂) -termination_by m₁ m₂ => (m₁.length, m₂.length) -decreasing_by all_goals sorry -- TODO: restore after bootstrap -- Remark: we expose `Mon.divides` and `Mon.div` because we use then to write tests using `rfl` @@ -79,8 +75,6 @@ def Mon.coprime : Mon → Mon → Bool | .eq => false | .lt => coprime m₁ (.mult pw₂ m₂) | .gt => coprime (.mult pw₁ m₁) m₂ -termination_by m₁ m₂ => (m₁.length, m₂.length) -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Contains the S-polynomial resulting from superposing two polynomials `p₁` and `p₂`, diff --git a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/SafePoly.lean b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/SafePoly.lean index fe3af6930d..00f8f6cb0b 100644 --- a/src/Lean/Meta/Tactic/Grind/Arith/CommRing/SafePoly.lean +++ b/src/Lean/Meta/Tactic/Grind/Arith/CommRing/SafePoly.lean @@ -44,8 +44,6 @@ private def combine (p₁ p₂ : Poly) : RingM Poly := withIncRecDepth do return .add k m₁ (← combine p₁ p₂) | .gt => return .add k₁ m₁ (← combine p₁ (.add k₂ m₂ p₂)) | .lt => return .add k₂ m₂ (← combine (.add k₁ m₁ p₁) p₂) -termination_by (sizeOf p₁, sizeOf p₂) -decreasing_by all_goals sorry -- TODO: restore after bootstrap private def mul (p₁ : Poly) (p₂ : Poly) : RingM Poly := go p₁ (.num 0) diff --git a/src/Lean/Meta/Tactic/Grind/CheckResult.lean b/src/Lean/Meta/Tactic/Grind/CheckResult.lean index 0f702f6f39..755e749a71 100644 --- a/src/Lean/Meta/Tactic/Grind/CheckResult.lean +++ b/src/Lean/Meta/Tactic/Grind/CheckResult.lean @@ -57,9 +57,9 @@ example : lt .propagated .closed := rfl example {x} : lt x x = false := by cases x <;> rfl example {x y z} : lt x y → lt y z → lt x z := by cases x <;> cases y <;> cases z <;> decide example {x y z} : le x y → le y z → le x z := by cases x <;> cases y <;> cases z <;> decide --- example {x y} : le x y ↔ x = y ∨ lt x y := by cases x <;> cases y <;> simp +decide +example {x y} : le x y ↔ x = y ∨ lt x y := by cases x <;> cases y <;> simp +decide example {x} : le x x := by cases x <;> rfl --- example {x y} : le x y → le y x → x = y := by cases x <;> cases y <;> simp +decide +example {x y} : le x y → le y x → x = y := by cases x <;> cases y <;> simp +decide example {x y} : le x (join x y) := by cases x <;> cases y <;> rfl example {y x} : le y (join x y) := by cases x <;> cases y <;> rfl example {x} : join x x = x := by cases x <;> rfl diff --git a/src/Lean/Meta/Tactic/Grind/Types.lean b/src/Lean/Meta/Tactic/Grind/Types.lean index 44ca24215d..0a8b1e9e4b 100644 --- a/src/Lean/Meta/Tactic/Grind/Types.lean +++ b/src/Lean/Meta/Tactic/Grind/Types.lean @@ -1930,8 +1930,6 @@ where go lhsTerms (.next id₂ rhs rhsTerms) else go (.next id₁ lhs lhsTerms) rhsTerms - termination_by (sizeOf lhsTerms, sizeOf rhsTerms) - decreasing_by all_goals sorry -- TODO: restore after bootstrap private def propagateDiseqOf (id : Nat) (lhs rhs : Expr) : GoalM Unit := do visitLhs (← getRootENode lhs).sTerms @@ -2042,8 +2040,6 @@ where else let (s, p) ← go (.next id₁ rhs rhsTerms) lhsTerms return (.next id₂ lhs s, .diseqs id₂ (← getParents rhsRoot.self) p) - termination_by (sizeOf rhsTerms, sizeOf lhsTerms) - decreasing_by all_goals sorry -- TODO: restore after bootstrap def PendingSolverPropagations.propagate (p : PendingSolverPropagations) : GoalM Unit := do go p.data diff --git a/src/Lean/Server/Completion/CompletionItemCompression.lean b/src/Lean/Server/Completion/CompletionItemCompression.lean index 55777db4c6..75dfb3ca9a 100644 --- a/src/Lean/Server/Completion/CompletionItemCompression.lean +++ b/src/Lean/Server/Completion/CompletionItemCompression.lean @@ -104,7 +104,7 @@ def compressItemFast (acc : String) (item : ResolvableCompletionItem) : String : acc := acc ++ "]" return acc ++ "}" -partial def compressItemsFast +def compressItemsFast (acc : String) (items : Array ResolvableCompletionItem) (i : Nat) : String := if h : i < items.size then diff --git a/src/Std/Data/DHashMap/Internal/AssocList/Iterator.lean b/src/Std/Data/DHashMap/Internal/AssocList/Iterator.lean index 5a1d509567..d3c887c423 100644 --- a/src/Std/Data/DHashMap/Internal/AssocList/Iterator.lean +++ b/src/Std/Data/DHashMap/Internal/AssocList/Iterator.lean @@ -40,6 +40,8 @@ def AssocListIterator.finitenessRelation : wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by simp_wf + obtain ⟨step, h, h'⟩ := h + cases step <;> simp_all [IterStep.successor, IterM.IsPlausibleStep, Iterator.IsPlausibleStep] public instance : Finite (AssocListIterator α β) Id := Finite.of_finitenessRelation AssocListIterator.finitenessRelation diff --git a/src/Std/Data/DHashMap/Internal/Model.lean b/src/Std/Data/DHashMap/Internal/Model.lean index 02804d2214..7ebc9dc29b 100644 --- a/src/Std/Data/DHashMap/Internal/Model.lean +++ b/src/Std/Data/DHashMap/Internal/Model.lean @@ -14,8 +14,6 @@ public import Std.Data.DHashMap.Internal.AssocList.Lemmas @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This is an internal implementation file of the hash map. Users of the hash map should not rely on the contents of this file. diff --git a/src/Std/Data/DHashMap/Internal/RawLemmas.lean b/src/Std/Data/DHashMap/Internal/RawLemmas.lean index 4ebdeab0c6..2a9dfb1bca 100644 --- a/src/Std/Data/DHashMap/Internal/RawLemmas.lean +++ b/src/Std/Data/DHashMap/Internal/RawLemmas.lean @@ -16,8 +16,6 @@ meta import Std.Data.DHashMap.Basic public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This is an internal implementation file of the hash map. Users of the hash map should not rely on the contents of this file. diff --git a/src/Std/Data/DHashMap/Internal/WF.lean b/src/Std/Data/DHashMap/Internal/WF.lean index 371ae6e399..f80d5659f8 100644 --- a/src/Std/Data/DHashMap/Internal/WF.lean +++ b/src/Std/Data/DHashMap/Internal/WF.lean @@ -15,8 +15,6 @@ import all Std.Data.DHashMap.RawDef public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This is an internal implementation file of the hash map. Users of the hash map should not rely on the contents of this file. diff --git a/src/Std/Data/DTreeMap/Internal/Operations.lean b/src/Std/Data/DTreeMap/Internal/Operations.lean index fcb7d20a79..023913a345 100644 --- a/src/Std/Data/DTreeMap/Internal/Operations.lean +++ b/src/Std/Data/DTreeMap/Internal/Operations.lean @@ -233,7 +233,6 @@ def link (k : α) (v : β k) (l r : Impl α β) (hl : l.Balanced) (hr : r.Balanc ⟨.inner (szl + 1 + szr) k v (inner szl k' v' l' r') (inner szr k'' v'' l'' r''), ✓, ✓⟩ termination_by sizeOf l + sizeOf r -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Slower version of `link` which can be used in the absence of balance information but @@ -253,7 +252,6 @@ def link! (k : α) (v : β k) (l r : Impl α β) : Impl α β := else .inner (l.size + 1 + r.size) k v l r termination_by sizeOf l + sizeOf r -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Builds the tree `l ++ r` without any balancing information at the root. -/ def link2 (l r : Impl α β) (hl : l.Balanced) (hr : r.Balanced) : @@ -273,7 +271,6 @@ def link2 (l r : Impl α β) (hl : l.Balanced) (hr : r.Balanced) : else ⟨glue l r ✓ ✓ ✓, ✓, ✓⟩ termination_by sizeOf l + sizeOf r -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Slower version of `link2` which can be used in the absence of balance information but still assumes the preconditions of `link2`, otherwise might panic. @@ -292,7 +289,6 @@ def link2! (l r : Impl α β) : Impl α β := else glue! l r termination_by sizeOf l + sizeOf r -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-! ## Modification operations diff --git a/src/Std/Data/DTreeMap/Internal/Queries.lean b/src/Std/Data/DTreeMap/Internal/Queries.lean index 7041f21695..4247b48cc7 100644 --- a/src/Std/Data/DTreeMap/Internal/Queries.lean +++ b/src/Std/Data/DTreeMap/Internal/Queries.lean @@ -350,124 +350,92 @@ def minEntry? : Impl α β → Option ((a : α) × β a) | .leaf => none | .inner _ k v .leaf _ => some ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _ => l.minEntry? -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntry : (t : Impl α β) → (h : t.isEmpty = false) → (a : α) × β a | .inner _ k v .leaf _, _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _, h => l.minEntry (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntry! [Inhabited ((a : α) × β a)] : Impl α β → (a : α) × β a | .leaf => panic! "Map is empty" | .inner _ k v .leaf _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _ => l.minEntry! -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntryD : Impl α β → (a : α) × β a → (a : α) × β a | .leaf, fallback => fallback | .inner _ k v .leaf _, _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _, fallback => l.minEntryD fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry? : Impl α β → Option ((a : α) × β a) | .leaf => none | .inner _ k v _ .leaf => some ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..) => r.maxEntry? -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry : (t : Impl α β) → (h : t.isEmpty = false) → (a : α) × β a | .inner _ k v _ .leaf, _ => ⟨k, v⟩ | .inner _ _ _ _ l@(.inner ..), h => l.maxEntry (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry! [Inhabited ((a : α) × β a)] : Impl α β → (a : α) × β a | .leaf => panic! "Map is empty" | .inner _ k v _ .leaf => ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..) => r.maxEntry! -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntryD : Impl α β → (a : α) × β a → (a : α) × β a | .leaf, fallback => fallback | .inner _ k v _ .leaf, _ => ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..), fallback => r.maxEntryD fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minKey? : Impl α β → Option α | .leaf => none | .inner _ k _ .leaf _ => some k | .inner _ _ _ l@(inner ..) _ => l.minKey? -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minKey : (t : Impl α β) → (h : t.isEmpty = false) → α | .inner _ k _ .leaf _, _ => k | .inner _ _ _ l@(.inner ..) _, h => l.minKey (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- The smallest key of `t`. Returns the given fallback value if the map is empty. -/ def minKey! [Inhabited α] : Impl α β → α | .leaf => panic! "Map is empty" | .inner _ k _ .leaf _ => k | .inner _ _ _ l@(.inner ..) _ => l.minKey! -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minKeyD : Impl α β → α → α | .leaf, fallback => fallback | .inner _ k _ .leaf _, _ => k | .inner _ _ _ l@(.inner ..) _, fallback => l.minKeyD fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxKey? : Impl α β → Option α | .leaf => none | .inner _ k _ _ .leaf => some k | .inner _ _ _ _ r@(.inner ..) => r.maxKey? -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxKey : (t : Impl α β) → (h : t.isEmpty = false) → α | .inner _ k _ _ .leaf, _ => k | .inner _ _ _ _ l@(.inner ..), h => l.maxKey (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxKey! [Inhabited α] : Impl α β → α | .leaf => panic! "Map is empty" | .inner _ k _ _ .leaf => k | .inner _ _ _ _ r@(.inner ..) => r.maxKey! -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxKeyD : Impl α β → α → α | .leaf, fallback => fallback | .inner _ k _ _ .leaf, _ => k | .inner _ _ _ _ r@(.inner ..), fallback => r.maxKeyD fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap attribute [Std.Internal.tree_tac] Nat.compare_eq_gt Nat.compare_eq_lt Nat.compare_eq_eq @@ -478,8 +446,6 @@ def entryAtIdx : (t : Impl α β) → (hl : t.Balanced) → (n : Nat) → (h : n | .lt => l'.entryAtIdx hl.left n (by simpa only [Std.Internal.tree_tac] using h) | .eq => ⟨k, v⟩ | .gt => r'.entryAtIdx hl.right (n - l'.size - 1) (by simp_all only [Std.Internal.tree_tac]; omega) -termination_by t _ _ _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def entryAtIdx? : Impl α β → Nat → Option ((a : α) × β a) @@ -833,62 +799,46 @@ def minEntry? : Impl α β → Option (α × β) | .leaf => none | .inner _ k v .leaf _ => some ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _ => minEntry? l -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntry : (t : Impl α β) → (h : t.isEmpty = false) → α × β | .inner _ k v .leaf _, _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _, h => minEntry l (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntry! [Inhabited (α × β)] : Impl α β → α × β | .leaf => panic! "Map is empty" | .inner _ k v .leaf _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _ => minEntry! l -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def minEntryD : Impl α β → α × β → α × β | .leaf, fallback => fallback | .inner _ k v .leaf _, _ => ⟨k, v⟩ | .inner _ _ _ l@(.inner ..) _, fallback => minEntryD l fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry? : Impl α β → Option (α × β) | .leaf => none | .inner _ k v _ .leaf => some ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..) => maxEntry? r -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry : (t : Impl α β) → (h : t.isEmpty = false) → α × β | .inner _ k v _ .leaf, _ => ⟨k, v⟩ | .inner _ _ _ _ l@(.inner ..), h => maxEntry l (by simp_all [isEmpty]) -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntry! [Inhabited (α × β)] : Impl α β → α × β | .leaf => panic! "Map is empty" | .inner _ k v _ .leaf => ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..) => maxEntry! r -termination_by t => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def maxEntryD : Impl α β → α × β → α × β | .leaf, fallback => fallback | .inner _ k v _ .leaf, _ => ⟨k, v⟩ | .inner _ _ _ _ r@(.inner ..), fallback => maxEntryD r fallback -termination_by t _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ @[inline] @@ -899,8 +849,6 @@ def entryAtIdx : (t : Impl α β) → (hl : t.Balanced) → (n : Nat) → (h : n | .eq => ⟨k, v⟩ | .gt => entryAtIdx r' hl.right (n - l'.size - 1) (by simp_all only [Std.Internal.tree_tac]; omega) -termination_by t _ _ _ => t.size -decreasing_by all_goals sorry -- TODO: restore after bootstrap /-- Implementation detail of the tree map -/ def entryAtIdx? : Impl α β → Nat → Option (α × β) diff --git a/src/Std/Data/DTreeMap/Internal/Zipper.lean b/src/Std/Data/DTreeMap/Internal/Zipper.lean index 3ff9f7099f..ba2f155684 100644 --- a/src/Std/Data/DTreeMap/Internal/Zipper.lean +++ b/src/Std/Data/DTreeMap/Internal/Zipper.lean @@ -405,7 +405,7 @@ theorem Zipper.toList_iter {α β} {z : Zipper α β} : z.iter.toList = z.toList simp only rw [← Iter.toList_eq_toList_toIterM, toList_iter, toList_prependMap_eq_append] termination_by z.size --- decreasing_by simp [size_prependMap] +decreasing_by simp [size_prependMap] public theorem Zipper.toList_iterOfTree (t : Impl α β) : (Zipper.iterOfTree t).toList = t.toList := by @@ -516,8 +516,8 @@ theorem RxcIterator.toList_rxcIter {α β} [Ord α] true_and] rw [← eq_toIterM_iter, ← Iter.toList_eq_toList_toIterM, toList_rxcIter, Zipper.toList_prependMap_eq_append] termination_by z.size --- decreasing_by --- simp_all [Zipper.size_prependMap] +decreasing_by + simp_all [Zipper.size_prependMap] theorem List.takeWhile_eq_filter_of_pairwise {α : Type u} {p : α → Bool} {l : List α} (h : l.Pairwise (fun a b => p a = false → p b = false)) : l.takeWhile p = l.filter p := by @@ -645,8 +645,8 @@ theorem RxoIterator.toList_rxoIter {α β} [Ord α] true_and] rw [← eq_toIterM_iter, ← Iter.toList_eq_toList_toIterM, toList_rxoIter, Zipper.toList_prependMap_eq_append] termination_by z.size --- decreasing_by --- simp_all [Zipper.size_prependMap] +decreasing_by + simp_all [Zipper.size_prependMap] theorem RxoIterator.takeWhile_eq_filter {α : Type u} {β : α → Type v} [Ord α] [TransOrd α] {bound : α} {l : List ((a : α) × β a)} diff --git a/src/Std/Data/DTreeMap/Raw/Lemmas.lean b/src/Std/Data/DTreeMap/Raw/Lemmas.lean index ee2f9557e0..077c0ddf78 100644 --- a/src/Std/Data/DTreeMap/Raw/Lemmas.lean +++ b/src/Std/Data/DTreeMap/Raw/Lemmas.lean @@ -1685,7 +1685,7 @@ theorem contains_of_contains_insertMany_list' [TransCmp cmp] [BEq α] [LawfulBEq (h' : contains (insertMany t l) k = true) (w : l.findSomeRev? (fun ⟨a, b⟩ => if cmp a k = .eq then some b else none) = none) : contains t k = true := - Impl.Const.contains_of_contains_insertMany_list' (l := l) h + Impl.Const.contains_of_contains_insertMany_list' h (by simpa [Impl.Const.insertMany_eq_insertMany!] using h') (by simpa [compare_eq_iff_beq, BEq.comm] using w) diff --git a/src/Std/Data/ExtHashMap/Lemmas.lean b/src/Std/Data/ExtHashMap/Lemmas.lean index 43d96d0695..43c885f264 100644 --- a/src/Std/Data/ExtHashMap/Lemmas.lean +++ b/src/Std/Data/ExtHashMap/Lemmas.lean @@ -808,7 +808,7 @@ theorem getElem_insertMany_list_of_contains_eq_false [EquivBEq α] [LawfulHashab theorem getElem_insertMany_list_of_mem [EquivBEq α] [LawfulHashable α] {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} - (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h : k' ∈ insertMany m l} : + (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h} : (insertMany m l)[k'] = v := ExtDHashMap.Const.get_insertMany_list_of_mem k_beq distinct mem (h := h) @@ -982,7 +982,7 @@ theorem getElem?_insertManyIfNewUnit_list [EquivBEq α] [LawfulHashable α] ExtDHashMap.Const.get?_insertManyIfNewUnit_list theorem getElem_insertManyIfNewUnit_list [EquivBEq α] [LawfulHashable α] - {l : List α} {k : α} {h : k ∈ insertManyIfNewUnit m l} : + {l : List α} {k : α} {h} : (insertManyIfNewUnit m l)[k] = () := rfl @@ -1149,7 +1149,7 @@ theorem getElem_ofList_of_mem [EquivBEq α] [LawfulHashable α] {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) - {h : k' ∈ ofList l} : + {h} : (ofList l)[k'] = v := ExtDHashMap.Const.get_ofList_of_mem k_beq distinct mem (h := h) @@ -1283,7 +1283,7 @@ theorem getElem?_unitOfList [EquivBEq α] [LawfulHashable α] @[simp] theorem getElem_unitOfList [EquivBEq α] [LawfulHashable α] - {l : List α} {k : α} {h : k ∈ unitOfList l} : + {l : List α} {k : α} {h} : (unitOfList l)[k] = () := rfl diff --git a/src/Std/Data/ExtTreeMap/Lemmas.lean b/src/Std/Data/ExtTreeMap/Lemmas.lean index 1064f4584b..9fc002250d 100644 --- a/src/Std/Data/ExtTreeMap/Lemmas.lean +++ b/src/Std/Data/ExtTreeMap/Lemmas.lean @@ -244,7 +244,7 @@ theorem isSome_getElem?_iff_mem [TransCmp cmp] {a : α} : mem_iff_isSome_getElem?.symm theorem getElem?_eq_some_iff [TransCmp cmp] {k : α} {v : β} : - t[k]? = some v ↔ ∃ (h : k ∈ t), t[k] = v := + t[k]? = some v ↔ ∃ h, t[k] = v := ExtDTreeMap.Const.get?_eq_some_iff theorem getElem?_eq_none_of_contains_eq_false [TransCmp cmp] {a : α} : diff --git a/src/Std/Data/HashMap/Lemmas.lean b/src/Std/Data/HashMap/Lemmas.lean index a8b37e38c4..94b1ec4d40 100644 --- a/src/Std/Data/HashMap/Lemmas.lean +++ b/src/Std/Data/HashMap/Lemmas.lean @@ -1239,7 +1239,7 @@ theorem getElem_insertMany_list_of_contains_eq_false [EquivBEq α] [LawfulHashab theorem getElem_insertMany_list_of_mem [EquivBEq α] [LawfulHashable α] {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} - (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h : k' ∈ insertMany m l} : + (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h} : (insertMany m l)[k'] = v := DHashMap.Const.get_insertMany_list_of_mem k_beq distinct mem @@ -2249,7 +2249,7 @@ theorem getElem?_insertManyIfNewUnit_list [EquivBEq α] [LawfulHashable α] DHashMap.Const.get?_insertManyIfNewUnit_list theorem getElem_insertManyIfNewUnit_list - {l : List α} {k : α} {h : k ∈ insertManyIfNewUnit m l} : + {l : List α} {k : α} {h} : (insertManyIfNewUnit m l)[k] = () := DHashMap.Const.get_insertManyIfNewUnit_list @@ -2416,7 +2416,7 @@ theorem getElem_ofList_of_mem [EquivBEq α] [LawfulHashable α] {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) - {h : k' ∈ ofList l} : + {h} : (ofList l)[k'] = v := DHashMap.Const.get_ofList_of_mem k_beq distinct mem @@ -2560,7 +2560,7 @@ theorem getElem?_unitOfList [EquivBEq α] [LawfulHashable α] @[simp] theorem getElem_unitOfList - {l : List α} {k : α} {h : k ∈ unitOfList l} : + {l : List α} {k : α} {h} : (unitOfList l)[k] = () := DHashMap.Const.get_unitOfList diff --git a/src/Std/Data/HashMap/RawLemmas.lean b/src/Std/Data/HashMap/RawLemmas.lean index 330ee1e10a..7d390701af 100644 --- a/src/Std/Data/HashMap/RawLemmas.lean +++ b/src/Std/Data/HashMap/RawLemmas.lean @@ -2221,7 +2221,7 @@ theorem getElem_insertMany_list_of_contains_eq_false [EquivBEq α] [LawfulHashab theorem getElem_insertMany_list_of_mem [EquivBEq α] [LawfulHashable α] (h : m.WF) {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} - (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h' : k' ∈ insertMany m l} : + (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) {h'} : (insertMany m l)[k'] = v := DHashMap.Raw.Const.get_insertMany_list_of_mem h.out k_beq distinct mem (h' := h') @@ -2408,7 +2408,7 @@ theorem getElem?_insertManyIfNewUnit_list [EquivBEq α] [LawfulHashable α] (h : @[simp] theorem getElem_insertManyIfNewUnit_list - {l : List α} {k : α} {h : k ∈ insertManyIfNewUnit m l} : + {l : List α} {k : α} {h} : (insertManyIfNewUnit m l)[k] = () := DHashMap.Raw.Const.get_insertManyIfNewUnit_list (h:=h) @@ -2478,7 +2478,7 @@ theorem getElem_ofList_of_mem [EquivBEq α] [LawfulHashable α] {l : List (α × β)} {k k' : α} (k_beq : k == k') {v : β} (distinct : l.Pairwise (fun a b => (a.1 == b.1) = false)) (mem : ⟨k, v⟩ ∈ l) - {h : k' ∈ ofList l} : + {h} : (ofList l)[k'] = v := DHashMap.Raw.Const.get_ofList_of_mem k_beq distinct mem (h:=h) @@ -2686,7 +2686,7 @@ theorem getElem?_unitOfList [EquivBEq α] [LawfulHashable α] @[simp] theorem getElem_unitOfList - {l : List α} {k : α} {h : k ∈ unitOfList l} : + {l : List α} {k : α} {h} : (unitOfList l)[k] = () := DHashMap.Raw.Const.get_unitOfList (h:=h) diff --git a/src/Std/Data/Iterators/Producers/Monadic/Array.lean b/src/Std/Data/Iterators/Producers/Monadic/Array.lean index 9f26d4f483..bbeb9043d1 100644 --- a/src/Std/Data/Iterators/Producers/Monadic/Array.lean +++ b/src/Std/Data/Iterators/Producers/Monadic/Array.lean @@ -96,7 +96,16 @@ private def ArrayIterator.instFinitenessRelation [Pure m] : (fun it => it.internalState.array.size - it.internalState.pos) wf := InvImage.wf _ WellFoundedRelation.wf subrelation {it it'} h := by - sorry + simp_wf + obtain ⟨step, h, h'⟩ := h + cases step + · cases h + obtain ⟨h, h', h'', rfl⟩ := h' + rw [h] at h'' + rw [h, h'] + omega + · cases h' + · cases h instance ArrayIterator.instFinite [Pure m] : Finite (ArrayIterator α) m := by exact Finite.of_finitenessRelation ArrayIterator.instFinitenessRelation diff --git a/src/Std/Data/TreeMap/Lemmas.lean b/src/Std/Data/TreeMap/Lemmas.lean index 26d5f2f0df..83be7f6723 100644 --- a/src/Std/Data/TreeMap/Lemmas.lean +++ b/src/Std/Data/TreeMap/Lemmas.lean @@ -255,7 +255,7 @@ theorem isSome_getElem?_iff_mem [TransCmp cmp] {a : α} : mem_iff_isSome_getElem?.symm theorem getElem?_eq_some_iff [TransCmp cmp] {k : α} {v : β} : - t[k]? = some v ↔ ∃ (h : k ∈ t), t[k] = v := + t[k]? = some v ↔ ∃ h, t[k] = v := DTreeMap.Const.get?_eq_some_iff theorem mem_of_getKey?_eq_some [TransCmp cmp] {k k' : α} diff --git a/src/Std/Data/TreeMap/Raw/Lemmas.lean b/src/Std/Data/TreeMap/Raw/Lemmas.lean index 1c1e83f5e8..c9626cdcc1 100644 --- a/src/Std/Data/TreeMap/Raw/Lemmas.lean +++ b/src/Std/Data/TreeMap/Raw/Lemmas.lean @@ -255,7 +255,7 @@ theorem isSome_getElem?_iff_mem [TransCmp cmp] (h : t.WF) {a : α} : (mem_iff_isSome_getElem? h).symm theorem getElem?_eq_some_iff [TransCmp cmp] (h : t.WF) {k : α} {v : β} : - t[k]? = some v ↔ ∃ (h : k ∈ t), t[k] = v := + t[k]? = some v ↔ ∃ h, t[k] = v := DTreeMap.Raw.Const.get?_eq_some_iff h theorem getElem?_eq_none_of_contains_eq_false [TransCmp cmp] (h : t.WF) {a : α} : diff --git a/src/Std/Do/PredTrans.lean b/src/Std/Do/PredTrans.lean index 6fdacad6ad..98556bb6f0 100644 --- a/src/Std/Do/PredTrans.lean +++ b/src/Std/Do/PredTrans.lean @@ -164,9 +164,9 @@ theorem bind_mono {x y : PredTrans ps α} {f : α → PredTrans ps β} instance instLawfulMonad : LawfulMonad (PredTrans ps) := LawfulMonad.mk' (PredTrans ps) - (id_map := by sorry) - (pure_bind := by sorry) - (bind_assoc := by sorry) + (id_map := by simp +unfoldPartialApp [Functor.map, bind, pure, apply]) + (pure_bind := by simp +unfoldPartialApp [Bind.bind, bind, Pure.pure, pure, apply]) + (bind_assoc := by simp +unfoldPartialApp [Bind.bind, bind, apply]) /-- Adds the ability to make assertions about a state of type `σ` to a predicate transformer with diff --git a/src/Std/Do/SPred/Laws.lean b/src/Std/Do/SPred/Laws.lean index c3842ebddf..04aae44bd0 100644 --- a/src/Std/Do/SPred/Laws.lean +++ b/src/Std/Do/SPred/Laws.lean @@ -59,7 +59,7 @@ theorem bientails.refl (P : SPred σs) : P ⊣⊢ₛ P := by theorem bientails.trans {P Q R : SPred σs} : (P ⊣⊢ₛ Q) → (Q ⊣⊢ₛ R) → (P ⊣⊢ₛ R) := by induction σs - case nil => sorry + case nil => simp +contextual only [bientails, implies_true] case cons σ σs ih => intro hpq hqr s; exact ih (hpq s) (hqr s) instance : Trans (@bientails σs) bientails bientails where diff --git a/src/Std/Do/Triple/SpecLemmas.lean b/src/Std/Do/Triple/SpecLemmas.lean index a38cf0fdb4..5bd5f1cf18 100644 --- a/src/Std/Do/Triple/SpecLemmas.lean +++ b/src/Std/Do/Triple/SpecLemmas.lean @@ -20,8 +20,6 @@ set_option linter.missingDocs true @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! # Hoare triple specifications for select functions diff --git a/src/Std/Sat/AIG/Basic.lean b/src/Std/Sat/AIG/Basic.lean index aa62544772..75a79e20b3 100644 --- a/src/Std/Sat/AIG/Basic.lean +++ b/src/Std/Sat/AIG/Basic.lean @@ -12,8 +12,6 @@ public import Init.Data.Hashable @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat @@ -531,10 +529,19 @@ def mkGate (aig : AIG α) (input : BinaryInput aig) : Entrypoint α := let decls := aig.decls.push <| .gate (.mk input.lhs.gate input.lhs.invert) (.mk input.rhs.gate input.rhs.invert) let cache := aig.cache.noUpdate - have hdag : IsDAG α decls := sorry -- TODO: restore after bootstrap - have hzero : 0 < decls.size := sorry -- TODO: restore after bootstrap - have hconst : decls[0] = Decl.false := sorry -- TODO: restore after bootstrap - ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, false, sorry⟩⟩ + have hdag := by + intro i lhs' rhs' h1 h2 + simp only [Array.getElem_push] at h2 + split at h2 + · apply aig.hdag <;> assumption + · injection h2 with hl hr + have := input.lhs.hgate + have := input.rhs.hgate + simp [← hl, ← hr] + omega + have hzero := by simp [decls] + have hconst := by simp [decls, Array.getElem_push, aig.hzero, aig.hconst] + ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, false, by simp [g, decls]⟩⟩ /-- Add a new input node to the AIG in `aig`. Note that this version is only meant for proving, @@ -544,10 +551,15 @@ def mkAtom (aig : AIG α) (n : α) : Entrypoint α := let g := aig.decls.size let decls := aig.decls.push (.atom n) let cache := aig.cache.noUpdate - have hdag : IsDAG α decls := sorry -- TODO: restore after bootstrap - have hzero : 0 < decls.size := sorry -- TODO: restore after bootstrap - have hconst : decls[0] = Decl.false := sorry -- TODO: restore after bootstrap - ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, false, sorry⟩⟩ + have hdag := by + intro i lhs rhs h1 h2 + simp only [Array.getElem_push] at h2 + split at h2 + · apply aig.hdag <;> assumption + · contradiction + have hzero := by simp [decls] + have hconst := by simp [decls, Array.getElem_push, aig.hzero, aig.hconst] + ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, false, by simp [g, decls]⟩⟩ /-- Add a new constant node to `aig`. Note that this version is only meant for proving, @@ -557,10 +569,15 @@ def mkConst (aig : AIG α) (val : Bool) : Entrypoint α := let g := aig.decls.size let decls := aig.decls.push .false let cache := aig.cache.noUpdate - have hdag : IsDAG α decls := sorry -- TODO: restore after bootstrap - have hzero : 0 < decls.size := sorry -- TODO: restore after bootstrap - have hconst : decls[0] = Decl.false := sorry -- TODO: restore after bootstrap - ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, val, sorry⟩⟩ + have hdag := by + intro i lhs rhs h1 h2 + simp only [Array.getElem_push] at h2 + split at h2 + · apply aig.hdag <;> assumption + · contradiction + have hzero := by simp [decls] + have hconst := by simp [decls, Array.getElem_push, aig.hzero, aig.hconst] + ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨g, val, by simp [g, decls]⟩⟩ /-- Determine whether `ref` is a `Decl.const` with value `b`. diff --git a/src/Std/Sat/AIG/CNF.lean b/src/Std/Sat/AIG/CNF.lean index 2d087b0730..b2187b84ca 100644 --- a/src/Std/Sat/AIG/CNF.lean +++ b/src/Std/Sat/AIG/CNF.lean @@ -11,8 +11,6 @@ public import Std.Sat.AIG.Lemmas public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains an implementation of a verified Tseitin transformation on AIGs. The key results diff --git a/src/Std/Sat/AIG/Cached.lean b/src/Std/Sat/AIG/Cached.lean index fc3f61e7a0..37912a7b85 100644 --- a/src/Std/Sat/AIG/Cached.lean +++ b/src/Std/Sat/AIG/Cached.lean @@ -37,10 +37,15 @@ def mkAtomCached (aig : AIG α) (n : α) : Entrypoint α := let g := decls.size let cache := cache.insert decls decl let decls := decls.push decl - have hdag' : IsDAG α decls := sorry -- TODO: restore after bootstrap - have hzero' : 0 < decls.size := sorry -- TODO: restore after bootstrap - have hconst' : decls[0] = Decl.false := sorry -- TODO: restore after bootstrap - ⟨⟨decls, cache, hdag', hzero', hconst'⟩, ⟨g, false, sorry⟩⟩ + have hdag := by + intro i lhs rhs h1 h2 + simp only [Array.getElem_push] at h2 + split at h2 + · apply hdag <;> assumption + · contradiction + have hzero' := by simp [decls] + have hconst := by simp [decls, Array.getElem_push, hzero, hconst] + ⟨⟨decls, cache, hdag, hzero', hconst⟩, ⟨g, false, by simp [g, decls]⟩⟩ /-- A version of `AIG.mkConst` that uses the subterm cache in `AIG`. This version is meant for @@ -90,15 +95,15 @@ where let ref := mkConstCached ⟨decls, cache, hdag, hzero, hconst⟩ false ⟨⟨decls, cache, hdag, hzero, hconst⟩, ref⟩ -- Left Neutrality - | .some true, _ => ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨rhs, rinv, sorry⟩⟩ + | .some true, _ => ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨rhs, rinv, by assumption⟩⟩ -- Right Neutrality - | _, .some true => ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨lhs, linv, sorry⟩⟩ + | _, .some true => ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨lhs, linv, by assumption⟩⟩ -- No constant inputs | _, _ => if lhs == rhs then -- Idempotency if linv == rinv then - ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨lhs, linv, sorry⟩⟩ + ⟨⟨decls, cache, hdag, hzero, hconst⟩, ⟨lhs, linv, by assumption⟩⟩ -- Contradiction else let ref := mkConstCached ⟨decls, cache, hdag, hzero, hconst⟩ false @@ -108,10 +113,18 @@ where let g := decls.size let cache := cache.insert decls decl let decls := decls.push decl - have hdag' : IsDAG α decls := sorry -- TODO: restore after bootstrap - have hzero' : 0 < decls.size := sorry -- TODO: restore after bootstrap - have hconst' : decls[0] = Decl.false := sorry -- TODO: restore after bootstrap - ⟨⟨decls, cache, hdag', hzero', hconst'⟩, ⟨g, false, sorry⟩⟩ + have hdag := by + intro i lhs rhs h1 h2 + simp only [Array.getElem_push] at h2 + simp_all + split at h2 + · apply hdag <;> assumption + · injection h2 with hl hr + simp [← hl, ← hr] + omega + have hzero' := by simp [decls] + have hconst := by simp [decls, Array.getElem_push, hzero, hconst] + ⟨⟨decls, cache, hdag, hzero', hconst⟩, ⟨g, false, by simp [g, decls]⟩⟩ end AIG diff --git a/src/Std/Sat/AIG/CachedLemmas.lean b/src/Std/Sat/AIG/CachedLemmas.lean index 9f55cbe18c..77133cbc5a 100644 --- a/src/Std/Sat/AIG/CachedLemmas.lean +++ b/src/Std/Sat/AIG/CachedLemmas.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.Cached @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the theory of the cached AIG node creation functions. It is mainly concerned with proving lemmas about the denotational semantics of the gate functions diff --git a/src/Std/Sat/AIG/If.lean b/src/Std/Sat/AIG/If.lean index ec1d764dad..d06ee4faa6 100644 --- a/src/Std/Sat/AIG/If.lean +++ b/src/Std/Sat/AIG/If.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.LawfulVecOperator @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! Besides introducing a way to construct an if statement in an `AIG`, this module also demonstrates a style of writing Lean code that minimizes the risk of linearity issues on the `AIG`. diff --git a/src/Std/Sat/AIG/LawfulOperator.lean b/src/Std/Sat/AIG/LawfulOperator.lean index afcbeae42b..719d9a94fd 100644 --- a/src/Std/Sat/AIG/LawfulOperator.lean +++ b/src/Std/Sat/AIG/LawfulOperator.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.Basic @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! The lawful operator framework provides free theorems around the typeclass `LawfulOperator`. Its definition is based on section 3.3 of the AIGNET paper. diff --git a/src/Std/Sat/AIG/LawfulVecOperator.lean b/src/Std/Sat/AIG/LawfulVecOperator.lean index 78a5fea5c4..a578c0fd81 100644 --- a/src/Std/Sat/AIG/LawfulVecOperator.lean +++ b/src/Std/Sat/AIG/LawfulVecOperator.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.RefVec @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat diff --git a/src/Std/Sat/AIG/Lemmas.lean b/src/Std/Sat/AIG/Lemmas.lean index a0b6b6a6ce..0051798c28 100644 --- a/src/Std/Sat/AIG/Lemmas.lean +++ b/src/Std/Sat/AIG/Lemmas.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.LawfulOperator @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module provides a basic theory around the naive AIG node creation functions. It is mostly fundamental work for the cached versions later on. diff --git a/src/Std/Sat/AIG/RefVec.lean b/src/Std/Sat/AIG/RefVec.lean index de2dbaa9ff..76e1b04571 100644 --- a/src/Std/Sat/AIG/RefVec.lean +++ b/src/Std/Sat/AIG/RefVec.lean @@ -11,8 +11,6 @@ public import Init.Data.Vector.Lemmas @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat @@ -60,7 +58,7 @@ def cast {aig1 aig2 : AIG α} (s : RefVec aig1 len) (h : aig1.decls.size ≤ aig def get (s : RefVec aig len) (idx : Nat) (hidx : idx < len) : Ref aig := let ⟨refs, hrefs⟩ := s let ref := refs[idx] - ⟨ref.gate, ref.invert, hrefs hidx⟩ + ⟨ref.gate, ref.invert, hrefs ..⟩ @[inline] def push (s : RefVec aig len) (ref : AIG.Ref aig) : RefVec aig (len + 1) := diff --git a/src/Std/Sat/AIG/RefVecOperator/Map.lean b/src/Std/Sat/AIG/RefVecOperator/Map.lean index a0a4eaf856..c8c219e82f 100644 --- a/src/Std/Sat/AIG/RefVecOperator/Map.lean +++ b/src/Std/Sat/AIG/RefVecOperator/Map.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.LawfulVecOperator @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat diff --git a/src/Std/Sat/AIG/RefVecOperator/Zip.lean b/src/Std/Sat/AIG/RefVecOperator/Zip.lean index 997d23f0e2..87d8e1916f 100644 --- a/src/Std/Sat/AIG/RefVecOperator/Zip.lean +++ b/src/Std/Sat/AIG/RefVecOperator/Zip.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.LawfulVecOperator @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat diff --git a/src/Std/Sat/AIG/Relabel.lean b/src/Std/Sat/AIG/Relabel.lean index e30db0b712..f82b4eb2db 100644 --- a/src/Std/Sat/AIG/Relabel.lean +++ b/src/Std/Sat/AIG/Relabel.lean @@ -10,8 +10,6 @@ public import Std.Sat.AIG.Lemmas @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - namespace Std namespace Sat diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Expr.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Expr.lean index a2d4427f5f..8cac25a5fa 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Expr.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Expr.lean @@ -53,21 +53,50 @@ def Cache.empty : Cache aig := def Cache.insert (cache : Cache aig) (expr : BVExpr w) (refs : AIG.RefVec aig w) : Cache aig := let ⟨map, hbound⟩ := cache - let newMap := map.insert ⟨w, expr⟩ refs.refs - ⟨newMap, by exact sorry⟩ -- TODO: restore after bootstrap + have := by + intro i k hk h2 + rw [Std.DHashMap.get_insert] + split + next heq => + rcases k with ⟨w, expr⟩ + simp only [beq_iff_eq, Key.mk.injEq] at heq + rcases heq with ⟨heq1, heq2⟩ + symm at heq1 + subst heq1 + have := refs.hrefs h2 + rw [getElem_congr_coll] + · exact this + · simp + · apply hbound + ⟨map.insert ⟨w, expr⟩ refs.refs, this⟩ @[inline] def Cache.get? (cache : Cache aig) (expr : BVExpr w) : Option (AIG.RefVec aig w) := match h : cache.map.get? ⟨w, expr⟩ with | some refs => - some ⟨refs, by exact sorry⟩ -- TODO: restore after bootstrap + have : ⟨w, expr⟩ ∈ cache.map := by + rw [Std.DHashMap.mem_iff_contains, Std.DHashMap.contains_eq_isSome_get?] + simp [h] + have : cache.map.get ⟨w, expr⟩ this = refs := by + rw [Std.DHashMap.get?_eq_some_get (h := this)] at h + simpa using h + have := by + intro i hi + rw [← this] + apply cache.hbound + some ⟨refs, this⟩ | none => none @[inline] def Cache.cast (cache : Cache aig1) (h : aig1.decls.size ≤ aig2.decls.size) : Cache aig2 := let ⟨map, hbound⟩ := cache - ⟨map, by exact sorry⟩ -- TODO: restore after bootstrap + have := by + intro i k hk h2 + apply Nat.lt_of_lt_of_le + · apply hbound + · exact h + ⟨map, this⟩ structure WithCache (α : Type u) (aig : AIG BVBit) where val : α diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Add.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Add.lean index ec1a0de8b5..7b41fa9c58 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Add.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Add.lean @@ -158,7 +158,9 @@ def mkFullAdder (aig : AIG α) (input : FullAdderInput aig) : FullAdderOutput ai have haig2 := AIG.LawfulOperator.le_size (f := mkFullAdderCarry) .. let outRef := outRef.cast haig2 have hle := by - sorry + simp +zetaDelta only + apply AIG.LawfulOperator.le_size_of_le_aig_size (f := mkFullAdderCarry) + apply AIG.LawfulOperator.le_size (f := mkFullAdderOut) ⟨aig, outRef, carryRef, hle⟩ def blastAdd (aig : AIG α) (input : AIG.BinaryRefVec aig w) : AIG.RefVecEntry α w := diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Reverse.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Reverse.lean index 00ed26e704..58949dd7db 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Reverse.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Operations/Reverse.lean @@ -11,8 +11,6 @@ public import Std.Sat.AIG.LawfulVecOperator @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the implementation of a bitblaster for `BitVec.reverse`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Substructure.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Substructure.lean index 7aa6dc36cf..1a55e06802 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Substructure.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Impl/Substructure.lean @@ -10,8 +10,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Pred @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the logic to turn a `BVLogicalExpr` into an `AIG` with maximum subterm sharing, through the use of a cache that re-uses sub-circuits if possible. Additionally a term level cache diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Const.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Const.lean index ec77bf16b0..4636917ba2 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Const.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Const.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Const @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the `BitVec` constant bitblaster from `Impl.Const`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Expr.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Expr.lean index 2f73dbea2c..24431bd162 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Expr.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Expr.lean @@ -21,8 +21,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Expr @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the `BitVec` expressions (`BVExpr`) bitblaster from `Impl.Expr`. @@ -39,7 +37,7 @@ namespace Cache abbrev Inv (assign : Assignment) (aig : AIG BVBit) (cache : Cache aig) : Prop := ∀ k (h1 : k ∈ cache.map), ∀ (i : Nat) (h2 : i < k.w), - ⟦aig, ⟨(cache.map.get k h1)[i].gate, (cache.map.get k h1)[i].invert, sorry⟩, assign.toAIGAssignment⟧ -- TODO: restore cache.hbound .. after bootstrap + ⟦aig, ⟨(cache.map.get k h1)[i].gate, (cache.map.get k h1)[i].invert, cache.hbound ..⟩, assign.toAIGAssignment⟧ = (k.expr.eval assign).getLsbD i diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Add.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Add.lean index 9715ef3271..6d1c306c6f 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Add.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Add.lean @@ -12,8 +12,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Add @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the `BitVec.add` bitblaster from `Impl.Operations.Add`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Reverse.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Reverse.lean index 4913715ccf..d41c629a87 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Reverse.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Reverse.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Revers @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblaster for `BitVec.reverse` from `Impl.Operations.Reverse`. diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftLeft.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftLeft.lean index c80e7d7223..166926819f 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftLeft.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftLeft.lean @@ -12,8 +12,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.ShiftL @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblasters for `BitVec.shiftLeft` from `Impl.Operations.ShiftLeft`. diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftRight.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftRight.lean index a6fb844993..cc09e862d5 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftRight.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ShiftRight.lean @@ -12,8 +12,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.ShiftR @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblasters for `BitVec.shiftRight` from `Impl.Operations.ShiftRight`. diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Udiv.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Udiv.lean index c070506d43..113c5e80df 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Udiv.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Udiv.lean @@ -17,8 +17,6 @@ public import Std.Tactic.BVDecide.Normalize.BitVec @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the `BitVec.udiv` bitblaster from `Impl.Operations.Udiv`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Ult.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Ult.lean index 3d9370a878..9b7e8395e8 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Ult.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/Ult.lean @@ -12,8 +12,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.Ult @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblaster for `BitVec.ult` from `Impl.Operations.Ult`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ZeroExtend.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ZeroExtend.lean index 54719721c3..2b720eef66 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ZeroExtend.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Operations/ZeroExtend.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Operations.ZeroEx @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblaster `BitVec.zeroExtend` from `Impl.Operations.ZeroExtend`. -/ diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Pred.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Pred.lean index ae860395d9..c46575ba69 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Pred.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Pred.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Pred @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblaster for predicates over `BitVec` expressions (`BVPred`) from `Impl.Pred`. diff --git a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean index 5c5c463ff8..42e62b9406 100644 --- a/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean +++ b/src/Std/Tactic/BVDecide/Bitblast/BVExpr/Circuit/Lemmas/Var.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.Bitblast.BVExpr.Circuit.Impl.Var @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of the bitblaster for symbolic `BitVec` values from `Impl.Var`. diff --git a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/Lemmas.lean b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/Lemmas.lean index b3ed3bcd94..d2e0838712 100644 --- a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/Lemmas.lean +++ b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/Lemmas.lean @@ -11,8 +11,6 @@ public import Std.Tactic.BVDecide.LRAT.Internal.CNF @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains basic statements about the invariants that are satisfied by the LRAT checker implementation in `Implementation`. diff --git a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddResult.lean b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddResult.lean index 7b78da1e92..610d35a70f 100644 --- a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddResult.lean +++ b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddResult.lean @@ -172,7 +172,10 @@ theorem ratAdd_result {n : Nat} (f : DefaultFormula n) (c : DefaultClause n) (p have insertRupUnits_rw : (insertRupUnits f (negate c)).1 = ⟨(insertRupUnits f (negate c)).1.clauses, (insertRupUnits f (negate c)).1.rupUnits, (insertRupUnits f (negate c)).1.ratUnits, (insertRupUnits f (negate c)).1.assignments⟩ := rfl - sorry + simp +zetaDelta only [performRatCheck_fold_formula_eq performRupCheck_res h_performRupCheck_res (Literal.negate p) ratHints, + clauses_performRupCheck, rupUnits_performRupCheck, ratUnits_performRupCheck, + restoreAssignments_performRupCheck fc fc_assignments_size, ← insertRupUnits_rw, + clear_insertRup f f_readyForRatAdd.2 (negate c)] · grind end DefaultFormula diff --git a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddSound.lean b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddSound.lean index 3030bb6038..0d9f26d8e4 100644 --- a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddSound.lean +++ b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RatAddSound.lean @@ -10,8 +10,6 @@ public import Std.Tactic.BVDecide.LRAT.Internal.Formula.RatAddResult @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of RAT-based clause adding for the default LRAT checker implementation. diff --git a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddResult.lean b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddResult.lean index 82aff8a89e..400609f9b1 100644 --- a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddResult.lean +++ b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddResult.lean @@ -10,8 +10,6 @@ public import Std.Tactic.BVDecide.LRAT.Internal.Formula.Lemmas @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the implementation of RUP-based clause adding for the default LRAT checker implementation. diff --git a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddSound.lean b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddSound.lean index 89b73212cc..841f2744d2 100644 --- a/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddSound.lean +++ b/src/Std/Tactic/BVDecide/LRAT/Internal/Formula/RupAddSound.lean @@ -10,8 +10,6 @@ public import Std.Tactic.BVDecide.LRAT.Internal.Formula.RupAddResult @[expose] public section -set_option debug.byAsSorry true -- TODO: remove after bootstrap - /-! This module contains the verification of RUP-based clause adding for the default LRAT checker implementation. diff --git a/src/Std/Time/Date/ValidDate.lean b/src/Std/Time/Date/ValidDate.lean index 49a026b249..86dae3f21f 100644 --- a/src/Std/Time/Date/ValidDate.lean +++ b/src/Std/Time/Date/ValidDate.lean @@ -66,7 +66,7 @@ def ofOrdinal (ordinal : Day.Ordinal.OfYear leap) : ValidDate leap := let bounded := Bounded.LE.mk ordinal.val (And.intro h h₁) |>.sub acc let bounded : Bounded.LE 1 monthDays.val := bounded.cast (by omega) (by omega) let days₁ : Day.Ordinal := ⟨bounded.val, And.intro bounded.property.left (Int.le_trans bounded.property.right monthDays.property.right)⟩ - ⟨⟨idx, days₁⟩, Int.le_trans bounded.property.right (by sorry)⟩ + ⟨⟨idx, days₁⟩, Int.le_trans bounded.property.right (by simp +zetaDelta)⟩ else by let h₂ := Int.not_le.mp h₁ @@ -89,15 +89,15 @@ def ofOrdinal (ordinal : Day.Ordinal.OfYear leap) : ValidDate leap := rw [difference_eq (Int.le_of_lt_add_one h₃)] termination_by 12 - idx.val.toNat - -- decreasing_by - -- simp_wf - -- simp [Bounded.LE.addTop] - -- let gt0 : idx.val ≥ 0 := Int.le_trans (by decide) idx.property.left - -- refine Nat.sub_lt_sub_left (Int.toNat_lt gt0 |>.mpr h₃) ?_ - -- let toNat_lt_lt {n z : Int} (h : 0 ≤ z) (h₁ : 0 ≤ n) : z.toNat < n.toNat ↔ z < n := by - -- rw [← Int.not_le, ← Nat.not_le, ← Int.ofNat_le, Int.toNat_of_nonneg h, Int.toNat_of_nonneg h₁] - -- rw [toNat_lt_lt (by omega) (by omega)] - -- omega + decreasing_by + simp_wf + simp [Bounded.LE.addTop] + let gt0 : idx.val ≥ 0 := Int.le_trans (by decide) idx.property.left + refine Nat.sub_lt_sub_left (Int.toNat_lt gt0 |>.mpr h₃) ?_ + let toNat_lt_lt {n z : Int} (h : 0 ≤ z) (h₁ : 0 ≤ n) : z.toNat < n.toNat ↔ z < n := by + rw [← Int.not_le, ← Nat.not_le, ← Int.ofNat_le, Int.toNat_of_nonneg h, Int.toNat_of_nonneg h₁] + rw [toNat_lt_lt (by omega) (by omega)] + omega go 1 0 (Int.le_trans (by decide) ordinal.property.left) (by cases leap <;> decide) diff --git a/src/lake/Lake/Toml/Data/Dict.lean b/src/lake/Lake/Toml/Data/Dict.lean index f389e534c6..923f9da6a5 100644 --- a/src/lake/Lake/Toml/Data/Dict.lean +++ b/src/lake/Lake/Toml/Data/Dict.lean @@ -66,7 +66,7 @@ public def findIdx? (k : α) (t : RBDict α β cmp) : Option (Fin t.size) := do let i ← t.indices.get? k; if h : i < t.items.size then some ⟨i, h⟩ else none public def findEntry? (k : α) (t : RBDict α β cmp) : Option (α × β) := do - return t.items[← t.findIdx? k]'sorry + return t.items[← t.findIdx? k] @[inline] public def find? (k : α) (t : RBDict α β cmp) : Option β := do return (← t.findEntry? k).2 diff --git a/src/lake/Lake/Util/Cli.lean b/src/lake/Lake/Util/Cli.lean index 6517ae65b3..3a07c0edf3 100644 --- a/src/lake/Lake/Util/Cli.lean +++ b/src/lake/Lake/Util/Cli.lean @@ -90,10 +90,10 @@ variable [Monad m] [MonadStateOf ArgList m] handle (p.get' opt h) loop (p.next' opt h) termination_by opt.utf8ByteSize - p.byteIdx - -- decreasing_by - -- simp [String.Pos.Raw.atEnd] at h - -- apply Nat.sub_lt_sub_left h - -- exact String.Pos.Raw.byteIdx_lt_byteIdx_next opt p + decreasing_by + simp [String.Pos.Raw.atEnd] at h + apply Nat.sub_lt_sub_left h + exact String.Pos.Raw.byteIdx_lt_byteIdx_next opt p loop ⟨1⟩ /-- Splits a long option of the form `"--long foo bar"` into `--long` and `"foo bar"`. -/ diff --git a/src/lake/Lake/Util/Name.lean b/src/lake/Lake/Util/Name.lean index 4c2910a01d..ac76a00fb3 100644 --- a/src/lake/Lake/Util/Name.lean +++ b/src/lake/Lake/Util/Name.lean @@ -53,7 +53,7 @@ public theorem eq_anonymous_of_isAnonymous {n : Name} (h : n.isAnonymous) : n = isAnonymous_iff_eq_anonymous.mp h @[simp] public protected theorem beq_false (m n : Name) : (m == n) = false ↔ ¬ (m = n) := by - rw [← beq_iff_eq (a := m) (b := n)]; cases m == n <;> sorry + rw [← beq_iff_eq (a := m) (b := n)]; cases m == n <;> simp +decide @[simp] public theorem isPrefixOf_self {n : Name} : n.isPrefixOf n := by cases n <;> simp [isPrefixOf] diff --git a/src/stdlib_flags.h b/src/stdlib_flags.h index ca30180108..79a0e58edd 100644 --- a/src/stdlib_flags.h +++ b/src/stdlib_flags.h @@ -6,7 +6,7 @@ options get_default_options() { // see https://github.com/leanprover/lean4/blob/master/doc/dev/bootstrap.md#further-bootstrapping-complications #if LEAN_IS_STAGE0 == 1 // set to true to generally avoid bootstrapping issues limited to proofs - opts = opts.update({"debug", "proofAsSorry"}, true); + opts = opts.update({"debug", "proofAsSorry"}, false); // set to true to generally avoid bootstrapping issues in `omega` and `grind` opts = opts.update({"debug", "terminalTacticsAsSorry"}, false); // switch to `true` for ABI-breaking changes affecting meta code;