Ejemplo n.º 1
0
        """
        if name == "_Sequence_generic__cr" and hasattr(self, "_Sequence__cr"):
            self.__cr = self._Sequence__cr
            return self.__cr
        elif name == "_Sequence_generic__cr_str" and hasattr(
                self, "_Sequence__cr_str"):
            self.__cr_str = self._Sequence__cr_str
            return self.__cr_str
        elif name == "_Sequence_generic__immutable" and hasattr(
                self, "_Sequence__immutable"):
            self.__immutable = self._Sequence__immutable
            return self.__immutable
        elif name == "_Sequence_generic__universe" and hasattr(
                self, "_Sequence__universe"):
            self.__universe = self._Sequence__universe
            return self.__universe
        elif name == "_Sequence_generic__hash" and hasattr(
                self, "_Sequence__hash"):
            self.__hash = self._Sequence__hash
            return self.__hash
        else:
            raise AttributeError(
                "'Sequence_generic' object has no attribute '%s'" % name)


seq = Sequence

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.structure.sequence', 'Sequence',
                           Sequence_generic)
Ejemplo n.º 2
0
            EXAMPLES::

                sage: s = SymmetricFunctions(QQ).s()
                sage: a = s([2,1])
                sage: a.expand(2)
                x0^2*x1 + x0*x1^2
                sage: a.expand(3)
                x0^2*x1 + x0*x1^2 + x0^2*x2 + 2*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2
                sage: a.expand(4)
                x0^2*x1 + x0*x1^2 + x0^2*x2 + 2*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2 + x0^2*x3 + 2*x0*x1*x3 + x1^2*x3 + 2*x0*x2*x3 + 2*x1*x2*x3 + x2^2*x3 + x0*x3^2 + x1*x3^2 + x2*x3^2
                sage: a.expand(2, alphabet='y')
                y0^2*y1 + y0*y1^2
                sage: a.expand(2, alphabet=['a','b'])
                a^2*b + a*b^2
                sage: s([1,1,1,1]).expand(3)
                0
                sage: (s([]) + 2*s([1])).expand(3)
                2*x0 + 2*x1 + 2*x2 + 1
                sage: s([1]).expand(0)
                0
                sage: (3*s([])).expand(0)
                3
            """
            condition = lambda part: len(part) > n
            return self._expand(condition, n, alphabet)

# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.schur', 'SymmetricFunctionAlgebraElement_schur',  SymmetricFunctionAlgebra_schur.Element)
Ejemplo n.º 3
0
        """
        x = [self.mset.index(_) for _ in x]
        return rank(x, len(self.mset))


##########################################################
# Deprecations


class ChooseNK(Combinations_setk):
    def __setstate__(self, state):
        r"""
        For unpickling old ``ChooseNK`` objects.

        TESTS::

            sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1K\xce\xc8\xcf"
            ....:   "/N\x8d\xcf\xcb\xe6r\x06\xb3\xfc\xbc\xb9\n\x195\x1b\x0b"
            ....:   "\x99j\x0b\x995B\x99\xe2\xf3\nY :\x8a2\xf3\xd2\x8b\xf52"
            ....:   "\xf3JR\xd3S\x8b\xb8r\x13\xb3S\xe3a\x9cB\xd6PF\xd3\xd6\xa0"
            ....:   "B6\xa0\xfa\xecB\xf6\x0c \xd7\x08\xc8\xe5(M\xd2\x03\x00{"
            ....:   "\x82$\xd8")
            Combinations of [0, 1, 2, 3, 4] of length 2
        """
        self.__class__ = Combinations_setk
        Combinations_setk.__init__(self, range(state['_n']), state['_k'])


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.choose_nk", "ChooseNK", ChooseNK)
Ejemplo n.º 4
0
            doctest:...: DeprecationWarning: OrderedAlphabet is deprecated; use Alphabet instead.
            See http://trac.sagemath.org/8920 for details.
            sage: O._alphabet = ['a', 'b']
            sage: O._elements
            ('a', 'b')
        """
        if name == '_elements':
            if not hasattr(self, '_alphabet'):
                raise AttributeError("no attribute '_elements'")
            self._elements = tuple(self._alphabet)
            from sage.structure.parent import Parent
            from sage.categories.finite_enumerated_sets import FiniteEnumeratedSets
            Parent.__init__(self, category=FiniteEnumeratedSets(), facade=True)
            return self._elements
        raise AttributeError("no attribute %s"%name)

from sage.structure.sage_object import register_unpickle_override

register_unpickle_override(
    'sage.combinat.words.alphabet',
    'OrderedAlphabet_NaturalNumbers',
    NonNegativeIntegers,
    call_name=('sage.sets.non_negative_integers', 'NonNegativeIntegers'))

register_unpickle_override(
    'sage.combinat.words.alphabet',
    'OrderedAlphabet_PositiveIntegers',
    PositiveIntegers,
    call_name=('sage.sets.positive_integers', 'PositiveIntegers'))

Ejemplo n.º 5
0
from __future__ import absolute_import

from .chain_complex import ChainComplex

from .chain_complex_morphism import ChainComplexMorphism

from .simplicial_complex import SimplicialComplex, Simplex

from .simplicial_complex_morphism import SimplicialComplexMorphism

from .delta_complex import DeltaComplex, delta_complexes

from .cubical_complex import CubicalComplex, cubical_complexes

from sage.misc.lazy_import import lazy_import
lazy_import('sage.homology.koszul_complex', 'KoszulComplex')
lazy_import('sage.homology', 'simplicial_complexes_catalog', 'simplicial_complexes')
lazy_import('sage.homology', 'simplicial_set_catalog', 'simplicial_sets')


# For taking care of old pickles
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.homology.examples', 'SimplicialSurface', SimplicialComplex)
Ejemplo n.º 6
0
            - ``n`` -- a positive integer
            - ``alphabet`` -- a variable for the expansion (default: `x`)

            OUTPUT:

            - a monomial expansion of an instance of dual of ``self`` in `n` variable

            EXAMPLES::

                sage: m = SymmetricFunctions(QQ).monomial()
                sage: zee = sage.combinat.sf.sfa.zee
                sage: h = m.dual_basis(zee)
                sage: a = h([2,1])+h([3])
                sage: a.expand(2)
                2*x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + 2*x1^3
                sage: a.dual().expand(2)
                2*x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + 2*x1^3
                sage: a.expand(2,alphabet='y')
                2*y0^3 + 3*y0^2*y1 + 3*y0*y1^2 + 2*y1^3
                sage: a.expand(2,alphabet='x,y')
                2*x^3 + 3*x^2*y + 3*x*y^2 + 2*y^3
            """
            return self._dual.expand(n, alphabet)


# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.dual',
                           'SymmetricFunctionAlgebraElement_dual',
                           SymmetricFunctionAlgebra_dual.Element)
Ejemplo n.º 7
0
             C1
             sage: sorted(b.edges())
             []
        """
        return self.dual().dynkin_diagram().dual()

    def ascii_art(self, label = lambda x: x):
        """
        Returns a ascii art representation of the extended Dynkin diagram

        EXAMPLES::

            sage: print CartanType(['C',1]).ascii_art()
            O
            1
            sage: print CartanType(['C',2]).ascii_art()
            O=<=O
            1   2
            sage: print CartanType(['C',3]).ascii_art()
            O---O=<=O
            1   2   3
            sage: print CartanType(['C',5]).ascii_art(label = lambda x: x+2)
            O---O---O---O=<=O
            3   4   5   6   7
        """
        return self.dual().ascii_art(label = label).replace("=>=", "=<=")

# For unpickling backward compatibility (Sage <= 4.1)
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.root_system.type_C', 'ambient_space',  AmbientSpace)
Ejemplo n.º 8
0
            - a monomial expansion of an instance of ``self`` in `n` variables

            EXAMPLES::

                sage: e = SymmetricFunctions(QQ).e()
                sage: e([2,1]).expand(3)
                x0^2*x1 + x0*x1^2 + x0^2*x2 + 3*x0*x1*x2 + x1^2*x2 + x0*x2^2 + x1*x2^2
                sage: e([1,1,1]).expand(2)
                x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + x1^3
                sage: e([3]).expand(2)
                0
                sage: e([2]).expand(3)
                x0*x1 + x0*x2 + x1*x2
                sage: e([3]).expand(4,alphabet='x,y,z,t')
                x*y*z + x*y*t + x*z*t + y*z*t
                sage: e([3]).expand(4,alphabet='y')
                y0*y1*y2 + y0*y1*y3 + y0*y2*y3 + y1*y2*y3
                sage: e([]).expand(2)
                1
            """
            condition = lambda part: max(part) > n
            return self._expand(condition, n, alphabet)


# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override

register_unpickle_override('sage.combinat.sf.elementary',
                           'SymmetricFunctionAlgebraElement_elementary',
                           SymmetricFunctionAlgebra_elementary.Element)
Ejemplo n.º 9
0
            yield cur + [zero] * (len(l) - len(cur))
        elif cur[-1] < zero or rem < zero:
            rem += cur.pop() * l[k]
            k -= 1
        elif len(l) == len(cur) + 1:
            if rem % l[-1] == zero:
                yield cur + [rem // l[-1]]
        else:
            k += 1
            cur.append(rem // l[k] + one)
            rem -= cur[-1] * l[k]


def WeightedIntegerVectors_nweight(n, weight):
    """
    Deprecated in :trac:`12453`. Use :class:`WeightedIntegerVectors` instead.

    EXAMPLES::

        sage: sage.combinat.integer_vector_weighted.WeightedIntegerVectors_nweight(7, [2,2])
        doctest:...: DeprecationWarning: this class is deprecated. Use WeightedIntegerVectors instead
        See http://trac.sagemath.org/12453 for details.
        Integer vectors of 7 weighted by [2, 2]
    """
    from sage.misc.superseded import deprecation
    deprecation(12453, 'this class is deprecated. Use WeightedIntegerVectors instead')
    return WeightedIntegerVectors(n, weight)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.integer_vector_weighted', 'WeightedIntegerVectors_nweight', WeightedIntegerVectors)
Ejemplo n.º 10
0
        
        INPUT:
        
        - ``R`` -- a ring.

        EXAMPLES::

            sage: E = EllipticCurve('37a')
            sage: Hom = E.point_homset();  Hom
            Abelian group of points on Elliptic Curve defined
            by y^2 + y = x^3 - x over Rational Field
            sage: Hom.base_ring()
            Integer Ring
            sage: Hom.base_extend(QQ)
            Traceback (most recent call last):
            ...
            NotImplementedError: Abelian variety point sets are not 
            implemented as modules over rings other than ZZ.
        """
        if R is not ZZ:
            raise NotImplementedError('Abelian variety point sets are not '
                            'implemented as modules over rings other than ZZ.')
        return self
    

from sage.structure.sage_object import register_unpickle_override 
register_unpickle_override('sage.schemes.generic.homset', 
                           'SchemeHomsetModule_abelian_variety_coordinates_field', 
                           SchemeHomset_points_abelian_variety_field) 

Ejemplo n.º 11
0
Archivo: spec.py Proyecto: Etn40ff/sage
            sage: from sage.schemes.generic.spec import SpecFunctor
            sage: F = SpecFunctor(GF(7))
            sage: A.<x, y> = GF(7)[]
            sage: B.<t> = GF(7)[]
            sage: f = A.hom((t^2, t^3))
            sage: Spec(f) # indirect doctest
            Affine Scheme morphism:
              From: Spectrum of Univariate Polynomial Ring in t over Finite Field of size 7
              To:   Spectrum of Multivariate Polynomial Ring in x, y over Finite Field of size 7
              Defn: Ring morphism:
                     From: Multivariate Polynomial Ring in x, y over Finite Field of size 7
                     To:   Univariate Polynomial Ring in t over Finite Field of size 7
                     Defn: x |--> t^2
                           y |--> t^3
        """
        A = f.domain()
        B = f.codomain()
        return self(B).hom(f, self(A))


SpecZ = Spec(ZZ)


# Compatibility with older versions of this module

from sage.misc.superseded import deprecated_function_alias
is_Spec = deprecated_function_alias(16158, is_AffineScheme)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.schemes.generic.spec', 'Spec', AffineScheme)
Ejemplo n.º 12
0

def unpickle_PolynomialRing(base_ring, arg1=None, arg2=None, sparse=False):
    """
    Custom unpickling function for polynomial rings.

    This has the same positional arguments as the old
    ``PolynomialRing`` constructor before :trac:`23338`.
    """
    args = [arg for arg in (arg1, arg2) if arg is not None]
    return PolynomialRing(base_ring, *args, sparse=sparse)


from sage.structure.sage_object import register_unpickle_override

register_unpickle_override('sage.rings.polynomial.polynomial_ring_constructor',
                           'PolynomialRing', unpickle_PolynomialRing)


def _get_from_cache(key):
    try:
        return _cache[key]
    except TypeError as msg:
        raise TypeError('key = %s\n%s' % (key, msg))
    except KeyError:
        return None


def _save_in_cache(key, R):
    try:
        _cache[key] = R
    except TypeError as msg:
Ejemplo n.º 13
0
        There is no coercion for additive groups since ``+`` could mean
        both the action (i.e., the group operation) or adding a term::

            sage: G = groups.misc.AdditiveCyclic(3)
            sage: ZG = G.algebra(ZZ, category=AdditiveMagmas())
            sage: ZG.has_coerce_map_from(G)
            False
        """
        G = self.basis().keys()
        K = self.base_ring()

        if G.has_coerce_map_from(S):
            from sage.categories.groups import Groups
            # No coercion for additive groups because of ambiguity of +
            #   being the group action or addition of a new term.
            return self.category().is_subcategory(Groups().Algebras(K))

        if S in Sets.Algebras:
            S_K = S.base_ring()
            S_G = S.basis().keys()
            hom_K = K.coerce_map_from(S_K)
            hom_G = G.coerce_map_from(S_G)
            if hom_K is not None and hom_G is not None:
                return SetMorphism(S.Hom(self, category=self.category() | S.category()),
                                   lambda x: self.sum_of_terms( (hom_G(g), hom_K(c)) for g,c in x ))

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.algebras.group_algebras', 'GroupAlgebra',  GroupAlgebra_class)

Ejemplo n.º 14
0
            sage: FormalSums(QQ).an_element()
            1/2*1
            sage: QQ.an_element()
            1/2
        """
        return FormalSum([(self.base_ring().an_element(), 1)],
                         check=check, reduce=reduce, parent=self)


formal_sums = FormalSums()

# Formal sums now derives from UniqueRepresentation, which makes the
# factory function unnecessary. This is why the name was changed from
# class FormalSums_generic to class FormalSums.
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.structure.formal_sum', 'FormalSums_generic', FormalSums)


class FormalSum(ModuleElement):
    """
    A formal sum over a ring.
    """
    def __init__(self, x, parent=formal_sums, check=True, reduce=True):
        """
        INPUT:
            - ``x`` -- object
            - ``parent`` -- FormalSums(R) module (default: FormalSums(ZZ))
            - ``check`` -- bool (default: True) if False, might not coerce
                           coefficients into base ring, which can speed
                           up constructing a formal sum.
            - ``reduce`` -- reduce (default: True) if False, do not
Ejemplo n.º 15
0
        """
        for p in descents_composition_list(self.shape):
            yield self.from_permutation(p)

class Ribbon_class(RibbonShapedTableau):
    """
    This exists solely for unpickling ``Ribbon_class`` objects.
    """
    def __setstate__(self, state):
        r"""
        Unpickle old ``Ribbon_class`` objects.

        EXAMPLES::

            sage: loads('x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+\xcaLJ\xca\xcf\xe3\n\x02S\xf1\xc99\x89\xc5\xc5\\\x85\x8c\x9a\x8d\x85L\xb5\x85\xcc\x1a\xa1\xac\xf1\x19\x89\xc5\x19\x85,~@VNfqI!kl!\x9bFl!\xbb\x06\xc4\x9c\xa2\xcc\xbc\xf4b\xbd\xcc\xbc\x92\xd4\xf4\xd4"\xae\xdc\xc4\xec\xd4x\x18\xa7\x90#\x94\xd1\xb05\xa8\x903\x03\xc80\x022\xb8Rc\x0b\xb95@<c \x8f\x07\xc40\x012xSSK\x93\xf4\x00l\x811\x17')
            [[None, 1, 2], [3, 4]]
            sage: loads(dumps( RibbonShapedTableau([[3,2,1], [1,1]]) ))  # indirect doctest
            [[None, 3, 2, 1], [1, 1]]
        """
        self.__class__ = RibbonShapedTableau
        self.__init__(RibbonShapedTableaux(), state['_list'])

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.ribbon', 'Ribbon_class', Ribbon_class)
register_unpickle_override('sage.combinat.ribbon', 'StandardRibbons_shape', StandardRibbonShapedTableaux)

# Deprecations from trac:18555. July 2016
from sage.misc.superseded import deprecated_function_alias
RibbonShapedTableaux.global_options = deprecated_function_alias(18555, RibbonShapedTableaux.options)
StandardRibbonShapedTableaux.global_options = deprecated_function_alias(18555, StandardRibbonShapedTableaux.options)
        """
        Return the last standard ribbon of ``self``.

        EXAMPLES::

            sage: StandardRibbonShapedTableaux([2,2]).last()
            [[None, 1, 2], [3, 4]]
        """
        return self.from_permutation(descents_composition_last(self.shape))

    def __iter__(self):
        """
        An iterator for the standard ribbon of ``self``.

        EXAMPLES::

            sage: [t for t in StandardRibbonShapedTableaux([2,2])]
            [[[None, 2, 4], [1, 3]],
             [[None, 2, 3], [1, 4]],
             [[None, 1, 4], [2, 3]],
             [[None, 1, 3], [2, 4]],
             [[None, 1, 2], [3, 4]]]
        """
        for p in descents_composition_list(self.shape):
            yield self.from_permutation(p)


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.ribbon', 'Ribbon_class',
                           RibbonShapedTableau)
Ejemplo n.º 17
0
        def expand(self, n, alphabet='x'):
            """
            Expands the symmetric function as a symmetric polynomial in n
            variables.
        
            EXAMPLES::
            
                sage: h = SFAHomogeneous(QQ)
                sage: h([3]).expand(2)
                x0^3 + x0^2*x1 + x0*x1^2 + x1^3
                sage: h([1,1,1]).expand(2)
                x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + x1^3
                sage: h([2,1]).expand(3)
                x0^3 + 2*x0^2*x1 + 2*x0*x1^2 + x1^3 + 2*x0^2*x2 + 3*x0*x1*x2 + 2*x1^2*x2 + 2*x0*x2^2 + 2*x1*x2^2 + x2^3
                sage: h([3]).expand(2,alphabet='y')
                y0^3 + y0^2*y1 + y0*y1^2 + y1^3
                sage: h([3]).expand(2,alphabet='x,y')
                x^3 + x^2*y + x*y^2 + y^3
                sage: h([3]).expand(3,alphabet='x,y,z')
                x^3 + x^2*y + x*y^2 + y^3 + x^2*z + x*y*z + y^2*z + x*z^2 + y*z^2 + z^3
            """
            condition = lambda part: False
            return self._expand(condition, n, alphabet)


# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.homogeneous',
                           'SymmetricFunctionAlgebraElement_homogeneous',
                           SymmetricFunctionAlgebra_homogeneous.Element)
Ejemplo n.º 18
0
            INPUT:

            - ``self`` -- an element of the symmetric functions in a dual basis
            - ``n`` -- a positive integer
            - ``alphabet`` -- a variable for the expansion (default: `x`)

            OUTPUT:

            - a monomial expansion of an instance of dual of ``self`` in `n` variable

            EXAMPLES::

                sage: m = SymmetricFunctions(QQ).monomial()
                sage: zee = sage.combinat.sf.sfa.zee
                sage: h = m.dual_basis(zee)
                sage: a = h([2,1])+h([3])
                sage: a.expand(2)
                2*x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + 2*x1^3
                sage: a.dual().expand(2)
                2*x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + 2*x1^3
                sage: a.expand(2,alphabet='y')
                2*y0^3 + 3*y0^2*y1 + 3*y0*y1^2 + 2*y1^3
                sage: a.expand(2,alphabet='x,y')
                2*x^3 + 3*x^2*y + 3*x*y^2 + 2*y^3
            """
            return self._dual.expand(n, alphabet)

# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.dual', 'SymmetricFunctionAlgebraElement_dual',  SymmetricFunctionAlgebra_dual.Element)
Ejemplo n.º 19
0
            a^8 + a^7 + a^4 + a + 1
            a^8 + a^7 + a^4 + a + 1

        AUTHORS:

        - David Joyner and William Stein (2005-11)
        """
        from  sage.groups.generic import discrete_log

        b = self.parent()(base)
        # TODO: This function is TERRIBLE!
        return discrete_log(self, b)

dynamic_FiniteField_ext_pariElement = None
def _late_import():
    """
    Used to reset the class of PARI finite field elements in their initialization.

    EXAMPLES::

        sage: from sage.rings.finite_rings.element_ext_pari import FiniteField_ext_pariElement
        sage: k.<a> = GF(3^17, impl='pari_mod')
        sage: a.__class__ is FiniteField_ext_pariElement # indirect doctest
        False
    """
    global dynamic_FiniteField_ext_pariElement
    dynamic_FiniteField_ext_pariElement = dynamic_class("%s_with_category"%FiniteField_ext_pariElement.__name__, (FiniteField_ext_pariElement, FiniteFields().element_class), doccls=FiniteField_ext_pariElement)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.finite_field_element', 'FiniteField_ext_pariElement', FiniteField_ext_pariElement)
Ejemplo n.º 20
0
            pos = 0  #Double check this
            restmp = [ S.from_shape_and_word(parts[0], [l[k][j] for j in range(s[0])]) ]
            for i in range(1, len(parts)):
                w = [l[k][j] for j in range(pos+s[i-1], pos+s[i-1]+s[i])]
                restmp.append( S.from_shape_and_word(parts[i], w) )
            yield self.element_class(self, restmp)

class RibbonTableau_class(RibbonTableau):
    """
    This exists solely for unpickling ``RibbonTableau_class`` objects.
    """
    def __setstate__(self, state):
        r"""
        Unpickle old ``RibbonTableau_class`` objects.

        TESTS::

            sage: loads('x\x9c5\xcc\xbd\x0e\xc2 \x14@\xe1\xb4Z\x7f\xd0\x07\xc1\x85D}\x8f\x0e\x8d\x1d\t\xb9\x90\x1bJ\xa44\x17\xe8h\xa2\x83\xef-\xda\xb8\x9do9\xcf\xda$\xb0(\xcc4j\x17 \x8b\xe8\xb4\x9e\x82\xca\xa0=\xc2\xcc\xba\x1fo\x8b\x94\xf1\x90\x12\xa3\xea\xf4\xa2\xfaA+\xde7j\x804\xd0\xba-\xe5]\xca\xd4H\xdapI[\xde.\xdf\xe8\x82M\xc2\x85\x8c\x16#\x1b\xe1\x8e\xea\x0f\xda\xf5\xd5\xf9\xdd\xd1\x1e%1>\x14]\x8a\x0e\xdf\xb8\x968"\xceZ|\x00x\xef5\x11')
            [[None, 1], [2, 3]]
            sage: loads(dumps( RibbonTableau([[None, 1],[2,3]]) ))
            [[None, 1], [2, 3]]
        """
        self.__class__ = RibbonTableau
        self.__init__(RibbonTableaux(), state['_list'])

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.ribbon_tableau', 'RibbonTableau_class', RibbonTableau_class)
register_unpickle_override('sage.combinat.ribbon_tableau', 'RibbonTableaux_shapeweightlength', RibbonTableaux)
register_unpickle_override('sage.combinat.ribbon_tableau', 'SemistandardMultiSkewTtableaux_shapeweight', SemistandardMultiSkewTableaux)

Ejemplo n.º 21
0
        TESTS::

            sage: Hom(GF(3^3, 'a'), GF(3^6, 'b')).an_element()
            Ring morphism:
              From: Finite Field in a of size 3^3
              To:   Finite Field in b of size 3^6
              Defn: a |--> 2*b^5 + 2*b^4

            sage: Hom(GF(3^3, 'a'), GF(3^2, 'c')).an_element()
            Traceback (most recent call last):
            ...
            EmptySetError: no homomorphisms from Finite Field in a of size 3^3 to Finite Field in c of size 3^2

        .. TODO::

            Use a more sophisticated algorithm; see also :trac:`8751`.

        """
        K = self.domain()
        L = self.codomain()
        if K.degree() == 1:
            return L.coerce_map_from(K)
        elif not K.degree().divides(L.degree()):
            from sage.categories.sets_cat import EmptySetError
            raise EmptySetError('no homomorphisms from %s to %s' % (K, L))
        return K.hom([K.modulus().any_root(L)])


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.finite_field_morphism', 'FiniteFieldHomset', FiniteFieldHomset)
Ejemplo n.º 22
0
    """
    EXAMPLES::

        sage: sage.combinat.skew_tableau.SemistandardSkewTableaux_pmu([[2,1],[]],[2,1])
        doctest:1: DeprecationWarning: this class is deprecated. Use SemistandardSkewTableaux_shape_weight instead
        See http://trac.sagemath.org/9265 for details.
        Semistandard skew tableaux of shape [[2, 1], []] and weight [2, 1]
    """
    deprecation(9265,'this class is deprecated. Use SemistandardSkewTableaux_shape_weight instead')
    return SemistandardSkewTableaux_shape_weight(*args, **kargs)

def StandardSkewTableaux_n(*args, **kargs):
    """
    EXAMPLES::

        sage: sage.combinat.skew_tableau.StandardSkewTableaux_n(2)
        doctest:1: DeprecationWarning: this class is deprecated. Use StandardSkewTableaux_size instead
        See http://trac.sagemath.org/9265 for details.
        Standard skew tableaux of size 2
    """
    deprecation(9265,'this class is deprecated. Use StandardSkewTableaux_size instead')
    return StandardSkewTableaux(*args, **kargs)

# October 2012: fixing outdated pickles which use the classes being deprecated
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.skew_tableau', 'StandardSkewTableaux_n',  StandardSkewTableaux_size)
register_unpickle_override('sage.combinat.skew_tableau', 'SemistandardSkewTableaux_n',  SemistandardSkewTableaux_size)
register_unpickle_override('sage.combinat.skew_tableau', 'SemistandardSkewTableaux_nmu',  SemistandardSkewTableaux_size_weight)
register_unpickle_override('sage.combinat.skew_tableau', 'SemistandardSkewTableaux_p',  SemistandardSkewTableaux_shape)
register_unpickle_override('sage.combinat.skew_tableau', 'SemistandardSkewTableaux_pmu',  SemistandardSkewTableaux_shape_weight)
Ejemplo n.º 23
0
        ret = "\\draw (0 cm,0) -- (%s cm,0);\n" % ((n - 2) * node_dist)
        ret += "\\draw (%s cm, 0.1 cm) -- +(%s cm,0);\n" % ((n - 2) * node_dist, node_dist)
        ret += "\\draw (%s cm, -0.1 cm) -- +(%s cm,0);\n" % ((n - 2) * node_dist, node_dist)
        if dual:
            ret += self._latex_draw_arrow_tip((n - 1.5) * node_dist - 0.2, 0, 180)
        else:
            ret += self._latex_draw_arrow_tip((n - 1.5) * node_dist + 0.2, 0, 0)
        for i in range(self.n):
            ret += node(i * node_dist, 0, label(i + 1))
        return ret

    def _default_folded_cartan_type(self):
        """
        Return the default folded Cartan type.

        EXAMPLES::

            sage: CartanType(['B', 3])._default_folded_cartan_type()
            ['B', 3] as a folding of ['D', 4]
        """
        from sage.combinat.root_system.type_folded import CartanTypeFolded

        n = self.n
        return CartanTypeFolded(self, ["D", n + 1], [[i] for i in range(1, n)] + [[n, n + 1]])


# For unpickling backward compatibility (Sage <= 4.1)
from sage.structure.sage_object import register_unpickle_override

register_unpickle_override("sage.combinat.root_system.type_B", "ambient_space", AmbientSpace)
Ejemplo n.º 24
0
    """
    For old pickles of ``MonotoneTriangles_n``.

    EXAMPLES::

        sage: sage.combinat.alternating_sign_matrix.MonotoneTriangles_n(3)
        doctest:...: DeprecationWarning: this class is deprecated. Use sage.combinat.alternating_sign_matrix.MonotoneTriangles instead
        See http://trac.sagemath.org/14301 for details.
        Monotone triangles with 3 rows
    """
    from sage.misc.superseded import deprecation
    deprecation(14301,'this class is deprecated. Use sage.combinat.alternating_sign_matrix.MonotoneTriangles instead')
    return MonotoneTriangles(n)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.alternating_sign_matrix', 'AlternatingSignMatrices_n', AlternatingSignMatrices)
register_unpickle_override('sage.combinat.alternating_sign_matrix', 'MonotoneTriangles_n', MonotoneTriangles)
register_unpickle_override('sage.combinat.alternating_sign_matrix', 'MonotoneTriangles_n', MonotoneTriangles_n)

# Here are the previous implementations of the combinatorial structure
# of the alternating sign matrices. Please, consider it obsolete and
# tend to use the monotone triangles instead.

def from_contre_tableau(comps):
    r"""
    Returns an alternating sign matrix from a contre-tableau.

    EXAMPLES::

        sage: import sage.combinat.alternating_sign_matrix as asm
        sage: asm.from_contre_tableau([[1, 2, 3], [1, 2], [1]])
Ejemplo n.º 25
0
        INPUT:

        - ``self`` -- an instance of the LLT hcospin basis
        - ``part`` -- a partition

        OUTPUT:

        - returns a function which accepts a partition and returns the coefficient
          in the expansion of the monomial basis

        EXAMPLES::

            sage: HCosp3 = SymmetricFunctions(FractionField(QQ['t'])).llt(3).hcospin()
            sage: f21 = HCosp3._to_m(Partition([2,1]))
            sage: [f21(p) for p in Partitions(3)]
            [1, t + 1, 2*t + 1]
            sage: HCosp3.symmetric_function_ring().m()( HCosp3[2,1] )
            (2*t+1)*m[1, 1, 1] + (t+1)*m[2, 1] + m[3]
        """
        level = self.level()
        f = lambda part2: QQt(ribbon_tableau.cospin_polynomial([level*i for i in part], part2, level))
        return f

    class Element(LLT_generic.Element):
        pass

# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.llt', 'LLTElement_spin',  LLT_spin.Element)
register_unpickle_override('sage.combinat.sf.llt', 'LLTElement_cospin',  LLT_cospin.Element)
Ejemplo n.º 26
0
        EXAMPLE::

            sage: R = Integers(12345678900)
            sage: R.degree()
            1
        """
        return integer.Integer(1)

Zmod = IntegerModRing
Integers = IntegerModRing

# Register unpickling methods for backward compatibility.

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.integer_mod_ring', 'IntegerModRing_generic', IntegerModRing_generic)

## def GF(p):
##     """
##     EXAMPLES:
##         sage: F = GF(11)
##         sage: F
##         Finite field of size 11
##     """
##     if not arith.is_prime(p):
##         raise NotImplementedError, "Only prime fields currently implemented."
##     return IntegerModRing(p)

def crt(v):
    """
    INPUT: v - (list) a lift of elements of rings.IntegerMod(n), for
Ejemplo n.º 27
0
            data = QQ(data).continued_fraction_list()
        else:
            from .continued_fraction import check_and_reduce_pair
            data,_ = check_and_reduce_pair(data, [])
        return self.element_class(data)

    def _coerce_map_from_(self, R):
        r"""
        Return True for ZZ and QQ.

        EXAMPLES::

            sage: CFF.has_coerce_map_from(ZZ) # indirect doctest
            True
            sage: CFF.has_coerce_map_from(QQ)
            True
            sage: CFF.has_coerce_map_from(RR)
            False
        """
        from sage.rings.integer_ring import ZZ
        from sage.rings.rational_field import QQ
        return R is ZZ or R is QQ

CFF = ContinuedFractionField()

# Unpickling support is needed as the class ContinuedFractionField_class has
# been renamed into ContinuedFractionField in the ticket 14567
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.contfrac', 'ContinuedFractionField_class',ContinuedFractionField)

Ejemplo n.º 28
0

##########################################################
# Deprecations


class SplitNK(OrderedSetPartitions_scomp):
    def __setstate__(self, state):
        r"""
        For unpickling old ``SplitNK`` objects.

        TESTS::

            sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+.\xc8\xc9,"
            ....:   "\x89\xcf\xcb\xe6\n\x061\xfc\xbcA\xccBF\xcd\xc6B\xa6\xda"
            ....:   "Bf\x8dP\xa6\xf8\xbcB\x16\x88\x96\xa2\xcc\xbc\xf4b\xbd\xcc"
            ....:   "\xbc\x92\xd4\xf4\xd4\"\xae\xdc\xc4\xec\xd4x\x18\xa7\x905"
            ....:   "\x94\xd1\xb45\xa8\x90\r\xa8>\xbb\x90=\x03\xc85\x02r9J\x93"
            ....:   "\xf4\x00\xb4\xc6%f")
            Ordered set partitions of {0, 1, 2, 3, 4} into parts of size [2, 3]
        """
        self.__class__ = OrderedSetPartitions_scomp
        n = state['_n']
        k = state['_k']
        OrderedSetPartitions_scomp.__init__(self, range(state['_n']),
                                            (k, n - k))


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.split_nk", "SplitNK_nk", SplitNK)
Ejemplo n.º 29
0
            yield self.element_class(self, restmp)


class RibbonTableau_class(RibbonTableau):
    """
    This exists solely for unpickling ``RibbonTableau_class`` objects.
    """
    def __setstate__(self, state):
        r"""
        Unpickle old ``RibbonTableau_class`` objects.

        TESTS::

            sage: loads('x\x9c5\xcc\xbd\x0e\xc2 \x14@\xe1\xb4Z\x7f\xd0\x07\xc1\x85D}\x8f\x0e\x8d\x1d\t\xb9\x90\x1bJ\xa44\x17\xe8h\xa2\x83\xef-\xda\xb8\x9do9\xcf\xda$\xb0(\xcc4j\x17 \x8b\xe8\xb4\x9e\x82\xca\xa0=\xc2\xcc\xba\x1fo\x8b\x94\xf1\x90\x12\xa3\xea\xf4\xa2\xfaA+\xde7j\x804\xd0\xba-\xe5]\xca\xd4H\xdapI[\xde.\xdf\xe8\x82M\xc2\x85\x8c\x16#\x1b\xe1\x8e\xea\x0f\xda\xf5\xd5\xf9\xdd\xd1\x1e%1>\x14]\x8a\x0e\xdf\xb8\x968"\xceZ|\x00x\xef5\x11')
            [[None, 1], [2, 3]]
            sage: loads(dumps( RibbonTableau([[None, 1],[2,3]]) ))
            [[None, 1], [2, 3]]
        """
        self.__class__ = RibbonTableau
        self.__init__(RibbonTableaux(), state['_list'])


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.ribbon_tableau',
                           'RibbonTableau_class', RibbonTableau_class)
register_unpickle_override('sage.combinat.ribbon_tableau',
                           'RibbonTableaux_shapeweightlength', RibbonTableaux)
register_unpickle_override('sage.combinat.ribbon_tableau',
                           'SemistandardMultiSkewTtableaux_shapeweight',
                           SemistandardMultiSkewTableaux)
Ejemplo n.º 30
0
            - ``self`` -- an element of the homogeneous basis of symmetric functions
            - ``n`` -- a positive integer
            - ``alphabet`` -- a variable for the expansion (default: `x`)

            OUTPUT: a monomial expansion of an instance of ``self`` in `n` variables
        
            EXAMPLES::
            
                sage: h = SymmetricFunctions(QQ).h()
                sage: h([3]).expand(2)
                x0^3 + x0^2*x1 + x0*x1^2 + x1^3
                sage: h([1,1,1]).expand(2)
                x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + x1^3
                sage: h([2,1]).expand(3)
                x0^3 + 2*x0^2*x1 + 2*x0*x1^2 + x1^3 + 2*x0^2*x2 + 3*x0*x1*x2 + 2*x1^2*x2 + 2*x0*x2^2 + 2*x1*x2^2 + x2^3
                sage: h([3]).expand(2,alphabet='y')
                y0^3 + y0^2*y1 + y0*y1^2 + y1^3
                sage: h([3]).expand(2,alphabet='x,y')
                x^3 + x^2*y + x*y^2 + y^3
                sage: h([3]).expand(3,alphabet='x,y,z')
                x^3 + x^2*y + x*y^2 + y^3 + x^2*z + x*y*z + y^2*z + x*z^2 + y*z^2 + z^3
                sage: (h([]) + 2*h([1])).expand(3)
                2*x0 + 2*x1 + 2*x2 + 1
            """
            condition = lambda part: False
            return self._expand(condition, n, alphabet)

# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.sf.homogeneous', 'SymmetricFunctionAlgebraElement_homogeneous',  SymmetricFunctionAlgebra_homogeneous.Element)
Ejemplo n.º 31
0
            sage: range(c.cardinality()) == map(c.rank, c.list())
            True
        """
        x = map(self.mset.index, x)
        return rank(x, len(self.mset))


##########################################################
# Deprecations

class ChooseNK(Combinations_setk):
    def __setstate__(self, state):
        r"""
        For unpickling old ``ChooseNK`` objects.

        TESTS::

            sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1K\xce\xc8\xcf"
            ....:   "/N\x8d\xcf\xcb\xe6r\x06\xb3\xfc\xbc\xb9\n\x195\x1b\x0b"
            ....:   "\x99j\x0b\x995B\x99\xe2\xf3\nY :\x8a2\xf3\xd2\x8b\xf52"
            ....:   "\xf3JR\xd3S\x8b\xb8r\x13\xb3S\xe3a\x9cB\xd6PF\xd3\xd6\xa0"
            ....:   "B6\xa0\xfa\xecB\xf6\x0c \xd7\x08\xc8\xe5(M\xd2\x03\x00{"
            ....:   "\x82$\xd8")
            Combinations of [0, 1, 2, 3, 4] of length 2
        """
        self.__class__ = Combinations_setk
        Combinations_setk.__init__(self, range(state['_n']), state['_k'])

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.choose_nk", "ChooseNK", ChooseNK)
Ejemplo n.º 32
0
            data = QQ(data).continued_fraction_list()
        else:
            from continued_fraction import check_and_reduce_pair
            data,_ = check_and_reduce_pair(data, [])
        return self.element_class(data)

    def _coerce_map_from_(self, R):
        r"""
        Return True for ZZ and QQ.

        EXAMPLES::

            sage: CFF.has_coerce_map_from(ZZ) # indirect doctest
            True
            sage: CFF.has_coerce_map_from(QQ)
            True
            sage: CFF.has_coerce_map_from(RR)
            False
        """
        from sage.rings.integer_ring import ZZ
        from sage.rings.rational_field import QQ
        return R is ZZ or R is QQ

CFF = ContinuedFractionField()

# Unpickling support is needed as the class ContinuedFractionField_class has
# been renamed into ContinuedFractionField in the ticket 14567
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.contfrac', 'ContinuedFractionField_class',ContinuedFractionField)

Ejemplo n.º 33
0
from __future__ import absolute_import

from .base import IntegerListsBackend, Envelope
from .lists import IntegerLists
from .invlex import IntegerListsLex

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.integer_list', 'IntegerListsLex',
                           IntegerListsLex)
Ejemplo n.º 34
0
            sage: R = Integers(12345678900)
            sage: R.degree()
            1
        """
        return integer.Integer(1)


Zmod = IntegerModRing
Integers = IntegerModRing

# Register unpickling methods for backward compatibility.

from sage.structure.sage_object import register_unpickle_override

register_unpickle_override("sage.rings.integer_mod_ring", "IntegerModRing_generic", IntegerModRing_generic)


def crt(v):
    """
    INPUT:

    - ``v`` -- (list) a lift of elements of ``rings.IntegerMod(n)``, for
      various coprime moduli ``n``

    EXAMPLES::

        sage: from sage.rings.finite_rings.integer_mod_ring import crt
        sage: crt([mod(3, 8),mod(1,19),mod(7, 15)])
        1027
    """
Ejemplo n.º 35
0
        TESTS::

            sage: P2.<x,y,z> = AffineSpace(3, GF(3))
            sage: point_homset = P2._point_homset(Spec(GF(3)), P2)
            sage: P2._point(point_homset, [1, 2, 3])
            (1, 2, 0)
        """
        return SchemeMorphism_point_affine_finite_field(*args, **kwds)

    def _morphism(self, *args, **kwds):
        """
        Construct a morphism.

        For internal use only. See :mod:`morphism` for details.

        TESTS::

            sage: P2.<x,y,z> = AffineSpace(3, GF(3))
            sage: P2._morphism(P2.Hom(P2), [x, y, z])
            Scheme endomorphism of Affine Space of dimension 3 over Finite Field of size 3
              Defn: Defined on coordinates by sending (x, y, z) to
                    (x, y, z)
        """
        return SchemeMorphism_polynomial_affine_space_finite_field(*args, **kwds)

#fix the pickles from moving affine_space.py
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.schemes.generic.affine_space',
                           'AffineSpace_generic',
                           AffineSpace_generic)
Ejemplo n.º 36
0
            sage: a = P.base_ring().gen()
            sage: F = Sequence([x*y + 1, a*x + 1], P)
            sage: F2 = F.weil_restriction()
            sage: F2
            [x1*y0 + x0*y1 + x1*y1,
             x0*y0 + x1*y1 + 1,
             x0 + x1,
             x1 + 1,
             x0^2 + x0,
             x1^2 + x1,
             y0^2 + y0,
             y1^2 + y1]

        Another bigger example for a small scale AES::

           sage: sr = mq.SR(1,1,1,4,gf2=False)
           sage: F,s = sr.polynomial_system(); F
           Polynomial Sequence with 40 Polynomials in 20 Variables
           sage: F2 = F.weil_restriction(); F2
           Polynomial Sequence with 240 Polynomials in 80 Variables
        """
        from sage.rings.ideal import FieldIdeal
        J = self.ideal().weil_restriction()
        J += FieldIdeal(J.ring())
        return PolynomialSequence(J)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.crypto.mq.mpolynomialsystem","MPolynomialSystem_generic", PolynomialSequence_generic)
register_unpickle_override("sage.crypto.mq.mpolynomialsystem","MPolynomialRoundSystem_generic", PolynomialSequence_generic)

Ejemplo n.º 37
0
            yield self.element_class(self, [Set(res[dcomp[i]+1:dcomp[i+1]+1])
                                            for i in range(l)])

##########################################################
# Deprecations


class SplitNK(OrderedSetPartitions_scomp):
    def __setstate__(self, state):
        r"""
        For unpickling old ``SplitNK`` objects.

        TESTS::

            sage: loads("x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+.\xc8\xc9,"
            ....:   "\x89\xcf\xcb\xe6\n\x061\xfc\xbcA\xccBF\xcd\xc6B\xa6\xda"
            ....:   "Bf\x8dP\xa6\xf8\xbcB\x16\x88\x96\xa2\xcc\xbc\xf4b\xbd\xcc"
            ....:   "\xbc\x92\xd4\xf4\xd4\"\xae\xdc\xc4\xec\xd4x\x18\xa7\x905"
            ....:   "\x94\xd1\xb45\xa8\x90\r\xa8>\xbb\x90=\x03\xc85\x02r9J\x93"
            ....:   "\xf4\x00\xb4\xc6%f")
            Ordered set partitions of {0, 1, 2, 3, 4} into parts of size [2, 3]
        """
        self.__class__ = OrderedSetPartitions_scomp
        n = state['_n']
        k = state['_k']
        OrderedSetPartitions_scomp.__init__(self, range(state['_n']), (k,n-k))

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.combinat.split_nk", "SplitNK_nk", SplitNK)

Ejemplo n.º 38
0
        # TODO: This function is TERRIBLE!
        return discrete_log(self, b)


dynamic_FiniteField_ext_pariElement = None


def _late_import():
    """
    Used to reset the class of PARI finite field elements in their initialization.

    EXAMPLES::

        sage: from sage.rings.finite_rings.element_ext_pari import FiniteField_ext_pariElement
        sage: k.<a> = GF(3^17)
        sage: a.__class__ is FiniteField_ext_pariElement # indirect doctest
        False
    """
    global dynamic_FiniteField_ext_pariElement
    dynamic_FiniteField_ext_pariElement = dynamic_class(
        "%s_with_category" % FiniteField_ext_pariElement.__name__,
        (FiniteField_ext_pariElement, FiniteFields().element_class),
        doccls=FiniteField_ext_pariElement)


from sage.structure.sage_object import register_unpickle_override

register_unpickle_override('sage.rings.finite_field_element',
                           'FiniteField_ext_pariElement',
                           FiniteField_ext_pariElement)
Ejemplo n.º 39
0
            sage: del S._Sequence_generic__hash
            sage: hash(S)
            Traceback (most recent call last):
            ...
            AttributeError: 'Sequence_generic' object has no attribute '_Sequence_generic__hash'
            sage: S._Sequence__hash = 34
            sage: hash(S)
            34
        """
        if name == "_Sequence_generic__cr" and hasattr(self,"_Sequence__cr"):
            self.__cr = self._Sequence__cr
            return self.__cr
        elif name == "_Sequence_generic__cr_str" and hasattr(self,"_Sequence__cr_str"):
            self.__cr_str = self._Sequence__cr_str
            return self.__cr_str
        elif name == "_Sequence_generic__immutable" and hasattr(self,"_Sequence__immutable"):
            self.__immutable = self._Sequence__immutable
            return self.__immutable
        elif name == "_Sequence_generic__universe" and hasattr(self,"_Sequence__universe"):
            self.__universe = self._Sequence__universe
            return self.__universe
        elif name == "_Sequence_generic__hash" and hasattr(self,"_Sequence__hash"):
            self.__hash = self._Sequence__hash
            return self.__hash
        else:
            raise AttributeError("'Sequence_generic' object has no attribute '%s'"%name)
seq = Sequence

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.structure.sequence', 'Sequence', Sequence_generic)
Ejemplo n.º 40
0
            sage: G = groups.misc.AdditiveCyclic(3)
            sage: ZG = G.algebra(ZZ, category=AdditiveMagmas())
            sage: ZG.has_coerce_map_from(G)
            False
        """
        G = self.basis().keys()
        K = self.base_ring()

        if G.has_coerce_map_from(S):
            from sage.categories.groups import Groups
            # No coercion for additive groups because of ambiguity of +
            #   being the group action or addition of a new term.
            return self.category().is_subcategory(Groups().Algebras(K))

        if S in Sets.Algebras:
            S_K = S.base_ring()
            S_G = S.basis().keys()
            hom_K = K.coerce_map_from(S_K)
            hom_G = G.coerce_map_from(S_G)
            if hom_K is not None and hom_G is not None:
                return SetMorphism(
                    S.Hom(self, category=self.category() | S.category()),
                    lambda x: self.sum_of_terms(
                        (hom_G(g), hom_K(c)) for g, c in x))


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.algebras.group_algebras', 'GroupAlgebra',
                           GroupAlgebra_class)
Ejemplo n.º 41
0
Archivo: homset.py Proyecto: dagss/sage
            Integer Ring
            sage: Hom.base_extend(QQ)
            Traceback (most recent call last):
            ...
            NotImplementedError: Abelian variety point sets are not 
            implemented as modules over rings other than ZZ.
        """
        if R is not ZZ:
            raise NotImplementedError('Abelian variety point sets are not '
                            'implemented as modules over rings other than ZZ.')
        return self
    

from sage.structure.sage_object import register_unpickle_override 
register_unpickle_override('sage.schemes.generic.homset', 
                           'SchemeHomsetModule_abelian_variety_coordinates_field', 
                           SchemeHomset_points_abelian_variety_field) 

#*******************************************************************
# Toric varieties
#*******************************************************************
class SchemeHomset_points_toric_field(SchemeHomset_points):
    """
    Set of rational points of a toric variety.

    INPUT:

    - same as for :class:`SchemeHomset_points`.

    OUPUT:
Ejemplo n.º 42
0
            sage: from sage.modular.modsym.g1list import _G1list_old_pickle
            sage: L = _G1list_old_pickle()
            sage: type(L) == G1list
            True
        """
        self.__class__ = G1list

    def __setstate__(self, state):
        """
        For unpickling new pickles.

        TESTS::

            sage: from sage.modular.modsym.g1list import G1list
            sage: L = G1list(6)
            sage: Lp = loads(dumps(L))
            sage: L == Lp
            True
            sage: type(Lp) == G1list
            True
        """
        # We don't really want this class, but we want to handle new
        #   pickles without creating a new class
        self.__class__ = G1list
        self.__dict__ = state # Default pickling is ``state = self.__dict__``

register_unpickle_override('sage.modular.modsym.g1list', 'G1list',
                           _G1list_old_pickle)

Ejemplo n.º 43
0
            variables.
        
            EXAMPLES::
            
                sage: h = SFAHomogeneous(QQ)
                sage: h([3]).expand(2)
                x0^3 + x0^2*x1 + x0*x1^2 + x1^3
                sage: h([1,1,1]).expand(2)
                x0^3 + 3*x0^2*x1 + 3*x0*x1^2 + x1^3
                sage: h([2,1]).expand(3)
                x0^3 + 2*x0^2*x1 + 2*x0*x1^2 + x1^3 + 2*x0^2*x2 + 3*x0*x1*x2 + 2*x1^2*x2 + 2*x0*x2^2 + 2*x1*x2^2 + x2^3
                sage: h([3]).expand(2,alphabet='y')
                y0^3 + y0^2*y1 + y0*y1^2 + y1^3
                sage: h([3]).expand(2,alphabet='x,y')
                x^3 + x^2*y + x*y^2 + y^3
                sage: h([3]).expand(3,alphabet='x,y,z')
                x^3 + x^2*y + x*y^2 + y^3 + x^2*z + x*y*z + y^2*z + x*z^2 + y*z^2 + z^3
            """
            condition = lambda part: False
            return self._expand(condition, n, alphabet)


# Backward compatibility for unpickling
from sage.structure.sage_object import register_unpickle_override

register_unpickle_override(
    "sage.combinat.sf.homogeneous",
    "SymmetricFunctionAlgebraElement_homogeneous",
    SymmetricFunctionAlgebra_homogeneous.Element,
)
Ejemplo n.º 44
0
                if weights is not None:
                    try:
                        for weight in weights:
                            new_adj[node1][node2][weight] = {}
                    except TypeError:
                        new_adj[node1][node2]['weight'] = weights

        if self.multiedges:
            G = networkx.MultiDiGraph(new_adj)
        else:
            G = networkx.DiGraph(new_adj)

        return G

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('networkx.xgraph','XGraph', NetworkXGraphDeprecated)
register_unpickle_override('networkx.xdigraph','XDiGraph', NetworkXDiGraphDeprecated)

class NetworkXGraphBackend(GenericGraphBackend):
    """
    A wrapper for NetworkX as the backend of a graph.

    TESTS::

        sage: import sage.graphs.base.graph_backends

    """

    _nxg = None

    def __init__(self, N=None):
Ejemplo n.º 45
0
        EXAMPLE::

            sage: R = Integers(12345678900)
            sage: R.degree()
            1
        """
        return integer.Integer(1)


Zmod = IntegerModRing
Integers = IntegerModRing

# Register unpickling methods for backward compatibility.

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.integer_mod_ring',
                           'IntegerModRing_generic', IntegerModRing_generic)


def crt(v):
    """
    INPUT:

    - ``v`` -- (list) a lift of elements of ``rings.IntegerMod(n)``, for
      various coprime moduli ``n``

    EXAMPLES::

        sage: from sage.rings.finite_rings.integer_mod_ring import crt
        sage: crt([mod(3, 8),mod(1,19),mod(7, 15)])
        1027
    """
Ejemplo n.º 46
0
                        for weight in weights:
                            new_adj[node1][node2][weight] = {}
                    except TypeError:
                        new_adj[node1][node2]['weight'] = weights

        if self.multiedges:
            G = networkx.MultiDiGraph(new_adj)
        else:
            G = networkx.DiGraph(new_adj)

        return G


from sage.structure.sage_object import register_unpickle_override

register_unpickle_override('networkx.xgraph', 'XGraph',
                           NetworkXGraphDeprecated)
register_unpickle_override('networkx.xdigraph', 'XDiGraph',
                           NetworkXDiGraphDeprecated)


class NetworkXGraphBackend(GenericGraphBackend):
    """
    A wrapper for NetworkX as the backend of a graph.

    TESTS::

        sage: import sage.graphs.base.graph_backends

    """

    _nxg = None
Ejemplo n.º 47
0
            sage: QQ.an_element()
            1/2
        """
        return FormalSum([(self.base_ring().an_element(), 1)],
                         check=check,
                         reduce=reduce,
                         parent=self)


formal_sums = FormalSums()

# Formal sums now derives from UniqueRepresentation, which makes the
# factory function unnecessary. This is why the name was changed from
# class FormalSums_generic to class FormalSums.
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.structure.formal_sum', 'FormalSums_generic',
                           FormalSums)


class FormalSum(ModuleElement):
    """
    A formal sum over a ring.
    """
    def __init__(self, x, parent=formal_sums, check=True, reduce=True):
        """
        INPUT:
            - ``x`` -- object
            - ``parent`` -- FormalSums(R) module (default: FormalSums(ZZ))
            - ``check`` -- bool (default: True) if False, might not coerce
                           coefficients into base ring, which can speed
                           up constructing a formal sum.
            - ``reduce`` -- reduce (default: True) if False, do not
Ejemplo n.º 48
0
        i = n

        while i > 0:
            P = [0 for _ in range(n + 1)]
            for ai in R:
                P[i] = ai
                for tup in S[i - 1]:
                    if gcd([ai] + tup) == 1:
                        for j in range(i):
                            P[j] = tup[j]
                        pts.append(self(P))
            i -= 1

        # now do i=0; this is treated as a special case so that
        # we don't have all points (1:0),(2,0),(3,0),etc.
        P = [0 for _ in range(n + 1)]
        P[0] = 1
        pts.append(self(P))
        return pts


#fix the pickles from moving projective_space.py
from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.schemes.generic.projective_space',
                           'ProjectiveSpace_field', ProjectiveSpace_field)

register_unpickle_override('sage.schemes.generic.projective_space',
                           'ProjectiveSpace_rational_field',
                           ProjectiveSpace_rational_field)
Ejemplo n.º 49
0
    pass


class Polynomial_generic_cdvf(Polynomial_generic_cdv,
                              Polynomial_generic_field):
    pass


class Polynomial_generic_dense_cdvf(Polynomial_generic_dense_cdv,
                                    Polynomial_generic_cdvf):
    pass


class Polynomial_generic_sparse_cdvf(Polynomial_generic_sparse_cdv,
                                     Polynomial_generic_cdvf):
    pass


############################################################################
# XXX:  Ensures that the generic polynomials implemented in SAGE via PARI  #
# until at least until 4.5.0 unpickle correctly as polynomials implemented #
# via FLINT.                                                               #
from sage.structure.sage_object import (register_unpickle_override, richcmp,
                                        richcmp_not_equal, rich_to_bool,
                                        rich_to_bool_sgn)
from sage.rings.polynomial.polynomial_rational_flint import Polynomial_rational_flint

register_unpickle_override( \
    'sage.rings.polynomial.polynomial_element_generic', \
    'Polynomial_rational_dense', Polynomial_rational_flint)
Ejemplo n.º 50
0
            sage: P2.<x,y,z> = AffineSpace(3, GF(3))
            sage: point_homset = P2._point_homset(Spec(GF(3)), P2)
            sage: P2._point(point_homset, [1,2,3])
            (1, 2, 0)
        """
        return SchemeMorphism_point_affine_finite_field(*args, **kwds)

    def _morphism(self, *args, **kwds):
        """
        Construct a morphism.

        For internal use only. See :mod:`morphism` for details.

        TESTS::

            sage: P2.<x,y,z> = AffineSpace(3, GF(3))
            sage: P2._morphism(P2.Hom(P2), [x,y,z])
            Scheme endomorphism of Affine Space of dimension 3 over Finite Field of size 3
              Defn: Defined on coordinates by sending (x, y, z) to
                    (x, y, z)
        """
        return SchemeMorphism_polynomial_affine_space_finite_field(
            *args, **kwds)


#fix the pickles from moving affine_space.py
from sage.structure.sage_object import register_unpickle_override

register_unpickle_override('sage.schemes.generic.affine_space',
                           'AffineSpace_generic', AffineSpace_generic)
Ejemplo n.º 51
0
            sage: a = P.base_ring().gen()
            sage: F = Sequence([x*y + 1, a*x + 1], P)
            sage: F2 = F.weil_restriction()
            sage: F2
            [x1*y0 + x0*y1 + x1*y1,
             x0*y0 + x1*y1 + 1,
             x0 + x1,
             x1 + 1,
             x0^2 + x0,
             x1^2 + x1,
             y0^2 + y0,
             y1^2 + y1]

        Another bigger example for a small scale AES::

           sage: sr = mq.SR(1,1,1,4,gf2=False)
           sage: F,s = sr.polynomial_system(); F
           Polynomial Sequence with 40 Polynomials in 20 Variables
           sage: F2 = F.weil_restriction(); F2
           Polynomial Sequence with 240 Polynomials in 80 Variables
        """
        from sage.rings.ideal import FieldIdeal
        J = self.ideal().weil_restriction()
        J += FieldIdeal(J.ring())
        return PolynomialSequence(J)

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override("sage.crypto.mq.mpolynomialsystem","MPolynomialSystem_generic", PolynomialSequence_generic)
register_unpickle_override("sage.crypto.mq.mpolynomialsystem","MPolynomialRoundSystem_generic", PolynomialSequence_generic)

Ejemplo n.º 52
0
            sage: Hom(GF(3^3, 'a'), GF(3^6, 'b')).an_element()
            Ring morphism:
              From: Finite Field in a of size 3^3
              To:   Finite Field in b of size 3^6
              Defn: a |--> 2*b^5 + 2*b^4

            sage: Hom(GF(3^3, 'a'), GF(3^2, 'c')).an_element()
            Traceback (most recent call last):
            ...
            EmptySetError: no homomorphisms from Finite Field in a of size 3^3 to Finite Field in c of size 3^2

        .. TODO::

            Use a more sophisticated algorithm; see also :trac:`8751`.

        """
        K = self.domain()
        L = self.codomain()
        if K.degree() == 1:
            return L.coerce_map_from(K)
        elif not K.degree().divides(L.degree()):
            from sage.categories.sets_cat import EmptySetError
            raise EmptySetError('no homomorphisms from %s to %s' % (K, L))
        return K.hom([K.modulus().any_root(L)])


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.rings.finite_field_morphism',
                           'FiniteFieldHomset', FiniteFieldHomset)
Ejemplo n.º 53
0
            Finite family {1: (1, 0, 0, 0), 2: (1, 1, 0, 0), 3: (1/2, 1/2, 1/2, -1/2), 4: (1/2, 1/2, 1/2, 1/2)}
        """
        if i not in self.index_set():
            raise ValueError("{} is not in the index set".format(i))
        n = self.dimension()
        if i == n:
            return self.sum(self.monomial(j) for j in range(n)) / 2
        elif i == n - 1:
            return (self.sum(self.monomial(j)
                             for j in range(n - 1)) - self.monomial(n - 1)) / 2
        else:
            return self.sum(self.monomial(j) for j in range(i))


from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.root_system.type_A', 'ambient_space',
                           AmbientSpace)

from sage.misc.cachefunc import cached_method
from cartan_type import CartanType_standard_finite, CartanType_simply_laced, CartanType_simple


class CartanType(CartanType_standard_finite, CartanType_simply_laced):
    def __init__(self, n):
        """
        EXAMPLES::

            sage: ct = CartanType(['D',4])
            sage: ct
            ['D', 4]
            sage: ct._repr_(compact = True)
            'D4'
Ejemplo n.º 54
0
class Polynomial_generic_sparse_field(Polynomial_generic_sparse, Polynomial_generic_field):
    """
    EXAMPLES::

        sage: R.<x> = PolynomialRing(Frac(RR['t']), sparse=True)
        sage: f = x^3 - x + 17
        sage: type(f)
        <class 'sage.rings.polynomial.polynomial_element_generic.PolynomialRing_field_with_category.element_class'>
        sage: loads(f.dumps()) == f
        True
    """
    def __init__(self, parent, x=None, check=True, is_gen = False, construct=False):
        Polynomial_generic_sparse.__init__(self, parent, x, check, is_gen)


class Polynomial_generic_dense_field(Polynomial_generic_dense, Polynomial_generic_field):
    def __init__(self, parent, x=None, check=True, is_gen = False, construct=False):
        Polynomial_generic_dense.__init__(self, parent, x, check, is_gen)

############################################################################
# XXX:  Ensures that the generic polynomials implemented in SAGE via PARI  #
# until at least until 4.5.0 unpickle correctly as polynomials implemented #
# via FLINT.                                                               #
from sage.structure.sage_object import register_unpickle_override
from sage.rings.polynomial.polynomial_rational_flint import Polynomial_rational_flint

register_unpickle_override( \
    'sage.rings.polynomial.polynomial_element_generic', \
    'Polynomial_rational_dense', Polynomial_rational_flint)
Ejemplo n.º 55
0
        """
        for p in descents_composition_list(self.shape):
            yield self.from_permutation(p)

class Ribbon_class(RibbonShapedTableau):
    """
    This exists solely for unpickling ``Ribbon_class`` objects.
    """
    def __setstate__(self, state):
        r"""
        Unpickle old ``Ribbon_class`` objects.

        EXAMPLES::

            sage: loads('x\x9ck`J.NLO\xd5K\xce\xcfM\xca\xccK,\xd1+\xcaLJ\xca\xcf\xe3\n\x02S\xf1\xc99\x89\xc5\xc5\\\x85\x8c\x9a\x8d\x85L\xb5\x85\xcc\x1a\xa1\xac\xf1\x19\x89\xc5\x19\x85,~@VNfqI!kl!\x9bFl!\xbb\x06\xc4\x9c\xa2\xcc\xbc\xf4b\xbd\xcc\xbc\x92\xd4\xf4\xd4"\xae\xdc\xc4\xec\xd4x\x18\xa7\x90#\x94\xd1\xb05\xa8\x903\x03\xc80\x022\xb8Rc\x0b\xb95@<c \x8f\x07\xc40\x012xSSK\x93\xf4\x00l\x811\x17')
            [[None, 1, 2], [3, 4]]
            sage: loads(dumps( RibbonShapedTableau([[3,2,1], [1,1]]) ))  # indirect doctest
            [[None, 3, 2, 1], [1, 1]]
        """
        self.__class__ = RibbonShapedTableau
        self.__init__(RibbonShapedTableaux(), state['_list'])

from sage.structure.sage_object import register_unpickle_override
register_unpickle_override('sage.combinat.ribbon', 'Ribbon_class', Ribbon_class)
register_unpickle_override('sage.combinat.ribbon', 'StandardRibbons_shape', StandardRibbonShapedTableaux)

# Deprecations from trac:18555. July 2016
from sage.misc.superseded import deprecated_function_alias
RibbonShapedTableaux.global_options = deprecated_function_alias(18555, RibbonShapedTableaux.options)
StandardRibbonShapedTableaux.global_options = deprecated_function_alias(18555, StandardRibbonShapedTableaux.options)
Ejemplo n.º 56
0
            sage: eps = DirichletGroup(4).gen(0)
            sage: from sage.modular.modsym.manin_symbol_list import ManinSymbolList_character
            sage: m = ManinSymbolList_character(eps,4); m
            Manin Symbol List of weight 4 for Gamma1(4) with character [-1]
            sage: [m.normalize(s.tuple()) for s in m.manin_symbol_list()]
            [((0, 0, 1), 1),
             ((0, 1, 0), 1),
             ((0, 1, 1), 1),
             ...
             ((2, 1, 3), 1),
             ((2, 2, 1), 1)]
        """
        u, v, s = self.__P1.normalize_with_scalar(x[1], x[2])
        return (x[0], u, v), self.__character(s)


register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList', ManinSymbolList)
register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList_group', ManinSymbolList_group)
register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList_gamma0', ManinSymbolList_gamma0)
register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList_gamma1', ManinSymbolList_gamma1)
register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList_gamma_h', ManinSymbolList_gamma_h)
register_unpickle_override('sage.modular.modsym.manin_symbols',
                           'ManinSymbolList_character',
                           ManinSymbolList_character)