dydx 0.1.29 → 0.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.pryrc +2 -0
- data/Gemfile +2 -0
- data/README.md +9 -7
- data/lib/dydx.rb +32 -25
- data/lib/dydx/algebra.rb +5 -9
- data/lib/dydx/algebra/operator.rb +5 -0
- data/lib/dydx/algebra/operator/formula.rb +0 -3
- data/lib/dydx/algebra/operator/general.rb +0 -3
- data/lib/dydx/algebra/operator/inverse.rb +0 -3
- data/lib/dydx/algebra/operator/num.rb +0 -3
- data/lib/dydx/algebra/operator/{common_parts.rb → parts.rb} +3 -0
- data/lib/dydx/algebra/operator/parts/formula.rb +14 -14
- data/lib/dydx/algebra/operator/parts/general.rb +2 -0
- data/lib/dydx/algebra/set.rb +40 -0
- data/lib/dydx/algebra/set/log10.rb +22 -0
- data/lib/dydx/algebra/set/log2.rb +22 -0
- data/lib/dydx/helper.rb +14 -10
- data/lib/dydx/integrand.rb +15 -9
- data/lib/dydx/version.rb +1 -1
- data/spec/lib/algebra/set/log10_spec.rb +16 -0
- data/spec/lib/algebra/set/log2_spec.rb +16 -0
- data/spec/lib/integrand_spec.rb +7 -7
- metadata +25 -32
- data/lib/dydx/algebra/operator/symbol.rb +0 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e4de7f815619a3ce01c34bc76a405749bd71f3b
|
4
|
+
data.tar.gz: 957aef1d10863b8fbacf8d142c5a8fd71d9c77e5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5236b464cc82383856640addf8bf5c0f725e68648282278195ac839050df72b35e65e444c15dbbd657b20a05dcb0fdf9df8046d123e735198dee306f764f8b07
|
7
|
+
data.tar.gz: a26cc47a1cb5be11eecb54c7358122dcd9d556644bda14a3a01e222db53779320736a9557036e9af9d967abfb37714f7019e559495bbb49e024f82bad9d5d20a
|
data/.pryrc
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Dydx is new
|
1
|
+
# Dydx is new MATH Language on Ruby.
|
2
2
|
|
3
3
|
### Since you report a bug, I will fix it within 24 hours.
|
4
4
|
|
@@ -8,6 +8,8 @@ we can handle math in the same sense sense of the math on paper.
|
|
8
8
|
|
9
9
|
ex. limit, trigonometric functions and logarithmic.
|
10
10
|
|
11
|
+
## We should enjoy MATH even using PC.
|
12
|
+
(to say nothing of using pen.)
|
11
13
|
|
12
14
|
After `inlcude Dydx` , ruby become like other language.
|
13
15
|
|
@@ -25,7 +27,7 @@ f(3)
|
|
25
27
|
f(x).to_s
|
26
28
|
=> "( x ^ 2 )"
|
27
29
|
|
28
|
-
f(x) == eval(
|
30
|
+
f(x) == eval(f(x).to_s)
|
29
31
|
=> true
|
30
32
|
|
31
33
|
# Differentiate
|
@@ -61,12 +63,12 @@ S(f(z), dz)[0,1]
|
|
61
63
|
|
62
64
|
f(x) <= sin(x)
|
63
65
|
S(f(x), dx)[0, Math::PI/2]
|
64
|
-
=> 1.
|
66
|
+
=> 1.0
|
65
67
|
|
66
68
|
# standard normal distribution;
|
67
69
|
f(x) <= (1.0 / ( ( 2.0 * pi ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
|
68
70
|
S(f(x), dx)[-oo, oo]
|
69
|
-
=> 0
|
71
|
+
=> 1.0
|
70
72
|
```
|
71
73
|
|
72
74
|
#### it's like a magic...
|
@@ -77,7 +79,7 @@ f(x) <= x ^ 2
|
|
77
79
|
f(a + b).to_s
|
78
80
|
=> "( ( a + b ) ^ 2 )"
|
79
81
|
|
80
|
-
#↓it
|
82
|
+
#↓it's like a magic!!!
|
81
83
|
g(a, b) <= f(a + b)
|
82
84
|
|
83
85
|
g(a, b).to_s
|
@@ -156,6 +158,6 @@ Or install it yourself as:
|
|
156
158
|
run `bundle exec rake spec`
|
157
159
|
|
158
160
|
```
|
159
|
-
Finished in 3.
|
160
|
-
|
161
|
+
Finished in 3.76 seconds
|
162
|
+
325 examples, 0 failures
|
161
163
|
```
|
data/lib/dydx.rb
CHANGED
@@ -6,33 +6,18 @@ require 'dydx/integrand'
|
|
6
6
|
|
7
7
|
module Dydx
|
8
8
|
include Algebra
|
9
|
-
# TODO: Refactor
|
10
9
|
%w(f g h).each do |functioner|
|
11
10
|
define_method(functioner) do |*vars|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
.gsub('pi', 'Math::PI')
|
23
|
-
else
|
24
|
-
string = function.algebra.to_s
|
25
|
-
end
|
26
|
-
function.vars.each_with_index do |var, i|
|
27
|
-
string.gsub!(var.to_s, vars[i].to_s)
|
28
|
-
end
|
29
|
-
eval(string)
|
30
|
-
else
|
31
|
-
function
|
32
|
-
end
|
33
|
-
else
|
34
|
-
eval("$#{functioner} = Function.new(*vars)")
|
35
|
-
end
|
11
|
+
function = eval("$#{functioner}")
|
12
|
+
return eval("$#{functioner} = Function.new(*vars)") unless function
|
13
|
+
|
14
|
+
raise ArgumentError, "invalid number of values (#{vars.count} for #{function.vars.count})" unless function.vars.count == vars.count
|
15
|
+
return function if function.vars == vars
|
16
|
+
return function unless function.algebra
|
17
|
+
|
18
|
+
string = substitute(vars, function)
|
19
|
+
string = rename_for_calc(string) if all_vars_num?(vars)
|
20
|
+
eval(string)
|
36
21
|
end
|
37
22
|
end
|
38
23
|
|
@@ -58,4 +43,26 @@ module Dydx
|
|
58
43
|
super
|
59
44
|
end
|
60
45
|
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def substitute(vars, function)
|
50
|
+
string = function.algebra.to_s
|
51
|
+
function.vars.each_with_index { |var, i| string.gsub!(var.to_s, vars[i].to_s) }
|
52
|
+
string
|
53
|
+
end
|
54
|
+
|
55
|
+
def all_vars_num?(vars)
|
56
|
+
vars.all? { |v| v.is_a?(Numeric) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def rename_for_calc(string)
|
60
|
+
# TODO: need more refactoring...
|
61
|
+
string.gsub!('cos', 'Math.cos')
|
62
|
+
string.gsub!('sin', 'Math.sin')
|
63
|
+
string.gsub!('log', 'Math.log')
|
64
|
+
string.gsub!(' e ', ' Math::E ')
|
65
|
+
string.gsub!('pi', 'Math::PI')
|
66
|
+
string
|
67
|
+
end
|
61
68
|
end
|
data/lib/dydx/algebra.rb
CHANGED
@@ -1,20 +1,13 @@
|
|
1
|
+
require 'dydx/algebra/set'
|
2
|
+
require 'dydx/algebra/operator'
|
1
3
|
require 'dydx/algebra/formula'
|
2
4
|
require 'dydx/algebra/inverse'
|
3
5
|
|
4
|
-
require 'dydx/algebra/set'
|
5
|
-
|
6
|
-
require 'dydx/algebra/operator/inverse'
|
7
|
-
require 'dydx/algebra/operator/formula'
|
8
|
-
require 'dydx/algebra/operator/symbol'
|
9
|
-
require 'dydx/algebra/operator/num'
|
10
|
-
require 'dydx/algebra/operator/general'
|
11
|
-
|
12
6
|
module Dydx
|
13
7
|
module Algebra
|
14
8
|
include Set
|
15
9
|
module Set
|
16
10
|
# TODO: Refactor
|
17
|
-
Symbol.class_eval{ include Operator::Symbol }
|
18
11
|
Fixnum.class_eval do
|
19
12
|
alias_method :addition, :+
|
20
13
|
alias_method :subtraction, :-
|
@@ -68,10 +61,13 @@ module Dydx
|
|
68
61
|
end
|
69
62
|
end
|
70
63
|
end
|
64
|
+
Symbol.class_eval{ include Operator::General }
|
71
65
|
class Num; include Operator::Num; end
|
72
66
|
class E; include Operator::General; end
|
73
67
|
class Pi; include Operator::General; end
|
74
68
|
class Log; include Operator::General; end
|
69
|
+
class Log2; include Operator::General; end
|
70
|
+
class Log10; include Operator::General; end
|
75
71
|
class Sin; include Operator::General; end
|
76
72
|
class Cos; include Operator::General; end
|
77
73
|
class Tan; include Operator::General; end
|
@@ -1,3 +1,6 @@
|
|
1
1
|
require 'dydx/algebra/operator/parts/base'
|
2
2
|
require 'dydx/algebra/operator/parts/general'
|
3
3
|
require 'dydx/algebra/operator/parts/interface'
|
4
|
+
require 'dydx/algebra/operator/parts/formula'
|
5
|
+
require 'dydx/algebra/operator/parts/inverse'
|
6
|
+
require 'dydx/algebra/operator/parts/num'
|
@@ -13,36 +13,36 @@ module Dydx
|
|
13
13
|
else
|
14
14
|
super(x)
|
15
15
|
end
|
16
|
-
elsif formula?(
|
17
|
-
f.send(operator, x).send(
|
18
|
-
elsif formula?(
|
16
|
+
elsif formula?(operator.sub) && openable?(operator, x)
|
17
|
+
f.send(operator, x).send(operator.sub, g.send(operator, x))
|
18
|
+
elsif formula?(operator.super) && x.formula?(operator.super)
|
19
19
|
w1, w2 = common_factors(x)
|
20
|
-
return super(x) unless (w1 && w2) && (
|
20
|
+
return super(x) unless (w1 && w2) && (operator.super.commutative? || w1 == w2)
|
21
21
|
|
22
22
|
case operator
|
23
23
|
when :+
|
24
|
-
send(w1).send(
|
24
|
+
send(w1).send(operator.super, send(rest(w1)).send(operator, x.send(rest(w2))))
|
25
25
|
when :*
|
26
26
|
case w1
|
27
27
|
when :f
|
28
|
-
send(w1).send(
|
28
|
+
send(w1).send(operator.super, send(rest(w1)).send(operator.sub, x.send(rest(w2))))
|
29
29
|
when :g
|
30
|
-
send(w1).send(
|
30
|
+
send(w1).send(operator.super, send(rest(w1)).send(operator, x.send(rest(w2)))).commutate!
|
31
31
|
end
|
32
32
|
end
|
33
|
-
elsif formula?(
|
33
|
+
elsif formula?(operator.super) && x.inverse?(operator) && x.x.formula?(operator.super)
|
34
34
|
w1, w2 = common_factors(x.x)
|
35
|
-
return super(x) unless (w1 && w2) && (
|
35
|
+
return super(x) unless (w1 && w2) && (operator.super.commutative? || w1 == w2)
|
36
36
|
|
37
37
|
case operator
|
38
38
|
when :+
|
39
|
-
send(w1).send(
|
39
|
+
send(w1).send(operator.super, send(rest(w1)).send(inverse_ope(operator), x.x.send(rest(w2))))
|
40
40
|
when :*
|
41
41
|
case w1
|
42
42
|
when :f
|
43
|
-
send(w1).send(
|
43
|
+
send(w1).send(operator.super, send(rest(w1)).send(inverse_ope(operator.sub), x.x.send(rest(w2))))
|
44
44
|
when :g
|
45
|
-
send(w1).send(
|
45
|
+
send(w1).send(operator.super, send(rest(w1)).send(inverse_ope(operator), x.x.send(rest(w2)))).commutate!
|
46
46
|
end
|
47
47
|
end
|
48
48
|
else
|
@@ -53,8 +53,8 @@ module Dydx
|
|
53
53
|
|
54
54
|
%w(^).map(&:to_sym).each do |operator|
|
55
55
|
define_method(operator) do |x|
|
56
|
-
if formula?(
|
57
|
-
f.send(operator, x).send(
|
56
|
+
if formula?(operator.sub) && openable?(operator, x)
|
57
|
+
f.send(operator, x).send(operator.sub, g.send(operator, x))
|
58
58
|
else
|
59
59
|
super(x)
|
60
60
|
end
|
@@ -35,6 +35,8 @@ module Dydx
|
|
35
35
|
else
|
36
36
|
super(x)
|
37
37
|
end
|
38
|
+
elsif [:+, :*].include?(operator) && x.formula?(operator.super) && self == x.f
|
39
|
+
send(operator.super, (1 + x.g))
|
38
40
|
elsif x.is_a?(Inverse) && x.operator == operator && x.x.formula?(operator)
|
39
41
|
if combinable?(x.x.f, operator)
|
40
42
|
send(operator, inverse(x.x.f, operator)).send(operator, inverse(x.x.g, operator))
|
data/lib/dydx/algebra/set.rb
CHANGED
@@ -6,6 +6,8 @@ require 'dydx/algebra/set/symbol'
|
|
6
6
|
require 'dydx/algebra/set/e'
|
7
7
|
require 'dydx/algebra/set/pi'
|
8
8
|
require 'dydx/algebra/set/log'
|
9
|
+
require 'dydx/algebra/set/log2'
|
10
|
+
require 'dydx/algebra/set/log10'
|
9
11
|
require 'dydx/algebra/set/sin'
|
10
12
|
require 'dydx/algebra/set/cos'
|
11
13
|
require 'dydx/algebra/set/tan'
|
@@ -56,6 +58,44 @@ module Dydx
|
|
56
58
|
end
|
57
59
|
end
|
58
60
|
|
61
|
+
def log2(formula)
|
62
|
+
# TODO: refactor with log function.
|
63
|
+
if formula.multiplication?
|
64
|
+
f, g = formula.f, formula.g
|
65
|
+
log2(f) + log2(g)
|
66
|
+
elsif formula.exponentiation?
|
67
|
+
f, g = formula.f, formula.g
|
68
|
+
g * log2(f)
|
69
|
+
elsif formula.is_1?
|
70
|
+
e0
|
71
|
+
elsif formula.is_a?(Num)
|
72
|
+
(formula.n == 2) ? e1 : log2(formula.n)
|
73
|
+
elsif formula == 2
|
74
|
+
e1
|
75
|
+
else
|
76
|
+
Log2.new(formula)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def log10(formula)
|
81
|
+
# TODO: refactor with log function.
|
82
|
+
if formula.multiplication?
|
83
|
+
f, g = formula.f, formula.g
|
84
|
+
log10(f) + log10(g)
|
85
|
+
elsif formula.exponentiation?
|
86
|
+
f, g = formula.f, formula.g
|
87
|
+
g * log10(f)
|
88
|
+
elsif formula.is_1?
|
89
|
+
e0
|
90
|
+
elsif formula.is_a?(Num)
|
91
|
+
(formula.n == 10) ? e1 : log10(formula.n)
|
92
|
+
elsif formula == 10
|
93
|
+
e1
|
94
|
+
else
|
95
|
+
Log10.new(formula)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
59
99
|
def sin(x)
|
60
100
|
multiplier = x.is_multiple_of(pi)
|
61
101
|
if multiplier.is_a?(Num)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dydx
|
2
|
+
module Algebra
|
3
|
+
module Set
|
4
|
+
class Log10 < Base
|
5
|
+
attr_accessor :f
|
6
|
+
|
7
|
+
def initialize(f)
|
8
|
+
@f = f
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"log10( #{f.to_s} )"
|
13
|
+
end
|
14
|
+
|
15
|
+
def differentiate(sym=:x)
|
16
|
+
f.d(sym) / (f * log(10))
|
17
|
+
end
|
18
|
+
alias_method :d, :differentiate
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Dydx
|
2
|
+
module Algebra
|
3
|
+
module Set
|
4
|
+
class Log2 < Base
|
5
|
+
attr_accessor :f
|
6
|
+
|
7
|
+
def initialize(f)
|
8
|
+
@f = f
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"log2( #{f.to_s} )"
|
13
|
+
end
|
14
|
+
|
15
|
+
def differentiate(sym=:x)
|
16
|
+
f.d(sym) / (f * log(2))
|
17
|
+
end
|
18
|
+
alias_method :d, :differentiate
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/dydx/helper.rb
CHANGED
@@ -22,20 +22,12 @@ module Dydx
|
|
22
22
|
:| => :^
|
23
23
|
}
|
24
24
|
|
25
|
-
def super_ope(operator)
|
26
|
-
SUPER_OPE_RELATION[operator]
|
27
|
-
end
|
28
|
-
|
29
|
-
def sub_ope(operator)
|
30
|
-
SUPER_OPE_RELATION.invert[operator]
|
31
|
-
end
|
32
|
-
|
33
25
|
def inverse_ope(operator)
|
34
26
|
INVERSE_OPE_RELATION[operator]
|
35
27
|
end
|
36
28
|
|
37
29
|
def inverse_super_ope(operator)
|
38
|
-
inverse_ope(
|
30
|
+
inverse_ope(operator.super)
|
39
31
|
end
|
40
32
|
|
41
33
|
def is_num?
|
@@ -55,7 +47,7 @@ module Dydx
|
|
55
47
|
end
|
56
48
|
|
57
49
|
def distributive?(ope1, ope2)
|
58
|
-
[
|
50
|
+
[ope1.super, ope1.inverse_super].include?(ope2)
|
59
51
|
end
|
60
52
|
|
61
53
|
def combinable?(x, operator)
|
@@ -132,6 +124,18 @@ module Dydx
|
|
132
124
|
def commutative?
|
133
125
|
[:+, :*].include?(self)
|
134
126
|
end
|
127
|
+
|
128
|
+
def super
|
129
|
+
SUPER_OPE_RELATION[self] || self
|
130
|
+
end
|
131
|
+
|
132
|
+
def sub
|
133
|
+
SUPER_OPE_RELATION.invert[self] || self
|
134
|
+
end
|
135
|
+
|
136
|
+
def inverse_super
|
137
|
+
inverse_super_ope(self) || self
|
138
|
+
end
|
135
139
|
end
|
136
140
|
|
137
141
|
def ==(x)
|
data/lib/dydx/integrand.rb
CHANGED
@@ -6,21 +6,27 @@ module Dydx
|
|
6
6
|
@var = var
|
7
7
|
end
|
8
8
|
|
9
|
-
def [](a, b, n =
|
10
|
-
f = function
|
11
|
-
a, b = [a, b].map(&:to_f)
|
9
|
+
def [](a, b, n = 1000)
|
12
10
|
raise ArgumentError, 'b should be greater than a' if a > b
|
11
|
+
f = function
|
13
12
|
# HOT FIX: should implement Infinity class
|
14
13
|
a = - 1000 if a == - Float::INFINITY
|
15
14
|
b = 1000 if b == Float::INFINITY
|
16
15
|
|
16
|
+
a, b = [a, b].map(&:to_f)
|
17
|
+
n = [n, (b - a) * 2].max
|
18
|
+
n += 1 if n.to_i.odd?
|
17
19
|
h = (b - a) / n
|
18
|
-
|
19
|
-
|
20
|
-
n.
|
21
|
-
|
22
|
-
|
23
|
-
|
20
|
+
x = ->(i){ a + h * i }
|
21
|
+
|
22
|
+
odd_sum = (1..n - 1).to_a.select(&:odd?).inject(0) { |sum, i| sum += f(x.(i))}
|
23
|
+
even_sum = (1..n - 1).to_a.select(&:even?).inject(0) { |sum, i| sum += f(x.(i))}
|
24
|
+
round_8( (h / 3) * (f(a) + f(b) + 2 * even_sum + 4 * odd_sum) )
|
25
|
+
end
|
26
|
+
|
27
|
+
def round_8(num)
|
28
|
+
return num if num.abs == Float::INFINITY
|
29
|
+
(num * 10 ** 8).round * 10.0 ** (-8)
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/dydx/version.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dydx::Algebra::Set::Log10 do
|
4
|
+
it { expect(log10(1)).to eq(_(0)) }
|
5
|
+
it { expect(log10(10)).to eq(_(1)) }
|
6
|
+
it { expect(log10(10 ^ :n)).to eq(:n) }
|
7
|
+
it { expect(log10(3 ^ :n).to_s).to eq('( n * log10( 3 ) )') }
|
8
|
+
|
9
|
+
describe '#to_s' do
|
10
|
+
end
|
11
|
+
describe '#differentiate' do
|
12
|
+
it { expect(log10(:x).d(:x).to_s).to eq('( 1 / ( x * log( 10 ) ) )') }
|
13
|
+
end
|
14
|
+
describe 'Calculate' do
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Dydx::Algebra::Set::Log2 do
|
4
|
+
it { expect(log2(1)).to eq(_(0)) }
|
5
|
+
it { expect(log2(2)).to eq(_(1)) }
|
6
|
+
it { expect(log2(2 ^ :n)).to eq(:n) }
|
7
|
+
it { expect(log2(3 ^ :n).to_s).to eq('( n * log2( 3 ) )') }
|
8
|
+
|
9
|
+
describe '#to_s' do
|
10
|
+
end
|
11
|
+
describe '#differentiate' do
|
12
|
+
it { expect(log2(:x).d(:x).to_s).to eq('( 1 / ( x * log( 2 ) ) )') }
|
13
|
+
end
|
14
|
+
describe 'Calculate' do
|
15
|
+
end
|
16
|
+
end
|
data/spec/lib/integrand_spec.rb
CHANGED
@@ -15,17 +15,17 @@ describe Dydx:Integrand do
|
|
15
15
|
|
16
16
|
it 'ex2' do
|
17
17
|
f(x) <= x * x
|
18
|
-
expect(S(f(x), dx)[0, 1]).to eq(0.
|
18
|
+
expect(S(f(x), dx)[0, 1]).to eq(0.33333333)
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'ex3' do
|
22
22
|
f(x) <= sin(x)
|
23
|
-
expect(S(f(x), dx)[0, Math::PI/2]).to eq(1.
|
23
|
+
expect(S(f(x), dx)[0, Math::PI/2]).to eq(1.0)
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'ex4' do
|
27
27
|
f(x) <= cos(x)
|
28
|
-
expect(S(f(x), dx)[0, Math::PI]).to eq(
|
28
|
+
expect(S(f(x), dx)[0, Math::PI]).to eq(0.0)
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'ex5' do
|
@@ -38,16 +38,16 @@ describe Dydx:Integrand do
|
|
38
38
|
expect(f(0)).to eq(1)
|
39
39
|
expect(f(1)).to eq(1.0/Math::E)
|
40
40
|
expect(f(1000)).to eq(0)
|
41
|
-
expect(S(f(x), dx)[-1000, 1000, 3000]).to eq(1.
|
41
|
+
expect(S(f(x), dx)[-1000, 1000, 3000]).to eq(1.77239273)
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'ex7' do
|
45
45
|
f(x) <= (1.0 / ( ( 2.0 * Math::PI ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
|
46
|
-
expect(S(f(x), dx)[-1000, 1000
|
46
|
+
expect(S(f(x), dx)[-1000, 1000]).to eq(1.0)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'ex8' do
|
50
|
-
f(x) <= (1.0 / ( ( 2.0 *
|
51
|
-
expect(S(f(x), dx)[-oo, oo
|
50
|
+
f(x) <= (1.0 / ( ( 2.0 * Math::PI ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
|
51
|
+
expect(S(f(x), dx)[-oo, oo]).to eq(1.0)
|
52
52
|
end
|
53
53
|
end
|
metadata
CHANGED
@@ -1,62 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dydx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.31
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- gogotanaka
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- - ~>
|
17
|
+
- - "~>"
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '1.6'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- - ~>
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '1.6'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rake
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: rspec
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
description: Dydx is new math DSL in Ruby. The most important thing in this DSL is
|
@@ -67,9 +60,10 @@ executables: []
|
|
67
60
|
extensions: []
|
68
61
|
extra_rdoc_files: []
|
69
62
|
files:
|
70
|
-
- .gitignore
|
71
|
-
- .
|
72
|
-
- .
|
63
|
+
- ".gitignore"
|
64
|
+
- ".pryrc"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
73
67
|
- Gemfile
|
74
68
|
- LICENSE.txt
|
75
69
|
- README.md
|
@@ -79,11 +73,12 @@ files:
|
|
79
73
|
- lib/dydx/algebra.rb
|
80
74
|
- lib/dydx/algebra/formula.rb
|
81
75
|
- lib/dydx/algebra/inverse.rb
|
82
|
-
- lib/dydx/algebra/operator
|
76
|
+
- lib/dydx/algebra/operator.rb
|
83
77
|
- lib/dydx/algebra/operator/formula.rb
|
84
78
|
- lib/dydx/algebra/operator/general.rb
|
85
79
|
- lib/dydx/algebra/operator/inverse.rb
|
86
80
|
- lib/dydx/algebra/operator/num.rb
|
81
|
+
- lib/dydx/algebra/operator/parts.rb
|
87
82
|
- lib/dydx/algebra/operator/parts/base.rb
|
88
83
|
- lib/dydx/algebra/operator/parts/formula.rb
|
89
84
|
- lib/dydx/algebra/operator/parts/general.rb
|
@@ -91,7 +86,6 @@ files:
|
|
91
86
|
- lib/dydx/algebra/operator/parts/inverse.rb
|
92
87
|
- lib/dydx/algebra/operator/parts/num.rb
|
93
88
|
- lib/dydx/algebra/operator/parts/symbol.rb
|
94
|
-
- lib/dydx/algebra/operator/symbol.rb
|
95
89
|
- lib/dydx/algebra/set.rb
|
96
90
|
- lib/dydx/algebra/set/base.rb
|
97
91
|
- lib/dydx/algebra/set/cos.rb
|
@@ -99,6 +93,8 @@ files:
|
|
99
93
|
- lib/dydx/algebra/set/fixnum.rb
|
100
94
|
- lib/dydx/algebra/set/float.rb
|
101
95
|
- lib/dydx/algebra/set/log.rb
|
96
|
+
- lib/dydx/algebra/set/log10.rb
|
97
|
+
- lib/dydx/algebra/set/log2.rb
|
102
98
|
- lib/dydx/algebra/set/num.rb
|
103
99
|
- lib/dydx/algebra/set/pi.rb
|
104
100
|
- lib/dydx/algebra/set/sin.rb
|
@@ -118,6 +114,8 @@ files:
|
|
118
114
|
- spec/lib/algebra/set/e_spec.rb
|
119
115
|
- spec/lib/algebra/set/fixnum_spec.rb
|
120
116
|
- spec/lib/algebra/set/float_spec.rb
|
117
|
+
- spec/lib/algebra/set/log10_spec.rb
|
118
|
+
- spec/lib/algebra/set/log2_spec.rb
|
121
119
|
- spec/lib/algebra/set/log_spec.rb
|
122
120
|
- spec/lib/algebra/set/num_spec.rb
|
123
121
|
- spec/lib/algebra/set/pi_spec.rb
|
@@ -132,33 +130,26 @@ files:
|
|
132
130
|
homepage: https://github.com/gogotanaka
|
133
131
|
licenses:
|
134
132
|
- MIT
|
133
|
+
metadata: {}
|
135
134
|
post_install_message:
|
136
135
|
rdoc_options: []
|
137
136
|
require_paths:
|
138
137
|
- lib
|
139
138
|
required_ruby_version: !ruby/object:Gem::Requirement
|
140
|
-
none: false
|
141
139
|
requirements:
|
142
|
-
- -
|
140
|
+
- - ">="
|
143
141
|
- !ruby/object:Gem::Version
|
144
142
|
version: '0'
|
145
|
-
segments:
|
146
|
-
- 0
|
147
|
-
hash: -4040478879646027093
|
148
143
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
144
|
requirements:
|
151
|
-
- -
|
145
|
+
- - ">="
|
152
146
|
- !ruby/object:Gem::Version
|
153
147
|
version: '0'
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
hash: -4040478879646027093
|
157
148
|
requirements: []
|
158
149
|
rubyforge_project:
|
159
|
-
rubygems_version:
|
150
|
+
rubygems_version: 2.2.2
|
160
151
|
signing_key:
|
161
|
-
specification_version:
|
152
|
+
specification_version: 4
|
162
153
|
summary: We can enjoy the math.
|
163
154
|
test_files:
|
164
155
|
- spec/dydx_spec.rb
|
@@ -170,6 +161,8 @@ test_files:
|
|
170
161
|
- spec/lib/algebra/set/e_spec.rb
|
171
162
|
- spec/lib/algebra/set/fixnum_spec.rb
|
172
163
|
- spec/lib/algebra/set/float_spec.rb
|
164
|
+
- spec/lib/algebra/set/log10_spec.rb
|
165
|
+
- spec/lib/algebra/set/log2_spec.rb
|
173
166
|
- spec/lib/algebra/set/log_spec.rb
|
174
167
|
- spec/lib/algebra/set/num_spec.rb
|
175
168
|
- spec/lib/algebra/set/pi_spec.rb
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'dydx/algebra/operator/common_parts'
|
2
|
-
require 'dydx/algebra/operator/parts/symbol'
|
3
|
-
|
4
|
-
module Dydx
|
5
|
-
module Algebra
|
6
|
-
module Operator
|
7
|
-
module Symbol
|
8
|
-
include Parts::Base
|
9
|
-
include Parts::Symbol
|
10
|
-
include Parts::General
|
11
|
-
include Parts::Interface
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|