lib/dydx/algebra/inverse.rb in dydx-0.1.4 vs lib/dydx/algebra/inverse.rb in dydx-0.1.25
- old
+ new
@@ -7,37 +7,30 @@
def initialize(x, operator)
@x, @operator = x, operator
end
def to_s
+ # sym = {'*'=>'/', '+'=>'-'}[operator.to_s]
case operator
- when :+ then "( - #{x} )"
- when :* then "( 1 / #{x} )"
+ when :+
+ "( - #{x} )"
+ when :*
+ "( 1 / #{x} )"
end
end
- def subst(hash = {})
+ def differentiate(sym=:x)
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
+
+ def ==(x)
+ to_s == x.to_s
+ end
end
end
-end
+end
\ No newline at end of file