Class: Multiplication
Overview
Implements the multiplication operation in SymCalc
Instance Method Summary
collapse
Methods inherited from Equation
#*, #**, #+, #-, #/, #coerce, #derivative, #eval, #inspect, #simplify, #to_s
Constructor Details
Returns a new instance of Multiplication.
437
438
439
440
|
# File 'lib/symcalc.rb', line 437
def initialize lside, rside
@lside = lside
@rside = rside
end
|
Instance Method Details
#__derivative__(variable: nil) ⇒ Object
450
451
452
|
# File 'lib/symcalc.rb', line 450
def __derivative__ variable: nil
return @lside.derivative(variable: variable) * @rside + @lside * @rside.derivative(variable: variable)
end
|
#__eval__(var_hash) ⇒ Object
446
447
448
|
# File 'lib/symcalc.rb', line 446
def __eval__ var_hash
return @lside.eval(var_hash) * @rside.eval(var_hash)
end
|
#__get_m_elements__(el_hash) ⇒ Object
476
477
478
479
480
|
# File 'lib/symcalc.rb', line 476
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
|
# File 'lib/symcalc.rb', line 454
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
|
#all_variables ⇒ Object
482
483
484
|
# File 'lib/symcalc.rb', line 482
def all_variables
return (@lside.all_variables + @rside.all_variables).uniq
end
|
#display ⇒ Object
442
443
444
|
# File 'lib/symcalc.rb', line 442
def display
return "(#{@lside.display}) * (#{@rside.display})"
end
|