Polynomial / PolynomialFactorization
(Class of Polynomial Ring)
This class expresses the polynomial ring over arbitrary ring. For creating the actual class, use the class method Polynomial.create or Polynomial, giving the coefficient ring.
Polynomial(ring [, obj0 , obj1 [, ...]])
Same as Polynomial.create(ring, obj0[, obj1 [, ...]])
Polynomial.create(ring, obj0[, obj1[, ...]])
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 = 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 = 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
This P
is equal to
Polynomial.create( Polynomial.create( Polynomial.create( Integer, "x"), "y"), "z")
and the last variable z is the primary variable.
Polynomial.var
Returns the (primary) variable of the polynomial ring.
Polynomial.vars
Returns the array of the variables of the polynomial rings, collecting recursively.
Polynomial.mvar
Same as Polynomial.vars.
Polynomial.variable
Returns the object which expresses the (primary) variable of the polynomial ring.
Polynomial.variables
Returns the array of the objects which express the variables of the polynomial rings, collecting recursively.
Polynomial.indeterminate(obj)
Returns the variable expressed by obj.
Polynomial.monomial([n])
Returns the monomial of degree n.
Example:
P = Polynomial(Integer, "x") P.monomial(3) #=> x^3
Polynomial.const(c)
Returns the constant value c.
Example:
P = Polynomial(Integer, "x") P.const(3) #=> 3 P.const(3).type #=> P
Polynomial.zero
Returns the zero.
Polynomial.unity
Returns the unity.
var
Same as Polynomial.var.
variable
Same as Polynomial.variable.
each(&b)
Iterates of coefficients in the ascendant power series.
Example:
P = Polynomial(Integer, "x") x = P.var (x**3 + 2*x**2 + 4).each do |c| p c #=> 4, 0, 2, 1 end
reverse_each(&b)
Iterates of coefficients in the descendent power series.
Example:
P = Polynomial(Integer, "x") x = P.var (x**3 + 2*x**2 + 4).reverse_each do |c| p c #=> 1, 2, 0, 4 end
[n]
Returns the coefficient of degree n.
[n] = v
Sets the coefficient of degree n into v.
monomial
Same as Polynomial.monomial.
monomial?
Returns true if self is a monomial.
zero?
Returns true if self is the zero.
zero
Returns the zero.
unity
Returns the unity.
==(other)
Returns true if self is equal to other.
<=>(other)
Returns positive if self is greater than other.
+(other)
Returns the sum of self and other.
-(other)
Returns the difference of self from other.
*(other)
Returns the product of self and other.
**(n)
Returns the n-th power of self.
/(other)
Returns the quotient of self by other. Same as div.
divmod(other)
Returns the array [quotient, remainder] by other.
div(other)
Returns the quotient of self by other.
Same as divmod(other).first
.
%(other)
Returns the remainder of self by other.
Same as divmod(other).last
.
divide?(other)
Returns true if self is divisible by other.
Same as divmod(other).last == zero?
.
deg
Returns the degree.
Example:
P = Polynomial(Integer, "x") x = P.var (5*x**3 + 2*x + 1).deg #=> 3
lc
Returns the leading coefficient.
Example:
(5*x**3 + 2*x + 1).lc #=> 5
lm
Returns the leading monomial.
Example:
(5*x**3 + 2*x + 1).lm #=> x**3
lt
Returns the leading term).
Same as lc * lm
.
Example:
(5*x**3 + 2*x + 1).lt #=> 5*x**3
rt
Returns the rest term, which has the same value as self - lt
.
Example:
(5*x**3 + 2*x + 1).rt #=> 2*x + 1
monic
Returns the polynomial, which corrected the maximum order coefficient in 1.
Same as self / lc
.
cont
Returns the content (i.e. L.C.M of coefficients).
pp
Returns the primitive part.
Same asself / cont
.
to_s
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
derivate
Return the derivative.
Example:
(5*x**3 + 2*x + 1).derivate #=> 15*x**2 + 2
sylvester_matrix(other)
Return the Sylvester matrix of self and other.
It is required that require "matrix"
.
resultant(other)
Return the resultant of self with other
It is required that require "matrix"
.
project(ring[, obj]){|c, n| ... }
Returns the sum of values of c*x**n
replacing by the evaluation
of ... for each coefficient c of degree n.
If obj is omitted, that is assumed to be ring.var
.
Example:
require "polynomial" require "rational" P = Polynomial(Integer, "x") PQ = Polynomial(Rational, "y") x = P.var f = 5*x**3 + 2*x + 1 p f.evaluate(-1) #=> -6 p f.convert_to(PQ) #=> 5y^3 + 2y + 1 p f.project(PQ) {|c, n| Rational(c) / (n + 1)} #=> 5/4y^3 + y + 1
evaluate(obj)
Returns the value of self at obj.
This is equivalent to project(ground, obj){|c, n| c}
.
convert_to(ring)
Returns the polynomial the one converted on ring.
This is equivalent to project(ring){|c, n| c}
.
(Module of Factorization)
The module of factorization of polynomials.
polynomial-factor.rb
sqfree
Returns the square free parts.
sqfree?
Returns true if square free.
irreducible?
Returns true if irreducible
factorize
Returns the factorization.
The following type can be factorized: