dydx 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dydx/algebra.rb +4 -0
- data/lib/dydx/algebra/operator/parts/formula.rb +27 -3
- data/lib/dydx/algebra/operator/parts/num.rb +2 -0
- data/lib/dydx/algebra/set/num.rb +4 -0
- data/lib/dydx/version.rb +1 -1
- data/spec/lib/algebra/formula_spec.rb +6 -0
- data/spec/lib/algebra/operator/parts/formula_spec.rb +12 -0
- data/spec/lib/algebra/set/num_spec.rb +4 -0
- metadata +29 -15
- checksums.yaml +0 -7
data/lib/dydx/algebra.rb
CHANGED
@@ -3,7 +3,7 @@ module Dydx
|
|
3
3
|
module Operator
|
4
4
|
module Parts
|
5
5
|
module Formula
|
6
|
-
%w(+ -).each do |operator|
|
6
|
+
%w(+ -).map(&:to_sym).each do |operator|
|
7
7
|
define_method(operator) do |x|
|
8
8
|
if multiplication? && x.multiplication?
|
9
9
|
if f == x.f
|
@@ -13,22 +13,46 @@ module Dydx
|
|
13
13
|
else
|
14
14
|
super(x)
|
15
15
|
end
|
16
|
+
elsif ([self.operator, operator].sort == [:+, :-]) && ( f == x || g == x )
|
17
|
+
if f == x
|
18
|
+
g
|
19
|
+
elsif g == x
|
20
|
+
f
|
21
|
+
end
|
22
|
+
elsif (self.operator == operator) && ( f == x || g == x )
|
23
|
+
if f == x
|
24
|
+
f.send(operator, x).send(operator, g)
|
25
|
+
elsif g == x
|
26
|
+
f.send(operator, g.send(:+, x))
|
27
|
+
end
|
16
28
|
else
|
17
29
|
super(x)
|
18
30
|
end
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
22
|
-
%w(* /).each do |operator|
|
34
|
+
%w(* /).map(&:to_sym).each do |operator|
|
23
35
|
define_method(operator) do |x|
|
24
36
|
if exponentiation? && x.exponentiation?
|
25
37
|
if f == x.f
|
26
|
-
f ^ g.send({'*'=>'+', '/'=>'-'}[operator], x.g)
|
38
|
+
f ^ g.send({'*'=>'+', '/'=>'-'}[operator.to_s], x.g)
|
27
39
|
elsif g == x.g
|
28
40
|
f.send(operator, x.f) ^ g
|
29
41
|
else
|
30
42
|
super(x)
|
31
43
|
end
|
44
|
+
elsif ([self.operator, operator].sort == [:*, :/]) && ( f == x || g == x )
|
45
|
+
if f == x
|
46
|
+
g
|
47
|
+
elsif g == x
|
48
|
+
f
|
49
|
+
end
|
50
|
+
elsif (self.operator == operator) && ( f == x || g == x )
|
51
|
+
if f == x
|
52
|
+
f.send(operator, x).send(operator, g)
|
53
|
+
elsif g == x
|
54
|
+
f.send(operator, g.send(:* , x))
|
55
|
+
end
|
32
56
|
else
|
33
57
|
super(x)
|
34
58
|
end
|
data/lib/dydx/algebra/set/num.rb
CHANGED
data/lib/dydx/version.rb
CHANGED
@@ -65,4 +65,10 @@ describe Dydx::Algebra::Formula do
|
|
65
65
|
it{ expect(d1.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
|
66
66
|
it{ expect(d2.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
|
67
67
|
end
|
68
|
+
|
69
|
+
$c = (:t ^ 2) / 2
|
70
|
+
let(:d1){ dc/dt }
|
71
|
+
let(:d2){ d/dt($c) }
|
72
|
+
it{ expect(d1.to_s).to eq('t') }
|
73
|
+
it{ expect(d2.to_s).to eq('t') }
|
68
74
|
end
|
@@ -10,4 +10,16 @@ describe Dydx::Algebra::Operator::Parts::Formula do
|
|
10
10
|
it{ expect(((:x ^ 3) / (:x ^ 2)).to_s).to eq('x') }
|
11
11
|
it{ expect(((:x ^ :n) * (:y ^ :n)).to_s).to eq('( ( x * y ) ^ n )') }
|
12
12
|
it{ expect(((:x ^ :n) / (:y ^ :n)).to_s).to eq('( ( x / y ) ^ n )') }
|
13
|
+
|
14
|
+
it{ expect(((:x - 2) + 2).to_s).to eq('x') }
|
15
|
+
it{ expect(((:x + 2) - 2).to_s).to eq('x') }
|
16
|
+
it{ expect(((:x * 2) / 2).to_s).to eq('x') }
|
17
|
+
it{ expect(((:x / 2) * 2).to_s).to eq('x') }
|
18
|
+
|
19
|
+
it{ expect(((:x + :y) + :y).to_s).to eq('( x + ( 2 * y ) )') }
|
20
|
+
it{ expect(((:x - :y) - :y).to_s).to eq('( x - ( 2 * y ) )') }
|
21
|
+
it{ expect(((:y - :x) - :y).to_s).to eq('( - x )') }
|
22
|
+
it{ expect(((:x * :y) * :y).to_s).to eq('( x * ( y ^ 2 ) )') }
|
23
|
+
it{ expect(((:x / :y) / :y).to_s).to eq('( x / ( y ^ 2 ) )') }
|
24
|
+
it{ expect(((:y / :x) / :y).to_s).to eq('( 1 / x )') }
|
13
25
|
end
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
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.3
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- gogotanaka
|
@@ -13,43 +14,49 @@ 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
|
@@ -113,26 +120,33 @@ files:
|
|
113
120
|
homepage: https://github.com/gogotanaka
|
114
121
|
licenses:
|
115
122
|
- MIT
|
116
|
-
metadata: {}
|
117
123
|
post_install_message:
|
118
124
|
rdoc_options: []
|
119
125
|
require_paths:
|
120
126
|
- lib
|
121
127
|
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
122
129
|
requirements:
|
123
|
-
- -
|
130
|
+
- - ! '>='
|
124
131
|
- !ruby/object:Gem::Version
|
125
132
|
version: '0'
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
hash: 3588905385522331028
|
126
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
127
138
|
requirements:
|
128
|
-
- -
|
139
|
+
- - ! '>='
|
129
140
|
- !ruby/object:Gem::Version
|
130
141
|
version: '0'
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
hash: 3588905385522331028
|
131
145
|
requirements: []
|
132
146
|
rubyforge_project:
|
133
|
-
rubygems_version:
|
147
|
+
rubygems_version: 1.8.23
|
134
148
|
signing_key:
|
135
|
-
specification_version:
|
149
|
+
specification_version: 3
|
136
150
|
summary: We can enjoy the derivative.
|
137
151
|
test_files:
|
138
152
|
- spec/dydx_spec.rb
|
checksums.yaml
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
---
|
2
|
-
SHA1:
|
3
|
-
metadata.gz: 8ec6bd373a47873bdafe89c3d13330f76ba28e0c
|
4
|
-
data.tar.gz: d65b0b2e28ba2e7af9448fbc85faff29b469497f
|
5
|
-
SHA512:
|
6
|
-
metadata.gz: 50c0d17b503141dffc4ee4268cfce736ba72c50e9eda312ecdfd4f6b8a121210132ec58142c6145cff4169337dac1386fc5d61fb576da63ddc2e92abfa5d3816
|
7
|
-
data.tar.gz: 065b046b6f972ffb1c46c2ff6312cd9c659be35dddc7ef39d189762b01ebff7a80df34ab3a304128b86d3addeb056057dd647e10ab32800d9f33e409248ddbd9
|