class CAS::Ln

Representation for the `log(x)` function. It is implemented as a `CAS::Op`

Public Class Methods

init_simplify_dict() click to toggle source
# File lib/functions/fnc-trsc.rb, line 158
def self.init_simplify_dict
  @simplify_dict = {
    CAS::Zero => CAS.invert(CAS::Infinity),
    CAS::One => CAS::Zero,
    CAS::E => CAS::One
  }
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

* **argument**: `Hash` with feed dictionary
* **returns**: `Numeric`
# File lib/functions/fnc-trsc.rb, line 133
def call(f)
  # I'm leaving to Math the honor
  # of handling negative values...
  CAS::Help.assert(f, Hash)
  Math::log(@x.call(f))
end
diff(v) click to toggle source

Return the derivative of the `log(x)` function using the chain rule. The input is a `CAS::Op` because it can handle derivatives with respect to functions.

“`

d              f'(x)

– log(f(x)) = ——- dx f(x) “`

* **argument**: `CAS::Op` object of the derivative
* **returns**: `CAS::Op` a derivated object, or `CAS::Zero` for constants
# File lib/functions/fnc-trsc.rb, line 118
def diff(v)
  if @x.depend? v
    return CAS::One / @x
  else
    return CAS::Zero
  end
end
simplify() click to toggle source

Simplification callback. It simplify the subgraph of each node until all possible simplification are performed (thus the execution time is not deterministic).

* **returns**: `CAS::Op` simplified version
Calls superclass method CAS::Op#simplify
# File lib/functions/fnc-trsc.rb, line 152
def simplify
  super
  return @x.x if @x.is_a? CAS::Exp
  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-trsc.rb, line 169
def to_code
  "Math::log(#{@x.to_code})"
end
to_latex() click to toggle source

Returns the latex representation of the current Op.

* **returns**: `String`
# File lib/functions/fnc-trsc.rb, line 176
def to_latex
  "\\log\\left( #{@x.to_latex} \\right)"
end
to_s() click to toggle source

Convert expression to string

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