Class: SyMath::Definition::Exp
- Inherits:
-
Function
- Object
- Value
- SyMath::Definition
- Operator
- Function
- SyMath::Definition::Exp
- Defined in:
- lib/symath/definition/exp.rb
Instance Attribute Summary
Attributes inherited from Operator
Attributes inherited from SyMath::Definition
Instance Method Summary collapse
- #description ⇒ Object
-
#initialize ⇒ Exp
constructor
A new instance of Exp.
- #reduce_call(call) ⇒ Object
Methods inherited from Function
#check_pi_fraction, functions, init_builtin, #is_function?, #latex_format
Methods inherited from Operator
#<=>, #==, #arity, #call, #compose_with_simplify, #dump, #evaluate_call, init_builtin, #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, #inspect, #is_constant?, #is_function?, #is_operator?, #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, initialize, #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, initialize
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
#initialize ⇒ Exp
Returns a new instance of Exp.
5 6 7 |
# File 'lib/symath/definition/exp.rb', line 5 def initialize() super(:exp) end |
Instance Method Details
#description ⇒ Object
9 10 11 |
# File 'lib/symath/definition/exp.rb', line 9 def description() return 'exp(x) - exponential function (e**x)' end |
#reduce_call(call) ⇒ Object
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/symath/definition/exp.rb', line 13 def reduce_call(call) arg = call.args[0] if arg.is_nan? return :nan.to_m end if arg == 0 return 1.to_m elsif arg == 1 return :e.to_m end if arg.is_finite? == false if SyMath.setting(:complex_arithmetic) return :nan.to_m else if arg.is_positive? == true return :oo.to_m else return 0.to_m end end end if SyMath.setting(:complex_arithmetic) ret = 1.to_m arg.terms.each do |t| if t.is_a?(SyMath::Minus) t = t.args[0] minus = true else minus = false end if t.class.method_defined?('definition') and t.definition.is_a?(SyMath::Definition::Ln) # exp(ln(c)) = c t2 = t.args[0] else # Euler's formula c, dc = check_pi_fraction(t, true) if !c.nil? if dc == 1 c *= 2 elsif dc != 2 # Not reducible return call end case c % 4 when 0 t2 = 1 when 1 t2 = :i when 2 t2 = -1 when 3 t2 = -:i end else # Cannot reduce return call end end ret = minus ? ret/t2 : ret*t2 end return ret else ret = 1.to_m call.args[0].terms.each do |t| if t.is_a?(SyMath::Minus) t = t.args[0] minus = true else minus = false end # exp(ln(c)) = c for positive c if t.class.method_defined?('definition') and t.definition.is_a?(SyMath::Definition::Ln) if t.args[0].is_number? ret = minus ? ret/t.args[0] : ret*t.args[0] next end end # Cannot reduce return call end return ret end end |