|
26 | 26 | # ***************************************************************************
|
27 | 27 |
|
28 | 28 | from __future__ import print_function, absolute_import, division
|
| 29 | +from sage.structure.factory import UniqueFactory |
29 | 30 | from sage import categories
|
30 | 31 | from sage.structure.category_object import normalize_names
|
31 | 32 | from sage.categories.morphism import Morphism, IdentityMorphism
|
|
34 | 35 | from sage.categories.commutative_rings import CommutativeRings
|
35 | 36 |
|
36 | 37 |
|
37 |
| - |
38 |
| -def SkewPolynomialRing(base_ring, base_ring_automorphism=None, names=None, sparse=False): |
| 38 | +class SkewPolynomialRingFactory(UniqueFactory): |
39 | 39 | r"""
|
40 | 40 | Return the globally unique skew polynomial ring with the given properties
|
41 | 41 | and variable names.
|
@@ -191,36 +191,76 @@ def SkewPolynomialRing(base_ring, base_ring_automorphism=None, names=None, spars
|
191 | 191 | - Multivariate Skew Polynomial Ring
|
192 | 192 | - Add derivations.
|
193 | 193 | """
|
194 |
| - if base_ring not in categories.rings.Rings().Commutative(): |
195 |
| - raise TypeError("base_ring must be a commutative ring") |
196 |
| - if base_ring not in CommutativeRings(): |
197 |
| - raise TypeError('base_ring must be a commutative ring') |
198 |
| - if base_ring_automorphism is None: |
199 |
| - base_ring_automorphism = IdentityMorphism(base_ring) |
200 |
| - else: |
201 |
| - if (not isinstance(base_ring_automorphism,Morphism) |
202 |
| - or base_ring_automorphism.domain() != base_ring |
203 |
| - or base_ring_automorphism.codomain() != base_ring): |
204 |
| - raise TypeError("base_ring_automorphism must be a ring automorphism of base_ring (=%s)" % base_ring) |
205 |
| - if sparse: |
206 |
| - raise NotImplementedError("sparse skew polynomial rings are not implemented") |
207 |
| - if names is None: |
208 |
| - raise TypeError("you must specify the name of the variable") |
209 |
| - try: |
210 |
| - names = normalize_names(1, names)[0] |
211 |
| - except IndexError: |
212 |
| - raise NotImplementedError("multivariate skew polynomials rings not supported") |
213 |
| - |
214 |
| - import sage.rings.polynomial.skew_polynomial_ring as spr |
215 |
| - |
216 |
| - # We check whether sigma has finite order |
217 |
| - if base_ring in Fields(): |
| 194 | + def create_key(self, base_ring, base_ring_automorphism=None, names=None, sparse=False): |
| 195 | + r""" |
| 196 | + Create a key from the input parameters |
| 197 | +
|
| 198 | + INPUT: |
| 199 | +
|
| 200 | + - ``base_ring`` -- a ring |
| 201 | +
|
| 202 | + - ``base_ring_automorphism`` -- a homomorphism of rings |
| 203 | +
|
| 204 | + - ``names`` -- a string; names of the indeterminates |
| 205 | +
|
| 206 | + - ``sparse`` - a boolean |
| 207 | +
|
| 208 | + EXAMPLES:: |
| 209 | +
|
| 210 | + sage: k.<a> = GF(11^2) |
| 211 | + sage: Frob = k.frobenius_endomorphism() |
| 212 | + sage: SkewPolynomialRing.create_key(k, Frob, 'x') |
| 213 | + (Finite Field in a of size 11^2, |
| 214 | + Frobenius endomorphism a |--> a^11 on Finite Field in a of size 11^2, |
| 215 | + 'x', |
| 216 | + False) |
| 217 | + """ |
| 218 | + if base_ring not in categories.rings.Rings().Commutative(): |
| 219 | + raise TypeError("base_ring must be a commutative ring") |
| 220 | + if base_ring not in CommutativeRings(): |
| 221 | + raise TypeError('base_ring must be a commutative ring') |
| 222 | + if base_ring_automorphism is None: |
| 223 | + base_ring_automorphism = IdentityMorphism(base_ring) |
| 224 | + else: |
| 225 | + if (not isinstance(base_ring_automorphism,Morphism) |
| 226 | + or base_ring_automorphism.domain() != base_ring |
| 227 | + or base_ring_automorphism.codomain() != base_ring): |
| 228 | + raise TypeError("base_ring_automorphism must be a ring automorphism of base_ring (=%s)" % base_ring) |
| 229 | + if sparse: |
| 230 | + raise NotImplementedError("sparse skew polynomial rings are not implemented") |
| 231 | + if names is None: |
| 232 | + raise TypeError("you must specify the name of the variable") |
218 | 233 | try:
|
219 |
| - order = base_ring_automorphism.order() |
220 |
| - if order is not Infinity: |
221 |
| - return spr.SkewPolynomialRing_finite_order(base_ring, base_ring_automorphism, names, sparse) |
222 |
| - except AttributeError: |
223 |
| - pass |
224 |
| - |
225 |
| - # Generic implementation |
226 |
| - return spr.SkewPolynomialRing_general(base_ring, base_ring_automorphism, names, sparse) |
| 234 | + names = normalize_names(1, names)[0] |
| 235 | + except IndexError: |
| 236 | + raise NotImplementedError("multivariate skew polynomials rings not supported") |
| 237 | + return (base_ring, base_ring_automorphism, names, sparse) |
| 238 | + |
| 239 | + def create_object(self, version, key): |
| 240 | + """ |
| 241 | + Create an object using the given key |
| 242 | +
|
| 243 | + TESTS:: |
| 244 | +
|
| 245 | + sage: k.<a> = GF(11^2) |
| 246 | + sage: Frob = k.frobenius_endomorphism() |
| 247 | + sage: key = SkewPolynomialRing.create_key(k, Frob, 'x') |
| 248 | + sage: SkewPolynomialRing.create_object((9,1,9), key) |
| 249 | + Skew Polynomial Ring in x over Finite Field in a of size 11^2 twisted by a |--> a^11 |
| 250 | + """ |
| 251 | + import sage.rings.polynomial.skew_polynomial_ring as spr |
| 252 | + (base_ring, base_ring_automorphism, names, sparse) = key |
| 253 | + |
| 254 | + # We check if the twisting morphism has finite order |
| 255 | + if base_ring in Fields(): |
| 256 | + try: |
| 257 | + order = base_ring_automorphism.order() |
| 258 | + if order is not Infinity: |
| 259 | + return spr.SkewPolynomialRing_finite_order(base_ring, base_ring_automorphism, names, sparse) |
| 260 | + except AttributeError: |
| 261 | + pass |
| 262 | + |
| 263 | + # We fallback to generic implementation |
| 264 | + return spr.SkewPolynomialRing_general(base_ring, base_ring_automorphism, names, sparse) |
| 265 | + |
| 266 | +SkewPolynomialRing = SkewPolynomialRingFactory("SkewPolynomialRing") |
0 commit comments