class CAS::Condition

Condition class is a pseudo-class for all the other kind of conditions:

* Equal
* Greater
* GreaterEqual
* Smaller
* SmallerEqual

When derivated, the two functions (that can be considered as the difference of two elements) are derived autonoumouosly. A condition is composed by:

* left function (x)
* right function (y)
* type of condition

Attributes

x[R]

Left hand side

y[R]

Right hand side

Public Class Methods

new(x, y) click to toggle source

Initializer for a new condition. The condition is implicit in the class, thus a pure `CAS::Condition` cannot be used.

* **argument**: `CAS::Op` left argument
* **argument**: `CAS::Op` right argument
* **returns**: `CAS::Condition` new instance
# File lib/functions/fnc-conditions.rb, line 59
def initialize(x, y)
  @x = x
  @y = y
  self.representative
end

Public Instance Methods

==(op) click to toggle source

Return true if two functions are equal, false if different

* **argument**: `CAS::Condition` operator to check against for equality
* **returns**: `TrueClass` or `FalseClass`
# File lib/functions/fnc-conditions.rb, line 142
def ==(op)
  CAS::Help.assert(op, CAS::Condition)

  # condB = (@x == op.y) and (@y == op.x)
  return ((@x == op.x) and (@y == op.y) and (self.class == op.class))
end
args() click to toggle source

Returns an array of variables of the two functions in the condition

* **returns**: `Array` of `CAS::Variable`
# File lib/functions/fnc-conditions.rb, line 105
def args
  (@x.args + @y.args).uniq
end
call(_fd) click to toggle source

Function call will evaluate left and right functions to solve the relation

* **argument**: `Hash` with feed dictionary
* **returns**: `Trueclass` or `Falseclass`
# File lib/functions/fnc-conditions.rb, line 77
def call(_fd)
  raise CAS::CASError, "This is a virtual method"
end
depend?(v) click to toggle source

Returns true if one of the two functions depends upon the expression included

* **argument**: `CAS::Op` operator to check against for dependencies
* **returns**: `TrueClass` or `FalseClass`
# File lib/functions/fnc-conditions.rb, line 132
def depend?(v)
  CAS::Help.assert v, CAS::Op

  @x.depend?(v) or @y.depend?(v)
end
diff(v) click to toggle source

Performs the derivative of the two elements:

“`

d

– [f(x) > g(y)] = f'(x) > g'(x) dx “`

since between the two there is a difference relation.

* **argument**: `CAS::Op` to perform the derivative
# File lib/functions/fnc-conditions.rb, line 120
def diff(v)
  CAS::Help.assert v, CAS::Op

  @x.diff(v)
  @y.diff(v)
  self.simplify
end
inspect() click to toggle source

Inspector for the class. It is class specific

* **returns**: `String`
# File lib/functions/fnc-conditions.rb, line 84
def inspect
  "#{self.class}(#{@x.inspect}, #{@y.inspect})"
end
representative() click to toggle source

Saves some required elements

# File lib/functions/fnc-conditions.rb, line 66
def representative
  @cond_type  = "??"
  @cond_repr  = "??"
  self
end
simplify() click to toggle source

Simplify left and right term of the operator

* **returns**: `CAS::Condition`
# File lib/functions/fnc-conditions.rb, line 152
def simplify
  @x = @x.simplify
  @x = @y.simplify
  return self
end
subs(fd) click to toggle source

Substitute in the two elements using a dictionary

* **returns**: `Hash` of substitutions
# File lib/functions/fnc-conditions.rb, line 161
def subs(fd)
  CAS::Help.assert(fd, Hash)
  @x.subs(fd)
  @y.subs(fd)
  return self
end
to_code() click to toggle source

Return the code that performs a condition evaluation

* **returns**: `String`
# File lib/functions/fnc-conditions.rb, line 98
def to_code
  "(#{@x} #{@cond_type} #{@y})"
end
to_s() click to toggle source

Returns a string that represents the object to be printed

`String`

# File lib/functions/fnc-conditions.rb, line 91
def to_s
  "(#{@x} #{@cond_repr} #{@y})"
end