Skip to content

Commit 10ec4fa

Browse files
author
Release Manager
committed
Trac #29171: Move giacpy_sage into sage source code
As discussed on [https://groups.google.com/forum/#!topic/sage- devel/uYXGzG_py28 this sage-devel thread], we propose to move the Cython code that used to be in the optional package `giacpy_sage` into `sage/libs/giac/`. URL: https://trac.sagemath.org/29171 Reported by: vdelecroix Ticket author(s): Vincent Delecroix, Matthias Koeppe, Frederic Han Reviewer(s): Matthias Koeppe, Frederic Han, Dima Pasechnik
2 parents 611a2d6 + 911ddfb commit 10ec4fa

20 files changed

+21225
-143
lines changed

build/pkgs/giac/checksums.ini

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
tarball=giac-VERSION.tar.bz2
2-
sha1=eadeb7194b1809298a0d94642d94c8dff80bbe3d
3-
md5=7760e342f5e5b3f5da0f1b9c15546b96
4-
cksum=1678878999
5-
upstream_url=https://trac.sagemath.org/raw-attachment/ticket/29521/giac-1.5.0.63-p0.tar.bz2
2+
sha1=c8b4b40dae98a83adda0142332a482c4fec2d4eb
3+
md5=504151eb5f483a24c941822d792f0bb3
4+
cksum=3611162964
5+
upstream_url=https://trac.sagemath.org/raw-attachment/ticket/29552/giac-VERSION.tar.bz2

build/pkgs/giac/package-version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.5.0.63-p0
1+
1.5.0.87

build/pkgs/giac/spkg-src

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
#!/usr/bin/env bash -x
22
#
33
# Script to prepare a GIAC spkg for Sage. This script is only for the
44
# package maintainer, not for building GIAC during a Sage install.
@@ -14,8 +14,8 @@ fi
1414
set -e
1515

1616
VERSION="1.5.0"
17-
VERSIONREV="63"
18-
PATCHSUFFIX="-p0"
17+
VERSIONREV="87"
18+
PATCHSUFFIX=""
1919

2020
# The upstream tarball name is: giac"$SOURCEORIG".tar.gz
2121
SOURCEORIG=_"$VERSION"-"$VERSIONREV"
@@ -30,7 +30,7 @@ if [ -f "$OUTPUTFILEBASENAME".tar.gz -o -f "$OUTPUTFILEBASENAME".tar.bz2 ] ; the
3030
fi
3131

3232
# Build a temporary working dir. (preferably, a subdir of SAGE_DISTFILES)
33-
TARGET=$(mktemp -d -p"$SAGE_DISTFILES" || mktemp -d)
33+
TARGET=$(mktemp -d -p"$SAGE_DISTFILES" 2>/dev/null || mktemp -d)
3434
ORIGDIR=`pwd`
3535
cd "$TARGET"
3636

build/pkgs/giacpy_sage/SPKG.rst

-31
This file was deleted.

build/pkgs/giacpy_sage/checksums.ini

-4
This file was deleted.

build/pkgs/giacpy_sage/dependencies

-6
This file was deleted.

build/pkgs/giacpy_sage/package-version.txt

-1
This file was deleted.

build/pkgs/giacpy_sage/spkg-check.in

-3
This file was deleted.

build/pkgs/giacpy_sage/spkg-install.in

-3
This file was deleted.

build/pkgs/giacpy_sage/type

-1
This file was deleted.

src/sage/interfaces/giac.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -992,11 +992,27 @@ def _latex_(self):
992992
993993
EXAMPLES::
994994
995-
sage: print(latex(giac('(x^4 - y)/(y^2-3*x)')))
996-
"\frac{(x^{4}-y)}{(y^{2}-3\cdot x)}"
997-
998-
"""
999-
return self.parent().eval('latex(%s)'%self.name())
995+
sage: M = matrix(QQ, [[1, 2], [3, 4]])
996+
sage: latex(M)
997+
\left(\begin{array}{rr}
998+
1 & 2 \\
999+
3 & 4
1000+
\end{array}\right)
1001+
sage: gM = giac(M)
1002+
sage: latex(gM)
1003+
\left...\begin{array}{cc}...1...&...2...\\...3...&...4...\end{array}\right...
1004+
sage: gf = giac('(x^4 - y)/(y^2-3*x)')
1005+
sage: latex(gf) # output changed slightly from 1.5.0-63 to 1.5.0-87
1006+
\frac{...x^{4}...-...y...}{...y^{2}-3...x...}
1007+
1008+
"""
1009+
s = self.parent().eval('latex(%s)'%self.name())
1010+
if s.startswith('"'):
1011+
s = s[1:]
1012+
if s.endswith('"'):
1013+
s = s[:-1]
1014+
s = s.strip()
1015+
return s
10001016

10011017
def _matrix_(self, R):
10021018
r"""

src/sage/libs/all.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@
1313
'mwrank_MordellWeil', 'mwrank_initprimes', 'CremonaModularSymbols'))
1414
lazy_import('sage.libs.eclib.all', 'get_precision', 'mwrank_get_precision')
1515
lazy_import('sage.libs.eclib.all', 'set_precision', 'mwrank_set_precision')
16+
17+
lazy_import('sage.libs.giac.giac', 'libgiac')

src/sage/libs/giac.py src/sage/libs/giac/__init__.py

+56-70
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
1313
EXAMPLES::
1414
15-
sage: from sage.libs.giac import groebner_basis as gb_giac # optional - giacpy_sage
15+
sage: from sage.libs.giac import groebner_basis as gb_giac # random
1616
sage: P = PolynomialRing(QQ, 6, 'x')
1717
sage: I = sage.rings.ideal.Cyclic(P)
18-
sage: B = gb_giac(I.gens()) # optional - giacpy_sage, random
19-
sage: B # optional - giacpy_sage
18+
sage: B = gb_giac(I.gens()) # random
19+
sage: B
2020
Polynomial Sequence with 45 Polynomials in 6 Variables
2121
"""
2222

@@ -32,6 +32,7 @@
3232

3333
from sage.structure.proof.all import polynomial as proof_polynomial
3434
from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
35+
from .giac import giacsettings, libgiac
3536

3637
# Remarks for doctests:
3738
# 1) The first time that the c++ library giac is loaded a message appears.
@@ -51,19 +52,14 @@ def __enter__(self):
5152
"""
5253
EXAMPLES::
5354
54-
sage: from sage.libs.giac import GiacSettingsDefaultContext # optional - giacpy_sage
55-
sage: from giacpy_sage import giacsettings # optional - giacpy_sage
56-
sage: giacsettings.proba_epsilon = 1e-16 # optional - giacpy_sage
57-
sage: with GiacSettingsDefaultContext(): giacsettings.proba_epsilon = 1e-12 # optional - giacpy_sage
58-
sage: giacsettings.proba_epsilon < 1e-14 # optional - giacpy_sage
55+
sage: from sage.libs.giac import GiacSettingsDefaultContext
56+
sage: from sage.libs.giac.giac import giacsettings
57+
sage: giacsettings.proba_epsilon = 1e-16
58+
sage: with GiacSettingsDefaultContext(): giacsettings.proba_epsilon = 1e-12
59+
sage: giacsettings.proba_epsilon < 1e-14
5960
True
6061
6162
"""
62-
try:
63-
from giacpy_sage import giacsettings, libgiac
64-
except ImportError:
65-
raise ImportError("""One of the optional packages giac or giacpy_sage is missing""")
66-
6763
self.proba_epsilon = giacsettings.proba_epsilon
6864
self.threads = giacsettings.threads
6965
# Change the debug level at the end to not have messages at each modification
@@ -73,19 +69,14 @@ def __exit__(self, typ, value, tb):
7369
"""
7470
EXAMPLES::
7571
76-
sage: from sage.libs.giac import GiacSettingsDefaultContext # optional - giacpy_sage
77-
sage: from giacpy_sage import giacsettings # optional - giacpy_sage
78-
sage: giacsettings.proba_epsilon = 1e-16 # optional - giacpy_sage
79-
sage: with GiacSettingsDefaultContext(): giacsettings.proba_epsilon = 1e-30 # optional - giacpy_sage
80-
sage: giacsettings.proba_epsilon < 1e-20 # optional - giacpy_sage
72+
sage: from sage.libs.giac import GiacSettingsDefaultContext
73+
sage: from sage.libs.giac.giac import giacsettings
74+
sage: giacsettings.proba_epsilon = 1e-16
75+
sage: with GiacSettingsDefaultContext(): giacsettings.proba_epsilon = 1e-30
76+
sage: giacsettings.proba_epsilon < 1e-20
8177
False
8278
8379
"""
84-
try:
85-
from giacpy_sage import giacsettings, libgiac
86-
except ImportError:
87-
raise ImportError("""One of the optional packages giac or giacpy_sage is missing""")
88-
8980
# Restore the debug level first to not have messages at each modification
9081
libgiac('debug_infolevel')(self.debuginfolevel)
9182
# NB: giacsettings.epsilon has a different meaning that giacsettings.proba_epsilon.
@@ -99,20 +90,20 @@ def local_giacsettings(func):
9990
10091
EXAMPLES::
10192
102-
sage: def testf(a,b): # optional - giacpy_sage
93+
sage: def testf(a,b):
10394
....: giacsettings.proba_epsilon = a/100
10495
....: giacsettings.threads = b+2
10596
....: return (giacsettings.proba_epsilon, giacsettings.threads)
10697
107-
sage: from giacpy_sage import giacsettings # optional - giacpy_sage
108-
sage: from sage.libs.giac import local_giacsettings # optional - giacpy_sage
109-
sage: gporig, gtorig = (giacsettings.proba_epsilon,giacsettings.threads) # optional - giacpy_sage
110-
sage: gp, gt = local_giacsettings(testf)(giacsettings.proba_epsilon,giacsettings.threads) # optional - giacpy_sage
111-
sage: gporig == giacsettings.proba_epsilon # optional - giacpy_sage
98+
sage: from sage.libs.giac.giac import giacsettings
99+
sage: from sage.libs.giac import local_giacsettings
100+
sage: gporig, gtorig = (giacsettings.proba_epsilon,giacsettings.threads)
101+
sage: gp, gt = local_giacsettings(testf)(giacsettings.proba_epsilon,giacsettings.threads)
102+
sage: gporig == giacsettings.proba_epsilon
112103
True
113-
sage: gtorig == giacsettings.threads # optional - giacpy_sage
104+
sage: gtorig == giacsettings.threads
114105
True
115-
sage: gp<gporig, gt-gtorig # optional - giacpy_sage
106+
sage: gp<gporig, gt-gtorig
116107
(True, 2)
117108
118109
"""
@@ -178,50 +169,50 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False,
178169
179170
EXAMPLES::
180171
181-
sage: from sage.libs.giac import groebner_basis as gb_giac # optional - giacpy_sage
182-
sage: P = PolynomialRing(GF(previous_prime(2**31)), 6, 'x') # optional - giacpy_sage
183-
sage: I = sage.rings.ideal.Cyclic(P) # optional - giacpy_sage
184-
sage: B=gb_giac(I.gens());B # optional - giacpy_sage
172+
sage: from sage.libs.giac import groebner_basis as gb_giac
173+
sage: P = PolynomialRing(GF(previous_prime(2**31)), 6, 'x')
174+
sage: I = sage.rings.ideal.Cyclic(P)
175+
sage: B=gb_giac(I.gens());B
185176
<BLANKLINE>
186177
// Groebner basis computation time ...
187178
Polynomial Sequence with 45 Polynomials in 6 Variables
188-
sage: B.is_groebner() # optional - giacpy_sage
179+
sage: B.is_groebner()
189180
True
190181
191182
Elimination ideals can be computed by passing ``elim_variables``::
192183
193-
sage: P = PolynomialRing(GF(previous_prime(2**31)), 5, 'x') # optional - giacpy_sage
194-
sage: I = sage.rings.ideal.Cyclic(P) # optional - giacpy_sage
195-
sage: B = gb_giac(I.gens(), elim_variables=[P.gen(0), P.gen(2)]) # optional - giacpy_sage
184+
sage: P = PolynomialRing(GF(previous_prime(2**31)), 5, 'x')
185+
sage: I = sage.rings.ideal.Cyclic(P)
186+
sage: B = gb_giac(I.gens(), elim_variables=[P.gen(0), P.gen(2)])
196187
<BLANKLINE>
197188
// Groebner basis computation time ...
198-
sage: B.is_groebner() # optional - giacpy_sage
189+
sage: B.is_groebner()
199190
True
200-
sage: B.ideal() == I.elimination_ideal([P.gen(0), P.gen(2)]) # optional - giacpy_sage
191+
sage: B.ideal() == I.elimination_ideal([P.gen(0), P.gen(2)])
201192
True
202193
203194
Computations over QQ can benefit from
204195
205196
* a probabilistic lifting::
206197
207-
sage: P = PolynomialRing(QQ,5, 'x') # optional - giacpy_sage
208-
sage: I = ideal([P.random_element(3,7) for j in range(5)]) # optional - giacpy_sage
209-
sage: B1 = gb_giac(I.gens(),1e-16) # optional - giacpy_sage, long time (1s)
198+
sage: P = PolynomialRing(QQ,5, 'x')
199+
sage: I = ideal([P.random_element(3,7) for j in range(5)])
200+
sage: B1 = gb_giac(I.gens(),1e-16) # long time (1s)
210201
...Running a probabilistic check for the reconstructed Groebner basis.
211202
If successfull, error probability is less than 1e-16 ...
212-
sage: sage.structure.proof.all.polynomial(True) # optional - giacpy_sage
213-
sage: B2 = gb_giac(I.gens()) # optional - giacpy_sage, long time (4s)
203+
sage: sage.structure.proof.all.polynomial(True)
204+
sage: B2 = gb_giac(I.gens()) # long time (4s)
214205
<BLANKLINE>
215206
// Groebner basis computation time...
216-
sage: B1 == B2 # optional - giacpy_sage, long time
207+
sage: B1 == B2 # long time
217208
True
218-
sage: B1.is_groebner() # optional - giacpy_sage, long time (20s)
209+
sage: B1.is_groebner() # long time (20s)
219210
True
220211
221212
* multi threaded operations::
222213
223-
sage: P = PolynomialRing(QQ, 8, 'x') # optional - giacpy_sage
224-
sage: I = sage.rings.ideal.Cyclic(P) # optional - giacpy_sage
214+
sage: P = PolynomialRing(QQ, 8, 'x')
215+
sage: I = sage.rings.ideal.Cyclic(P)
225216
sage: time B = gb_giac(I.gens(),1e-6,threads=2) # doctest: +SKIP
226217
Running a probabilistic check for the reconstructed Groebner basis...
227218
Time: CPU 168.98 s, Wall: 94.13 s
@@ -230,8 +221,8 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False,
230221
231222
::
232223
233-
sage: I = sage.rings.ideal.Katsura(P) # optional - giacpy_sage
234-
sage: gb_giac(I,prot=True) # optional - giacpy_sage, random, long time (3s)
224+
sage: I = sage.rings.ideal.Katsura(P)
225+
sage: gb_giac(I,prot=True) # random, long time (3s)
235226
9381383 begin computing basis modulo 535718473
236227
9381501 begin new iteration zmod, number of pairs: 8, base size: 8
237228
...end, basis size 74 prime number 1
@@ -253,49 +244,44 @@ def groebner_basis(gens, proba_epsilon=None, threads=None, prot=False,
253244
254245
TESTS::
255246
256-
sage: from giacpy_sage import libgiac # optional - giacpy_sage
257-
sage: libgiac("x2:=22; x4:='whywouldyoudothis'") # optional - giacpy_sage
247+
sage: from sage.libs.giac.giac import libgiac
248+
sage: libgiac("x2:=22; x4:='whywouldyoudothis'")
258249
22,whywouldyoudothis
259-
sage: gb_giac(I) # optional - giacpy_sage
250+
sage: gb_giac(I)
260251
Traceback (most recent call last):
261252
...
262253
ValueError: Variables names ['x2', 'x4'] conflict in giac. Change them or purge them from in giac with libgiac.purge('x2')
263-
sage: libgiac.purge('x2'),libgiac.purge('x4') # optional - giacpy_sage
254+
sage: libgiac.purge('x2'),libgiac.purge('x4')
264255
(22, whywouldyoudothis)
265-
sage: gb_giac(I) # optional - giacpy_sage, long time (3s)
256+
sage: gb_giac(I) # long time (3s)
266257
<BLANKLINE>
267258
// Groebner basis computation time...
268259
Polynomial Sequence with 74 Polynomials in 8 Variables
269260
270-
sage: I = ideal(P(0),P(0)) # optional - giacpy_sage
271-
sage: I.groebner_basis() == gb_giac(I) # optional - giacpy_sage
261+
sage: I = ideal(P(0),P(0))
262+
sage: I.groebner_basis() == gb_giac(I)
272263
True
273264
274265
Test the supported term orderings::
275266
276267
sage: from sage.rings.ideal import Cyclic
277268
sage: P = PolynomialRing(QQ, 'x', 4, order='lex')
278-
sage: B = gb_giac(Cyclic(P)) # optional - giacpy_sage
269+
sage: B = gb_giac(Cyclic(P))
279270
...
280-
sage: B.is_groebner(), B.ideal() == Cyclic(P) # optional - giacpy_sage
271+
sage: B.is_groebner(), B.ideal() == Cyclic(P)
281272
(True, True)
282273
sage: P = P.change_ring(order='deglex')
283-
sage: B = gb_giac(Cyclic(P)) # optional - giacpy_sage
274+
sage: B = gb_giac(Cyclic(P))
284275
...
285-
sage: B.is_groebner(), B.ideal() == Cyclic(P) # optional - giacpy_sage
276+
sage: B.is_groebner(), B.ideal() == Cyclic(P)
286277
(True, True)
287278
sage: P = P.change_ring(order='degrevlex(2),degrevlex(2)')
288-
sage: B = gb_giac(Cyclic(P)) # optional - giacpy_sage
279+
sage: B = gb_giac(Cyclic(P))
289280
...
290-
sage: B.is_groebner(), B.ideal() == Cyclic(P) # optional - giacpy_sage
281+
sage: B.is_groebner(), B.ideal() == Cyclic(P)
291282
(True, True)
292283
293284
"""
294-
try:
295-
from giacpy_sage import libgiac, giacsettings
296-
except ImportError:
297-
raise ImportError("""One of the optional packages giac or giacpy_sage is missing""")
298-
299285
try:
300286
iter(gens)
301287
except TypeError:

0 commit comments

Comments
 (0)