Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/libs/singular/singular.pyx
4056 views
1
"""
2
libSingular conversion routines and initialisation.
3
4
AUTHOR:
5
6
- Martin Albrecht <[email protected]>
7
"""
8
###############################################################################
9
# Copyright (C) 2005, 2006 William Stein <[email protected]>
10
#
11
# Distributed under the terms of the GNU General Public License (GPL)
12
# as published by the Free Software Foundation; either version 2 of
13
# the License, or (at your option) any later version.
14
# http://www.gnu.org/licenses/
15
###############################################################################
16
17
include "sage/libs/ntl/decl.pxi"
18
include "sage/ext/stdsage.pxi"
19
include "sage/ext/interrupt.pxi"
20
21
cdef extern from "limits.h":
22
long INT_MAX
23
long INT_MIN
24
25
import os
26
27
from sage.misc.misc_c import is_64_bit
28
29
from sage.libs.singular.decl cimport intvec
30
from sage.libs.singular.decl cimport SR_HDL, SR_INT, SR_TO_INT
31
from sage.libs.singular.decl cimport singular_options, singular_verbose_options
32
from sage.libs.singular.decl cimport On, Off, SW_USE_NTL, SW_USE_NTL_GCD_0, SW_USE_EZGCD, SW_USE_NTL_SORT, SW_USE_NTL_GCD_P
33
from sage.libs.singular.decl cimport napoly, lnumber, Sy_bit, OPT_REDSB, OPT_INTSTRATEGY, OPT_REDTAIL, OPT_REDTHROUGH
34
from sage.libs.singular.decl cimport nlGetNumerator, nlGetDenom, nlDelete, nlInit2gmp
35
from sage.libs.singular.decl cimport naIsOne, naIsOne, naIsZero, naPar, naInit, naAdd, naMult, naDelete, naMap00
36
from sage.libs.singular.decl cimport napGetCoeff, napGetExpFrom, pNext
37
from sage.libs.singular.decl cimport nrzInit, nr2mMapZp, nrnMapGMP
38
from sage.libs.singular.decl cimport siInit
39
from sage.libs.singular.decl cimport n_Init
40
from sage.libs.singular.decl cimport rChangeCurrRing, currRing
41
from sage.libs.singular.decl cimport WerrorS_callback, const_char_ptr
42
43
from sage.rings.rational_field import RationalField
44
from sage.rings.integer_ring cimport IntegerRing_class
45
from sage.rings.finite_rings.integer_mod_ring import IntegerModRing_generic
46
from sage.rings.finite_rings.finite_field_prime_modn import FiniteField_prime_modn
47
from sage.rings.finite_rings.finite_field_ext_pari import FiniteField_ext_pari
48
from sage.rings.finite_rings.finite_field_givaro import FiniteField_givaro
49
from sage.rings.finite_rings.finite_field_ntl_gf2e import FiniteField_ntl_gf2e
50
from sage.libs.pari.all import pari
51
52
from sage.structure.parent_base cimport ParentWithBase
53
from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular
54
55
_saved_options = (int(0),0,0)
56
57
cdef Rational si2sa_QQ(number *n, ring *_ring):
58
"""
59
TESTS::
60
61
sage: P.<x,y,z> = QQ[]
62
sage: P(1/3).lc()
63
1/3
64
sage: P(1).lc()
65
1
66
sage: P(0).lc()
67
0
68
sage: P(-1/3).lc()
69
-1/3
70
sage: type(P(3).lc())
71
<type 'sage.rings.rational.Rational'>
72
"""
73
cdef number *nom
74
cdef number *denom
75
cdef mpq_t _z
76
77
cdef mpz_t nom_z, denom_z
78
79
cdef Rational z
80
81
mpq_init(_z)
82
83
## Immediate integers handles carry the tag 'SR_INT', i.e. the last bit is 1.
84
## This distinguishes immediate integers from other handles which point to
85
## structures aligned on 4 byte boundaries and therefor have last bit zero.
86
## (The second bit is reserved as tag to allow extensions of this scheme.)
87
## Using immediates as pointers and dereferencing them gives address errors.
88
nom = nlGetNumerator(n, _ring)
89
mpz_init(nom_z)
90
91
if (SR_HDL(nom) & SR_INT): mpz_set_si(nom_z, SR_TO_INT(nom))
92
else: mpz_set(nom_z,nom.z)
93
94
mpq_set_num(_z,nom_z)
95
nlDelete(&nom,_ring)
96
mpz_clear(nom_z)
97
98
denom = nlGetDenom(n, _ring)
99
mpz_init(denom_z)
100
101
if (SR_HDL(denom) & SR_INT): mpz_set_si(denom_z, SR_TO_INT(denom))
102
else: mpz_set(denom_z,denom.z)
103
104
mpq_set_den(_z, denom_z)
105
nlDelete(&denom,_ring)
106
mpz_clear(denom_z)
107
108
z = Rational()
109
z.set_from_mpq(_z)
110
mpq_clear(_z)
111
return z
112
113
cdef Integer si2sa_ZZ(number *n, ring *_ring):
114
"""
115
TESTS::
116
117
sage: P.<x,y,z> = ZZ[]
118
sage: P(3).lc()
119
3
120
sage: P(0).lc()
121
0
122
sage: P(-3).lc()
123
-3
124
sage: P(-1234567890).lc()
125
-1234567890
126
sage: type(P(3).lc())
127
<type 'sage.rings.integer.Integer'>
128
"""
129
cdef Integer z
130
z = Integer()
131
z.set_from_mpz(<__mpz_struct*>n)
132
return z
133
134
cdef FFgivE si2sa_GFqGivaro(number *n, ring *_ring, Cache_givaro cache):
135
"""
136
TESTS::
137
138
sage: K.<a> = GF(5^3)
139
sage: R.<x,y,z> = PolynomialRing(K)
140
sage: K( (4*R(a)^2 + R(a))^3 )
141
a^2
142
sage: K(R(0))
143
0
144
"""
145
cdef napoly *z
146
cdef int c, e
147
cdef int a
148
cdef int ret
149
cdef int order
150
151
if naIsZero(n):
152
return cache._zero_element
153
elif naIsOne(n):
154
return cache._one_element
155
z = (<lnumber*>n).z
156
157
a = cache.objectptr.sage_generator()
158
ret = cache.objectptr.zero
159
order = cache.objectptr.cardinality() - 1
160
161
while z:
162
c = cache.objectptr.initi(c,<long>napGetCoeff(z))
163
e = napGetExpFrom(z,1, _ring)
164
if e == 0:
165
ret = cache.objectptr.add(ret, c, ret)
166
else:
167
a = ( e * cache.objectptr.sage_generator() ) % order
168
ret = cache.objectptr.axpy(ret, c, a, ret)
169
z = <napoly*>pNext(<poly*>z)
170
return (<FFgivE>cache._zero_element)._new_c(ret)
171
172
cdef FFgf2eE si2sa_GFqNTLGF2E(number *n, ring *_ring, Cache_ntl_gf2e cache):
173
"""
174
TESTS::
175
176
sage: K.<a> = GF(2^20)
177
sage: P.<x,y,z> = K[]
178
sage: f = a^21*x^2 + 1 # indirect doctest
179
sage: f.lc()
180
a^11 + a^10 + a^8 + a^7 + a^6 + a^5 + a^2 + a
181
sage: type(f.lc())
182
<type 'sage.rings.finite_rings.element_ntl_gf2e.FiniteField_ntl_gf2eElement'>
183
"""
184
cdef napoly *z
185
cdef int c, e
186
cdef FFgf2eE a
187
cdef FFgf2eE ret
188
189
if naIsZero(n):
190
return cache._zero_element
191
elif naIsOne(n):
192
return cache._one_element
193
z = (<lnumber*>n).z
194
195
a = cache._gen
196
ret = cache._zero_element
197
198
while z:
199
c = <long>napGetCoeff(z)
200
e = napGetExpFrom(z,1, _ring)
201
ret += c * a**e
202
z = <napoly*>pNext(<poly*>z)
203
return ret
204
205
cdef object si2sa_GFqPari(number *n, ring *_ring, object base):
206
"""
207
TESTS::
208
209
sage: K.<a> = GF(3^16)
210
sage: P.<x,y,z> = K[]
211
sage: f = a^21*x^2 + 1 # indirect doctest
212
sage: f.lc()
213
a^12 + a^11 + a^9 + a^8 + a^7 + 2*a^6 + a^5
214
sage: type(f.lc())
215
<class 'sage.rings.finite_rings.element_ext_pari.FiniteField_ext_pariElement_with_category'>
216
"""
217
cdef napoly *z
218
cdef int c, e
219
cdef object a
220
cdef object ret
221
222
if naIsZero(n):
223
return base._zero_element
224
elif naIsOne(n):
225
return base._one_element
226
z = (<lnumber*>n).z
227
228
a = pari("a")
229
ret = pari(int(0)).Mod(int(_ring.ch))
230
231
while z:
232
c = <long>napGetCoeff(z)
233
e = napGetExpFrom(z,1, _ring)
234
if e == 0:
235
ret = ret + c
236
elif c != 0:
237
ret = ret + c * a**e
238
z = <napoly*>pNext(<poly*>z)
239
return base(ret)
240
241
cdef object si2sa_NF(number *n, ring *_ring, object base):
242
"""
243
TESTS::
244
245
sage: K.<a> = NumberField(x^2 - 2)
246
sage: P.<x,y,z> = K[]
247
sage: f = a^21*x^2 + 1 # indirect doctest
248
sage: f.lc()
249
1024*a
250
sage: type(f.lc())
251
<type 'sage.rings.number_field.number_field_element_quadratic.NumberFieldElement_quadratic'>
252
"""
253
cdef napoly *z
254
cdef number *c
255
cdef int e
256
cdef object a
257
cdef object ret
258
259
if naIsZero(n):
260
return base._zero_element
261
elif naIsOne(n):
262
return base._one_element
263
z = (<lnumber*>n).z
264
265
a = base.gen()
266
ret = base(0)
267
268
while z:
269
c = napGetCoeff(z)
270
coeff = si2sa_QQ(c, _ring)
271
e = napGetExpFrom(z,1, _ring)
272
if e == 0:
273
ret = ret + coeff
274
elif coeff != 0:
275
ret = ret + coeff * a**e
276
z = <napoly*>pNext(<poly*>z)
277
return base(ret)
278
279
cdef inline object si2sa_ZZmod(number *n, ring *_ring, object base):
280
"""
281
TESTS::
282
283
sage: P.<x,y,z> = Integers(10)[]
284
sage: P(3).lc()
285
3
286
sage: P(13).lc()
287
3
288
289
sage: P.<x,y,z> = Integers(16)[]
290
sage: P(3).lc()
291
3
292
sage: P(19).lc()
293
3
294
295
sage: P.<x,y,z> = Integers(3**2)[]
296
sage: P(3).lc()
297
3
298
sage: P(12).lc()
299
3
300
301
sage: P.<x,y,z> = Integers(2^32)[]
302
sage: P(2^32-1).lc()
303
4294967295
304
305
sage: P(3).lc()
306
3
307
308
sage: P.<x,y,z> = Integers(17^20)[]
309
sage: P(17^19 + 3).lc()
310
239072435685151324847156
311
312
sage: P(3)
313
3
314
"""
315
cdef Integer ret
316
if _ring.ringtype == 1:
317
return base(<long>n)
318
else:
319
ret = Integer()
320
ret.set_from_mpz(<__mpz_struct*>n)
321
return base(ret)
322
323
return base(_ring.cf.n_Int(n,_ring))
324
325
cdef number *sa2si_QQ(Rational r, ring *_ring):
326
"""
327
TESTS::
328
329
sage: P.<x,y,z> = QQ[]
330
sage: P(0) + 1/2 - 2/4
331
0
332
sage: P(1/2) + 3/5 - 3/5
333
1/2
334
sage: P(2/3) + 1/4 - 1/4
335
2/3
336
sage: P(12345678901234567890/23) + 5/2 - 5/2
337
12345678901234567890/23
338
"""
339
if _ring != currRing: rChangeCurrRing(_ring)
340
return nlInit2gmp( mpq_numref(r.value), mpq_denref(r.value) )
341
342
cdef number *sa2si_GFqGivaro(int quo, ring *_ring):
343
"""
344
"""
345
if _ring != currRing: rChangeCurrRing(_ring)
346
cdef number *n1, *n2, *a, *coeff, *apow1, *apow2
347
cdef int b = - _ring.ch
348
349
a = naPar(1)
350
351
apow1 = naInit(1, _ring)
352
n1 = naInit(0, _ring)
353
354
while quo!=0:
355
coeff = naInit(quo%b, _ring)
356
357
if not naIsZero(coeff):
358
apow2 = naMult(coeff, apow1)
359
n2 = naAdd(apow2, n1)
360
naDelete(&apow2, _ring)
361
naDelete(&n1, _ring)
362
n1 = n2
363
364
apow2 = naMult(apow1, a)
365
naDelete(&apow1, _ring)
366
apow1 = apow2
367
368
quo = quo/b
369
naDelete(&coeff, _ring)
370
371
naDelete(&apow1, _ring)
372
naDelete(&a, _ring)
373
return n1
374
375
cdef number *sa2si_GFqNTLGF2E(FFgf2eE elem, ring *_ring):
376
"""
377
"""
378
if _ring != currRing: rChangeCurrRing(_ring)
379
cdef int i
380
cdef number *n1, *n2, *a, *coeff, *apow1, *apow2
381
cdef GF2X_c rep = GF2E_rep(elem.x)
382
383
if GF2X_deg(rep) >= 1:
384
n1 = naInit(0, _ring)
385
a = naPar(1)
386
apow1 = naInit(1, _ring)
387
388
for i from 0 <= i <= GF2X_deg(rep):
389
coeff = naInit(GF2_conv_to_long(GF2X_coeff(rep,i)), _ring)
390
391
if not naIsZero(coeff):
392
apow2 = naMult(coeff, apow1)
393
n2 = naAdd(apow2, n1)
394
naDelete(&apow2, _ring)
395
naDelete(&n1, _ring);
396
n1 = n2
397
398
apow2 = naMult(apow1, a)
399
naDelete(&apow1, _ring)
400
apow1 = apow2
401
402
naDelete(&coeff, _ring)
403
404
naDelete(&apow1, _ring)
405
naDelete(&a, _ring)
406
else:
407
n1 = naInit(GF2_conv_to_long(GF2X_coeff(rep,0)), _ring)
408
409
return n1
410
411
cdef number *sa2si_GFqPari(object elem, ring *_ring):
412
"""
413
"""
414
cdef int i
415
cdef number *n1, *n2, *a, *coeff, *apow1, *apow2
416
elem = elem._pari_().lift().lift()
417
418
if _ring != currRing: rChangeCurrRing(_ring)
419
if len(elem) > 1:
420
n1 = naInit(0, _ring)
421
a = naPar(1)
422
apow1 = naInit(1, _ring)
423
424
for i from 0 <= i < len(elem):
425
coeff = naInit(int(elem[i]), _ring)
426
427
if not naIsZero(coeff):
428
apow2 = naMult(coeff, apow1)
429
n2 = naAdd(apow2, n1)
430
naDelete(&apow2, _ring)
431
naDelete(&n1, _ring);
432
n1 = n2
433
434
apow2 = naMult(apow1, a)
435
naDelete(&apow1, _ring)
436
apow1 = apow2
437
438
naDelete(&coeff, _ring)
439
440
naDelete(&apow1, _ring)
441
naDelete(&a, _ring)
442
else:
443
n1 = naInit(int(elem), _ring)
444
445
return n1
446
447
cdef number *sa2si_NF(object elem, ring *_ring):
448
"""
449
"""
450
cdef int i
451
cdef number *n1, *n2, *a, *nlCoeff, *naCoeff, *apow1, *apow2
452
elem = list(elem)
453
454
if _ring != currRing: rChangeCurrRing(_ring)
455
n1 = naInit(0, _ring)
456
a = naPar(1)
457
apow1 = naInit(1, _ring)
458
459
for i from 0 <= i < len(elem):
460
nlCoeff = nlInit2gmp( mpq_numref((<Rational>elem[i]).value), mpq_denref((<Rational>elem[i]).value) )
461
naCoeff = naMap00(nlCoeff)
462
nlDelete(&nlCoeff, _ring)
463
464
# faster would be to assign the coefficient directly
465
apow2 = naMult(naCoeff, apow1)
466
n2 = naAdd(apow2, n1)
467
naDelete(&apow2, _ring)
468
naDelete(&n1, _ring);
469
naDelete(&naCoeff, _ring)
470
n1 = n2
471
472
apow2 = naMult(apow1, a)
473
naDelete(&apow1, _ring)
474
apow1 = apow2
475
476
naDelete(&apow1, _ring)
477
naDelete(&a, _ring)
478
479
return n1
480
481
cdef number *sa2si_ZZ(Integer d, ring *_ring):
482
"""
483
TESTS::
484
485
sage: P.<x,y,z> = ZZ[]
486
sage: P(0) + 1 - 1
487
0
488
sage: P(1) + 1 - 1
489
1
490
sage: P(2) + 1 - 1
491
2
492
sage: P(12345678901234567890) + 2 - 2
493
12345678901234567890
494
"""
495
if _ring != currRing: rChangeCurrRing(_ring)
496
cdef number *n = nrzInit(0, _ring)
497
mpz_set(<__mpz_struct*>n, d.value)
498
return <number*>n
499
500
cdef inline number *sa2si_ZZmod(IntegerMod_abstract d, ring *_ring):
501
"""
502
TESTS::
503
504
sage: P.<x,y,z> = Integers(10)[]
505
sage: P(3)
506
3
507
sage: P(13)
508
3
509
510
sage: P.<x,y,z> = Integers(16)[]
511
sage: P(3)
512
3
513
sage: P(19)
514
3
515
516
sage: P.<x,y,z> = Integers(3^2)[]
517
sage: P(3)
518
3
519
sage: P(12)
520
3
521
522
sage: P.<x,y,z> = Integers(2^32)[]
523
sage: P(2^32-1)
524
4294967295
525
526
sage: P(3)
527
3
528
529
sage: P.<x,y,z> = Integers(17^20)[]
530
sage: P(17^19 + 3)
531
239072435685151324847156
532
533
sage: P(3)
534
3
535
"""
536
nr2mModul = d.parent().characteristic()
537
if _ring != currRing: rChangeCurrRing(_ring)
538
cdef int _d
539
if _ring.ringtype == 1:
540
_d = long(d)
541
return nr2mMapZp(<number *>_d)
542
else:
543
lift = d.lift()
544
return nrnMapGMP(<number *>((<Integer>lift).value))
545
546
cdef object si2sa(number *n, ring *_ring, object base):
547
if PY_TYPE_CHECK(base, FiniteField_prime_modn):
548
return base(_ring.cf.n_Int(n, _ring))
549
550
elif PY_TYPE_CHECK(base, RationalField):
551
return si2sa_QQ(n,_ring)
552
553
elif PY_TYPE_CHECK(base, IntegerRing_class):
554
return si2sa_ZZ(n,_ring)
555
556
elif PY_TYPE_CHECK(base, FiniteField_givaro):
557
return si2sa_GFqGivaro(n, _ring, base._cache)
558
559
elif PY_TYPE_CHECK(base, FiniteField_ext_pari):
560
return si2sa_GFqPari(n, _ring, base)
561
562
elif PY_TYPE_CHECK(base, FiniteField_ntl_gf2e):
563
return si2sa_GFqNTLGF2E(n, _ring, <Cache_ntl_gf2e>base._cache)
564
565
elif PY_TYPE_CHECK(base, NumberField) and base.is_absolute():
566
return si2sa_NF(n, _ring, base)
567
568
elif PY_TYPE_CHECK(base, IntegerModRing_generic):
569
if _ring.ringtype == 0:
570
return base(_ring.cf.n_Int(n, _ring))
571
return si2sa_ZZmod(n, _ring, base)
572
573
else:
574
raise ValueError, "cannot convert from SINGULAR number"
575
576
cdef number *sa2si(Element elem, ring * _ring):
577
cdef int i
578
if PY_TYPE_CHECK(elem._parent, FiniteField_prime_modn):
579
return n_Init(int(elem),_ring)
580
581
elif PY_TYPE_CHECK(elem._parent, RationalField):
582
return sa2si_QQ(elem, _ring)
583
584
elif PY_TYPE_CHECK(elem._parent, IntegerRing_class):
585
return sa2si_ZZ(elem, _ring)
586
587
elif isinstance(elem._parent, FiniteField_givaro):
588
return sa2si_GFqGivaro( (<FFgivE>elem)._cache.objectptr.convert(i, (<FFgivE>elem).element ), _ring )
589
590
elif PY_TYPE_CHECK(elem._parent, FiniteField_ext_pari):
591
return sa2si_GFqPari(elem, _ring)
592
593
elif PY_TYPE_CHECK(elem._parent, FiniteField_ntl_gf2e):
594
return sa2si_GFqNTLGF2E(elem, _ring)
595
596
elif PY_TYPE_CHECK(elem._parent, NumberField) and elem._parent.is_absolute():
597
return sa2si_NF(elem, _ring)
598
elif PY_TYPE_CHECK(elem._parent, IntegerModRing_generic):
599
if _ring.ringtype == 0:
600
return n_Init(int(elem),_ring)
601
return sa2si_ZZmod(elem, _ring)
602
else:
603
raise ValueError, "cannot convert to SINGULAR number"
604
605
606
cdef object si2sa_intvec(intvec *v):
607
cdef int r
608
cdef list l = list()
609
for r in range(v.length()):
610
l.append(v.get(r))
611
return tuple(l)
612
613
# ==============
614
# Initialisation
615
# ==============
616
617
cdef extern from "":
618
int unlikely(int)
619
620
cdef extern from "dlfcn.h":
621
void *dlopen(char *, long)
622
char *dlerror()
623
void dlclose(void *handle)
624
625
cdef extern from "dlfcn.h":
626
cdef long RTLD_LAZY
627
cdef long RTLD_GLOBAL
628
629
# Our attempt at avoiding exponent overflows.
630
cdef unsigned int max_exponent_size
631
632
cdef inline int overflow_check(long e, ring *_ring) except -1:
633
"""
634
Raises an ``OverflowError`` if e is > ``max_exponent_size``,
635
or if it is not acceptable for Singular as exponent of the
636
given ring.
637
638
INPUT:
639
640
- ``e`` - some integer representing a degree.
641
- ``_ring`` - a pointer to some ring.
642
643
TESTS:
644
645
Whether an overflow occurs or not, partially depends
646
on the number of variables in the ring. See trac ticket
647
#11856::
648
649
sage: P.<x,y,z> = QQ[]
650
sage: y^2^30
651
Traceback (most recent call last):
652
...
653
OverflowError: Exponent overflow (1073741824).
654
sage: P.<x,y> = QQ[]
655
sage: y^2^30
656
y^1073741824 # 64-bit
657
Traceback (most recent call last): # 32-bit
658
... # 32-bit
659
OverflowError: Exponent overflow (1073741824). # 32-bit
660
661
sage: x^2^30*x^2^30
662
Traceback (most recent call last):
663
...
664
OverflowError: Exponent overflow (2147483648). # 64-bit
665
OverflowError: Exponent overflow (1073741824). # 32-bit
666
667
"""
668
if unlikely(e > min(max_exponent_size,max(_ring.N,_ring.bitmask))):
669
raise OverflowError("Exponent overflow (%d)."%(e))
670
return 0
671
672
cdef init_libsingular():
673
"""
674
This initializes the SINGULAR library. This is a hack to some
675
extent.
676
677
SINGULAR has a concept of compiled extension modules similar to
678
Sage. For this, the compiled modules need to see the symbols from
679
the main program. However, SINGULAR is a shared library in this
680
context these symbols are not known globally. The work around so
681
far is to load the library again and to specify ``RTLD_GLOBAL``.
682
"""
683
global singular_options
684
global singular_verbose_options
685
global max_exponent_size
686
global WerrorS_callback
687
global error_messages
688
689
cdef void *handle = NULL
690
691
for extension in ["so", "dylib", "dll"]:
692
lib = os.environ['SAGE_LOCAL']+"/lib/libsingular."+extension
693
if os.path.exists(lib):
694
handle = dlopen(lib, RTLD_GLOBAL|RTLD_LAZY)
695
break
696
697
if handle == NULL:
698
print dlerror()
699
raise ImportError, "cannot load libSINGULAR library"
700
701
# load SINGULAR
702
siInit(lib)
703
704
dlclose(handle)
705
706
# we set and save some global Singular options
707
singular_options = singular_options | Sy_bit(OPT_REDSB) | Sy_bit(OPT_INTSTRATEGY) | Sy_bit(OPT_REDTAIL) | Sy_bit(OPT_REDTHROUGH)
708
global _saved_options
709
global _saved_verbose_options
710
_saved_options = (int(singular_options), 0, 0)
711
_saved_verbose_options = int(singular_verbose_options)
712
713
On(SW_USE_NTL)
714
On(SW_USE_NTL_GCD_0)
715
On(SW_USE_NTL_GCD_P)
716
On(SW_USE_EZGCD)
717
Off(SW_USE_NTL_SORT)
718
719
if is_64_bit:
720
max_exponent_size = 1<<31-1;
721
else:
722
max_exponent_size = 1<<16-1;
723
724
WerrorS_callback = libsingular_error_callback
725
726
error_messages = []
727
728
cdef inline unsigned long get_max_exponent_size():
729
global max_exponent_size
730
return max_exponent_size
731
732
# call the init routine
733
init_libsingular()
734
735
cdef void libsingular_error_callback(const_char_ptr s):
736
_s = s
737
error_messages.append(_s)
738
739