class Keisan::Functions::MathFunction

Public Class Methods

new(name, proc_function = nil) click to toggle source
Calls superclass method
# File lib/keisan/functions/math_function.rb, line 4
def initialize(name, proc_function = nil)
  super(name, proc_function || Proc.new {|arg| Math.send(name, arg)})
end

Protected Class Methods

apply_simplifications(simplified) click to toggle source
# File lib/keisan/functions/math_function.rb, line 29
def self.apply_simplifications(simplified)
  simplified
end
derivative(argument) click to toggle source
# File lib/keisan/functions/math_function.rb, line 25
def self.derivative(argument)
  raise Exceptions::NotImplementedError.new
end

Public Instance Methods

differentiate(ast_function, variable, context = nil) click to toggle source
# File lib/keisan/functions/math_function.rb, line 13
def differentiate(ast_function, variable, context = nil)
  raise Exceptions::InvalidFunctionError.new unless ast_function.children.count == 1
  context ||= Context.new

  argument_simplified = ast_function.children.first.simplify(context)
  argument_differentiated = argument_simplified.differentiate(variable, context)

  (argument_differentiated * self.class.derivative(argument_simplified)).simplify(context)
end
simplify(ast_function, context = nil) click to toggle source
Calls superclass method
# File lib/keisan/functions/math_function.rb, line 8
def simplify(ast_function, context = nil)
  simplified = super
  self.class.apply_simplifications(simplified)
end