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
Left hand side
Right hand side
Public Class Methods
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 36 def initialize(x, y) @x = x @y = y self.representative end
Public Instance Methods
Return true if two functions are equal, false if different
* **argument**: `CAS::Op` operator to check against for equality * **returns**: `TrueClass` or `FalseClass`
# File lib/functions/fnc-conditions.rb, line 119 def ==(op) CAS::Help.assert(op, CAS::Op) # condB = (@x == op.y) and (@y == op.x) return ((@x == op.x) and (@y == op.y) and (self.class == op.class)) end
Returns an array of variables of the two functions in the condition
* **returns**: `Array` of `CAS::Variable`
# File lib/functions/fnc-conditions.rb, line 82 def args (@x.args + @y.args).uniq end
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 54 def call(_fd) raise CAS::CASError, "This is a virtual method" end
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 109 def depend?(v) CAS::Help.assert v, CAS::Op @x.depend?(v) or @y.depend?(v) end
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 97 def diff(v) CAS::Help.assert v, CAS::Op @x.diff(v) @y.diff(v) self.simplify end
Returns the dot graphviz representation of the code
* **returns**: `String`
# File lib/functions/fnc-conditions.rb, line 148 def dot_graph(node) cls = "#{self.class.to_s.gsub("CAS::", "")}_#{self.object_id}" "#{cls} -> #{@x.dot_graph node}\n #{cls} -> #{@y.dot_graph node}" end
Inspector for the class. It is class specific
* **returns**: `String`
# File lib/functions/fnc-conditions.rb, line 61 def inspect "#{self.class}(#{@x.inspect}, #{@y.inspect})" end
Saves some required elements
# File lib/functions/fnc-conditions.rb, line 43 def representative @cond_type = "??" @cond_repr = "??" self end
Simplify left and right term of the operator
* **returns**: `CAS::Condition`
# File lib/functions/fnc-conditions.rb, line 129 def simplify @x.simplify @y.simplify return self end
Substitute in the two elements using a dictionary
* **returns**: `Hash` of substitutions
# File lib/functions/fnc-conditions.rb, line 138 def subs(fd) CAS::Help.assert(fd, Hash) @x.subs(fd) @y.subs(fd) return self end
Return the code that performs a condition evaluation
* **returns**: `String`
# File lib/functions/fnc-conditions.rb, line 75 def to_code "(#{@x} #{@cond_type} #{@y})" end
Returns a string that represents the object to be printed
`String`
# File lib/functions/fnc-conditions.rb, line 68 def to_s "(#{@x} #{@cond_repr} #{@y})" end