Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 94b09d6

Browse files
ChrisHughes24digama0
authored andcommitted
refactor(data/real/basic): make real irreducible (#454)
1 parent c57a9a6 commit 94b09d6

File tree

7 files changed

+57
-39
lines changed

7 files changed

+57
-39
lines changed

analysis/complex.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ tendsto_of_uniform_continuous_subtype
9393
(λ x, id))
9494
(mem_nhds_sets
9595
(is_open_prod
96-
(continuous_abs _ $ is_open_gt' _)
97-
(continuous_abs _ $ is_open_gt' _))
96+
(continuous_abs _ $ is_open_gt' (abs a₁ + 1))
97+
(continuous_abs _ $ is_open_gt' (abs a₂ + 1)))
9898
⟨lt_add_one (abs a₁), lt_add_one (abs a₂)⟩)
9999

100100
local attribute [semireducible] real.le

analysis/limits.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ lemma tendsto_coe_iff {f : ℕ → ℕ} : tendsto (λ n, (f n : ℝ)) at_top at_
139139
(have _, from tendsto_infi.1 h i, by simpa using tendsto_principal.1 this),
140140
λ h, tendsto.comp h tendsto_of_nat_at_top_at_top ⟩
141141

142-
lemma tendsto_pow_at_top_at_top_of_gt_1_nat {k : ℕ} (h : k > 1) : tendsto (λn:ℕ, k ^ n) at_top at_top :=
142+
lemma tendsto_pow_at_top_at_top_of_gt_1_nat {k : ℕ} (h : 1 < k) : tendsto (λn:ℕ, k ^ n) at_top at_top :=
143143
tendsto_coe_iff.1 $
144-
have hr : (k : ℝ) > 1, from show (k : ℝ) > (1 : ℕ), from nat.cast_lt.2 h,
144+
have hr : 1 < (k : ℝ), by rw [← nat.cast_one, nat.cast_lt]; exact h,
145145
by simpa using tendsto_pow_at_top_at_top_of_gt_1 hr
146146

147147
lemma tendsto_inverse_at_top_nhds_0_nat : tendsto (λ n : ℕ, (n : ℝ)⁻¹) at_top (nhds 0) :=

analysis/real.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ tendsto_of_uniform_continuous_subtype
182182
(λ x, id))
183183
(mem_nhds_sets
184184
(is_open_prod
185-
(real.continuous_abs _ $ is_open_gt' _)
186-
(real.continuous_abs _ $ is_open_gt' _))
185+
(real.continuous_abs _ $ is_open_gt' (abs a₁ + 1))
186+
(real.continuous_abs _ $ is_open_gt' (abs a₂ + 1)))
187187
⟨lt_add_one (abs a₁), lt_add_one (abs a₂)⟩)
188188

189189
instance : topological_ring ℝ :=

data/complex/basic.lean

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,24 @@ instance : has_add ℂ := ⟨λ z w, ⟨z.re + w.re, z.im + w.im⟩⟩
5858

5959
@[simp] lemma add_re (z w : ℂ) : (z + w).re = z.re + w.re := rfl
6060
@[simp] lemma add_im (z w : ℂ) : (z + w).im = z.im + w.im := rfl
61-
@[simp] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := rfl
61+
@[simp] lemma of_real_add (r s : ℝ) : ((r + s : ℝ) : ℂ) = r + s := ext_iff.2 $ by simp
6262

63-
@[simp] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r := rfl
64-
@[simp] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r := rfl
63+
@[simp] lemma of_real_bit0 (r : ℝ) : ((bit0 r : ℝ) : ℂ) = bit0 r := ext_iff.2 $ by simp [bit0]
64+
@[simp] lemma of_real_bit1 (r : ℝ) : ((bit1 r : ℝ) : ℂ) = bit1 r := ext_iff.2 $ by simp [bit1]
6565

6666
instance : has_neg ℂ := ⟨λ z, ⟨-z.re, -z.im⟩⟩
6767

6868
@[simp] lemma neg_re (z : ℂ) : (-z).re = -z.re := rfl
6969
@[simp] lemma neg_im (z : ℂ) : (-z).im = -z.im := rfl
70-
@[simp] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := rfl
70+
@[simp] lemma of_real_neg (r : ℝ) : ((-r : ℝ) : ℂ) = -r := ext_iff.2 $ by simp
7171

7272
instance : has_mul ℂ := ⟨λ z w, ⟨z.re * w.re - z.im * w.im, z.re * w.im + z.im * w.re⟩⟩
7373

7474
@[simp] lemma mul_re (z w : ℂ) : (z * w).re = z.re * w.re - z.im * w.im := rfl
7575
@[simp] lemma mul_im (z w : ℂ) : (z * w).im = z.re * w.im + z.im * w.re := rfl
7676
@[simp] lemma of_real_mul (r s : ℝ) : ((r * s : ℝ) : ℂ) = r * s := ext_iff.2 $ by simp
7777

78-
@[simp] lemma I_mul_I : I * I = -1 := rfl
78+
@[simp] lemma I_mul_I : I * I = -1 := ext_iff.2 $ by simp
7979

8080
lemma I_ne_zero : (I : ℂ) ≠ 0 := mt (congr_arg im) zero_ne_one.symm
8181

@@ -90,12 +90,12 @@ def conj (z : ℂ) : ℂ := ⟨z.re, -z.im⟩
9090
@[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl
9191
@[simp] lemma conj_im (z : ℂ) : (conj z).im = -z.im := rfl
9292

93-
@[simp] lemma conj_of_real (r : ℝ) : conj r = r := rfl
93+
@[simp] lemma conj_of_real (r : ℝ) : conj r = r := ext_iff.2 $ by simp [conj]
9494

95-
@[simp] lemma conj_zero : conj 0 = 0 := rfl
96-
@[simp] lemma conj_one : conj 1 = 1 := rfl
97-
@[simp] lemma conj_I : conj I = -I := rfl
98-
@[simp] lemma conj_neg_I : conj (-I) = I := rfl
95+
@[simp] lemma conj_zero : conj 0 = 0 := ext_iff.2 $ by simp [conj]
96+
@[simp] lemma conj_one : conj 1 = 1 := ext_iff.2 $ by simp
97+
@[simp] lemma conj_I : conj I = -I := ext_iff.2 $ by simp
98+
@[simp] lemma conj_neg_I : conj (-I) = I := ext_iff.2 $ by simp
9999

100100
@[simp] lemma conj_add (z w : ℂ) : conj (z + w) = conj z + conj w :=
101101
ext_iff.2 $ by simp
@@ -127,9 +127,9 @@ def norm_sq (z : ℂ) : ℝ := z.re * z.re + z.im * z.im
127127
@[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r :=
128128
by simp [norm_sq]
129129

130-
@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := rfl
131-
@[simp] lemma norm_sq_one : norm_sq 1 = 1 := rfl
132-
@[simp] lemma norm_sq_I : norm_sq I = 1 := rfl
130+
@[simp] lemma norm_sq_zero : norm_sq 0 = 0 := by simp [norm_sq]
131+
@[simp] lemma norm_sq_one : norm_sq 1 = 1 := by simp [norm_sq]
132+
@[simp] lemma norm_sq_I : norm_sq I = 1 := by simp [norm_sq]
133133

134134
lemma norm_sq_nonneg (z : ℂ) : 0 ≤ norm_sq z :=
135135
add_nonneg (mul_self_nonneg _) (mul_self_nonneg _)
@@ -179,7 +179,7 @@ by refine { zero := 0, add := (+), neg := has_neg.neg, one := 1, mul := (*), ..}
179179

180180
@[simp] lemma sub_re (z w : ℂ) : (z - w).re = z.re - w.re := rfl
181181
@[simp] lemma sub_im (z w : ℂ) : (z - w).im = z.im - w.im := rfl
182-
@[simp] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := rfl
182+
@[simp] lemma of_real_sub (r s : ℝ) : ((r - s : ℝ) : ℂ) = r - s := ext_iff.2 $ by simp
183183
@[simp] lemma of_real_pow (r : ℝ) (n : ℕ) : ((r ^ n : ℝ) : ℂ) = r ^ n :=
184184
by induction n; simp [*, of_real_mul, pow_succ]
185185

@@ -228,7 +228,9 @@ noncomputable instance : discrete_field ℂ :=
228228
by rw [division_def, of_real_mul, division_def, of_real_inv]
229229

230230
@[simp] theorem of_real_int_cast : ∀ n : ℤ, ((n : ℝ) : ℂ) = n :=
231-
int.eq_cast (λ n, ((n : ℝ) : ℂ)) rfl (by simp)
231+
int.eq_cast (λ n, ((n : ℝ) : ℂ))
232+
(by rw [int.cast_one, of_real_one])
233+
(λ _ _, by rw [int.cast_add, of_real_add])
232234

233235
@[simp] theorem of_real_nat_cast (n : ℕ) : ((n : ℝ) : ℂ) = n :=
234236
by rw [← int.cast_coe_nat, of_real_int_cast]; refl

data/complex/exponential.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,7 @@ lemma abs_exp_sub_one_le {x : ℂ} (hx : abs x ≤ 1) :
907907
abs (exp x - 1) ≤ 2 * abs x :=
908908
calc abs (exp x - 1) = abs (exp x - (range 1).sum (λ m, x ^ m / m.fact)) :
909909
by simp [sum_range_succ]
910-
... ≤ abs x ^ 1 * ((nat.succ 1) * (nat.fact 1 * 1)⁻¹) :
910+
... ≤ abs x ^ 1 * ((nat.succ 1) * (nat.fact 1 * (1 : ℕ))⁻¹) :
911911
exp_bound hx dec_trivial
912912
... = 2 * abs x : by simp [two_mul, mul_two, mul_add, mul_comm]
913913

data/padics/hensel.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ lt_of_le_of_lt (norm_nonneg _) hnorm
7878
private lemma deriv_sq_norm_ne_zero : ∥F.derivative.eval a∥^20 := ne_of_gt deriv_sq_norm_pos
7979

8080
private lemma deriv_norm_ne_zero : ∥F.derivative.eval a∥ ≠ 0 :=
81-
λ h, deriv_sq_norm_ne_zero (by simp *; refl)
81+
λ h, deriv_sq_norm_ne_zero (by simp [*, _root_.pow_two])
8282

8383
private lemma deriv_norm_pos : 0 < ∥F.derivative.eval a∥ :=
8484
lt_of_le_of_ne (norm_nonneg _) (ne.symm deriv_norm_ne_zero)

data/real/basic.lean

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ import order.conditionally_complete_lattice data.real.cau_seq_completion
1111

1212
def real := @cau_seq.completion.Cauchy ℚ _ _ _ abs _
1313
notation `ℝ` := real
14-
local attribute [reducible] real
1514

1615
namespace real
1716
open cau_seq cau_seq.completion
1817

1918
def of_rat (x : ℚ) : ℝ := of_rat x
2019

21-
instance : comm_ring ℝ := cau_seq.completion.comm_ring
20+
def mk (x : cau_seq ℚ abs) : ℝ := cau_seq.completion.mk x
21+
22+
def comm_ring_aux : comm_ring ℝ := cau_seq.completion.comm_ring
23+
24+
instance : comm_ring ℝ := { ..comm_ring_aux }
2225

2326
/- Extra instances to short-circuit type class resolution -/
2427
instance : ring ℝ := by apply_instance
@@ -49,6 +52,12 @@ instance : has_lt ℝ :=
4952

5053
@[simp] theorem mk_lt {f g : cau_seq ℚ abs} : mk f < mk g ↔ f < g := iff.rfl
5154

55+
theorem mk_eq {f g : cau_seq ℚ abs} : mk f = mk g ↔ f ≈ g := mk_eq
56+
57+
theorem quotient_mk_eq_mk (f : cau_seq ℚ abs) : ⟦f⟧ = mk f := rfl
58+
59+
theorem mk_eq_mk {f : cau_seq ℚ abs} : cau_seq.completion.mk f = mk f := rfl
60+
5261
@[simp] theorem mk_pos {f : cau_seq ℚ abs} : 0 < mk f ↔ pos f :=
5362
iff_of_eq (congr_arg pos (sub_zero f))
5463

@@ -66,13 +75,13 @@ instance : linear_order ℝ :=
6675
{ le := (≤), lt := (<),
6776
le_refl := λ a, or.inr rfl,
6877
le_trans := λ a b c, quotient.induction_on₃ a b c $
69-
λ f g h, by simpa using le_trans,
78+
λ f g h, by simpa [quotient_mk_eq_mk] using le_trans,
7079
lt_iff_le_not_le := λ a b, quotient.induction_on₂ a b $
71-
λ f g, by simpa using lt_iff_le_not_le,
80+
λ f g, by simpa [quotient_mk_eq_mk] using lt_iff_le_not_le,
7281
le_antisymm := λ a b, quotient.induction_on₂ a b $
73-
λ f g, by simpa [mk_eq] using @cau_seq.le_antisymm _ _ f g,
82+
λ f g, by simpa [mk_eq, quotient_mk_eq_mk] using @cau_seq.le_antisymm _ _ f g,
7483
le_total := λ a b, quotient.induction_on₂ a b $
75-
λ f g, by simpa using le_total f g }
84+
λ f g, by simpa [quotient_mk_eq_mk] using le_total f g }
7685

7786
instance : partial_order ℝ := by apply_instance
7887
instance : preorder ℝ := by apply_instance
@@ -82,7 +91,9 @@ theorem of_rat_lt {x y : ℚ} : of_rat x < of_rat y ↔ x < y := const_lt
8291
protected theorem zero_lt_one : (0 : ℝ) < 1 := of_rat_lt.2 zero_lt_one
8392

8493
protected theorem mul_pos {a b : ℝ} : 0 < a → 0 < b → 0 < a * b :=
85-
quotient.induction_on₂ a b $ λ f g, by simpa using cau_seq.mul_pos
94+
quotient.induction_on₂ a b $ λ f g,
95+
show pos (f - 0) → pos (g - 0) → pos (f * g - 0),
96+
by simpa using cau_seq.mul_pos
8697

8798
instance : linear_ordered_comm_ring ℝ :=
8899
{ add_le_add_left := λ a b h c,
@@ -112,19 +123,18 @@ instance : domain ℝ := by apply_instance
112123
local attribute [instance] classical.prop_decidable
113124

114125
noncomputable instance : discrete_linear_ordered_field ℝ :=
115-
{ inv := has_inv.inv,
116-
inv_mul_cancel := @cau_seq.completion.inv_mul_cancel _ _ _ _ _ _,
117-
mul_inv_cancel := λ x x0, by rw [mul_comm, cau_seq.completion.inv_mul_cancel x0],
118-
inv_zero := inv_zero,
119-
decidable_le := by apply_instance,
120-
..real.linear_ordered_comm_ring }
126+
{ decidable_le := by apply_instance,
127+
..real.linear_ordered_comm_ring,
128+
..real.domain,
129+
..cau_seq.completion.discrete_field }
121130

122131
/- Extra instances to short-circuit type class resolution -/
132+
123133
noncomputable instance : linear_ordered_field ℝ := by apply_instance
124134
noncomputable instance : decidable_linear_ordered_comm_ring ℝ := by apply_instance
125135
noncomputable instance : decidable_linear_ordered_semiring ℝ := by apply_instance
126136
noncomputable instance : decidable_linear_ordered_comm_group ℝ := by apply_instance
127-
noncomputable instance real.discrete_field : discrete_field ℝ := by apply_instance
137+
noncomputable instance discrete_field : discrete_field ℝ := by apply_instance
128138
noncomputable instance : field ℝ := by apply_instance
129139
noncomputable instance : division_ring ℝ := by apply_instance
130140
noncomputable instance : integral_domain ℝ := by apply_instance
@@ -159,7 +169,7 @@ end
159169

160170
theorem mk_le_of_forall_le {f : cau_seq ℚ abs} {x : ℝ} :
161171
(∃ i, ∀ j ≥ i, (f j : ℝ) ≤ x) → mk f ≤ x
162-
| ⟨i, H⟩ := by rw [← neg_le_neg_iff, mk_neg]; exact
172+
| ⟨i, H⟩ := by rw [← neg_le_neg_iff, ← mk_eq_mk, mk_neg]; exact
163173
le_mk_of_forall_le ⟨i, λ j ij, by simp [H _ ij]⟩
164174

165175
theorem mk_near_of_forall_near {f : cau_seq ℚ abs} {x : ℝ} {ε : ℝ}
@@ -176,6 +186,12 @@ let ⟨M, M0, H⟩ := f.bounded' 0 in
176186
⟨M, mk_le_of_forall_le ⟨0, λ i _,
177187
rat.cast_le.2 $ le_of_lt (abs_lt.1 (H i)).2⟩⟩
178188

189+
/- mark `real` irreducible in order to prevent `auto_cases` unfolding reals,
190+
since users rarely want to consider real numbers as Cauchy sequences.
191+
Marking `comm_ring_aux` `irreducible` is done to ensure that there are no problems
192+
with non definitionally equal instances, caused by making `real` irreducible-/
193+
attribute [irreducible] real comm_ring_aux
194+
179195
noncomputable instance : floor_ring ℝ := archimedean.floor_ring _
180196

181197
theorem is_cau_seq_iff_lift {f : ℕ → ℚ} : is_cau_seq abs f ↔ is_cau_seq abs (λ i, (f i : ℝ)) :=
@@ -188,7 +204,7 @@ theorem is_cau_seq_iff_lift {f : ℕ → ℚ} : is_cau_seq abs f ↔ is_cau_seq
188204

189205
theorem of_near (f : ℕ → ℚ) (x : ℝ)
190206
(h : ∀ ε > 0, ∃ i, ∀ j ≥ i, abs ((f j : ℝ) - x) < ε) :
191-
∃ h', cau_seq.completion.mk ⟨f, h'⟩ = x :=
207+
∃ h', real.mk ⟨f, h'⟩ = x :=
192208
⟨is_cau_seq_iff_lift.2 (of_near _ (const abs x) h),
193209
sub_eq_zero.1 $ abs_eq_zero.1 $
194210
eq_of_le_of_forall_le_of_dense (abs_nonneg _) $ λ ε ε0,

0 commit comments

Comments
 (0)