Class: Keisan::Functions::MathFunction
Instance Attribute Summary
Attributes inherited from ProcFunction
#function_proc
#arity, #name
Instance Method Summary
collapse
#call, #evaluate, #value
#evaluate, #unbound_variables, #value
Constructor Details
#initialize(name, proc_function = nil) ⇒ MathFunction
4
5
6
|
# 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
|
Instance Method Details
#differentiate(ast_function, variable, context = nil) ⇒ Object
13
14
15
16
17
18
19
20
21
|
# 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) ⇒ Object
8
9
10
11
|
# File 'lib/keisan/functions/math_function.rb', line 8
def simplify(ast_function, context = nil)
simplified = super
self.class.apply_simplifications(simplified)
end
|