def create_key(self,base_ring, arg1=None, arg2=None, sparse=False, order='degrevlex', names=None, name=None, implementation=None, degrees=None): """ Create the key under which a free algebra is stored. TESTS:: sage: FreeAlgebra.create_key(GF(5),['x','y','z']) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),3,'xyz') (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'], implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3, implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace', degrees=[1,2,3]) ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5) """ if arg1 is None and arg2 is None and names is None: # this is used for pickling if degrees is None: return (base_ring,) return tuple(degrees),base_ring PolRing = None # test if we can use libSingular/letterplace if implementation is not None and implementation != 'generic': try: PolRing = PolynomialRing(base_ring, arg1, arg2, sparse=sparse, order=order, names=names, name=name, implementation=implementation if implementation!='letterplace' else None) if not isinstance(PolRing,MPolynomialRing_libsingular): if PolRing.ngens() == 1: PolRing = PolynomialRing(base_ring,1,PolRing.variable_names()) if not isinstance(PolRing,MPolynomialRing_libsingular): raise TypeError else: raise TypeError except (TypeError, NotImplementedError),msg: raise NotImplementedError, "The letterplace implementation is not available for the free algebra you requested"
def create_key(self, base_ring, arg1=None, arg2=None, sparse=False, order='degrevlex', names=None, name=None, implementation=None, degrees=None): """ Create the key under which a free algebra is stored. TESTS:: sage: FreeAlgebra.create_key(GF(5),['x','y','z']) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),3,'xyz') (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'], implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3, implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace', degrees=[1,2,3]) ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5) """ if arg1 is None and arg2 is None and names is None: # this is used for pickling if degrees is None: return (base_ring, ) return tuple(degrees), base_ring PolRing = None # test if we can use libSingular/letterplace if implementation is not None and implementation != 'generic': try: PolRing = PolynomialRing( base_ring, arg1, arg2, sparse=sparse, order=order, names=names, name=name, implementation=implementation if implementation != 'letterplace' else None) if not isinstance(PolRing, MPolynomialRing_libsingular): if PolRing.ngens() == 1: PolRing = PolynomialRing(base_ring, 1, PolRing.variable_names()) if not isinstance(PolRing, MPolynomialRing_libsingular): raise TypeError else: raise TypeError except (TypeError, NotImplementedError), msg: raise NotImplementedError, "The letterplace implementation is not available for the free algebra you requested"
def create_key(self,base_ring, arg1=None, arg2=None, sparse=False, order='degrevlex', names=None, name=None, implementation=None, degrees=None): """ Create the key under which a free algebra is stored. TESTS:: sage: FreeAlgebra.create_key(GF(5),['x','y','z']) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),3,'xyz') (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'], implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3, implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace', degrees=[1,2,3]) ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5) """ if arg1 is None and arg2 is None and names is None: # this is used for pickling if degrees is None: return (base_ring,) return tuple(degrees),base_ring PolRing = None # test if we can use libSingular/letterplace if implementation is not None and implementation != 'generic': try: PolRing = PolynomialRing(base_ring, arg1, arg2, sparse=sparse, order=order, names=names, name=name, implementation=implementation if implementation != 'letterplace' else None) if not isinstance(PolRing, MPolynomialRing_libsingular): if PolRing.ngens() == 1: PolRing = PolynomialRing(base_ring, 1, PolRing.variable_names()) if not isinstance(PolRing, MPolynomialRing_libsingular): raise TypeError else: raise TypeError except (TypeError, NotImplementedError) as msg: raise NotImplementedError("The letterplace implementation is not available for the free algebra you requested") if PolRing is not None: if degrees is None: return (PolRing,) from sage.all import TermOrder T = PolRing.term_order() + TermOrder('lex',1) varnames = list(PolRing.variable_names()) newname = 'x' while newname in varnames: newname += '_' varnames.append(newname) return tuple(degrees),PolynomialRing(PolRing.base(), varnames, sparse=sparse, order=T, implementation=implementation if implementation != 'letterplace' else None) # normalise the generator names from sage.all import Integer if isinstance(arg1, (int, long, Integer)): arg1, arg2 = arg2, arg1 if not names is None: arg1 = names elif not name is None: arg1 = name if arg2 is None: arg2 = len(arg1) names = sage.structure.parent_gens.normalize_names(arg2, arg1) return base_ring, names
def create_key(self,base_ring, arg1=None, arg2=None, sparse=False, order='degrevlex', names=None, name=None, implementation=None, degrees=None): """ Create the key under which a free algebra is stored. TESTS:: sage: FreeAlgebra.create_key(GF(5),['x','y','z']) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),3,'xyz') (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'], implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3, implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace', degrees=[1,2,3]) ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5) """ if arg1 is None and arg2 is None and names is None: # this is used for pickling if degrees is None: return (base_ring,) return tuple(degrees),base_ring PolRing = None # test if we can use libSingular/letterplace if implementation is not None and implementation != 'generic': try: PolRing = PolynomialRing(base_ring, arg1, arg2, sparse=sparse, order=order, names=names, name=name, implementation=implementation if implementation != 'letterplace' else None) if not isinstance(PolRing, MPolynomialRing_libsingular): if PolRing.ngens() == 1: PolRing = PolynomialRing(base_ring, 1, PolRing.variable_names()) if not isinstance(PolRing, MPolynomialRing_libsingular): raise TypeError else: raise TypeError except (TypeError, NotImplementedError) as msg: raise NotImplementedError("The letterplace implementation is not available for the free algebra you requested") if PolRing is not None: if degrees is None: return (PolRing,) from sage.all import TermOrder T = PolRing.term_order() + TermOrder('lex',1) varnames = list(PolRing.variable_names()) newname = 'x' while newname in varnames: newname += '_' varnames.append(newname) return tuple(degrees),PolynomialRing(PolRing.base(), varnames, sparse=sparse, order=T, implementation=implementation if implementation != 'letterplace' else None) # normalise the generator names from sage.all import Integer if isinstance(arg1, (int, long, Integer)): arg1, arg2 = arg2, arg1 if not names is None: arg1 = names elif not name is None: arg1 = name if arg2 is None: arg2 = len(arg1) names = sage.structure.parent_gens.normalize_names(arg2, arg1) return base_ring, names
def create_key(self, base_ring, arg1=None, arg2=None, sparse=None, order=None, names=None, name=None, implementation=None, degrees=None): """ Create the key under which a free algebra is stored. TESTS:: sage: FreeAlgebra.create_key(GF(5),['x','y','z']) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3) (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),3,'xyz') (Finite Field of size 5, ('x', 'y', 'z')) sage: FreeAlgebra.create_key(GF(5),['x','y','z'], implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),['x','y','z'],3, implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace') (Multivariate Polynomial Ring in x, y, z over Finite Field of size 5,) sage: FreeAlgebra.create_key(GF(5),3,'xyz', implementation='letterplace', degrees=[1,2,3]) ((1, 2, 3), Multivariate Polynomial Ring in x, y, z, x_ over Finite Field of size 5) """ if arg1 is None and arg2 is None and names is None: # this is used for pickling if degrees is None: return (base_ring, ) return tuple(degrees), base_ring # test if we can use libSingular/letterplace if implementation == "letterplace": if order is None: order = 'degrevlex' if degrees is None else 'deglex' args = [arg for arg in (arg1, arg2) if arg is not None] kwds = dict(sparse=sparse, order=order, implementation="singular") if name is not None: kwds["name"] = name if names is not None: kwds["names"] = names PolRing = PolynomialRing(base_ring, *args, **kwds) if degrees is None: return (PolRing, ) from sage.all import TermOrder T = TermOrder(PolRing.term_order(), PolRing.ngens() + 1) varnames = list(PolRing.variable_names()) newname = 'x' while newname in varnames: newname += '_' varnames.append(newname) R = PolynomialRing(PolRing.base(), varnames, sparse=sparse, order=T) return tuple(degrees), R # normalise the generator names from sage.all import Integer if isinstance(arg1, (Integer, int)): arg1, arg2 = arg2, arg1 if not names is None: arg1 = names elif not name is None: arg1 = name if arg2 is None: arg2 = len(arg1) names = normalize_names(arg2, arg1) return base_ring, names