Skip to content

Commit da1933f

Browse files
author
Matthias Koeppe
committed
pkgs/sagemath-{flint,symbolics}: Fixups
1 parent 3088ebf commit da1933f

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/sage/rings/finite_rings/element_ntl_gf2e.pyx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ cdef class Cache_ntl_gf2e(Cache_base):
274274
cdef FiniteField_ntl_gf2eElement x
275275
cdef FiniteField_ntl_gf2eElement g
276276
cdef Py_ssize_t i
277-
from sage.libs.gap.element import GapElement_FiniteField
278277

279278
if is_IntegerMod(e):
280279
e = e.lift()
@@ -334,11 +333,14 @@ cdef class Cache_ntl_gf2e(Cache_base):
334333
# Reduce to pari
335334
e = e.__pari__()
336335

337-
elif isinstance(e, GapElement_FiniteField):
338-
return e.sage(ring=self._parent)
339-
340336
elif isinstance(e, GapElement):
337+
from sage.libs.gap.element import GapElement_FiniteField
338+
339+
if isinstance(e, GapElement_FiniteField):
340+
return e.sage(ring=self._parent)
341+
341342
from sage.libs.gap.libgap import libgap
343+
342344
return libgap(e).sage(ring=self._parent)
343345

344346
else:

src/sage/rings/number_field/number_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282

8383

8484
import sage.libs.ntl.all as ntl
85-
import sage.interfaces.gap
8685

8786
import sage.rings.complex_mpfr
8887
from sage.rings.polynomial.polynomial_element import Polynomial
@@ -4530,7 +4529,8 @@ def _gap_init_(self):
45304529
"""
45314530
if not self.is_absolute():
45324531
raise NotImplementedError("Currently, only simple algebraic extensions are implemented in gap")
4533-
G = sage.interfaces.gap.gap
4532+
from sage.interfaces.gap import gap as G
4533+
45344534
q = self.polynomial()
45354535
if q.variable_name() != 'E':
45364536
return 'CallFuncList(function() local %s,E; %s:=Indeterminate(%s,"%s"); E:=AlgebraicExtension(%s,%s,"%s"); return E; end,[])' % (q.variable_name(), q.variable_name(), G(self.base_ring()).name(), q.variable_name(), G(self.base_ring()).name(), repr(self.polynomial()), str(self.gen()))

src/sage/rings/polynomial/complex_roots.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
2222
sage: x = polygen(ZZ)
2323
sage: (x^5 - x - 1).roots(ring=CIF)
24-
[(1.167303978261419?, 1), (-0.764884433600585? - 0.352471546031727?*I, 1), (-0.764884433600585? + 0.352471546031727?*I, 1), (0.181232444469876? - 1.083954101317711?*I, 1), (0.181232444469876? + 1.083954101317711?*I, 1)]
24+
[(1.167303978261419?, 1),
25+
(-0.764884433600585? - 0.352471546031727?*I, 1),
26+
(-0.764884433600585? + 0.352471546031727?*I, 1),
27+
(0.181232444469876? - 1.083954101317711?*I, 1),
28+
(0.181232444469876? + 1.083954101317711?*I, 1)]
2529
"""
2630

2731
#*****************************************************************************
@@ -61,9 +65,13 @@ def interval_roots(p, rts, prec):
6165
sage: rts = [CC.zeta(3)^i for i in range(0, 3)]
6266
sage: from sage.rings.polynomial.complex_roots import interval_roots
6367
sage: interval_roots(p, rts, 53)
64-
[1, -0.500000000000000? + 0.866025403784439?*I, -0.500000000000000? - 0.866025403784439?*I]
68+
[1, -0.500000000000000? + 0.866025403784439?*I,
69+
-0.500000000000000? - 0.866025403784439?*I]
6570
sage: interval_roots(p, rts, 200)
66-
[1, -0.500000000000000000000000000000000000000000000000000000000000? + 0.866025403784438646763723170752936183471402626905190314027904?*I, -0.500000000000000000000000000000000000000000000000000000000000? - 0.866025403784438646763723170752936183471402626905190314027904?*I]
71+
[1, -0.500000000000000000000000000000000000000000000000000000000000?
72+
+ 0.866025403784438646763723170752936183471402626905190314027904?*I,
73+
-0.500000000000000000000000000000000000000000000000000000000000?
74+
- 0.866025403784438646763723170752936183471402626905190314027904?*I]
6775
"""
6876

6977
CIF = ComplexIntervalField(prec)
@@ -172,15 +180,19 @@ def complex_roots(p, skip_squarefree=False, retval='interval', min_prec=0):
172180
sage: from sage.rings.polynomial.complex_roots import complex_roots
173181
sage: x = polygen(ZZ)
174182
sage: complex_roots(x^5 - x - 1)
175-
[(1.167303978261419?, 1), (-0.764884433600585? - 0.352471546031727?*I, 1), (-0.764884433600585? + 0.352471546031727?*I, 1), (0.181232444469876? - 1.083954101317711?*I, 1), (0.181232444469876? + 1.083954101317711?*I, 1)]
176-
sage: v=complex_roots(x^2 + 27*x + 181)
183+
[(1.167303978261419?, 1),
184+
(-0.764884433600585? - 0.352471546031727?*I, 1),
185+
(-0.764884433600585? + 0.352471546031727?*I, 1),
186+
(0.181232444469876? - 1.083954101317711?*I, 1),
187+
(0.181232444469876? + 1.083954101317711?*I, 1)]
188+
sage: v = complex_roots(x^2 + 27*x + 181)
177189
178190
Unfortunately due to numerical noise there can be a small imaginary part to each
179191
root depending on CPU, compiler, etc, and that affects the printing order. So we
180192
verify the real part of each root and check that the imaginary part is small in
181193
both cases::
182194
183-
sage: v # random
195+
sage: v # random
184196
[(-14.61803398874990?..., 1), (-12.3819660112501...? + 0.?e-27*I, 1)]
185197
sage: sorted((v[0][0].real(),v[1][0].real()))
186198
[-14.61803398874989?, -12.3819660112501...?]
@@ -227,11 +239,16 @@ def complex_roots(p, skip_squarefree=False, retval='interval', min_prec=0):
227239
....: if tiny(x.imag()): return x.real()
228240
....: if tiny(x.real()): return CIF(0, x.imag())
229241
sage: rts = complex_roots(p); type(rts[0][0]), sorted(map(smash, rts))
230-
(<class 'sage.rings.complex_interval.ComplexIntervalFieldElement'>, [-1.618033988749895?, -0.618033988749895?*I, 1.618033988749895?*I, 0.618033988749895?])
242+
(<class 'sage.rings.complex_interval.ComplexIntervalFieldElement'>,
243+
[-1.618033988749895?, -0.618033988749895?*I,
244+
1.618033988749895?*I, 0.618033988749895?])
231245
sage: rts = complex_roots(p, retval='algebraic'); type(rts[0][0]), sorted(map(smash, rts))
232-
(<class 'sage.rings.qqbar.AlgebraicNumber'>, [-1.618033988749895?, -0.618033988749895?*I, 1.618033988749895?*I, 0.618033988749895?])
246+
(<class 'sage.rings.qqbar.AlgebraicNumber'>,
247+
[-1.618033988749895?, -0.618033988749895?*I,
248+
1.618033988749895?*I, 0.618033988749895?])
233249
sage: rts = complex_roots(p, retval='algebraic_real'); type(rts[0][0]), rts
234-
(<class 'sage.rings.qqbar.AlgebraicReal'>, [(-1.618033988749895?, 1), (0.618033988749895?, 1)])
250+
(<class 'sage.rings.qqbar.AlgebraicReal'>,
251+
[(-1.618033988749895?, 1), (0.618033988749895?, 1)])
235252
236253
TESTS:
237254

0 commit comments

Comments
 (0)