1 # -*- coding: utf-8 -*-
10 # [_order_min_] 次数の最小値 (ex. 2)
11 # [_order_max_] 次数の最大値 (ex. 2)
12 # [_x_] 使用する変数 (ex. ['x'] / [['x', 'y']])
13 # [_factor_minus_] 真なら分母の整数部に負の数を使用する (ex. true)
14 # [_factor_min_] 分母の整数部の最小値 (ex. 0)
15 # [_factor_max_] 分母の整数部の最大値 (ex. 100)
16 # [_coefficient_minus_] 真なら分母の変数部に負の数を使用する (ex. true)
17 # [_coefficient_min_] 分母の変数部の最小値 (ex. 0)
18 # [_coefficient_max_] 分母の変数部の最大値 (ex. 100)
19 # [_numerator_minus_] 真なら分子に負の数を使用するか (ex. true)
20 # [_numerator_min_] 分子の最小値 (ex. 0)
21 # [_numerator_max_] 分子の最大値 (ex. 100)
23 class PartialFractionExpansion < Base
31 :order_min => 2, :order_max => 2, :x => ['x'],
32 :factor_minus => false, :factor_min => 1, :factor_max => 100,
33 :coefficient_minus => false, :coefficient_min => 1, :coefficient_max => 1,
34 :numerator_minus => false, :numerator_min => 1, :numerator_max => 1,
36 targets = %w[order factor coefficient numerator]
37 options = min_max_order(options(defaults), targets)
41 def partial_fraction(options)
42 numerator_part = create_integer(options[:numerator_min], options[:numerator_max], options[:numerator_minus])
43 denominator_part = expansion(options)
44 "#{numerator_part}/#{denominator_part}"
47 def expression(options)
49 result << partial_fraction(options)
53 def expansion(options)
55 order = create_integer(options[:order_min], options[:order_max], false)
56 x = options[:x].sample
58 coefficient = factor(options, 'coefficient')
59 factor = factor(options)
60 result << single(coefficient, factor, x)