Sha256: 3bb0f7d43e3a6f5b9924cb101ca6efaf965463d2d915cafd4dc374e8493a07fc
Contents?: true
Size: 1.45 KB
Versions: 3
Compression:
Stored size: 1.45 KB
Contents
require 'dydx/algebra/set/base' require 'dydx/algebra/set/num' require 'dydx/algebra/set/fixnum' require 'dydx/algebra/set/symbol' require 'dydx/algebra/set/e' require 'dydx/algebra/set/pi' require 'dydx/algebra/set/log' require 'dydx/algebra/set/sin' require 'dydx/algebra/set/cos' require 'dydx/algebra/set/tan' module Dydx module Algebra module Set def _(num) if num >= 0 eval("$p#{num} ||= Num.new(num)") else eval("$n#{-1 * num} ||= Num.new(num)") end end def pi $pi ||= Pi.new end def e $e ||= E.new end def log(formula) if formula.multiplication? f, g = formula.f, formula.g log(f) + log(g) elsif formula.exponentiation? f, g = formula.f, formula.g g * log(f) elsif formula.is_1? _(0) elsif formula.is_a?(E) _(1) else Log.new(formula) end end def sin(x) multiplier = x.is_multiple_of(pi) if multiplier.is_a?(Num) _(0) else Sin.new(x) end end def cos(x) multiplier = x.is_multiple_of(pi) if multiplier.is_a?(Num) && multiplier.n % 2 == 0 _(1) elsif multiplier.is_a?(Num) && multiplier.n % 2 == 1 _(-1) else Cos.new(x) end end def tan(x) Tan.new(x) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dydx-0.0.4 | lib/dydx/algebra/set.rb |
dydx-0.0.3 | lib/dydx/algebra/set.rb |
dydx-0.0.2 | lib/dydx/algebra/set.rb |