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