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) -> FiniteFieldPolynomialAdd two polynomials self and rhs, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__contains__
FiniteFieldPolynomial.__contains__(var: Expression) -> boolCheck if the polynomial contains the given variable.
Parameters
var(Expression) The variable whose presence should be tested.
__copy__
FiniteFieldPolynomial.__copy__() -> FiniteFieldPolynomialCopy the polynomial.
__eq__
FiniteFieldPolynomial.__eq__(rhs: Polynomial | int) -> boolCheck if two polynomials are equal.
Parameters
rhs(Polynomial | int) The right-hand-side operand.
__floordiv__
FiniteFieldPolynomial.__floordiv__(rhs: Polynomial) -> PolynomialDivide the polynomial self by rhs, rounding down, returning the result.
Parameters
rhs(Polynomial) The right-hand-side operand.
__mod__
FiniteFieldPolynomial.__mod__(rhs: FiniteFieldPolynomial) -> FiniteFieldPolynomialCompute the remainder of the division of self by rhs.
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.
__mul__
FiniteFieldPolynomial.__mul__(rhs: FiniteFieldPolynomial | int) -> FiniteFieldPolynomialMultiply two polynomials self and rhs, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__ne__
FiniteFieldPolynomial.__ne__(rhs: Polynomial | int) -> boolCheck if two polynomials are not equal.
Parameters
rhs(Polynomial | int) The right-hand-side operand.
__neg__
FiniteFieldPolynomial.__neg__() -> FiniteFieldPolynomialNegate the polynomial.
__pow__
FiniteFieldPolynomial.__pow__(exp: int) -> FiniteFieldPolynomialRaise the polynomial to the power of exp, returning the result.
Parameters
exp(int) The exponent.
__radd__
FiniteFieldPolynomial.__radd__(rhs: FiniteFieldPolynomial | int) -> FiniteFieldPolynomialAdd two polynomials self and rhs, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__rmul__
FiniteFieldPolynomial.__rmul__(rhs: FiniteFieldPolynomial | int) -> FiniteFieldPolynomialMultiply two polynomials self and rhs, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__rsub__
FiniteFieldPolynomial.__rsub__(rhs: FiniteFieldPolynomial | int) -> FiniteFieldPolynomialSubtract polynomials self from rhs, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__str__
FiniteFieldPolynomial.__str__() -> strPrint the polynomial in a human-readable format.
__sub__
FiniteFieldPolynomial.__sub__(rhs: FiniteFieldPolynomial | int) -> FiniteFieldPolynomialSubtract polynomials rhs from self, returning the result.
Parameters
rhs(FiniteFieldPolynomial | int) The right-hand-side operand.
__truediv__
FiniteFieldPolynomial.__truediv__(rhs: FiniteFieldPolynomial) -> FiniteFieldPolynomialDivide the polynomial self by rhs if possible, returning the result.
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.
adjoin
FiniteFieldPolynomial.adjoin(
b: FiniteFieldPolynomial,
new_symbol: Expression | None = 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.
Parameters
b(FiniteFieldPolynomial) The finite-field polynomial that defines the extension to adjoin.new_symbol(Expression | None) The symbol chosen for the adjoined generator.
coefficient_list
FiniteFieldPolynomial.coefficient_list(xs: Expression | Sequence[Expression] | None = 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)Parameters
xs(Expression | Sequence[Expression] | None) The variables with respect to which coefficients should be listed.
contains
FiniteFieldPolynomial.contains(var: Expression) -> boolCheck if the polynomial contains the given variable.
Parameters
var(Expression) The variable whose presence should be tested.
degree
FiniteFieldPolynomial.degree(var: Expression) -> intGet the degree of the polynomial in var.
Parameters
var(Expression) The variable whose degree should be returned.
derivative
FiniteFieldPolynomial.derivative(x: Expression) -> FiniteFieldPolynomialTake a derivative in x.
Examples
from symbolica import *
x = S('x')
p = E('x^2+2').to_polynomial()
print(p.derivative(x))Parameters
x(Expression) The variable with respect to which to differentiate.
evaluate
FiniteFieldPolynomial.evaluate(input: Sequence[int]) -> intEvaluate the polynomial at point input.
Examples
from symbolica import *
P('x*y+2*x+x^2', modulus=5).evaluate([2, 3])Yields 4.
Parameters
input(Sequence[int]) The input value.
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).
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.
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: str | None = 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: int | None = None,
show_namespaces: bool = False,
hide_namespace: str | None = None,
include_attributes: bool = False,
max_terms: int | None = None,
custom_print_mode: int | None = None,
) -> strConvert 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.
Parameters
mode(PrintMode) The mode that controls how the input is interpreted or formatted.max_line_length(int | None) The preferred maximum line length before wrapping.indentation(int) The number of spaces used for wrapped lines.fill_indented_lines(bool) Whether wrapped lines should be padded to the configured indentation.terms_on_new_line(bool) Whether wrapped output should place terms on separate lines.color_top_level_sum(bool) Whether top-level sums should be colorized.color_builtin_symbols(bool) Whether built-in symbols should be colorized.bracket_level_colors(Sequence[int] | None) The colors assigned to successive nested bracket levels.print_ring(bool) Whether the coefficient ring should be included in the printed output.symmetric_representation_for_finite_field(bool) Whether finite-field elements should be printed using symmetric representatives.explicit_rational_polynomial(bool) Whether rational polynomials should be printed explicitly as numerator and denominator.number_thousands_separator(str | None) The separator inserted between groups of digits in printed integers.multiplication_operator(str) The string used to print multiplication.double_star_for_exponentiation(bool) Whether exponentiation should be printed as**instead of^.square_brackets_for_function(bool) Whether function calls should be printed with square brackets.function_brackets(tuple[str, str]) The opening and closing brackets used when printing function arguments.num_exp_as_superscript(bool) Whether small integer exponents should be printed as superscripts.precision(int | None) The decimal precision used when printing numeric coefficients.show_namespaces(bool) Whether namespaces should be included in the formatted output.hide_namespace(str | None) A namespace prefix to omit from printed symbol names.include_attributes(bool) Whether symbol attributes should be included in the printed output.max_terms(int | None) The maximum number of terms to print before truncating the output.custom_print_mode(int | None) A custom print-mode identifier passed through to custom print callbacks.
gcd
FiniteFieldPolynomial.gcd(*rhs: FiniteFieldPolynomial) -> FiniteFieldPolynomialCompute the greatest common divisor (GCD) of two or more polynomials.
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.
get_minimal_polynomial
FiniteFieldPolynomial.get_minimal_polynomial() -> FiniteFieldPolynomialGet the minimal polynomial of the algebraic extension.
get_modulus
FiniteFieldPolynomial.get_modulus() -> intGet 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) IfTrue, reverse graded lexicographical ordering is used, otherwise the ordering is lexicographical.print_stats(bool) IfTrue, intermediate statistics will be printed.
integrate
FiniteFieldPolynomial.integrate(x: Expression) -> FiniteFieldPolynomialIntegrate the polynomial in x.
Examples
from symbolica import *
x = S('x')
p = E('x^2+2').to_polynomial()
print(p.integrate(x))Parameters
x(Expression) The variable with respect to which to integrate.
lcoeff
FiniteFieldPolynomial.lcoeff() -> FiniteFieldPolynomialGet the leading coefficient.
Examples
from symbolica import Expression as E
p = E('3x^2+6x+9').to_polynomial().lcoeff()
print(p) # 3monic
FiniteFieldPolynomial.monic() -> FiniteFieldPolynomialGet 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()) # x^2+1/2*x+3/2nterms
FiniteFieldPolynomial.nterms() -> intGet the number of terms in the polynomial.
parse
FiniteFieldPolynomial.parse(
input: str,
vars: Sequence[str],
prime: int,
default_namespace: str | None = None,
) -> FiniteFieldPolynomialParse 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)Parameters
input(str) The input value.vars(Sequence[str]) The variables treated as polynomial variables, in the given order.prime(int) The prime modulus of the finite field.default_namespace(str | None) The namespace assumed for unqualified symbols during parsing.
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.
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.
reduce
FiniteFieldPolynomial.reduce(
gs: Sequence[Polynomial],
grevlex: bool = True,
) -> FiniteFieldPolynomialCompletely 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
Parameters
gs(Sequence[Polynomial]) The polynomials that define the reducing set.grevlex(bool) Whether graded reverse lexicographic ordering should be used.
reorder
FiniteFieldPolynomial.reorder(vars: Sequence[Expression]) -> NoneReorder the polynomial in-place to use the given variable order.
Parameters
vars(Sequence[Expression]) The variables treated as polynomial variables, in the given order.
replace
FiniteFieldPolynomial.replace(
x: Expression,
v: FiniteFieldPolynomial | int,
) -> FiniteFieldPolynomialReplace 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)Parameters
x(Expression) The variable to replace.v(FiniteFieldPolynomial | int) The polynomial or scalar value that should replacex.
resultant
FiniteFieldPolynomial.resultant(
rhs: FiniteFieldPolynomial,
var: Expression,
) -> FiniteFieldPolynomialCompute the resultant of two polynomials with respect to the variable var.
Parameters
rhs(FiniteFieldPolynomial) The right-hand-side operand.var(Expression) The variable with respect to which the resultant is computed.
simplify_algebraic_number
FiniteFieldPolynomial.simplify_algebraic_number(min_poly: FiniteFieldPolynomial) -> FiniteFieldPolynomialFind the minimal polynomial for the algebraic number represented by this polynomial expressed in the number field defined by minimal_poly.
Parameters
min_poly(FiniteFieldPolynomial) The minimal polynomial that defines the algebraic extension.
to_expression
FiniteFieldPolynomial.to_expression() -> ExpressionConvert the polynomial to an expression.
to_galois_field
FiniteFieldPolynomial.to_galois_field(min_poly: FiniteFieldPolynomial) -> FiniteFieldPolynomialConvert the coefficients of the polynomial to a Galois field defined by the minimal polynomial min_poly.
Parameters
min_poly(FiniteFieldPolynomial) The minimal polynomial that defines the algebraic extension.
to_integer_polynomial
FiniteFieldPolynomial.to_integer_polynomial(symmetric_representation: bool = True) -> PolynomialConvert the polynomial to a polynomial with integer coefficients.
Parameters
symmetric_representation(bool) Whether finite-field coefficients should use symmetric integer representatives.
to_latex
FiniteFieldPolynomial.to_latex() -> strConvert the polynomial into a LaTeX string.
to_polynomial
FiniteFieldPolynomial.to_polynomial() -> PolynomialConvert a Galois field polynomial to a simple finite field polynomial.