From 596292bda2ec8026d6e9d210d9b233d247ef53de Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Fri, 13 Sep 2024 17:55:53 -0400 Subject: [PATCH 1/8] src/sage/features/giac.py: add new feature for the giac program In preparation for adding a --disable-giac option, we add a new feature that detects the presence of the "giac" executable. We already have a feature for sage.libs.giac, but that only guards the libgiac interface; we still have code that runs "giac" behind pexpect. This will allow us to skip those tests when giac is not installed. --- src/sage/features/giac.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/sage/features/giac.py diff --git a/src/sage/features/giac.py b/src/sage/features/giac.py new file mode 100644 index 00000000000..6f9fe2ccfba --- /dev/null +++ b/src/sage/features/giac.py @@ -0,0 +1,30 @@ +# sage_setup: distribution = sagemath-environment +r""" +Feature for testing the presence of ``giac`` +""" + +from . import Executable, FeatureTestResult + +class Giac(Executable): + r""" + A :class:`~sage.features.Feature` describing the presence of :ref:`giac `. + + EXAMPLES:: + + sage: from sage.features.giac import Giac + sage: Giac().is_present() # needs giac + FeatureTestResult('giac', True) + """ + def __init__(self): + r""" + TESTS:: + + sage: from sage.features.giac import Giac + sage: isinstance(Giac(), Giac) + True + """ + Executable.__init__(self, 'giac', executable='giac', + spkg='giac', type='standard') + +def all_features(): + return [Giac()] From 1e13c94267c9000859c1706b61a0cdabbb5a1340 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 15 Sep 2024 16:51:07 -0400 Subject: [PATCH 2/8] src/sage/calculus/calculus.py: add "abs tol" to a numeric integral test Various implementations get it a little (1e-10) different. --- src/sage/calculus/calculus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/calculus/calculus.py b/src/sage/calculus/calculus.py index 6d765144e23..65a075a2e1f 100644 --- a/src/sage/calculus/calculus.py +++ b/src/sage/calculus/calculus.py @@ -407,7 +407,7 @@ 0.6321205588285577 sage: result = integral(exp(-300.0/(-0.064*x+14.0)),x,0.0,120.0) ... - sage: result + sage: result # abs tol 1e-10 4.62770039817000e-9 To check that :issue:`27092` is fixed:: From d065fc4deab3c8cf646835c5afe85ab307e22025 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 15 Sep 2024 17:36:23 -0400 Subject: [PATCH 3/8] src/sage/symbolic/integration/integral.py: accept both giac/sympy answers We have an integration test in this file that is looking for the giac result, but sympy gives an equivalent one. We should accept that, too. --- src/sage/symbolic/integration/integral.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/sage/symbolic/integration/integral.py b/src/sage/symbolic/integration/integral.py index 70bb877e5a1..5c7e5db192f 100644 --- a/src/sage/symbolic/integration/integral.py +++ b/src/sage/symbolic/integration/integral.py @@ -71,12 +71,13 @@ def __init__(self): sage: (f*f).integrate(x, algorithm='mathematica_free') # optional -- internet -b*log(e^(a/b) + e^(x/b)) + x + b/(e^(-(a - x)/b) + 1) - Check for :issue:`25119`:: + After :issue:`25119` we can integrate the following function, + although giac and sympy give different-looking answers:: sage: result = integrate(sqrt(x^2)/x,x) ... - sage: result - x*sgn(x) + sage: result in [x*sgn(x), sqrt(x^2)] + True """ # The automatic evaluation routine will try these integrators # in the given order. This is an attribute of the class instead of From 5e8e41c937a0ccb3b77dd9fef9edcef45e31b1c5 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 16 Sep 2024 08:14:32 -0400 Subject: [PATCH 4/8] src/sage/functions/piecewise.py: switch one test from giac to sympy There's one piecewise test that uses algorithm='giac', but it will soon be possible to install sage without giac. We could make the test conditional on giac's presence, but the same thing works with sympy, so let's just use that. --- src/sage/functions/piecewise.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/sage/functions/piecewise.py b/src/sage/functions/piecewise.py index 8a8cbcb62b2..469ce0fbef5 100644 --- a/src/sage/functions/piecewise.py +++ b/src/sage/functions/piecewise.py @@ -828,9 +828,9 @@ def integral(self, parameters, variable, x=None, a=None, b=None, definite=False, Check that the algorithm keyword can be used:: sage: ex = piecewise([([0, 1], 1), ((1, oo), 1/x**2)]) - sage: integral(ex, x, 0, 100, algorithm='giac') + sage: integral(ex, x, 0, 100, algorithm='sympy') 199/100 - sage: integral(ex, x, algorithm='giac') + sage: integral(ex, x, algorithm='sympy') piecewise(x|-->x on [0, 1], x|-->-1/x + 2 on (1, +oo); x) """ if a is not None and b is not None: From 1a846b625aea56ff1b77a43aa248311a0ad3025a Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Wed, 25 Sep 2024 18:27:54 +0100 Subject: [PATCH 5/8] downgrade giac to optional --- build/pkgs/giac/type | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/pkgs/giac/type b/build/pkgs/giac/type index a6a7b9cd726..134d9bc32d5 100644 --- a/build/pkgs/giac/type +++ b/build/pkgs/giac/type @@ -1 +1 @@ -standard +optional From 9cc97cc46fea86dd693c67f8672daaa931a82c9b Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Wed, 25 Sep 2024 22:03:51 +0100 Subject: [PATCH 6/8] make giac doctesting/feature optional --- src/sage/features/giac.py | 2 +- src/sage/interfaces/giac.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/sage/features/giac.py b/src/sage/features/giac.py index 6f9fe2ccfba..5a7833c1d20 100644 --- a/src/sage/features/giac.py +++ b/src/sage/features/giac.py @@ -24,7 +24,7 @@ def __init__(self): True """ Executable.__init__(self, 'giac', executable='giac', - spkg='giac', type='standard') + spkg='giac', type='optional') def all_features(): return [Giac()] diff --git a/src/sage/interfaces/giac.py b/src/sage/interfaces/giac.py index 00c9ff429c3..10d0dadf177 100644 --- a/src/sage/interfaces/giac.py +++ b/src/sage/interfaces/giac.py @@ -1,3 +1,4 @@ +# sage.doctest: optional - giac r""" Pexpect Interface to Giac From 773d3a9fea8b9eb5188c49c74c545fa23ec8ee84 Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Wed, 25 Sep 2024 22:35:27 +0100 Subject: [PATCH 7/8] use variable SAGE_GIAC_ENABLED to control giac feature --- build/pkgs/giac/spkg-configure.m4 | 1 + pkgs/sage-conf/_sage_conf/_conf.py.in | 2 ++ src/sage/env.py | 1 + src/sage/features/giac.py | 7 ++++++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build/pkgs/giac/spkg-configure.m4 b/build/pkgs/giac/spkg-configure.m4 index 53e3a8301cd..0c22692a1a1 100644 --- a/build/pkgs/giac/spkg-configure.m4 +++ b/build/pkgs/giac/spkg-configure.m4 @@ -22,6 +22,7 @@ SAGE_SPKG_CONFIGURE([giac], [ AC_SEARCH_LIBS([ConvertUTF16toUTF8], [giac], [ ], [sage_spkg_install_giac=yes]) ], [sage_spkg_install_giac=yes]) + AC_SUBST(SAGE_ENABLE_giac) m4_popdef([GIAC_MIN_VERSION]) m4_popdef([GIAC_MAX_VERSION]) ]) diff --git a/pkgs/sage-conf/_sage_conf/_conf.py.in b/pkgs/sage-conf/_sage_conf/_conf.py.in index 54a59fdbacf..c14dc14c197 100644 --- a/pkgs/sage-conf/_sage_conf/_conf.py.in +++ b/pkgs/sage-conf/_sage_conf/_conf.py.in @@ -34,6 +34,8 @@ SAGE_NAUTY_BINS_PREFIX = "@SAGE_NAUTY_BINS_PREFIX@" SAGE_ECMBIN = "@SAGE_ECMBIN@" +SAGE_GIAC_ENABLED = "@SAGE_ENABLE_giac@" + # Names or paths of the 4ti2 executables FOURTITWO_HILBERT = "@FOURTITWO_HILBERT@" FOURTITWO_MARKOV = "@FOURTITWO_MARKOV@" diff --git a/src/sage/env.py b/src/sage/env.py index 3548c65f43e..88edba6d5d4 100644 --- a/src/sage/env.py +++ b/src/sage/env.py @@ -224,6 +224,7 @@ def var(key: str, *fallbacks: Optional[str], force: bool = False) -> Optional[st KENZO_FAS = var("KENZO_FAS") SAGE_NAUTY_BINS_PREFIX = var("SAGE_NAUTY_BINS_PREFIX", "") SAGE_ECMBIN = var("SAGE_ECMBIN", "ecm") +SAGE_GIAC_ENABLED = var("SAGE_GIAC_ENABLED", "yes") RUBIKS_BINS_PREFIX = var("RUBIKS_BINS_PREFIX", "") FOURTITWO_HILBERT = var("FOURTITWO_HILBERT") FOURTITWO_MARKOV = var("FOURTITWO_MARKOV") diff --git a/src/sage/features/giac.py b/src/sage/features/giac.py index 5a7833c1d20..57e120a57c5 100644 --- a/src/sage/features/giac.py +++ b/src/sage/features/giac.py @@ -4,6 +4,7 @@ """ from . import Executable, FeatureTestResult +from sage.env import SAGE_GIAC_ENABLED class Giac(Executable): r""" @@ -23,7 +24,11 @@ def __init__(self): sage: isinstance(Giac(), Giac) True """ - Executable.__init__(self, 'giac', executable='giac', + if SAGE_GIAC_ENABLED == "no": + giac_exe = 'fofobar42barfoo' + else: + giac_exe = 'giac' + Executable.__init__(self, 'giac', executable=giac_exe, spkg='giac', type='optional') def all_features(): From 83c4a14736f46288873a5e2bd5c946e43cb927eb Mon Sep 17 00:00:00 2001 From: Dima Pasechnik Date: Thu, 26 Sep 2024 14:53:29 +0100 Subject: [PATCH 8/8] also add sage.doctest: optional to feature/giac --- src/sage/features/giac.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sage/features/giac.py b/src/sage/features/giac.py index 57e120a57c5..cf86bad4360 100644 --- a/src/sage/features/giac.py +++ b/src/sage/features/giac.py @@ -1,4 +1,5 @@ # sage_setup: distribution = sagemath-environment +# sage.doctest: optional - giac r""" Feature for testing the presence of ``giac`` """