Sha256: b307633ffe1ad3f923023d3a5b4e300089546f7f0be7811f476b08f8ad162e08

Contents?: true

Size: 587 Bytes

Versions: 3

Compression:

Stored size: 587 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
        case operator
        when :+ then "( - #{x} )"
        when :* then "( 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
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dydx-0.1.31 lib/dydx/algebra/inverse.rb
dydx-0.1.3 lib/dydx/algebra/inverse.rb
dydx-0.1.29 lib/dydx/algebra/inverse.rb