Skip to content

Commit fd393d1

Browse files
eric-wieserBergschaf
authored andcommitted
feat: add ofScientific lemmas for Complex/RCLike/Quaternion (leanprover-community#39628)
1 parent 8b7f7b6 commit fd393d1

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

Mathlib/Algebra/Quaternion.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,18 @@ instance instRatCast : RatCast ℍ[R] where ratCast q := (q : R)
11731173

11741174
@[norm_cast] lemma coe_ratCast (q : ℚ) : ↑(q : R) = (q : ℍ[R]) := rfl
11751175

1176+
section ofScientific
1177+
open OfScientific (ofScientific)
1178+
variable (m : ℕ) (s : Bool) (e : ℕ)
1179+
1180+
@[norm_cast] lemma coe_ofScientific : ((ofScientific m s e : R) : ℍ[R]) = ofScientific m s e := rfl
1181+
@[simp] lemma re_ofScientific : (ofScientific m s e : ℍ[R]).re = ofScientific m s e := rfl
1182+
@[simp] lemma imI_ofScientific : (ofScientific m s e : ℍ[R]).imI = 0 := rfl
1183+
@[simp] lemma imJ_ofScientific : (ofScientific m s e : ℍ[R]).imJ = 0 := rfl
1184+
@[simp] lemma imK_ofScientific : (ofScientific m s e : ℍ[R]).imK = 0 := rfl
1185+
1186+
end ofScientific
1187+
11761188
variable [LinearOrder R] [IsStrictOrderedRing R] (a b : ℍ[R])
11771189

11781190
@[simps -isSimp]

Mathlib/Analysis/RCLike/Basic.lean

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,20 @@ theorem ratCast_re (q : ℚ) : re (q : K) = q := by rw [← ofReal_ratCast, ofRe
631631
@[simp, rclike_simps, norm_cast]
632632
theorem ratCast_im (q : ℚ) : im (q : K) = 0 := by rw [← ofReal_ratCast, ofReal_im]
633633

634+
open OfScientific (ofScientific)
635+
636+
@[rclike_simps, norm_cast]
637+
theorem ofReal_ofScientific (m : ℕ) (s : Bool) (e : ℕ) :
638+
((ofScientific m s e : ℝ) : K) = ofScientific m s e := ofReal_nnratCast _
639+
640+
@[simp, rclike_simps]
641+
theorem ofScientific_re (m : ℕ) (s : Bool) (e : ℕ) :
642+
re (ofScientific m s e : K) = ofScientific m s e := by rw [← ofReal_ofScientific, ofReal_re]
643+
644+
@[simp, rclike_simps, norm_cast]
645+
theorem ofScientific_im (m : ℕ) (s : Bool) (e : ℕ) :
646+
im (ofScientific m s e : K) = 0 := by rw [← ofReal_ofScientific, ofReal_im]
647+
634648
/-! ### Norm -/
635649

636650
theorem norm_of_nonneg {r : ℝ} (h : 0 ≤ r) : ‖(r : K)‖ = r :=

Mathlib/Data/Complex/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,8 @@ instance instRatCast : RatCast ℂ where ratCast q := ofReal q
347347
@[simp, norm_cast] lemma ofReal_intCast (n : ℤ) : ofReal n = n := rfl
348348
@[simp, norm_cast] lemma ofReal_nnratCast (q : ℚ≥0) : ofReal q = q := rfl
349349
@[simp, norm_cast] lemma ofReal_ratCast (q : ℚ) : ofReal q = q := rfl
350+
@[simp, norm_cast] lemma ofReal_ofScientific (m : ℕ) (s : Bool) (e : ℕ) :
351+
ofReal (OfScientific.ofScientific m s e : ℝ) = OfScientific.ofScientific m s e := rfl
350352

351353
@[simp] lemma re_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).re = ofNat(n) := rfl
352354
@[simp] lemma im_ofNat (n : ℕ) [n.AtLeastTwo] : (ofNat(n) : ℂ).im = 0 := rfl
@@ -358,6 +360,10 @@ instance instRatCast : RatCast ℂ where ratCast q := ofReal q
358360
@[simp, norm_cast] lemma im_nnratCast (q : ℚ≥0) : (q : ℂ).im = 0 := rfl
359361
@[simp, norm_cast] lemma ratCast_re (q : ℚ) : (q : ℂ).re = q := rfl
360362
@[simp, norm_cast] lemma ratCast_im (q : ℚ) : (q : ℂ).im = 0 := rfl
363+
@[simp] lemma re_ofScientific (m : ℕ) (s : Bool) (e : ℕ) :
364+
(OfScientific.ofScientific m s e : ℂ).re = OfScientific.ofScientific m s e := rfl
365+
@[simp] lemma im_ofScientific (m : ℕ) (s : Bool) (e : ℕ) :
366+
(OfScientific.ofScientific m s e : ℂ).im = 0 := rfl
361367

362368

363369
/-! ### Ring structure -/

0 commit comments

Comments
 (0)