class CAS::Constant

Constant is a `CAS::Op` container for a `Numeric` value, that is not a `CAS::Variable`, thus its derivative it is always zero

Public Class Methods

new(x) click to toggle source
# File lib/numbers/constants.rb, line 36
def initialize(x)
  @x = x
end

Public Instance Methods

==(op) click to toggle source

Check if a constant is equal to another `CAS::Op` object

* **argument**: `CAs::Op`
* **returns**: `TrueClass` or `FalseClass`
# 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() click to toggle source

Args of a constant is an empty `Array`

* **returns**: `Array` empty
# File lib/numbers/constants.rb, line 99
def args
  []
end
call(_f) click to toggle source

Calling a constant will return the value of the constant itself.

* **argument**: Unused argument
* **returns**: `Numeric` value of the constant
# File lib/numbers/constants.rb, line 57
def call(_f)
  @x
end
depend?(_v) click to toggle source

There is no dependency in a constant, thus this method will always return false

* **argument**: Unused argument
* **returns**: `FalseClass`
# File lib/numbers/constants.rb, line 66
def depend?(_v)
  false
end
diff(_v) click to toggle source

Evaluates the derivative of a constant. The derivative is always a `CAS::Zero`

“`

d

– c = 0 dx “`

# File lib/numbers/constants.rb, line 48
def diff(_v)
  CAS::Zero
end
inspect() click to toggle source

Inspection for `CAS::Constant` class

* **returns**: `String`
# File lib/numbers/constants.rb, line 118
def inspect
  "Const(#{self})"
end
simplify() click to toggle source

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
# File lib/numbers/constants.rb, line 91
def simplify
  return self
end
subs(_dt) click to toggle source

Subs for a constant is a dummy method that returns always `self`

* **argument**: Unused argument
* **returns**: `CAS::Constant` that represent `self`
# File lib/numbers/constants.rb, line 82
def subs(_dt)
  return self
end
to_dot() click to toggle source

Return the local Graphviz node of the tree

* **returns**: `String` of local Graphiz node
# File lib/Mr.CAS/graphviz.rb, line 85
def to_dot
  "Const(#{@x})"
end
to_s() click to toggle source

The string representation of a constant is the value of the constant

* **returns**: `String`
# File lib/numbers/constants.rb, line 74
def to_s
  "#{@x}"
end