Class: CAS::Constant
- Defined in:
- lib/numbers/constants.rb,
lib/Mr.CAS/graphviz.rb,
lib/numbers/constants.rb
Overview
Constant is a ‘CAS::Op` container for a `Numeric` value, that is not a `CAS::Variable`, thus its derivative it is always zero
Direct Known Subclasses
E_CONSTANT, INFINITY_CONSTANT, MINUS_ONE_CONSTANT, NEG_INFINITY_CONSTANT, ONE_CONSTANT, PI_CONSTANT, TWO_CONSTANT, ZERO_CONSTANT
Constant Summary collapse
- @@simplify_dict =
{ 0 => CAS::Zero, 1 => CAS::One, Math::PI => CAS::Pi, Math::E => CAS::E, (1.0/0.0) => CAS::Infinity }
Instance Attribute Summary
Attributes inherited from Op
Instance Method Summary collapse
-
#==(op) ⇒ Object
Check if a constant is equal to another ‘CAS::Op` object.
-
#args ⇒ Object
Args of a constant is an empty ‘Array`.
-
#call(_f) ⇒ Object
Calling a constant will return the value of the constant itself.
-
#depend?(_v) ⇒ Boolean
There is no dependency in a constant, thus this method will always return false.
-
#diff(_v) ⇒ Object
Evaluates the derivative of a constant.
-
#initialize(x) ⇒ Constant
constructor
A new instance of Constant.
-
#inspect ⇒ Object
Inspection for ‘CAS::Constant` class.
-
#simplify ⇒ Object
Simplification callback.
-
#subs(_dt) ⇒ Object
Subs for a constant is a dummy method that returns always ‘self`.
-
#to_dot ⇒ Object
Return the local Graphviz node of the tree.
-
#to_s ⇒ Object
The string representation of a constant is the value of the constant.
Methods inherited from Op
#!=, #*, #**, #+, #-, #-@, #/, #as_proc, #dot_graph, #equal, #greater, #greater_equal, init_simplify_dict, #limit, numeric_to_const, simplify_dict, #simplify_dictionary, #smaller, #smaller_equal, #to_c_lib, #to_code
Constructor Details
#initialize(x) ⇒ Constant
Returns a new instance of Constant.
36 37 38 |
# File 'lib/numbers/constants.rb', line 36 def initialize(x) @x = x end |
Instance Method Details
#==(op) ⇒ Object
Check if a constant is equal to another ‘CAS::Op` object
* **argument**: `CAs::Op`
* **returns**: `TrueClass` or `FalseClass`
107 108 109 110 111 112 113 |
# File 'lib/numbers/constants.rb', line 107 def ==(op) if op.is_a? CAS::Constant return @x == op.x else return false end end |
#args ⇒ Object
Args of a constant is an empty ‘Array`
* **returns**: `Array` empty
99 100 101 |
# File 'lib/numbers/constants.rb', line 99 def args [] end |
#call(_f) ⇒ Object
Calling a constant will return the value of the constant itself.
* **argument**: Unused argument
* **returns**: `Numeric` value of the constant
57 58 59 |
# File 'lib/numbers/constants.rb', line 57 def call(_f) @x end |
#depend?(_v) ⇒ Boolean
There is no dependency in a constant, thus this method will always return false
* **argument**: Unused argument
* **returns**: `FalseClass`
66 67 68 |
# File 'lib/numbers/constants.rb', line 66 def depend?(_v) false end |
#diff(_v) ⇒ Object
Evaluates the derivative of a constant. The derivative is always a ‘CAS::Zero`
“‘
d
– c = 0 dx “‘
48 49 50 |
# File 'lib/numbers/constants.rb', line 48 def diff(_v) CAS::Zero end |
#inspect ⇒ Object
Inspection for ‘CAS::Constant` class
* **returns**: `String`
118 119 120 |
# File 'lib/numbers/constants.rb', line 118 def inspect "Const(#{self})" 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
91 92 93 |
# File 'lib/numbers/constants.rb', line 91 def simplify return self end |
#subs(_dt) ⇒ Object
Subs for a constant is a dummy method that returns always ‘self`
* **argument**: Unused argument
* **returns**: `CAS::Constant` that represent `self`
82 83 84 |
# File 'lib/numbers/constants.rb', line 82 def subs(_dt) return self end |
#to_dot ⇒ Object
Return the local Graphviz node of the tree
* **returns**: `String` of local Graphiz node
85 86 87 |
# File 'lib/Mr.CAS/graphviz.rb', line 85 def to_dot "Const(#{@x})" end |
#to_s ⇒ Object
The string representation of a constant is the value of the constant
* **returns**: `String`
74 75 76 |
# File 'lib/numbers/constants.rb', line 74 def to_s "#{@x}" end |