dydx 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dydx.rb +2 -3
- data/lib/dydx/algebra/set.rb +4 -4
- data/lib/dydx/algebra/set/e.rb +2 -2
- data/lib/dydx/algebra/set/fixnum.rb +1 -1
- data/lib/dydx/algebra/set/num.rb +3 -3
- data/lib/dydx/algebra/set/symbol.rb +2 -2
- data/lib/dydx/algebra/set/tan.rb +1 -1
- data/lib/dydx/helper.rb +3 -3
- data/lib/dydx/version.rb +1 -1
- data/spec/lib/algebra/formula_spec.rb +18 -18
- data/spec/lib/algebra/operator/parts/formula_spec.rb +4 -3
- data/spec/lib/algebra/set/fixnum_spec.rb +4 -3
- metadata +30 -16
- checksums.yaml +0 -7
data/lib/dydx.rb
CHANGED
@@ -21,8 +21,7 @@ module Dydx
|
|
21
21
|
|
22
22
|
def method_missing(method, *args, &block)
|
23
23
|
method_name = method.to_s
|
24
|
-
return super unless
|
25
|
-
method_name.
|
26
|
-
Delta.new(method_name.empty? ? nil : method_name.to_sym, args.first)
|
24
|
+
return super unless method_name =~ /^d.?$/
|
25
|
+
Delta.new(method_name[1] ? method_name[1].to_sym : nil, args.first)
|
27
26
|
end
|
28
27
|
end
|
data/lib/dydx/algebra/set.rb
CHANGED
@@ -43,9 +43,9 @@ module Dydx
|
|
43
43
|
f, g = formula.f, formula.g
|
44
44
|
g * log(f)
|
45
45
|
elsif formula.is_1?
|
46
|
-
|
46
|
+
e0
|
47
47
|
elsif formula.is_a?(E)
|
48
|
-
|
48
|
+
e1
|
49
49
|
else
|
50
50
|
Log.new(formula)
|
51
51
|
end
|
@@ -54,7 +54,7 @@ module Dydx
|
|
54
54
|
def sin(x)
|
55
55
|
multiplier = x.is_multiple_of(pi)
|
56
56
|
if multiplier.is_a?(Num)
|
57
|
-
|
57
|
+
e0
|
58
58
|
else
|
59
59
|
Sin.new(x)
|
60
60
|
end
|
@@ -63,7 +63,7 @@ module Dydx
|
|
63
63
|
def cos(x)
|
64
64
|
multiplier = x.is_multiple_of(pi)
|
65
65
|
if multiplier.is_a?(Num) && multiplier.n % 2 == 0
|
66
|
-
|
66
|
+
e1
|
67
67
|
elsif multiplier.is_a?(Num) && multiplier.n % 2 == 1
|
68
68
|
_(-1)
|
69
69
|
else
|
data/lib/dydx/algebra/set/e.rb
CHANGED
data/lib/dydx/algebra/set/num.rb
CHANGED
@@ -9,7 +9,7 @@ module Dydx
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def differentiate(sym=:x)
|
12
|
-
|
12
|
+
e0
|
13
13
|
end
|
14
14
|
alias_method :d, :differentiate
|
15
15
|
|
@@ -18,9 +18,9 @@ module Dydx
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def ==(x)
|
21
|
-
|
21
|
+
to_s == x.to_s
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
26
|
-
end
|
26
|
+
end
|
data/lib/dydx/algebra/set/tan.rb
CHANGED
data/lib/dydx/helper.rb
CHANGED
@@ -8,11 +8,11 @@ module Dydx
|
|
8
8
|
}
|
9
9
|
|
10
10
|
def is_0?
|
11
|
-
self == 0 || (is_a?(Num) && n == 0)
|
11
|
+
self == 0 || (is_a?(Num) && n == 0)
|
12
12
|
end
|
13
13
|
|
14
14
|
def is_1?
|
15
|
-
self == 1 || (is_a?(Num) && n == 1)
|
15
|
+
self == 1 || (is_a?(Num) && n == 1)
|
16
16
|
end
|
17
17
|
|
18
18
|
def is_minus1?
|
@@ -122,4 +122,4 @@ module Dydx
|
|
122
122
|
is_a?(Inverse) && operator == :*
|
123
123
|
end
|
124
124
|
end
|
125
|
-
end
|
125
|
+
end
|
data/lib/dydx/version.rb
CHANGED
@@ -9,13 +9,13 @@ describe Dydx::Algebra::Formula do
|
|
9
9
|
describe 'Calculate' do
|
10
10
|
context 'With Fixnum' do
|
11
11
|
let(:formula) { (:x + :y) }
|
12
|
-
it{ expect(formula + 0).to eq(formula
|
13
|
-
it{ expect(formula - 0).to eq(formula
|
14
|
-
it{ expect(
|
15
|
-
it{ expect(
|
12
|
+
it{ expect(formula + 0).to eq(formula) }
|
13
|
+
it{ expect(formula - 0).to eq(formula) }
|
14
|
+
it{ expect(formula * 0).to eq(0) }
|
15
|
+
it{ expect(formula * 1).to eq(formula) }
|
16
16
|
it{ expect{(formula / 0).to_s}.to raise_error(ZeroDivisionError) }
|
17
17
|
it{ expect(formula / 1).to eq(formula) }
|
18
|
-
it{ expect(
|
18
|
+
it{ expect(formula ^ 0).to eq(1) }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
@@ -29,25 +29,25 @@ describe Dydx::Algebra::Formula do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#differentiate' do
|
32
|
-
it{ expect(addition.d(:x)
|
33
|
-
it{ expect(addition.d(:y)
|
34
|
-
it{ expect(addition.d(:z)
|
32
|
+
it{ expect(addition.d(:x)).to eq(1) }
|
33
|
+
it{ expect(addition.d(:y)).to eq(1) }
|
34
|
+
it{ expect(addition.d(:z)).to eq(0) }
|
35
35
|
|
36
|
-
it{ expect(subtraction.d(:x)
|
37
|
-
it{ expect(subtraction.d(:y)
|
38
|
-
it{ expect(subtraction.d(:z)
|
36
|
+
it{ expect(subtraction.d(:x)).to eq(1) }
|
37
|
+
it{ expect(subtraction.d(:y)).to eq('( - 1 )') }
|
38
|
+
it{ expect(subtraction.d(:z)).to eq(0) }
|
39
39
|
|
40
40
|
it{ expect(multiplication.d(:x)).to eq(:y) }
|
41
41
|
it{ expect(multiplication.d(:y)).to eq(:x) }
|
42
|
-
it{ expect(multiplication.d(:z)
|
42
|
+
it{ expect(multiplication.d(:z)).to eq(0) }
|
43
43
|
|
44
|
-
it{ expect(division.d(:x)
|
45
|
-
it{ expect(division.d(:y)
|
46
|
-
it{ expect(division.d(:z)
|
44
|
+
it{ expect(division.d(:x)).to eq(1/:y) }
|
45
|
+
it{ expect(division.d(:y)).to eq('( - ( x / ( y ^ 2 ) ) )') }
|
46
|
+
it{ expect(division.d(:z)).to eq(0) }
|
47
47
|
|
48
48
|
it{ expect(exponentiation.d(:x).to_s).to eq('( y * ( x ^ ( y - 1 ) ) )') }
|
49
|
-
it{ expect(exponentiation.d(:y)
|
50
|
-
it{ expect(exponentiation.d(:z)
|
49
|
+
it{ expect(exponentiation.d(:y)).to eq((:x ^ :y) * log(:x)) }
|
50
|
+
it{ expect(exponentiation.d(:z)).to eq(0) }
|
51
51
|
end
|
52
52
|
|
53
53
|
describe '#include?' do
|
@@ -59,4 +59,4 @@ describe Dydx::Algebra::Formula do
|
|
59
59
|
it{ expect((1 + :x).openable?(_(1))).to be_true }
|
60
60
|
it{ expect((1 + :x).openable?(:z)).to be_false }
|
61
61
|
end
|
62
|
-
end
|
62
|
+
end
|
@@ -50,6 +50,7 @@ describe Dydx::Algebra::Operator::Parts::Formula do
|
|
50
50
|
it{ expect(((:x * 2) ^ 2).to_s).to eq('( ( x ^ 2 ) * 4 )') }
|
51
51
|
it{ expect(((:x / 2) ^ 2).to_s).to eq('( ( x ^ 2 ) / 4 )') }
|
52
52
|
|
53
|
-
|
54
|
-
it{ expect((2 ^ (:x
|
55
|
-
|
53
|
+
# TODO:
|
54
|
+
it{ expect((2 ^ (:x * 2)).to_s).to eq('( 2 ^ ( x * 2 ) )') }
|
55
|
+
it{ expect((2 ^ (:x / 2)).to_s).to eq('( 2 ^ ( x / 2 ) )') }
|
56
|
+
end
|
@@ -49,16 +49,17 @@ describe Fixnum do
|
|
49
49
|
it{ expect(3 * 2).to eq(6) }
|
50
50
|
|
51
51
|
it{ expect((0 / 3).to_s).to eq('0') }
|
52
|
-
it{ expect{(3 / 0).to_s}.to raise_error(
|
52
|
+
it{ expect{(3 / 0).to_s}.to raise_error(FloatDomainError) }
|
53
53
|
it{ expect((3 / 1).to_s).to eq('3') }
|
54
|
-
|
54
|
+
# TODO:
|
55
|
+
it{ expect((2 / 3).to_s).to eq('0') }
|
55
56
|
|
56
57
|
|
57
58
|
it{ expect((0 ^ 3).to_s).to eq('0') }
|
58
59
|
it{ expect((3 ^ 0).to_s).to eq('1') }
|
59
60
|
it{ expect((1 ^ 3).to_s).to eq('1') }
|
60
61
|
it{ expect((3 ^ 1).to_s).to eq('3') }
|
61
|
-
it{ expect((3 ^ 2).to_s).to eq('
|
62
|
+
it{ expect((3 ^ 2).to_s).to eq('9') }
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
metadata
CHANGED
@@ -1,55 +1,62 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dydx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- gogotanaka
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
|
-
- -
|
19
|
+
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '1.6'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
23
26
|
requirements:
|
24
|
-
- -
|
27
|
+
- - ~>
|
25
28
|
- !ruby/object:Gem::Version
|
26
29
|
version: '1.6'
|
27
30
|
- !ruby/object:Gem::Dependency
|
28
31
|
name: rake
|
29
32
|
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
30
34
|
requirements:
|
31
|
-
- -
|
35
|
+
- - ! '>='
|
32
36
|
- !ruby/object:Gem::Version
|
33
37
|
version: '0'
|
34
38
|
type: :development
|
35
39
|
prerelease: false
|
36
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
37
42
|
requirements:
|
38
|
-
- -
|
43
|
+
- - ! '>='
|
39
44
|
- !ruby/object:Gem::Version
|
40
45
|
version: '0'
|
41
46
|
- !ruby/object:Gem::Dependency
|
42
47
|
name: rspec
|
43
48
|
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
44
50
|
requirements:
|
45
|
-
- -
|
51
|
+
- - ! '>='
|
46
52
|
- !ruby/object:Gem::Version
|
47
53
|
version: '0'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ! '>='
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
description: It is possible to use the differential using the Symbol and Fixnum by
|
@@ -60,9 +67,9 @@ executables: []
|
|
60
67
|
extensions: []
|
61
68
|
extra_rdoc_files: []
|
62
69
|
files:
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
70
|
+
- .gitignore
|
71
|
+
- .rspec
|
72
|
+
- .travis.yml
|
66
73
|
- Gemfile
|
67
74
|
- LICENSE.txt
|
68
75
|
- README.md
|
@@ -117,26 +124,33 @@ files:
|
|
117
124
|
homepage: https://github.com/gogotanaka
|
118
125
|
licenses:
|
119
126
|
- MIT
|
120
|
-
metadata: {}
|
121
127
|
post_install_message:
|
122
128
|
rdoc_options: []
|
123
129
|
require_paths:
|
124
130
|
- lib
|
125
131
|
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
none: false
|
126
133
|
requirements:
|
127
|
-
- -
|
134
|
+
- - ! '>='
|
128
135
|
- !ruby/object:Gem::Version
|
129
136
|
version: '0'
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
hash: -4588855111168317577
|
130
140
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
131
142
|
requirements:
|
132
|
-
- -
|
143
|
+
- - ! '>='
|
133
144
|
- !ruby/object:Gem::Version
|
134
145
|
version: '0'
|
146
|
+
segments:
|
147
|
+
- 0
|
148
|
+
hash: -4588855111168317577
|
135
149
|
requirements: []
|
136
150
|
rubyforge_project:
|
137
|
-
rubygems_version:
|
151
|
+
rubygems_version: 1.8.23
|
138
152
|
signing_key:
|
139
|
-
specification_version:
|
153
|
+
specification_version: 3
|
140
154
|
summary: We can enjoy the derivative.
|
141
155
|
test_files:
|
142
156
|
- spec/dydx_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 50b217dcece3200df260f85267cc8eb9962327d1
|
4
|
-
data.tar.gz: c1f0fad073894322d1fe70198ad12ec81eeb7fc3
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 20a5be7e5853dbb70910c8595a509a903882a58d7393bffe44d809e37d38910aefbe17024bd82c27e6ed1084895cdd1d74dc0765a033d852f3d4187d1b8e12a1
|
7
|
-
data.tar.gz: bcb0c305f6d9befd7de5b1c415bf522c012adfb910fe4707efdaeaf745d3cdb1391c64f6ea3e94f7e39d29c8e5369a12626c0b4eb57f48bdad18bf4f1372ed07
|