Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exponentiation of rational numbers to integer powers #19883

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Mathlib/Data/Rat/Defs.lean
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,14 @@ instance instPowNat : Pow ℚ ℕ where
pow q n := ⟨q.num ^ n, q.den ^ n, by simp [Nat.pow_eq_zero], by
rw [Int.natAbs_pow]; exact q.reduced.pow _ _⟩

def pow_int_exponent (q : ℚ) (n : ℤ) : ℚ :=
if n ≥ 0
then q ^ (Int.toNat n)
else q ^ (Int.toNat (-n))
Copy link
Member

Choose a reason for hiding this comment

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

Didn't you mean to add a 1/ here?

Either way, your instPowInt instance below already exists in mathlib; you can find it with

import Mathlib
#synth Pow ℚ ℤ

Copy link
Member

Choose a reason for hiding this comment

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

(the name of the instance that it finds is bad though; fixed in #19884)

Copy link
Author

Choose a reason for hiding this comment

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

Didn't you mean to add a 1/ here?

Either way, your instPowInt instance below already exists in mathlib; you can find it with

import Mathlib
#synth Pow ℚ ℤ

Ack, yes, that's what I meant, of course. Curious that I wasn't able to find that instance. I think your PR is the right way to do it, so I'm happy to close this PR.


instance instPowInt : Pow ℚ ℤ where
pow q n := pow_int_exponent q n

lemma pow_def (q : ℚ) (n : ℕ) :
q ^ n = ⟨q.num ^ n, q.den ^ n,
by simp [Nat.pow_eq_zero],
Expand Down