# == r, p, q について
# r, p, q を用いて 係数 a, b, c を生成します.
# それぞれ以下の式で求めることができます.
- # - a = r^2 / gcd(r, p, q)
- # - b = -2pr / gcd(r, p, q)
- # - c = (p^2 - q) / gcd(r, p, q)
- #
+ # - a' = r^2
+ # - b' = -2pr
+ # - c' = (p^2 - q)
+ # - gcd = GCD(a', b', c')
+ # とすると
+ # - a = a' / gcd
+ # - b = b' / gcd
+ # - c = c' / gcd
#
class QuadraticEquation < Base
def generate_r
min = [1, options[:r_min]].max
- create_integer(min, options[:r_max], false) {|ra|
- !Prime.prime?(ra)
- }
+ create_integer(min, options[:r_max], false)
end
def generate_p
- create_integer(options[:p_min], options[:p_max], options[:p_minus]) {|pa|
- !Prime.prime?(pa)
- }
+ create_integer(options[:p_min], options[:p_max], options[:p_minus])
end
def rational_q
min = [0, options[:q_min]].max
squares = squares(options[:q_min], options[:q_max])
create_integer(min, options[:q_max], false) {|qa|
- !squares.include?(qa) &&
- !Prime.prime?(qa)
+ !squares.include?(qa)
}
end
def imaginary_q
min = [1, options[:q_min]].max
- -create_integer(min, options[:q_max], false) {|qa|
- !Prime.prime?(qa)
- }
+ -create_integer(min, options[:q_max], false)
end
def squares(min, max)
}
subject.__send__(:options=, @options)
@squares = subject.__send__(:squares, @options[:q_min], @options[:q_max])
- @prime_numbers = (@options[:q_min]..@options[:q_max]).to_a.select {|i| Prime.prime?(i) }
end
it { (@options[:r_min]..@options[:r_max]).should include(subject.__send__(:generate_r)) }
subject.__send__(:options=, subject.__send__(:options).merge(:p_minus => false))
end
- it { @squares.should include(subject.__send__(:rational_q)) }
- it { @squares.should_not include(subject.__send__(:irrational_q)) }
- it { @prime_numbers.should_not include(subject.__send__(:irrational_q)) }
- it { (@options[:q_min]..@options[:q_max]).should include(subject.__send__(:irrational_q)) }
- it { @prime_numbers.should_not include(subject.__send__(:imaginary_q)) }
- it { (@options[:q_min]..@options[:q_max]).should include(-subject.__send__(:imaginary_q)) }
+ it { @squares.should include(subject.__send__(:rational_q)) }
+ it { @squares.should_not include(subject.__send__(:irrational_q)) }
+ it { (@options[:q_min]..@options[:q_max]).should include(subject.__send__(:irrational_q)) }
+ it { (@options[:q_min]..@options[:q_max]).should include(-subject.__send__(:imaginary_q)) }
end
end
end
@params = subject.__send__(:generate_coefficients, r, p, q)
end
it { discriminant(*@params).should > 0 }
+ it { Math.sqrt(discriminant(*@params)).should_not be_an_instance_of(Fixnum) }
end
context 'rational' do
@params = subject.__send__(:generate_coefficients, r, p, q)
end
it { discriminant(*@params).should > 0 }
+ it { Math.sqrt(discriminant(*@params)).should be_an_instance_of(Fixnum) }
end
context 'imaginary' do