dydx 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. data/.gitignore +22 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +6 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +29 -0
  7. data/Rakefile +13 -0
  8. data/dydx.gemspec +25 -0
  9. data/lib/dydx.rb +28 -0
  10. data/lib/dydx/algebra.rb +90 -0
  11. data/lib/dydx/algebra/formula.rb +42 -0
  12. data/lib/dydx/algebra/operator/common_parts.rb +3 -0
  13. data/lib/dydx/algebra/operator/formula.rb +15 -0
  14. data/lib/dydx/algebra/operator/general.rb +14 -0
  15. data/lib/dydx/algebra/operator/num.rb +15 -0
  16. data/lib/dydx/algebra/operator/parts/base.rb +28 -0
  17. data/lib/dydx/algebra/operator/parts/formula.rb +41 -0
  18. data/lib/dydx/algebra/operator/parts/general.rb +55 -0
  19. data/lib/dydx/algebra/operator/parts/interface.rb +16 -0
  20. data/lib/dydx/algebra/operator/parts/num.rb +55 -0
  21. data/lib/dydx/algebra/operator/parts/symbol.rb +29 -0
  22. data/lib/dydx/algebra/operator/symbol.rb +15 -0
  23. data/lib/dydx/algebra/set/base.rb +9 -0
  24. data/lib/dydx/algebra/set/cos.rb +21 -0
  25. data/lib/dydx/algebra/set/e.rb +16 -0
  26. data/lib/dydx/algebra/set/fixnum.rb +28 -0
  27. data/lib/dydx/algebra/set/log.rb +22 -0
  28. data/lib/dydx/algebra/set/num.rb +22 -0
  29. data/lib/dydx/algebra/set/pi.rb +16 -0
  30. data/lib/dydx/algebra/set/sin.rb +21 -0
  31. data/lib/dydx/algebra/set/symbol.rb +14 -0
  32. data/lib/dydx/algebra/set/tan.rb +17 -0
  33. data/lib/dydx/helper.rb +38 -0
  34. data/lib/dydx/version.rb +3 -0
  35. data/spec/dydx_spec.rb +7 -0
  36. data/spec/lib/algebra/formula_spec.rb +68 -0
  37. data/spec/lib/algebra/operator/parts/base_spec.rb +8 -0
  38. data/spec/lib/algebra/operator/parts/formula_spec.rb +13 -0
  39. data/spec/lib/algebra/set/cos_spec.rb +18 -0
  40. data/spec/lib/algebra/set/e_spec.rb +27 -0
  41. data/spec/lib/algebra/set/fixnum_spec.rb +64 -0
  42. data/spec/lib/algebra/set/log_spec.rb +15 -0
  43. data/spec/lib/algebra/set/num_spec.rb +17 -0
  44. data/spec/lib/algebra/set/pi_spec.rb +25 -0
  45. data/spec/lib/algebra/set/sin_spec.rb +14 -0
  46. data/spec/lib/algebra/set/symbol_spec.rb +22 -0
  47. data/spec/lib/algebra/set/tan_spec.rb +13 -0
  48. data/spec/lib/helper_spec.rb +32 -0
  49. data/spec/spec_helper.rb +4 -0
  50. metadata +165 -0
@@ -0,0 +1,8 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Operator::Parts::Base do
4
+ it{ expect((:x + :x).to_s).to eq('( 2 * x )') }
5
+ it{ expect((:x - :x).to_s).to eq('0') }
6
+ it{ expect((:x * :x).to_s).to eq('( x ^ 2 )') }
7
+ it{ expect((:x / :x).to_s).to eq('1') }
8
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Operator::Parts::Formula do
4
+ it{ expect(((:a * :b) + (:a * :c)).to_s).to eq('( a * ( b + c ) )') }
5
+ it{ expect(((:b * :a) + (:c * :a)).to_s).to eq('( ( b + c ) * a )') }
6
+ it{ expect(((:a * :b) - (:a * :c)).to_s).to eq('( a * ( b - c ) )') }
7
+ it{ expect(((:b * :a) - (:c * :a)).to_s).to eq('( ( b - c ) * a )') }
8
+
9
+ it{ expect(((:x ^ 3) * (:x ^ 2)).to_s).to eq('( x ^ 5 )') }
10
+ it{ expect(((:x ^ 3) / (:x ^ 2)).to_s).to eq('x') }
11
+ it{ expect(((:x ^ :n) * (:y ^ :n)).to_s).to eq('( ( x * y ) ^ n )') }
12
+ it{ expect(((:x ^ :n) / (:y ^ :n)).to_s).to eq('( ( x / y ) ^ n )') }
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Cos do
4
+ it{ expect(cos(0).to_s).to eq('1') }
5
+ it{ expect(cos(pi).to_s).to eq('-1') }
6
+ it{ expect(cos(2 * pi).to_s).to eq('1') }
7
+
8
+ describe '#to_s' do
9
+ it{ expect(cos(:x).to_s).to eq('cos( x )') }
10
+ end
11
+
12
+ describe '#differentiate' do
13
+ it{ expect(cos(:x).d.to_s).to eq('( - sin( x ) )') }
14
+ end
15
+
16
+ describe 'Calculate' do
17
+ end
18
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::E do
4
+ it{ expect(e).to eq(e) }
5
+
6
+ describe '#to_s' do
7
+ it{ expect(e.to_s).to eq('e') }
8
+ end
9
+
10
+ describe '#differentiate' do
11
+ it{ expect(e.d(:x).to_s).to eq(_(0).to_s) }
12
+ it{ expect((e ^ :x).d(:x).to_s).to eq('( e ^ x )') }
13
+ it{ expect((e ^ (:x + :y)).d(:x).to_s).to eq('( e ^ ( x + y ) )') }
14
+ end
15
+
16
+ describe 'Calculate' do
17
+ context 'With Fixnum' do
18
+ it{ expect(e + 0).to eq(e) }
19
+ it{ expect(e - 0).to eq(e) }
20
+ it{ expect((e * 0).to_s).to eq('0') }
21
+ it{ expect(e * 1).to eq(e) }
22
+ it{ expect{(e / 0).to_s}.to raise_error(ZeroDivisionError) }
23
+ it{ expect(e / 1).to eq(e) }
24
+ it{ expect((e ^ 0).to_s).to eq('1') }
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,64 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fixnum do
4
+ describe '#to_s' do
5
+ it{ expect(1.to_s).to eq('1') }
6
+ end
7
+
8
+ describe '#differentiate' do
9
+ it{ expect(3.d(:x).to_s).to eq('0') }
10
+ end
11
+
12
+ describe 'Calculate' do
13
+ context 'With Formula' do
14
+ let(:formula) { (:x + :y) }
15
+ it{ expect((0 + formula).to_s).to eq(formula.to_s) }
16
+ it{ expect((0 - formula).to_s).to eq('( - ( x + y ) )') }
17
+ it{ expect((0 * formula).to_s).to eq('0') }
18
+ it{ expect((1 * formula).to_s).to eq(formula.to_s) }
19
+ it{ expect((0 / formula).to_s).to eq('0') }
20
+ it{ expect((1 / formula).to_s).to eq('( 1 / ( x + y ) )') }
21
+ it{ expect((0 ^ formula).to_s).to eq('0') }
22
+ it{ expect((1 ^ formula).to_s).to eq('1') }
23
+ end
24
+
25
+ context 'With Symbol' do
26
+ it{ expect(0 + :x).to eq(:x) }
27
+ it{ expect((0 - :x).to_s).to eq('( - x )') }
28
+ it{ expect((0 * :x).to_s).to eq('0') }
29
+ it{ expect(1 * :x).to eq(:x) }
30
+ it{ expect((0 / :x).to_s).to eq('0') }
31
+ it{ expect((1 / :x).to_s).to eq('( 1 / x )') }
32
+ it{ expect((0 ^ :x).to_s).to eq('0') }
33
+ it{ expect((1 ^ :x).to_s).to eq('1') }
34
+ end
35
+
36
+ context 'With Fixnum' do
37
+ it{ expect(0 + 3).to eq(3) }
38
+ it{ expect(3 + 0).to eq(3) }
39
+ it{ expect(2 + 3).to eq(5) }
40
+
41
+ it{ expect(0 - 3).to eq(-3) }
42
+ it{ expect(3 - 0).to eq(3) }
43
+ it{ expect(2 - 3).to eq(-1) }
44
+
45
+ it{ expect(0 * 3).to eq(0) }
46
+ it{ expect(3 * 0).to eq(0) }
47
+ it{ expect(1 * 3).to eq(3) }
48
+ it{ expect(3 * 1).to eq(3) }
49
+ it{ expect(3 * 2).to eq(6) }
50
+
51
+ it{ expect((0 / 3).to_s).to eq('0') }
52
+ it{ expect{(3 / 0).to_s}.to raise_error(ZeroDivisionError) }
53
+ it{ expect((3 / 1).to_s).to eq('3') }
54
+ it{ expect((2 / 3).to_s).to eq('( 2 / 3 )') }
55
+
56
+
57
+ it{ expect((0 ^ 3).to_s).to eq('0') }
58
+ it{ expect((3 ^ 0).to_s).to eq('1') }
59
+ it{ expect((1 ^ 3).to_s).to eq('1') }
60
+ it{ expect((3 ^ 1).to_s).to eq('3') }
61
+ it{ expect((3 ^ 2).to_s).to eq('( 3 ^ 2 )') }
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Log do
4
+ it{ expect(log(1)).to eq(_(0)) }
5
+ it{ expect(log(e)).to eq(_(1)) }
6
+ it{ expect(log(e ^ :n)).to eq(:n) }
7
+
8
+ describe '#to_s' do
9
+ end
10
+ describe '#differentiate' do
11
+ it{ expect(log(:x).d(:x).to_s).to eq('( 1 / x )') }
12
+ end
13
+ describe 'Calculate' do
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Num do
4
+ it{ expect(_(1)).to eq(_(1)) }
5
+ it{ expect(_(-1)).to eq(_(-1)) }
6
+
7
+ describe '#to_s' do
8
+ it{ expect(_(1).to_s).to eq('1') }
9
+ end
10
+
11
+ describe '#differentiate' do
12
+ it{ expect(_(1).d(:x).to_s).to eq(_(0).to_s) }
13
+ end
14
+
15
+ describe 'Calculate' do
16
+ end
17
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Pi do
4
+ it{ expect(pi).to eq(pi) }
5
+
6
+ describe '#to_s' do
7
+ it{ expect(pi.to_s).to eq('pi') }
8
+ end
9
+
10
+ describe '#differentiate' do
11
+ it{ expect(pi.d(:x).to_s).to eq(_(0).to_s) }
12
+ end
13
+
14
+ describe 'Calculate' do
15
+ context 'With Fixnum' do
16
+ it{ expect(pi + 0).to eq(pi) }
17
+ it{ expect(pi - 0).to eq(pi) }
18
+ it{ expect((pi * 0).to_s).to eq('0') }
19
+ it{ expect(pi * 1).to eq(pi) }
20
+ it{ expect{(pi / 0).to_s}.to raise_error(ZeroDivisionError) }
21
+ it{ expect(pi / 1).to eq(pi) }
22
+ it{ expect((pi ^ 0).to_s).to eq('1') }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Sin do
4
+ it{ expect(sin(pi)).to eq(_(0)) }
5
+
6
+ describe '#to_s' do
7
+ it{ expect(sin(:x).to_s).to eq('sin( x )') }
8
+ end
9
+ describe '#differentiate' do
10
+ it{ expect(sin(:x).d.to_s).to eq('cos( x )') }
11
+ end
12
+ describe 'Calculate' do
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Symbol do
4
+ describe '#to_s' do
5
+ it{ expect(:x.to_s).to eq('x') }
6
+ end
7
+ describe '#differentiate' do
8
+ it{ expect(:x.d(:x).to_s).to eq('1') }
9
+ end
10
+ describe 'Calculate' do
11
+ context 'With Fixnum' do
12
+ it{ expect(:x + 0).to eq(:x) }
13
+ it{ expect(:x - 0).to eq(:x) }
14
+ it{ expect((:x * 0).to_s).to eq('0') }
15
+ it{ expect(:x * 1).to eq(:x) }
16
+ it{ expect{(:x / 0).to_s}.to raise_error(ZeroDivisionError) }
17
+ it{ expect(:x / 1).to eq(:x) }
18
+ it{ expect((:x ^ 0).to_s).to eq('1') }
19
+ it{ expect(:x ^ 1).to eq(:x) }
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Dydx::Algebra::Set::Tan do
4
+ describe '#to_s' do
5
+ it{ expect(tan(:x).to_s).to eq('tan( x )') }
6
+ end
7
+
8
+ describe '#differentiate' do
9
+ end
10
+
11
+ describe 'Calculate' do
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe Helper do
4
+ it{ expect(0.is_0?).to be_true }
5
+ it{ expect(_(0).is_0?).to be_true }
6
+ it{ expect(1.is_1?).to be_true }
7
+ it{ expect(_(1).is_1?).to be_true }
8
+ it{ expect(-1.is_minus1?).to be_true }
9
+ it{ expect(_(-1).is_minus1?).to be_true }
10
+
11
+ it{ expect(0.is_multiple_of(:x).to_s).to eq('0') }
12
+ it{ expect(_(0).is_multiple_of(:y).to_s).to eq('0')}
13
+
14
+ it{ expect(:x.is_multiple_of(:x).to_s).to eq('1') }
15
+ it{ expect(:x.is_multiple_of(:y)).to be_false }
16
+
17
+ it{ expect((:x * :y).is_multiple_of(:x)).to eq(:y) }
18
+ it{ expect((:x * :y).is_multiple_of(:y)).to eq(:x) }
19
+ it{ expect((:x * :y).is_multiple_of(:z)).to be_false }
20
+
21
+ let(:addition) { (:x + :y) }
22
+ let(:subtraction) { (:x - :y) }
23
+ let(:multiplication){ (:x * :y) }
24
+ let(:division) { (:x / :y) }
25
+ let(:exponentiation){ (:x ^ :y) }
26
+
27
+ it{ expect(addition.addition?).to be_true }
28
+ it{ expect(subtraction.subtraction?).to be_true }
29
+ it{ expect(multiplication.multiplication?).to be_true }
30
+ it{ expect(division.division?).to be_true }
31
+ it{ expect(exponentiation.exponentiation?).to be_true }
32
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'dydx'
3
+ require 'pry'
4
+ include Dydx
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dydx
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - gogotanaka
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: It is possible to use the differential using the Symbol and Fixnum by
63
+ including the Dydx. And, we can use the natural logarithm and log.
64
+ email:
65
+ - qlli.illb@gmail.com
66
+ executables: []
67
+ extensions: []
68
+ extra_rdoc_files: []
69
+ files:
70
+ - .gitignore
71
+ - .rspec
72
+ - .travis.yml
73
+ - Gemfile
74
+ - LICENSE.txt
75
+ - README.md
76
+ - Rakefile
77
+ - dydx.gemspec
78
+ - lib/dydx.rb
79
+ - lib/dydx/algebra.rb
80
+ - lib/dydx/algebra/formula.rb
81
+ - lib/dydx/algebra/operator/common_parts.rb
82
+ - lib/dydx/algebra/operator/formula.rb
83
+ - lib/dydx/algebra/operator/general.rb
84
+ - lib/dydx/algebra/operator/num.rb
85
+ - lib/dydx/algebra/operator/parts/base.rb
86
+ - lib/dydx/algebra/operator/parts/formula.rb
87
+ - lib/dydx/algebra/operator/parts/general.rb
88
+ - lib/dydx/algebra/operator/parts/interface.rb
89
+ - lib/dydx/algebra/operator/parts/num.rb
90
+ - lib/dydx/algebra/operator/parts/symbol.rb
91
+ - lib/dydx/algebra/operator/symbol.rb
92
+ - lib/dydx/algebra/set/base.rb
93
+ - lib/dydx/algebra/set/cos.rb
94
+ - lib/dydx/algebra/set/e.rb
95
+ - lib/dydx/algebra/set/fixnum.rb
96
+ - lib/dydx/algebra/set/log.rb
97
+ - lib/dydx/algebra/set/num.rb
98
+ - lib/dydx/algebra/set/pi.rb
99
+ - lib/dydx/algebra/set/sin.rb
100
+ - lib/dydx/algebra/set/symbol.rb
101
+ - lib/dydx/algebra/set/tan.rb
102
+ - lib/dydx/helper.rb
103
+ - lib/dydx/version.rb
104
+ - spec/dydx_spec.rb
105
+ - spec/lib/algebra/formula_spec.rb
106
+ - spec/lib/algebra/operator/parts/base_spec.rb
107
+ - spec/lib/algebra/operator/parts/formula_spec.rb
108
+ - spec/lib/algebra/set/cos_spec.rb
109
+ - spec/lib/algebra/set/e_spec.rb
110
+ - spec/lib/algebra/set/fixnum_spec.rb
111
+ - spec/lib/algebra/set/log_spec.rb
112
+ - spec/lib/algebra/set/num_spec.rb
113
+ - spec/lib/algebra/set/pi_spec.rb
114
+ - spec/lib/algebra/set/sin_spec.rb
115
+ - spec/lib/algebra/set/symbol_spec.rb
116
+ - spec/lib/algebra/set/tan_spec.rb
117
+ - spec/lib/helper_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/gogotanaka
120
+ licenses:
121
+ - MIT
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ segments:
133
+ - 0
134
+ hash: 4103525150309275403
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ none: false
137
+ requirements:
138
+ - - ! '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ segments:
142
+ - 0
143
+ hash: 4103525150309275403
144
+ requirements: []
145
+ rubyforge_project:
146
+ rubygems_version: 1.8.23
147
+ signing_key:
148
+ specification_version: 3
149
+ summary: We can enjoy the derivative.
150
+ test_files:
151
+ - spec/dydx_spec.rb
152
+ - spec/lib/algebra/formula_spec.rb
153
+ - spec/lib/algebra/operator/parts/base_spec.rb
154
+ - spec/lib/algebra/operator/parts/formula_spec.rb
155
+ - spec/lib/algebra/set/cos_spec.rb
156
+ - spec/lib/algebra/set/e_spec.rb
157
+ - spec/lib/algebra/set/fixnum_spec.rb
158
+ - spec/lib/algebra/set/log_spec.rb
159
+ - spec/lib/algebra/set/num_spec.rb
160
+ - spec/lib/algebra/set/pi_spec.rb
161
+ - spec/lib/algebra/set/sin_spec.rb
162
+ - spec/lib/algebra/set/symbol_spec.rb
163
+ - spec/lib/algebra/set/tan_spec.rb
164
+ - spec/lib/helper_spec.rb
165
+ - spec/spec_helper.rb