Class: CAS::BoxCondition
- Defined in:
- lib/functions/fnc-box-conditions.rb
Overview
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`
Direct Known Subclasses
BoxConditionClosed, BoxConditionLowerClosed, BoxConditionOpen, BoxConditionUpperClosed
Instance Attribute Summary collapse
-
#lower ⇒ Object
readonly
Upper bound as ‘CAS::Constant`.
-
#upper ⇒ Object
readonly
Lower bound as ‘CAs::Constant`.
-
#x ⇒ Object
readonly
Contained operation.
Attributes inherited from Condition
Instance Method Summary collapse
-
#==(cond) ⇒ Object
Return true if two BoxConditions are equal, false if different.
-
#args ⇒ Object
Returns an array of variables of the central function.
-
#call(_fd) ⇒ Object
Function call will evaluate left and right functions to solve the relation.
-
#depend?(v) ⇒ Boolean
Returns true if one the central function depends upon the expression included.
-
#diff(v) ⇒ Object
Performs the derivative of the box condition.
-
#initialize(x, lower, upper) ⇒ BoxCondition
constructor
Initializes a new box condition.
-
#inspect ⇒ Object
Inspector for the class.
-
#representative ⇒ Object
Saves some required elements.
-
#simplify ⇒ Object
Simplify left and right term of the operator.
-
#subs(fd) ⇒ Object
Substitute in the central element using a dictionary.
-
#to_code ⇒ Object
Return the code that performs a condition evaluation.
-
#to_s ⇒ Object
Returns a string that represents the object to be printed.
Constructor Details
#initialize(x, lower, upper) ⇒ BoxCondition
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
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/functions/fnc-box-conditions.rb', line 61 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 |
Instance Attribute Details
#lower ⇒ Object (readonly)
Upper bound as ‘CAS::Constant`
49 50 51 |
# File 'lib/functions/fnc-box-conditions.rb', line 49 def lower @lower end |
#upper ⇒ Object (readonly)
Lower bound as ‘CAs::Constant`
51 52 53 |
# File 'lib/functions/fnc-box-conditions.rb', line 51 def upper @upper end |
#x ⇒ Object (readonly)
Contained operation
47 48 49 |
# File 'lib/functions/fnc-box-conditions.rb', line 47 def x @x end |
Instance Method Details
#==(cond) ⇒ Object
Return true if two BoxConditions are equal, false if different
* **argument**: `CAS::Op` operator to check against for equality
* **returns**: `TrueClass` or `FalseClass`
139 140 141 142 |
# File 'lib/functions/fnc-box-conditions.rb', line 139 def ==(cond) return false if not self.class != cond.class return (@x == cond.x and @lower == cond.lower and @upper == cond.upper) end |
#args ⇒ Object
Returns an array of variables of the central function
* **returns**: `Array` of `CAS::Variable`
131 132 133 |
# File 'lib/functions/fnc-box-conditions.rb', line 131 def args @x.args end |
#call(_fd) ⇒ Object
Function call will evaluate left and right functions to solve the relation
* **argument**: `Hash` with feed dictionary
* **returns**: `Trueclass` or `Falseclass`
149 150 151 |
# File 'lib/functions/fnc-box-conditions.rb', line 149 def call(_fd) raise CAS::CASError, "This is a virtual method" end |
#depend?(v) ⇒ Boolean
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`
91 92 93 |
# File 'lib/functions/fnc-box-conditions.rb', line 91 def depend?(v) @x.depend? v end |
#diff(v) ⇒ Object
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
124 125 126 |
# File 'lib/functions/fnc-box-conditions.rb', line 124 def diff(v) CAS::equal(@x.diff(v).simplify, CAS::Zero) end |
#inspect ⇒ Object
Inspector for the class. It is class specific
* **returns**: `String`
156 157 158 |
# File 'lib/functions/fnc-box-conditions.rb', line 156 def inspect "(#{@lower.inspect} #{@lower_cond} #{@x.inspect} #{@upper_cond} #{@upper.inspect})" end |
#representative ⇒ Object
Saves some required elements
81 82 83 84 85 |
# File 'lib/functions/fnc-box-conditions.rb', line 81 def representative @lower_cond = @upper_cond = "<" @lower_str = @upper_str = "<" self end |
#simplify ⇒ Object
Simplify left and right term of the operator
* **returns**: `CAS::BoxCondition`
98 99 100 101 |
# File 'lib/functions/fnc-box-conditions.rb', line 98 def simplify @x.simplify return self end |
#subs(fd) ⇒ Object
Substitute in the central element using a dictionary
* **returns**: `Hash` of substitutions
106 107 108 109 |
# File 'lib/functions/fnc-box-conditions.rb', line 106 def subs(fd) @x = @x.subs(fd) return self end |
#to_code ⇒ Object
Return the code that performs a condition evaluation
* **returns**: `String`
170 171 172 |
# File 'lib/functions/fnc-box-conditions.rb', line 170 def to_code "((#{@lower.to_code} #{@lower_cond} (#{@x.to_code})) and ((#{@x.to_code}) #{@upper_cond} #{@upper.to_code}))" end |
#to_s ⇒ Object
Returns a string that represents the object to be printed
‘String`
163 164 165 |
# File 'lib/functions/fnc-box-conditions.rb', line 163 def to_s "#{@lower} #{@lower_str} #{@x} #{@upper_str} #{@upper}" end |