1 # -*- coding: utf-8 -*-
10 # [_term_number_] 生成する項の数 (ex. 2)
11 # [_operators_] 使用する演算子 (ex. %w[ + - * div ]
12 # [numerator_term_min] 分子の項数の最小値 (ex. 1)
13 # [numerator_term_max] 分子の項数の最大値 (ex. 1)
14 # [denominator_term_min] 分母の項数の最大値 (ex. 1)
15 # [denominator_term_max] 分母の項数の最大値 (ex. 1)
16 # [factor_minus] 真なら整数部に負の数を使う (ex. false)
17 # [factor_min] 整数部の最小値 (ex. 1)
18 # [factor_max] 整数部の最大値 (ex. 9)
20 class FractionalExpressionArithmetic < Arithmetic
22 DEFAULT_OPERATORS = %w[+ - * div]
28 # TODO: I wanna set option for expression order
30 option :numerator_term_min, 1
31 option :numerator_term_max, 1
32 option :denominator_term_min, 1
33 option :denominator_term_max, 1
34 option :factor_minus, false
43 @x ||= options[:x].sample
49 result << '(' if options[:denominator_term_max] > 1
50 result << denominator_part(x)
51 result << ')' if options[:denominator_term_max] > 1
53 result << '(' if options[:numerator_term_max] > 1
54 result << "#{numerator_part(x)}"
55 result << ')' if options[:numerator_term_max] > 1
63 def denominator_part(x)
69 term_number = term_number(position)
71 return create_integer(
74 options[:factor_minus]).to_s
77 factor = factor(options, 'factor')
78 result << single(1, factor, x)
83 def term_number(position)
85 options[:"#{position}_term_min"],
86 options[:"#{position}_term_max"],