lib/dydx/algebra/inverse.rb in dydx-0.1.3 vs lib/dydx/algebra/inverse.rb in dydx-0.1.4

- old
+ new

@@ -13,15 +13,29 @@ when :+ then "( - #{x} )" when :* then "( 1 / #{x} )" end end - def differentiate(sym=:x) + def subst(hash = {}) case operator + when :+ then x.subst(hash) * -1 + when :* then x.subst(hash) ** -1 + end + end + + def to_f + case operator + when :+ then x.to_f * -1 + when :* then x.to_f ** -1 + end + end + + def differentiate(sym = :x) + case operator when :+ inverse(x.differentiate(sym), :+) when :* - inverse(x.differentiate(sym) * inverse(x ^ 2, :*), :+) + inverse(x.differentiate(sym) * inverse(x ** 2, :*), :+) end end alias_method :d, :differentiate end end