lib/dydx/algebra/set.rb in dydx-0.1.29 vs lib/dydx/algebra/set.rb in dydx-0.1.31
- old
+ new
@@ -4,10 +4,12 @@
require 'dydx/algebra/set/float'
require 'dydx/algebra/set/symbol'
require 'dydx/algebra/set/e'
require 'dydx/algebra/set/pi'
require 'dydx/algebra/set/log'
+require 'dydx/algebra/set/log2'
+require 'dydx/algebra/set/log10'
require 'dydx/algebra/set/sin'
require 'dydx/algebra/set/cos'
require 'dydx/algebra/set/tan'
module Dydx
@@ -51,9 +53,47 @@
e0
elsif formula.is_a?(E)
e1
else
Log.new(formula)
+ end
+ end
+
+ def log2(formula)
+ # TODO: refactor with log function.
+ if formula.multiplication?
+ f, g = formula.f, formula.g
+ log2(f) + log2(g)
+ elsif formula.exponentiation?
+ f, g = formula.f, formula.g
+ g * log2(f)
+ elsif formula.is_1?
+ e0
+ elsif formula.is_a?(Num)
+ (formula.n == 2) ? e1 : log2(formula.n)
+ elsif formula == 2
+ e1
+ else
+ Log2.new(formula)
+ end
+ end
+
+ def log10(formula)
+ # TODO: refactor with log function.
+ if formula.multiplication?
+ f, g = formula.f, formula.g
+ log10(f) + log10(g)
+ elsif formula.exponentiation?
+ f, g = formula.f, formula.g
+ g * log10(f)
+ elsif formula.is_1?
+ e0
+ elsif formula.is_a?(Num)
+ (formula.n == 10) ? e1 : log10(formula.n)
+ elsif formula == 10
+ e1
+ else
+ Log10.new(formula)
end
end
def sin(x)
multiplier = x.is_multiple_of(pi)