Polynomial

Polynomial()

A Symbolica polynomial with rational coefficients.

Methods

Name Description
coefficient_list Get the coefficient list, optionally in the variables xs.
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.
groebner_basis Compute the Groebner basis of a polynomial system.
integrate Integrate the polynomial in x.
nterms Get the number of terms in the polynomial.
optimize Optimize the polynomial for evaluation using iterations number of iterations.
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_finite_field Convert the coefficients of the polynomial to a finite field with prime prime.
to_integer_polynomial Convert the polynomial to a polynomial with integer coefficients, if possible.
to_latex Convert the polynomial into a LaTeX string.

coefficient_list

Polynomial.coefficient_list(xs)

Get the coefficient list, optionally in the variables xs.

Examples

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

content

Polynomial.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()
>>> print(p.content())

derivative

Polynomial.derivative(x)

Take a derivative in x.

Examples

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

factor

Polynomial.factor()

Factorize the polynomial.

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()
>>> print('Factorization of {}:'.format(p))
>>> for f, exp in p.factor():
>>>     print(' ({})^{}'.format(f, exp))

factor_square_free

Polynomial.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()
>>> print('Square-free factorization of {}:'.format(p))
>>> for f, exp in p.factor_square_free():
>>>     print(' ({})^{}'.format(f, exp))

gcd

Polynomial.gcd(rhs)

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

get_var_list

Polynomial.get_var_list()

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

groebner_basis

Polynomial.groebner_basis(_cls, system, grevlex=True, print_stats=False)

Compute the Groebner basis of a polynomial system.

If grevlex=True, reverse graded lexicographical ordering is used, otherwise the ordering is lexicographical.

If print_stats=True intermediate statistics will be printed.

Examples

>>> basis = Polynomial.groebner_basis(
>>>     [Expression.parse("a b c d - 1").to_polynomial(),
>>>     Expression.parse("a b c + a b d + a c d + b c d").to_polynomial(),
>>>     Expression.parse("a b + b c + a d + c d").to_polynomial(),
>>>     Expression.parse("a + b + c + d").to_polynomial()],
>>>     grevlex=True,
>>>     print_stats=True
>>> )
>>> for p in basis:
>>>     print(p)

integrate

Polynomial.integrate(x)

Integrate the polynomial in x.

Examples

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

nterms

Polynomial.nterms()

Get the number of terms in the polynomial.

optimize

Polynomial.optimize(iterations=1000, to_file=None)

Optimize the polynomial for evaluation using iterations number of iterations. The optimized output can be exported in a C++ format using to_file.

Returns an evaluator for the polynomial.

parse

Polynomial.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 = Polynomial.parse('3*x^2+y+y*4', ['x', 'y'])

Raises

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

pretty_str

Polynomial.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

Polynomial.quot_rem(rhs)

Divide self by rhs, returning the quotient and remainder.

replace

Polynomial.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

Polynomial.resultant(rhs, var)

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

to_expression

Polynomial.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()
>>> print((e - p.to_expression()).expand())

to_finite_field

Polynomial.to_finite_field(prime)

Convert the coefficients of the polynomial to a finite field with prime prime.

to_integer_polynomial

Polynomial.to_integer_polynomial()

Convert the polynomial to a polynomial with integer coefficients, if possible.

to_latex

Polynomial.to_latex()

Convert the polynomial into a LaTeX string.