Skip to content

Commit 202175c

Browse files
authored
bump toolchain to nightly 2026-03-07 (#278)
1 parent 03e707c commit 202175c

File tree

4 files changed

+21
-193
lines changed

4 files changed

+21
-193
lines changed

HumanEvalLean/HumanEval0.lean

Lines changed: 0 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -12,178 +12,12 @@ set_option mvcgen.warning false
1212
## Missing API
1313
-/
1414

15-
namespace Array
16-
17-
def MergeSort.merge (xs ys : Array α) (le : α → α → Bool := by exact (· ≤ ·)) : Array α :=
18-
if hxs : 0 < xs.size then
19-
if hys : 0 < ys.size then
20-
go xs[*...*] ys[*...*] (by simp only [Array.size_mkSlice_rii]; omega) (by simp only [Array.size_mkSlice_rii]; omega) (Array.emptyWithCapacity (xs.size + ys.size))
21-
else
22-
xs
23-
else
24-
ys
25-
where
26-
go (xs ys : Subarray α) (hxs : 0 < xs.size) (hys : 0 < ys.size) (acc : Array α) : Array α :=
27-
let x := xs[0]
28-
let y := ys[0]
29-
if le x y then
30-
if hi : 1 < xs.size then
31-
go (xs.drop 1) ys (by simp only [Subarray.size_drop]; omega) hys (acc.push x)
32-
else
33-
ys.foldl (init := acc.push x) (fun acc y => acc.push y)
34-
else
35-
if hj : 1 < ys.size then
36-
go xs (ys.drop 1) hxs (by simp only [Subarray.size_drop]; omega) (acc.push y)
37-
else
38-
xs.foldl (init := acc.push y) (fun acc x => acc.push x)
39-
termination_by xs.size + ys.size
40-
41-
def _root_.Subarray.mergeSort (xs : Subarray α) (le : α → α → Bool := by exact (· ≤ ·)) : Array α :=
42-
if h : 1 < xs.size then
43-
let splitIdx := (xs.size + 1) / 2 -- We follow the same splitting convention as `List.mergeSort`
44-
let left := xs[*...splitIdx]
45-
let right := xs[splitIdx...*]
46-
MergeSort.merge (mergeSort left le) (mergeSort right le) le
47-
else
48-
xs
49-
termination_by xs.size
50-
decreasing_by
51-
· simp only [Subarray.size_mkSlice_rio]; omega
52-
· simp only [Subarray.size_mkSlice_rci]; omega
53-
54-
def mergeSort (xs : Array α) (le : α → α → Bool := by exact (· ≤ ·)) : Array α :=
55-
xs[*...*].mergeSort le
56-
57-
end Array
58-
59-
theorem Array.MergeSort.merge.go_eq_listMerge {xs ys : Subarray α} {hxs hys le acc} :
60-
(Array.MergeSort.merge.go le xs ys hxs hys acc).toList = acc.toList ++ List.merge xs.toList ys.toList le := by
61-
fun_induction Array.MergeSort.merge.go le xs ys hxs hys acc
62-
· rename_i xs ys _ _ _ _ _ _ _ _
63-
rw [List.merge.eq_def]
64-
split
65-
· have : xs.size = 0 := by simp [← Subarray.length_toList, *]
66-
omega
67-
· have : ys.size = 0 := by simp [← Subarray.length_toList, *]
68-
omega
69-
· rename_i x' xs' y' ys' _ _
70-
simp +zetaDelta only at *
71-
have h₁ : x' = xs[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
72-
have h₂ : y' = ys[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
73-
cases h₁
74-
cases h₂
75-
simp [Subarray.toList_drop, *]
76-
· rename_i xs ys _ _ _ _ _ _ _
77-
rw [List.merge.eq_def]
78-
split
79-
· have : xs.size = 0 := by simp [← Subarray.length_toList, *]
80-
omega
81-
· have : ys.size = 0 := by simp [← Subarray.length_toList, *]
82-
omega
83-
· rename_i x' xs' y' ys' _ _
84-
simp +zetaDelta only at *
85-
have h₁ : x' = xs[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
86-
have h₂ : y' = ys[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
87-
cases h₁
88-
cases h₂
89-
simp [*]
90-
have : xs.size = xs'.length + 1 := by simp [← Subarray.length_toList, *]
91-
have : xs' = [] := List.eq_nil_of_length_eq_zero (by omega)
92-
simp [this]
93-
rw [← Subarray.foldl_toList]
94-
simp [*]
95-
· rename_i xs ys _ _ _ _ _ _ _ _
96-
rw [List.merge.eq_def]
97-
split
98-
· have : xs.size = 0 := by simp [← Subarray.length_toList, *]
99-
omega
100-
· have : ys.size = 0 := by simp [← Subarray.length_toList, *]
101-
omega
102-
· rename_i x' xs' y' ys' _ _
103-
simp +zetaDelta only at *
104-
have h₁ : x' = xs[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
105-
have h₂ : y' = ys[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
106-
cases h₁
107-
cases h₂
108-
simp [Subarray.toList_drop, *]
109-
· rename_i xs ys _ _ _ _ _ _ _
110-
rw [List.merge.eq_def]
111-
split
112-
· have : xs.size = 0 := by simp [← Subarray.length_toList, *]
113-
omega
114-
· have : ys.size = 0 := by simp [← Subarray.length_toList, *]
115-
omega
116-
· rename_i x' xs' y' ys' _ _
117-
simp +zetaDelta only at *
118-
have h₁ : x' = xs[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
119-
have h₂ : y' = ys[0] := by simp [Subarray.getElem_eq_getElem_toList, *]
120-
cases h₁
121-
cases h₂
122-
simp [*]
123-
have : ys.size = ys'.length + 1 := by simp [← Subarray.length_toList, *]
124-
have : ys' = [] := List.eq_nil_of_length_eq_zero (by omega)
125-
simp [this]
126-
rw [← Subarray.foldl_toList]
127-
simp [*]
128-
129-
theorem Array.MergeSort.merge_eq_listMerge {xs ys : Array α} {le} :
130-
(Array.MergeSort.merge xs ys le).toList = List.merge xs.toList ys.toList le := by
131-
rw [Array.MergeSort.merge]
132-
split <;> rename_i heq₁
133-
· split <;> rename_i heq₂
134-
· simp [Array.MergeSort.merge.go_eq_listMerge]
135-
· have : ys.toList = [] := by simp_all
136-
simp [this]
137-
· have : xs.toList = [] := by simp_all
138-
simp [this]
139-
140-
theorem List.mergeSort_eq_merge_mkSlice {xs : List α} :
141-
xs.mergeSort le =
142-
if 1 < xs.length then
143-
merge (xs[*...((xs.length + 1) / 2)].toList.mergeSort le) (xs[((xs.length + 1) / 2)...*].toList.mergeSort le) le
144-
else
145-
xs := by
146-
fun_cases xs.mergeSort le
147-
· simp
148-
· simp
149-
· rename_i x y ys lr hl hr
150-
simp [lr]
151-
152-
theorem Subarray.toList_mergeSort {xs : Subarray α} {le : α → α → Bool} :
153-
(xs.mergeSort le).toList = xs.toList.mergeSort le := by
154-
fun_induction xs.mergeSort le
155-
· rw [List.mergeSort_eq_merge_mkSlice]
156-
simp +zetaDelta [Array.MergeSort.merge_eq_listMerge, *]
157-
· simp [List.mergeSort_eq_merge_mkSlice, *]
158-
159-
theorem Array.toList_mergeSort {xs : Array α} {le : α → α → Bool} :
160-
(xs.mergeSort le).toList = xs.toList.mergeSort le := by
161-
rw [Array.mergeSort, Subarray.toList_mergeSort, Array.toList_mkSlice_rii]
162-
16315
theorem Nat.eq_add_of_toList_rio_eq_append_cons {a : Nat} {pref cur suff}
16416
(h : (*...a).toList = pref ++ cur :: suff) :
16517
cur = pref.length := by
16618
have := Rio.eq_succMany?_of_toList_eq_append_cons h
16719
simpa [PRange.UpwardEnumerable.least, PRange.least?] using this
16820

169-
@[simp, grind =]
170-
theorem Array.size_mergeSort {xs : Array α} :
171-
(xs.mergeSort le).size = xs.size := by
172-
rw [← length_toList, Array.toList_mergeSort, List.length_mergeSort, length_toList]
173-
174-
theorem Array.mergeSort_perm {xs : Array α} :
175-
(xs.mergeSort le).Perm xs := by
176-
simpa only [perm_iff_toList_perm, Array.toList_mergeSort] using List.mergeSort_perm _ _
177-
178-
theorem Array.pairwise_mergeSort
179-
(trans : ∀ (a b c : α), le a b → le b c → le a c)
180-
(total : ∀ (a b : α), le a b || le b a) :
181-
(l : Array α) → (mergeSort l le).toList.Pairwise (le · ·) := by
182-
intro xs
183-
simpa [toList_mergeSort] using List.pairwise_mergeSort trans total _
184-
185-
attribute [simp, grind =] Rio.mem_iff
186-
18721
/-!
18822
## Implementation
18923
-/

HumanEvalLean/HumanEval20.lean

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public section
1515
increasing order.
1616
-/
1717
def findClosestElements (xs : Array Rat) (h : 2 ≤ xs.size := by grind) : Rat × Rat := Id.run do
18-
let sorted := xs.toList.mergeSort.toArray
19-
have : 2 ≤ sorted.size := by grind [List.length_mergeSort]
18+
let sorted := xs.mergeSort
19+
have : 2 ≤ sorted.size := by grind [Array.size_mergeSort]
2020
let mut closest := (sorted[0], sorted[1])
2121
for hi : i in 1...(sorted.size - 1) do
2222
if (sorted[i + 1] - sorted[i]).abs < (closest.2 - closest.1).abs then
@@ -33,8 +33,6 @@ example : findClosestElements #[(1.1 : Rat), 2.2, 3.1, 4.1, 5.1] = (2.2, 3.1) :=
3333

3434
/-! ## Missing API -/
3535

36-
-- TODO: As soon as `Array.mergeSort` is merged, use that one.
37-
3836
theorem Nat.eq_add_of_toList_rco_eq_append_cons {a b : Nat} {pref cur suff}
3937
(h : (a...b).toList = pref ++ cur :: suff) :
4038
cur = a + pref.length := by
@@ -54,11 +52,11 @@ theorem sorted_findClosestElements {xs : Array Rat} {h : 2 ≤ xs.size} :
5452
invariants
5553
· ⇓⟨cur, closest⟩ => ⌜closest.1 ≤ closest.2
5654
case vc1 sorted _ _ _ _ _ _ _ _ _ =>
57-
have : sorted.toList.Pairwise (· ≤ ·) := by grind [List.pairwise_mergeSort]
55+
have : sorted.toList.Pairwise (· ≤ ·) := by grind [Array.pairwise_mergeSort]
5856
simp only [List.pairwise_iff_getElem] at this
5957
grind
6058
case vc3 sorted _ _ =>
61-
have : sorted.toList.Pairwise (· ≤ ·) := by grind [List.pairwise_mergeSort]
59+
have : sorted.toList.Pairwise (· ≤ ·) := by grind [Array.pairwise_mergeSort]
6260
simp only [List.pairwise_iff_getElem] at this
6361
grind
6462

@@ -69,8 +67,8 @@ The elements of the pair `findClosestElements xs` are located in two distinct po
6967
theorem exists_mem_findClosestElements {xs : Array Rat} {h : 2 ≤ xs.size} :
7068
∃ (i j : Nat) (hi : i < xs.size) (hj : j < xs.size) (_hij : i ≠ j),
7169
findClosestElements xs = (xs[i], xs[j]) := by
72-
suffices h' : ¬ xs.toList.mergeSort.Pairwise (fun x y => ¬ (findClosestElements xs = (x, y) ∨ findClosestElements xs = (y, x))) by
73-
have := xs.toList.mergeSort_perm (· ≤ ·)
70+
suffices h' : ¬ xs.mergeSort.toList.Pairwise (fun x y => ¬ (findClosestElements xs = (x, y) ∨ findClosestElements xs = (y, x))) by
71+
have := xs.mergeSort_perm (le := (· ≤ ·))
7472
rw [this.pairwise_iff (by grind)] at h'
7573
grind [List.pairwise_iff_getElem]
7674
generalize hwp : findClosestElements xs = wp
@@ -79,9 +77,9 @@ theorem exists_mem_findClosestElements {xs : Array Rat} {h : 2 ≤ xs.size} :
7977
invariants
8078
| inv1 sorted _ _ => ⇓⟨cur, closest⟩ => ⌜∃ (i j : Nat) (hi : i < sorted.size) (hj : j < sorted.size) (hij : i ≠ j),
8179
closest = (sorted[i], sorted[j])⌝
82-
case vc1 => grind [List.length_mergeSort, List.pairwise_iff_getElem]
80+
case vc1 => grind [List.pairwise_iff_getElem]
8381
case vc3 => exact ⟨0, 1, by grind⟩
84-
case vc4 => grind [List.length_mergeSort, List.pairwise_iff_getElem]
82+
case vc4 => grind [List.pairwise_iff_getElem]
8583

8684
/--
8785
This lemma is an intermediate step towards `pairwise_abs_findClosestElements_le`.
@@ -91,7 +89,7 @@ distance of any two consecutive elements in the *sorted* array.
9189
-/
9290
private theorem abs_findClosestElements_le_mergeSort {xs : Array Rat} {h : 2 ≤ xs.size} :
9391
letI closest := findClosestElements xs
94-
letI sorted := xs.toList.mergeSort.toArray
92+
letI sorted := xs.mergeSort
9593
∀ (i : Nat) (hi : i + 1 < sorted.size),
9694
(closest.2 - closest.1).abs ≤ (sorted[i + 1] - sorted[i]).abs := by
9795
generalize hwp : findClosestElements xs = wp
@@ -109,7 +107,7 @@ private theorem abs_findClosestElements_le_mergeSort {xs : Array Rat} {h : 2 ≤
109107
by_cases i < cur <;> grind
110108
case vc3 => grind
111109
case vc4 h =>
112-
simp +zetaDelta only [List.getElem!_toArray, List.getElem!_eq_getElem?_getD] at h
110+
simp +zetaDelta only [Array.getElem!_eq_getD, Array.getD_eq_getD_getElem?] at h
113111
grind [Nat.length_toList_rco]
114112

115113
/--
@@ -121,11 +119,11 @@ is at least as large as the distance between the components of `findClosestEleme
121119
theorem pairwise_abs_findClosestElements_le {xs : Array Rat} {h : 2 ≤ xs.size} :
122120
letI closest := findClosestElements xs
123121
xs.toList.Pairwise (fun x y => (closest.2 - closest.1).abs ≤ (y - x).abs) := by
124-
have := xs.toList.mergeSort_perm (· ≤ ·)
122+
have := xs.mergeSort_perm (le := (· ≤ ·))
125123
rw [← this.pairwise_iff (by grind [Rat.abs_sub_comm]), List.pairwise_iff_getElem]
126124
intro i j hi hj hij
127125
have := abs_findClosestElements_le_mergeSort (xs := xs) (h := h) i (by grind)
128-
have h_sorted := xs.toList.pairwise_mergeSort (le := (· ≤ ·)) (by grind) (by grind)
126+
have h_sorted := xs.pairwise_mergeSort (le := (· ≤ ·)) (by grind) (by grind)
129127
grind [List.pairwise_iff_getElem, Rat.abs_of_nonneg]
130128

131129
/-!

HumanEvalLean/HumanEval47.lean

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,9 @@ module
44

55
public section
66

7-
@[grind =]
8-
def Array.mergeSort (xs : Array Int) : Array Int :=
9-
xs.toList.mergeSort.toArray
10-
117
def median (xs : Array Int) (h : xs ≠ #[]) : Rat :=
128
let sorted := xs.mergeSort
13-
have : 0 < sorted.size := by grind [List.length_mergeSort]
9+
have : 0 < sorted.size := by grind [Array.size_mergeSort]
1410
if xs.size % 2 = 1 then
1511
sorted[sorted.size / 2]
1612
else
@@ -27,14 +23,14 @@ example : median #[8, 1, 3, 9, 9, 2, 7] (by decide) = 7 := by native_decide
2723
/-! ## Verification -/
2824

2925
theorem median_eq_getElem_of_odd {xs : Array Int} {h} (h' : xs.size % 2 = 1) :
30-
median xs h = xs.mergeSort[xs.size / 2]'(by grind [List.length_mergeSort]) := by
31-
grind [median, List.length_mergeSort]
26+
median xs h = xs.mergeSort[xs.size / 2]'(by grind [Array.size_mergeSort]) := by
27+
grind [median, Array.size_mergeSort]
3228

3329
theorem two_mul_median_of_even {xs : Array Int} {h} (h' : xs.size % 2 = 0) :
3430
2 * median xs h =
35-
xs.mergeSort[xs.size / 2 - 1]'(by grind [List.length_mergeSort]) +
36-
xs.mergeSort[xs.size / 2]'(by grind [List.length_mergeSort]) := by
37-
grind [median, List.length_mergeSort]
31+
xs.mergeSort[xs.size / 2 - 1]'(by grind [Array.size_mergeSort]) +
32+
xs.mergeSort[xs.size / 2]'(by grind [Array.size_mergeSort]) := by
33+
grind [median, Array.size_mergeSort]
3834

3935
/-!
4036
### MergeSort properties
@@ -43,10 +39,10 @@ The following two library lemmas show that `Array.mergeSort` correctly sorts an
4339
-/
4440

4541
example {xs : Array Int} : xs.mergeSort.toList.Pairwise (· ≤ ·) := by
46-
grind [List.pairwise_mergeSort]
42+
grind [Array.pairwise_mergeSort]
4743

4844
example {xs : Array Int} : xs.mergeSort.Perm xs := by
49-
grind [List.mergeSort_perm, Array.Perm]
45+
grind [Array.mergeSort_perm, Array.Perm]
5046

5147
/-!
5248
## Prompt

lean-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
leanprover/lean4:nightly-2026-03-05
1+
leanprover/lean4:nightly-2026-03-07

0 commit comments

Comments
 (0)