Sha256: e088a96b698214941e144bed351c79cef7beb3285c38c8edee2a1e79fe7d74e7

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Formula
          %w(+ -).each do |operator|
            define_method(operator) do |x|
              if multiplication? && x.multiplication?
                if f == x.f
                  f * g.send(operator, x.g)
                elsif g == x.g
                  f.send(operator, x.f) * g
                else
                  super(x)
                end
              else
                super(x)
              end
            end
          end

          %w(* /).each do |operator|
            define_method(operator) do |x|
              if exponentiation? && x.exponentiation?
                if f == x.f
                  f ^ g.send({'*'=>'+', '/'=>'-'}[operator], x.g)
                elsif g == x.g
                  f.send(operator, x.f) ^ g
                else
                  super(x)
                end
              else
                super(x)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dydx-0.0.2 lib/dydx/algebra/operator/parts/formula.rb
dydx-0.0.1 lib/dydx/algebra/operator/parts/formula.rb