Sha256: 12b192527c37e5613d9063de1c2dc3067f583396e4b4d9fe22a333d96128a2c2

Contents?: true

Size: 698 Bytes

Versions: 10

Compression:

Stored size: 698 Bytes

Contents

module Dydx
  module Algebra
    class Inverse
      include Helper
      attr_accessor :x, :operator

      def initialize(x, operator)
        @x, @operator = x, operator
      end

      def to_s
        # sym = {'*'=>'/', '+'=>'-'}[operator.to_s]
        case operator
        when :+
          "( - #{x} )"
        when :*
          "( 1 / #{x} )"
        end
      end

      def differentiate(sym=:x)
        case operator
        when :+
          inverse(x.differentiate(sym), :+)
        when :*
          inverse(x.differentiate(sym) * inverse(x ^ 2, :*), :+)
        end
      end
      alias_method :d, :differentiate

      def ==(x)
        to_s == x.to_s
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dydx-0.1.28 lib/dydx/algebra/inverse.rb
dydx-0.1.25 lib/dydx/algebra/inverse.rb
dydx-0.1.2 lib/dydx/algebra/inverse.rb
dydx-0.1.1 lib/dydx/algebra/inverse.rb
dydx-0.1.0 lib/dydx/algebra/inverse.rb
dydx-0.0.9 lib/dydx/algebra/inverse.rb
dydx-0.0.8 lib/dydx/algebra/inverse.rb
dydx-0.0.7 lib/dydx/algebra/inverse.rb
dydx-0.0.6 lib/dydx/algebra/inverse.rb
dydx-0.0.5 lib/dydx/algebra/inverse.rb