lib/dydx/algebra/operator/parts/inverse.rb in dydx-0.0.7 vs lib/dydx/algebra/operator/parts/inverse.rb in dydx-0.0.8

- old
+ new

@@ -1,33 +1,23 @@ module Dydx module Algebra module Operator module Parts module Inverse - def +(x) - if self.x == x && operator == :+ - e0 - elsif !x.is_a?(Inverse) - x + self - else - super(x) - end - end - - def *(x) - if self.x == x && operator == :* - e1 - else - super(x) - end - end - - def ^(x) - case operator - when :+ - super(x) - when :* - inverse(self.x ^ x, :*) + %w(+ * ^).map(&:to_sym).each do |operator| + define_method(operator) do |x| + if inverse?(operator, x) + case operator + when :+ then e0 + when :* then e1 + end + elsif !x.is_a?(Inverse) && operator == :+ + x + self + elsif self.operator == :* && operator == :^ + inverse(self.x ^ x, :*) + else + super(x) + end end end end end end