Class: CAS::Tan
Overview
Representation for the ‘tan(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 ‘tan(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_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`
384 385 386 387 |
# File 'lib/functions/fnc-trig.rb', line 384 def call(f) CAS::Help.assert(f, Hash) Math::tan(@x.call(f)) end |
#diff(v) ⇒ Object
Return the derivative of the ‘tan(x)` function using the chain rule. The input is a `CAS::Op` because it can handle derivatives with respect to functions. E.g.:
“‘
d f'(x)
– sin(f(x)) = ——- dx cos²(x) “‘
* **argument**: `CAS::Op` object of the derivative
* **returns**: `CAS::Op` a derivated object, or `CAS::Zero` for constants
369 370 371 372 373 374 375 |
# File 'lib/functions/fnc-trig.rb', line 369 def diff(v) if @x.depend? v return @x.diff(v) * CAS.pow(CAS::One/CAS.cos(@x), CAS::Two) 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
401 402 403 404 405 |
# File 'lib/functions/fnc-trig.rb', line 401 def simplify super return @x.x if @x.is_a? CAS::Atan 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`
418 419 420 |
# File 'lib/functions/fnc-trig.rb', line 418 def to_code "Math::tan(#{@x.to_code})" end |
#to_s ⇒ Object
Convert expression to string
* **returns**: `String` to print on screen
392 393 394 |
# File 'lib/functions/fnc-trig.rb', line 392 def to_s "tan(#{@x})" end |