Class: CAS::Ln
Overview
Representation for the ‘log(x)` function. It is implemented as a `CAS::Op`
Instance Attribute Summary
Attributes inherited from Op
Class Method Summary collapse
Instance Method Summary collapse
-
#call(f) ⇒ Object
Call resolves the operation tree in a ‘Numeric` (if `Fixnum`) or `Float` (depends upon promotions).
-
#diff(v) ⇒ Object
Return the derivative of the ‘log(x)` function using the chain rule.
-
#simplify ⇒ Object
Simplification callback.
-
#to_code ⇒ Object
Convert expression to code (internal, for ‘CAS::Op#to_proc` method).
-
#to_latex ⇒ Object
Returns the latex representation of the current Op.
-
#to_s ⇒ Object
Convert expression to string.
Methods inherited from Op
#!=, #*, #**, #+, #-, #-@, #/, #==, #args, #as_proc, #depend?, #dot_graph, #equal, #greater, #greater_equal, #initialize, #inspect, #limit, numeric_to_const, simplify_dict, #simplify_dictionary, #smaller, #smaller_equal, #subs, #to_c_lib
Constructor Details
This class inherits a constructor from CAS::Op
Class Method Details
Instance Method Details
#call(f) ⇒ Object
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`
156 157 158 159 160 161 |
# File 'lib/functions/fnc-trsc.rb', line 156 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) ⇒ Object
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
141 142 143 144 145 146 147 |
# File 'lib/functions/fnc-trsc.rb', line 141 def diff(v) if @x.depend? v return CAS::One / @x else return CAS::Zero end end |
#simplify ⇒ Object
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
175 176 177 178 179 |
# File 'lib/functions/fnc-trsc.rb', line 175 def simplify super return @x.x if @x.is_a? CAS::Exp return self.simplify_dictionary end |
#to_code ⇒ Object
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`
192 193 194 |
# File 'lib/functions/fnc-trsc.rb', line 192 def to_code "Math::log(#{@x.to_code})" end |
#to_latex ⇒ Object
Returns the latex representation of the current Op.
* **returns**: `String`
199 200 201 |
# File 'lib/functions/fnc-trsc.rb', line 199 def to_latex "\\log\\left( #{@x.to_latex} \\right)" end |
#to_s ⇒ Object
Convert expression to string
* **returns**: `String` to print on screen
166 167 168 |
# File 'lib/functions/fnc-trsc.rb', line 166 def to_s "log(#{@x})" end |