dydx 0.1.3 → 0.1.4

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.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/.pryrc +2 -0
  3. data/.rubocop.yml +25 -0
  4. data/Gemfile +3 -0
  5. data/README.md +29 -64
  6. data/Rakefile +5 -8
  7. data/dydx.gemspec +13 -13
  8. data/lib/dydx.rb +20 -29
  9. data/lib/dydx/algebra.rb +8 -76
  10. data/lib/dydx/algebra/formula.rb +67 -29
  11. data/lib/dydx/algebra/inverse.rb +16 -2
  12. data/lib/dydx/algebra/operator/formula.rb +0 -4
  13. data/lib/dydx/algebra/operator/general.rb +0 -4
  14. data/lib/dydx/algebra/operator/inverse.rb +0 -4
  15. data/lib/dydx/algebra/operator/num.rb +0 -4
  16. data/lib/dydx/algebra/operator/parts/base.rb +2 -2
  17. data/lib/dydx/algebra/operator/parts/formula.rb +61 -40
  18. data/lib/dydx/algebra/operator/parts/general.rb +83 -30
  19. data/lib/dydx/algebra/operator/parts/inverse.rb +4 -4
  20. data/lib/dydx/algebra/operator/parts/num.rb +16 -11
  21. data/lib/dydx/algebra/operator/parts/symbol.rb +2 -2
  22. data/lib/dydx/algebra/set.rb +271 -34
  23. data/lib/dydx/delta.rb +1 -1
  24. data/lib/dydx/function.rb +1 -1
  25. data/lib/dydx/helper.rb +53 -67
  26. data/lib/dydx/integrand.rb +22 -10
  27. data/lib/dydx/version.rb +1 -1
  28. data/spec/dydx_spec.rb +10 -29
  29. data/spec/lib/algebra/formula_spec.rb +44 -38
  30. data/spec/lib/algebra/operator/parts/base_spec.rb +5 -5
  31. data/spec/lib/algebra/operator/parts/formula_spec.rb +57 -57
  32. data/spec/lib/algebra/operator/parts/inverse_spec.rb +8 -8
  33. data/spec/lib/algebra/set_spec.rb +263 -0
  34. data/spec/lib/delta_spec.rb +32 -8
  35. data/spec/lib/function_spec.rb +60 -34
  36. data/spec/lib/helper_spec.rb +44 -51
  37. data/spec/lib/integrand_spec.rb +13 -15
  38. data/spec/spec_helper.rb +2 -1
  39. metadata +20 -64
  40. data/lib/dydx/algebra/operator/common_parts.rb +0 -3
  41. data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
  42. data/lib/dydx/algebra/operator/symbol.rb +0 -15
  43. data/lib/dydx/algebra/set/base.rb +0 -9
  44. data/lib/dydx/algebra/set/cos.rb +0 -22
  45. data/lib/dydx/algebra/set/e.rb +0 -16
  46. data/lib/dydx/algebra/set/fixnum.rb +0 -14
  47. data/lib/dydx/algebra/set/float.rb +0 -14
  48. data/lib/dydx/algebra/set/log.rb +0 -22
  49. data/lib/dydx/algebra/set/num.rb +0 -22
  50. data/lib/dydx/algebra/set/pi.rb +0 -16
  51. data/lib/dydx/algebra/set/sin.rb +0 -22
  52. data/lib/dydx/algebra/set/symbol.rb +0 -14
  53. data/lib/dydx/algebra/set/tan.rb +0 -17
  54. data/spec/lib/algebra/set/cos_spec.rb +0 -18
  55. data/spec/lib/algebra/set/e_spec.rb +0 -27
  56. data/spec/lib/algebra/set/fixnum_spec.rb +0 -65
  57. data/spec/lib/algebra/set/float_spec.rb +0 -65
  58. data/spec/lib/algebra/set/log_spec.rb +0 -15
  59. data/spec/lib/algebra/set/num_spec.rb +0 -23
  60. data/spec/lib/algebra/set/pi_spec.rb +0 -25
  61. data/spec/lib/algebra/set/sin_spec.rb +0 -14
  62. data/spec/lib/algebra/set/symbol_spec.rb +0 -22
  63. data/spec/lib/algebra/set/tan_spec.rb +0 -13
@@ -1,31 +1,29 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dydx:Integrand do
4
- before(:each) do
5
- reset
6
- end
3
+ describe Dydx::Integrand do
4
+ before { reset }
7
5
 
8
6
  it 'ex1' do
9
7
  f(x, y) <= x * y
10
8
  integrand = S(f(x, y), dx)
11
9
  expect(integrand.function).to eq(f(x, y))
12
10
  expect(integrand.var).to eq(:x)
13
- expect{integrand[4, 3]}.to raise_error(ArgumentError)
11
+ expect { integrand[4, 3] }.to raise_error(ArgumentError)
14
12
  end
15
13
 
16
14
  it 'ex2' do
17
15
  f(x) <= x * x
18
- expect(S(f(x), dx)[0, 1]).to eq(0.3333333333333334)
16
+ expect(S(f(x), dx)[0, 1]).to eq(0.33333333)
19
17
  end
20
18
 
21
19
  it 'ex3' do
22
20
  f(x) <= sin(x)
23
- expect(S(f(x), dx)[0, Math::PI/2]).to eq(1.000000000021139)
21
+ expect(S(f(x), dx)[0, pi / 2]).to eq(1.0)
24
22
  end
25
23
 
26
24
  it 'ex4' do
27
25
  f(x) <= cos(x)
28
- expect(S(f(x), dx)[0, Math::PI]).to eq(7.440786129085082e-17)
26
+ expect(S(f(x), dx)[0, pi]).to eq(0.0)
29
27
  end
30
28
 
31
29
  it 'ex5' do
@@ -34,20 +32,20 @@ describe Dydx:Integrand do
34
32
  end
35
33
 
36
34
  it 'ex6' do
37
- f(x) <= e ^ (- (x ^ 2))
35
+ f(x) <= e ** -x ** 2
38
36
  expect(f(0)).to eq(1)
39
- expect(f(1)).to eq(1.0/Math::E)
37
+ expect(f(1)).to eq(1.0 / Math::E)
40
38
  expect(f(1000)).to eq(0)
41
- expect(S(f(x), dx)[-1000, 1000, 3000]).to eq(1.7724538506374117)
39
+ expect(S(f(x), dx)[-1000, 1000, 3000]).to eq(1.77239273)
42
40
  end
43
41
 
44
42
  it 'ex7' do
45
- f(x) <= (1.0 / ( ( 2.0 * Math::PI ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
46
- expect(S(f(x), dx)[-1000, 1000, 1000]).to eq(0.9952054164466917)
43
+ f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
44
+ expect(S(f(x), dx)[-1000, 1000]).to eq(1.0)
47
45
  end
48
46
 
49
47
  it 'ex8' do
50
- f(x) <= (1.0 / ( ( 2.0 * pi ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
51
- expect(S(f(x), dx)[-oo, oo, 1000]).to eq(0.9952054164466917)
48
+ f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
49
+ expect(S(f(x), dx)[-oo, oo]).to eq(1.0)
52
50
  end
53
51
  end
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'dydx'
3
3
  require 'pry'
4
- include Dydx
4
+
5
+ include Dydx
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.3
5
- prerelease:
4
+ version: 0.1.4
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-28 00:00:00.000000000 Z
11
+ date: 2014-07-14 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,11 @@ executables: []
67
60
  extensions: []
68
61
  extra_rdoc_files: []
69
62
  files:
70
- - .gitignore
71
- - .rspec
72
- - .travis.yml
63
+ - ".gitignore"
64
+ - ".pryrc"
65
+ - ".rspec"
66
+ - ".rubocop.yml"
67
+ - ".travis.yml"
73
68
  - Gemfile
74
69
  - LICENSE.txt
75
70
  - README.md
@@ -79,7 +74,6 @@ files:
79
74
  - lib/dydx/algebra.rb
80
75
  - lib/dydx/algebra/formula.rb
81
76
  - lib/dydx/algebra/inverse.rb
82
- - lib/dydx/algebra/operator/common_parts.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
@@ -87,23 +81,10 @@ files:
87
81
  - lib/dydx/algebra/operator/parts/base.rb
88
82
  - lib/dydx/algebra/operator/parts/formula.rb
89
83
  - lib/dydx/algebra/operator/parts/general.rb
90
- - lib/dydx/algebra/operator/parts/interface.rb
91
84
  - lib/dydx/algebra/operator/parts/inverse.rb
92
85
  - lib/dydx/algebra/operator/parts/num.rb
93
86
  - lib/dydx/algebra/operator/parts/symbol.rb
94
- - lib/dydx/algebra/operator/symbol.rb
95
87
  - lib/dydx/algebra/set.rb
96
- - lib/dydx/algebra/set/base.rb
97
- - lib/dydx/algebra/set/cos.rb
98
- - lib/dydx/algebra/set/e.rb
99
- - lib/dydx/algebra/set/fixnum.rb
100
- - lib/dydx/algebra/set/float.rb
101
- - lib/dydx/algebra/set/log.rb
102
- - lib/dydx/algebra/set/num.rb
103
- - lib/dydx/algebra/set/pi.rb
104
- - lib/dydx/algebra/set/sin.rb
105
- - lib/dydx/algebra/set/symbol.rb
106
- - lib/dydx/algebra/set/tan.rb
107
88
  - lib/dydx/delta.rb
108
89
  - lib/dydx/function.rb
109
90
  - lib/dydx/helper.rb
@@ -114,16 +95,7 @@ files:
114
95
  - spec/lib/algebra/operator/parts/base_spec.rb
115
96
  - spec/lib/algebra/operator/parts/formula_spec.rb
116
97
  - spec/lib/algebra/operator/parts/inverse_spec.rb
117
- - spec/lib/algebra/set/cos_spec.rb
118
- - spec/lib/algebra/set/e_spec.rb
119
- - spec/lib/algebra/set/fixnum_spec.rb
120
- - spec/lib/algebra/set/float_spec.rb
121
- - spec/lib/algebra/set/log_spec.rb
122
- - spec/lib/algebra/set/num_spec.rb
123
- - spec/lib/algebra/set/pi_spec.rb
124
- - spec/lib/algebra/set/sin_spec.rb
125
- - spec/lib/algebra/set/symbol_spec.rb
126
- - spec/lib/algebra/set/tan_spec.rb
98
+ - spec/lib/algebra/set_spec.rb
127
99
  - spec/lib/delta_spec.rb
128
100
  - spec/lib/function_spec.rb
129
101
  - spec/lib/helper_spec.rb
@@ -132,33 +104,26 @@ files:
132
104
  homepage: https://github.com/gogotanaka
133
105
  licenses:
134
106
  - MIT
107
+ metadata: {}
135
108
  post_install_message:
136
109
  rdoc_options: []
137
110
  require_paths:
138
111
  - lib
139
112
  required_ruby_version: !ruby/object:Gem::Requirement
140
- none: false
141
113
  requirements:
142
- - - ! '>='
114
+ - - ">="
143
115
  - !ruby/object:Gem::Version
144
116
  version: '0'
145
- segments:
146
- - 0
147
- hash: 1610563563432672313
148
117
  required_rubygems_version: !ruby/object:Gem::Requirement
149
- none: false
150
118
  requirements:
151
- - - ! '>='
119
+ - - ">="
152
120
  - !ruby/object:Gem::Version
153
121
  version: '0'
154
- segments:
155
- - 0
156
- hash: 1610563563432672313
157
122
  requirements: []
158
123
  rubyforge_project:
159
- rubygems_version: 1.8.23
124
+ rubygems_version: 2.2.2
160
125
  signing_key:
161
- specification_version: 3
126
+ specification_version: 4
162
127
  summary: We can enjoy the math.
163
128
  test_files:
164
129
  - spec/dydx_spec.rb
@@ -166,16 +131,7 @@ test_files:
166
131
  - spec/lib/algebra/operator/parts/base_spec.rb
167
132
  - spec/lib/algebra/operator/parts/formula_spec.rb
168
133
  - spec/lib/algebra/operator/parts/inverse_spec.rb
169
- - spec/lib/algebra/set/cos_spec.rb
170
- - spec/lib/algebra/set/e_spec.rb
171
- - spec/lib/algebra/set/fixnum_spec.rb
172
- - spec/lib/algebra/set/float_spec.rb
173
- - spec/lib/algebra/set/log_spec.rb
174
- - spec/lib/algebra/set/num_spec.rb
175
- - spec/lib/algebra/set/pi_spec.rb
176
- - spec/lib/algebra/set/sin_spec.rb
177
- - spec/lib/algebra/set/symbol_spec.rb
178
- - spec/lib/algebra/set/tan_spec.rb
134
+ - spec/lib/algebra/set_spec.rb
179
135
  - spec/lib/delta_spec.rb
180
136
  - spec/lib/function_spec.rb
181
137
  - spec/lib/helper_spec.rb
@@ -1,3 +0,0 @@
1
- require 'dydx/algebra/operator/parts/base'
2
- require 'dydx/algebra/operator/parts/general'
3
- require 'dydx/algebra/operator/parts/interface'
@@ -1,22 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Operator
4
- module Parts
5
- module Interface
6
- %w(+ - * / ^).map(&:to_sym).each do |operator|
7
- define_method(operator) do |x|
8
- x = ::Set::Num.new(x) if x.is_a?(Fixnum)
9
- if operator == :/ && x.is_0?
10
- raise ZeroDivisionError
11
- elsif [:-, :/].include?(operator)
12
- send(inverse_ope(operator), inverse(x, inverse_ope(operator)))
13
- else
14
- super(x)
15
- end
16
- end
17
- end
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -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
@@ -1,9 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class Base
5
- include Helper
6
- end
7
- end
8
- end
9
- end
@@ -1,22 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class Cos < Base
5
- attr_accessor :x
6
-
7
- def initialize(x)
8
- @x = x
9
- end
10
-
11
- def to_s
12
- "cos( #{x.to_s} )"
13
- end
14
-
15
- def differentiate(sym=:x)
16
- -1 * sin(x) * x.d(sym)
17
- end
18
- alias_method :d, :differentiate
19
- end
20
- end
21
- end
22
- end
@@ -1,16 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class E < Base
5
- def differentiate(sym=:x)
6
- e0
7
- end
8
- alias_method :d, :differentiate
9
-
10
- def to_s
11
- 'e'
12
- end
13
- end
14
- end
15
- end
16
- end
@@ -1,14 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- Fixnum.class_eval do
5
- include Helper
6
-
7
- def differentiate(sym=:x)
8
- e0
9
- end
10
- alias_method :d, :differentiate
11
- end
12
- end
13
- end
14
- end
@@ -1,14 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- Float.class_eval do
5
- include Helper
6
-
7
- def differentiate(sym=:x)
8
- e0
9
- end
10
- alias_method :d, :differentiate
11
- end
12
- end
13
- end
14
- end
@@ -1,22 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class Log < Base
5
- attr_accessor :f
6
-
7
- def initialize(f)
8
- @f = f
9
- end
10
-
11
- def differentiate(sym=:x)
12
- f.d(sym) / (f)
13
- end
14
- alias_method :d, :differentiate
15
-
16
- def to_s
17
- "log( #{f.to_s} )"
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,22 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class Num < Base
5
- attr_accessor :n
6
-
7
- def initialize(n)
8
- @n = n
9
- end
10
-
11
- def differentiate(sym=:x)
12
- e0
13
- end
14
- alias_method :d, :differentiate
15
-
16
- def to_s
17
- @n.to_s
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,16 +0,0 @@
1
- module Dydx
2
- module Algebra
3
- module Set
4
- class Pi < Base
5
- def differentiate(sym=:x)
6
- _(0)
7
- end
8
- alias_method :d, :differentiate
9
-
10
- def to_s
11
- 'pi'
12
- end
13
- end
14
- end
15
- end
16
- end