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

Conversation

jessealama
Copy link

r^x for rational r and integer x is just r^x for natural x, or 1/(r^(-x)) for negative integers. To my surprise, I couldn't find this in the mathlib, though I may well have missed something. The only thing available here is a type class; if a lemma or two would be desired, I'd be happy to continue working on this.

Open in Gitpod

r^x for rational r and integer x is just r^x for natural x, or
1/(r^(-x)) for negative integers.
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.

@jessealama
Copy link
Author

Closing this because the functionality I wanted already existed, though was perhaps somewhat opqaue. #19884 is the right solution.

@jessealama jessealama closed this Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants