This class expresses the polynomial ring over arbitrary ring.
For creating the actual class, use the class method ::create
or Algebra.Polynomial, giving the coefficient ring.
Creates a polynomial ring class over the coefficient ring
expressed by the class: ring.
The objects designated in obj0, obj1, ... express the variables,
and the polynomial ring on the polynomial ring is recursively created,
if this is multiple.
The value of this method is the subclass of Polynomial class.
This subclass has the class methods: ground, var,
and vars, which return the coefficient ring ring,
the primary variable object(the latest one) and all variables,
respectively.
The objects obj0, obj1, ... are to utilize for the name
(the value of to_s ) of the variable.
Example: Polynomial ring over Integer
require "polynomial"
P = Algebra::Polynomial.create(Integer, "x")
x = P.var
p((x + 1)**100) #=> x^100 + 100x^99 + ... + 100x + 1
p P.ground #=> integer
Example: Multi variate Polynomial ring over Integer
require "polynomial"
P = Algebra::Polynomial.create(Integer, "x", "y", "z")
x, y, z = P.vars
p((-x + y + z)*(x + y - z)*(x - y + z))
#=> -z^3 + (y + x)z^2 + (y^2 - 2xy + x^2)z - y^3 + xy^2 + x^2y - x^3
p P.var #=> z
Returns the expression in strings.
Use display_type in order to change the display format.
The possible value of display_type is
:norm(default) and :code.
Example:
P = Polynomial(Integer, "x")
x = P.var
p 5*x**3 + 2*x + 1 #=>5x^3 + 2x + 1
P.display_type = :code
p 5*x**3 + 2*x + 1 #=> 5*x**3 + 2*x + 1
Returns the value of self at obj.
This is equivalent to project(ground, obj){|c, n| c} .
Example:
require "polynomial"
P = Algebra::Polynomial(Integer, "x")
x = P.var
f = x**3 - 3*x**2 + 1
p f.evaluate(-1) #=> -3 (in Integer)
p f.evaluate(x + 1) #=> x^3 - 3x - 1 (in P)
Here the elements are:
field the mimimal splitting field of poly,
def_polys the irreducible polynomial needed for the splitting,
facts the linear factors of poly over field,
roots the roots of poly and
addelems the elements to extend the base field to field.
fac0 makes the factorization fast. (facts and fact0
are the instance of Algebra::Factors).
Generally, field is the object of
AlgebraicExtensionField.
If self is splitted linearlly,
that is the ground ring own.
Example:
require "algebra"
PQ = Polynomial(Rational, "x")
x = PQ.var
f = x**4 + 2
field, def_polys, facts, roots, addelems = f.decompose
p def_polys #=> [a^4 + 2, b^2 + a^2]
p facts #=> (x - a)(x + a)(x - b)(x + b)
p roots #=> [a, b, a, -b]
p addelems #=> [a, b]
fp = Polynomial(field, "x")
x = fp.var
facts1 = Factors.new(facts.collect{|g, n| [g.call(x), n]})
p facts1.pi == f.convert_to(fp) #=> true