class Keisan::AST::UnaryInverse
Public Instance Methods
differentiate(variable, context = nil)
click to toggle source
# File lib/keisan/ast/unary_inverse.rb, line 28 def differentiate(variable, context = nil) context ||= Context.new Times.new( [ UnaryMinus.new(child.differentiate(variable, context)), UnaryInverse.new( Exponent.new([ child.deep_dup, Number.new(2) ]) ) ] ).simplify(context) end
evaluate(context = nil)
click to toggle source
# File lib/keisan/ast/unary_inverse.rb, line 12 def evaluate(context = nil) 1.to_node / child.evaluate(context) end
simplify(context = nil)
click to toggle source
# File lib/keisan/ast/unary_inverse.rb, line 16 def simplify(context = nil) context ||= Context.new @children = [child.simplify(context)] case child when Number Number.new(child.value**-1) else (child ** -1).simplify(context) end end
to_s()
click to toggle source
# File lib/keisan/ast/unary_inverse.rb, line 8 def to_s "(#{child.to_s})**(-1)" end
value(context = nil)
click to toggle source
# File lib/keisan/ast/unary_inverse.rb, line 4 def value(context = nil) return Rational(1, child.value(context)) end