dydx 0.1.4 → 0.1.25

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -3
  3. data/README.md +124 -61
  4. data/Rakefile +8 -5
  5. data/dydx.gemspec +13 -13
  6. data/lib/dydx.rb +25 -23
  7. data/lib/dydx/algebra.rb +76 -8
  8. data/lib/dydx/algebra/formula.rb +38 -71
  9. data/lib/dydx/algebra/inverse.rb +12 -19
  10. data/lib/dydx/algebra/operator/common_parts.rb +3 -0
  11. data/lib/dydx/algebra/operator/formula.rb +4 -0
  12. data/lib/dydx/algebra/operator/general.rb +4 -0
  13. data/lib/dydx/algebra/operator/inverse.rb +4 -0
  14. data/lib/dydx/algebra/operator/num.rb +4 -0
  15. data/lib/dydx/algebra/operator/parts/base.rb +2 -2
  16. data/lib/dydx/algebra/operator/parts/formula.rb +38 -63
  17. data/lib/dydx/algebra/operator/parts/general.rb +31 -84
  18. data/lib/dydx/algebra/operator/parts/interface.rb +22 -0
  19. data/lib/dydx/algebra/operator/parts/inverse.rb +4 -4
  20. data/lib/dydx/algebra/operator/parts/num.rb +11 -16
  21. data/lib/dydx/algebra/operator/parts/symbol.rb +2 -2
  22. data/lib/dydx/algebra/operator/symbol.rb +15 -0
  23. data/lib/dydx/algebra/set.rb +34 -271
  24. data/lib/dydx/algebra/set/base.rb +9 -0
  25. data/lib/dydx/algebra/set/cos.rb +22 -0
  26. data/lib/dydx/algebra/set/e.rb +16 -0
  27. data/lib/dydx/algebra/set/fixnum.rb +14 -0
  28. data/lib/dydx/algebra/set/float.rb +14 -0
  29. data/lib/dydx/algebra/set/log.rb +22 -0
  30. data/lib/dydx/algebra/set/num.rb +26 -0
  31. data/lib/dydx/algebra/set/pi.rb +16 -0
  32. data/lib/dydx/algebra/set/sin.rb +21 -0
  33. data/lib/dydx/algebra/set/symbol.rb +14 -0
  34. data/lib/dydx/algebra/set/tan.rb +17 -0
  35. data/lib/dydx/delta.rb +1 -1
  36. data/lib/dydx/function.rb +1 -1
  37. data/lib/dydx/helper.rb +61 -55
  38. data/lib/dydx/integrand.rb +10 -22
  39. data/lib/dydx/version.rb +1 -1
  40. data/spec/dydx_spec.rb +29 -10
  41. data/spec/lib/algebra/formula_spec.rb +38 -44
  42. data/spec/lib/algebra/operator/parts/base_spec.rb +5 -5
  43. data/spec/lib/algebra/operator/parts/formula_spec.rb +50 -57
  44. data/spec/lib/algebra/operator/parts/inverse_spec.rb +8 -8
  45. data/spec/lib/algebra/set/cos_spec.rb +18 -0
  46. data/spec/lib/algebra/set/e_spec.rb +27 -0
  47. data/spec/lib/algebra/set/fixnum_spec.rb +65 -0
  48. data/spec/lib/algebra/set/float_spec.rb +65 -0
  49. data/spec/lib/algebra/set/log_spec.rb +15 -0
  50. data/spec/lib/algebra/set/num_spec.rb +23 -0
  51. data/spec/lib/algebra/set/pi_spec.rb +25 -0
  52. data/spec/lib/algebra/set/sin_spec.rb +14 -0
  53. data/spec/lib/algebra/set/symbol_spec.rb +22 -0
  54. data/spec/lib/algebra/set/tan_spec.rb +13 -0
  55. data/spec/lib/delta_spec.rb +8 -32
  56. data/spec/lib/function_spec.rb +34 -60
  57. data/spec/lib/helper_spec.rb +49 -47
  58. data/spec/lib/integrand_spec.rb +15 -13
  59. data/spec/spec_helper.rb +1 -2
  60. metadata +39 -9
  61. data/.pryrc +0 -2
  62. data/.rubocop.yml +0 -25
  63. data/spec/lib/algebra/set_spec.rb +0 -263
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'dydx'
3
3
  require 'pry'
4
-
5
- include Dydx
4
+ include Dydx
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dydx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-14 00:00:00.000000000 Z
11
+ date: 2014-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Dydx is new math DSL in Ruby. The most important thing in this DSL is
56
- we can handle math in the same sense sense of the math on paper.
55
+ description: It is possible to use the differential using the Symbol and Fixnum by
56
+ including the Dydx. And, we can use the natural logarithm and log.
57
57
  email:
58
58
  - qlli.illb@gmail.com
59
59
  executables: []
@@ -61,9 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - ".gitignore"
64
- - ".pryrc"
65
64
  - ".rspec"
66
- - ".rubocop.yml"
67
65
  - ".travis.yml"
68
66
  - Gemfile
69
67
  - LICENSE.txt
@@ -74,6 +72,7 @@ files:
74
72
  - lib/dydx/algebra.rb
75
73
  - lib/dydx/algebra/formula.rb
76
74
  - lib/dydx/algebra/inverse.rb
75
+ - lib/dydx/algebra/operator/common_parts.rb
77
76
  - lib/dydx/algebra/operator/formula.rb
78
77
  - lib/dydx/algebra/operator/general.rb
79
78
  - lib/dydx/algebra/operator/inverse.rb
@@ -81,10 +80,23 @@ files:
81
80
  - lib/dydx/algebra/operator/parts/base.rb
82
81
  - lib/dydx/algebra/operator/parts/formula.rb
83
82
  - lib/dydx/algebra/operator/parts/general.rb
83
+ - lib/dydx/algebra/operator/parts/interface.rb
84
84
  - lib/dydx/algebra/operator/parts/inverse.rb
85
85
  - lib/dydx/algebra/operator/parts/num.rb
86
86
  - lib/dydx/algebra/operator/parts/symbol.rb
87
+ - lib/dydx/algebra/operator/symbol.rb
87
88
  - lib/dydx/algebra/set.rb
89
+ - lib/dydx/algebra/set/base.rb
90
+ - lib/dydx/algebra/set/cos.rb
91
+ - lib/dydx/algebra/set/e.rb
92
+ - lib/dydx/algebra/set/fixnum.rb
93
+ - lib/dydx/algebra/set/float.rb
94
+ - lib/dydx/algebra/set/log.rb
95
+ - lib/dydx/algebra/set/num.rb
96
+ - lib/dydx/algebra/set/pi.rb
97
+ - lib/dydx/algebra/set/sin.rb
98
+ - lib/dydx/algebra/set/symbol.rb
99
+ - lib/dydx/algebra/set/tan.rb
88
100
  - lib/dydx/delta.rb
89
101
  - lib/dydx/function.rb
90
102
  - lib/dydx/helper.rb
@@ -95,7 +107,16 @@ files:
95
107
  - spec/lib/algebra/operator/parts/base_spec.rb
96
108
  - spec/lib/algebra/operator/parts/formula_spec.rb
97
109
  - spec/lib/algebra/operator/parts/inverse_spec.rb
98
- - spec/lib/algebra/set_spec.rb
110
+ - spec/lib/algebra/set/cos_spec.rb
111
+ - spec/lib/algebra/set/e_spec.rb
112
+ - spec/lib/algebra/set/fixnum_spec.rb
113
+ - spec/lib/algebra/set/float_spec.rb
114
+ - spec/lib/algebra/set/log_spec.rb
115
+ - spec/lib/algebra/set/num_spec.rb
116
+ - spec/lib/algebra/set/pi_spec.rb
117
+ - spec/lib/algebra/set/sin_spec.rb
118
+ - spec/lib/algebra/set/symbol_spec.rb
119
+ - spec/lib/algebra/set/tan_spec.rb
99
120
  - spec/lib/delta_spec.rb
100
121
  - spec/lib/function_spec.rb
101
122
  - spec/lib/helper_spec.rb
@@ -124,14 +145,23 @@ rubyforge_project:
124
145
  rubygems_version: 2.2.2
125
146
  signing_key:
126
147
  specification_version: 4
127
- summary: We can enjoy the math.
148
+ summary: We can enjoy the derivative.
128
149
  test_files:
129
150
  - spec/dydx_spec.rb
130
151
  - spec/lib/algebra/formula_spec.rb
131
152
  - spec/lib/algebra/operator/parts/base_spec.rb
132
153
  - spec/lib/algebra/operator/parts/formula_spec.rb
133
154
  - spec/lib/algebra/operator/parts/inverse_spec.rb
134
- - spec/lib/algebra/set_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/float_spec.rb
159
+ - spec/lib/algebra/set/log_spec.rb
160
+ - spec/lib/algebra/set/num_spec.rb
161
+ - spec/lib/algebra/set/pi_spec.rb
162
+ - spec/lib/algebra/set/sin_spec.rb
163
+ - spec/lib/algebra/set/symbol_spec.rb
164
+ - spec/lib/algebra/set/tan_spec.rb
135
165
  - spec/lib/delta_spec.rb
136
166
  - spec/lib/function_spec.rb
137
167
  - spec/lib/helper_spec.rb
data/.pryrc DELETED
@@ -1,2 +0,0 @@
1
- require 'dydx'
2
- include Dydx
data/.rubocop.yml DELETED
@@ -1,25 +0,0 @@
1
- Eval:
2
- Enabled: false
3
-
4
- LineLength:
5
- Enabled: false
6
-
7
- # Configuration parameters: AllowedVariables.
8
- GlobalVars:
9
- Enabled: false
10
-
11
- # Configuration parameters: EnforcedStyle, SupportedStyles.
12
- MethodName:
13
- Enabled: false
14
-
15
- OpMethod:
16
- Enabled: false
17
-
18
- Void:
19
- Enabled: false
20
-
21
- SpaceInsideParens:
22
- Enabled: false
23
-
24
- SpaceAroundOperators:
25
- Enabled: false
@@ -1,263 +0,0 @@
1
- require 'spec_helper'
2
- # HOTFIX: Refactor by using context or describe
3
- describe Dydx::Algebra::Set do
4
- it { expect(_(1)).to eq(_(1)) }
5
- it { expect(_(-1)).to eq(_(-1)) }
6
- it { expect(e0).to eq(e0) }
7
- it { expect(e1).to eq(e1) }
8
-
9
- it { expect(e).to eq(e) }
10
- it { expect(pi).to eq(pi) }
11
-
12
- it { expect(log10(1)).to eq(e0) }
13
- it { expect(log10(10)).to eq(e1) }
14
- it { expect(log10(10 ** n)).to eq(n) }
15
- it { expect(log10(3 ** n)).to eq(n * log10( 3 )) }
16
-
17
- it { expect(log2(1)).to eq(e0) }
18
- it { expect(log2(2)).to eq(e1) }
19
- it { expect(log2(2 ** n)).to eq(n) }
20
- it { expect(log2(3 ** n)).to eq(n * log2( 3 )) }
21
-
22
- it { expect(log(1)).to eq(0) }
23
- it { expect(log(e)).to eq(1) }
24
- it { expect(log(e ** n)).to eq(n) }
25
-
26
- it { expect(sin(pi)).to eq(0) }
27
-
28
- it { expect(cos(0)).to eq(1) }
29
- it { expect(cos(pi)).to eq(-1) }
30
- it { expect(cos(2 * pi)).to eq(1) }
31
-
32
- describe '#to_s' do
33
- it { expect(e.to_s).to eq('e') }
34
-
35
- it { expect(1.to_s).to eq('1') }
36
-
37
- it { expect(1.0.to_s).to eq('1.0') }
38
-
39
- it { expect(e1.to_s).to eq('1') }
40
-
41
- it { expect(pi.to_s).to eq('pi') }
42
-
43
- it { expect(cos(x).to_s).to eq('cos( x )') }
44
- it { expect(sin(x).to_s).to eq('sin( x )') }
45
- it { expect(tan(x).to_s).to eq('tan( x )') }
46
-
47
- it { expect(x.to_s).to eq('x') }
48
- end
49
-
50
- describe '#==' do
51
- it { expect(_(1) == _(1)).to be true }
52
- end
53
-
54
- describe '#subst' do
55
- it { expect(1.subst).to eq(1) }
56
- it { expect(1.0.subst).to eq(1.0) }
57
- it { expect(e.subst).to eq(e) }
58
- it { expect(pi.subst).to eq(pi) }
59
- it { expect(sin(x).subst(x: 3)).to eq(sin(3)) }
60
- it { expect(cos(x).subst(x: pi)).to eq(-1) }
61
- it { expect(tan(0).subst(x: pi)).to eq(0) }
62
- it { expect(log(x).subst(x: e)).to eq(1) }
63
- it { expect(log10(x).subst(x: 7)).to eq(log10(7)) }
64
- it { expect(log2(2).subst(x: 2)).to eq(1) }
65
- it { expect(x.subst(x: 2)).to eq(2) }
66
- it { expect(x.subst(y: 2)).to eq(x) }
67
- end
68
-
69
- describe '#differentiate' do
70
- it { expect(e.d).to eq(0) }
71
- it { expect((e ** x).d).to eq(e ** x) }
72
- it { expect((e ** (x + y)).d).to eq(e ** ( x + y )) }
73
-
74
- it { expect(pi.d(x)).to eq(0) }
75
-
76
- it { expect(1.d).to eq(0) }
77
- it { expect(3.d).to eq(0) }
78
- it { expect(3.0.d).to eq(0) }
79
-
80
- it { expect(sin(x).d).to eq(cos(x)) }
81
- it { expect(cos(x).d).to eq(- sin(x)) }
82
- it { expect(tan(x).d).to eq(1 / cos(x) ** 2) }
83
-
84
- it { expect(log(x).d).to eq(1 / x) }
85
- it { expect(log10(x).d).to eq(1 / ( x * log( 10 ) )) }
86
- it { expect(log2(x).d).to eq(1 / ( x * log( 2 ) )) }
87
-
88
- it { expect(x.d(x)).to eq(1) }
89
- end
90
-
91
- describe 'Calculate' do
92
- context 'E with Fixnum' do
93
- it { expect(e + 0).to eq(e) }
94
- it { expect(e - 0).to eq(e) }
95
- it { expect((e * 0).to_s).to eq('0') }
96
- it { expect(e * 1).to eq(e) }
97
- it { expect { (e / 0).to_s }.to raise_error(ZeroDivisionError) }
98
- it { expect(e / 1).to eq(e) }
99
- it { expect((e ** 0).to_s).to eq('1') }
100
- end
101
-
102
- context 'Fixnum with Formula' do
103
- let(:formula) { (x + y) }
104
- it { expect(0 + formula).to eq(formula) }
105
- it { expect(0 - formula).to eq( - ( x + y ) ) }
106
- it { expect(0 * formula).to eq(0) }
107
- it { expect(1 * formula).to eq(formula) }
108
- it { expect(0 / formula).to eq(0) }
109
- it { expect(1 / formula).to eq( 1 / ( x + y ) ) }
110
- it { expect(0 ** formula).to eq(0) }
111
- it { expect(1 ** formula).to eq(1) }
112
- end
113
-
114
- context 'Fixnum with Symbol' do
115
- it { expect(0 + x).to eq(x) }
116
- it { expect(0 - x).to eq(- x) }
117
- it { expect(0 * x).to eq(0) }
118
- it { expect(1 * x).to eq(x) }
119
- it { expect(0 / x).to eq(0) }
120
- it { expect(1 / x).to eq( 1 / x ) }
121
- it { expect(0 ** x).to eq(0) }
122
- it { expect(1 ** x).to eq(1) }
123
- end
124
-
125
- context 'Fixnum with Fixnum' do
126
- it { expect(0 + 3).to eq(3) }
127
- it { expect(3 + 0).to eq(3) }
128
- it { expect(2 + 3).to eq(5) }
129
-
130
- it { expect(0 - 3).to eq(-3) }
131
- it { expect(3 - 0).to eq(3) }
132
- it { expect(2 - 3).to eq(-1) }
133
-
134
- it { expect(0 * 3).to eq(0) }
135
- it { expect(3 * 0).to eq(0) }
136
- it { expect(1 * 3).to eq(3) }
137
- it { expect(3 * 1).to eq(3) }
138
- it { expect(3 * 2).to eq(6) }
139
-
140
- it { expect((0 / 3).to_s).to eq('0') }
141
- it { expect { (3 / 0).to_s }.to raise_error(ZeroDivisionError) }
142
- it { expect((3 / 1).to_s).to eq('3') }
143
- # TODO:
144
- it { expect((2 / 3).to_s).to eq('0') }
145
-
146
- it { expect((0 ** 3).to_s).to eq('0') }
147
- it { expect((3 ** 0).to_s).to eq('1') }
148
- it { expect((1 ** 3).to_s).to eq('1') }
149
- it { expect((3 ** 1).to_s).to eq('3') }
150
- it { expect((3 ** 2).to_s).to eq('9') }
151
- end
152
-
153
- context 'Float with Formula' do
154
- let(:formula) { (:x + :y) }
155
- it { expect((0.0 + formula).to_s).to eq(formula.to_s) }
156
- it { expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
157
- it { expect((0.0 * formula).to_s).to eq('0') }
158
- it { expect((1.0 * formula).to_s).to eq(formula.to_s) }
159
- it { expect((0.0 / formula).to_s).to eq('0') }
160
- it { expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
161
- it { expect((0.0 ** formula).to_s).to eq('0') }
162
- it { expect((1.0 ** formula).to_s).to eq('1') }
163
- end
164
-
165
- context 'Float with Symbol' do
166
- it { expect(0.0 + :x).to eq(:x) }
167
- it { expect((0.0 - :x).to_s).to eq('( - x )') }
168
- it { expect((0.0 * :x).to_s).to eq('0') }
169
- it { expect(1.0 * :x).to eq(:x) }
170
- it { expect((0.0 / :x).to_s).to eq('0') }
171
- it { expect((1.0 / :x).to_s).to eq('( 1 / x )') }
172
- it { expect((0.0 ** :x).to_s).to eq('0') }
173
- it { expect((1.0 ** :x).to_s).to eq('1') }
174
- end
175
-
176
- context 'Float with Float' do
177
- it { expect(0.0 + 3.0).to eq(3.0) }
178
- it { expect(3.0 + 0.0).to eq(3.0) }
179
- it { expect(2.0 + 3.0).to eq(5.0) }
180
-
181
- it { expect(0.0 - 3.0).to eq(-3.0) }
182
- it { expect(3.0 - 0.0).to eq(3.0) }
183
- it { expect(2.0 - 3.0).to eq(-1.0) }
184
-
185
- it { expect(0.0 * 3.0).to eq(0.0) }
186
- it { expect(3.0 * 0.0).to eq(0.0) }
187
- it { expect(1.0 * 3.0).to eq(3.0) }
188
- it { expect(3.0 * 1.0).to eq(3.0) }
189
- it { expect(3.0 * 2.0).to eq(6.0) }
190
-
191
- it { expect(0.0 / 3.0).to eq(0.0) }
192
- it { expect(3.0 / 0.0).to eq(oo) }
193
- it { expect(3.0 / 1.0).to eq(3.0) }
194
- # TODO:
195
- it { expect(2.0 / 3.0).to eq(0.6666666666666666) }
196
-
197
- it { expect(0.0 ** 3.0).to eq(0.0) }
198
- it { expect(3.0 ** 0.0).to eq(1.0) }
199
- it { expect(1.0 ** 3.0).to eq(1.0) }
200
- it { expect(3.0 ** 1.0).to eq(3.0) }
201
- it { expect(3.0 ** 2.0).to eq(9.0) }
202
- end
203
-
204
- context 'Pi with Fixnum' do
205
- it { expect(pi + 0).to eq(pi) }
206
- it { expect(pi - 0).to eq(pi) }
207
- it { expect((pi * 0).to_s).to eq('0') }
208
- it { expect(pi * 1).to eq(pi) }
209
- it { expect { (pi / 0).to_s }.to raise_error(ZeroDivisionError) }
210
- it { expect(pi / 1).to eq(pi) }
211
- it { expect((pi ** 0).to_s).to eq('1') }
212
- end
213
-
214
- context 'Symbol with Fixnum' do
215
- it { expect(x + 0).to eq(x) }
216
- it { expect(x - 0).to eq(x) }
217
- it { expect(x * 0).to eq(0) }
218
- it { expect(x * 1).to eq(x) }
219
- it { expect { x / 0 }.to raise_error(ZeroDivisionError) }
220
- it { expect(x / 1).to eq(x) }
221
- it { expect(x ** 0).to eq(1) }
222
- it { expect(x ** 1).to eq(x) }
223
- end
224
-
225
- context 'Num with Num' do
226
- it { expect(_(1) + _(2)).to eq(3) }
227
- it { expect(_(1) - _(2)).to eq(-1) }
228
- it { expect(_(1) * _(2)).to eq(2) }
229
- it { expect((_(1) / _(2)).to_s).to eq('( 1 / 2 )') }
230
- it { expect(_(1) % _(2)).to eq(1) }
231
- end
232
- end
233
-
234
- describe Dydx::Algebra::Set::Num do
235
- describe :< do
236
- it { expect(_(1) < _(2)).to be(true) }
237
- it { expect(_(1) < 2).to be(true) }
238
- it { expect(_(2) < _(1)).to be(false) }
239
- it { expect(_(2) < 1).to be(false) }
240
- end
241
-
242
- describe :<= do
243
- it { expect(_(1) <= _(2)).to be(true) }
244
- it { expect(_(1) <= 2).to be(true) }
245
- it { expect(_(2) <= _(1)).to be(false) }
246
- it { expect(_(2) <= 1).to be(false) }
247
- end
248
-
249
- describe :> do
250
- it { expect(_(1) > _(2)).to be(false) }
251
- it { expect(_(1) > 2).to be(false) }
252
- it { expect(_(2) > _(1)).to be(true) }
253
- it { expect(_(2) > 1).to be(true) }
254
- end
255
-
256
- describe :>= do
257
- it { expect(_(1) >= _(2)).to be(false) }
258
- it { expect(_(1) >= 2).to be(false) }
259
- it { expect(_(2) >= _(1)).to be(true) }
260
- it { expect(_(2) >= 1).to be(true) }
261
- end
262
- end
263
- end