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

Commit 0f6b3ca

Browse files
doc(data/complex/basic): docstrings and pp_nodots (#3044)
1 parent 96676a7 commit 0f6b3ca

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/data/complex/basic.lean

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
Copyright (c) 2017 Kevin Buzzard. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Kevin Buzzard, Mario Carneiro
5-
6-
The complex numbers, modelled as R^2 in the obvious way.
75
-/
86
import data.real.basic
97
import deprecated.field
8+
/-!
9+
# The complex numbers
10+
11+
The complex numbers are modelled as ℝ^2 in the obvious way.
12+
-/
1013

14+
/-- Complex numbers consist of two `real`s, a real part `re` and an imaginary part `im`. -/
1115
structure complex : Type :=
1216
(re : ℝ) (im : ℝ)
1317

@@ -51,6 +55,7 @@ instance : has_one ℂ := ⟨(1 : ℝ)⟩
5155
@[simp] lemma one_im : (1 : ℂ).im = 0 := rfl
5256
@[simp, norm_cast] lemma of_real_one : ((1 : ℝ) : ℂ) = 1 := rfl
5357

58+
/-- the imaginary unit -/
5459
def I : ℂ := ⟨0, 1
5560

5661
@[simp] lemma I_re : I.re = 0 := rfl
@@ -90,6 +95,7 @@ ext_iff.2 $ by simp
9095
@[simp] lemma re_add_im (z : ℂ) : (z.re : ℂ) + z.im * I = z :=
9196
ext_iff.2 $ by simp
9297

98+
/-- The complex numbers are equivalent to `ℝ × ℝ` -/
9399
def real_prod_equiv : ℂ ≃ (ℝ × ℝ) :=
94100
{ to_fun := λ z, ⟨z.re, z.im⟩,
95101
inv_fun := λ p, ⟨p.1, p.2⟩,
@@ -100,6 +106,7 @@ def real_prod_equiv : ℂ ≃ (ℝ × ℝ) :=
100106
theorem real_prod_equiv_symm_re (x y : ℝ) : (real_prod_equiv.symm (x, y)).re = x := rfl
101107
theorem real_prod_equiv_symm_im (x y : ℝ) : (real_prod_equiv.symm (x, y)).im = y := rfl
102108

109+
/-- the complex conjugate -/
103110
def conj (z : ℂ) : ℂ := ⟨z.re, -z.im⟩
104111

105112
@[simp] lemma conj_re (z : ℂ) : (conj z).re = z.re := rfl
@@ -141,7 +148,8 @@ lemma eq_conj_iff_real {z : ℂ} : conj z = z ↔ ∃ r : ℝ, z = r :=
141148
lemma eq_conj_iff_re {z : ℂ} : conj z = z ↔ (z.re : ℂ) = z :=
142149
eq_conj_iff_real.trans ⟨by rintro ⟨r, rfl⟩; simp, λ h, ⟨_, h.symm⟩⟩
143150

144-
def norm_sq (z : ℂ) : ℝ := z.re * z.re + z.im * z.im
151+
/-- the norm squared function -/
152+
@[pp_nodot] def norm_sq (z : ℂ) : ℝ := z.re * z.re + z.im * z.im
145153

146154
@[simp] lemma norm_sq_of_real (r : ℝ) : norm_sq r = r * r :=
147155
by simp [norm_sq]
@@ -329,7 +337,8 @@ by rw [← of_real_rat_cast, of_real_re]
329337
@[simp, norm_cast] lemma rat_cast_im (q : ℚ) : (q : ℂ).im = 0 :=
330338
by rw [← of_real_rat_cast, of_real_im]
331339

332-
noncomputable def abs (z : ℂ) : ℝ := (norm_sq z).sqrt
340+
/-- the complex absolute value function, defined as the square root of the norm squared. -/
341+
@[pp_nodot] noncomputable def abs (z : ℂ) : ℝ := (norm_sq z).sqrt
333342

334343
local notation `abs'` := _root_.abs
335344

@@ -439,9 +448,11 @@ theorem is_cau_seq_im (f : cau_seq ℂ abs) : is_cau_seq abs' (λ n, (f n).im) :
439448
λ ε ε0, (f.cauchy ε0).imp $ λ i H j ij,
440449
lt_of_le_of_lt (by simpa using abs_im_le_abs (f j - f i)) (H _ ij)
441450

451+
/-- The real part of a complex Cauchy sequence is a real Cauchy sequence. -/
442452
noncomputable def cau_seq_re (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
443453
⟨_, is_cau_seq_re f⟩
444454

455+
/-- The imaginary part of a complex Cauchy sequence is a real Cauchy sequence. -/
445456
noncomputable def cau_seq_im (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
446457
⟨_, is_cau_seq_im f⟩
447458

@@ -450,6 +461,7 @@ lemma is_cau_seq_abs {f : ℕ → ℂ} (hf : is_cau_seq abs f) :
450461
λ ε ε0, let ⟨i, hi⟩ := hf ε ε0 in
451462
⟨i, λ j hj, lt_of_le_of_lt (abs_abs_sub_le_abs_sub _ _) (hi j hj)⟩
452463

464+
/-- the limit of a Cauchy sequence of complex numbers -/
453465
noncomputable def lim_aux (f : cau_seq ℂ abs) : ℂ :=
454466
⟨cau_seq.lim (cau_seq_re f), cau_seq.lim (cau_seq_im f)⟩
455467

@@ -487,12 +499,15 @@ lemma is_cau_seq_conj (f : cau_seq ℂ abs) : is_cau_seq abs (λ n, conj (f n))
487499
λ ε ε0, let ⟨i, hi⟩ := f.2 ε ε0 in
488500
⟨i, λ j hj, by rw [← conj_sub, abs_conj]; exact hi j hj⟩
489501

490-
noncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs := ⟨_, is_cau_seq_conj f⟩
502+
/-- The complex conjugation of a complex Cauchy sequence is a Cauchy sequence. -/
503+
noncomputable def cau_seq_conj (f : cau_seq ℂ abs) : cau_seq ℂ abs :=
504+
⟨_, is_cau_seq_conj f⟩
491505

492506
lemma lim_conj (f : cau_seq ℂ abs) : lim (cau_seq_conj f) = conj (lim f) :=
493507
complex.ext (by simp [cau_seq_conj, (lim_re _).symm, cau_seq_re])
494508
(by simp [cau_seq_conj, (lim_im _).symm, cau_seq_im, (lim_neg _).symm]; refl)
495509

510+
/-- The absolute value of a complex Cauchy sequence is a real Cauchy sequence. -/
496511
noncomputable def cau_seq_abs (f : cau_seq ℂ abs) : cau_seq ℝ abs' :=
497512
⟨_, is_cau_seq_abs f.2
498513

0 commit comments

Comments
 (0)