class CAS::BoxCondition
BoxCondition
class constructs a condition of the type:
“` L < f(x) < U “`
and this is a metaclass for different type of box conditions:
* open: `a < f(x) < b` * lower closed: `a ≤ f(x) < b` * upper closed: `a < f(x) ≤ b` * closed: `a ≤ f(x) ≤ b`
Attributes
Upper bound as `CAS::Constant`
Lower bound as `CAs::Constant`
Contained operation
Public Class Methods
Initializes a new box condition. A function is required as central term, while the second and the third elements are lower and upper bounds as `CAS::Constant`
* **argument**: `CAS::Op` central term of the box condition * **argument**: `CAS::Constant` lower bound * **argument**: `CAS::Constant` upper bound * **returns**: `CAS::BoxCondition` new instance
# File lib/functions/fnc-box-conditions.rb, line 38 def initialize(x, lower, upper) if lower.is_a? Numeric lower = CAS::const lower end if upper.is_a? Numeric upper = CAS::const upper end CAS::Help.assert(lower, CAS::Constant) CAS::Help.assert(upper, CAS::Constant) CAS::Help.assert(x, CAS::Op) lower, upper = upper, lower if lower.x > upper.x @lower = lower @upper = upper @x = x end
Public Instance Methods
Return true if two BoxConditions are equal, false if different
* **argument**: `CAS::Op` operator to check against for equality * **returns**: `TrueClass` or `FalseClass`
# File lib/functions/fnc-box-conditions.rb, line 116 def ==(cond) return false if not self.class != cond.class return (@x == cond.x and @lower == cond.lower and @upper == cond.upper) end
Returns an array of variables of the central function
* **returns**: `Array` of `CAS::Variable`
# File lib/functions/fnc-box-conditions.rb, line 108 def args @x.args 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-box-conditions.rb, line 126 def call(_fd) raise CAS::CASError, "This is a virtual method" end
Returns true if one the central function depends upon the expression included
* **argument**: `CAS::Op` operator to check against for dependencies * **returns**: `TrueClass` or `FalseClass`
# File lib/functions/fnc-box-conditions.rb, line 68 def depend?(v) @x.depend? v end
Performs the derivative of the box condition. The derivative of a box condition is a `CAS::Equal` object (the derivative of a constant is zero):
“`
d -- [a < f(x) < b] = f'(x) == 0 dx
“`
since between the two there is a difference relation.
* **argument**: `CAS::Op` to perform the derivative
# File lib/functions/fnc-box-conditions.rb, line 101 def diff(v) CAS::equal(@x.diff(v).simplify, CAS::Zero) end
Inspector for the class. It is class specific
* **returns**: `String`
# File lib/functions/fnc-box-conditions.rb, line 133 def inspect "(#{@lower.inspect} #{@lower_cond} #{@x.inspect} #{@upper_cond} #{@upper.inspect})" end
Saves some required elements
# File lib/functions/fnc-box-conditions.rb, line 58 def representative @lower_cond = @upper_cond = "<" @lower_str = @upper_str = "<" self end
Simplify left and right term of the operator
* **returns**: `CAS::BoxCondition`
# File lib/functions/fnc-box-conditions.rb, line 75 def simplify @x.simplify return self end
Substitute in the central element using a dictionary
* **returns**: `Hash` of substitutions
# File lib/functions/fnc-box-conditions.rb, line 83 def subs(fd) @x = @x.subs(fd) return self end
Return the code that performs a condition evaluation
* **returns**: `String`
# File lib/functions/fnc-box-conditions.rb, line 147 def to_code "((#{@lower.to_code} #{@lower_cond} (#{@x.to_code})) and ((#{@x.to_code}) #{@upper_cond} #{@upper.to_code}))" end
Returns a string that represents the object to be printed
`String`
# File lib/functions/fnc-box-conditions.rb, line 140 def to_s "#{@lower} #{@lower_str} #{@x} #{@upper_str} #{@upper}" end