Module: Algebra::PolynomialFactorization::Q

Included in:
Algebra::PolynomialFactorization
Defined in:
lib/algebra/polynomial-factor-int.rb

Instance Method Summary collapse

Instance Method Details

#contQObject



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'lib/algebra/polynomial-factor-int.rb', line 171

def contQ
  ns = collect{|q| q.numerator}
  ds = collect{|q| q.denominator}
  n = ns.first.gcd_all(* ns[1..-1])
  d = ds.first.lcm_all(* ds[1..-1])
#      ground.new(n, d)
  if ground == Rational #in 1.8.0, Rational.new is private.
    Rational(n, d)
  else
  raise "unknown gound type #{ground}" #20030606
  ground.new(n, d)
  end
end

#factorize_rationalObject



189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/algebra/polynomial-factor-int.rb', line 189

def factorize_rational
  pz = Algebra.Polynomial(Integer, "x")
  fz = ppQ(pz)
  a = fz.factorize
  u = ground.ground.unity # ground == Rational, ground.ground == Integer
  b = a.collect{|f, i|
  [f.project(self.class){|c, j|
#     ground.new
 ##in 1.8.0, Rational.new is private.
 ground == Rational ? Rational(c, u) : Rational(c, u)
    }, i]
  }
  contQ == ground.unity ? b : b.unshift([self.class.const(contQ), 1])
end

#ppQ(ring) ⇒ Object



185
186
187
# File 'lib/algebra/polynomial-factor-int.rb', line 185

def ppQ(ring)
  (self / contQ).project(ring){|c, j| c.to_i}
end