Skip to content

Commit dd30058

Browse files
author
mathlib4-bot
committed
Merge remote-tracking branch 'upstream/master' into bump/v4.31.0
2 parents ac22942 + 354fc4d commit dd30058

95 files changed

Lines changed: 1889 additions & 1144 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Archive/Wiedijk100Theorems/BirthdayProblem.lean

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ in terms of injective functions. The general result about `Fintype.card (α ↪
1717
uses is `Fintype.card_embedding_eq`.
1818
-/
1919

20-
2120
namespace Theorems100
2221

2322
local notation "|" x "|" => Finset.card x
24-
2523
local notation "‖" x "‖" => Fintype.card x
2624

2725
/-- **Birthday Problem**: set cardinality interpretation. -/
@@ -30,38 +28,23 @@ theorem birthday :
3028
simp only [Fintype.card_fin, Fintype.card_embedding_eq, Fintype.card_fun]
3129
decide
3230

33-
section MeasureTheory
34-
3531
open MeasureTheory ProbabilityTheory
3632

37-
open scoped ProbabilityTheory ENNReal
38-
3933
variable {n m : ℕ}
4034

41-
/- In order for Lean to understand that we can take probabilities in `Fin 23 → Fin 365`, we must
42-
tell Lean that there is a `MeasurableSpace` structure on the space. Note that this instance
43-
is only for `Fin m` - Lean automatically figures out that the function space `Fin n → Fin m`
44-
is _also_ measurable, by using `MeasurableSpace.pi`, and furthermore that all sets are measurable,
45-
from `MeasurableSingletonClass.pi`. -/
46-
instance : MeasurableSpace (Fin m) :=
47-
48-
49-
instance : MeasurableSingletonClass (Fin m) :=
50-
fun _ => trivial⟩
51-
5235
/- We then endow the space with a canonical measure, which is called ℙ.
5336
We define this to be the conditional counting measure. -/
5437
noncomputable instance measureSpace : MeasureSpace (Fin n → Fin m) :=
5538
⟨uniformOn Set.univ⟩
5639

57-
theorem FinFin.measure_apply {s : Set <| Fin n → Fin m} :
40+
theorem Fin.measure_apply {s : Set <| Fin n → Fin m} :
5841
ℙ s = |s.toFinite.toFinset| / ‖Fin n → Fin m‖ := by
5942
rw [volume, measureSpace, uniformOn_univ, Measure.count_apply_finite]
6043

6144
/-- **Birthday Problem**: first probabilistic interpretation. -/
6245
theorem birthday_measure :
63-
ℙ ({f | (Function.Injective f)} : Set ((Fin 23)(Fin 365))) < 1 / 2 := by
64-
rw [FinFin.measure_apply]
46+
ℙ ({f | f.Injective} : Set (Fin 23 → Fin 365)) < 1 / 2 := by
47+
rw [Fin.measure_apply]
6548
generalize_proofs hfin
6649
have : |hfin.toFinset| = 42200819302092359872395663074908957253749760700776448000000 := by
6750
trans ‖Fin 23 ↪ Fin 365
@@ -76,6 +59,4 @@ theorem birthday_measure :
7659
simp only [Fintype.card_pi, Fintype.card_fin, Finset.prod_const, Finset.card_univ]
7760
norm_num
7861

79-
end MeasureTheory
80-
8162
end Theorems100

Mathlib/Algebra/Algebra/Operations.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,10 +570,8 @@ theorem mul_smul_mul_eq_smul_mul_smul (x y : R) : (x * y) • (M * N) = (x • M
570570

571571
/-- Sub-R-modules of an R-algebra form an idempotent semiring. -/
572572
instance idemSemiring : IdemSemiring (Submodule R A) where
573-
__ := instNonUnitalSemiring
574573
one_mul := Submodule.one_mul
575574
mul_one := Submodule.mul_one
576-
bot_le _ := bot_le
577575

578576
instance : IsOrderedRing (Submodule R A) where
579577

@@ -797,7 +795,6 @@ theorem prod_span_singleton {ι : Type*} (s : Finset ι) (x : ι → A) :
797795

798796
variable (R A)
799797

800-
set_option backward.isDefEq.respectTransparency false in
801798
/-- R-submodules of the R-algebra A are a module over `Set A`. -/
802799
noncomputable instance moduleSet : Module (SetSemiring A) (Submodule R A) where
803800
smul s P := span R (SetSemiring.down s) * P

Mathlib/Algebra/Order/Floor/Defs.lean

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ instance : FloorRing ℤ where
170170

171171
/-- A `FloorRing` constructor from the `floor` function alone. -/
172172
@[implicit_reducible]
173-
def FloorRing.ofFloor (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (floor : α → ℤ)
173+
def FloorRing.ofFloor (α) [Ring α] [LinearOrder α] [IsOrderedRing α] (floor : α → ℤ)
174174
(gc_coe_floor : GaloisConnection (↑) floor) : FloorRing α :=
175175
{ floor
176176
ceil := fun a => -floor (-a)
@@ -179,7 +179,7 @@ def FloorRing.ofFloor (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (
179179

180180
/-- A `FloorRing` constructor from the `ceil` function alone. -/
181181
@[implicit_reducible]
182-
def FloorRing.ofCeil (α) [Ring α] [LinearOrder α] [IsStrictOrderedRing α] (ceil : α → ℤ)
182+
def FloorRing.ofCeil (α) [Ring α] [LinearOrder α] [IsOrderedRing α] (ceil : α → ℤ)
183183
(gc_ceil_coe : GaloisConnection ceil (↑)) : FloorRing α :=
184184
{ floor := fun a => -ceil (-a)
185185
ceil
@@ -286,7 +286,7 @@ theorem floor_le (a : α) : (⌊a⌋ : α) ≤ a :=
286286
theorem floor_nonneg : 0 ≤ ⌊a⌋ ↔ 0 ≤ a := by rw [le_floor, Int.cast_zero]
287287

288288
@[bound]
289-
theorem floor_nonpos [IsStrictOrderedRing α] (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by
289+
theorem floor_nonpos [IsOrderedRing α] (ha : a ≤ 0) : ⌊a⌋ ≤ 0 := by
290290
rw [← @cast_le α, Int.cast_zero]
291291
exact (floor_le a).trans ha
292292

@@ -306,7 +306,7 @@ theorem le_ceil (a : α) : a ≤ ⌈a⌉ :=
306306
gc_ceil_coe.le_u_l a
307307

308308
@[bound]
309-
theorem ceil_nonneg [IsStrictOrderedRing α] (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a)
309+
theorem ceil_nonneg [IsOrderedRing α] (ha : 0 ≤ a) : 0 ≤ ⌈a⌉ := mod_cast ha.trans (le_ceil a)
310310

311311
@[simp]
312312
theorem ceil_pos : 0 < ⌈a⌉ ↔ 0 < a := by rw [lt_ceil, cast_zero]
@@ -315,7 +315,7 @@ end Int
315315

316316
section FloorRingToSemiring
317317

318-
variable [Ring α] [LinearOrder α] [IsStrictOrderedRing α] [FloorRing α]
318+
variable [Ring α] [LinearOrder α] [IsOrderedRing α] [FloorRing α]
319319

320320
/-! #### A floor ring as a floor semiring -/
321321

Mathlib/Algebra/Order/Floor/Ring.lean

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ theorem floor_eq_on_Ico' (n : ℤ) : ∀ a ∈ Set.Ico (n : R) (n + 1), (⌊a⌋
158158
theorem preimage_floor_singleton (m : ℤ) : (floor : R → ℤ) ⁻¹' {m} = Ico (m : R) (m + 1) :=
159159
ext fun _ => floor_eq_iff
160160

161-
variable [IsStrictOrderedRing R]
161+
variable [IsOrderedRing R]
162162

163163
@[simp, bound]
164164
theorem sub_one_lt_floor (a : R) : a - 1 < ⌊a⌋ :=
@@ -276,21 +276,16 @@ theorem mul_fract_eq_one_iff_exists_int {x : R} {k : R} (hk : 1 < k) :
276276
rw [floor_eq_iff, ← mul_le_mul_iff_right₀ hk0, ← mul_lt_mul_iff_right₀ hk0, hn]
277277
simp [mul_add, hk]
278278

279-
end LinearOrderedRing
280-
281-
section LinearOrderedCommRing
282-
variable {R : Type*} [CommRing R] [LinearOrder R] [IsStrictOrderedRing R] [FloorRing R] {a : R}
283-
284279
theorem cast_mul_floor_div_cancel_of_pos {n : ℤ} (hn : 0 < n) (a : R) : ⌊n * a⌋ / n = ⌊a⌋ := by
285-
rw [mul_comm, mul_cast_floor_div_cancel_of_pos hn]
280+
rw [Commute.intCast_left, mul_cast_floor_div_cancel_of_pos hn]
286281

287282
theorem natCast_mul_floor_div_cancel {n : ℕ} (hn : n ≠ 0) (a : R) : ⌊n * a⌋ / n = ⌊a⌋ := by
288-
rw [mul_comm, mul_natCast_floor_div_cancel hn]
283+
rw [Nat.cast_comm, mul_natCast_floor_div_cancel hn]
289284

290-
end LinearOrderedCommRing
285+
end LinearOrderedRing
291286

292287
section LinearOrderedField
293-
variable {k : Type*} [Field k] [LinearOrder k] [IsStrictOrderedRing k] [FloorRing k] {a b : k}
288+
variable {k : Type*} [Field k] [LinearOrder k] [IsOrderedRing k] [FloorRing k] {a b : k}
294289

295290
theorem floor_div_cast_of_nonneg {n : ℤ} (hn : 0 ≤ n) (a : k) : ⌊a / n⌋ = ⌊a⌋ / n := by
296291
obtain rfl | hn := hn.eq_or_lt
@@ -332,7 +327,7 @@ theorem fract_sub_self (a : R) : fract a - a = -⌊a⌋ :=
332327
theorem fract_add (a b : R) : ∃ z : ℤ, fract (a + b) - fract a - fract b = z :=
333328
⟨⌊a⌋ + ⌊b⌋ - ⌊a + b⌋, by unfold fract; grind⟩
334329

335-
variable [IsStrictOrderedRing R]
330+
variable [IsOrderedRing R]
336331

337332
@[simp]
338333
theorem fract_add_intCast (a : R) (m : ℤ) : fract (a + m) = fract a := by
@@ -441,8 +436,9 @@ theorem fract_eq_iff {a b : R} : fract a = b ↔ 0 ≤ b ∧ b < 1 ∧ ∃ z :
441436
exact ⟨fract_nonneg _, fract_lt_one _, ⟨⌊a⌋, sub_sub_cancel _ _⟩⟩,
442437
by
443438
rintro ⟨h₀, h₁, z, hz⟩
444-
rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz,
445-
Int.cast_inj, floor_eq_iff, ← hz]
439+
rw [← self_sub_floor, eq_comm, eq_sub_iff_add_eq, add_comm, ← eq_sub_iff_add_eq, hz]
440+
refine congrArg Int.cast ?_
441+
rw [floor_eq_iff, ← hz]
446442
constructor <;> simpa [sub_eq_add_neg, add_assoc] ⟩
447443

448444
theorem fract_eq_fract {a b : R} : fract a = fract b ↔ ∃ z : ℤ, a - b = z :=
@@ -513,13 +509,13 @@ theorem image_fract (s : Set R) : fract '' s = ⋃ m : ℤ, (fun x : R => x - m)
513509

514510
section LinearOrderedField
515511

516-
variable {k : Type*} [Field k] [LinearOrder k] [IsStrictOrderedRing k] [FloorRing k] {b : k}
512+
variable {k : Type*} [Field k] [LinearOrder k] [IsOrderedRing k] [FloorRing k] {b : k}
517513

518514
theorem fract_div_mul_self_mem_Ico (a b : k) (ha : 0 < a) : fract (b / a) * a ∈ Ico 0 a :=
519515
⟨(mul_nonneg_iff_of_pos_right ha).2 (fract_nonneg (b / a)),
520516
(mul_lt_iff_lt_one_left ha).2 (fract_lt_one (b / a))⟩
521517

522-
omit [IsStrictOrderedRing k] in
518+
omit [IsOrderedRing k] in
523519
theorem fract_div_mul_self_add_zsmul_eq (a b : k) (ha : a ≠ 0) :
524520
fract (b / a) * a + ⌊b / a⌋ • a = b := by
525521
rw [zsmul_eq_mul, ← add_mul, fract_add_floor, div_mul_cancel₀ b ha]
@@ -619,7 +615,7 @@ theorem ceil_eq_on_Ioc (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : R) z, ⌈a⌉ = z
619615
theorem preimage_ceil_singleton (m : ℤ) : (ceil : R → ℤ) ⁻¹' {m} = Ioc ((m : R) - 1) m :=
620616
ext fun _ => ceil_eq_iff
621617

622-
variable [IsStrictOrderedRing R]
618+
variable [IsOrderedRing R]
623619

624620
theorem floor_neg : ⌊-a⌋ = -⌈a⌉ :=
625621
eq_of_forall_le_iff fun z => by rw [le_neg, ceil_le, le_floor, Int.cast_neg, le_neg]
@@ -713,8 +709,9 @@ theorem ceil_zero : ⌈(0 : R)⌉ = 0 := by rw [← cast_zero, ceil_intCast]
713709
@[simp]
714710
theorem ceil_one : ⌈(1 : R)⌉ = 1 := by rw [← cast_one, ceil_intCast]
715711

716-
theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : R) z, (⌈a⌉ : R) = z := fun a ha =>
717-
mod_cast ceil_eq_on_Ioc z a ha
712+
omit [IsOrderedRing R] in
713+
theorem ceil_eq_on_Ioc' (z : ℤ) : ∀ a ∈ Set.Ioc (z - 1 : R) z, (⌈a⌉ : R) = z :=
714+
fun a ha => congrArg Int.cast (ceil_eq_on_Ioc z a ha)
718715

719716
lemma ceil_eq_self_iff_mem (a : R) : ⌈a⌉ = a ↔ a ∈ Set.range Int.cast := by
720717
aesop
@@ -729,8 +726,9 @@ theorem floor_lt_ceil_of_lt {a b : R} (h : a < b) : ⌊a⌋ < ⌈b⌉ :=
729726

730727
lemma ceil_eq_floor_add_one_iff_notMem (a : R) : ⌈a⌉ = ⌊a⌋ + 1 ↔ a ∉ Set.range Int.cast := by
731728
refine ⟨fun h ht => ?_, fun h => ?_⟩
732-
· have := ((floor_eq_self_iff_mem _).mpr ht).trans ((ceil_eq_self_iff_mem _).mpr ht).symm
733-
linarith [Int.cast_inj.mp this]
729+
· have h0 := ((floor_eq_self_iff_mem _).mpr ht).trans ((ceil_eq_self_iff_mem _).mpr ht).symm
730+
rw [h, cast_add, cast_one, left_eq_add] at h0
731+
exact one_ne_zero h0
734732
· apply le_antisymm (Int.ceil_le_floor_add_one _)
735733
rw [add_one_le_iff, lt_ceil]
736734
exact lt_of_le_of_ne (Int.floor_le a) ((iff_false_right h).mp (floor_eq_self_iff_mem a))
@@ -742,9 +740,8 @@ theorem fract_eq_zero_or_add_one_sub_ceil (a : R) : fract a = 0 ∨ fract a = a
742740
suffices (⌈a⌉ : R) = ⌊a⌋ + 1 by
743741
rw [this, ← self_sub_fract]
744742
abel
745-
norm_cast
746-
rw [ceil_eq_iff]
747-
refine ⟨?_, _root_.le_of_lt <| by simp⟩
743+
rw [← Int.cast_one, ← Int.cast_add]
744+
refine congrArg Int.cast (ceil_eq_iff.mpr ⟨?_, _root_.le_of_lt <| by simp⟩)
748745
rw [cast_add, cast_one, add_tsub_cancel_right, ← self_sub_fract a, sub_lt_self_iff]
749746
exact ha.symm.lt_of_le (fract_nonneg a)
750747

@@ -759,7 +756,7 @@ theorem ceil_sub_self_eq (ha : fract a ≠ 0) : (⌈a⌉ : R) - a = 1 - fract a
759756
end ceil
760757

761758
section LinearOrderedField
762-
variable {k : Type*} [Field k] [LinearOrder k] [IsStrictOrderedRing k] [FloorRing k] {a b : k}
759+
variable {k : Type*} [Field k] [LinearOrder k] [IsOrderedRing k] [FloorRing k] {a b : k}
763760

764761
lemma mul_lt_floor (hb₀ : 0 < b) (hb : b < 1) (hba : ⌈b / (1 - b)⌉ ≤ a) : b * a < ⌊a⌋ := by
765762
calc
@@ -889,7 +886,7 @@ end Nat
889886

890887
section FloorRingToSemiring
891888

892-
variable [Ring R] [LinearOrder R] [IsStrictOrderedRing R] [FloorRing R]
889+
variable [Ring R] [LinearOrder R] [IsOrderedRing R] [FloorRing R]
893890

894891
/-! #### A floor ring as a floor semiring -/
895892

Mathlib/Algebra/Order/Floor/Semifield.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ theorem floor_div_eq_div (m n : ℕ) : ⌊(m : K) / n⌋₊ = m / n := by
5151
end LinearOrderedSemifield
5252

5353
section LinearOrderedField
54-
variable [Field K] [LinearOrder K] [IsStrictOrderedRing K] [FloorSemiring K] {a b : K}
54+
variable [Field K] [LinearOrder K] [IsOrderedRing K] [FloorSemiring K] {a b : K}
5555

5656
lemma mul_lt_floor (hb₀ : 0 < b) (hb : b < 1) (hba : ⌈b / (1 - b)⌉₊ ≤ a) : b * a < ⌊a⌋₊ := by
5757
calc

Mathlib/Algebra/Order/Floor/Semiring.lean

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,9 @@ theorem mul_cast_floor_div_cancel {n : ℕ} (hn : n ≠ 0) (a : R) : ⌊a * n⌋
157157
rw [le_div_iff_mul_le (zero_lt_of_ne_zero hn), le_floor_iff (mul_nonneg ha (cast_nonneg' n)),
158158
le_floor_iff ha, cast_mul, mul_le_mul_iff_of_pos_right (cast_pos'.mpr (zero_lt_of_ne_zero hn))]
159159

160-
theorem cast_mul_floor_div_cancel {R : Type*} [CommSemiring R] [LinearOrder R]
161-
[IsStrictOrderedRing R] [FloorSemiring R] {n : ℕ} (hn : n ≠ 0) (a : R) :
160+
theorem cast_mul_floor_div_cancel {n : ℕ} (hn : n ≠ 0) (a : R) :
162161
⌊n * a⌋₊ / n = ⌊a⌋₊ := by
163-
rw [mul_comm, mul_cast_floor_div_cancel hn]
162+
rw [Nat.cast_comm, mul_cast_floor_div_cancel hn]
164163

165164
end floor
166165

@@ -207,7 +206,7 @@ theorem ceil_le_floor_add_one (a : R) : ⌈a⌉₊ ≤ ⌊a⌋₊ + 1 := by
207206
exact (lt_floor_add_one a).le
208207

209208
@[simp]
210-
theorem ceil_intCast {R : Type*} [Ring R] [LinearOrder R] [IsStrictOrderedRing R]
209+
theorem ceil_intCast {R : Type*} [Ring R] [LinearOrder R] [IsOrderedRing R]
211210
[FloorSemiring R] (z : ℤ) :
212211
⌈(z : R)⌉₊ = z.toNat :=
213212
eq_of_forall_ge_iff fun a => by

0 commit comments

Comments
 (0)