Class: SyMath::Definition::Int
- Inherits:
-
Operator
- Object
- Value
- SyMath::Definition
- Operator
- SyMath::Definition::Int
- Defined in:
- lib/symath/definition/int.rb
Instance Attribute Summary
Attributes inherited from Operator
Attributes inherited from SyMath::Definition
Instance Method Summary collapse
- #description ⇒ Object
- #evaluate_call(c) ⇒ Object
- #get_variable(exp) ⇒ Object
-
#initialize ⇒ Int
constructor
A new instance of Int.
- #to_latex(args) ⇒ Object
- #validate_args(e) ⇒ Object
Methods inherited from Operator
#<=>, #==, #arity, #call, #compose_with_simplify, #dump, init_builtin, #is_operator?, #latex_format, operators, #replace, #to_s
Methods inherited from SyMath::Definition
#<=>, #==, #arity, define, defined?, definitions, get, #hash, init_builtin, #inspect, #is_constant?, #is_function?, #is_operator?, #reduce_call, #replace, #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 ⇒ Int
Returns a new instance of Int.
6 7 8 |
# File 'lib/symath/definition/int.rb', line 6 def initialize() super(:int) end |
Instance Method Details
#description ⇒ Object
10 11 12 |
# File 'lib/symath/definition/int.rb', line 10 def description() return 'int(f, a, b) - integral of f [from a to b]' end |
#evaluate_call(c) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/symath/definition/int.rb', line 35 def evaluate_call(c) exp = c.args[0] var = get_variable(exp) a = c.args[1] b = c.args[2] exp = exp.evaluate if a.nil? ret = exp.normalize.anti_derivative(var) return ret.nil? ? nil : ret + :C.to_m else int = exp.normalize.anti_derivative(var) # TODO: Setting for evaluating the bounds expression? return op(:bounds, lmd(int, var.undiff), a, b).evaluate end end |
#get_variable(exp) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/symath/definition/int.rb', line 23 def get_variable(exp) if exp.is_a?(SyMath::Operator) and exp.definition.is_function? and exp.definition.args.length > 0 v = exp.definition.args[0] else v = (exp.variables)[0].to_m end return v.to_d end |
#to_latex(args) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/symath/definition/int.rb', line 53 def to_latex(args) if !args args = @args end if args[0].is_sum_exp? exp = "\\left(#{args[0].to_latex}\\right)" else exp = args[0].to_latex end var = get_variable(args[0]) a = args[1] b = args[2] if a.nil? return "\\int #{exp}\\,#{var.to_latex}" else return "\\int_{#{a.to_latex}}^{#{b.to_latex}} #{exp}\\,#{var.to_latex}" end end |
#validate_args(e) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/symath/definition/int.rb', line 14 def validate_args(e) a = e.args[1] b = e.args[2] if (!a.nil? and b.nil?) or (a.nil? and !b.nil?) raise "A cannot be defined without b and vica versa." end end |