class CAS::Diff

**Difference basic operation**. It's a binary operation. This cannot be implemented as a n-ary op, thus will not be changed

Public Instance Methods

call(f) click to toggle source

Same as `CAS::Op`

# File lib/functions/fnc-base.rb, line 31
def call(f)
  CAS::Help.assert(f, Hash)

  return @x.call(f).overloaded_minus(@y.call(f))
end
diff(v) click to toggle source

Performs the difference between two `CAS::Op`s

“`

d

—- (f(x) - g(x)) = f'(x) - g'(x)

dx

“`

* **argument**: `CAS::Op` argument of derivative
* **returns**: `CAS::Op` derivative
Calls superclass method CAS::BinaryOp#diff
# File lib/functions/fnc-base.rb, line 23
def diff(v)
  left, right = super v
  return left if right == CAS::Zero
  return CAS::Invert.new(right) if left == CAS::Zero
  left - right
end
simplify() click to toggle source

Same as `CAS::Op`

Simplifcation engine supports:

* 0 - y = -y
* x - 0 = x
* a - b = c (constants reduction)
* x - x = 0
* x - (-y) = x + y

* **returns**: `CAS::Op` simplified version
Calls superclass method CAS::BinaryOp#simplify
# File lib/functions/fnc-base.rb, line 53
def simplify
  super
  return CAS.invert(@y) if @x == CAS::Zero
  return @x if @y == CAS::Zero
  return CAS::Zero if @x == @y
  return CAS.const(self.call({})) if (@x.is_a? CAS::Constant and @y.is_a? CAS::Constant)
  return @x + @y.x if @y.is_a? CAS::Invert
  return -(@x.x + @y) if @x.is_a? CAS::Invert
  return self
end
to_code() click to toggle source

Convert expression to code (internal, for `CAS::Op#to_proc` method)

* **returns**: `String` that represent Ruby code to be parsed in `CAS::Op#to_proc`
# File lib/functions/fnc-base.rb, line 67
def to_code
  "(#{@x.to_code} - #{@y.to_code})"
end
to_s() click to toggle source

Same as `CAS::Op`

# File lib/functions/fnc-base.rb, line 38
def to_s
  "(#{@x} - #{@y})"
end