FiniteFieldPolynomial

FiniteFieldPolynomial

FiniteFieldPolynomial()

A Symbolica polynomial with finite field 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.
__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.
adjoin Adjoin the coefficient ring of this polynomial R[a] with b, whose minimal polynomial is R[a][b] and form R[b]
coefficient_list Get the coefficient list, optionally in the variables xs.
contains Check if the polynomial contains the given variable.
degree Get the degree of the polynomial in var.
derivative Take a derivative in x.
evaluate Evaluate the polynomial at point input.
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_modulus Get the modulus of the finite field.
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.
parse Parse a polynomial with integer coefficients from a string
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.
simplify_algebraic_number Find the minimal polynomial for the algebraic number represented by this polynomial expressed in the number field defined by minimal_poly.
to_expression Convert the polynomial to an expression.
to_galois_field Convert the coefficients of the polynomial to a Galois field defined by the minimal polynomial min_poly.
to_integer_polynomial Convert the polynomial to a polynomial with integer coefficients.
to_latex Convert the polynomial into a LaTeX string.
to_polynomial Convert a Galois field polynomial to a simple finite field polynomial.

__add__

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

Add two polynomials self and rhs, returning the result.

__contains__

FiniteFieldPolynomial.__contains__(var: Expression) -> bool

Check if the polynomial contains the given variable.

__copy__

FiniteFieldPolynomial.__copy__() -> FiniteFieldPolynomial

Copy the polynomial.

__eq__

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

Check if two polynomials are equal.

__floordiv__

FiniteFieldPolynomial.__floordiv__(rhs: Polynomial) -> Polynomial

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

__mod__

FiniteFieldPolynomial.__mod__(rhs: FiniteFieldPolynomial) -> FiniteFieldPolynomial

Compute the remainder of the division of self by rhs.

__mul__

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

Multiply two polynomials self and rhs, returning the result.

__ne__

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

Check if two polynomials are not equal.

__neg__

FiniteFieldPolynomial.__neg__() -> FiniteFieldPolynomial

Negate the polynomial.

__pow__

FiniteFieldPolynomial.__pow__(exp: int) -> FiniteFieldPolynomial

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

__radd__

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

Add two polynomials self and rhs, returning the result.

__rmul__

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

Multiply two polynomials self and rhs, returning the result.

__rsub__

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

Subtract polynomials self from rhs, returning the result.

__str__

FiniteFieldPolynomial.__str__() -> str

Print the polynomial in a human-readable format.

__sub__

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

Subtract polynomials rhs from self, returning the result.

__truediv__

FiniteFieldPolynomial.__truediv__(rhs: FiniteFieldPolynomial) -> FiniteFieldPolynomial

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

adjoin

FiniteFieldPolynomial.adjoin(
    b: FiniteFieldPolynomial,
    new_symbol: Optional[Expression] = None,
) -> Tuple[FiniteFieldPolynomial, FiniteFieldPolynomial, FiniteFieldPolynomial]

Adjoin the coefficient ring of this polynomial R[a] with b, whose minimal polynomial is R[a][b] and form R[b]. Also return the new representation of a and b.

b must be irreducible over R and R[a]; this is not checked.

If new_symbol is provided, the variable of the new extension will be renamed to it. Otherwise, the variable of the new extension will be the same as that of b.

coefficient_list

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

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

FiniteFieldPolynomial.contains(var: Expression) -> bool

Check if the polynomial contains the given variable.

degree

FiniteFieldPolynomial.degree(var: Expression) -> int

Get the degree of the polynomial in var.

derivative

FiniteFieldPolynomial.derivative(x: Expression) -> FiniteFieldPolynomial

Take a derivative in x.

Examples

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

evaluate

FiniteFieldPolynomial.evaluate(input: Sequence[int]) -> int

Evaluate the polynomial at point input.

Examples

from symbolica import *
P('x*y+2*x+x^2', modulus=5).evaluate([2, 3])

Yields 4.

extended_gcd

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

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

Examples

from symbolica import *
E('(1+x)(20+x)').to_polynomial(modulus=5).extended_gcd(E('x^2+2').to_polynomial(modulus=5))

yields (1, 3+4*x, 3+x).

factor

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

factor_square_free

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

format

FiniteFieldPolynomial.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 = FiniteFieldPolynomial.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

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

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

get_minimal_polynomial

FiniteFieldPolynomial.get_minimal_polynomial() -> FiniteFieldPolynomial

Get the minimal polynomial of the algebraic extension.

get_modulus

FiniteFieldPolynomial.get_modulus() -> int

Get the modulus of the finite field.

get_variables

FiniteFieldPolynomial.get_variables() -> Sequence[Expression]

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

groebner_basis

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

Compute the Groebner basis of a polynomial system.

Examples

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

Parameters

  • grevlex (bool) If True, reverse graded lexicographical ordering is used, otherwise the ordering is lexicographical.
  • print_stats (bool) If True, intermediate statistics will be printed.

integrate

FiniteFieldPolynomial.integrate(x: Expression) -> FiniteFieldPolynomial

Integrate the polynomial in x.

Examples

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

lcoeff

FiniteFieldPolynomial.lcoeff() -> FiniteFieldPolynomial

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

FiniteFieldPolynomial.monic() -> FiniteFieldPolynomial

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+3/2.

nterms

FiniteFieldPolynomial.nterms() -> int

Get the number of terms in the polynomial.

parse

FiniteFieldPolynomial.parse(
    input: str,
    vars: Sequence[str],
    prime: int,
    default_namespace: str | None = None,
) -> FiniteFieldPolynomial

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

Raises

  • ValueError: If the input is not a valid Symbolica polynomial.

quot_rem

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

Divide self by rhs, returning the quotient and remainder.

reduce

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

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

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

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

replace

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

Replace the variable x with a polynomial v.

Examples

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

resultant

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

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

simplify_algebraic_number

FiniteFieldPolynomial.simplify_algebraic_number(min_poly: FiniteFieldPolynomial) -> FiniteFieldPolynomial

Find the minimal polynomial for the algebraic number represented by this polynomial expressed in the number field defined by minimal_poly.

to_expression

FiniteFieldPolynomial.to_expression() -> Expression

Convert the polynomial to an expression.

to_galois_field

FiniteFieldPolynomial.to_galois_field(min_poly: FiniteFieldPolynomial) -> FiniteFieldPolynomial

Convert the coefficients of the polynomial to a Galois field defined by the minimal polynomial min_poly.

to_integer_polynomial

FiniteFieldPolynomial.to_integer_polynomial(symmetric_representation: bool = True) -> Polynomial

Convert the polynomial to a polynomial with integer coefficients.

to_latex

FiniteFieldPolynomial.to_latex() -> str

Convert the polynomial into a LaTeX string.

to_polynomial

FiniteFieldPolynomial.to_polynomial() -> Polynomial

Convert a Galois field polynomial to a simple finite field polynomial.