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

Change behavior of algebraic reals with respect to fractional powers #38564

Draft
wants to merge 9 commits into
base: develop
Choose a base branch
from

Conversation

kwankyu
Copy link
Collaborator

@kwankyu kwankyu commented Aug 26, 2024

We fix two inconsistent behaviors of algebraic reals:

(1)

sage: RR(-1)^(1/3) 
0.500000000000000 + 0.866025403784439*I
sage: CC(-1)^(1/3)
0.500000000000000 + 0.866025403784439*I
sage: QQbar(-1)^(1/3)
0.500000000000000? + 0.866025403784439?*I
sage: AA(-1)^(1/3)                   
-1

See the discussion: https://groups.google.com/g/sage-devel/c/s81ieq2vpVo

(2)

sage: QQbar((-1)^(1/3))
0.500000000000000? + 0.866025403784439?*I
sage: RR((-1)^(1/3))
...
TypeError: unable to convert '0.500000000000000+0.866025403784439*I' to a real number
sage: AA((-1)^(1/3))                
-1

With this PR,

sage: AA(-1)^(1/3)  # principal cube root
0.500000000000000? + 0.866025403784439?*I
sage: AA((-1)^(1/3))
...
ValueError: Cannot coerce algebraic number with nonzero imaginary part to algebraic real

These behavior changes fix #12745, #36735.

On the other hand, the behavior of AA(x).nth_root(n) does not change, and gives an n-th root in AA.

sage: AA(-8).nth_root(3)
-2
sage: AA(8).nth_root(3)
2
sage: AA(sqrt(8)).nth_root(3)
1.414213562373095?
sage: AA(-sqrt(8)).nth_root(3)
-1.414213562373095?

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

github-actions bot commented Aug 26, 2024

Documentation preview for this PR (built with commit 541c338; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@kwankyu kwankyu changed the title Convert symbolic expression in algebraic closure Change behavior of algebraic reals with respect to fractional powers Aug 27, 2024
@dimpase
Copy link
Member

dimpase commented Aug 29, 2024

As I explained in sage-devel, I don't think the behaviour of AA(-1)^(1/3) is incorrect.
Indeed, $1/(2k+1):AA\to AA$ is 1-1 on the whole AA (or, indeed, on the reals).

@kwankyu
Copy link
Collaborator Author

kwankyu commented Aug 29, 2024

The issue is not mathematical correctness. Any cube root of -1 is a mathematically correct answer to AA(-1)^(1/3).

Currently, for a parent P, P(-1)^(1/3) gives the principal root of -1 for all parents P, with a unique exception AA. This inconsistency causes confusion. Fortunately, P(x).nth_root(3) may be used when a cube root in P is expected.

In the same vein, I think it is a "bug" if P(-1).nth_root(n) gives an answer not in P. Currently RR(-1).nth_root(4) correctly raises an exception. But AA(-1).nth_root(4) silently gives the principal root of -1. One may hope to "fix" this. This PR won't.

If you are still not convinced, please put forth your objection in #38362 when that PR is ready to be merged.

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

Successfully merging this pull request may close these issues.

Coercion problem with Algebraic Real Field
2 participants