class CAS::Pow

Power function.

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 141
def call(f)
  CAS::Help.assert(f, Hash)
  @x.call(f).overloaded_pow(@y.call(f))
end
diff(v) click to toggle source

Performs the power between two `CAS::Op`

“`

d

—- (f(x)^a) = f(x)^(a - 1) * a * f'(x)

dx

 d

—- (a^f(x)) = a^f(x) * f'(x) * ln a

dx

 d

—- (f(x)^g(x)) = (f(x)^g(x)) * (g'(x) * ln f(x) + g(x) * f'(x) / f(x))

dx

“`

* **argument**: `CAS::Op` argument of derivative
* **returns**: `CAS::Op` derivative
Calls superclass method CAS::BinaryOp#diff
# File lib/functions/fnc-base.rb, line 122
def diff(v)
  diff_x, diff_y = super v
  if diff_y == CAS::Zero
    return ((@x ** (@y - 1.0)) * @y * diff_x)
  elsif diff_x == CAS::Zero
    return (@x ** @y) * diff_y * CAS.ln(@x)
  else
    return (@x ** @y) * ((diff_y * CAS.ln(@x)) + (@y * diff_x / @x))
  end
end
simplify() click to toggle source

Same as `CAS::Op`

Simplifcation engine supports:

* 0 ^ y = 0
* x ^ 0 = 1
* a ^ b = c (constants reduction)
* x ^ 1 = x
* 1 ^ y = 1

* **returns**: `CAS::Op` simplified version
Calls superclass method CAS::BinaryOp#simplify
# File lib/functions/fnc-base.rb, line 164
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::One if @x == CAS::One
  return @x if @y == CAS::One
  return CAS::One if @y == CAS::Zero
  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 182
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 149
def to_s
  "(#{@x})^(#{@y})"
end