Skip to content

Commit c0f8fc0

Browse files
Merge branch 'main' into binary_rewrite
2 parents c643ec7 + bf597c7 commit c0f8fc0

File tree

13 files changed

+39
-113
lines changed

13 files changed

+39
-113
lines changed

Batteries/Data/Char/AsciiCasing.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ theorem beqCaseInsensitiveAsciiOnly.eqv : Equivalence (beqCaseInsensitiveAsciiOn
159159
/--
160160
Setoid structure on `Char` using `beqCaseInsensitiveAsciiOnly`
161161
-/
162+
@[implicit_reducible]
162163
def beqCaseInsensitiveAsciiOnly.isSetoid : Setoid Char:=
163164
⟨(beqCaseInsensitiveAsciiOnly · ·), beqCaseInsensitiveAsciiOnly.eqv⟩
164165

Batteries/Data/Char/Basic.lean

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ instance : Std.LawfulOrd Char :=
1919
.compareOfLessAndEq_of_irrefl_of_trans_of_not_lt_of_antisymm
2020
(fun _ => Nat.lt_irrefl _) Nat.lt_trans Nat.not_lt Char.le_antisymm
2121

22-
@[simp] theorem toNat_val (c : Char) : c.val.toNat = c.toNat := rfl
23-
2422
@[simp] theorem toNat_ofNatAux {n : Nat} (h : n.isValidChar) : toNat (ofNatAux n h) = n := by
2523
simp [ofNatAux, toNat]
2624

@@ -29,9 +27,6 @@ theorem toNat_ofNat (n : Nat) : toNat (ofNat n) = if n.isValidChar then n else 0
2927
· simp [ofNat, *]
3028
· simp [ofNat, toNat, *]
3129

32-
@[simp, grind =]
33-
theorem toNat_mk (h : UInt32.isValidChar v) : Char.toNat ⟨v, h⟩ = v.toNat := rfl
34-
3530
@[simp]
3631
theorem val_ofNat (hn : Nat.isValidChar n) : (ofNat n).val = UInt32.ofNat n := by
3732
simp [ofNat, hn, ofNatAux, UInt32.ofNatLT_eq_ofNat]

Batteries/Data/List/Basic.lean

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -105,43 +105,6 @@ def splitAtD (n : Nat) (l : List α) (dflt : α) : List α × List α := go n l
105105
| 0, xs, acc => (acc.reverse, xs)
106106
| n, [], acc => (acc.reverseAux (replicate n dflt), [])
107107

108-
/--
109-
Split a list at every element satisfying a predicate. The separators are not in the result.
110-
```
111-
[1, 1, 2, 3, 2, 4, 4].splitOnP (· == 2) = [[1, 1], [3], [4, 4]]
112-
```
113-
-/
114-
def splitOnP (P : α → Bool) (l : List α) : List (List α) := go l [] where
115-
/-- Auxiliary for `splitOnP`: `splitOnP.go xs acc = res'`
116-
where `res'` is obtained from `splitOnP P xs` by prepending `acc.reverse` to the first element. -/
117-
go : List α → List α → List (List α)
118-
| [], acc => [acc.reverse]
119-
| a :: t, acc => if P a then acc.reverse :: go t [] else go t (a::acc)
120-
121-
/-- Tail recursive version of `splitOnP`. -/
122-
@[inline] def splitOnPTR (P : α → Bool) (l : List α) : List (List α) := go l #[] #[] where
123-
/-- Auxiliary for `splitOnP`: `splitOnP.go xs acc r = r.toList ++ res'`
124-
where `res'` is obtained from `splitOnP P xs` by prepending `acc.toList` to the first element. -/
125-
@[specialize] go : List α → Array α → Array (List α) → List (List α)
126-
| [], acc, r => r.toListAppend [acc.toList]
127-
| a :: t, acc, r => bif P a then go t #[] (r.push acc.toList) else go t (acc.push a) r
128-
129-
@[csimp] theorem splitOnP_eq_splitOnPTR : @splitOnP = @splitOnPTR := by
130-
funext α P l; simp [splitOnPTR]
131-
suffices ∀ xs acc r,
132-
splitOnPTR.go P xs acc r = r.toList ++ splitOnP.go P xs acc.toList.reverse from
133-
(this l #[] #[]).symm
134-
intro xs acc r; induction xs generalizing acc r with simp [splitOnP.go, splitOnPTR.go]
135-
| cons x xs IH => cases P x <;> simp [*]
136-
137-
/--
138-
Split a list at every occurrence of a separator element. The separators are not in the result.
139-
```
140-
[1, 1, 2, 3, 2, 4, 4].splitOn 2 = [[1, 1], [3], [4, 4]]
141-
```
142-
-/
143-
@[inline] def splitOn [BEq α] (a : α) (as : List α) : List (List α) := as.splitOnP (· == a)
144-
145108
/-- Apply `f` to the last element of `l`, if it exists. -/
146109
@[inline] def modifyLast (f : α → α) (l : List α) : List α := go l #[] where
147110
/-- Auxiliary for `modifyLast`: `modifyLast.go f l acc = acc.toList ++ modifyLast f l`. -/

Batteries/Data/List/Lemmas.lean

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,21 +1312,6 @@ theorem map_coe_finRange_eq_range : (finRange n).map (↑·) = List.range n := b
13121312
apply List.ext_getElem <;> simp
13131313
/-! ### sum/prod -/
13141314

1315-
private theorem foldr_eq_foldl_aux (f : α → α → α) (init : α) [Std.Associative f]
1316-
[Std.LawfulIdentity f init] {l : List α} :
1317-
l.foldl f a = f a (l.foldl f init) := by
1318-
induction l generalizing a with
1319-
| nil => simp [Std.LawfulRightIdentity.right_id]
1320-
| cons b l ih =>
1321-
simp [Std.LawfulLeftIdentity.left_id, ih (a := f a b), ih (a := b), Std.Associative.assoc]
1322-
1323-
theorem foldr_eq_foldl (f : α → α → α) (init : α) [Std.Associative f]
1324-
[Std.LawfulIdentity f init] {l : List α} :
1325-
l.foldr f init = l.foldl f init := by
1326-
induction l with
1327-
| nil => rfl
1328-
| cons a l ih => simp [ih, Std.LawfulLeftIdentity.left_id, foldr_eq_foldl_aux (a := a)]
1329-
13301315
@[simp, grind =]
13311316
theorem prod_nil [Mul α] [One α] : ([] : List α).prod = 1 := rfl
13321317

@@ -1367,9 +1352,6 @@ theorem prod_eq_foldl [Mul α] [One α] [Std.Associative (α := α) (· * ·)]
13671352
theorem sum_zero_cons [Add α] [Zero α] [Std.LawfulLeftIdentity (α := α) (· + ·) 0] {l : List α} :
13681353
(0 :: l).sum = l.sum := by simp [Std.LawfulLeftIdentity.left_id]
13691354

1370-
theorem sum_singleton [Add α] [Zero α] [Std.LawfulRightIdentity (α := α) (· + ·) 0] {a : α} :
1371-
[a].sum = a := by simp [Std.LawfulRightIdentity.right_id]
1372-
13731355
theorem sum_pair [Add α] [Zero α] [Std.LawfulRightIdentity (α := α) (· + ·) 0] {a b : α} :
13741356
[a, b].sum = a + b := by simp [Std.LawfulRightIdentity.right_id]
13751357

@@ -1383,14 +1365,8 @@ theorem sum_flatten [Add α] [Zero α] [Std.LawfulIdentity (α := α) (· + ·)
13831365
l.flatten.sum = (l.map sum).sum := by
13841366
induction l with simp [*]
13851367

1386-
theorem sum_eq_foldl [Add α] [Zero α] [Std.Associative (α := α) (· + ·)]
1387-
[Std.LawfulIdentity (α := α) (· + ·) 0] {l : List α} :
1388-
l.sum = l.foldl (· + ·) 0 := foldr_eq_foldl ..
1389-
13901368
theorem take_succ_drop {l : List α} {n stop : Nat}
13911369
(h : n < l.length - stop) :
13921370
(l.drop stop |>.take (n + 1)) = (l.drop stop |>.take n) ++ [l[stop + n]'(by omega)] := by
13931371
rw [← List.take_append_getElem (by simpa [← List.length_drop] using h)]
13941372
simp [List.getElem_drop]
1395-
1396-
attribute [simp] reverse_singleton

Batteries/Data/List/Pairwise.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ theorem pwFilter_sublist [DecidableRel (α := α) R] : ∀ l : List α, pwFilter
6969
| [] => nil_sublist _
7070
| x :: l =>
7171
if h : ∀ y ∈ pwFilter R l, R x y then
72-
pwFilter_cons_of_pos h ▸ (pwFilter_sublist l).cons₂ _
72+
pwFilter_cons_of_pos h ▸ (pwFilter_sublist l).cons_cons _
7373
else
7474
pwFilter_cons_of_neg h ▸ Sublist.cons _ (pwFilter_sublist l)
7575

Batteries/Data/List/Perm.lean

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ theorem Subperm.count_le [BEq α] {l₁ l₂ : List α} (s : l₁ <+~ l₂) (a)
8686
count a l₁ ≤ count a l₂ := s.countP_le _
8787

8888
theorem subperm_cons (a : α) {l₁ l₂ : List α} : a :: l₁ <+~ a :: l₂ ↔ l₁ <+~ l₂ := by
89-
refine ⟨fun ⟨l, p, s⟩ => ?_, fun ⟨l, p, s⟩ => ⟨a :: l, p.cons a, s.cons₂ _⟩⟩
89+
refine ⟨fun ⟨l, p, s⟩ => ?_, fun ⟨l, p, s⟩ => ⟨a :: l, p.cons a, s.cons_cons _⟩⟩
9090
match s with
9191
| .cons _ s' => exact (p.subperm_left.2 <| (sublist_cons_self _ _).subperm).trans s'.subperm
92-
| .cons₂ _ s' => exact ⟨_, p.cons_inv, s'⟩
92+
| .cons_cons _ s' => exact ⟨_, p.cons_inv, s'⟩
9393

9494
/-- Weaker version of `Subperm.cons_left` -/
9595
theorem cons_subperm_of_not_mem_of_mem {a : α} {l₁ l₂ : List α} (h₁ : a ∉ l₁) (h₂ : a ∈ l₂)
@@ -100,17 +100,17 @@ theorem cons_subperm_of_not_mem_of_mem {a : α} {l₁ l₂ : List α} (h₁ : a
100100
| @cons r₁ _ b s' ih =>
101101
simp at h₂
102102
match h₂ with
103-
| .inl e => subst_vars; exact ⟨_ :: r₁, p.cons _, s'.cons₂ _⟩
103+
| .inl e => subst_vars; exact ⟨_ :: r₁, p.cons _, s'.cons_cons _⟩
104104
| .inr m => let ⟨t, p', s'⟩ := ih h₁ m p; exact ⟨t, p', s'.cons _⟩
105-
| @cons₂ _ r₂ b _ ih =>
105+
| @cons_cons _ r₂ b _ ih =>
106106
have bm : b ∈ l₁ := p.subset mem_cons_self
107107
have am : a ∈ r₂ := by
108108
simp only [mem_cons] at h₂
109109
exact h₂.resolve_left fun e => h₁ <| e.symm ▸ bm
110110
obtain ⟨t₁, t₂, rfl⟩ := append_of_mem bm
111111
have st : t₁ ++ t₂ <+ t₁ ++ b :: t₂ := by simp
112112
obtain ⟨t, p', s'⟩ := ih (mt (st.subset ·) h₁) am (.cons_inv <| p.trans perm_middle)
113-
exact ⟨b :: t, (p'.cons b).trans <| (swap ..).trans (perm_middle.symm.cons a), s'.cons₂ _⟩
113+
exact ⟨b :: t, (p'.cons b).trans <| (swap ..).trans (perm_middle.symm.cons a), s'.cons_cons _⟩
114114

115115
theorem subperm_append_left {l₁ l₂ : List α} : ∀ l, l ++ l₁ <+~ l ++ l₂ ↔ l₁ <+~ l₂
116116
| [] => .rfl
@@ -131,7 +131,7 @@ theorem Subperm.exists_of_length_lt {l₁ l₂ : List α} (s : l₁ <+~ l₂) (h
131131
match Nat.lt_or_eq_of_le (Nat.le_of_lt_succ h) with
132132
| .inl h => exact (IH h).imp fun a s => s.trans (sublist_cons_self _ _).subperm
133133
| .inr h => exact ⟨a, s.eq_of_length h ▸ .refl _⟩
134-
| cons₂ b _ IH =>
134+
| cons_cons b _ IH =>
135135
exact (IH <| Nat.lt_of_succ_lt_succ h).imp fun a s =>
136136
(swap ..).subperm_right.1 <| (subperm_cons _).2 s
137137

@@ -155,15 +155,15 @@ theorem Nodup.perm_iff_eq_of_sublist {l₁ l₂ l : List α} (d : Nodup l)
155155
| cons a s₂ IH =>
156156
match s₁ with
157157
| .cons _ s₁ => exact IH d.2 s₁ h
158-
| .cons₂ _ s₁ =>
158+
| .cons_cons _ s₁ =>
159159
have := Subperm.subset ⟨_, h.symm, s₂⟩ (.head _)
160160
exact (d.1 this).elim
161-
| cons₂ a _ IH =>
161+
| cons_cons a _ IH =>
162162
match s₁ with
163163
| .cons _ s₁ =>
164164
have := Subperm.subset ⟨_, h, s₁⟩ (.head _)
165165
exact (d.1 this).elim
166-
| .cons₂ _ s₁ => rw [IH d.2 s₁ h.cons_inv]
166+
| .cons_cons _ s₁ => rw [IH d.2 s₁ h.cons_inv]
167167

168168
theorem subperm_cons_erase [BEq α] [LawfulBEq α] (a : α) (l : List α) : l <+~ a :: l.erase a :=
169169
if h : a ∈ l then

Batteries/Data/String/Lemmas.lean

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ open List
9292
theorem utf8Len_le_of_sublist : ∀ {cs₁ cs₂}, cs₁ <+ cs₂ → utf8Len cs₁ ≤ utf8Len cs₂
9393
| _, _, .slnil => Nat.le_refl _
9494
| _, _, .cons _ h => Nat.le_trans (utf8Len_le_of_sublist h) (Nat.le_add_right ..)
95-
| _, _, .cons₂ _ h => Nat.add_le_add_right (utf8Len_le_of_sublist h) _
95+
| _, _, .cons_cons _ h => Nat.add_le_add_right (utf8Len_le_of_sublist h) _
9696

9797
theorem utf8Len_le_of_infix (h : cs₁ <:+: cs₂) : utf8Len cs₁ ≤ utf8Len cs₂ :=
9898
utf8Len_le_of_sublist h.sublist
@@ -322,25 +322,13 @@ theorem prev_of_valid' (cs cs' : List Char) :
322322
| _, .inl rfl => apply Pos.Raw.prev_zero
323323
| _, .inr ⟨cs, c, rfl⟩ => simp [prev_of_valid, -ofList_append]
324324

325-
theorem front_eq (s : String) : Legacy.front s = s.toList.headD default := by
326-
unfold Legacy.front; simpa using get_of_valid [] s.toList
327-
328325
theorem back_eq_get_prev_rawEndPos {s : String} : Legacy.back s = (s.rawEndPos.prev s).get s := rfl
329326

330-
theorem back_eq (s : String) : Legacy.back s = s.toList.getLastD default := by
331-
conv => lhs; rw [← s.ofList_toList]
332-
match s.toList.eq_nil_or_concat with
333-
| .inl h => simp [h]; rfl
334-
| .inr ⟨cs, c, h⟩ =>
335-
simp only [h, back_eq_get_prev_rawEndPos]
336-
have : (ofList (cs ++ [c])).rawEndPos = ⟨utf8Len cs + c.utf8Size⟩ := by
337-
simp [rawEndPos, utf8ByteSize_ofList]
338-
simp [-ofList_append, this, prev_of_valid, get_of_valid]
339-
340327
theorem atEnd_of_valid (cs : List Char) (cs' : List Char) :
341328
String.Pos.Raw.atEnd (ofList (cs ++ cs')) ⟨utf8Len cs⟩ ↔ cs' = [] := by
342329
rw [atEnd_iff]
343-
cases cs' <;> simp [add_utf8Size_pos, rawEndPos, utf8ByteSize_ofList]
330+
cases cs' <;> simp [rawEndPos, utf8ByteSize_ofList]
331+
exact Nat.add_pos_left (Char.utf8Size_pos _) _
344332

345333
unseal Legacy.posOfAux Legacy.findAux in
346334
theorem posOfAux_eq (s c) : Legacy.posOfAux s c = Legacy.findAux s (· == c) := (rfl)
@@ -517,24 +505,25 @@ theorem extract_of_valid (l m r : List Char) :
517505

518506
theorem splitAux_of_valid (p l m r acc) :
519507
splitAux (ofList (l ++ m ++ r)) p ⟨utf8Len l⟩ ⟨utf8Len l + utf8Len m⟩ acc =
520-
acc.reverse ++ (List.splitOnP.go p r m.reverse).map ofList := by
508+
acc.reverse ++ (List.splitOnPPrepend p r m.reverse).map ofList := by
521509
unfold splitAux
522510
simp only [List.append_assoc, atEnd_iff, rawEndPos_ofList, utf8Len_append, Pos.Raw.mk_le_mk,
523511
Nat.add_le_add_iff_left, (by omega : utf8Len m + utf8Len r ≤ utf8Len m ↔ utf8Len r = 0),
524512
utf8Len_eq_zero, List.reverse_cons, dite_eq_ite]
525513
split
526-
· subst r; simpa [List.splitOnP.go] using extract_of_valid l m []
514+
· subst r
515+
simpa using extract_of_valid l m []
527516
· obtain ⟨c, r, rfl⟩ := r.exists_cons_of_ne_nil ‹_›
528517
simp only [by
529518
simpa [-ofList_append] using
530519
(⟨get_of_valid (l ++ m) (c :: r), next_of_valid (l ++ m) c r,
531520
extract_of_valid l m (c :: r)⟩ :
532-
_ ∧ _ ∧ _),
533-
List.splitOnP.go, List.reverse_reverse]
521+
_ ∧ _ ∧ _)]
534522
split <;> rename_i h
535-
· simpa [Nat.add_assoc]
536-
using splitAux_of_valid p (l++m++[c]) [] r ((ofList m)::acc)
537-
· simpa [Nat.add_assoc] using splitAux_of_valid p l (m++[c]) r acc
523+
· simpa [Nat.add_assoc, List.splitOnPPrepend_cons_eq_if, h] using
524+
splitAux_of_valid p (l++m++[c]) [] r ((ofList m)::acc)
525+
· simpa [List.splitOnPPrepend_cons_eq_if, h, Nat.add_assoc] using
526+
splitAux_of_valid p l (m++[c]) r acc
538527

539528
theorem splitToList_of_valid (s p) : splitToList s p = (List.splitOnP p s.toList).map ofList := by
540529
simpa [splitToList] using splitAux_of_valid p [] [] s.toList []
@@ -559,12 +548,9 @@ theorem join_eq (ss : List String) : join ss = ofList (ss.map toList).flatten :=
559548
| nil => simp
560549
| cons s ss ih => simp [ih]
561550

562-
@[simp] theorem toList_join (ss : List String) : (join ss).toList = (ss.map toList).flatten := by
563-
simp [join_eq]
564-
565551
@[deprecated toList_join (since := "2025-10-31")]
566552
theorem data_join (ss : List String) : (join ss).toList = (ss.map toList).flatten :=
567-
toList_join ss
553+
toList_join
568554

569555
namespace Legacy.Iterator
570556

@@ -573,7 +559,7 @@ namespace Legacy.Iterator
573559

574560
theorem hasNext_cons_addChar (c : Char) (cs : List Char) (i : Pos.Raw) :
575561
hasNext ⟨String.ofList (c :: cs), i + c⟩ = hasNext ⟨String.ofList cs, i⟩ := by
576-
simp [hasNext, Nat.add_lt_add_iff_right]
562+
simp [hasNext, utf8ByteSize_ofList]; lia
577563

578564
/-- Validity for a string iterator. -/
579565
def Valid (it : Iterator) : Prop := it.pos.Valid it.s

Batteries/Data/Vector/Lemmas.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ theorem get_tail (v : Vector α (n + 1)) (i : Fin n) :
100100

101101
@[simp]
102102
theorem finIdxOf?_empty [BEq α] (v : Vector α 0) : v.finIdxOf? a = none := by
103-
simp [v.eq_empty]; rfl
103+
simp [v.eq_empty]
104104

105105
@[simp]
106106
theorem finIdxOf?_eq_none_iff [BEq α] [LawfulBEq α] {v : Vector α n} {a : α} :

Batteries/Lean/Expr.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def toSyntax (e : Expr) : TermElabM Syntax.Term := withFreshMacroScope do
3232
/-- Like `withApp` but ignores metadata. -/
3333
@[inline]
3434
def withApp' (e : Expr) (k : Expr → Array Expr → α) : α :=
35-
let dummy := mkSort levelZero
35+
let dummy := mkSort .zero
3636
let nargs := e.getAppNumArgs'
3737
go e (.replicate nargs dummy) (nargs - 1)
3838
where

Batteries/Tactic/Alias.lean

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ elab (name := alias) mods:declModifiers "alias " alias:ident " := " name:ident :
8888
let declMods ← elabModifiers mods
8989
Lean.withExporting (isExporting := declMods.isInferredPublic (← getEnv)) do
9090
let (attrs, machineApplicable) := setDeprecatedTarget name declMods.attrs
91+
let env ← getEnv
9192
let declMods := { declMods with
9293
computeKind :=
93-
if isNoncomputable (← getEnv) name then .noncomputable
94+
if isNoncomputable env name then .noncomputable
95+
else if isMarkedMeta env name then .meta
9496
else declMods.computeKind
9597
isUnsafe := declMods.isUnsafe || cinfo.isUnsafe
9698
attrs
@@ -109,10 +111,11 @@ elab (name := alias) mods:declModifiers "alias " alias:ident " := " name:ident :
109111
safety := if declMods.isUnsafe then .unsafe else .safe
110112
}
111113
checkNotAlreadyDeclared declName
112-
if declMods.isNoncomputable then
113-
addDecl decl
114-
else
115-
addAndCompile decl
114+
addDecl decl
115+
if !declMods.isNoncomputable then
116+
if declMods.isMeta then
117+
modifyEnv (markMeta · declName)
118+
compileDecl decl
116119
addDeclarationRangesFromSyntax declName (← getRef) alias
117120
Term.addTermInfo' alias (← mkConstWithLevelParams declName) (isBinder := true)
118121
if let some (doc, isVerso) := declMods.docString? then

0 commit comments

Comments
 (0)