File tree Expand file tree Collapse file tree 5 files changed +10
-29
lines changed
Expand file tree Collapse file tree 5 files changed +10
-29
lines changed Original file line number Diff line number Diff line change 33public import Std
44
55public def isExchangePossible (xs ys : Array Int) : String :=
6- let need := xs.iter.filter (· % 2 == 1 ) |>.count
7- let available := ys.iter.filter (· % 2 == 0 ) |>.count
6+ let need := xs.iter.filter (· % 2 == 1 ) |>.length
7+ let available := ys.iter.filter (· % 2 == 0 ) |>.length
88 if need ≤ available then "YES" else "NO"
99
1010/-!
@@ -134,7 +134,7 @@ public theorem isExchangePossible_correct {xs ys : Array Int} :
134134 generalize h : VectorPair.mk xs.toVector ys.toVector = p
135135 simp only [show xs = p.1 .toArray by grind, show ys = p.2 .toArray by grind]
136136 -- prove the actual statement
137- simp [isExchangePossible, ← Std.Iter.length_toList_eq_count ,
137+ simp [isExchangePossible, ← Std.Iter.length_toList_eq_length ,
138138 ← List.countP_eq_length_filter, VectorPair.countP_le_countP_iff_exists]
139139
140140/-!
Original file line number Diff line number Diff line change @@ -141,7 +141,7 @@ theorem isMinSubarraySum₀_append_singleton_eq {xs : List Int} {x minSum minSuf
141141 · grind
142142 · simp only [heq, List.toList_mkSlice_rco, List.take_length]
143143 have := h₂.2 i (by grind)
144- grind [List.drop_append_of_le_length]
144+ grind
145145 · have := h₁.2 i j (by grind) (by grind)
146146 grind [List.take_append_of_le_length]
147147
@@ -163,16 +163,16 @@ theorem isMinSuffixSum₀_append_singleton_eq {xs : List Int} {x minSuff : Int}
163163 by_cases hieq : i = (xs ++ [x]).length
164164 · grind
165165 · simp only [IsMinSuffixSum₀] at h
166- grind [List.drop_append_of_le_length]
166+ grind
167167 · rw [show min 0 (minSuff + x) = minSuff + x by grind]
168168 apply And.intro
169169 · simp only [IsMinSuffixSum₀] at h
170- grind [List.drop_append_of_le_length]
170+ grind
171171 · intro i hi
172172 by_cases hieq : i = (xs ++ [x]).length
173173 · grind
174174 · simp only [IsMinSuffixSum₀] at h
175- grind [List.drop_append_of_le_length]
175+ grind
176176
177177theorem List.zero_le_min_of_zero_le_sum {xs : List Int} (hne : xs ≠ []) (h : xs.sum ≤ 0 ) :
178178 xs.min hne ≤ 0 := by
Original file line number Diff line number Diff line change @@ -44,25 +44,6 @@ actions needed.
4444
4545attribute [grind =] Vector.sum_mk List.zip_cons_cons List.zip_nil_right List.zip_nil_left
4646
47- -- this is in Mathlib
48- theorem Nat.div_add_div_le_add_div (a b c : Nat) : a / c + b / c ≤ (a + b) / c := by
49- by_cases h : 0 < c
50- · rw [← (Nat.mul_le_mul_right_iff (show 0 < c by grind)), Nat.add_mul]
51- simp only [Nat.div_mul_self_eq_mod_sub_self]
52- have (a b c d : Nat) (h : b ≤ a) (h' : d ≤ c) : (a - b) + (c - d) = (a + c) - (b + d) := by grind
53- rw [this, Nat.sub_le_sub_iff_left]
54- · rw [Nat.add_mod]
55- apply Nat.mod_le
56- · apply Nat.mod_le
57- · apply Nat.mod_le
58- · apply Nat.mod_le
59- · grind
60-
61- theorem Nat.le_mul_iff_le_left (hc : 0 < z) :
62- x ≤ y * z ↔ (x + z - 1 ) / z ≤ y := by
63- rw [Nat.div_le_iff_le_mul hc]
64- omega
65-
6647@ [simp, grind =]
6748theorem Vector.sum_toList {xs : Vector Nat α} :
6849 xs.toList.sum = xs.sum := by
Original file line number Diff line number Diff line change @@ -460,11 +460,11 @@ example : oddCollatz₂ 1 = [1] := by native_decide
460460We'll verify `oddCollatz₂` by proving it equivalent to `oddCollatz₁`.
461461-/
462462
463- theorem oddCollatz₂_pairwise_distinct {n : Nat} (h : Acc CollatzRel n) :
463+ theorem oddCollatz₂_pairwise_distinct {n : Nat} :
464464 (oddCollatz₂ n).Pairwise (· ≠ ·) := by
465465 simpa [oddCollatz₂] using TreeSet.distinct_toList (α := Nat) (cmp := compare)
466466
467- theorem oddCollatz₂_pairwise_lt {n : Nat} (h : Acc CollatzRel n) :
467+ theorem oddCollatz₂_pairwise_lt {n : Nat} :
468468 (oddCollatz₂ n).Pairwise (· < ·) := by
469469 simpa [oddCollatz₁, compare_eq_lt] using TreeSet.ordered_toList (α := Nat) (cmp := compare)
470470
Original file line number Diff line number Diff line change 1- leanprover/lean4:nightly-2026-01-28
1+ leanprover/lean4:nightly-2026-02-01
You can’t perform that action at this time.
0 commit comments