NumberFieldPolynomial

NumberFieldPolynomial

NumberFieldPolynomial()

A Symbolica polynomial with rational coefficients.

Methods

Name Description
__add__ Add two polynomials self and rhs, returning the result.
__contains__ Check if the polynomial contains the given variable.
__copy__ Copy the polynomial.
__eq__ Check if two polynomials are equal.
__floordiv__ Divide the polynomial self by rhs, rounding down, returning the result.
__ge__ Check if the polynomial is greater than or equal to an integer.
__gt__ Check if the polynomial is greater than an integer.
__le__ Check if the polynomial is less than or equal to an integer.
__lt__ Check if the polynomial is less than an integer.
__mod__ Compute the remainder of the division of self by rhs.
__mul__ Multiply two polynomials self and rhs, returning the result.
__ne__ Check if two polynomials are not equal.
__neg__ Negate the polynomial.
__pow__ Raise the polynomial to the power of exp, returning the result.
__radd__ Add two polynomials self and rhs, returning the result.
__rmul__ Multiply two polynomials self and rhs, returning the result.
__rsub__ Subtract polynomials self from rhs, returning the result.
__str__ Print the polynomial in a human-readable format.
__sub__ Subtract polynomials rhs from self, returning the result.
__truediv__ Divide the polynomial self by rhs if possible, returning the result.
coefficient_list Get the coefficient list, optionally in the variables xs.
contains Check if the polynomial contains the given variable.
content Get the content, i.e., the GCD of the coefficients.
degree Get the degree of the polynomial in var.
derivative Take a derivative in x.
extended_gcd Compute the extended GCD of two polynomials, yielding the GCD and the Bezout coefficients s and t such that self * s + rhs * t = gcd(self, rhs).
factor Factorize the polynomial.
factor_square_free Compute the square-free factorization of the polynomial.
format Convert the polynomial into a human-readable string, with tunable settings.
gcd Compute the greatest common divisor (GCD) of two or more polynomials.
get_minimal_polynomial Get the minimal polynomial of the algebraic extension.
get_variables 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.
lcoeff Get the leading coefficient.
monic Get the monic part of the polynomial, i.e., the polynomial divided by its leading coefficient.
nterms Get the number of terms in the polynomial.
primitive Get the primitive part of the polynomial, i.e., the polynomial with the content removed.
quot_rem Divide self by rhs, returning the quotient and remainder.
reduce Completely reduce the polynomial w.r.t the polynomials gs
reorder Reorder the polynomial in-place to use the given variable order.
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.
to_polynomial Convert the number field polynomial to a rational polynomial.

__add__

NumberFieldPolynomial.__add__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Add two polynomials self and rhs, returning the result.

__contains__

NumberFieldPolynomial.__contains__(var: Expression) -> bool

Check if the polynomial contains the given variable.

__copy__

NumberFieldPolynomial.__copy__() -> NumberFieldPolynomial

Copy the polynomial.

__eq__

NumberFieldPolynomial.__eq__(rhs: Polynomial | int) -> bool

Check if two polynomials are equal.

__floordiv__

NumberFieldPolynomial.__floordiv__(rhs: Polynomial) -> Polynomial

Divide the polynomial self by rhs, rounding down, returning the result.

__ge__

NumberFieldPolynomial.__ge__(rhs: int) -> bool

Check if the polynomial is greater than or equal to an integer.

__gt__

NumberFieldPolynomial.__gt__(rhs: int) -> bool

Check if the polynomial is greater than an integer.

__le__

NumberFieldPolynomial.__le__(rhs: int) -> bool

Check if the polynomial is less than or equal to an integer.

__lt__

NumberFieldPolynomial.__lt__(rhs: int) -> bool

Check if the polynomial is less than an integer.

__mod__

NumberFieldPolynomial.__mod__(rhs: NumberFieldPolynomial) -> NumberFieldPolynomial

Compute the remainder of the division of self by rhs.

__mul__

NumberFieldPolynomial.__mul__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Multiply two polynomials self and rhs, returning the result.

__ne__

NumberFieldPolynomial.__ne__(rhs: Polynomial | int) -> bool

Check if two polynomials are not equal.

__neg__

NumberFieldPolynomial.__neg__() -> NumberFieldPolynomial

Negate the polynomial.

__pow__

NumberFieldPolynomial.__pow__(exp: int) -> NumberFieldPolynomial

Raise the polynomial to the power of exp, returning the result.

__radd__

NumberFieldPolynomial.__radd__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Add two polynomials self and rhs, returning the result.

__rmul__

NumberFieldPolynomial.__rmul__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Multiply two polynomials self and rhs, returning the result.

__rsub__

NumberFieldPolynomial.__rsub__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Subtract polynomials self from rhs, returning the result.

__str__

NumberFieldPolynomial.__str__() -> str

Print the polynomial in a human-readable format.

__sub__

NumberFieldPolynomial.__sub__(rhs: NumberFieldPolynomial | int) -> NumberFieldPolynomial

Subtract polynomials rhs from self, returning the result.

__truediv__

NumberFieldPolynomial.__truediv__(rhs: NumberFieldPolynomial) -> NumberFieldPolynomial

Divide the polynomial self by rhs if possible, returning the result.

coefficient_list

NumberFieldPolynomial.coefficient_list(xs: Optional[Expression | Sequence[Expression]] = None) -> list[Tuple[list[int], NumberFieldPolynomial]]

Get the coefficient list, optionally in the variables xs.

Examples

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

contains

NumberFieldPolynomial.contains(var: Expression) -> bool

Check if the polynomial contains the given variable.

content

NumberFieldPolynomial.content() -> NumberFieldPolynomial

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

Examples

from symbolica import *
p = E('3x^2+6x+9').to_polynomial()
print(p.content())

degree

NumberFieldPolynomial.degree(var: Expression) -> int

Get the degree of the polynomial in var.

derivative

NumberFieldPolynomial.derivative(x: Expression) -> NumberFieldPolynomial

Take a derivative in x.

Examples

from symbolica import *
x = S('x')
p = E('x^2+2').to_polynomial()
print(p.derivative(x))

extended_gcd

NumberFieldPolynomial.extended_gcd(rhs: NumberFieldPolynomial) -> Tuple[NumberFieldPolynomial, NumberFieldPolynomial, NumberFieldPolynomial]

Compute the extended GCD of two polynomials, yielding the GCD and the Bezout coefficients s and t such that self * s + rhs * t = gcd(self, rhs).

factor

NumberFieldPolynomial.factor() -> list[Tuple[NumberFieldPolynomial, int]]

Factorize the polynomial.

Examples

from symbolica import *
p = E('(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

NumberFieldPolynomial.factor_square_free() -> list[Tuple[NumberFieldPolynomial, int]]

Compute the square-free factorization of the polynomial.

Examples

from symbolica import *
p = E('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))

format

NumberFieldPolynomial.format(
    mode: PrintMode = PrintMode.Symbolica,
    max_line_length: int | None = 80,
    indentation: int = 4,
    fill_indented_lines: bool = True,
    terms_on_new_line: bool = False,
    color_top_level_sum: bool = True,
    color_builtin_symbols: bool = True,
    bracket_level_colors: Sequence[int] | None = [244, 25, 97, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60],
    print_ring: bool = True,
    symmetric_representation_for_finite_field: bool = False,
    explicit_rational_polynomial: bool = False,
    number_thousands_separator: Optional[str] = None,
    multiplication_operator: str = '*',
    double_star_for_exponentiation: bool = False,
    square_brackets_for_function: bool = False,
    function_brackets: tuple[str, str] = ('(', ')'),
    num_exp_as_superscript: bool = True,
    precision: Optional[int] = None,
    show_namespaces: bool = False,
    hide_namespace: Optional[str] = None,
    include_attributes: bool = False,
    max_terms: Optional[int] = None,
    custom_print_mode: Optional[int] = None,
) -> str

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

Examples

p = FiniteFieldNumberFieldPolynomial.parse("3*x^2+2*x+7*x^3", ['x'], 11)
print(p.format(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.

gcd

NumberFieldPolynomial.gcd(*rhs: NumberFieldPolynomial) -> NumberFieldPolynomial

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

get_minimal_polynomial

NumberFieldPolynomial.get_minimal_polynomial() -> Polynomial

Get the minimal polynomial of the algebraic extension.

get_variables

NumberFieldPolynomial.get_variables() -> Sequence[Expression]

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

groebner_basis

NumberFieldPolynomial.groebner_basis(
    system: list[NumberFieldPolynomial],
    grevlex: bool = True,
    print_stats: bool = False,
) -> list[NumberFieldPolynomial]

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.

integrate

NumberFieldPolynomial.integrate(x: Expression) -> NumberFieldPolynomial

Integrate the polynomial in x.

Examples

from symbolica import *
x = S('x')
p = E('x^2+2').to_polynomial()
print(p.integrate(x))

lcoeff

NumberFieldPolynomial.lcoeff() -> NumberFieldPolynomial

Get the leading coefficient.

Examples

from symbolica import Expression as E
p = E('3x^2+6x+9').to_polynomial().lcoeff()
print(p)

Yields 3.

monic

NumberFieldPolynomial.monic() -> NumberFieldPolynomial

Get the monic part of the polynomial, i.e., the polynomial divided by its leading coefficient.

Examples

from symbolica import Expression as E
p = E('6x^2+3x+9').to_polynomial()
print(p.monic())

Yields x^2+1/2*x+2/3.

nterms

NumberFieldPolynomial.nterms() -> int

Get the number of terms in the polynomial.

primitive

NumberFieldPolynomial.primitive() -> NumberFieldPolynomial

Get the primitive part of the polynomial, i.e., the polynomial with the content removed.

Examples

from symbolica import Expression as E
p = E('3x^2+6x+9').to_polynomial()
print(p.primitive())

Yields x^2+2*x+3.

quot_rem

NumberFieldPolynomial.quot_rem(rhs: NumberFieldPolynomial) -> Tuple[NumberFieldPolynomial, NumberFieldPolynomial]

Divide self by rhs, returning the quotient and remainder.

reduce

NumberFieldPolynomial.reduce(
    gs: Sequence[Polynomial],
    grevlex: bool = True,
) -> NumberFieldPolynomial

Completely reduce the polynomial w.r.t the polynomials gs.

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

Examples

E('y^2+x').to_polynomial().reduce([E('x').to_polynomial()])

yields y^2

reorder

NumberFieldPolynomial.reorder(vars: Sequence[Expression]) -> None

Reorder the polynomial in-place to use the given variable order.

replace

NumberFieldPolynomial.replace(
    x: Expression,
    v: NumberFieldPolynomial | int,
) -> NumberFieldPolynomial

Replace the variable x with a polynomial v.

Examples

from symbolica import *
x = S('x')
p = E('x*y+2*x+x^2').to_polynomial()
r = E('y+1').to_polynomial())
p.replace(x, r)

resultant

NumberFieldPolynomial.resultant(
    rhs: NumberFieldPolynomial,
    var: Expression,
) -> NumberFieldPolynomial

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

to_expression

NumberFieldPolynomial.to_expression() -> Expression

Convert the polynomial to an expression.

Examples

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

to_latex

NumberFieldPolynomial.to_latex() -> str

Convert the polynomial into a LaTeX string.

to_polynomial

NumberFieldPolynomial.to_polynomial() -> Polynomial

Convert the number field polynomial to a rational polynomial.