feat: a norm_num extension for complex numbers#26975
Conversation
PR summary 69e27a97b7Import changes for modified filesNo significant changes to the import graph Import changes for all files
|
|
Please add a file that tests all the operations handled here; I assume you already have some tests downstream that you can include here? |
|
where should I put the test file? |
Please make a new file in |
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Vierkantor
left a comment
There was a problem hiding this comment.
I implemented exponentiation in the style of the other operations. If you're happy with this, I can do a full review.
Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
@eric-wieser Are you happy with this implementation? I think it's okay |
| | .isNegNNRat dα .., _ | _, .isNegNNRat dα .. => ratArm dα | ||
| -- mixing positive rationals and negative naturals means we need to use the full rat handler | ||
| | .isNNRat dsα .., .isNegNat rα .. | .isNegNat rα .., .isNNRat dsα .. => | ||
| | .isNNRat _ .., .isNegNat _ .. | .isNegNat _ .., .isNNRat _ .. => |
There was a problem hiding this comment.
Removing these names makes the comment below not make any sense any more.
| /-- Result of `norm_num` running on lift of natural numbers in real -/ | ||
| def NormNum.Resultn (n0 : ℕ) : MetaM (NormNum.Result q(OfNat.ofNat (α := ℝ) $n0)) := do | ||
| have n : Q(ℕ) := .lit (.natVal n0) | ||
| let ⟨_, (pa)⟩ ← NormNum.mkOfNat q(ℝ) q(inferInstance) n | ||
| return NormNum.Result.isNat (α := q(ℝ)) q(inferInstance) n q(NormNum.isNat_ofNat ℝ $pa) | ||
|
|
||
| /-- Result of `norm_num` on scientific expressions in real -/ | ||
| def NormNum.ResultOfScientific (mantissa : ℕ) (exponentSign : Bool) (decimalExponent : ℕ) : | ||
| MetaM (NormNum.Result q(OfScientific.ofScientific (α := ℝ) $mantissa | ||
| $exponentSign $decimalExponent )) := do |
There was a problem hiding this comment.
These two look misnamed; they are not types so should not be TitleCase.
This also looks fishy in general though; is this duplicating the implementation of some norm_num extensions?
There was a problem hiding this comment.
when I was writing these two I had the same doubt and I failed to find any, I'd love to be proved wrong!
There was a problem hiding this comment.
I've replaced both with a call to derive.
| @[simp, rclike_simps] | ||
| theorem nnratCast_re (q : ℚ≥0) : re (q : K) = q := by rw [← ofReal_nnratCast, ofReal_re] | ||
|
|
||
| @[simp, rclike_simps, norm_cast] | ||
| theorem nnratCast_im (q : ℚ≥0) : im (q : K) = 0 := by rw [← ofReal_nnratCast, ofReal_im] | ||
|
|
| -- casts | ||
| example : (Nat.cast 3 : ℂ) = 3 := by norm_num1 | ||
| example : (Int.cast (-2) : ℂ) = -2 := by norm_num1 | ||
| example : (Rat.cast 1.5 : ℂ) = 3 / 2 := by norm_num1 |
co-authored-by : @thefundamentaltheor3m, @hrmacbeth
ofScientificlemmas forComplex/RCLike/Quaternion#39628