示例#1
0
def prepare_indeterminates(names, ctx, coeffring=None):
    """
    From space separated names of indeterminates, prepare variables
    representing the indeterminates.  The result will be stored in ctx
    dictionary.

    The variables should be prepared at once, otherwise wrong aliases
    of variables may confuse you in later calculation.

    If an optional coeffring is not given, indeterminates will be
    initialized as integer coefficient polynomials.

    Example:
    >>> prepare_indeterminates("X Y Z", globals())
    >>> Y
    UniqueFactorizationDomainPolynomial({(0, 1, 0): 1})

    """
    split_names = names.split()
    number_of_variables = len(split_names)
    if coeffring is None:
        coeffring = uniutil.init_coefficient_ring({1:1})
    for i, name in enumerate(split_names):
        e_i = tuple([0] * i + [1] + [0] * (number_of_variables - i - 1))
        ctx[name] = polynomial({e_i: 1}, coeffring, number_of_variables)
示例#2
0
    def __init__(self, coefficients, **kwds):
        """
        Initialize the polynomial.

        Required argument:
        - coefficients: initializer for polynomial coefficients

        Keyword arguments should include:
        - coeffring: domain
        - number_of_variables: the number of variables
        """
        if "number_of_variables" not in kwds:
            coefficients = dict(coefficients)
            for i in coefficients.keys():
                kwds["number_of_variables"] = len(i)
                break
        multivar.BasicPolynomial.__init__(self, coefficients, **kwds)
        NestProvider.__init__(self)
        PseudoDivisionProvider.__init__(self)
        RingElementProvider.__init__(self)
        coeffring = None
        if "coeffring" in kwds:
            coeffring = kwds["coeffring"]
        else:
            coeffring = uniutil.init_coefficient_ring(self._coefficients)
        if coeffring is not None:
            self.set_coefficient_ring(coeffring)
        else:
            raise TypeError("argument `coeffring' is required")
        if "order" in kwds:
            order = kwds["order"]
        else:
            order = termorder.lexicographic_order
        OrderProvider.__init__(self, order)
示例#3
0
def prepare_indeterminates(names, ctx, coeffring=None):
    """
    From space separated names of indeterminates, prepare variables
    representing the indeterminates.  The result will be stored in ctx
    dictionary.

    The variables should be prepared at once, otherwise wrong aliases
    of variables may confuse you in later calculation.

    If an optional coeffring is not given, indeterminates will be
    initialized as integer coefficient polynomials.

    Example:
    >>> prepare_indeterminates("X Y Z", globals())
    >>> Y
    UniqueFactorizationDomainPolynomial({(0, 1, 0): 1})

    """
    split_names = names.split()
    number_of_variables = len(split_names)
    if coeffring is None:
        coeffring = uniutil.init_coefficient_ring({1:1})
    for i, name in enumerate(split_names):
        e_i = tuple([0] * i + [1] + [0] * (number_of_variables - i - 1))
        ctx[name] = polynomial({e_i: 1}, coeffring, number_of_variables)
示例#4
0
    def __init__(self, coefficients, **kwds):
        """
        Initialize the polynomial.

        Required argument:
        - coefficients: initializer for polynomial coefficients

        Keyword arguments should include:
        - coeffring: domain
        - number_of_variables: the number of variables
        """
        if "number_of_variables" not in kwds:
            coefficients = dict(coefficients)
            for i in coefficients.iterkeys():
                kwds["number_of_variables"] = len(i)
                break
        multivar.BasicPolynomial.__init__(self, coefficients, **kwds)
        NestProvider.__init__(self)
        PseudoDivisionProvider.__init__(self)
        RingElementProvider.__init__(self)
        coeffring = None
        if "coeffring" in kwds:
            coeffring = kwds["coeffring"]
        else:
            coeffring = uniutil.init_coefficient_ring(self._coefficients)
        if coeffring is not None:
            self.set_coefficient_ring(coeffring)
        else:
            raise TypeError("argument `coeffring' is required")
        if "order" in kwds:
            order = kwds["order"]
        else:
            order = termorder.lexicographic_order
        OrderProvider.__init__(self, order)
示例#5
0
def MultiVariableSparsePolynomial(coefficient, variable, coeffring=None):
    """
    MultiVariableSparsePolynomial(coefficient, variable [,coeffring])

    - coefficient has to be a dictionary of form {(i1,...,ik): c}
    - variable has to be a list of character strings.
    - coeffring has to be, if specified, an object inheriting ring.Ring.
    
    This function is provided for backward compatible way of defining
    multivariate polynomial.  The variable names are ignored, but
    their number is used.
    """
    if not isinstance(variable, list) or not isinstance(coefficient, dict):
        raise ValueError("You must input MultiVariableSparsePolynomial(dict, list) but (%s, %s)." % (coefficient.__class__, variable.__class__))
    if coeffring is None:
        coeffring = uniutil.init_coefficient_ring(coefficient)
    return polynomial(coefficient, coeffring=coeffring, number_of_variables=len(variable))
示例#6
0
def MultiVariableSparsePolynomial(coefficient, variable, coeffring=None):
    """
    MultiVariableSparsePolynomial(coefficient, variable [,coeffring])

    - coefficient has to be a dictionary of form {(i1,...,ik): c}
    - variable has to be a list of character strings.
    - coeffring has to be, if specified, an object inheriting ring.Ring.
    
    This function is provided for backward compatible way of defining
    multivariate polynomial.  The variable names are ignored, but
    their number is used.
    """
    if not isinstance(variable, list) or not isinstance(coefficient, dict):
        raise ValueError("You must input MultiVariableSparsePolynomial(dict, list) but (%s, %s)." % (coefficient.__class__, variable.__class__))
    if coeffring is None:
        coeffring = uniutil.init_coefficient_ring(coefficient)
    return polynomial(coefficient, coeffring=coeffring, number_of_variables=len(variable))