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
is_power
and is_prime_power_with_data
are inconsistent
#2352
Comments
On Sat, May 06, 2023 at 10:19:54AM -0700, Lars Göttgens wrote:
I would expect both methods to return _basically_ the same (up to the boolean flag). However, the order of base and exponent is different.
`is_power(::IntegerUnion)` gives first the exponent and then the base.
```julia
help?> is_power
is_power(a::ZZRingElem) -> Int, ZZRingElem
is_power(a::Integer) -> Int, Integer
Returns e, r such that a = r^e with e maximal. Note: 1 = 1^0.
```
On the other hand, `is_prime_power_with_data(::IntegerUnion)` gives after the boolean flag first the base and then the exponent.
```julia
help?> is_prime_power_with_data
search: is_prime_power_with_data
is_prime_power_with_data(q::IntegerUnion) -> Bool, ZZRingElem, Int
Returns a flag indicating whether q is a prime power and integers p, e such that q = p^e. If q is a prime power, than p
is a prime.
```
Finally, for `is_power(::QQFieldElem)`, the docstring specifies no behavior at all (although it again is exponent, base).
```julia
is_power(a::QQFieldElem) -> Int, QQFieldElem
is_power(a::Rational) -> Int, Rational
Writes a = r^e with e maximal. Note: 1 = 1^0.
```
I would propose adding the order into the docstring of `is_power(::QQFieldElem)`.
Furthermore, I think it would be less confusing to make these two functions consistent in their return semantics.
Well spotted - there is actually a 3rd point to consider... in
Oscar/example/PerfectPowers.jl
is a far superior implementation for large integers...
Do you happen to have any idea what the order is for is_power for ideals
and/or polynomials? I assume the is_prime_power_with_data is the black
sheep.
--
Reply to this email directly or view it on GitHub:
#2352
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***>
|
I guess, there is none... julia> R, x = polynomial_ring(QQ, "x")
(Univariate Polynomial Ring in x over Rational Field, x)
julia> is_power(x^3)
ERROR: MethodError: no method matching is_power(::QQPolyRingElem) |
Are there use cases for |
On Fri, May 12, 2023 at 03:02:26AM -0700, JohnAAbbott wrote:
Are there use cases for `is_power` (or similar) for polynomials or ideals?
Generic code that works over a range of (euclidean) rings.
For ideals there is a specific application
Related functions are "squarefree factorization" for polynomials (and maybe also polynomial decomposition), and radical for ideals.
Yep
I agree that the return order should be consistent! My instinct prefers returning the base first, and the exponent second. I'm not sure why `is_prime_power_with_data` returns a boolean as well as base, exponent -- that seems superfluous to me (_e.g._ set base to 0 to indicate not prime?)
because it is a "is_..." function hence return a boolean first.
The order of the other values is just wrong - I did not check when I
wrote it.
CoCoA has a function `StarRoot` which computes the `r` from `is_power`; given `n` and `r` it should be easy to compute `e` (right?) _Any suggestions for a better fn name are welcome_
it is called valuation(n, r) or, slight variation, remove
… Just for self-inconsistency: I prefer that functions whose name is `is_XYZ` return a boolean (as primary return value). I think that may be why I named the CoCoA function `StarRoot` rather than `IsPower`.
--
Reply to this email directly or view it on GitHub:
#2352 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
|
@fieker do you have a preference for the order of the return values? Base first or exponent first? |
On Sun, May 28, 2023 at 08:31:52AM -0700, Tommy Hofmann wrote:
@fieker do you have a preference for the order of the return values? Base first or exponent first?
No preference
… --
Reply to this email directly or view it on GitHub:
#2352 (comment)
You are receiving this because you were mentioned.
Message ID: ***@***.***>
|
I would expect both methods to return basically the same (up to the boolean flag). However, the order of base and exponent is different.
is_power(::IntegerUnion)
gives first the exponent and then the base.On the other hand,
is_prime_power_with_data(::IntegerUnion)
gives after the boolean flag first the base and then the exponent.Finally, for
is_power(::QQFieldElem)
, the docstring specifies no behavior at all (although it again is exponent, base).I would propose adding the order into the docstring of
is_power(::QQFieldElem)
.Furthermore, I think it would be less confusing to make these two functions consistent in their return semantics.
The text was updated successfully, but these errors were encountered: