lib/dydx/algebra.rb in dydx-0.1.314 vs lib/dydx/algebra.rb in dydx-0.1.412
- old
+ new
@@ -1,20 +1,22 @@
require 'dydx/algebra/set'
-require 'dydx/algebra/formula'
-require 'dydx/algebra/inverse'
module Dydx
module Algebra
include Set
class Formula; include Operator::Formula; end
class Inverse; include Operator::Inverse; end
+ # TODO: Cyclomatic complexity for inverse is too high. [7/6]
def inverse(x, operator)
- if operator == :+ && x.is_0?
- e0
- elsif operator == :* && x.is_1?
- e1
+ if x.num?
+ x = x.to_numeric
+ if operator == :+
+ _(- x)
+ else
+ _(Rational(1, x))
+ end
elsif x.is_a?(Inverse) && x.operator == operator
x.x
else
Inverse.new(x, operator)
end