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

lower[R]

Upper bound as `CAS::Constant`

upper[R]

Lower bound as `CAs::Constant`

x[R]

Contained operation

Public Class Methods

new(x, lower, upper) click to toggle source

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 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

Public Instance Methods

==(cond) click to toggle source

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 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() click to toggle source

Returns an array of variables of the central function

* **returns**: `Array` of `CAS::Variable`
# File lib/functions/fnc-box-conditions.rb, line 131
def args
  @x.args
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-box-conditions.rb, line 149
def call(_fd)
  raise CAS::CASError, "This is a virtual method"
end
depend?(v) click to toggle source

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 91
def depend?(v)
  @x.depend? v
end
diff(v) click to toggle source

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 124
def diff(v)
  CAS::equal(@x.diff(v).simplify, CAS::Zero)
end
inspect() click to toggle source

Inspector for the class. It is class specific

* **returns**: `String`
# File lib/functions/fnc-box-conditions.rb, line 156
def inspect
  "(#{@lower.inspect} #{@lower_cond} #{@x.inspect} #{@upper_cond} #{@upper.inspect})"
end
representative() click to toggle source

Saves some required elements

# File lib/functions/fnc-box-conditions.rb, line 81
def representative
  @lower_cond  = @upper_cond = "<"
  @lower_str   = @upper_str  = "<"
  self
end
simplify() click to toggle source

Simplify left and right term of the operator

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

Substitute in the central element using a dictionary

* **returns**: `Hash` of substitutions
# File lib/functions/fnc-box-conditions.rb, line 106
def subs(fd)
  @x = @x.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-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() click to toggle source

Returns a string that represents the object to be printed

`String`

# File lib/functions/fnc-box-conditions.rb, line 163
def to_s
  "#{@lower} #{@lower_str} #{@x} #{@upper_str} #{@upper}"
end