Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/sage/databases/symbolic_data.py
8814 views
1
"""
2
Ideals from the Symbolic Data project
3
4
This file implements a thin wrapper for the optional symbolic data set
5
of ideals as published on http://www.symbolicdata.org . From the
6
project website:
7
8
For different purposes algorithms and implementations are tested
9
on certified and reliable data. The development of tools and data
10
for such tests is usually 'orthogonal' to the main
11
implementation efforts, it requires different skills and
12
technologies and is not loved by programmers. On the other hand,
13
in many cases tools and data could easily be reused - with slight
14
modifications - across similar projects. The SymbolicData Project
15
is set out to coordinate such efforts within the Computer Algebra
16
Community. Commonly collected certified and reliable data can
17
also be used to compare otherwise incomparable approaches,
18
algorithms, and implementations. Benchmark suites and Challenges
19
for symbolic computations are not as well established as in other
20
areas of computer science. This is probably due to the fact that
21
there are not yet well agreed aims of such a
22
benchmarking. Nevertheless various (often high quality) special
23
benchmarks are scattered through the literature. During the last
24
years efforts toward collection of test data for symbolic
25
computations were intensified. They focused mainly on the creation
26
of general benchmarks for different areas of symbolic computation
27
and the collection of such activities on different Web site. For
28
further qualification of these efforts it would be of great
29
benefit to create a commonly available digital archive of these
30
special benchmark data scattered through the literature. This
31
would provide the community with an electronic repository of
32
certified data that could be addressed and extended during further
33
development.
34
35
EXAMPLES::
36
37
sage: sd = SymbolicData(); sd # optional - database_symbolic_data
38
SymbolicData with 372 ideals
39
40
sage: sd.ZeroDim__example_1 # optional - database_symbolic_data
41
Ideal (x1^2 + x2^2 - 10, x1^2 + x1*x2 + 2*x2^2 - 16) of Multivariate Polynomial Ring in x1, x2 over Rational Field
42
43
sage: sd.Katsura_3 # optional - database_symbolic_data
44
Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
45
u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
46
2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
47
u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Rational Field
48
49
sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional - database_symbolic_data
50
Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
51
u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
52
2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
53
u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Finite Field of size 127
54
55
AUTHORS:
56
57
- Martin Albrecht <[email protected]>
58
"""
59
import os
60
from xml.dom.minidom import parse
61
from sage.rings.rational_field import QQ
62
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
63
64
class SymbolicData:
65
"""
66
Database of ideals as distributed by the The SymbolicData Project
67
(http://symbolicdata.org).
68
69
This class needs the optional ``database_symbolic_data`` package to be
70
installed.
71
"""
72
def __init__(self):
73
"""
74
EXAMPLES:
75
sage: sd = SymbolicData(); sd # optional - database_symbolic_data
76
SymbolicData with 372 ideals
77
"""
78
from sage.misc.misc import SAGE_SHARE
79
path = os.path.join(SAGE_SHARE, 'symbolic_data')
80
self.__intpath = path + "/Data/XMLResources/INTPS/"
81
self.__genpath = path + "/Data/XMLResources/GenPS/"
82
83
def get_ideal(self, name, base_ring=QQ, term_order="degrevlex"):
84
"""
85
Returns the ideal given by 'name' over the base ring given by
86
'base_ring' in a polynomial ring with the term order given by
87
'term_order'.
88
89
INPUT:
90
91
- ``name`` - name as on the symbolic data website
92
- ``base_ring`` - base ring for the polynomial ring (default: ``QQ``)
93
- ``term_order`` - term order for the polynomial ring (default: ``degrevlex``)
94
95
OUTPUT:
96
97
ideal as given by ``name`` in ``PolynomialRing(base_ring,vars,term_order)``
98
99
EXAMPLES::
100
101
sage: sd = SymbolicData() # optional - database_symbolic_data
102
sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional - database_symbolic_data
103
Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
104
u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
105
2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
106
u0^2 + 2*u1^2 + 2*u2^2 + 2*u3^2 - u0) of Multivariate Polynomial Ring in u0, u1, u2, u3 over Finite Field of size 127
107
"""
108
109
def _getTextFromNode(node):
110
t = ""
111
for n in node.childNodes:
112
if n.nodeType == n.TEXT_NODE:
113
t += str(n.nodeValue)
114
else:
115
raise NotTextNodeError
116
return t
117
118
def _dom2ideal(node):
119
"""
120
"""
121
l = []
122
123
if str(node.nodeName) in ['vars','poly']:
124
l.append(_getTextFromNode(node))
125
126
for c in node.childNodes:
127
l += _dom2ideal(c)
128
129
return l
130
131
orig_name = name
132
name = name.replace('__','.')
133
134
try:
135
name = self.__intpath + name + ".xml"
136
open(name)
137
except IOError:
138
try:
139
name = self.__genpath + name + ".xml"
140
open(name)
141
except IOError:
142
raise AttributeError("No ideal matching '%s' found in database."%orig_name)
143
144
dom = parse(name)
145
res = _dom2ideal(dom)
146
variables, polys = res[0].replace("_",""), [p.replace("_","") for p in res[1:]]
147
148
P = PolynomialRing(base_ring, len(variables.split(",")), variables)
149
I = P.ideal([P(f) for f in polys])
150
return I
151
152
153
def __repr__(self):
154
"""
155
EXAMPLES::
156
157
sage: sd = SymbolicData(); sd # optional - database_symbolic_data
158
SymbolicData with 372 ideals
159
"""
160
try:
161
l = len(self.trait_names())
162
except AttributeError:
163
l = 0
164
return "SymbolicData with %d ideals"%l
165
166
def __getattr__(self, name):
167
"""
168
EXAMPLES::
169
170
sage: sd = SymbolicData() # optional - database_symbolic_data
171
sage: sd.Cyclic5 # optional - database_symbolic_data
172
Traceback (most recent call last):
173
...
174
AttributeError: No ideal matching 'Cyclic5' found in database.
175
176
sage: sd.Cyclic_5 # optional - database_symbolic_data
177
Ideal (v + w + x + y + z,
178
v*w + w*x + x*y + v*z + y*z,
179
v*w*x + w*x*y + v*w*z + v*y*z + x*y*z,
180
v*w*x*y + v*w*x*z + v*w*y*z + v*x*y*z + w*x*y*z,
181
v*w*x*y*z - 1) of Multivariate Polynomial Ring in v, w, x, y, z over Rational Field
182
"""
183
return self.get_ideal(name)
184
185
def trait_names(self):
186
"""
187
EXAMPLES::
188
189
sage: sd = SymbolicData() # optional - database_symbolic_data
190
sage: sorted(sd.trait_names())[:10] # optional - database_symbolic_data
191
['Bjoerk_8',
192
'Bronstein-86',
193
'Buchberger-87',
194
'Butcher',
195
'Caprasse',
196
'Cassou',
197
'Cohn_2',
198
'Curves__curve10_20',
199
'Curves__curve10_20',
200
'Curves__curve10_30']
201
"""
202
if hasattr(self,"__ideals"): return self.__ideals
203
try:
204
__ideals = [s.replace('.xml','') for s in os.listdir(self.__intpath)]
205
__ideals += [s.replace('.xml','') for s in os.listdir(self.__genpath)]
206
self.__ideals = [s.replace('.', '__') for s in __ideals]
207
return self.__ideals
208
except OSError:
209
raise AttributeError("Could not find symbolic data, you should perhaps install the optional package")
210
211