Skip to content

feat: a norm_num extension for complex numbers#26975

Open
Whysoserioushah wants to merge 62 commits into
leanprover-community:masterfrom
Whysoserioushah:edison/norm_numI
Open

feat: a norm_num extension for complex numbers#26975
Whysoserioushah wants to merge 62 commits into
leanprover-community:masterfrom
Whysoserioushah:edison/norm_numI

Conversation

@Whysoserioushah

@Whysoserioushah Whysoserioushah commented Jul 10, 2025

Copy link
Copy Markdown
Collaborator

@github-actions github-actions Bot added the t-meta Tactics, attributes or user commands label Jul 10, 2025
@github-actions

github-actions Bot commented Jul 10, 2025

Copy link
Copy Markdown

PR summary 69e27a97b7

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference
Mathlib.Tactic 1
Mathlib.Tactic.NormNum.NormNumI (new file) 1657

Declarations diff

+ Result.eq
+ Result.toBool
+ ResultI
+ ResultI.add
+ ResultI.conj
+ ResultI.eq
+ ResultI.eqTrans
+ ResultI.eqeq
+ ResultI.inv
+ ResultI.mk'
+ ResultI.mul
+ ResultI.neg
+ ResultI.sub
+ eq_of_eq_of_eq
+ evalComplexEq
+ evalIm
+ evalRe
+ im_ofScientific
+ im_pow_zero
+ instance (a : Q(ℂ)) : ToMessageData (ResultI a)
+ ne_of_im_ne
+ ne_of_re_ne
+ nnratCast_im
+ nnratCast_re
+ ofReal_ofScientific
+ of_pow_negSucc
+ of_pow_ofNat
+ pow_bit_false
+ pow_bit_true
+ re_ofScientific
+ re_pow_zero

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to strong technical debt.
No changes to weak technical debt.

@Whysoserioushah
Whysoserioushah requested a review from b-mehta July 10, 2025 17:40
@grunweg grunweg changed the title feat(Mathlib/Tactic/NormNum/NormNumI): a norm_num tactic for complex feat: a norm_num extension for complex numbers Jul 10, 2025
@eric-wieser

Copy link
Copy Markdown
Member

Please add a file that tests all the operations handled here; I assume you already have some tests downstream that you can include here?

@eric-wieser eric-wieser added the awaiting-author A reviewer has asked the author a question or requested changes. label Jul 10, 2025
@Whysoserioushah

Copy link
Copy Markdown
Collaborator Author

where should I put the test file?

@hrmacbeth

Copy link
Copy Markdown
Member

where should I put the test file?

Please make a new file in MathlibTest.

Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Whysoserioushah and others added 2 commits July 11, 2025 02:07
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread MathlibTest/norm_numI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated

@Vierkantor Vierkantor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented exponentiation in the style of the other operations. If you're happy with this, I can do a full review.

Comment thread Mathlib/Analysis/RCLike/Basic.lean Outdated
@Vierkantor Vierkantor added the awaiting-author A reviewer has asked the author a question or requested changes. label Mar 4, 2026
Whysoserioushah and others added 2 commits May 1, 2026 00:55
Co-authored-by: Anne Baanen <Vierkantor@users.noreply.github.com>
@Whysoserioushah

Copy link
Copy Markdown
Collaborator Author

I implemented exponentiation in the style of the other operations. If you're happy with this, I can do a full review.

@eric-wieser Are you happy with this implementation? I think it's okay

@Vierkantor Vierkantor removed the awaiting-author A reviewer has asked the author a question or requested changes. label May 15, 2026
@Vierkantor Vierkantor assigned eric-wieser and unassigned Vierkantor May 15, 2026
| .isNegNNRat dα .., _ | _, .isNegNNRat dα .. => ratArm dα
-- mixing positive rationals and negative naturals means we need to use the full rat handler
| .isNNRat dsα .., .isNegNat .. | .isNegNat .., .isNNRat dsα .. =>
| .isNNRat _ .., .isNegNat _ .. | .isNegNat _ .., .isNNRat _ .. =>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing these names makes the comment below not make any sense any more.

Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment on lines +154 to +163
/-- 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I was writing these two I had the same doubt and I failed to find any, I'd love to be proved wrong!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've replaced both with a call to derive.

Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment thread Mathlib/Tactic/NormNum/NormNumI.lean Outdated
Comment on lines +617 to +622
@[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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#39620, which also adds one more

Comment on lines +25 to +28
-- 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NNRat.cast needs #34805

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-meta Tactics, attributes or user commands

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants