IntegerPolynomial

IntegerPolynomial()

A Symbolica polynomial with integer coefficients.

Methods

Name Description
coefficient_list Get the coefficient list in x.
content Get the content, i.e., the GCD of the coefficients.
derivative Take a derivative in x.
factor Factorize the polynomial.
factor_square_free Compute the square-free factorization of the polynomial.
gcd Compute the greatest common divisor (GCD) of two polynomials.
get_var_list Get the list of variables in the internal ordering of the polynomial.
nterms Get the number of terms in the polynomial.
parse Parse a polynomial with integer coefficients from a string.
pretty_str Convert the polynomial into a human-readable string, with tunable settings.
quot_rem Divide self by rhs, returning the quotient and remainder.
replace Replace the variable x with a polynomial v.
resultant Compute the resultant of two polynomials with respect to the variable var.
to_expression Convert the polynomial to an expression.
to_latex Convert the polynomial into a LaTeX string.

coefficient_list

IntegerPolynomial.coefficient_list(x)

Get the coefficient list in x.

Examples

>>> from symbolica import Expression
>>> x = Expression.symbol('x')
>>> p = Expression.parse('x*y+2*x+x^2').to_polynomial().to_integer_polynomial()
>>> for n, pp in p.coefficient_list(x):
>>>     print(n, pp)

content

IntegerPolynomial.content()

Get the content, i.e., the GCD of the coefficients.

Examples

>>> from symbolica import Expression
>>> p = Expression.parse('3x^2+6x+9').to_polynomial().to_integer_polynomial()
>>> print(p.content())

derivative

IntegerPolynomial.derivative(x)

Take a derivative in x.

Examples

>>> from symbolica import Expression
>>> x = Expression.symbol('x')
>>> p = Expression.parse('x^2+2').to_polynomial().to_integer_polynomial()
>>> print(p.derivative(x))

factor

IntegerPolynomial.factor()

Factorize the polynomial.

The polynomial must be univariate.

Examples

>>> from symbolica import Expression
>>> p = Expression.parse('(x+1)(x+2)(x+3)(x+4)(x+5)(x^2+6)(x^3+7)(x+8)(x^4+9)(x^5+x+10)').expand().to_polynomial().to_integer_polynomial()
>>> print('Factorization of {}:'.format(p))
>>> for f, exp in p.factor():
>>>     print(' ({})^{}'.format(f, exp))

factor_square_free

IntegerPolynomial.factor_square_free()

Compute the square-free factorization of the polynomial.

Examples

>>> from symbolica import Expression
>>> p = Expression.parse('3*(2*x^2+y)(x^3+y)^2(1+4*y)^2(1+x)').expand().to_polynomial().to_integer_polynomial()
>>> print('Square-free factorization of {}:'.format(p))
>>> for f, exp in p.factor_square_free():
>>>     print(' ({})^{}'.format(f, exp))

gcd

IntegerPolynomial.gcd(rhs)

Compute the greatest common divisor (GCD) of two polynomials.

get_var_list

IntegerPolynomial.get_var_list()

Get the list of variables in the internal ordering of the polynomial.

nterms

IntegerPolynomial.nterms()

Get the number of terms in the polynomial.

parse

IntegerPolynomial.parse(_cls, input, vars)

Parse a polynomial with integer coefficients from a string. The input must be written in an expanded format and a list of all the variables must be provided.

If these requirements are too strict, use Expression.to_polynomial() or RationalPolynomial.parse() instead.

Examples

>>> e = IntegerPolynomial.parse('3*x^2+y+y*4', ['x', 'y'])

Raises

Type Description
ValueError If the input is not a valid Symbolica polynomial.

pretty_str

IntegerPolynomial.pretty_str(terms_on_new_line=False, color_top_level_sum=True, color_builtin_symbols=True, print_finite_field=True, symmetric_representation_for_finite_field=False, explicit_rational_polynomial=False, number_thousands_separator=None, multiplication_operator='*', square_brackets_for_function=False, num_exp_as_superscript=True, latex=False)

Convert the polynomial into a human-readable string, with tunable settings.

Examples

>>> p = FiniteFieldPolynomial.parse("3*x^2+2*x+7*x^3", ['x'], 11)
>>> print(p.pretty_str(symmetric_representation_for_finite_field=True))

Yields z³⁴+x^(x+2)+y⁴+f(x,x²)+128_378_127_123 z^(2/3) w² x⁻¹ y⁻¹+3/5.

quot_rem

IntegerPolynomial.quot_rem(rhs)

Divide self by rhs, returning the quotient and remainder.

replace

IntegerPolynomial.replace(x, v)

Replace the variable x with a polynomial v.

Examples

>>> from symbolica import Expression
>>> x = Expression.symbol('x')
>>> p = Expression.parse('x*y+2*x+x^2').to_polynomial()
>>> r = Expression.parse('y+1').to_polynomial())
>>> p.replace(x, r)

resultant

IntegerPolynomial.resultant(rhs, var)

Compute the resultant of two polynomials with respect to the variable var.

to_expression

IntegerPolynomial.to_expression()

Convert the polynomial to an expression.

Examples

>>> from symbolica import Expression
>>> e = Expression.parse('x*y+2*x+x^2')
>>> p = e.to_polynomial().to_integer_polynomial()
>>> print((e - p.to_expression()).expand())

to_latex

IntegerPolynomial.to_latex()

Convert the polynomial into a LaTeX string.