Class: CAS::Atan

Inherits:
Op
  • Object
show all
Defined in:
lib/functions/fnc-trig.rb

Overview

Representation for the ‘arctan(x)` function. It is implemented as a `CAS::Op`. It is the inverse of the `tan(x)` function

Instance Attribute Summary

Attributes inherited from Op

#x

Class Method Summary collapse

Instance Method Summary collapse

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

.init_simplify_dictObject



485
486
487
488
489
490
491
# File 'lib/functions/fnc-trig.rb', line 485

def self.init_simplify_dict
  @simplify_dict = {
    CAS::Zero => CAS::Zero,
    CAS::One => (CAS::Pi/4),
    CAS::Infinity => (CAS::Pi/2)
  }
end

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`


462
463
464
465
# File 'lib/functions/fnc-trig.rb', line 462

def call(f)
  CAS::Help.assert(f, Hash)
  Math::atan(@x.call(f))
end

#diff(v) ⇒ Object

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

* **argument**: `CAS::Op` object of the derivative
* **returns**: `CAS::Op` a derivated object, or `CAS::Zero` for constants


447
448
449
450
451
452
453
# File 'lib/functions/fnc-trig.rb', line 447

def diff(v)
  if @x.depend? v
    return (@x.diff(v) / (CAS.pow(@x, CAS::Two) + CAS::One))
  else
    return CAS::Zero
  end
end

#simplifyObject

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


479
480
481
482
483
# File 'lib/functions/fnc-trig.rb', line 479

def simplify
  super
  return @x.x if @x.is_a? CAS::Tan
  return self.simplify_dictionary
end

#to_codeObject

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`


496
497
498
# File 'lib/functions/fnc-trig.rb', line 496

def to_code
  "Math::atan(#{@x.to_code})"
end

#to_sObject

Convert expression to string

* **returns**: `String` to print on screen


470
471
472
# File 'lib/functions/fnc-trig.rb', line 470

def to_s
  "atan(#{@x})"
end