passagemath-brial 10.6.31rc3__cp314-cp314-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of passagemath-brial might be problematic. Click here for more details.

Files changed (38) hide show
  1. passagemath_brial-10.6.31rc3.dist-info/METADATA +97 -0
  2. passagemath_brial-10.6.31rc3.dist-info/RECORD +38 -0
  3. passagemath_brial-10.6.31rc3.dist-info/WHEEL +6 -0
  4. passagemath_brial-10.6.31rc3.dist-info/top_level.txt +2 -0
  5. passagemath_brial.libs/libbrial-a2b87c7c.so.3.0.7 +0 -0
  6. passagemath_brial.libs/libbrial_groebner-0f8afeeb.so.3.0.7 +0 -0
  7. passagemath_brial.libs/libgmp-93ebf16a.so.10.5.0 +0 -0
  8. passagemath_brial.libs/libm4ri-ffdb5f7f.so.1.0.0 +0 -0
  9. passagemath_brial.libs/libpng16-89198bef.so.16.43.0 +0 -0
  10. sage/all__sagemath_brial.py +9 -0
  11. sage/libs/all__sagemath_brial.py +1 -0
  12. sage/libs/polybori/__init__.pxd +2 -0
  13. sage/libs/polybori/decl.pxd +401 -0
  14. sage/libs/polybori/pb_wrap.h +133 -0
  15. sage/rings/all__sagemath_brial.py +1 -0
  16. sage/rings/polynomial/all__sagemath_brial.py +1 -0
  17. sage/rings/polynomial/pbori/PyPolyBoRi.py +123 -0
  18. sage/rings/polynomial/pbori/__init__.py +44 -0
  19. sage/rings/polynomial/pbori/blocks.py +443 -0
  20. sage/rings/polynomial/pbori/cnf.py +241 -0
  21. sage/rings/polynomial/pbori/easy_polynomials.py +56 -0
  22. sage/rings/polynomial/pbori/fglm.py +93 -0
  23. sage/rings/polynomial/pbori/frontend.py +70 -0
  24. sage/rings/polynomial/pbori/gbcore.py +634 -0
  25. sage/rings/polynomial/pbori/gbrefs.py +127 -0
  26. sage/rings/polynomial/pbori/heuristics.py +35 -0
  27. sage/rings/polynomial/pbori/interpolate.py +115 -0
  28. sage/rings/polynomial/pbori/interred.py +35 -0
  29. sage/rings/polynomial/pbori/ll.py +292 -0
  30. sage/rings/polynomial/pbori/nf.py +662 -0
  31. sage/rings/polynomial/pbori/parallel.py +298 -0
  32. sage/rings/polynomial/pbori/pbori.cpython-314-aarch64-linux-gnu.so +0 -0
  33. sage/rings/polynomial/pbori/pbori.pxd +127 -0
  34. sage/rings/polynomial/pbori/pbori.pyx +8107 -0
  35. sage/rings/polynomial/pbori/randompoly.py +105 -0
  36. sage/rings/polynomial/pbori/rank.py +27 -0
  37. sage/rings/polynomial/pbori/specialsets.py +112 -0
  38. sage/rings/polynomial/pbori/statistics.py +31 -0
@@ -0,0 +1,298 @@
1
+ # sage_setup: distribution = sagemath-brial
2
+ # sage.doctest: needs sage.rings.polynomial.pbori
3
+ r"""
4
+ parallel.py
5
+ PolyBoRi
6
+
7
+ Created by Michael Brickenstein on 2008-10-31.
8
+ Copyright 2008 The PolyBoRi Team
9
+ """
10
+ from zlib import compress, decompress
11
+ import copyreg
12
+
13
+ from .pbori import if_then_else, BooleSet, CCuddNavigator
14
+ from .PyPolyBoRi import (Polynomial, Ring, WeakRingRef, Monomial, Variable)
15
+ from .gbcore import groebner_basis
16
+
17
+
18
+ def to_fast_pickable(l):
19
+ r"""
20
+ Convert a list of polynomials into a builtin Python value, which is fast pickable and compact.
21
+
22
+ INPUT:
23
+
24
+ - ``l`` -- a list of Boolean polynomials
25
+
26
+ OUTPUT:
27
+
28
+ It is converted to a tuple consisting of
29
+ - codes referring to the polynomials
30
+ - list of conversions of nodes.
31
+ The nodes are sorted, so that n occurs before n.else_branch(), n.then_branch()
32
+ nodes are only listed, if they are not constant.
33
+
34
+ A node is converted in this way:
35
+ 0 -> 0
36
+ 1 -> 1
37
+ if_then_else(v,t,e) -> (v, index of then branch +2, index of else branch +2)
38
+ the shift of +2 is for the constant values implicitly contained in the list.
39
+ Each code c refers to the c-2-th position in the conversion list, if c >=2, else to
40
+ the corresponding Boolean constant if c in {0, 1}
41
+
42
+ EXAMPLES::
43
+
44
+ sage: from sage.rings.polynomial.pbori import Ring, Polynomial
45
+ sage: from sage.rings.polynomial.pbori.parallel import to_fast_pickable, from_fast_pickable
46
+ sage: r = Ring(1000)
47
+ sage: x = r.variable
48
+ sage: to_fast_pickable([Polynomial(1, r)])
49
+ [[1], []]
50
+ sage: to_fast_pickable([Polynomial(0, r)])
51
+ [[0], []]
52
+ sage: to_fast_pickable([x(0)])
53
+ [[2], [(0, 1, 0)]]
54
+ sage: to_fast_pickable([x(0)*x(1)+x(1)])
55
+ [[2], [(0, 3, 3), (1, 1, 0)]]
56
+ sage: to_fast_pickable([x(1)])
57
+ [[2], [(1, 1, 0)]]
58
+ sage: to_fast_pickable([x(0)+1])
59
+ [[2], [(0, 1, 1)]]
60
+ sage: to_fast_pickable([x(0)*x(1)])
61
+ [[2], [(0, 3, 0), (1, 1, 0)]]
62
+ sage: to_fast_pickable([x(0)*x(1)+x(1)])
63
+ [[2], [(0, 3, 3), (1, 1, 0)]]
64
+ sage: to_fast_pickable([x(0)*x(1)+x(2)])
65
+ [[2], [(0, 3, 4), (1, 1, 0), (2, 1, 0)]]
66
+ sage: p=x(5)*x(23) + x(5)*x(24)*x(59) + x(5) + x(6)*x(23)*x(89) + x(6)*x(60)*x(89) + x(23) + x(24)*x(89) + x(24) + x(60)*x(89) + x(89) + 1
67
+ sage: from_fast_pickable(to_fast_pickable([p]), r)==[p]
68
+ True
69
+ sage: to_fast_pickable([x(0)*x(1), Polynomial(0, r), Polynomial(1, r), x(3)])
70
+ [[2, 0, 1, 4], [(0, 3, 0), (1, 1, 0), (3, 1, 0)]]
71
+ """
72
+ if not l:
73
+ return [[], []]
74
+
75
+ f = l[0]
76
+ f = f.set()
77
+ r = f.ring()
78
+ one = r.one().navigation()
79
+ zero = r.zero().navigation()
80
+ nodes = set()
81
+
82
+ def find_navs(nav):
83
+ if nav not in nodes and not nav.constant():
84
+ nodes.add(nav)
85
+ find_navs(nav.then_branch())
86
+ find_navs(nav.else_branch())
87
+ for f in l:
88
+ f_nav = f.set().navigation()
89
+ find_navs(f_nav)
90
+
91
+ nodes_sorted = sorted(nodes, key=CCuddNavigator.value)
92
+ nodes2i = {one: 1, zero: 0}
93
+ for (i, n) in enumerate(nodes_sorted):
94
+ nodes2i[n] = i + 2
95
+
96
+ for i in range(len(nodes_sorted)):
97
+ n = nodes_sorted[i]
98
+ t = nodes2i[n.then_branch()]
99
+ e = nodes2i[n.else_branch()]
100
+ nodes_sorted[i] = (n.value(), t, e)
101
+
102
+ return [[nodes2i[f.set().navigation()] for f in l], nodes_sorted]
103
+
104
+
105
+ def from_fast_pickable(l, r):
106
+ r"""
107
+ Undo the operation :func:`to_fast_pickable`.
108
+
109
+ The first argument is an object created by :func:`to_fast_pickable`.
110
+
111
+ For the specified format, see the documentation of :func:`to_fast_pickable`.
112
+ The second argument is ring, in which this polynomial should be created.
113
+
114
+ INPUT:
115
+
116
+ See OUTPUT of :func:`to_fast_pickable`.
117
+
118
+ OUTPUT: list of Boolean polynomials
119
+
120
+ EXAMPLES::
121
+
122
+ sage: from sage.rings.polynomial.pbori import Ring
123
+ sage: from sage.rings.polynomial.pbori.parallel import from_fast_pickable
124
+ sage: r = Ring(1000)
125
+ sage: x = r.variable
126
+ sage: from_fast_pickable([[1], []], r)
127
+ [1]
128
+ sage: from_fast_pickable([[0], []], r)
129
+ [0]
130
+ sage: from_fast_pickable([[2], [(0, 1, 0)]], r)
131
+ [x(0)]
132
+ sage: from_fast_pickable([[2], [(1, 1, 0)]], r)
133
+ [x(1)]
134
+ sage: from_fast_pickable([[2], [(0, 1, 1)]], r)
135
+ [x(0) + 1]
136
+ sage: from_fast_pickable([[2], [(0, 3, 0), (1, 1, 0)]], r)
137
+ [x(0)*x(1)]
138
+ sage: from_fast_pickable([[2], [(0, 3, 3), (1, 1, 0)]], r)
139
+ [x(0)*x(1) + x(1)]
140
+ sage: from_fast_pickable([[2], [(0, 3, 4), (1, 1, 0), (2, 1, 0)]], r)
141
+ [x(0)*x(1) + x(2)]
142
+ sage: from_fast_pickable([[2, 0, 1, 4], [(0, 3, 0), (1, 1, 0), (3, 1, 0)]], r)
143
+ [x(0)*x(1), 0, 1, x(3)]
144
+ """
145
+ i2poly = {0: r.zero(), 1: r.one()}
146
+ (indices, terms) = l
147
+
148
+ for i in reversed(range(len(terms))):
149
+ (v, t, e) = terms[i]
150
+ t = i2poly[t]
151
+ e = i2poly[e]
152
+ terms[i] = if_then_else(v, t, e)
153
+ i2poly[i + 2] = terms[i]
154
+ return [Polynomial(i2poly[i]) for i in indices]
155
+
156
+
157
+ def _calculate_gb_with_keywords(args):
158
+ (I, kwds_as_single_arg) = args
159
+ return groebner_basis(I, **kwds_as_single_arg)
160
+
161
+
162
+ def _decode_polynomial(code):
163
+ return from_fast_pickable(*code)[0]
164
+
165
+
166
+ def _encode_polynomial(poly):
167
+ return (to_fast_pickable([poly]), poly.ring())
168
+
169
+
170
+ def pickle_polynomial(self):
171
+ return (_decode_polynomial, (_encode_polynomial(self), ))
172
+
173
+
174
+ copyreg.pickle(Polynomial, pickle_polynomial)
175
+
176
+
177
+ def pickle_bset(self):
178
+ return (BooleSet, (Polynomial(self), ))
179
+
180
+
181
+ copyreg.pickle(BooleSet, pickle_bset)
182
+
183
+
184
+ def pickle_monom(self):
185
+ return (Monomial, (list(self.variables()),))
186
+
187
+
188
+ copyreg.pickle(Monomial, pickle_monom)
189
+
190
+
191
+ def pickle_var(self):
192
+ return (Variable, (self.index(), self.ring()))
193
+
194
+
195
+ copyreg.pickle(Variable, pickle_var)
196
+
197
+
198
+ def _decode_ring(code):
199
+ import os
200
+ (identifier, data, varnames, blocks) = code
201
+
202
+ global _polybori_parallel_rings
203
+ try:
204
+ _polybori_parallel_rings
205
+ except NameError:
206
+ _polybori_parallel_rings = {}
207
+
208
+ for key in [key for key in _polybori_parallel_rings
209
+ if not _polybori_parallel_rings[key][0]()]:
210
+ del _polybori_parallel_rings[key]
211
+
212
+ if identifier in _polybori_parallel_rings:
213
+ ring = _polybori_parallel_rings[identifier][0]()
214
+ else:
215
+ ring = None
216
+
217
+ if not ring:
218
+ varnames = decompress(varnames).split('\n')
219
+ (nvars, ordercode) = data
220
+ ring = Ring(nvars, ordercode, names=varnames, blocks=blocks)
221
+ storage_data = (WeakRingRef(ring), code)
222
+ _polybori_parallel_rings[identifier] = storage_data
223
+ _polybori_parallel_rings[(ring.id(), os.getpid())] = storage_data
224
+
225
+ return ring
226
+
227
+
228
+ def _encode_ring(ring):
229
+ import os
230
+ identifier = (ring.id(), os.getpid())
231
+
232
+ global _polybori_parallel_rings
233
+ try:
234
+ _polybori_parallel_rings
235
+ except NameError:
236
+ _polybori_parallel_rings = {}
237
+
238
+ for key in [key for key in _polybori_parallel_rings
239
+ if not _polybori_parallel_rings[key][0]()]:
240
+ del _polybori_parallel_rings[key]
241
+
242
+ if identifier in _polybori_parallel_rings:
243
+ code = _polybori_parallel_rings[identifier][1]
244
+ else:
245
+ nvars = ring.n_variables()
246
+ data = (nvars, ring.get_order_code())
247
+ varnames = '\n'.join(str(ring.variable(idx))
248
+ for idx in range(nvars))
249
+ blocks = list(ring.blocks())
250
+ code = (identifier, data, compress(varnames), blocks[:-1])
251
+ _polybori_parallel_rings[identifier] = (WeakRingRef(ring), code)
252
+
253
+ return code
254
+
255
+
256
+ def pickle_ring(self):
257
+ return (_decode_ring, (_encode_ring(self), ))
258
+
259
+
260
+ copyreg.pickle(Ring, pickle_ring)
261
+
262
+
263
+ def groebner_basis_first_finished(I, *l):
264
+ r"""
265
+
266
+ INPUT:
267
+
268
+ - ``I`` -- ideal
269
+ - ``l`` -- keyword dictionaries, which will be keyword arguments to
270
+ ``groebner_basis``
271
+
272
+ OUTPUT:
273
+
274
+ - tries to compute ``groebner_basis(I, **kwd)`` for kwd in l
275
+ - returns the result of the first terminated computation
276
+
277
+ EXAMPLES::
278
+
279
+ sage: from sage.rings.polynomial.pbori.PyPolyBoRi import Ring
280
+ sage: r = Ring(1000)
281
+ sage: ideal = [r.variable(1)*r.variable(2)+r.variable(2)+r.variable(1)]
282
+ sage: from sage.rings.polynomial.pbori.parallel import groebner_basis_first_finished
283
+ sage: groebner_basis_first_finished(ideal, dict(heuristic=True), dict(heuristic=False))
284
+ [x1, x2]
285
+ """
286
+ if not I:
287
+ return []
288
+
289
+ from multiprocessing import Pool
290
+
291
+ pool = Pool(processes=len(l))
292
+ it = pool.imap_unordered(_calculate_gb_with_keywords,
293
+ [(I, kwds) for kwds in l])
294
+ res = next(it)
295
+
296
+ pool.terminate()
297
+
298
+ return res
@@ -0,0 +1,127 @@
1
+ # sage_setup: distribution = sagemath-brial
2
+ from libcpp.memory cimport unique_ptr, shared_ptr, make_shared
3
+
4
+ from sage.rings.polynomial.multi_polynomial_ring_base cimport MPolynomialRing_base, BooleanPolynomialRing_base
5
+ from sage.rings.polynomial.multi_polynomial cimport MPolynomial
6
+ from sage.structure.element cimport MonoidElement
7
+
8
+ from sage.libs.polybori.decl cimport *
9
+
10
+
11
+ cdef class BooleanPolynomialRing(BooleanPolynomialRing_base):
12
+ cdef PBRing _pbring
13
+ cdef Py_ssize_t* pbind
14
+ cdef public _monom_monoid
15
+ cdef public object __interface
16
+ cdef object _repr
17
+
18
+ # it is very important to keep this cached, since otherwise the magma interface will break
19
+ cdef public object __cover_ring
20
+
21
+ cdef _convert(self, rhs)
22
+
23
+ cdef class BooleanPolynomial(MPolynomial):
24
+ cdef PBPoly _pbpoly
25
+ cpdef _add_(self, other)
26
+ cpdef _mul_(self, other)
27
+
28
+ cdef class BooleSet:
29
+ cdef BooleanPolynomialRing _ring
30
+ cdef PBSet _pbset
31
+
32
+ cdef class CCuddNavigator:
33
+ cdef PBNavigator _pbnav
34
+ cdef Py_ssize_t* _pbind
35
+
36
+ cdef class BooleanMonomial(MonoidElement):
37
+ cdef PBMonom _pbmonom
38
+ cdef BooleanPolynomialRing _ring
39
+ cpdef _mul_(self, other)
40
+
41
+ cdef class BooleanMonomialVariableIterator:
42
+ cdef object parent
43
+ cdef BooleanPolynomialRing _ring
44
+ cdef BooleanMonomial obj
45
+ cdef PBMonomIter _iter
46
+ cdef PBMonomIter _end
47
+ cdef Py_ssize_t* pbind
48
+
49
+ cdef class BooleanMonomialIterator:
50
+ cdef BooleanMonomial obj
51
+ cdef PBMonomIter _iter
52
+ cdef PBMonomIter _end
53
+ cdef Py_ssize_t* pbind
54
+
55
+ # Wrap PBPolyIter using pointers because there is no default constructor
56
+ cdef class BooleanPolynomialIterator:
57
+ cdef BooleanPolynomial obj
58
+ cdef PBPolyIter* _iter
59
+ cdef PBPolyIter* _end
60
+
61
+ # Wrap PBSetIter using pointers because there is no default constructor
62
+ cdef class BooleSetIterator:
63
+ cdef object _parent
64
+ cdef BooleanPolynomialRing _ring
65
+ cdef PBSetIter* _iter
66
+ cdef PBSetIter* _end
67
+ cdef BooleSet obj
68
+
69
+ cdef class BooleanPolynomialEntry:
70
+ cdef public BooleanPolynomial p
71
+
72
+ # Wrap PBRedStrategy using shared_ptr because there is no default
73
+ # constructor and because multiple Python objects may point to
74
+ # the same PBRedStrategy
75
+ cdef class ReductionStrategy:
76
+ cdef shared_ptr[PBRedStrategy] _strat
77
+ cdef BooleanPolynomialRing _parent
78
+
79
+ # Wrap PBGBStrategy using shared_ptr because there is no default
80
+ # constructor and because multiple Python objects may point to
81
+ # the same PBGBStrategy
82
+ cdef class GroebnerStrategy:
83
+ cdef shared_ptr[PBGBStrategy] _strat
84
+ cdef BooleanPolynomialRing _parent
85
+ cdef public ReductionStrategy reduction_strategy
86
+
87
+ # Wrap PBFGLMStrategy using unique_ptr for analogy with
88
+ # ReductionStrategy and GroebnerStrategy
89
+ cdef class FGLMStrategy:
90
+ cdef unique_ptr[PBFGLMStrategy] _strat
91
+ cdef BooleanPolynomialRing _parent
92
+
93
+ cdef class BooleanPolynomialVector:
94
+ cdef PBPolyVector _vec
95
+ cdef BooleanPolynomialRing _parent
96
+
97
+ cdef class BooleanPolynomialVectorIterator:
98
+ cdef BooleanPolynomialVector obj
99
+ cdef BooleanPolynomialRing _parent
100
+ cdef PBPolyVectorIter _iter
101
+ cdef PBPolyVectorIter _end
102
+
103
+ cdef class VariableBlock:
104
+ cdef BooleanPolynomialRing _ring
105
+ cdef PBVarBlock* _block
106
+ cdef public object __name__
107
+
108
+ cdef class BooleConstant:
109
+ cdef PBConstant _pbconst
110
+
111
+ cdef class VariableFactory:
112
+ cdef BooleanPolynomialRing _ring
113
+ cdef PBVarFactory _factory
114
+
115
+ cdef class MonomialFactory:
116
+ cdef BooleanPolynomialRing _ring
117
+ cdef PBMonomFactory _factory
118
+
119
+ cdef class PolynomialFactory:
120
+ cdef BooleanPolynomialRing _ring
121
+ cdef PBPolyFactory _factory
122
+
123
+
124
+ # Cython doesn't seem to support constructors with additional template
125
+ # parameters, so we declare this aliasing constructor as special case
126
+ cdef extern from *:
127
+ cdef shared_ptr[T] shared_ptr_alias_PBGBStrategy "std::shared_ptr"[T](shared_ptr[PBGBStrategy]&, T*)