Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- llmeval-env/lib/python3.10/site-packages/nvidia/cusparse/lib/libcusparse.so.12 +3 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__init__.py +5 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/extensions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/homomorphisms.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/ideals.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/modules.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/extensions.py +346 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/homomorphisms.py +691 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/ideals.py +394 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/modules.py +1484 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__init__.py +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_appellseqs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_constructor.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densearith.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densebasic.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densetools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_dispersion.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_distributedmodules.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_euclidtools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_factortools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_fields.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_galoistools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_groebnertools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_heuristicgcd.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_injections.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_modulargcd.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_monomials.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_multivariate_resultants.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orderings.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orthopolys.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_partfrac.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyclasses.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyfuncs.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polymatrix.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyoptions.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyroots.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polytools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyutils.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_pythonrational.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rationaltools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_ring_series.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rings.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rootisolation.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rootoftools.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_solvers.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_specialpolys.cpython-310.pyc +0 -0
- llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_sqfreetools.cpython-310.pyc +0 -0
.gitattributes
CHANGED
@@ -188,3 +188,4 @@ env-llmeval/lib/python3.10/site-packages/pyarrow/libarrow_flight.so.1500 filter=
|
|
188 |
llmeval-env/lib/python3.10/site-packages/scipy/stats/_unuran/unuran_wrapper.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
189 |
llmeval-env/lib/python3.10/site-packages/nvidia/cudnn/lib/libcudnn_adv_infer.so.8 filter=lfs diff=lfs merge=lfs -text
|
190 |
llmeval-env/lib/python3.10/site-packages/nvidia/nccl/lib/libnccl.so.2 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
188 |
llmeval-env/lib/python3.10/site-packages/scipy/stats/_unuran/unuran_wrapper.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
189 |
llmeval-env/lib/python3.10/site-packages/nvidia/cudnn/lib/libcudnn_adv_infer.so.8 filter=lfs diff=lfs merge=lfs -text
|
190 |
llmeval-env/lib/python3.10/site-packages/nvidia/nccl/lib/libnccl.so.2 filter=lfs diff=lfs merge=lfs -text
|
191 |
+
llmeval-env/lib/python3.10/site-packages/nvidia/cusparse/lib/libcusparse.so.12 filter=lfs diff=lfs merge=lfs -text
|
llmeval-env/lib/python3.10/site-packages/nvidia/cusparse/lib/libcusparse.so.12
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:500466a2f559de622a71bb920d3d2923e69135245747a2742ee13edff0ba6085
|
3 |
+
size 264876688
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__init__.py
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Module for algebraic geometry and commutative algebra."""
|
2 |
+
|
3 |
+
from .homomorphisms import homomorphism
|
4 |
+
|
5 |
+
__all__ = ['homomorphism']
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (332 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/extensions.cpython-310.pyc
ADDED
Binary file (10.6 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/homomorphisms.cpython-310.pyc
ADDED
Binary file (25.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/ideals.cpython-310.pyc
ADDED
Binary file (13.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/__pycache__/modules.cpython-310.pyc
ADDED
Binary file (52.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/extensions.py
ADDED
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Finite extensions of ring domains."""
|
2 |
+
|
3 |
+
from sympy.polys.domains.domain import Domain
|
4 |
+
from sympy.polys.domains.domainelement import DomainElement
|
5 |
+
from sympy.polys.polyerrors import (CoercionFailed, NotInvertible,
|
6 |
+
GeneratorsError)
|
7 |
+
from sympy.polys.polytools import Poly
|
8 |
+
from sympy.printing.defaults import DefaultPrinting
|
9 |
+
|
10 |
+
|
11 |
+
class ExtensionElement(DomainElement, DefaultPrinting):
|
12 |
+
"""
|
13 |
+
Element of a finite extension.
|
14 |
+
|
15 |
+
A class of univariate polynomials modulo the ``modulus``
|
16 |
+
of the extension ``ext``. It is represented by the
|
17 |
+
unique polynomial ``rep`` of lowest degree. Both
|
18 |
+
``rep`` and the representation ``mod`` of ``modulus``
|
19 |
+
are of class DMP.
|
20 |
+
|
21 |
+
"""
|
22 |
+
__slots__ = ('rep', 'ext')
|
23 |
+
|
24 |
+
def __init__(self, rep, ext):
|
25 |
+
self.rep = rep
|
26 |
+
self.ext = ext
|
27 |
+
|
28 |
+
def parent(f):
|
29 |
+
return f.ext
|
30 |
+
|
31 |
+
def __bool__(f):
|
32 |
+
return bool(f.rep)
|
33 |
+
|
34 |
+
def __pos__(f):
|
35 |
+
return f
|
36 |
+
|
37 |
+
def __neg__(f):
|
38 |
+
return ExtElem(-f.rep, f.ext)
|
39 |
+
|
40 |
+
def _get_rep(f, g):
|
41 |
+
if isinstance(g, ExtElem):
|
42 |
+
if g.ext == f.ext:
|
43 |
+
return g.rep
|
44 |
+
else:
|
45 |
+
return None
|
46 |
+
else:
|
47 |
+
try:
|
48 |
+
g = f.ext.convert(g)
|
49 |
+
return g.rep
|
50 |
+
except CoercionFailed:
|
51 |
+
return None
|
52 |
+
|
53 |
+
def __add__(f, g):
|
54 |
+
rep = f._get_rep(g)
|
55 |
+
if rep is not None:
|
56 |
+
return ExtElem(f.rep + rep, f.ext)
|
57 |
+
else:
|
58 |
+
return NotImplemented
|
59 |
+
|
60 |
+
__radd__ = __add__
|
61 |
+
|
62 |
+
def __sub__(f, g):
|
63 |
+
rep = f._get_rep(g)
|
64 |
+
if rep is not None:
|
65 |
+
return ExtElem(f.rep - rep, f.ext)
|
66 |
+
else:
|
67 |
+
return NotImplemented
|
68 |
+
|
69 |
+
def __rsub__(f, g):
|
70 |
+
rep = f._get_rep(g)
|
71 |
+
if rep is not None:
|
72 |
+
return ExtElem(rep - f.rep, f.ext)
|
73 |
+
else:
|
74 |
+
return NotImplemented
|
75 |
+
|
76 |
+
def __mul__(f, g):
|
77 |
+
rep = f._get_rep(g)
|
78 |
+
if rep is not None:
|
79 |
+
return ExtElem((f.rep * rep) % f.ext.mod, f.ext)
|
80 |
+
else:
|
81 |
+
return NotImplemented
|
82 |
+
|
83 |
+
__rmul__ = __mul__
|
84 |
+
|
85 |
+
def _divcheck(f):
|
86 |
+
"""Raise if division is not implemented for this divisor"""
|
87 |
+
if not f:
|
88 |
+
raise NotInvertible('Zero divisor')
|
89 |
+
elif f.ext.is_Field:
|
90 |
+
return True
|
91 |
+
elif f.rep.is_ground and f.ext.domain.is_unit(f.rep.rep[0]):
|
92 |
+
return True
|
93 |
+
else:
|
94 |
+
# Some cases like (2*x + 2)/2 over ZZ will fail here. It is
|
95 |
+
# unclear how to implement division in general if the ground
|
96 |
+
# domain is not a field so for now it was decided to restrict the
|
97 |
+
# implementation to division by invertible constants.
|
98 |
+
msg = (f"Can not invert {f} in {f.ext}. "
|
99 |
+
"Only division by invertible constants is implemented.")
|
100 |
+
raise NotImplementedError(msg)
|
101 |
+
|
102 |
+
def inverse(f):
|
103 |
+
"""Multiplicative inverse.
|
104 |
+
|
105 |
+
Raises
|
106 |
+
======
|
107 |
+
|
108 |
+
NotInvertible
|
109 |
+
If the element is a zero divisor.
|
110 |
+
|
111 |
+
"""
|
112 |
+
f._divcheck()
|
113 |
+
|
114 |
+
if f.ext.is_Field:
|
115 |
+
invrep = f.rep.invert(f.ext.mod)
|
116 |
+
else:
|
117 |
+
R = f.ext.ring
|
118 |
+
invrep = R.exquo(R.one, f.rep)
|
119 |
+
|
120 |
+
return ExtElem(invrep, f.ext)
|
121 |
+
|
122 |
+
def __truediv__(f, g):
|
123 |
+
rep = f._get_rep(g)
|
124 |
+
if rep is None:
|
125 |
+
return NotImplemented
|
126 |
+
g = ExtElem(rep, f.ext)
|
127 |
+
|
128 |
+
try:
|
129 |
+
ginv = g.inverse()
|
130 |
+
except NotInvertible:
|
131 |
+
raise ZeroDivisionError(f"{f} / {g}")
|
132 |
+
|
133 |
+
return f * ginv
|
134 |
+
|
135 |
+
__floordiv__ = __truediv__
|
136 |
+
|
137 |
+
def __rtruediv__(f, g):
|
138 |
+
try:
|
139 |
+
g = f.ext.convert(g)
|
140 |
+
except CoercionFailed:
|
141 |
+
return NotImplemented
|
142 |
+
return g / f
|
143 |
+
|
144 |
+
__rfloordiv__ = __rtruediv__
|
145 |
+
|
146 |
+
def __mod__(f, g):
|
147 |
+
rep = f._get_rep(g)
|
148 |
+
if rep is None:
|
149 |
+
return NotImplemented
|
150 |
+
g = ExtElem(rep, f.ext)
|
151 |
+
|
152 |
+
try:
|
153 |
+
g._divcheck()
|
154 |
+
except NotInvertible:
|
155 |
+
raise ZeroDivisionError(f"{f} % {g}")
|
156 |
+
|
157 |
+
# Division where defined is always exact so there is no remainder
|
158 |
+
return f.ext.zero
|
159 |
+
|
160 |
+
def __rmod__(f, g):
|
161 |
+
try:
|
162 |
+
g = f.ext.convert(g)
|
163 |
+
except CoercionFailed:
|
164 |
+
return NotImplemented
|
165 |
+
return g % f
|
166 |
+
|
167 |
+
def __pow__(f, n):
|
168 |
+
if not isinstance(n, int):
|
169 |
+
raise TypeError("exponent of type 'int' expected")
|
170 |
+
if n < 0:
|
171 |
+
try:
|
172 |
+
f, n = f.inverse(), -n
|
173 |
+
except NotImplementedError:
|
174 |
+
raise ValueError("negative powers are not defined")
|
175 |
+
|
176 |
+
b = f.rep
|
177 |
+
m = f.ext.mod
|
178 |
+
r = f.ext.one.rep
|
179 |
+
while n > 0:
|
180 |
+
if n % 2:
|
181 |
+
r = (r*b) % m
|
182 |
+
b = (b*b) % m
|
183 |
+
n //= 2
|
184 |
+
|
185 |
+
return ExtElem(r, f.ext)
|
186 |
+
|
187 |
+
def __eq__(f, g):
|
188 |
+
if isinstance(g, ExtElem):
|
189 |
+
return f.rep == g.rep and f.ext == g.ext
|
190 |
+
else:
|
191 |
+
return NotImplemented
|
192 |
+
|
193 |
+
def __ne__(f, g):
|
194 |
+
return not f == g
|
195 |
+
|
196 |
+
def __hash__(f):
|
197 |
+
return hash((f.rep, f.ext))
|
198 |
+
|
199 |
+
def __str__(f):
|
200 |
+
from sympy.printing.str import sstr
|
201 |
+
return sstr(f.rep)
|
202 |
+
|
203 |
+
__repr__ = __str__
|
204 |
+
|
205 |
+
@property
|
206 |
+
def is_ground(f):
|
207 |
+
return f.rep.is_ground
|
208 |
+
|
209 |
+
def to_ground(f):
|
210 |
+
[c] = f.rep.to_list()
|
211 |
+
return c
|
212 |
+
|
213 |
+
ExtElem = ExtensionElement
|
214 |
+
|
215 |
+
|
216 |
+
class MonogenicFiniteExtension(Domain):
|
217 |
+
r"""
|
218 |
+
Finite extension generated by an integral element.
|
219 |
+
|
220 |
+
The generator is defined by a monic univariate
|
221 |
+
polynomial derived from the argument ``mod``.
|
222 |
+
|
223 |
+
A shorter alias is ``FiniteExtension``.
|
224 |
+
|
225 |
+
Examples
|
226 |
+
========
|
227 |
+
|
228 |
+
Quadratic integer ring $\mathbb{Z}[\sqrt2]$:
|
229 |
+
|
230 |
+
>>> from sympy import Symbol, Poly
|
231 |
+
>>> from sympy.polys.agca.extensions import FiniteExtension
|
232 |
+
>>> x = Symbol('x')
|
233 |
+
>>> R = FiniteExtension(Poly(x**2 - 2)); R
|
234 |
+
ZZ[x]/(x**2 - 2)
|
235 |
+
>>> R.rank
|
236 |
+
2
|
237 |
+
>>> R(1 + x)*(3 - 2*x)
|
238 |
+
x - 1
|
239 |
+
|
240 |
+
Finite field $GF(5^3)$ defined by the primitive
|
241 |
+
polynomial $x^3 + x^2 + 2$ (over $\mathbb{Z}_5$).
|
242 |
+
|
243 |
+
>>> F = FiniteExtension(Poly(x**3 + x**2 + 2, modulus=5)); F
|
244 |
+
GF(5)[x]/(x**3 + x**2 + 2)
|
245 |
+
>>> F.basis
|
246 |
+
(1, x, x**2)
|
247 |
+
>>> F(x + 3)/(x**2 + 2)
|
248 |
+
-2*x**2 + x + 2
|
249 |
+
|
250 |
+
Function field of an elliptic curve:
|
251 |
+
|
252 |
+
>>> t = Symbol('t')
|
253 |
+
>>> FiniteExtension(Poly(t**2 - x**3 - x + 1, t, field=True))
|
254 |
+
ZZ(x)[t]/(t**2 - x**3 - x + 1)
|
255 |
+
|
256 |
+
"""
|
257 |
+
is_FiniteExtension = True
|
258 |
+
|
259 |
+
dtype = ExtensionElement
|
260 |
+
|
261 |
+
def __init__(self, mod):
|
262 |
+
if not (isinstance(mod, Poly) and mod.is_univariate):
|
263 |
+
raise TypeError("modulus must be a univariate Poly")
|
264 |
+
|
265 |
+
# Using auto=True (default) potentially changes the ground domain to a
|
266 |
+
# field whereas auto=False raises if division is not exact. We'll let
|
267 |
+
# the caller decide whether or not they want to put the ground domain
|
268 |
+
# over a field. In most uses mod is already monic.
|
269 |
+
mod = mod.monic(auto=False)
|
270 |
+
|
271 |
+
self.rank = mod.degree()
|
272 |
+
self.modulus = mod
|
273 |
+
self.mod = mod.rep # DMP representation
|
274 |
+
|
275 |
+
self.domain = dom = mod.domain
|
276 |
+
self.ring = mod.rep.ring or dom.old_poly_ring(*mod.gens)
|
277 |
+
|
278 |
+
self.zero = self.convert(self.ring.zero)
|
279 |
+
self.one = self.convert(self.ring.one)
|
280 |
+
|
281 |
+
gen = self.ring.gens[0]
|
282 |
+
self.symbol = self.ring.symbols[0]
|
283 |
+
self.generator = self.convert(gen)
|
284 |
+
self.basis = tuple(self.convert(gen**i) for i in range(self.rank))
|
285 |
+
|
286 |
+
# XXX: It might be necessary to check mod.is_irreducible here
|
287 |
+
self.is_Field = self.domain.is_Field
|
288 |
+
|
289 |
+
def new(self, arg):
|
290 |
+
rep = self.ring.convert(arg)
|
291 |
+
return ExtElem(rep % self.mod, self)
|
292 |
+
|
293 |
+
def __eq__(self, other):
|
294 |
+
if not isinstance(other, FiniteExtension):
|
295 |
+
return False
|
296 |
+
return self.modulus == other.modulus
|
297 |
+
|
298 |
+
def __hash__(self):
|
299 |
+
return hash((self.__class__.__name__, self.modulus))
|
300 |
+
|
301 |
+
def __str__(self):
|
302 |
+
return "%s/(%s)" % (self.ring, self.modulus.as_expr())
|
303 |
+
|
304 |
+
__repr__ = __str__
|
305 |
+
|
306 |
+
def convert(self, f, base=None):
|
307 |
+
rep = self.ring.convert(f, base)
|
308 |
+
return ExtElem(rep % self.mod, self)
|
309 |
+
|
310 |
+
def convert_from(self, f, base):
|
311 |
+
rep = self.ring.convert(f, base)
|
312 |
+
return ExtElem(rep % self.mod, self)
|
313 |
+
|
314 |
+
def to_sympy(self, f):
|
315 |
+
return self.ring.to_sympy(f.rep)
|
316 |
+
|
317 |
+
def from_sympy(self, f):
|
318 |
+
return self.convert(f)
|
319 |
+
|
320 |
+
def set_domain(self, K):
|
321 |
+
mod = self.modulus.set_domain(K)
|
322 |
+
return self.__class__(mod)
|
323 |
+
|
324 |
+
def drop(self, *symbols):
|
325 |
+
if self.symbol in symbols:
|
326 |
+
raise GeneratorsError('Can not drop generator from FiniteExtension')
|
327 |
+
K = self.domain.drop(*symbols)
|
328 |
+
return self.set_domain(K)
|
329 |
+
|
330 |
+
def quo(self, f, g):
|
331 |
+
return self.exquo(f, g)
|
332 |
+
|
333 |
+
def exquo(self, f, g):
|
334 |
+
rep = self.ring.exquo(f.rep, g.rep)
|
335 |
+
return ExtElem(rep % self.mod, self)
|
336 |
+
|
337 |
+
def is_negative(self, a):
|
338 |
+
return False
|
339 |
+
|
340 |
+
def is_unit(self, a):
|
341 |
+
if self.is_Field:
|
342 |
+
return bool(a)
|
343 |
+
elif a.is_ground:
|
344 |
+
return self.domain.is_unit(a.to_ground())
|
345 |
+
|
346 |
+
FiniteExtension = MonogenicFiniteExtension
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/homomorphisms.py
ADDED
@@ -0,0 +1,691 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Computations with homomorphisms of modules and rings.
|
3 |
+
|
4 |
+
This module implements classes for representing homomorphisms of rings and
|
5 |
+
their modules. Instead of instantiating the classes directly, you should use
|
6 |
+
the function ``homomorphism(from, to, matrix)`` to create homomorphism objects.
|
7 |
+
"""
|
8 |
+
|
9 |
+
|
10 |
+
from sympy.polys.agca.modules import (Module, FreeModule, QuotientModule,
|
11 |
+
SubModule, SubQuotientModule)
|
12 |
+
from sympy.polys.polyerrors import CoercionFailed
|
13 |
+
|
14 |
+
# The main computational task for module homomorphisms is kernels.
|
15 |
+
# For this reason, the concrete classes are organised by domain module type.
|
16 |
+
|
17 |
+
|
18 |
+
class ModuleHomomorphism:
|
19 |
+
"""
|
20 |
+
Abstract base class for module homomoprhisms. Do not instantiate.
|
21 |
+
|
22 |
+
Instead, use the ``homomorphism`` function:
|
23 |
+
|
24 |
+
>>> from sympy import QQ
|
25 |
+
>>> from sympy.abc import x
|
26 |
+
>>> from sympy.polys.agca import homomorphism
|
27 |
+
|
28 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
29 |
+
>>> homomorphism(F, F, [[1, 0], [0, 1]])
|
30 |
+
Matrix([
|
31 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
32 |
+
[0, 1]])
|
33 |
+
|
34 |
+
Attributes:
|
35 |
+
|
36 |
+
- ring - the ring over which we are considering modules
|
37 |
+
- domain - the domain module
|
38 |
+
- codomain - the codomain module
|
39 |
+
- _ker - cached kernel
|
40 |
+
- _img - cached image
|
41 |
+
|
42 |
+
Non-implemented methods:
|
43 |
+
|
44 |
+
- _kernel
|
45 |
+
- _image
|
46 |
+
- _restrict_domain
|
47 |
+
- _restrict_codomain
|
48 |
+
- _quotient_domain
|
49 |
+
- _quotient_codomain
|
50 |
+
- _apply
|
51 |
+
- _mul_scalar
|
52 |
+
- _compose
|
53 |
+
- _add
|
54 |
+
"""
|
55 |
+
|
56 |
+
def __init__(self, domain, codomain):
|
57 |
+
if not isinstance(domain, Module):
|
58 |
+
raise TypeError('Source must be a module, got %s' % domain)
|
59 |
+
if not isinstance(codomain, Module):
|
60 |
+
raise TypeError('Target must be a module, got %s' % codomain)
|
61 |
+
if domain.ring != codomain.ring:
|
62 |
+
raise ValueError('Source and codomain must be over same ring, '
|
63 |
+
'got %s != %s' % (domain, codomain))
|
64 |
+
self.domain = domain
|
65 |
+
self.codomain = codomain
|
66 |
+
self.ring = domain.ring
|
67 |
+
self._ker = None
|
68 |
+
self._img = None
|
69 |
+
|
70 |
+
def kernel(self):
|
71 |
+
r"""
|
72 |
+
Compute the kernel of ``self``.
|
73 |
+
|
74 |
+
That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
|
75 |
+
`ker(\phi) = \{x \in M | \phi(x) = 0\}`. This is a submodule of `M`.
|
76 |
+
|
77 |
+
Examples
|
78 |
+
========
|
79 |
+
|
80 |
+
>>> from sympy import QQ
|
81 |
+
>>> from sympy.abc import x
|
82 |
+
>>> from sympy.polys.agca import homomorphism
|
83 |
+
|
84 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
85 |
+
>>> homomorphism(F, F, [[1, 0], [x, 0]]).kernel()
|
86 |
+
<[x, -1]>
|
87 |
+
"""
|
88 |
+
if self._ker is None:
|
89 |
+
self._ker = self._kernel()
|
90 |
+
return self._ker
|
91 |
+
|
92 |
+
def image(self):
|
93 |
+
r"""
|
94 |
+
Compute the image of ``self``.
|
95 |
+
|
96 |
+
That is, if ``self`` is the homomorphism `\phi: M \to N`, then compute
|
97 |
+
`im(\phi) = \{\phi(x) | x \in M \}`. This is a submodule of `N`.
|
98 |
+
|
99 |
+
Examples
|
100 |
+
========
|
101 |
+
|
102 |
+
>>> from sympy import QQ
|
103 |
+
>>> from sympy.abc import x
|
104 |
+
>>> from sympy.polys.agca import homomorphism
|
105 |
+
|
106 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
107 |
+
>>> homomorphism(F, F, [[1, 0], [x, 0]]).image() == F.submodule([1, 0])
|
108 |
+
True
|
109 |
+
"""
|
110 |
+
if self._img is None:
|
111 |
+
self._img = self._image()
|
112 |
+
return self._img
|
113 |
+
|
114 |
+
def _kernel(self):
|
115 |
+
"""Compute the kernel of ``self``."""
|
116 |
+
raise NotImplementedError
|
117 |
+
|
118 |
+
def _image(self):
|
119 |
+
"""Compute the image of ``self``."""
|
120 |
+
raise NotImplementedError
|
121 |
+
|
122 |
+
def _restrict_domain(self, sm):
|
123 |
+
"""Implementation of domain restriction."""
|
124 |
+
raise NotImplementedError
|
125 |
+
|
126 |
+
def _restrict_codomain(self, sm):
|
127 |
+
"""Implementation of codomain restriction."""
|
128 |
+
raise NotImplementedError
|
129 |
+
|
130 |
+
def _quotient_domain(self, sm):
|
131 |
+
"""Implementation of domain quotient."""
|
132 |
+
raise NotImplementedError
|
133 |
+
|
134 |
+
def _quotient_codomain(self, sm):
|
135 |
+
"""Implementation of codomain quotient."""
|
136 |
+
raise NotImplementedError
|
137 |
+
|
138 |
+
def restrict_domain(self, sm):
|
139 |
+
"""
|
140 |
+
Return ``self``, with the domain restricted to ``sm``.
|
141 |
+
|
142 |
+
Here ``sm`` has to be a submodule of ``self.domain``.
|
143 |
+
|
144 |
+
Examples
|
145 |
+
========
|
146 |
+
|
147 |
+
>>> from sympy import QQ
|
148 |
+
>>> from sympy.abc import x
|
149 |
+
>>> from sympy.polys.agca import homomorphism
|
150 |
+
|
151 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
152 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
153 |
+
>>> h
|
154 |
+
Matrix([
|
155 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
156 |
+
[0, 0]])
|
157 |
+
>>> h.restrict_domain(F.submodule([1, 0]))
|
158 |
+
Matrix([
|
159 |
+
[1, x], : <[1, 0]> -> QQ[x]**2
|
160 |
+
[0, 0]])
|
161 |
+
|
162 |
+
This is the same as just composing on the right with the submodule
|
163 |
+
inclusion:
|
164 |
+
|
165 |
+
>>> h * F.submodule([1, 0]).inclusion_hom()
|
166 |
+
Matrix([
|
167 |
+
[1, x], : <[1, 0]> -> QQ[x]**2
|
168 |
+
[0, 0]])
|
169 |
+
"""
|
170 |
+
if not self.domain.is_submodule(sm):
|
171 |
+
raise ValueError('sm must be a submodule of %s, got %s'
|
172 |
+
% (self.domain, sm))
|
173 |
+
if sm == self.domain:
|
174 |
+
return self
|
175 |
+
return self._restrict_domain(sm)
|
176 |
+
|
177 |
+
def restrict_codomain(self, sm):
|
178 |
+
"""
|
179 |
+
Return ``self``, with codomain restricted to to ``sm``.
|
180 |
+
|
181 |
+
Here ``sm`` has to be a submodule of ``self.codomain`` containing the
|
182 |
+
image.
|
183 |
+
|
184 |
+
Examples
|
185 |
+
========
|
186 |
+
|
187 |
+
>>> from sympy import QQ
|
188 |
+
>>> from sympy.abc import x
|
189 |
+
>>> from sympy.polys.agca import homomorphism
|
190 |
+
|
191 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
192 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
193 |
+
>>> h
|
194 |
+
Matrix([
|
195 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
196 |
+
[0, 0]])
|
197 |
+
>>> h.restrict_codomain(F.submodule([1, 0]))
|
198 |
+
Matrix([
|
199 |
+
[1, x], : QQ[x]**2 -> <[1, 0]>
|
200 |
+
[0, 0]])
|
201 |
+
"""
|
202 |
+
if not sm.is_submodule(self.image()):
|
203 |
+
raise ValueError('the image %s must contain sm, got %s'
|
204 |
+
% (self.image(), sm))
|
205 |
+
if sm == self.codomain:
|
206 |
+
return self
|
207 |
+
return self._restrict_codomain(sm)
|
208 |
+
|
209 |
+
def quotient_domain(self, sm):
|
210 |
+
"""
|
211 |
+
Return ``self`` with domain replaced by ``domain/sm``.
|
212 |
+
|
213 |
+
Here ``sm`` must be a submodule of ``self.kernel()``.
|
214 |
+
|
215 |
+
Examples
|
216 |
+
========
|
217 |
+
|
218 |
+
>>> from sympy import QQ
|
219 |
+
>>> from sympy.abc import x
|
220 |
+
>>> from sympy.polys.agca import homomorphism
|
221 |
+
|
222 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
223 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
224 |
+
>>> h
|
225 |
+
Matrix([
|
226 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
227 |
+
[0, 0]])
|
228 |
+
>>> h.quotient_domain(F.submodule([-x, 1]))
|
229 |
+
Matrix([
|
230 |
+
[1, x], : QQ[x]**2/<[-x, 1]> -> QQ[x]**2
|
231 |
+
[0, 0]])
|
232 |
+
"""
|
233 |
+
if not self.kernel().is_submodule(sm):
|
234 |
+
raise ValueError('kernel %s must contain sm, got %s' %
|
235 |
+
(self.kernel(), sm))
|
236 |
+
if sm.is_zero():
|
237 |
+
return self
|
238 |
+
return self._quotient_domain(sm)
|
239 |
+
|
240 |
+
def quotient_codomain(self, sm):
|
241 |
+
"""
|
242 |
+
Return ``self`` with codomain replaced by ``codomain/sm``.
|
243 |
+
|
244 |
+
Here ``sm`` must be a submodule of ``self.codomain``.
|
245 |
+
|
246 |
+
Examples
|
247 |
+
========
|
248 |
+
|
249 |
+
>>> from sympy import QQ
|
250 |
+
>>> from sympy.abc import x
|
251 |
+
>>> from sympy.polys.agca import homomorphism
|
252 |
+
|
253 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
254 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
255 |
+
>>> h
|
256 |
+
Matrix([
|
257 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2
|
258 |
+
[0, 0]])
|
259 |
+
>>> h.quotient_codomain(F.submodule([1, 1]))
|
260 |
+
Matrix([
|
261 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
|
262 |
+
[0, 0]])
|
263 |
+
|
264 |
+
This is the same as composing with the quotient map on the left:
|
265 |
+
|
266 |
+
>>> (F/[(1, 1)]).quotient_hom() * h
|
267 |
+
Matrix([
|
268 |
+
[1, x], : QQ[x]**2 -> QQ[x]**2/<[1, 1]>
|
269 |
+
[0, 0]])
|
270 |
+
"""
|
271 |
+
if not self.codomain.is_submodule(sm):
|
272 |
+
raise ValueError('sm must be a submodule of codomain %s, got %s'
|
273 |
+
% (self.codomain, sm))
|
274 |
+
if sm.is_zero():
|
275 |
+
return self
|
276 |
+
return self._quotient_codomain(sm)
|
277 |
+
|
278 |
+
def _apply(self, elem):
|
279 |
+
"""Apply ``self`` to ``elem``."""
|
280 |
+
raise NotImplementedError
|
281 |
+
|
282 |
+
def __call__(self, elem):
|
283 |
+
return self.codomain.convert(self._apply(self.domain.convert(elem)))
|
284 |
+
|
285 |
+
def _compose(self, oth):
|
286 |
+
"""
|
287 |
+
Compose ``self`` with ``oth``, that is, return the homomorphism
|
288 |
+
obtained by first applying then ``self``, then ``oth``.
|
289 |
+
|
290 |
+
(This method is private since in this syntax, it is non-obvious which
|
291 |
+
homomorphism is executed first.)
|
292 |
+
"""
|
293 |
+
raise NotImplementedError
|
294 |
+
|
295 |
+
def _mul_scalar(self, c):
|
296 |
+
"""Scalar multiplication. ``c`` is guaranteed in self.ring."""
|
297 |
+
raise NotImplementedError
|
298 |
+
|
299 |
+
def _add(self, oth):
|
300 |
+
"""
|
301 |
+
Homomorphism addition.
|
302 |
+
``oth`` is guaranteed to be a homomorphism with same domain/codomain.
|
303 |
+
"""
|
304 |
+
raise NotImplementedError
|
305 |
+
|
306 |
+
def _check_hom(self, oth):
|
307 |
+
"""Helper to check that oth is a homomorphism with same domain/codomain."""
|
308 |
+
if not isinstance(oth, ModuleHomomorphism):
|
309 |
+
return False
|
310 |
+
return oth.domain == self.domain and oth.codomain == self.codomain
|
311 |
+
|
312 |
+
def __mul__(self, oth):
|
313 |
+
if isinstance(oth, ModuleHomomorphism) and self.domain == oth.codomain:
|
314 |
+
return oth._compose(self)
|
315 |
+
try:
|
316 |
+
return self._mul_scalar(self.ring.convert(oth))
|
317 |
+
except CoercionFailed:
|
318 |
+
return NotImplemented
|
319 |
+
|
320 |
+
# NOTE: _compose will never be called from rmul
|
321 |
+
__rmul__ = __mul__
|
322 |
+
|
323 |
+
def __truediv__(self, oth):
|
324 |
+
try:
|
325 |
+
return self._mul_scalar(1/self.ring.convert(oth))
|
326 |
+
except CoercionFailed:
|
327 |
+
return NotImplemented
|
328 |
+
|
329 |
+
def __add__(self, oth):
|
330 |
+
if self._check_hom(oth):
|
331 |
+
return self._add(oth)
|
332 |
+
return NotImplemented
|
333 |
+
|
334 |
+
def __sub__(self, oth):
|
335 |
+
if self._check_hom(oth):
|
336 |
+
return self._add(oth._mul_scalar(self.ring.convert(-1)))
|
337 |
+
return NotImplemented
|
338 |
+
|
339 |
+
def is_injective(self):
|
340 |
+
"""
|
341 |
+
Return True if ``self`` is injective.
|
342 |
+
|
343 |
+
That is, check if the elements of the domain are mapped to the same
|
344 |
+
codomain element.
|
345 |
+
|
346 |
+
Examples
|
347 |
+
========
|
348 |
+
|
349 |
+
>>> from sympy import QQ
|
350 |
+
>>> from sympy.abc import x
|
351 |
+
>>> from sympy.polys.agca import homomorphism
|
352 |
+
|
353 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
354 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
355 |
+
>>> h.is_injective()
|
356 |
+
False
|
357 |
+
>>> h.quotient_domain(h.kernel()).is_injective()
|
358 |
+
True
|
359 |
+
"""
|
360 |
+
return self.kernel().is_zero()
|
361 |
+
|
362 |
+
def is_surjective(self):
|
363 |
+
"""
|
364 |
+
Return True if ``self`` is surjective.
|
365 |
+
|
366 |
+
That is, check if every element of the codomain has at least one
|
367 |
+
preimage.
|
368 |
+
|
369 |
+
Examples
|
370 |
+
========
|
371 |
+
|
372 |
+
>>> from sympy import QQ
|
373 |
+
>>> from sympy.abc import x
|
374 |
+
>>> from sympy.polys.agca import homomorphism
|
375 |
+
|
376 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
377 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
378 |
+
>>> h.is_surjective()
|
379 |
+
False
|
380 |
+
>>> h.restrict_codomain(h.image()).is_surjective()
|
381 |
+
True
|
382 |
+
"""
|
383 |
+
return self.image() == self.codomain
|
384 |
+
|
385 |
+
def is_isomorphism(self):
|
386 |
+
"""
|
387 |
+
Return True if ``self`` is an isomorphism.
|
388 |
+
|
389 |
+
That is, check if every element of the codomain has precisely one
|
390 |
+
preimage. Equivalently, ``self`` is both injective and surjective.
|
391 |
+
|
392 |
+
Examples
|
393 |
+
========
|
394 |
+
|
395 |
+
>>> from sympy import QQ
|
396 |
+
>>> from sympy.abc import x
|
397 |
+
>>> from sympy.polys.agca import homomorphism
|
398 |
+
|
399 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
400 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
401 |
+
>>> h = h.restrict_codomain(h.image())
|
402 |
+
>>> h.is_isomorphism()
|
403 |
+
False
|
404 |
+
>>> h.quotient_domain(h.kernel()).is_isomorphism()
|
405 |
+
True
|
406 |
+
"""
|
407 |
+
return self.is_injective() and self.is_surjective()
|
408 |
+
|
409 |
+
def is_zero(self):
|
410 |
+
"""
|
411 |
+
Return True if ``self`` is a zero morphism.
|
412 |
+
|
413 |
+
That is, check if every element of the domain is mapped to zero
|
414 |
+
under self.
|
415 |
+
|
416 |
+
Examples
|
417 |
+
========
|
418 |
+
|
419 |
+
>>> from sympy import QQ
|
420 |
+
>>> from sympy.abc import x
|
421 |
+
>>> from sympy.polys.agca import homomorphism
|
422 |
+
|
423 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
424 |
+
>>> h = homomorphism(F, F, [[1, 0], [x, 0]])
|
425 |
+
>>> h.is_zero()
|
426 |
+
False
|
427 |
+
>>> h.restrict_domain(F.submodule()).is_zero()
|
428 |
+
True
|
429 |
+
>>> h.quotient_codomain(h.image()).is_zero()
|
430 |
+
True
|
431 |
+
"""
|
432 |
+
return self.image().is_zero()
|
433 |
+
|
434 |
+
def __eq__(self, oth):
|
435 |
+
try:
|
436 |
+
return (self - oth).is_zero()
|
437 |
+
except TypeError:
|
438 |
+
return False
|
439 |
+
|
440 |
+
def __ne__(self, oth):
|
441 |
+
return not (self == oth)
|
442 |
+
|
443 |
+
|
444 |
+
class MatrixHomomorphism(ModuleHomomorphism):
|
445 |
+
r"""
|
446 |
+
Helper class for all homomoprhisms which are expressed via a matrix.
|
447 |
+
|
448 |
+
That is, for such homomorphisms ``domain`` is contained in a module
|
449 |
+
generated by finitely many elements `e_1, \ldots, e_n`, so that the
|
450 |
+
homomorphism is determined uniquely by its action on the `e_i`. It
|
451 |
+
can thus be represented as a vector of elements of the codomain module,
|
452 |
+
or potentially a supermodule of the codomain module
|
453 |
+
(and hence conventionally as a matrix, if there is a similar interpretation
|
454 |
+
for elements of the codomain module).
|
455 |
+
|
456 |
+
Note that this class does *not* assume that the `e_i` freely generate a
|
457 |
+
submodule, nor that ``domain`` is even all of this submodule. It exists
|
458 |
+
only to unify the interface.
|
459 |
+
|
460 |
+
Do not instantiate.
|
461 |
+
|
462 |
+
Attributes:
|
463 |
+
|
464 |
+
- matrix - the list of images determining the homomorphism.
|
465 |
+
NOTE: the elements of matrix belong to either self.codomain or
|
466 |
+
self.codomain.container
|
467 |
+
|
468 |
+
Still non-implemented methods:
|
469 |
+
|
470 |
+
- kernel
|
471 |
+
- _apply
|
472 |
+
"""
|
473 |
+
|
474 |
+
def __init__(self, domain, codomain, matrix):
|
475 |
+
ModuleHomomorphism.__init__(self, domain, codomain)
|
476 |
+
if len(matrix) != domain.rank:
|
477 |
+
raise ValueError('Need to provide %s elements, got %s'
|
478 |
+
% (domain.rank, len(matrix)))
|
479 |
+
|
480 |
+
converter = self.codomain.convert
|
481 |
+
if isinstance(self.codomain, (SubModule, SubQuotientModule)):
|
482 |
+
converter = self.codomain.container.convert
|
483 |
+
self.matrix = tuple(converter(x) for x in matrix)
|
484 |
+
|
485 |
+
def _sympy_matrix(self):
|
486 |
+
"""Helper function which returns a SymPy matrix ``self.matrix``."""
|
487 |
+
from sympy.matrices import Matrix
|
488 |
+
c = lambda x: x
|
489 |
+
if isinstance(self.codomain, (QuotientModule, SubQuotientModule)):
|
490 |
+
c = lambda x: x.data
|
491 |
+
return Matrix([[self.ring.to_sympy(y) for y in c(x)] for x in self.matrix]).T
|
492 |
+
|
493 |
+
def __repr__(self):
|
494 |
+
lines = repr(self._sympy_matrix()).split('\n')
|
495 |
+
t = " : %s -> %s" % (self.domain, self.codomain)
|
496 |
+
s = ' '*len(t)
|
497 |
+
n = len(lines)
|
498 |
+
for i in range(n // 2):
|
499 |
+
lines[i] += s
|
500 |
+
lines[n // 2] += t
|
501 |
+
for i in range(n//2 + 1, n):
|
502 |
+
lines[i] += s
|
503 |
+
return '\n'.join(lines)
|
504 |
+
|
505 |
+
def _restrict_domain(self, sm):
|
506 |
+
"""Implementation of domain restriction."""
|
507 |
+
return SubModuleHomomorphism(sm, self.codomain, self.matrix)
|
508 |
+
|
509 |
+
def _restrict_codomain(self, sm):
|
510 |
+
"""Implementation of codomain restriction."""
|
511 |
+
return self.__class__(self.domain, sm, self.matrix)
|
512 |
+
|
513 |
+
def _quotient_domain(self, sm):
|
514 |
+
"""Implementation of domain quotient."""
|
515 |
+
return self.__class__(self.domain/sm, self.codomain, self.matrix)
|
516 |
+
|
517 |
+
def _quotient_codomain(self, sm):
|
518 |
+
"""Implementation of codomain quotient."""
|
519 |
+
Q = self.codomain/sm
|
520 |
+
converter = Q.convert
|
521 |
+
if isinstance(self.codomain, SubModule):
|
522 |
+
converter = Q.container.convert
|
523 |
+
return self.__class__(self.domain, self.codomain/sm,
|
524 |
+
[converter(x) for x in self.matrix])
|
525 |
+
|
526 |
+
def _add(self, oth):
|
527 |
+
return self.__class__(self.domain, self.codomain,
|
528 |
+
[x + y for x, y in zip(self.matrix, oth.matrix)])
|
529 |
+
|
530 |
+
def _mul_scalar(self, c):
|
531 |
+
return self.__class__(self.domain, self.codomain, [c*x for x in self.matrix])
|
532 |
+
|
533 |
+
def _compose(self, oth):
|
534 |
+
return self.__class__(self.domain, oth.codomain, [oth(x) for x in self.matrix])
|
535 |
+
|
536 |
+
|
537 |
+
class FreeModuleHomomorphism(MatrixHomomorphism):
|
538 |
+
"""
|
539 |
+
Concrete class for homomorphisms with domain a free module or a quotient
|
540 |
+
thereof.
|
541 |
+
|
542 |
+
Do not instantiate; the constructor does not check that your data is well
|
543 |
+
defined. Use the ``homomorphism`` function instead:
|
544 |
+
|
545 |
+
>>> from sympy import QQ
|
546 |
+
>>> from sympy.abc import x
|
547 |
+
>>> from sympy.polys.agca import homomorphism
|
548 |
+
|
549 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
550 |
+
>>> homomorphism(F, F, [[1, 0], [0, 1]])
|
551 |
+
Matrix([
|
552 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
553 |
+
[0, 1]])
|
554 |
+
"""
|
555 |
+
|
556 |
+
def _apply(self, elem):
|
557 |
+
if isinstance(self.domain, QuotientModule):
|
558 |
+
elem = elem.data
|
559 |
+
return sum(x * e for x, e in zip(elem, self.matrix))
|
560 |
+
|
561 |
+
def _image(self):
|
562 |
+
return self.codomain.submodule(*self.matrix)
|
563 |
+
|
564 |
+
def _kernel(self):
|
565 |
+
# The domain is either a free module or a quotient thereof.
|
566 |
+
# It does not matter if it is a quotient, because that won't increase
|
567 |
+
# the kernel.
|
568 |
+
# Our generators {e_i} are sent to the matrix entries {b_i}.
|
569 |
+
# The kernel is essentially the syzygy module of these {b_i}.
|
570 |
+
syz = self.image().syzygy_module()
|
571 |
+
return self.domain.submodule(*syz.gens)
|
572 |
+
|
573 |
+
|
574 |
+
class SubModuleHomomorphism(MatrixHomomorphism):
|
575 |
+
"""
|
576 |
+
Concrete class for homomorphism with domain a submodule of a free module
|
577 |
+
or a quotient thereof.
|
578 |
+
|
579 |
+
Do not instantiate; the constructor does not check that your data is well
|
580 |
+
defined. Use the ``homomorphism`` function instead:
|
581 |
+
|
582 |
+
>>> from sympy import QQ
|
583 |
+
>>> from sympy.abc import x
|
584 |
+
>>> from sympy.polys.agca import homomorphism
|
585 |
+
|
586 |
+
>>> M = QQ.old_poly_ring(x).free_module(2)*x
|
587 |
+
>>> homomorphism(M, M, [[1, 0], [0, 1]])
|
588 |
+
Matrix([
|
589 |
+
[1, 0], : <[x, 0], [0, x]> -> <[x, 0], [0, x]>
|
590 |
+
[0, 1]])
|
591 |
+
"""
|
592 |
+
|
593 |
+
def _apply(self, elem):
|
594 |
+
if isinstance(self.domain, SubQuotientModule):
|
595 |
+
elem = elem.data
|
596 |
+
return sum(x * e for x, e in zip(elem, self.matrix))
|
597 |
+
|
598 |
+
def _image(self):
|
599 |
+
return self.codomain.submodule(*[self(x) for x in self.domain.gens])
|
600 |
+
|
601 |
+
def _kernel(self):
|
602 |
+
syz = self.image().syzygy_module()
|
603 |
+
return self.domain.submodule(
|
604 |
+
*[sum(xi*gi for xi, gi in zip(s, self.domain.gens))
|
605 |
+
for s in syz.gens])
|
606 |
+
|
607 |
+
|
608 |
+
def homomorphism(domain, codomain, matrix):
|
609 |
+
r"""
|
610 |
+
Create a homomorphism object.
|
611 |
+
|
612 |
+
This function tries to build a homomorphism from ``domain`` to ``codomain``
|
613 |
+
via the matrix ``matrix``.
|
614 |
+
|
615 |
+
Examples
|
616 |
+
========
|
617 |
+
|
618 |
+
>>> from sympy import QQ
|
619 |
+
>>> from sympy.abc import x
|
620 |
+
>>> from sympy.polys.agca import homomorphism
|
621 |
+
|
622 |
+
>>> R = QQ.old_poly_ring(x)
|
623 |
+
>>> T = R.free_module(2)
|
624 |
+
|
625 |
+
If ``domain`` is a free module generated by `e_1, \ldots, e_n`, then
|
626 |
+
``matrix`` should be an n-element iterable `(b_1, \ldots, b_n)` where
|
627 |
+
the `b_i` are elements of ``codomain``. The constructed homomorphism is the
|
628 |
+
unique homomorphism sending `e_i` to `b_i`.
|
629 |
+
|
630 |
+
>>> F = R.free_module(2)
|
631 |
+
>>> h = homomorphism(F, T, [[1, x], [x**2, 0]])
|
632 |
+
>>> h
|
633 |
+
Matrix([
|
634 |
+
[1, x**2], : QQ[x]**2 -> QQ[x]**2
|
635 |
+
[x, 0]])
|
636 |
+
>>> h([1, 0])
|
637 |
+
[1, x]
|
638 |
+
>>> h([0, 1])
|
639 |
+
[x**2, 0]
|
640 |
+
>>> h([1, 1])
|
641 |
+
[x**2 + 1, x]
|
642 |
+
|
643 |
+
If ``domain`` is a submodule of a free module, them ``matrix`` determines
|
644 |
+
a homomoprhism from the containing free module to ``codomain``, and the
|
645 |
+
homomorphism returned is obtained by restriction to ``domain``.
|
646 |
+
|
647 |
+
>>> S = F.submodule([1, 0], [0, x])
|
648 |
+
>>> homomorphism(S, T, [[1, x], [x**2, 0]])
|
649 |
+
Matrix([
|
650 |
+
[1, x**2], : <[1, 0], [0, x]> -> QQ[x]**2
|
651 |
+
[x, 0]])
|
652 |
+
|
653 |
+
If ``domain`` is a (sub)quotient `N/K`, then ``matrix`` determines a
|
654 |
+
homomorphism from `N` to ``codomain``. If the kernel contains `K`, this
|
655 |
+
homomorphism descends to ``domain`` and is returned; otherwise an exception
|
656 |
+
is raised.
|
657 |
+
|
658 |
+
>>> homomorphism(S/[(1, 0)], T, [0, [x**2, 0]])
|
659 |
+
Matrix([
|
660 |
+
[0, x**2], : <[1, 0] + <[1, 0]>, [0, x] + <[1, 0]>, [1, 0] + <[1, 0]>> -> QQ[x]**2
|
661 |
+
[0, 0]])
|
662 |
+
>>> homomorphism(S/[(0, x)], T, [0, [x**2, 0]])
|
663 |
+
Traceback (most recent call last):
|
664 |
+
...
|
665 |
+
ValueError: kernel <[1, 0], [0, 0]> must contain sm, got <[0,x]>
|
666 |
+
|
667 |
+
"""
|
668 |
+
def freepres(module):
|
669 |
+
"""
|
670 |
+
Return a tuple ``(F, S, Q, c)`` where ``F`` is a free module, ``S`` is a
|
671 |
+
submodule of ``F``, and ``Q`` a submodule of ``S``, such that
|
672 |
+
``module = S/Q``, and ``c`` is a conversion function.
|
673 |
+
"""
|
674 |
+
if isinstance(module, FreeModule):
|
675 |
+
return module, module, module.submodule(), lambda x: module.convert(x)
|
676 |
+
if isinstance(module, QuotientModule):
|
677 |
+
return (module.base, module.base, module.killed_module,
|
678 |
+
lambda x: module.convert(x).data)
|
679 |
+
if isinstance(module, SubQuotientModule):
|
680 |
+
return (module.base.container, module.base, module.killed_module,
|
681 |
+
lambda x: module.container.convert(x).data)
|
682 |
+
# an ordinary submodule
|
683 |
+
return (module.container, module, module.submodule(),
|
684 |
+
lambda x: module.container.convert(x))
|
685 |
+
|
686 |
+
SF, SS, SQ, _ = freepres(domain)
|
687 |
+
TF, TS, TQ, c = freepres(codomain)
|
688 |
+
# NOTE this is probably a bit inefficient (redundant checks)
|
689 |
+
return FreeModuleHomomorphism(SF, TF, [c(x) for x in matrix]
|
690 |
+
).restrict_domain(SS).restrict_codomain(TS
|
691 |
+
).quotient_codomain(TQ).quotient_domain(SQ)
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/ideals.py
ADDED
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""Computations with ideals of polynomial rings."""
|
2 |
+
|
3 |
+
from sympy.polys.polyerrors import CoercionFailed
|
4 |
+
from sympy.polys.polyutils import IntegerPowerable
|
5 |
+
|
6 |
+
|
7 |
+
class Ideal(IntegerPowerable):
|
8 |
+
"""
|
9 |
+
Abstract base class for ideals.
|
10 |
+
|
11 |
+
Do not instantiate - use explicit constructors in the ring class instead:
|
12 |
+
|
13 |
+
>>> from sympy import QQ
|
14 |
+
>>> from sympy.abc import x
|
15 |
+
>>> QQ.old_poly_ring(x).ideal(x+1)
|
16 |
+
<x + 1>
|
17 |
+
|
18 |
+
Attributes
|
19 |
+
|
20 |
+
- ring - the ring this ideal belongs to
|
21 |
+
|
22 |
+
Non-implemented methods:
|
23 |
+
|
24 |
+
- _contains_elem
|
25 |
+
- _contains_ideal
|
26 |
+
- _quotient
|
27 |
+
- _intersect
|
28 |
+
- _union
|
29 |
+
- _product
|
30 |
+
- is_whole_ring
|
31 |
+
- is_zero
|
32 |
+
- is_prime, is_maximal, is_primary, is_radical
|
33 |
+
- is_principal
|
34 |
+
- height, depth
|
35 |
+
- radical
|
36 |
+
|
37 |
+
Methods that likely should be overridden in subclasses:
|
38 |
+
|
39 |
+
- reduce_element
|
40 |
+
"""
|
41 |
+
|
42 |
+
def _contains_elem(self, x):
|
43 |
+
"""Implementation of element containment."""
|
44 |
+
raise NotImplementedError
|
45 |
+
|
46 |
+
def _contains_ideal(self, I):
|
47 |
+
"""Implementation of ideal containment."""
|
48 |
+
raise NotImplementedError
|
49 |
+
|
50 |
+
def _quotient(self, J):
|
51 |
+
"""Implementation of ideal quotient."""
|
52 |
+
raise NotImplementedError
|
53 |
+
|
54 |
+
def _intersect(self, J):
|
55 |
+
"""Implementation of ideal intersection."""
|
56 |
+
raise NotImplementedError
|
57 |
+
|
58 |
+
def is_whole_ring(self):
|
59 |
+
"""Return True if ``self`` is the whole ring."""
|
60 |
+
raise NotImplementedError
|
61 |
+
|
62 |
+
def is_zero(self):
|
63 |
+
"""Return True if ``self`` is the zero ideal."""
|
64 |
+
raise NotImplementedError
|
65 |
+
|
66 |
+
def _equals(self, J):
|
67 |
+
"""Implementation of ideal equality."""
|
68 |
+
return self._contains_ideal(J) and J._contains_ideal(self)
|
69 |
+
|
70 |
+
def is_prime(self):
|
71 |
+
"""Return True if ``self`` is a prime ideal."""
|
72 |
+
raise NotImplementedError
|
73 |
+
|
74 |
+
def is_maximal(self):
|
75 |
+
"""Return True if ``self`` is a maximal ideal."""
|
76 |
+
raise NotImplementedError
|
77 |
+
|
78 |
+
def is_radical(self):
|
79 |
+
"""Return True if ``self`` is a radical ideal."""
|
80 |
+
raise NotImplementedError
|
81 |
+
|
82 |
+
def is_primary(self):
|
83 |
+
"""Return True if ``self`` is a primary ideal."""
|
84 |
+
raise NotImplementedError
|
85 |
+
|
86 |
+
def is_principal(self):
|
87 |
+
"""Return True if ``self`` is a principal ideal."""
|
88 |
+
raise NotImplementedError
|
89 |
+
|
90 |
+
def radical(self):
|
91 |
+
"""Compute the radical of ``self``."""
|
92 |
+
raise NotImplementedError
|
93 |
+
|
94 |
+
def depth(self):
|
95 |
+
"""Compute the depth of ``self``."""
|
96 |
+
raise NotImplementedError
|
97 |
+
|
98 |
+
def height(self):
|
99 |
+
"""Compute the height of ``self``."""
|
100 |
+
raise NotImplementedError
|
101 |
+
|
102 |
+
# TODO more
|
103 |
+
|
104 |
+
# non-implemented methods end here
|
105 |
+
|
106 |
+
def __init__(self, ring):
|
107 |
+
self.ring = ring
|
108 |
+
|
109 |
+
def _check_ideal(self, J):
|
110 |
+
"""Helper to check ``J`` is an ideal of our ring."""
|
111 |
+
if not isinstance(J, Ideal) or J.ring != self.ring:
|
112 |
+
raise ValueError(
|
113 |
+
'J must be an ideal of %s, got %s' % (self.ring, J))
|
114 |
+
|
115 |
+
def contains(self, elem):
|
116 |
+
"""
|
117 |
+
Return True if ``elem`` is an element of this ideal.
|
118 |
+
|
119 |
+
Examples
|
120 |
+
========
|
121 |
+
|
122 |
+
>>> from sympy.abc import x
|
123 |
+
>>> from sympy import QQ
|
124 |
+
>>> QQ.old_poly_ring(x).ideal(x+1, x-1).contains(3)
|
125 |
+
True
|
126 |
+
>>> QQ.old_poly_ring(x).ideal(x**2, x**3).contains(x)
|
127 |
+
False
|
128 |
+
"""
|
129 |
+
return self._contains_elem(self.ring.convert(elem))
|
130 |
+
|
131 |
+
def subset(self, other):
|
132 |
+
"""
|
133 |
+
Returns True if ``other`` is is a subset of ``self``.
|
134 |
+
|
135 |
+
Here ``other`` may be an ideal.
|
136 |
+
|
137 |
+
Examples
|
138 |
+
========
|
139 |
+
|
140 |
+
>>> from sympy.abc import x
|
141 |
+
>>> from sympy import QQ
|
142 |
+
>>> I = QQ.old_poly_ring(x).ideal(x+1)
|
143 |
+
>>> I.subset([x**2 - 1, x**2 + 2*x + 1])
|
144 |
+
True
|
145 |
+
>>> I.subset([x**2 + 1, x + 1])
|
146 |
+
False
|
147 |
+
>>> I.subset(QQ.old_poly_ring(x).ideal(x**2 - 1))
|
148 |
+
True
|
149 |
+
"""
|
150 |
+
if isinstance(other, Ideal):
|
151 |
+
return self._contains_ideal(other)
|
152 |
+
return all(self._contains_elem(x) for x in other)
|
153 |
+
|
154 |
+
def quotient(self, J, **opts):
|
155 |
+
r"""
|
156 |
+
Compute the ideal quotient of ``self`` by ``J``.
|
157 |
+
|
158 |
+
That is, if ``self`` is the ideal `I`, compute the set
|
159 |
+
`I : J = \{x \in R | xJ \subset I \}`.
|
160 |
+
|
161 |
+
Examples
|
162 |
+
========
|
163 |
+
|
164 |
+
>>> from sympy.abc import x, y
|
165 |
+
>>> from sympy import QQ
|
166 |
+
>>> R = QQ.old_poly_ring(x, y)
|
167 |
+
>>> R.ideal(x*y).quotient(R.ideal(x))
|
168 |
+
<y>
|
169 |
+
"""
|
170 |
+
self._check_ideal(J)
|
171 |
+
return self._quotient(J, **opts)
|
172 |
+
|
173 |
+
def intersect(self, J):
|
174 |
+
"""
|
175 |
+
Compute the intersection of self with ideal J.
|
176 |
+
|
177 |
+
Examples
|
178 |
+
========
|
179 |
+
|
180 |
+
>>> from sympy.abc import x, y
|
181 |
+
>>> from sympy import QQ
|
182 |
+
>>> R = QQ.old_poly_ring(x, y)
|
183 |
+
>>> R.ideal(x).intersect(R.ideal(y))
|
184 |
+
<x*y>
|
185 |
+
"""
|
186 |
+
self._check_ideal(J)
|
187 |
+
return self._intersect(J)
|
188 |
+
|
189 |
+
def saturate(self, J):
|
190 |
+
r"""
|
191 |
+
Compute the ideal saturation of ``self`` by ``J``.
|
192 |
+
|
193 |
+
That is, if ``self`` is the ideal `I`, compute the set
|
194 |
+
`I : J^\infty = \{x \in R | xJ^n \subset I \text{ for some } n\}`.
|
195 |
+
"""
|
196 |
+
raise NotImplementedError
|
197 |
+
# Note this can be implemented using repeated quotient
|
198 |
+
|
199 |
+
def union(self, J):
|
200 |
+
"""
|
201 |
+
Compute the ideal generated by the union of ``self`` and ``J``.
|
202 |
+
|
203 |
+
Examples
|
204 |
+
========
|
205 |
+
|
206 |
+
>>> from sympy.abc import x
|
207 |
+
>>> from sympy import QQ
|
208 |
+
>>> QQ.old_poly_ring(x).ideal(x**2 - 1).union(QQ.old_poly_ring(x).ideal((x+1)**2)) == QQ.old_poly_ring(x).ideal(x+1)
|
209 |
+
True
|
210 |
+
"""
|
211 |
+
self._check_ideal(J)
|
212 |
+
return self._union(J)
|
213 |
+
|
214 |
+
def product(self, J):
|
215 |
+
r"""
|
216 |
+
Compute the ideal product of ``self`` and ``J``.
|
217 |
+
|
218 |
+
That is, compute the ideal generated by products `xy`, for `x` an element
|
219 |
+
of ``self`` and `y \in J`.
|
220 |
+
|
221 |
+
Examples
|
222 |
+
========
|
223 |
+
|
224 |
+
>>> from sympy.abc import x, y
|
225 |
+
>>> from sympy import QQ
|
226 |
+
>>> QQ.old_poly_ring(x, y).ideal(x).product(QQ.old_poly_ring(x, y).ideal(y))
|
227 |
+
<x*y>
|
228 |
+
"""
|
229 |
+
self._check_ideal(J)
|
230 |
+
return self._product(J)
|
231 |
+
|
232 |
+
def reduce_element(self, x):
|
233 |
+
"""
|
234 |
+
Reduce the element ``x`` of our ring modulo the ideal ``self``.
|
235 |
+
|
236 |
+
Here "reduce" has no specific meaning: it could return a unique normal
|
237 |
+
form, simplify the expression a bit, or just do nothing.
|
238 |
+
"""
|
239 |
+
return x
|
240 |
+
|
241 |
+
def __add__(self, e):
|
242 |
+
if not isinstance(e, Ideal):
|
243 |
+
R = self.ring.quotient_ring(self)
|
244 |
+
if isinstance(e, R.dtype):
|
245 |
+
return e
|
246 |
+
if isinstance(e, R.ring.dtype):
|
247 |
+
return R(e)
|
248 |
+
return R.convert(e)
|
249 |
+
self._check_ideal(e)
|
250 |
+
return self.union(e)
|
251 |
+
|
252 |
+
__radd__ = __add__
|
253 |
+
|
254 |
+
def __mul__(self, e):
|
255 |
+
if not isinstance(e, Ideal):
|
256 |
+
try:
|
257 |
+
e = self.ring.ideal(e)
|
258 |
+
except CoercionFailed:
|
259 |
+
return NotImplemented
|
260 |
+
self._check_ideal(e)
|
261 |
+
return self.product(e)
|
262 |
+
|
263 |
+
__rmul__ = __mul__
|
264 |
+
|
265 |
+
def _zeroth_power(self):
|
266 |
+
return self.ring.ideal(1)
|
267 |
+
|
268 |
+
def _first_power(self):
|
269 |
+
# Raising to any power but 1 returns a new instance. So we mult by 1
|
270 |
+
# here so that the first power is no exception.
|
271 |
+
return self * 1
|
272 |
+
|
273 |
+
def __eq__(self, e):
|
274 |
+
if not isinstance(e, Ideal) or e.ring != self.ring:
|
275 |
+
return False
|
276 |
+
return self._equals(e)
|
277 |
+
|
278 |
+
def __ne__(self, e):
|
279 |
+
return not (self == e)
|
280 |
+
|
281 |
+
|
282 |
+
class ModuleImplementedIdeal(Ideal):
|
283 |
+
"""
|
284 |
+
Ideal implementation relying on the modules code.
|
285 |
+
|
286 |
+
Attributes:
|
287 |
+
|
288 |
+
- _module - the underlying module
|
289 |
+
"""
|
290 |
+
|
291 |
+
def __init__(self, ring, module):
|
292 |
+
Ideal.__init__(self, ring)
|
293 |
+
self._module = module
|
294 |
+
|
295 |
+
def _contains_elem(self, x):
|
296 |
+
return self._module.contains([x])
|
297 |
+
|
298 |
+
def _contains_ideal(self, J):
|
299 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
300 |
+
raise NotImplementedError
|
301 |
+
return self._module.is_submodule(J._module)
|
302 |
+
|
303 |
+
def _intersect(self, J):
|
304 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
305 |
+
raise NotImplementedError
|
306 |
+
return self.__class__(self.ring, self._module.intersect(J._module))
|
307 |
+
|
308 |
+
def _quotient(self, J, **opts):
|
309 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
310 |
+
raise NotImplementedError
|
311 |
+
return self._module.module_quotient(J._module, **opts)
|
312 |
+
|
313 |
+
def _union(self, J):
|
314 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
315 |
+
raise NotImplementedError
|
316 |
+
return self.__class__(self.ring, self._module.union(J._module))
|
317 |
+
|
318 |
+
@property
|
319 |
+
def gens(self):
|
320 |
+
"""
|
321 |
+
Return generators for ``self``.
|
322 |
+
|
323 |
+
Examples
|
324 |
+
========
|
325 |
+
|
326 |
+
>>> from sympy import QQ
|
327 |
+
>>> from sympy.abc import x, y
|
328 |
+
>>> list(QQ.old_poly_ring(x, y).ideal(x, y, x**2 + y).gens)
|
329 |
+
[x, y, x**2 + y]
|
330 |
+
"""
|
331 |
+
return (x[0] for x in self._module.gens)
|
332 |
+
|
333 |
+
def is_zero(self):
|
334 |
+
"""
|
335 |
+
Return True if ``self`` is the zero ideal.
|
336 |
+
|
337 |
+
Examples
|
338 |
+
========
|
339 |
+
|
340 |
+
>>> from sympy.abc import x
|
341 |
+
>>> from sympy import QQ
|
342 |
+
>>> QQ.old_poly_ring(x).ideal(x).is_zero()
|
343 |
+
False
|
344 |
+
>>> QQ.old_poly_ring(x).ideal().is_zero()
|
345 |
+
True
|
346 |
+
"""
|
347 |
+
return self._module.is_zero()
|
348 |
+
|
349 |
+
def is_whole_ring(self):
|
350 |
+
"""
|
351 |
+
Return True if ``self`` is the whole ring, i.e. one generator is a unit.
|
352 |
+
|
353 |
+
Examples
|
354 |
+
========
|
355 |
+
|
356 |
+
>>> from sympy.abc import x
|
357 |
+
>>> from sympy import QQ, ilex
|
358 |
+
>>> QQ.old_poly_ring(x).ideal(x).is_whole_ring()
|
359 |
+
False
|
360 |
+
>>> QQ.old_poly_ring(x).ideal(3).is_whole_ring()
|
361 |
+
True
|
362 |
+
>>> QQ.old_poly_ring(x, order=ilex).ideal(2 + x).is_whole_ring()
|
363 |
+
True
|
364 |
+
"""
|
365 |
+
return self._module.is_full_module()
|
366 |
+
|
367 |
+
def __repr__(self):
|
368 |
+
from sympy.printing.str import sstr
|
369 |
+
return '<' + ','.join(sstr(x) for [x] in self._module.gens) + '>'
|
370 |
+
|
371 |
+
# NOTE this is the only method using the fact that the module is a SubModule
|
372 |
+
def _product(self, J):
|
373 |
+
if not isinstance(J, ModuleImplementedIdeal):
|
374 |
+
raise NotImplementedError
|
375 |
+
return self.__class__(self.ring, self._module.submodule(
|
376 |
+
*[[x*y] for [x] in self._module.gens for [y] in J._module.gens]))
|
377 |
+
|
378 |
+
def in_terms_of_generators(self, e):
|
379 |
+
"""
|
380 |
+
Express ``e`` in terms of the generators of ``self``.
|
381 |
+
|
382 |
+
Examples
|
383 |
+
========
|
384 |
+
|
385 |
+
>>> from sympy.abc import x
|
386 |
+
>>> from sympy import QQ
|
387 |
+
>>> I = QQ.old_poly_ring(x).ideal(x**2 + 1, x)
|
388 |
+
>>> I.in_terms_of_generators(1)
|
389 |
+
[1, -x]
|
390 |
+
"""
|
391 |
+
return self._module.in_terms_of_generators([e])
|
392 |
+
|
393 |
+
def reduce_element(self, x, **options):
|
394 |
+
return self._module.reduce_element([x], **options)[0]
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/agca/modules.py
ADDED
@@ -0,0 +1,1484 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
Computations with modules over polynomial rings.
|
3 |
+
|
4 |
+
This module implements various classes that encapsulate groebner basis
|
5 |
+
computations for modules. Most of them should not be instantiated by hand.
|
6 |
+
Instead, use the constructing routines on objects you already have.
|
7 |
+
|
8 |
+
For example, to construct a free module over ``QQ[x, y]``, call
|
9 |
+
``QQ[x, y].free_module(rank)`` instead of the ``FreeModule`` constructor.
|
10 |
+
In fact ``FreeModule`` is an abstract base class that should not be
|
11 |
+
instantiated, the ``free_module`` method instead returns the implementing class
|
12 |
+
``FreeModulePolyRing``.
|
13 |
+
|
14 |
+
In general, the abstract base classes implement most functionality in terms of
|
15 |
+
a few non-implemented methods. The concrete base classes supply only these
|
16 |
+
non-implemented methods. They may also supply new implementations of the
|
17 |
+
convenience methods, for example if there are faster algorithms available.
|
18 |
+
"""
|
19 |
+
|
20 |
+
|
21 |
+
from copy import copy
|
22 |
+
from functools import reduce
|
23 |
+
|
24 |
+
from sympy.polys.agca.ideals import Ideal
|
25 |
+
from sympy.polys.domains.field import Field
|
26 |
+
from sympy.polys.orderings import ProductOrder, monomial_key
|
27 |
+
from sympy.polys.polyerrors import CoercionFailed
|
28 |
+
from sympy.core.basic import _aresame
|
29 |
+
from sympy.utilities.iterables import iterable
|
30 |
+
|
31 |
+
# TODO
|
32 |
+
# - module saturation
|
33 |
+
# - module quotient/intersection for quotient rings
|
34 |
+
# - free resoltutions / syzygies
|
35 |
+
# - finding small/minimal generating sets
|
36 |
+
# - ...
|
37 |
+
|
38 |
+
##########################################################################
|
39 |
+
## Abstract base classes #################################################
|
40 |
+
##########################################################################
|
41 |
+
|
42 |
+
|
43 |
+
class Module:
|
44 |
+
"""
|
45 |
+
Abstract base class for modules.
|
46 |
+
|
47 |
+
Do not instantiate - use ring explicit constructors instead:
|
48 |
+
|
49 |
+
>>> from sympy import QQ
|
50 |
+
>>> from sympy.abc import x
|
51 |
+
>>> QQ.old_poly_ring(x).free_module(2)
|
52 |
+
QQ[x]**2
|
53 |
+
|
54 |
+
Attributes:
|
55 |
+
|
56 |
+
- dtype - type of elements
|
57 |
+
- ring - containing ring
|
58 |
+
|
59 |
+
Non-implemented methods:
|
60 |
+
|
61 |
+
- submodule
|
62 |
+
- quotient_module
|
63 |
+
- is_zero
|
64 |
+
- is_submodule
|
65 |
+
- multiply_ideal
|
66 |
+
|
67 |
+
The method convert likely needs to be changed in subclasses.
|
68 |
+
"""
|
69 |
+
|
70 |
+
def __init__(self, ring):
|
71 |
+
self.ring = ring
|
72 |
+
|
73 |
+
def convert(self, elem, M=None):
|
74 |
+
"""
|
75 |
+
Convert ``elem`` into internal representation of this module.
|
76 |
+
|
77 |
+
If ``M`` is not None, it should be a module containing it.
|
78 |
+
"""
|
79 |
+
if not isinstance(elem, self.dtype):
|
80 |
+
raise CoercionFailed
|
81 |
+
return elem
|
82 |
+
|
83 |
+
def submodule(self, *gens):
|
84 |
+
"""Generate a submodule."""
|
85 |
+
raise NotImplementedError
|
86 |
+
|
87 |
+
def quotient_module(self, other):
|
88 |
+
"""Generate a quotient module."""
|
89 |
+
raise NotImplementedError
|
90 |
+
|
91 |
+
def __truediv__(self, e):
|
92 |
+
if not isinstance(e, Module):
|
93 |
+
e = self.submodule(*e)
|
94 |
+
return self.quotient_module(e)
|
95 |
+
|
96 |
+
def contains(self, elem):
|
97 |
+
"""Return True if ``elem`` is an element of this module."""
|
98 |
+
try:
|
99 |
+
self.convert(elem)
|
100 |
+
return True
|
101 |
+
except CoercionFailed:
|
102 |
+
return False
|
103 |
+
|
104 |
+
def __contains__(self, elem):
|
105 |
+
return self.contains(elem)
|
106 |
+
|
107 |
+
def subset(self, other):
|
108 |
+
"""
|
109 |
+
Returns True if ``other`` is is a subset of ``self``.
|
110 |
+
|
111 |
+
Examples
|
112 |
+
========
|
113 |
+
|
114 |
+
>>> from sympy.abc import x
|
115 |
+
>>> from sympy import QQ
|
116 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
117 |
+
>>> F.subset([(1, x), (x, 2)])
|
118 |
+
True
|
119 |
+
>>> F.subset([(1/x, x), (x, 2)])
|
120 |
+
False
|
121 |
+
"""
|
122 |
+
return all(self.contains(x) for x in other)
|
123 |
+
|
124 |
+
def __eq__(self, other):
|
125 |
+
return self.is_submodule(other) and other.is_submodule(self)
|
126 |
+
|
127 |
+
def __ne__(self, other):
|
128 |
+
return not (self == other)
|
129 |
+
|
130 |
+
def is_zero(self):
|
131 |
+
"""Returns True if ``self`` is a zero module."""
|
132 |
+
raise NotImplementedError
|
133 |
+
|
134 |
+
def is_submodule(self, other):
|
135 |
+
"""Returns True if ``other`` is a submodule of ``self``."""
|
136 |
+
raise NotImplementedError
|
137 |
+
|
138 |
+
def multiply_ideal(self, other):
|
139 |
+
"""
|
140 |
+
Multiply ``self`` by the ideal ``other``.
|
141 |
+
"""
|
142 |
+
raise NotImplementedError
|
143 |
+
|
144 |
+
def __mul__(self, e):
|
145 |
+
if not isinstance(e, Ideal):
|
146 |
+
try:
|
147 |
+
e = self.ring.ideal(e)
|
148 |
+
except (CoercionFailed, NotImplementedError):
|
149 |
+
return NotImplemented
|
150 |
+
return self.multiply_ideal(e)
|
151 |
+
|
152 |
+
__rmul__ = __mul__
|
153 |
+
|
154 |
+
def identity_hom(self):
|
155 |
+
"""Return the identity homomorphism on ``self``."""
|
156 |
+
raise NotImplementedError
|
157 |
+
|
158 |
+
|
159 |
+
class ModuleElement:
|
160 |
+
"""
|
161 |
+
Base class for module element wrappers.
|
162 |
+
|
163 |
+
Use this class to wrap primitive data types as module elements. It stores
|
164 |
+
a reference to the containing module, and implements all the arithmetic
|
165 |
+
operators.
|
166 |
+
|
167 |
+
Attributes:
|
168 |
+
|
169 |
+
- module - containing module
|
170 |
+
- data - internal data
|
171 |
+
|
172 |
+
Methods that likely need change in subclasses:
|
173 |
+
|
174 |
+
- add
|
175 |
+
- mul
|
176 |
+
- div
|
177 |
+
- eq
|
178 |
+
"""
|
179 |
+
|
180 |
+
def __init__(self, module, data):
|
181 |
+
self.module = module
|
182 |
+
self.data = data
|
183 |
+
|
184 |
+
def add(self, d1, d2):
|
185 |
+
"""Add data ``d1`` and ``d2``."""
|
186 |
+
return d1 + d2
|
187 |
+
|
188 |
+
def mul(self, m, d):
|
189 |
+
"""Multiply module data ``m`` by coefficient d."""
|
190 |
+
return m * d
|
191 |
+
|
192 |
+
def div(self, m, d):
|
193 |
+
"""Divide module data ``m`` by coefficient d."""
|
194 |
+
return m / d
|
195 |
+
|
196 |
+
def eq(self, d1, d2):
|
197 |
+
"""Return true if d1 and d2 represent the same element."""
|
198 |
+
return d1 == d2
|
199 |
+
|
200 |
+
def __add__(self, om):
|
201 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
202 |
+
try:
|
203 |
+
om = self.module.convert(om)
|
204 |
+
except CoercionFailed:
|
205 |
+
return NotImplemented
|
206 |
+
return self.__class__(self.module, self.add(self.data, om.data))
|
207 |
+
|
208 |
+
__radd__ = __add__
|
209 |
+
|
210 |
+
def __neg__(self):
|
211 |
+
return self.__class__(self.module, self.mul(self.data,
|
212 |
+
self.module.ring.convert(-1)))
|
213 |
+
|
214 |
+
def __sub__(self, om):
|
215 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
216 |
+
try:
|
217 |
+
om = self.module.convert(om)
|
218 |
+
except CoercionFailed:
|
219 |
+
return NotImplemented
|
220 |
+
return self.__add__(-om)
|
221 |
+
|
222 |
+
def __rsub__(self, om):
|
223 |
+
return (-self).__add__(om)
|
224 |
+
|
225 |
+
def __mul__(self, o):
|
226 |
+
if not isinstance(o, self.module.ring.dtype):
|
227 |
+
try:
|
228 |
+
o = self.module.ring.convert(o)
|
229 |
+
except CoercionFailed:
|
230 |
+
return NotImplemented
|
231 |
+
return self.__class__(self.module, self.mul(self.data, o))
|
232 |
+
|
233 |
+
__rmul__ = __mul__
|
234 |
+
|
235 |
+
def __truediv__(self, o):
|
236 |
+
if not isinstance(o, self.module.ring.dtype):
|
237 |
+
try:
|
238 |
+
o = self.module.ring.convert(o)
|
239 |
+
except CoercionFailed:
|
240 |
+
return NotImplemented
|
241 |
+
return self.__class__(self.module, self.div(self.data, o))
|
242 |
+
|
243 |
+
def __eq__(self, om):
|
244 |
+
if not isinstance(om, self.__class__) or om.module != self.module:
|
245 |
+
try:
|
246 |
+
om = self.module.convert(om)
|
247 |
+
except CoercionFailed:
|
248 |
+
return False
|
249 |
+
return self.eq(self.data, om.data)
|
250 |
+
|
251 |
+
def __ne__(self, om):
|
252 |
+
return not self == om
|
253 |
+
|
254 |
+
##########################################################################
|
255 |
+
## Free Modules ##########################################################
|
256 |
+
##########################################################################
|
257 |
+
|
258 |
+
|
259 |
+
class FreeModuleElement(ModuleElement):
|
260 |
+
"""Element of a free module. Data stored as a tuple."""
|
261 |
+
|
262 |
+
def add(self, d1, d2):
|
263 |
+
return tuple(x + y for x, y in zip(d1, d2))
|
264 |
+
|
265 |
+
def mul(self, d, p):
|
266 |
+
return tuple(x * p for x in d)
|
267 |
+
|
268 |
+
def div(self, d, p):
|
269 |
+
return tuple(x / p for x in d)
|
270 |
+
|
271 |
+
def __repr__(self):
|
272 |
+
from sympy.printing.str import sstr
|
273 |
+
return '[' + ', '.join(sstr(x) for x in self.data) + ']'
|
274 |
+
|
275 |
+
def __iter__(self):
|
276 |
+
return self.data.__iter__()
|
277 |
+
|
278 |
+
def __getitem__(self, idx):
|
279 |
+
return self.data[idx]
|
280 |
+
|
281 |
+
|
282 |
+
class FreeModule(Module):
|
283 |
+
"""
|
284 |
+
Abstract base class for free modules.
|
285 |
+
|
286 |
+
Additional attributes:
|
287 |
+
|
288 |
+
- rank - rank of the free module
|
289 |
+
|
290 |
+
Non-implemented methods:
|
291 |
+
|
292 |
+
- submodule
|
293 |
+
"""
|
294 |
+
|
295 |
+
dtype = FreeModuleElement
|
296 |
+
|
297 |
+
def __init__(self, ring, rank):
|
298 |
+
Module.__init__(self, ring)
|
299 |
+
self.rank = rank
|
300 |
+
|
301 |
+
def __repr__(self):
|
302 |
+
return repr(self.ring) + "**" + repr(self.rank)
|
303 |
+
|
304 |
+
def is_submodule(self, other):
|
305 |
+
"""
|
306 |
+
Returns True if ``other`` is a submodule of ``self``.
|
307 |
+
|
308 |
+
Examples
|
309 |
+
========
|
310 |
+
|
311 |
+
>>> from sympy.abc import x
|
312 |
+
>>> from sympy import QQ
|
313 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
314 |
+
>>> M = F.submodule([2, x])
|
315 |
+
>>> F.is_submodule(F)
|
316 |
+
True
|
317 |
+
>>> F.is_submodule(M)
|
318 |
+
True
|
319 |
+
>>> M.is_submodule(F)
|
320 |
+
False
|
321 |
+
"""
|
322 |
+
if isinstance(other, SubModule):
|
323 |
+
return other.container == self
|
324 |
+
if isinstance(other, FreeModule):
|
325 |
+
return other.ring == self.ring and other.rank == self.rank
|
326 |
+
return False
|
327 |
+
|
328 |
+
def convert(self, elem, M=None):
|
329 |
+
"""
|
330 |
+
Convert ``elem`` into the internal representation.
|
331 |
+
|
332 |
+
This method is called implicitly whenever computations involve elements
|
333 |
+
not in the internal representation.
|
334 |
+
|
335 |
+
Examples
|
336 |
+
========
|
337 |
+
|
338 |
+
>>> from sympy.abc import x
|
339 |
+
>>> from sympy import QQ
|
340 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
341 |
+
>>> F.convert([1, 0])
|
342 |
+
[1, 0]
|
343 |
+
"""
|
344 |
+
if isinstance(elem, FreeModuleElement):
|
345 |
+
if elem.module is self:
|
346 |
+
return elem
|
347 |
+
if elem.module.rank != self.rank:
|
348 |
+
raise CoercionFailed
|
349 |
+
return FreeModuleElement(self,
|
350 |
+
tuple(self.ring.convert(x, elem.module.ring) for x in elem.data))
|
351 |
+
elif iterable(elem):
|
352 |
+
tpl = tuple(self.ring.convert(x) for x in elem)
|
353 |
+
if len(tpl) != self.rank:
|
354 |
+
raise CoercionFailed
|
355 |
+
return FreeModuleElement(self, tpl)
|
356 |
+
elif _aresame(elem, 0):
|
357 |
+
return FreeModuleElement(self, (self.ring.convert(0),)*self.rank)
|
358 |
+
else:
|
359 |
+
raise CoercionFailed
|
360 |
+
|
361 |
+
def is_zero(self):
|
362 |
+
"""
|
363 |
+
Returns True if ``self`` is a zero module.
|
364 |
+
|
365 |
+
(If, as this implementation assumes, the coefficient ring is not the
|
366 |
+
zero ring, then this is equivalent to the rank being zero.)
|
367 |
+
|
368 |
+
Examples
|
369 |
+
========
|
370 |
+
|
371 |
+
>>> from sympy.abc import x
|
372 |
+
>>> from sympy import QQ
|
373 |
+
>>> QQ.old_poly_ring(x).free_module(0).is_zero()
|
374 |
+
True
|
375 |
+
>>> QQ.old_poly_ring(x).free_module(1).is_zero()
|
376 |
+
False
|
377 |
+
"""
|
378 |
+
return self.rank == 0
|
379 |
+
|
380 |
+
def basis(self):
|
381 |
+
"""
|
382 |
+
Return a set of basis elements.
|
383 |
+
|
384 |
+
Examples
|
385 |
+
========
|
386 |
+
|
387 |
+
>>> from sympy.abc import x
|
388 |
+
>>> from sympy import QQ
|
389 |
+
>>> QQ.old_poly_ring(x).free_module(3).basis()
|
390 |
+
([1, 0, 0], [0, 1, 0], [0, 0, 1])
|
391 |
+
"""
|
392 |
+
from sympy.matrices import eye
|
393 |
+
M = eye(self.rank)
|
394 |
+
return tuple(self.convert(M.row(i)) for i in range(self.rank))
|
395 |
+
|
396 |
+
def quotient_module(self, submodule):
|
397 |
+
"""
|
398 |
+
Return a quotient module.
|
399 |
+
|
400 |
+
Examples
|
401 |
+
========
|
402 |
+
|
403 |
+
>>> from sympy.abc import x
|
404 |
+
>>> from sympy import QQ
|
405 |
+
>>> M = QQ.old_poly_ring(x).free_module(2)
|
406 |
+
>>> M.quotient_module(M.submodule([1, x], [x, 2]))
|
407 |
+
QQ[x]**2/<[1, x], [x, 2]>
|
408 |
+
|
409 |
+
Or more conicisely, using the overloaded division operator:
|
410 |
+
|
411 |
+
>>> QQ.old_poly_ring(x).free_module(2) / [[1, x], [x, 2]]
|
412 |
+
QQ[x]**2/<[1, x], [x, 2]>
|
413 |
+
"""
|
414 |
+
return QuotientModule(self.ring, self, submodule)
|
415 |
+
|
416 |
+
def multiply_ideal(self, other):
|
417 |
+
"""
|
418 |
+
Multiply ``self`` by the ideal ``other``.
|
419 |
+
|
420 |
+
Examples
|
421 |
+
========
|
422 |
+
|
423 |
+
>>> from sympy.abc import x
|
424 |
+
>>> from sympy import QQ
|
425 |
+
>>> I = QQ.old_poly_ring(x).ideal(x)
|
426 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
427 |
+
>>> F.multiply_ideal(I)
|
428 |
+
<[x, 0], [0, x]>
|
429 |
+
"""
|
430 |
+
return self.submodule(*self.basis()).multiply_ideal(other)
|
431 |
+
|
432 |
+
def identity_hom(self):
|
433 |
+
"""
|
434 |
+
Return the identity homomorphism on ``self``.
|
435 |
+
|
436 |
+
Examples
|
437 |
+
========
|
438 |
+
|
439 |
+
>>> from sympy.abc import x
|
440 |
+
>>> from sympy import QQ
|
441 |
+
>>> QQ.old_poly_ring(x).free_module(2).identity_hom()
|
442 |
+
Matrix([
|
443 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2
|
444 |
+
[0, 1]])
|
445 |
+
"""
|
446 |
+
from sympy.polys.agca.homomorphisms import homomorphism
|
447 |
+
return homomorphism(self, self, self.basis())
|
448 |
+
|
449 |
+
|
450 |
+
class FreeModulePolyRing(FreeModule):
|
451 |
+
"""
|
452 |
+
Free module over a generalized polynomial ring.
|
453 |
+
|
454 |
+
Do not instantiate this, use the constructor method of the ring instead:
|
455 |
+
|
456 |
+
Examples
|
457 |
+
========
|
458 |
+
|
459 |
+
>>> from sympy.abc import x
|
460 |
+
>>> from sympy import QQ
|
461 |
+
>>> F = QQ.old_poly_ring(x).free_module(3)
|
462 |
+
>>> F
|
463 |
+
QQ[x]**3
|
464 |
+
>>> F.contains([x, 1, 0])
|
465 |
+
True
|
466 |
+
>>> F.contains([1/x, 0, 1])
|
467 |
+
False
|
468 |
+
"""
|
469 |
+
|
470 |
+
def __init__(self, ring, rank):
|
471 |
+
from sympy.polys.domains.old_polynomialring import PolynomialRingBase
|
472 |
+
FreeModule.__init__(self, ring, rank)
|
473 |
+
if not isinstance(ring, PolynomialRingBase):
|
474 |
+
raise NotImplementedError('This implementation only works over '
|
475 |
+
+ 'polynomial rings, got %s' % ring)
|
476 |
+
if not isinstance(ring.dom, Field):
|
477 |
+
raise NotImplementedError('Ground domain must be a field, '
|
478 |
+
+ 'got %s' % ring.dom)
|
479 |
+
|
480 |
+
def submodule(self, *gens, **opts):
|
481 |
+
"""
|
482 |
+
Generate a submodule.
|
483 |
+
|
484 |
+
Examples
|
485 |
+
========
|
486 |
+
|
487 |
+
>>> from sympy.abc import x, y
|
488 |
+
>>> from sympy import QQ
|
489 |
+
>>> M = QQ.old_poly_ring(x, y).free_module(2).submodule([x, x + y])
|
490 |
+
>>> M
|
491 |
+
<[x, x + y]>
|
492 |
+
>>> M.contains([2*x, 2*x + 2*y])
|
493 |
+
True
|
494 |
+
>>> M.contains([x, y])
|
495 |
+
False
|
496 |
+
"""
|
497 |
+
return SubModulePolyRing(gens, self, **opts)
|
498 |
+
|
499 |
+
|
500 |
+
class FreeModuleQuotientRing(FreeModule):
|
501 |
+
"""
|
502 |
+
Free module over a quotient ring.
|
503 |
+
|
504 |
+
Do not instantiate this, use the constructor method of the ring instead:
|
505 |
+
|
506 |
+
Examples
|
507 |
+
========
|
508 |
+
|
509 |
+
>>> from sympy.abc import x
|
510 |
+
>>> from sympy import QQ
|
511 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(3)
|
512 |
+
>>> F
|
513 |
+
(QQ[x]/<x**2 + 1>)**3
|
514 |
+
|
515 |
+
Attributes
|
516 |
+
|
517 |
+
- quot - the quotient module `R^n / IR^n`, where `R/I` is our ring
|
518 |
+
"""
|
519 |
+
|
520 |
+
def __init__(self, ring, rank):
|
521 |
+
from sympy.polys.domains.quotientring import QuotientRing
|
522 |
+
FreeModule.__init__(self, ring, rank)
|
523 |
+
if not isinstance(ring, QuotientRing):
|
524 |
+
raise NotImplementedError('This implementation only works over '
|
525 |
+
+ 'quotient rings, got %s' % ring)
|
526 |
+
F = self.ring.ring.free_module(self.rank)
|
527 |
+
self.quot = F / (self.ring.base_ideal*F)
|
528 |
+
|
529 |
+
def __repr__(self):
|
530 |
+
return "(" + repr(self.ring) + ")" + "**" + repr(self.rank)
|
531 |
+
|
532 |
+
def submodule(self, *gens, **opts):
|
533 |
+
"""
|
534 |
+
Generate a submodule.
|
535 |
+
|
536 |
+
Examples
|
537 |
+
========
|
538 |
+
|
539 |
+
>>> from sympy.abc import x, y
|
540 |
+
>>> from sympy import QQ
|
541 |
+
>>> M = (QQ.old_poly_ring(x, y)/[x**2 - y**2]).free_module(2).submodule([x, x + y])
|
542 |
+
>>> M
|
543 |
+
<[x + <x**2 - y**2>, x + y + <x**2 - y**2>]>
|
544 |
+
>>> M.contains([y**2, x**2 + x*y])
|
545 |
+
True
|
546 |
+
>>> M.contains([x, y])
|
547 |
+
False
|
548 |
+
"""
|
549 |
+
return SubModuleQuotientRing(gens, self, **opts)
|
550 |
+
|
551 |
+
def lift(self, elem):
|
552 |
+
"""
|
553 |
+
Lift the element ``elem`` of self to the module self.quot.
|
554 |
+
|
555 |
+
Note that self.quot is the same set as self, just as an R-module
|
556 |
+
and not as an R/I-module, so this makes sense.
|
557 |
+
|
558 |
+
Examples
|
559 |
+
========
|
560 |
+
|
561 |
+
>>> from sympy.abc import x
|
562 |
+
>>> from sympy import QQ
|
563 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
|
564 |
+
>>> e = F.convert([1, 0])
|
565 |
+
>>> e
|
566 |
+
[1 + <x**2 + 1>, 0 + <x**2 + 1>]
|
567 |
+
>>> L = F.quot
|
568 |
+
>>> l = F.lift(e)
|
569 |
+
>>> l
|
570 |
+
[1, 0] + <[x**2 + 1, 0], [0, x**2 + 1]>
|
571 |
+
>>> L.contains(l)
|
572 |
+
True
|
573 |
+
"""
|
574 |
+
return self.quot.convert([x.data for x in elem])
|
575 |
+
|
576 |
+
def unlift(self, elem):
|
577 |
+
"""
|
578 |
+
Push down an element of self.quot to self.
|
579 |
+
|
580 |
+
This undoes ``lift``.
|
581 |
+
|
582 |
+
Examples
|
583 |
+
========
|
584 |
+
|
585 |
+
>>> from sympy.abc import x
|
586 |
+
>>> from sympy import QQ
|
587 |
+
>>> F = (QQ.old_poly_ring(x)/[x**2 + 1]).free_module(2)
|
588 |
+
>>> e = F.convert([1, 0])
|
589 |
+
>>> l = F.lift(e)
|
590 |
+
>>> e == l
|
591 |
+
False
|
592 |
+
>>> e == F.unlift(l)
|
593 |
+
True
|
594 |
+
"""
|
595 |
+
return self.convert(elem.data)
|
596 |
+
|
597 |
+
##########################################################################
|
598 |
+
## Submodules and subquotients ###########################################
|
599 |
+
##########################################################################
|
600 |
+
|
601 |
+
|
602 |
+
class SubModule(Module):
|
603 |
+
"""
|
604 |
+
Base class for submodules.
|
605 |
+
|
606 |
+
Attributes:
|
607 |
+
|
608 |
+
- container - containing module
|
609 |
+
- gens - generators (subset of containing module)
|
610 |
+
- rank - rank of containing module
|
611 |
+
|
612 |
+
Non-implemented methods:
|
613 |
+
|
614 |
+
- _contains
|
615 |
+
- _syzygies
|
616 |
+
- _in_terms_of_generators
|
617 |
+
- _intersect
|
618 |
+
- _module_quotient
|
619 |
+
|
620 |
+
Methods that likely need change in subclasses:
|
621 |
+
|
622 |
+
- reduce_element
|
623 |
+
"""
|
624 |
+
|
625 |
+
def __init__(self, gens, container):
|
626 |
+
Module.__init__(self, container.ring)
|
627 |
+
self.gens = tuple(container.convert(x) for x in gens)
|
628 |
+
self.container = container
|
629 |
+
self.rank = container.rank
|
630 |
+
self.ring = container.ring
|
631 |
+
self.dtype = container.dtype
|
632 |
+
|
633 |
+
def __repr__(self):
|
634 |
+
return "<" + ", ".join(repr(x) for x in self.gens) + ">"
|
635 |
+
|
636 |
+
def _contains(self, other):
|
637 |
+
"""Implementation of containment.
|
638 |
+
Other is guaranteed to be FreeModuleElement."""
|
639 |
+
raise NotImplementedError
|
640 |
+
|
641 |
+
def _syzygies(self):
|
642 |
+
"""Implementation of syzygy computation wrt self generators."""
|
643 |
+
raise NotImplementedError
|
644 |
+
|
645 |
+
def _in_terms_of_generators(self, e):
|
646 |
+
"""Implementation of expression in terms of generators."""
|
647 |
+
raise NotImplementedError
|
648 |
+
|
649 |
+
def convert(self, elem, M=None):
|
650 |
+
"""
|
651 |
+
Convert ``elem`` into the internal represantition.
|
652 |
+
|
653 |
+
Mostly called implicitly.
|
654 |
+
|
655 |
+
Examples
|
656 |
+
========
|
657 |
+
|
658 |
+
>>> from sympy.abc import x
|
659 |
+
>>> from sympy import QQ
|
660 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([1, x])
|
661 |
+
>>> M.convert([2, 2*x])
|
662 |
+
[2, 2*x]
|
663 |
+
"""
|
664 |
+
if isinstance(elem, self.container.dtype) and elem.module is self:
|
665 |
+
return elem
|
666 |
+
r = copy(self.container.convert(elem, M))
|
667 |
+
r.module = self
|
668 |
+
if not self._contains(r):
|
669 |
+
raise CoercionFailed
|
670 |
+
return r
|
671 |
+
|
672 |
+
def _intersect(self, other):
|
673 |
+
"""Implementation of intersection.
|
674 |
+
Other is guaranteed to be a submodule of same free module."""
|
675 |
+
raise NotImplementedError
|
676 |
+
|
677 |
+
def _module_quotient(self, other):
|
678 |
+
"""Implementation of quotient.
|
679 |
+
Other is guaranteed to be a submodule of same free module."""
|
680 |
+
raise NotImplementedError
|
681 |
+
|
682 |
+
def intersect(self, other, **options):
|
683 |
+
"""
|
684 |
+
Returns the intersection of ``self`` with submodule ``other``.
|
685 |
+
|
686 |
+
Examples
|
687 |
+
========
|
688 |
+
|
689 |
+
>>> from sympy.abc import x, y
|
690 |
+
>>> from sympy import QQ
|
691 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
692 |
+
>>> F.submodule([x, x]).intersect(F.submodule([y, y]))
|
693 |
+
<[x*y, x*y]>
|
694 |
+
|
695 |
+
Some implementation allow further options to be passed. Currently, to
|
696 |
+
only one implemented is ``relations=True``, in which case the function
|
697 |
+
will return a triple ``(res, rela, relb)``, where ``res`` is the
|
698 |
+
intersection module, and ``rela`` and ``relb`` are lists of coefficient
|
699 |
+
vectors, expressing the generators of ``res`` in terms of the
|
700 |
+
generators of ``self`` (``rela``) and ``other`` (``relb``).
|
701 |
+
|
702 |
+
>>> F.submodule([x, x]).intersect(F.submodule([y, y]), relations=True)
|
703 |
+
(<[x*y, x*y]>, [(y,)], [(x,)])
|
704 |
+
|
705 |
+
The above result says: the intersection module is generated by the
|
706 |
+
single element `(-xy, -xy) = -y (x, x) = -x (y, y)`, where
|
707 |
+
`(x, x)` and `(y, y)` respectively are the unique generators of
|
708 |
+
the two modules being intersected.
|
709 |
+
"""
|
710 |
+
if not isinstance(other, SubModule):
|
711 |
+
raise TypeError('%s is not a SubModule' % other)
|
712 |
+
if other.container != self.container:
|
713 |
+
raise ValueError(
|
714 |
+
'%s is contained in a different free module' % other)
|
715 |
+
return self._intersect(other, **options)
|
716 |
+
|
717 |
+
def module_quotient(self, other, **options):
|
718 |
+
r"""
|
719 |
+
Returns the module quotient of ``self`` by submodule ``other``.
|
720 |
+
|
721 |
+
That is, if ``self`` is the module `M` and ``other`` is `N`, then
|
722 |
+
return the ideal `\{f \in R | fN \subset M\}`.
|
723 |
+
|
724 |
+
Examples
|
725 |
+
========
|
726 |
+
|
727 |
+
>>> from sympy import QQ
|
728 |
+
>>> from sympy.abc import x, y
|
729 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
730 |
+
>>> S = F.submodule([x*y, x*y])
|
731 |
+
>>> T = F.submodule([x, x])
|
732 |
+
>>> S.module_quotient(T)
|
733 |
+
<y>
|
734 |
+
|
735 |
+
Some implementations allow further options to be passed. Currently, the
|
736 |
+
only one implemented is ``relations=True``, which may only be passed
|
737 |
+
if ``other`` is principal. In this case the function
|
738 |
+
will return a pair ``(res, rel)`` where ``res`` is the ideal, and
|
739 |
+
``rel`` is a list of coefficient vectors, expressing the generators of
|
740 |
+
the ideal, multiplied by the generator of ``other`` in terms of
|
741 |
+
generators of ``self``.
|
742 |
+
|
743 |
+
>>> S.module_quotient(T, relations=True)
|
744 |
+
(<y>, [[1]])
|
745 |
+
|
746 |
+
This means that the quotient ideal is generated by the single element
|
747 |
+
`y`, and that `y (x, x) = 1 (xy, xy)`, `(x, x)` and `(xy, xy)` being
|
748 |
+
the generators of `T` and `S`, respectively.
|
749 |
+
"""
|
750 |
+
if not isinstance(other, SubModule):
|
751 |
+
raise TypeError('%s is not a SubModule' % other)
|
752 |
+
if other.container != self.container:
|
753 |
+
raise ValueError(
|
754 |
+
'%s is contained in a different free module' % other)
|
755 |
+
return self._module_quotient(other, **options)
|
756 |
+
|
757 |
+
def union(self, other):
|
758 |
+
"""
|
759 |
+
Returns the module generated by the union of ``self`` and ``other``.
|
760 |
+
|
761 |
+
Examples
|
762 |
+
========
|
763 |
+
|
764 |
+
>>> from sympy.abc import x
|
765 |
+
>>> from sympy import QQ
|
766 |
+
>>> F = QQ.old_poly_ring(x).free_module(1)
|
767 |
+
>>> M = F.submodule([x**2 + x]) # <x(x+1)>
|
768 |
+
>>> N = F.submodule([x**2 - 1]) # <(x-1)(x+1)>
|
769 |
+
>>> M.union(N) == F.submodule([x+1])
|
770 |
+
True
|
771 |
+
"""
|
772 |
+
if not isinstance(other, SubModule):
|
773 |
+
raise TypeError('%s is not a SubModule' % other)
|
774 |
+
if other.container != self.container:
|
775 |
+
raise ValueError(
|
776 |
+
'%s is contained in a different free module' % other)
|
777 |
+
return self.__class__(self.gens + other.gens, self.container)
|
778 |
+
|
779 |
+
def is_zero(self):
|
780 |
+
"""
|
781 |
+
Return True if ``self`` is a zero module.
|
782 |
+
|
783 |
+
Examples
|
784 |
+
========
|
785 |
+
|
786 |
+
>>> from sympy.abc import x
|
787 |
+
>>> from sympy import QQ
|
788 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
789 |
+
>>> F.submodule([x, 1]).is_zero()
|
790 |
+
False
|
791 |
+
>>> F.submodule([0, 0]).is_zero()
|
792 |
+
True
|
793 |
+
"""
|
794 |
+
return all(x == 0 for x in self.gens)
|
795 |
+
|
796 |
+
def submodule(self, *gens):
|
797 |
+
"""
|
798 |
+
Generate a submodule.
|
799 |
+
|
800 |
+
Examples
|
801 |
+
========
|
802 |
+
|
803 |
+
>>> from sympy.abc import x
|
804 |
+
>>> from sympy import QQ
|
805 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([x, 1])
|
806 |
+
>>> M.submodule([x**2, x])
|
807 |
+
<[x**2, x]>
|
808 |
+
"""
|
809 |
+
if not self.subset(gens):
|
810 |
+
raise ValueError('%s not a subset of %s' % (gens, self))
|
811 |
+
return self.__class__(gens, self.container)
|
812 |
+
|
813 |
+
def is_full_module(self):
|
814 |
+
"""
|
815 |
+
Return True if ``self`` is the entire free module.
|
816 |
+
|
817 |
+
Examples
|
818 |
+
========
|
819 |
+
|
820 |
+
>>> from sympy.abc import x
|
821 |
+
>>> from sympy import QQ
|
822 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
823 |
+
>>> F.submodule([x, 1]).is_full_module()
|
824 |
+
False
|
825 |
+
>>> F.submodule([1, 1], [1, 2]).is_full_module()
|
826 |
+
True
|
827 |
+
"""
|
828 |
+
return all(self.contains(x) for x in self.container.basis())
|
829 |
+
|
830 |
+
def is_submodule(self, other):
|
831 |
+
"""
|
832 |
+
Returns True if ``other`` is a submodule of ``self``.
|
833 |
+
|
834 |
+
>>> from sympy.abc import x
|
835 |
+
>>> from sympy import QQ
|
836 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
837 |
+
>>> M = F.submodule([2, x])
|
838 |
+
>>> N = M.submodule([2*x, x**2])
|
839 |
+
>>> M.is_submodule(M)
|
840 |
+
True
|
841 |
+
>>> M.is_submodule(N)
|
842 |
+
True
|
843 |
+
>>> N.is_submodule(M)
|
844 |
+
False
|
845 |
+
"""
|
846 |
+
if isinstance(other, SubModule):
|
847 |
+
return self.container == other.container and \
|
848 |
+
all(self.contains(x) for x in other.gens)
|
849 |
+
if isinstance(other, (FreeModule, QuotientModule)):
|
850 |
+
return self.container == other and self.is_full_module()
|
851 |
+
return False
|
852 |
+
|
853 |
+
def syzygy_module(self, **opts):
|
854 |
+
r"""
|
855 |
+
Compute the syzygy module of the generators of ``self``.
|
856 |
+
|
857 |
+
Suppose `M` is generated by `f_1, \ldots, f_n` over the ring
|
858 |
+
`R`. Consider the homomorphism `\phi: R^n \to M`, given by
|
859 |
+
sending `(r_1, \ldots, r_n) \to r_1 f_1 + \cdots + r_n f_n`.
|
860 |
+
The syzygy module is defined to be the kernel of `\phi`.
|
861 |
+
|
862 |
+
Examples
|
863 |
+
========
|
864 |
+
|
865 |
+
The syzygy module is zero iff the generators generate freely a free
|
866 |
+
submodule:
|
867 |
+
|
868 |
+
>>> from sympy.abc import x, y
|
869 |
+
>>> from sympy import QQ
|
870 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([1, 0], [1, 1]).syzygy_module().is_zero()
|
871 |
+
True
|
872 |
+
|
873 |
+
A slightly more interesting example:
|
874 |
+
|
875 |
+
>>> M = QQ.old_poly_ring(x, y).free_module(2).submodule([x, 2*x], [y, 2*y])
|
876 |
+
>>> S = QQ.old_poly_ring(x, y).free_module(2).submodule([y, -x])
|
877 |
+
>>> M.syzygy_module() == S
|
878 |
+
True
|
879 |
+
"""
|
880 |
+
F = self.ring.free_module(len(self.gens))
|
881 |
+
# NOTE we filter out zero syzygies. This is for convenience of the
|
882 |
+
# _syzygies function and not meant to replace any real "generating set
|
883 |
+
# reduction" algorithm
|
884 |
+
return F.submodule(*[x for x in self._syzygies() if F.convert(x) != 0],
|
885 |
+
**opts)
|
886 |
+
|
887 |
+
def in_terms_of_generators(self, e):
|
888 |
+
"""
|
889 |
+
Express element ``e`` of ``self`` in terms of the generators.
|
890 |
+
|
891 |
+
Examples
|
892 |
+
========
|
893 |
+
|
894 |
+
>>> from sympy.abc import x
|
895 |
+
>>> from sympy import QQ
|
896 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
897 |
+
>>> M = F.submodule([1, 0], [1, 1])
|
898 |
+
>>> M.in_terms_of_generators([x, x**2])
|
899 |
+
[-x**2 + x, x**2]
|
900 |
+
"""
|
901 |
+
try:
|
902 |
+
e = self.convert(e)
|
903 |
+
except CoercionFailed:
|
904 |
+
raise ValueError('%s is not an element of %s' % (e, self))
|
905 |
+
return self._in_terms_of_generators(e)
|
906 |
+
|
907 |
+
def reduce_element(self, x):
|
908 |
+
"""
|
909 |
+
Reduce the element ``x`` of our ring modulo the ideal ``self``.
|
910 |
+
|
911 |
+
Here "reduce" has no specific meaning, it could return a unique normal
|
912 |
+
form, simplify the expression a bit, or just do nothing.
|
913 |
+
"""
|
914 |
+
return x
|
915 |
+
|
916 |
+
def quotient_module(self, other, **opts):
|
917 |
+
"""
|
918 |
+
Return a quotient module.
|
919 |
+
|
920 |
+
This is the same as taking a submodule of a quotient of the containing
|
921 |
+
module.
|
922 |
+
|
923 |
+
Examples
|
924 |
+
========
|
925 |
+
|
926 |
+
>>> from sympy.abc import x
|
927 |
+
>>> from sympy import QQ
|
928 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
929 |
+
>>> S1 = F.submodule([x, 1])
|
930 |
+
>>> S2 = F.submodule([x**2, x])
|
931 |
+
>>> S1.quotient_module(S2)
|
932 |
+
<[x, 1] + <[x**2, x]>>
|
933 |
+
|
934 |
+
Or more coincisely, using the overloaded division operator:
|
935 |
+
|
936 |
+
>>> F.submodule([x, 1]) / [(x**2, x)]
|
937 |
+
<[x, 1] + <[x**2, x]>>
|
938 |
+
"""
|
939 |
+
if not self.is_submodule(other):
|
940 |
+
raise ValueError('%s not a submodule of %s' % (other, self))
|
941 |
+
return SubQuotientModule(self.gens,
|
942 |
+
self.container.quotient_module(other), **opts)
|
943 |
+
|
944 |
+
def __add__(self, oth):
|
945 |
+
return self.container.quotient_module(self).convert(oth)
|
946 |
+
|
947 |
+
__radd__ = __add__
|
948 |
+
|
949 |
+
def multiply_ideal(self, I):
|
950 |
+
"""
|
951 |
+
Multiply ``self`` by the ideal ``I``.
|
952 |
+
|
953 |
+
Examples
|
954 |
+
========
|
955 |
+
|
956 |
+
>>> from sympy.abc import x
|
957 |
+
>>> from sympy import QQ
|
958 |
+
>>> I = QQ.old_poly_ring(x).ideal(x**2)
|
959 |
+
>>> M = QQ.old_poly_ring(x).free_module(2).submodule([1, 1])
|
960 |
+
>>> I*M
|
961 |
+
<[x**2, x**2]>
|
962 |
+
"""
|
963 |
+
return self.submodule(*[x*g for [x] in I._module.gens for g in self.gens])
|
964 |
+
|
965 |
+
def inclusion_hom(self):
|
966 |
+
"""
|
967 |
+
Return a homomorphism representing the inclusion map of ``self``.
|
968 |
+
|
969 |
+
That is, the natural map from ``self`` to ``self.container``.
|
970 |
+
|
971 |
+
Examples
|
972 |
+
========
|
973 |
+
|
974 |
+
>>> from sympy.abc import x
|
975 |
+
>>> from sympy import QQ
|
976 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([x, x]).inclusion_hom()
|
977 |
+
Matrix([
|
978 |
+
[1, 0], : <[x, x]> -> QQ[x]**2
|
979 |
+
[0, 1]])
|
980 |
+
"""
|
981 |
+
return self.container.identity_hom().restrict_domain(self)
|
982 |
+
|
983 |
+
def identity_hom(self):
|
984 |
+
"""
|
985 |
+
Return the identity homomorphism on ``self``.
|
986 |
+
|
987 |
+
Examples
|
988 |
+
========
|
989 |
+
|
990 |
+
>>> from sympy.abc import x
|
991 |
+
>>> from sympy import QQ
|
992 |
+
>>> QQ.old_poly_ring(x).free_module(2).submodule([x, x]).identity_hom()
|
993 |
+
Matrix([
|
994 |
+
[1, 0], : <[x, x]> -> <[x, x]>
|
995 |
+
[0, 1]])
|
996 |
+
"""
|
997 |
+
return self.container.identity_hom().restrict_domain(
|
998 |
+
self).restrict_codomain(self)
|
999 |
+
|
1000 |
+
|
1001 |
+
class SubQuotientModule(SubModule):
|
1002 |
+
"""
|
1003 |
+
Submodule of a quotient module.
|
1004 |
+
|
1005 |
+
Equivalently, quotient module of a submodule.
|
1006 |
+
|
1007 |
+
Do not instantiate this, instead use the submodule or quotient_module
|
1008 |
+
constructing methods:
|
1009 |
+
|
1010 |
+
>>> from sympy.abc import x
|
1011 |
+
>>> from sympy import QQ
|
1012 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
1013 |
+
>>> S = F.submodule([1, 0], [1, x])
|
1014 |
+
>>> Q = F/[(1, 0)]
|
1015 |
+
>>> S/[(1, 0)] == Q.submodule([5, x])
|
1016 |
+
True
|
1017 |
+
|
1018 |
+
Attributes:
|
1019 |
+
|
1020 |
+
- base - base module we are quotient of
|
1021 |
+
- killed_module - submodule used to form the quotient
|
1022 |
+
"""
|
1023 |
+
def __init__(self, gens, container, **opts):
|
1024 |
+
SubModule.__init__(self, gens, container)
|
1025 |
+
self.killed_module = self.container.killed_module
|
1026 |
+
# XXX it is important for some code below that the generators of base
|
1027 |
+
# are in this particular order!
|
1028 |
+
self.base = self.container.base.submodule(
|
1029 |
+
*[x.data for x in self.gens], **opts).union(self.killed_module)
|
1030 |
+
|
1031 |
+
def _contains(self, elem):
|
1032 |
+
return self.base.contains(elem.data)
|
1033 |
+
|
1034 |
+
def _syzygies(self):
|
1035 |
+
# let N = self.killed_module be generated by e_1, ..., e_r
|
1036 |
+
# let F = self.base be generated by f_1, ..., f_s and e_1, ..., e_r
|
1037 |
+
# Then self = F/N.
|
1038 |
+
# Let phi: R**s --> self be the evident surjection.
|
1039 |
+
# Similarly psi: R**(s + r) --> F.
|
1040 |
+
# We need to find generators for ker(phi). Let chi: R**s --> F be the
|
1041 |
+
# evident lift of phi. For X in R**s, phi(X) = 0 iff chi(X) is
|
1042 |
+
# contained in N, iff there exists Y in R**r such that
|
1043 |
+
# psi(X, Y) = 0.
|
1044 |
+
# Hence if alpha: R**(s + r) --> R**s is the projection map, then
|
1045 |
+
# ker(phi) = alpha ker(psi).
|
1046 |
+
return [X[:len(self.gens)] for X in self.base._syzygies()]
|
1047 |
+
|
1048 |
+
def _in_terms_of_generators(self, e):
|
1049 |
+
return self.base._in_terms_of_generators(e.data)[:len(self.gens)]
|
1050 |
+
|
1051 |
+
def is_full_module(self):
|
1052 |
+
"""
|
1053 |
+
Return True if ``self`` is the entire free module.
|
1054 |
+
|
1055 |
+
Examples
|
1056 |
+
========
|
1057 |
+
|
1058 |
+
>>> from sympy.abc import x
|
1059 |
+
>>> from sympy import QQ
|
1060 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
1061 |
+
>>> F.submodule([x, 1]).is_full_module()
|
1062 |
+
False
|
1063 |
+
>>> F.submodule([1, 1], [1, 2]).is_full_module()
|
1064 |
+
True
|
1065 |
+
"""
|
1066 |
+
return self.base.is_full_module()
|
1067 |
+
|
1068 |
+
def quotient_hom(self):
|
1069 |
+
"""
|
1070 |
+
Return the quotient homomorphism to self.
|
1071 |
+
|
1072 |
+
That is, return the natural map from ``self.base`` to ``self``.
|
1073 |
+
|
1074 |
+
Examples
|
1075 |
+
========
|
1076 |
+
|
1077 |
+
>>> from sympy.abc import x
|
1078 |
+
>>> from sympy import QQ
|
1079 |
+
>>> M = (QQ.old_poly_ring(x).free_module(2) / [(1, x)]).submodule([1, 0])
|
1080 |
+
>>> M.quotient_hom()
|
1081 |
+
Matrix([
|
1082 |
+
[1, 0], : <[1, 0], [1, x]> -> <[1, 0] + <[1, x]>, [1, x] + <[1, x]>>
|
1083 |
+
[0, 1]])
|
1084 |
+
"""
|
1085 |
+
return self.base.identity_hom().quotient_codomain(self.killed_module)
|
1086 |
+
|
1087 |
+
|
1088 |
+
_subs0 = lambda x: x[0]
|
1089 |
+
_subs1 = lambda x: x[1:]
|
1090 |
+
|
1091 |
+
|
1092 |
+
class ModuleOrder(ProductOrder):
|
1093 |
+
"""A product monomial order with a zeroth term as module index."""
|
1094 |
+
|
1095 |
+
def __init__(self, o1, o2, TOP):
|
1096 |
+
if TOP:
|
1097 |
+
ProductOrder.__init__(self, (o2, _subs1), (o1, _subs0))
|
1098 |
+
else:
|
1099 |
+
ProductOrder.__init__(self, (o1, _subs0), (o2, _subs1))
|
1100 |
+
|
1101 |
+
|
1102 |
+
class SubModulePolyRing(SubModule):
|
1103 |
+
"""
|
1104 |
+
Submodule of a free module over a generalized polynomial ring.
|
1105 |
+
|
1106 |
+
Do not instantiate this, use the constructor method of FreeModule instead:
|
1107 |
+
|
1108 |
+
>>> from sympy.abc import x, y
|
1109 |
+
>>> from sympy import QQ
|
1110 |
+
>>> F = QQ.old_poly_ring(x, y).free_module(2)
|
1111 |
+
>>> F.submodule([x, y], [1, 0])
|
1112 |
+
<[x, y], [1, 0]>
|
1113 |
+
|
1114 |
+
Attributes:
|
1115 |
+
|
1116 |
+
- order - monomial order used
|
1117 |
+
"""
|
1118 |
+
|
1119 |
+
#self._gb - cached groebner basis
|
1120 |
+
#self._gbe - cached groebner basis relations
|
1121 |
+
|
1122 |
+
def __init__(self, gens, container, order="lex", TOP=True):
|
1123 |
+
SubModule.__init__(self, gens, container)
|
1124 |
+
if not isinstance(container, FreeModulePolyRing):
|
1125 |
+
raise NotImplementedError('This implementation is for submodules of '
|
1126 |
+
+ 'FreeModulePolyRing, got %s' % container)
|
1127 |
+
self.order = ModuleOrder(monomial_key(order), self.ring.order, TOP)
|
1128 |
+
self._gb = None
|
1129 |
+
self._gbe = None
|
1130 |
+
|
1131 |
+
def __eq__(self, other):
|
1132 |
+
if isinstance(other, SubModulePolyRing) and self.order != other.order:
|
1133 |
+
return False
|
1134 |
+
return SubModule.__eq__(self, other)
|
1135 |
+
|
1136 |
+
def _groebner(self, extended=False):
|
1137 |
+
"""Returns a standard basis in sdm form."""
|
1138 |
+
from sympy.polys.distributedmodules import sdm_groebner, sdm_nf_mora
|
1139 |
+
if self._gbe is None and extended:
|
1140 |
+
gb, gbe = sdm_groebner(
|
1141 |
+
[self.ring._vector_to_sdm(x, self.order) for x in self.gens],
|
1142 |
+
sdm_nf_mora, self.order, self.ring.dom, extended=True)
|
1143 |
+
self._gb, self._gbe = tuple(gb), tuple(gbe)
|
1144 |
+
if self._gb is None:
|
1145 |
+
self._gb = tuple(sdm_groebner(
|
1146 |
+
[self.ring._vector_to_sdm(x, self.order) for x in self.gens],
|
1147 |
+
sdm_nf_mora, self.order, self.ring.dom))
|
1148 |
+
if extended:
|
1149 |
+
return self._gb, self._gbe
|
1150 |
+
else:
|
1151 |
+
return self._gb
|
1152 |
+
|
1153 |
+
def _groebner_vec(self, extended=False):
|
1154 |
+
"""Returns a standard basis in element form."""
|
1155 |
+
if not extended:
|
1156 |
+
return [FreeModuleElement(self,
|
1157 |
+
tuple(self.ring._sdm_to_vector(x, self.rank)))
|
1158 |
+
for x in self._groebner()]
|
1159 |
+
gb, gbe = self._groebner(extended=True)
|
1160 |
+
return ([self.convert(self.ring._sdm_to_vector(x, self.rank))
|
1161 |
+
for x in gb],
|
1162 |
+
[self.ring._sdm_to_vector(x, len(self.gens)) for x in gbe])
|
1163 |
+
|
1164 |
+
def _contains(self, x):
|
1165 |
+
from sympy.polys.distributedmodules import sdm_zero, sdm_nf_mora
|
1166 |
+
return sdm_nf_mora(self.ring._vector_to_sdm(x, self.order),
|
1167 |
+
self._groebner(), self.order, self.ring.dom) == \
|
1168 |
+
sdm_zero()
|
1169 |
+
|
1170 |
+
def _syzygies(self):
|
1171 |
+
"""Compute syzygies. See [SCA, algorithm 2.5.4]."""
|
1172 |
+
# NOTE if self.gens is a standard basis, this can be done more
|
1173 |
+
# efficiently using Schreyer's theorem
|
1174 |
+
|
1175 |
+
# First bullet point
|
1176 |
+
k = len(self.gens)
|
1177 |
+
r = self.rank
|
1178 |
+
zero = self.ring.convert(0)
|
1179 |
+
one = self.ring.convert(1)
|
1180 |
+
Rkr = self.ring.free_module(r + k)
|
1181 |
+
newgens = []
|
1182 |
+
for j, f in enumerate(self.gens):
|
1183 |
+
m = [0]*(r + k)
|
1184 |
+
for i, v in enumerate(f):
|
1185 |
+
m[i] = f[i]
|
1186 |
+
for i in range(k):
|
1187 |
+
m[r + i] = one if j == i else zero
|
1188 |
+
m = FreeModuleElement(Rkr, tuple(m))
|
1189 |
+
newgens.append(m)
|
1190 |
+
# Note: we need *descending* order on module index, and TOP=False to
|
1191 |
+
# get an elimination order
|
1192 |
+
F = Rkr.submodule(*newgens, order='ilex', TOP=False)
|
1193 |
+
|
1194 |
+
# Second bullet point: standard basis of F
|
1195 |
+
G = F._groebner_vec()
|
1196 |
+
|
1197 |
+
# Third bullet point: G0 = G intersect the new k components
|
1198 |
+
G0 = [x[r:] for x in G if all(y == zero for y in x[:r])]
|
1199 |
+
|
1200 |
+
# Fourth and fifth bullet points: we are done
|
1201 |
+
return G0
|
1202 |
+
|
1203 |
+
def _in_terms_of_generators(self, e):
|
1204 |
+
"""Expression in terms of generators. See [SCA, 2.8.1]."""
|
1205 |
+
# NOTE: if gens is a standard basis, this can be done more efficiently
|
1206 |
+
M = self.ring.free_module(self.rank).submodule(*((e,) + self.gens))
|
1207 |
+
S = M.syzygy_module(
|
1208 |
+
order="ilex", TOP=False) # We want decreasing order!
|
1209 |
+
G = S._groebner_vec()
|
1210 |
+
# This list cannot not be empty since e is an element
|
1211 |
+
e = [x for x in G if self.ring.is_unit(x[0])][0]
|
1212 |
+
return [-x/e[0] for x in e[1:]]
|
1213 |
+
|
1214 |
+
def reduce_element(self, x, NF=None):
|
1215 |
+
"""
|
1216 |
+
Reduce the element ``x`` of our container modulo ``self``.
|
1217 |
+
|
1218 |
+
This applies the normal form ``NF`` to ``x``. If ``NF`` is passed
|
1219 |
+
as none, the default Mora normal form is used (which is not unique!).
|
1220 |
+
"""
|
1221 |
+
from sympy.polys.distributedmodules import sdm_nf_mora
|
1222 |
+
if NF is None:
|
1223 |
+
NF = sdm_nf_mora
|
1224 |
+
return self.container.convert(self.ring._sdm_to_vector(NF(
|
1225 |
+
self.ring._vector_to_sdm(x, self.order), self._groebner(),
|
1226 |
+
self.order, self.ring.dom),
|
1227 |
+
self.rank))
|
1228 |
+
|
1229 |
+
def _intersect(self, other, relations=False):
|
1230 |
+
# See: [SCA, section 2.8.2]
|
1231 |
+
fi = self.gens
|
1232 |
+
hi = other.gens
|
1233 |
+
r = self.rank
|
1234 |
+
ci = [[0]*(2*r) for _ in range(r)]
|
1235 |
+
for k in range(r):
|
1236 |
+
ci[k][k] = 1
|
1237 |
+
ci[k][r + k] = 1
|
1238 |
+
di = [list(f) + [0]*r for f in fi]
|
1239 |
+
ei = [[0]*r + list(h) for h in hi]
|
1240 |
+
syz = self.ring.free_module(2*r).submodule(*(ci + di + ei))._syzygies()
|
1241 |
+
nonzero = [x for x in syz if any(y != self.ring.zero for y in x[:r])]
|
1242 |
+
res = self.container.submodule(*([-y for y in x[:r]] for x in nonzero))
|
1243 |
+
reln1 = [x[r:r + len(fi)] for x in nonzero]
|
1244 |
+
reln2 = [x[r + len(fi):] for x in nonzero]
|
1245 |
+
if relations:
|
1246 |
+
return res, reln1, reln2
|
1247 |
+
return res
|
1248 |
+
|
1249 |
+
def _module_quotient(self, other, relations=False):
|
1250 |
+
# See: [SCA, section 2.8.4]
|
1251 |
+
if relations and len(other.gens) != 1:
|
1252 |
+
raise NotImplementedError
|
1253 |
+
if len(other.gens) == 0:
|
1254 |
+
return self.ring.ideal(1)
|
1255 |
+
elif len(other.gens) == 1:
|
1256 |
+
# We do some trickery. Let f be the (vector!) generating ``other``
|
1257 |
+
# and f1, .., fn be the (vectors) generating self.
|
1258 |
+
# Consider the submodule of R^{r+1} generated by (f, 1) and
|
1259 |
+
# {(fi, 0) | i}. Then the intersection with the last module
|
1260 |
+
# component yields the quotient.
|
1261 |
+
g1 = list(other.gens[0]) + [1]
|
1262 |
+
gi = [list(x) + [0] for x in self.gens]
|
1263 |
+
# NOTE: We *need* to use an elimination order
|
1264 |
+
M = self.ring.free_module(self.rank + 1).submodule(*([g1] + gi),
|
1265 |
+
order='ilex', TOP=False)
|
1266 |
+
if not relations:
|
1267 |
+
return self.ring.ideal(*[x[-1] for x in M._groebner_vec() if
|
1268 |
+
all(y == self.ring.zero for y in x[:-1])])
|
1269 |
+
else:
|
1270 |
+
G, R = M._groebner_vec(extended=True)
|
1271 |
+
indices = [i for i, x in enumerate(G) if
|
1272 |
+
all(y == self.ring.zero for y in x[:-1])]
|
1273 |
+
return (self.ring.ideal(*[G[i][-1] for i in indices]),
|
1274 |
+
[[-x for x in R[i][1:]] for i in indices])
|
1275 |
+
# For more generators, we use I : <h1, .., hn> = intersection of
|
1276 |
+
# {I : <hi> | i}
|
1277 |
+
# TODO this can be done more efficiently
|
1278 |
+
return reduce(lambda x, y: x.intersect(y),
|
1279 |
+
(self._module_quotient(self.container.submodule(x)) for x in other.gens))
|
1280 |
+
|
1281 |
+
|
1282 |
+
class SubModuleQuotientRing(SubModule):
|
1283 |
+
"""
|
1284 |
+
Class for submodules of free modules over quotient rings.
|
1285 |
+
|
1286 |
+
Do not instantiate this. Instead use the submodule methods.
|
1287 |
+
|
1288 |
+
>>> from sympy.abc import x, y
|
1289 |
+
>>> from sympy import QQ
|
1290 |
+
>>> M = (QQ.old_poly_ring(x, y)/[x**2 - y**2]).free_module(2).submodule([x, x + y])
|
1291 |
+
>>> M
|
1292 |
+
<[x + <x**2 - y**2>, x + y + <x**2 - y**2>]>
|
1293 |
+
>>> M.contains([y**2, x**2 + x*y])
|
1294 |
+
True
|
1295 |
+
>>> M.contains([x, y])
|
1296 |
+
False
|
1297 |
+
|
1298 |
+
Attributes:
|
1299 |
+
|
1300 |
+
- quot - the subquotient of `R^n/IR^n` generated by lifts of our generators
|
1301 |
+
"""
|
1302 |
+
|
1303 |
+
def __init__(self, gens, container):
|
1304 |
+
SubModule.__init__(self, gens, container)
|
1305 |
+
self.quot = self.container.quot.submodule(
|
1306 |
+
*[self.container.lift(x) for x in self.gens])
|
1307 |
+
|
1308 |
+
def _contains(self, elem):
|
1309 |
+
return self.quot._contains(self.container.lift(elem))
|
1310 |
+
|
1311 |
+
def _syzygies(self):
|
1312 |
+
return [tuple(self.ring.convert(y, self.quot.ring) for y in x)
|
1313 |
+
for x in self.quot._syzygies()]
|
1314 |
+
|
1315 |
+
def _in_terms_of_generators(self, elem):
|
1316 |
+
return [self.ring.convert(x, self.quot.ring) for x in
|
1317 |
+
self.quot._in_terms_of_generators(self.container.lift(elem))]
|
1318 |
+
|
1319 |
+
##########################################################################
|
1320 |
+
## Quotient Modules ######################################################
|
1321 |
+
##########################################################################
|
1322 |
+
|
1323 |
+
|
1324 |
+
class QuotientModuleElement(ModuleElement):
|
1325 |
+
"""Element of a quotient module."""
|
1326 |
+
|
1327 |
+
def eq(self, d1, d2):
|
1328 |
+
"""Equality comparison."""
|
1329 |
+
return self.module.killed_module.contains(d1 - d2)
|
1330 |
+
|
1331 |
+
def __repr__(self):
|
1332 |
+
return repr(self.data) + " + " + repr(self.module.killed_module)
|
1333 |
+
|
1334 |
+
|
1335 |
+
class QuotientModule(Module):
|
1336 |
+
"""
|
1337 |
+
Class for quotient modules.
|
1338 |
+
|
1339 |
+
Do not instantiate this directly. For subquotients, see the
|
1340 |
+
SubQuotientModule class.
|
1341 |
+
|
1342 |
+
Attributes:
|
1343 |
+
|
1344 |
+
- base - the base module we are a quotient of
|
1345 |
+
- killed_module - the submodule used to form the quotient
|
1346 |
+
- rank of the base
|
1347 |
+
"""
|
1348 |
+
|
1349 |
+
dtype = QuotientModuleElement
|
1350 |
+
|
1351 |
+
def __init__(self, ring, base, submodule):
|
1352 |
+
Module.__init__(self, ring)
|
1353 |
+
if not base.is_submodule(submodule):
|
1354 |
+
raise ValueError('%s is not a submodule of %s' % (submodule, base))
|
1355 |
+
self.base = base
|
1356 |
+
self.killed_module = submodule
|
1357 |
+
self.rank = base.rank
|
1358 |
+
|
1359 |
+
def __repr__(self):
|
1360 |
+
return repr(self.base) + "/" + repr(self.killed_module)
|
1361 |
+
|
1362 |
+
def is_zero(self):
|
1363 |
+
"""
|
1364 |
+
Return True if ``self`` is a zero module.
|
1365 |
+
|
1366 |
+
This happens if and only if the base module is the same as the
|
1367 |
+
submodule being killed.
|
1368 |
+
|
1369 |
+
Examples
|
1370 |
+
========
|
1371 |
+
|
1372 |
+
>>> from sympy.abc import x
|
1373 |
+
>>> from sympy import QQ
|
1374 |
+
>>> F = QQ.old_poly_ring(x).free_module(2)
|
1375 |
+
>>> (F/[(1, 0)]).is_zero()
|
1376 |
+
False
|
1377 |
+
>>> (F/[(1, 0), (0, 1)]).is_zero()
|
1378 |
+
True
|
1379 |
+
"""
|
1380 |
+
return self.base == self.killed_module
|
1381 |
+
|
1382 |
+
def is_submodule(self, other):
|
1383 |
+
"""
|
1384 |
+
Return True if ``other`` is a submodule of ``self``.
|
1385 |
+
|
1386 |
+
Examples
|
1387 |
+
========
|
1388 |
+
|
1389 |
+
>>> from sympy.abc import x
|
1390 |
+
>>> from sympy import QQ
|
1391 |
+
>>> Q = QQ.old_poly_ring(x).free_module(2) / [(x, x)]
|
1392 |
+
>>> S = Q.submodule([1, 0])
|
1393 |
+
>>> Q.is_submodule(S)
|
1394 |
+
True
|
1395 |
+
>>> S.is_submodule(Q)
|
1396 |
+
False
|
1397 |
+
"""
|
1398 |
+
if isinstance(other, QuotientModule):
|
1399 |
+
return self.killed_module == other.killed_module and \
|
1400 |
+
self.base.is_submodule(other.base)
|
1401 |
+
if isinstance(other, SubQuotientModule):
|
1402 |
+
return other.container == self
|
1403 |
+
return False
|
1404 |
+
|
1405 |
+
def submodule(self, *gens, **opts):
|
1406 |
+
"""
|
1407 |
+
Generate a submodule.
|
1408 |
+
|
1409 |
+
This is the same as taking a quotient of a submodule of the base
|
1410 |
+
module.
|
1411 |
+
|
1412 |
+
Examples
|
1413 |
+
========
|
1414 |
+
|
1415 |
+
>>> from sympy.abc import x
|
1416 |
+
>>> from sympy import QQ
|
1417 |
+
>>> Q = QQ.old_poly_ring(x).free_module(2) / [(x, x)]
|
1418 |
+
>>> Q.submodule([x, 0])
|
1419 |
+
<[x, 0] + <[x, x]>>
|
1420 |
+
"""
|
1421 |
+
return SubQuotientModule(gens, self, **opts)
|
1422 |
+
|
1423 |
+
def convert(self, elem, M=None):
|
1424 |
+
"""
|
1425 |
+
Convert ``elem`` into the internal representation.
|
1426 |
+
|
1427 |
+
This method is called implicitly whenever computations involve elements
|
1428 |
+
not in the internal representation.
|
1429 |
+
|
1430 |
+
Examples
|
1431 |
+
========
|
1432 |
+
|
1433 |
+
>>> from sympy.abc import x
|
1434 |
+
>>> from sympy import QQ
|
1435 |
+
>>> F = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
1436 |
+
>>> F.convert([1, 0])
|
1437 |
+
[1, 0] + <[1, 2], [1, x]>
|
1438 |
+
"""
|
1439 |
+
if isinstance(elem, QuotientModuleElement):
|
1440 |
+
if elem.module is self:
|
1441 |
+
return elem
|
1442 |
+
if self.killed_module.is_submodule(elem.module.killed_module):
|
1443 |
+
return QuotientModuleElement(self, self.base.convert(elem.data))
|
1444 |
+
raise CoercionFailed
|
1445 |
+
return QuotientModuleElement(self, self.base.convert(elem))
|
1446 |
+
|
1447 |
+
def identity_hom(self):
|
1448 |
+
"""
|
1449 |
+
Return the identity homomorphism on ``self``.
|
1450 |
+
|
1451 |
+
Examples
|
1452 |
+
========
|
1453 |
+
|
1454 |
+
>>> from sympy.abc import x
|
1455 |
+
>>> from sympy import QQ
|
1456 |
+
>>> M = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
1457 |
+
>>> M.identity_hom()
|
1458 |
+
Matrix([
|
1459 |
+
[1, 0], : QQ[x]**2/<[1, 2], [1, x]> -> QQ[x]**2/<[1, 2], [1, x]>
|
1460 |
+
[0, 1]])
|
1461 |
+
"""
|
1462 |
+
return self.base.identity_hom().quotient_codomain(
|
1463 |
+
self.killed_module).quotient_domain(self.killed_module)
|
1464 |
+
|
1465 |
+
def quotient_hom(self):
|
1466 |
+
"""
|
1467 |
+
Return the quotient homomorphism to ``self``.
|
1468 |
+
|
1469 |
+
That is, return a homomorphism representing the natural map from
|
1470 |
+
``self.base`` to ``self``.
|
1471 |
+
|
1472 |
+
Examples
|
1473 |
+
========
|
1474 |
+
|
1475 |
+
>>> from sympy.abc import x
|
1476 |
+
>>> from sympy import QQ
|
1477 |
+
>>> M = QQ.old_poly_ring(x).free_module(2) / [(1, 2), (1, x)]
|
1478 |
+
>>> M.quotient_hom()
|
1479 |
+
Matrix([
|
1480 |
+
[1, 0], : QQ[x]**2 -> QQ[x]**2/<[1, 2], [1, x]>
|
1481 |
+
[0, 1]])
|
1482 |
+
"""
|
1483 |
+
return self.base.identity_hom().quotient_codomain(
|
1484 |
+
self.killed_module)
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__init__.py
ADDED
File without changes
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (190 Bytes). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_appellseqs.cpython-310.pyc
ADDED
Binary file (4.51 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_constructor.cpython-310.pyc
ADDED
Binary file (5.47 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densearith.cpython-310.pyc
ADDED
Binary file (38.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densebasic.cpython-310.pyc
ADDED
Binary file (24.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_densetools.cpython-310.pyc
ADDED
Binary file (23.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_dispersion.cpython-310.pyc
ADDED
Binary file (2.45 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_distributedmodules.cpython-310.pyc
ADDED
Binary file (9.04 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_euclidtools.cpython-310.pyc
ADDED
Binary file (18.8 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_factortools.cpython-310.pyc
ADDED
Binary file (24.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_fields.cpython-310.pyc
ADDED
Binary file (12.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_galoistools.cpython-310.pyc
ADDED
Binary file (27.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_groebnertools.cpython-310.pyc
ADDED
Binary file (20.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_heuristicgcd.cpython-310.pyc
ADDED
Binary file (3.95 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_injections.cpython-310.pyc
ADDED
Binary file (1.46 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_modulargcd.cpython-310.pyc
ADDED
Binary file (8.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_monomials.cpython-310.pyc
ADDED
Binary file (12.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_multivariate_resultants.cpython-310.pyc
ADDED
Binary file (8.76 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orderings.cpython-310.pyc
ADDED
Binary file (4.12 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_orthopolys.cpython-310.pyc
ADDED
Binary file (7.68 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_partfrac.cpython-310.pyc
ADDED
Binary file (8.79 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyclasses.cpython-310.pyc
ADDED
Binary file (15.3 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyfuncs.cpython-310.pyc
ADDED
Binary file (5.38 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polymatrix.cpython-310.pyc
ADDED
Binary file (8.48 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyoptions.cpython-310.pyc
ADDED
Binary file (14.7 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyroots.cpython-310.pyc
ADDED
Binary file (29.9 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polytools.cpython-310.pyc
ADDED
Binary file (137 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_polyutils.cpython-310.pyc
ADDED
Binary file (11 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_pythonrational.cpython-310.pyc
ADDED
Binary file (5.14 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rationaltools.cpython-310.pyc
ADDED
Binary file (2.76 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_ring_series.cpython-310.pyc
ADDED
Binary file (30.1 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rings.cpython-310.pyc
ADDED
Binary file (54.4 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rootisolation.cpython-310.pyc
ADDED
Binary file (26.5 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_rootoftools.cpython-310.pyc
ADDED
Binary file (24 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_solvers.cpython-310.pyc
ADDED
Binary file (21.2 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_specialpolys.cpython-310.pyc
ADDED
Binary file (6.55 kB). View file
|
|
llmeval-env/lib/python3.10/site-packages/sympy/polys/tests/__pycache__/test_sqfreetools.cpython-310.pyc
ADDED
Binary file (4.62 kB). View file
|
|