Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/databases/symbolic_data.py
6915 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
path=os.environ["SAGE_ROOT"]+"/data/symbolic_data"
79
self.__intpath = path + "/Data/XMLResources/INTPS/"
80
self.__genpath = path + "/Data/XMLResources/GenPS/"
81
82
def get_ideal(self, name, base_ring=QQ, term_order="degrevlex"):
83
"""
84
Returns the ideal given by 'name' over the base ring given by
85
'base_ring' in a polynomial ring with the term order given by
86
'term_order'.
87
88
INPUT:
89
90
- ``name`` - name as on the symbolic data website
91
- ``base_ring`` - base ring for the polynomial ring (default: ``QQ``)
92
- ``term_order`` - term order for the polynomial ring (default: ``degrevlex``)
93
94
OUTPUT:
95
96
ideal as given by ``name`` in ``PolynomialRing(base_ring,vars,term_order)``
97
98
EXAMPLES::
99
100
sage: sd = SymbolicData() # optional - database_symbolic_data
101
sage: sd.get_ideal('Katsura_3',GF(127),'degrevlex') # optional - database_symbolic_data
102
Ideal (u0 + 2*u1 + 2*u2 + 2*u3 - 1,
103
u1^2 + 2*u0*u2 + 2*u1*u3 - u2,
104
2*u0*u1 + 2*u1*u2 + 2*u2*u3 - u1,
105
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
106
"""
107
108
def _getTextFromNode(node):
109
t = ""
110
for n in node.childNodes:
111
if n.nodeType == n.TEXT_NODE:
112
t += str(n.nodeValue)
113
else:
114
raise NotTextNodeError
115
return t
116
117
def _dom2ideal(node):
118
"""
119
"""
120
l = []
121
122
if str(node.nodeName) in ['vars','poly']:
123
l.append(_getTextFromNode(node))
124
125
for c in node.childNodes:
126
l += _dom2ideal(c)
127
128
return l
129
130
orig_name = name
131
name = name.replace('__','.')
132
133
try:
134
name = self.__intpath + name + ".xml"
135
open(name)
136
except IOError:
137
try:
138
name = self.__genpath + name + ".xml"
139
open(name)
140
except IOError:
141
raise AttributeError("No ideal matching '%s' found in database."%orig_name)
142
143
dom = parse(name)
144
res = _dom2ideal(dom)
145
variables, polys = res[0].replace("_",""), [p.replace("_","") for p in res[1:]]
146
147
P = PolynomialRing(base_ring, len(variables.split(",")), variables)
148
I = P.ideal([P(f) for f in polys])
149
return I
150
151
152
def __repr__(self):
153
"""
154
EXAMPLES::
155
156
sage: sd = SymbolicData(); sd # optional - database_symbolic_data
157
SymbolicData with 372 ideals
158
"""
159
try:
160
l = len(self.trait_names())
161
except AttributeError:
162
l = 0
163
return "SymbolicData with %d ideals"%l
164
165
def __getattr__(self, name):
166
"""
167
EXAMPLES::
168
169
sage: sd = SymbolicData() # optional - database_symbolic_data
170
sage: sd.Cyclic5 # optional - database_symbolic_data
171
Traceback (most recent call last):
172
...
173
AttributeError: No ideal matching 'Cyclic5' found in database.
174
175
sage: sd.Cyclic_5 # optional - database_symbolic_data
176
Ideal (v + w + x + y + z,
177
v*w + w*x + x*y + v*z + y*z,
178
v*w*x + w*x*y + v*w*z + v*y*z + x*y*z,
179
v*w*x*y + v*w*x*z + v*w*y*z + v*x*y*z + w*x*y*z,
180
v*w*x*y*z - 1) of Multivariate Polynomial Ring in v, w, x, y, z over Rational Field
181
"""
182
return self.get_ideal(name)
183
184
def trait_names(self):
185
"""
186
EXAMPLES::
187
188
sage: sd = SymbolicData() # optional - database_symbolic_data
189
sage: sorted(sd.trait_names())[:10] # optional - database_symbolic_data
190
['Bjoerk_8',
191
'Bronstein-86',
192
'Buchberger-87',
193
'Butcher',
194
'Caprasse',
195
'Cassou',
196
'Cohn_2',
197
'Curves__curve10_20',
198
'Curves__curve10_20',
199
'Curves__curve10_30']
200
"""
201
if hasattr(self,"__ideals"): return self.__ideals
202
try:
203
__ideals = [s.replace('.xml','') for s in os.listdir(self.__intpath)]
204
__ideals += [s.replace('.xml','') for s in os.listdir(self.__genpath)]
205
self.__ideals = [s.replace('.', '__') for s in __ideals]
206
return self.__ideals
207
except OSError:
208
raise AttributeError, "Could not find symbolic data, you should perhaps install the optional package"
209
210