Class: Subtraction
Overview
Implements the subtraction operation in SymCalc
Instance Method Summary
collapse
Methods inherited from Equation
#*, #**, #+, #-, #/, #coerce, #derivative, #eval, #inspect, #simplify, #sub, #to_s
Constructor Details
#initialize(lside, rside) ⇒ Subtraction
407
408
409
410
|
# File 'lib/symcalc.rb', line 407
def initialize lside, rside
@lside = lside
@rside = rside
end
|
Instance Method Details
#__derivative__(variable: nil) ⇒ Object
420
421
422
|
# File 'lib/symcalc.rb', line 420
def __derivative__ variable: nil
return @lside.derivative(variable: variable) - @rside.derivative(variable: variable)
end
|
#__eval__(var_hash) ⇒ Object
416
417
418
|
# File 'lib/symcalc.rb', line 416
def __eval__ var_hash
return @lside.eval(var_hash) - @rside.eval(var_hash)
end
|
#__get_m_elements__(el_hash) ⇒ Object
424
425
426
427
428
429
430
431
|
# File 'lib/symcalc.rb', line 424
def __get_m_elements__ el_hash
if el_hash.keys.include? self
el_hash[self] += 1
else
el_hash[self] = 1
end
return el_hash
end
|
#__simplify__ ⇒ Object
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
|
# File 'lib/symcalc.rb', line 433
def __simplify__
@lside = @lside.__simplify__
@rside = @rside.__simplify__
if (@lside.is_a? EquationValue) && (@rside.is_a? EquationValue)
return EquationValue.new((@lside - @rside).eval(Hash.new))
elsif @rside == EquationValue.new(0)
return @lside
elsif @lside == EquationValue.new(0)
return -1 * @rside
elsif @lside == @rside
return EquationValue.new(0)
else
return self
end
end
|
#__sub__(original, replacement) ⇒ Object
454
455
456
457
|
# File 'lib/symcalc.rb', line 454
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
450
451
452
|
# File 'lib/symcalc.rb', line 450
def all_variables
return (@lside.all_variables + @rside.all_variables).uniq
end
|
#display ⇒ Object
412
413
414
|
# File 'lib/symcalc.rb', line 412
def display
return "(#{@lside.display}) - (#{@rside.display})"
end
|