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.
13 14 15 |
# File 'lib/numbers/constants.rb', line 13 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`
84 85 86 87 88 89 90 |
# File 'lib/numbers/constants.rb', line 84 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
76 77 78 |
# File 'lib/numbers/constants.rb', line 76 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
34 35 36 |
# File 'lib/numbers/constants.rb', line 34 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`
43 44 45 |
# File 'lib/numbers/constants.rb', line 43 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 “‘
25 26 27 |
# File 'lib/numbers/constants.rb', line 25 def diff(_v) CAS::Zero end |
#inspect ⇒ Object
Inspection for ‘CAS::Constant` class
* **returns**: `String`
95 96 97 |
# File 'lib/numbers/constants.rb', line 95 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
68 69 70 |
# File 'lib/numbers/constants.rb', line 68 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`
59 60 61 |
# File 'lib/numbers/constants.rb', line 59 def subs(_dt) return self end |
#to_dot ⇒ Object
Return the local Graphviz node of the tree
* **returns**: `String` of local Graphiz node
62 63 64 |
# File 'lib/Mr.CAS/graphviz.rb', line 62 def to_dot "Const(#{@x})" end |
#to_s ⇒ Object
The string representation of a constant is the value of the constant
* **returns**: `String`
51 52 53 |
# File 'lib/numbers/constants.rb', line 51 def to_s "#{@x}" end |