Sha256: dc6d58822698403fdd99ee21d47eda63590955b2e6fb6664724cd976309c6458

Contents?: true

Size: 1.9 KB

Versions: 1

Compression:

Stored size: 1.9 KB

Contents

module Dydx
  module Algebra
    module Operator
      module Parts
        module Formula
          %w(+ -).map(&:to_sym).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
              elsif ([self.operator, operator].sort == [:+, :-]) &&  include?(x)
                if f == x
                  g
                elsif g == x
                  f
                end
              elsif (self.operator == operator) && include?(x)
                if f == x
                  f.send(operator, x).send(operator, g)
                elsif g == x
                  f.send(operator, g.send(:+, x))
                end
              else
                super(x)
              end
            end
          end

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

Version data entries

1 entries across 1 versions & 1 rubygems

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