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

Trivial simplifications for arccos #36069

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

rhinopotamus
Copy link

This fixes a couple of places where arccos doesn't automatically simplify for ratios arising from the unit circle (but arcsin does).

Turns out that in src/sage/symbolic/ginac/inifcns_trig.cpp, asin_eval has some logic handling unit circle cases directly that was not replicated in acos_eval. I copy-pasted the logic from asin_eval and modified appropriately.

Partially fixes #24211.

I'm not sure exactly how to create tests covering this change but would be happy to do so with a little guidance!

📝 Checklist

  • The title is concise, informative, and self-explanatory.
  • 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 accordingly.

⌛ Dependencies

None!

This fixes a couple of places where arccos doesn't automatically simplify for ratios arising from the unit circle (but arcsin does). Turns out that asin_eval has some logic handling unit circle cases directly that was not replicated in acos_eval. I copy-pasted the logic from asin_eval and modified appropriately.

sagemath#24211
@github-actions
Copy link

github-actions bot commented Aug 14, 2023

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

@tscrim
Copy link
Collaborator

tscrim commented Sep 13, 2023

You should be able to add doctests showing the simplifications are occurring in the output. I imagine

sage: arcsin(sqrt(2)/2)
1/4*pi
sage: arccos(sqrt(2)/2)  # is simplified to 1/4*pi with your change
arccos(1/2*sqrt(2))

@fchapoton
Copy link
Contributor

fchapoton commented Oct 28, 2024

one test has to be fixed:

File "src/doc/de/thematische_anleitungen/sage_gymnasium.rst", line 790, in doc.de.thematische_anleitungen.sage_gymnasium
Failed example:
    acos(sqrt(3)/2)
Expected:
    arccos(1/2*sqrt(3))
Got:
    1/6*pi

and the same in src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py

adding one doctest
Copy link
Collaborator

@tscrim tscrim left a comment

Choose a reason for hiding this comment

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

LGTM. Just will wait for a green bot before a positive review.

@tscrim
Copy link
Collaborator

tscrim commented Dec 5, 2024

Trivial failures in

src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py
src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py

@fchapoton
Copy link
Contributor

the failures are not so trivial to fix, and keep their meaning

@fchapoton
Copy link
Contributor

fchapoton commented Feb 4, 2025

From ad4c750bfb1ab05a2bcf06247e1baec44506fb58 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= <[email protected]>
Date: Tue, 4 Feb 2025 21:51:54 +0100
Subject: [PATCH] fixing the doctests

---
 src/doc/de/thematische_anleitungen/sage_gymnasium.rst     | 8 +-------
 src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py | 4 ++--
 .../premierspas_doctest.py                                | 2 +-
 3 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/doc/de/thematische_anleitungen/sage_gymnasium.rst b/src/doc/de/thematische_anleitungen/sage_gymnasium.rst
index 9dc38d8bf0b..dfeb3e13c82 100644
--- a/src/doc/de/thematische_anleitungen/sage_gymnasium.rst
+++ b/src/doc/de/thematische_anleitungen/sage_gymnasium.rst
@@ -774,8 +774,7 @@ falls wir im Bogenmass rechnen möchten. Ansonsten müssen wir wie oben beschrie
 
 Ihre Umkehrfunktionen sind auch mit den nicht sehr überraschenden Namen ``asin()``, ``acos()``, ``atan()`` und ``acot()`` versehen.
 Sie geben uns aber wie oben erklärt nur Winkel im Bogenmass zurück. Möchten wir im Gradmass rechnen, müssen wir wieder
-konvertieren. Die exakte Berechnung der Werte funktioniert in die Gegenrichtung nur, falls im ursprünglichen Wert keine
-Wurzeln vorkommen::
+konvertieren. Exakte Berechnung der Werte funktioniert, wenn es möglich ist::
 
     sage: atan(1)
     1/4*pi
@@ -784,12 +783,7 @@ Wurzeln vorkommen::
     sage: rad2deg(x) = x*(180/pi)
     sage: rad2deg(acos(-1/2))
     120
-
-Falls wir Wurzelterme verwenden, müssen wir mit der Funktion ``simplify_full()`` vereinfachen::
-
     sage: acos(sqrt(3)/2)
-    arccos(1/2*sqrt(3))
-    sage: (acos(sqrt(3)/2)).simplify_full()
     1/6*pi
 
 Sage kann auch weitere Regeln für trigonometrische Funktionen anwenden, um Terme zu vereinfachen. Es kennt zum Beispiel auch die
diff --git a/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py b/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py
index b9488e77b16..52f889f30d1 100644
--- a/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py
+++ b/src/sage/geometry/hyperbolic_space/hyperbolic_geodesic.py
@@ -1854,9 +1854,9 @@ class HyperbolicGeodesicUHP(HyperbolicGeodesic):
             sage: g = HyperbolicPlane().UHP().get_geodesic(1, 1 + I)
             sage: h = HyperbolicPlane().UHP().get_geodesic(-sqrt(2), sqrt(2))
             sage: g.angle(h)
-            arccos(1/2*sqrt(2))
+            1/4*pi
             sage: h.angle(g)
-            arccos(1/2*sqrt(2))
+            1/4*pi
 
         Angle is unoriented, as opposed to oriented. ::
 
diff --git a/src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py b/src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py
index feb5391b4d6..027c31eecfe 100644
--- a/src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py
+++ b/src/sage/tests/books/computational-mathematics-with-sagemath/premierspas_doctest.py
@@ -65,7 +65,7 @@ Sage example in ./premierspas.tex, line 952::
 Sage example in ./premierspas.tex, line 967::
 
   sage: arccos(sin(pi/3))
-  arccos(1/2*sqrt(3))
+  1/6*pi
   sage: sqrt(2)
   sqrt(2)
   sage: exp(I*pi/7)
-- 
2.43.0

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.

Some trivial identities and simplifications missed by Sage (pynac ?)
4 participants