class CAS::Div
Division between two functions. A function divided by zero it is considered as an Infinity.
Public Instance Methods
call(f)
click to toggle source
Call resolves the operation tree in a `Numeric` (if `Fixnum`) or `Float` (depends upon promotions). As input, it requires an hash with `CAS::Variable` or `CAS::Variable#name` as keys, and a `Numeric` as a value. In this case it will call the `Fixnum#overloaded_plus`, that is the old plus function.
* **argument**: `Hash` with feed dictionary * **returns**: `Numeric`
# File lib/functions/fnc-base.rb, line 235 def call(f) CAS::Help.assert(f, Hash) @x.call(f).overloaded_div(@y.call(f)) end
diff(v)
click to toggle source
Performs the division between two `CAS::Op`
“`
d
—- (f(x) / g(x)) = (f'(x) * g(x) - f(x) * g'(x))/(g(x)^2)
dx
“`
* **argument**: `CAS::Op` argument of derivative * **returns**: `CAS::Op` derivative
Calls superclass method
CAS::BinaryOp#diff
# File lib/functions/fnc-base.rb, line 216 def diff(v) diff_x, diff_y = super v if diff_y == CAS::Zero return (diff_x/@y) elsif diff_x == CAS::Zero return CAS.invert(@x * diff_y / CAS.pow(@y, CAS.const(2.0))) else return ((diff_x * @y) - (diff_y * @x))/CAS.pow(@y, CAS.const(2.0)) end end
simplify()
click to toggle source
Same as `CAS::Op`
Simplifcation engine supports:
* 0 / y = 0 * x / 0 = Inf * x / 1 = x * x / Inf = 0 * a / b = c (constants reduction) * **returns**: `CAS::Op` simplified version
Calls superclass method
CAS::BinaryOp#simplify
# File lib/functions/fnc-base.rb, line 259 def simplify super return self if (@x == CAS::Zero and @y == CAS::Zero) return self if (@x == CAS::Infinity and @y == CAS::Infinity) return self if (@x == CAS::Infinity and @y == CAS::Zero) return self if (@x == CAS::Zero and @y == CAS::Infinity) return CAS::Zero if @x == CAS::Zero return CAS::Infinity if @y == CAS::Zero return @x if @y == CAS::One return CAS::Zero if @y == CAS::Infinity return CAS::One if @x == @y return CAS.const(self.call({})) if (@x.is_a? CAS::Constant and @y.is_a? CAS::Constant) return self end
to_code()
click to toggle source
Convert expression to code (internal, for `CAS::Op#to_proc` method)
* **returns**: `String` that represent Ruby code to be parsed in `CAS::Op#to_proc`
# File lib/functions/fnc-base.rb, line 278 def to_code "(#{@x.to_code} / #{@y.to_code})" end
to_s()
click to toggle source
Convert expression to string
* **returns**: `String` to print on screen
# File lib/functions/fnc-base.rb, line 244 def to_s "(#{@x}) / (#{@y})" end