Sha256: c5525cd844521bb1dc00f89f466047c734b3f15176696e4aa02a014bf39a0593

Contents?: true

Size: 934 Bytes

Versions: 11

Compression:

Stored size: 934 Bytes

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Num
          %w(+ * ^).map(&:to_sym).each do |operator|
            define_method(operator) do |x|
              if is_0?
                case operator
                when :+ then x
                when :* then e0
                when :^ then e0
                end
              elsif is_1?
                case operator
                when :+ then super(x)
                when :* then x
                when :^ then e1
                end
              elsif x.is_a?(Num)
                _(n.send(operator, x.n))
              elsif operator == :+ && x.inverse?(:+) && x.x.is_a?(Num)
                _(n - x.x.n)
              elsif operator == :* && x.inverse?(:*) && x.x.is_a?(Num)
                _(n / x.x.n)
              else
                super(x)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
dydx-0.1.314 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.31 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.3 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.29 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.28 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.25 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.2 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.1 lib/dydx/algebra/operator/parts/num.rb
dydx-0.1.0 lib/dydx/algebra/operator/parts/num.rb
dydx-0.0.9 lib/dydx/algebra/operator/parts/num.rb
dydx-0.0.8 lib/dydx/algebra/operator/parts/num.rb