Class: SyMath::Definition::Trig
- Inherits:
-
Function
- Object
- Value
- SyMath::Definition
- Operator
- Function
- SyMath::Definition::Trig
- Defined in:
- lib/symath/definition/trig.rb
Constant Summary collapse
- @@trig_reductions =
{}
Instance Attribute Summary
Attributes inherited from Operator
Attributes inherited from SyMath::Definition
Class Method Summary collapse
Instance Method Summary collapse
- #reduce_sec_and_csc(f, off) ⇒ Object
- #reduce_sin_and_cos(f, off) ⇒ Object
- #reduce_tan_and_cot(f, off, sign) ⇒ Object
Methods inherited from Function
#check_pi_fraction, functions, init_builtin, #is_function?, #latex_format, #reduce_call
Methods inherited from Operator
#<=>, #==, #arity, #call, #compose_with_simplify, #dump, #evaluate_call, init_builtin, #initialize, #is_operator?, #latex_format, operators, #replace, #to_latex, #to_s, #validate_args
Methods inherited from SyMath::Definition
#<=>, #==, #arity, define, defined?, definitions, get, #hash, init_builtin, #initialize, #inspect, #is_constant?, #is_function?, #is_operator?, #reduce_call, #replace, #to_latex, #to_s, undefine, #variables
Methods inherited from Value
#*, #**, #+, #-, #-@, #/, #<, #<=, #<=>, #>, #>=, #^, #add, #base, compose_with_simplify, create, #deep_clone, #div, #dump, #evaluate, #exponent, #factors, #inspect, #inv, #is_divisor_factor?, #is_finite?, #is_nan?, #is_negative?, #is_negative_number?, #is_number?, #is_positive?, #is_prod_exp?, #is_sum_exp?, #is_unit_quaternion?, #is_zero?, #mul, #neg, #power, #reduce, #reduce_modulo_sign, #sign, #sub, #terms, #to_m, #type, #wedge
Methods included from Operation::Exterior
Methods included from Operation::Integration
#anti_derivative, #get_linear_constants, #int_constant, #int_failure, #int_function, #int_inv, #int_pattern, #int_power, #int_product, #int_sum, #integral_bounds
Methods included from Operation::Differential
#_d_wedge, #d, #d_failure, #d_fraction, #d_function, #d_function_def, #d_power, #d_product
Methods included from Operation
Methods included from Operation::DistributiveLaw
#combfrac_add_term, #combfrac_sum, #combine_fractions, #expand, #expand_product, #expand_single_pass, #factorize, #factorize_integer_poly, #factorize_simple, #has_fractional_terms?
Methods included from Operation::Normalization
#combine_factors, #compare_factors_and_swap, #normalize, #normalize_matrix, #normalize_power, #normalize_product, #normalize_single_pass, #normalize_sum, #order_product, #product_on_fraction_form, #reduce_constant_factors, #replace_combined_factors, #swap_factors
Methods included from Operation::Match
#build_assoc_op, #match, #match_assoc, #match_replace
Constructor Details
This class inherits a constructor from SyMath::Definition::Operator
Class Method Details
.initialize ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/symath/definition/trig.rb', line 7 def self.initialize() sqrt3 = fn(:sqrt, 3) sqrt2 = fn(:sqrt, 2) @@trig_reductions = { :sin_div6 => [ 0.to_m, 1.to_m/2, sqrt3/2, 1.to_m, sqrt3/2, 1.to_m/2, 0.to_m, -(1.to_m/2), -(sqrt3/2), -1.to_m, -(sqrt3/2), -(1.to_m/2)], :sin_div4 => [ 0.to_m, sqrt2/2, 1.to_m, sqrt2/2, 0.to_m, -(sqrt2/2), -1.to_m, -(sqrt2/2)], :sec_div6 => [ 1.to_m, 2.to_m*sqrt3/3, 2.to_m, nil, -2.to_m, -(2.to_m*sqrt3/2), -1.to_m, -(2.to_m*sqrt3/3), -2.to_m, nil, 2.to_m, 2.to_m*sqrt3/3], :sec_div4 => [ 1.to_m, sqrt2/2, nil, -(sqrt2/2), -1.to_m, -(sqrt2/2), nil, sqrt2/2], :tan_div6 => [0.to_m, sqrt3/3, sqrt3, nil, -sqrt3, -(sqrt3/3)], :tan_div4 => [0.to_m, 1.to_m, nil, -1.to_m], } end |
Instance Method Details
#reduce_sec_and_csc(f, off) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/symath/definition/trig.rb', line 76 def reduce_sec_and_csc(f, off) c, dc = check_pi_fraction(f.args[0], false) return f if c.nil? # Divisor is divisible by 6 if 6 % dc == 0 ret = @@trig_reductions[:sec_div6][(off*3 + c*6/dc) % 12] return ret.nil? ? f : ret end # Divisor is divisible by 4 if 4 % dc == 0 ret = @@trig_reductions[:sec_div4][(off*2 + c*4/dc) % 8] return ret.nil? ? f : ret end return f end |
#reduce_sin_and_cos(f, off) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/symath/definition/trig.rb', line 40 def reduce_sin_and_cos(f, off) c, dc = check_pi_fraction(f.args[0], false) return f if c.nil? # Divisor is divisible by 6 if 6 % dc == 0 return @@trig_reductions[:sin_div6][(off*3 + c*6/dc) % 12] end # Divisor is divisible by 4 if 4 % dc == 0 return @@trig_reductions[:sin_div4][(off*2 + c*4/dc) % 8] end return f end |
#reduce_tan_and_cot(f, off, sign) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/symath/definition/trig.rb', line 57 def reduce_tan_and_cot(f, off, sign) c, dc = check_pi_fraction(f.args[0], false) return f if c.nil? # Divisor is divisible by 6 if 6 % dc == 0 ret = @@trig_reductions[:tan_div6][(off*3 + sign*c*6/dc) % 6] return ret.nil? ? f : ret end # Divisor is divisible by 4 if 4 % dc == 0 ret = @@trig_reductions[:tan_div4][(off*2 + sign*c*4/dc) % 4] return ret.nil? ? f : ret end return f end |