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.
Methods inherited from Condition
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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# 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 |
Instance Attribute Details
#lower ⇒ Object (readonly)
Upper bound as ‘CAS::Constant`
26 27 28 |
# File 'lib/functions/fnc-box-conditions.rb', line 26 def lower @lower end |
#upper ⇒ Object (readonly)
Lower bound as ‘CAs::Constant`
28 29 30 |
# File 'lib/functions/fnc-box-conditions.rb', line 28 def upper @upper end |
#x ⇒ Object (readonly)
Contained operation
24 25 26 |
# File 'lib/functions/fnc-box-conditions.rb', line 24 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`
116 117 118 119 |
# 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 |
#args ⇒ Object
Returns an array of variables of the central function
* **returns**: `Array` of `CAS::Variable`
108 109 110 |
# File 'lib/functions/fnc-box-conditions.rb', line 108 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`
126 127 128 |
# File 'lib/functions/fnc-box-conditions.rb', line 126 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`
68 69 70 |
# File 'lib/functions/fnc-box-conditions.rb', line 68 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
101 102 103 |
# File 'lib/functions/fnc-box-conditions.rb', line 101 def diff(v) CAS::equal(@x.diff(v).simplify, CAS::Zero) end |
#inspect ⇒ Object
Inspector for the class. It is class specific
* **returns**: `String`
133 134 135 |
# File 'lib/functions/fnc-box-conditions.rb', line 133 def inspect "(#{@lower.inspect} #{@lower_cond} #{@x.inspect} #{@upper_cond} #{@upper.inspect})" end |
#representative ⇒ Object
Saves some required elements
58 59 60 61 62 |
# File 'lib/functions/fnc-box-conditions.rb', line 58 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`
75 76 77 78 |
# File 'lib/functions/fnc-box-conditions.rb', line 75 def simplify @x.simplify return self end |
#subs(fd) ⇒ Object
Substitute in the central element using a dictionary
* **returns**: `Hash` of substitutions
83 84 85 86 |
# File 'lib/functions/fnc-box-conditions.rb', line 83 def subs(fd) @x = @x.subs(fd) return self end |
#to_code ⇒ Object
Return the code that performs a condition evaluation
* **returns**: `String`
147 148 149 |
# 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 |
#to_s ⇒ Object
Returns a string that represents the object to be printed
‘String`
140 141 142 |
# File 'lib/functions/fnc-box-conditions.rb', line 140 def to_s "#{@lower} #{@lower_str} #{@x} #{@upper_str} #{@upper}" end |