class CAS::Invert

Invert is the same as multiply by `-1` a function. `Invert(x)` is equal to `-x`

Public Class Methods

init_simplify_dict() click to toggle source
# File lib/functions/fnc-base.rb, line 431
def self.init_simplify_dict
  @simplify_dict = {
    CAS::Zero => CAS::Zero
  }
end

Public Instance Methods

call(f) click to toggle source

Call resolves the operation tree in a `Numeric` (if `Fixnum`) or `Float` (depends upon promotions). As input, it requires an hash with `CAS::Variable` or `CAS::Variable#name` as keys, and a `Numeric` as a value. In this case it will call the `Fixnum#overloaded_plus`, that is the old plus function.

* **argument**: `Hash` with feed dictionary
* **returns**: `Numeric`
# File lib/functions/fnc-base.rb, line 404
def call(f)
  CAS::Help.assert(f, Hash)

  -1.0 * @x.call(f)
end
diff(v) click to toggle source

Performs the inversion of a `CAS::Op`

“`

d

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

dx

“`

* **argument**: `CAS::Op` argument of derivative
* **returns**: `CAS::Op` derivative
# File lib/functions/fnc-base.rb, line 388
def diff(v)
  if @x.depend? v
    -@x.diff(v)
  else
    CAS::Zero
  end
end
simplify() click to toggle source

Same as `CAS::Op`

Simplifcation engine supports:

* -(-x) = x
* -0 = 0

* **returns**: `CAS::Op` simplified version
Calls superclass method CAS::Op#simplify
# File lib/functions/fnc-base.rb, line 425
def simplify
  super
  return @x.x if @x.is_a? CAS::Invert
  return self.simplify_dictionary
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 440
def to_code
  "(-#{@x.to_code})"
end
to_s() click to toggle source

Convert expression to string

* **returns**: `String` to print on screen
# File lib/functions/fnc-base.rb, line 413
def to_s
  "-#{@x}"
end