Class: Multiplication
Overview
Implements the multiplication operation in SymCalc
Instance Method Summary
collapse
Methods inherited from Equation
#*, #**, #+, #-, #/, #coerce, #derivative, #eval, #inspect, #simplify, #sub, #to_s
Constructor Details
Returns a new instance of Multiplication.
462
463
464
465
|
# File 'lib/symcalc.rb', line 462
def initialize lside, rside
@lside = lside
@rside = rside
end
|
Instance Method Details
#__derivative__(variable: nil) ⇒ Object
475
476
477
|
# File 'lib/symcalc.rb', line 475
def __derivative__ variable: nil
return @lside.derivative(variable: variable) * @rside + @lside * @rside.derivative(variable: variable)
end
|
#__eval__(var_hash) ⇒ Object
471
472
473
|
# File 'lib/symcalc.rb', line 471
def __eval__ var_hash
return @lside.eval(var_hash) * @rside.eval(var_hash)
end
|
#__get_m_elements__(el_hash) ⇒ Object
501
502
503
504
505
|
# File 'lib/symcalc.rb', line 501
def __get_m_elements__ el_hash
el_hash = @lside.__get_m_elements__(el_hash)
el_hash = @rside.__get_m_elements__(el_hash)
return el_hash
end
|
#__simplify__ ⇒ Object
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
|
# File 'lib/symcalc.rb', line 479
def __simplify__
@lside = @lside.__simplify__
@rside = @rside.__simplify__
if (@lside == EquationValue.new(0)) || (@rside == EquationValue.new(0))
return EquationValue.new 0
elsif @lside == EquationValue.new(1)
return @rside
elsif @rside == EquationValue.new(1)
return @lside
elsif @rside.is_a? EquationValue and @lside.is_a? EquationValue
calculated = @rside.value * @lside.value
if calculated.to_s.size <= 6
return to_equation(calculated)
else
return self
end
else
return self
end
end
|
#__sub__(original, replacement) ⇒ Object
511
512
513
514
|
# File 'lib/symcalc.rb', line 511
def __sub__ original, replacement
return to_equation(replacement) if self == to_equation(original)
return @lside.__sub__(original, replacement) * @rside.__sub__(original, replacement)
end
|
#all_variables ⇒ Object
507
508
509
|
# File 'lib/symcalc.rb', line 507
def all_variables
return (@lside.all_variables + @rside.all_variables).uniq
end
|
#display ⇒ Object
467
468
469
|
# File 'lib/symcalc.rb', line 467
def display
return "(#{@lside.display}) * (#{@rside.display})"
end
|