dydx 0.1.314 → 0.1.412

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +25 -0
  3. data/.travis.yml +3 -1
  4. data/Gemfile +1 -0
  5. data/README.md +4 -2
  6. data/Rakefile +5 -8
  7. data/dydx.gemspec +13 -13
  8. data/lib/dydx.rb +20 -27
  9. data/lib/dydx/algebra.rb +8 -6
  10. data/lib/dydx/algebra/formula.rb +53 -28
  11. data/lib/dydx/algebra/inverse.rb +2 -2
  12. data/lib/dydx/algebra/operator/formula.rb +0 -1
  13. data/lib/dydx/algebra/operator/general.rb +0 -1
  14. data/lib/dydx/algebra/operator/inverse.rb +0 -1
  15. data/lib/dydx/algebra/operator/num.rb +0 -1
  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 -32
  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 +82 -122
  23. data/lib/dydx/delta.rb +1 -1
  24. data/lib/dydx/function.rb +1 -1
  25. data/lib/dydx/helper.rb +43 -66
  26. data/lib/dydx/integrand.rb +7 -6
  27. data/lib/dydx/version.rb +1 -1
  28. data/spec/dydx_spec.rb +3 -3
  29. data/spec/lib/algebra/formula_spec.rb +41 -41
  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 +193 -150
  34. data/spec/lib/delta_spec.rb +23 -25
  35. data/spec/lib/function_spec.rb +4 -6
  36. data/spec/lib/helper_spec.rb +44 -51
  37. data/spec/lib/integrand_spec.rb +12 -10
  38. data/spec/spec_helper.rb +2 -1
  39. metadata +6 -7
  40. data/lib/dydx/algebra/operator/parts.rb +0 -6
  41. data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
@@ -1,17 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Dydx:Function do
4
- before(:each) do
5
- reset
6
- end
3
+ describe Dydx::Function do
4
+ before { reset }
7
5
 
8
6
  it 'ex1' do
9
7
  expect(f(x, y)).to eq(f(x, y))
10
8
  expect(f(x, y)).to eq($f)
11
9
  expect(f(x, y).algebra).to be_nil
12
10
  expect(f(x, y).vars).to eq([:x, :y])
13
- expect{f(x, y, z)}.to raise_error(ArgumentError)
14
- expect{f(x)}.to raise_error(ArgumentError)
11
+ expect { f(x, y, z) }.to raise_error(ArgumentError)
12
+ expect { f(x) }.to raise_error(ArgumentError)
15
13
  end
16
14
 
17
15
  it 'ex2' do
@@ -3,70 +3,63 @@ require 'spec_helper'
3
3
  describe Helper do
4
4
  include Helper
5
5
  context '#is_n?' do
6
- it{ expect(0.is_0?).to be_true }
7
- it{ expect(_(0).is_0?).to be_true }
8
- it{ expect(inverse(0, :+).is_0?).to be_true }
9
- it{ expect(1.is_1?).to be_true }
10
- it{ expect(_(1).is_1?).to be_true }
11
- it{ expect(inverse(1, :*).is_1?).to be_true }
12
- it{ expect(-1.is_minus1?).to be_true }
13
- it{ expect(_(-1).is_minus1?).to be_true }
6
+ it { expect(0.zero?).to be true }
7
+ it { expect(_(0).zero?).to be true }
8
+ it { expect(inverse(0, :+).zero?).to be true }
9
+ it { expect(1.one?).to be true }
10
+ it { expect(_(1).one?).to be true }
11
+ it { expect(inverse(1, :*).one?).to be true }
12
+ it { expect(-1.minus1?).to be true }
13
+ it { expect(_(-1).minus1?).to be true }
14
14
  end
15
15
 
16
- context '#is_multiple_of' do
17
- it{ expect(0.is_multiple_of(:x).to_s).to eq('0') }
18
- it{ expect(_(0).is_multiple_of(:y).to_s).to eq('0')}
16
+ context '#multiple_of?' do
17
+ it { expect(0.multiple_of?(x)).to be(true) }
19
18
 
20
- it{ expect(:x.is_multiple_of(:x).to_s).to eq('1') }
21
- it{ expect(:x.is_multiple_of(:y)).to be_false }
19
+ it { expect(4.multiple_of?(_(2))).to be(true) }
20
+ it { expect(_(4).multiple_of?(2)).to be(true) }
21
+ it { expect(_(4).multiple_of?(_(2))).to be(true) }
22
22
 
23
- it{ expect((:x * :y).is_multiple_of(:x)).to eq(:y) }
24
- it{ expect((:x * :y).is_multiple_of(:y)).to eq(:x) }
25
- it{ expect((:x * :y).is_multiple_of(:z)).to be_false }
23
+ it { expect(x.multiple_of?(x)).to be(true) }
24
+ it { expect(x.multiple_of?(y)).to be(false) }
25
+
26
+ it { expect((x * y).multiple_of?(x)).to be(true) }
27
+ it { expect((x * y).multiple_of?(x)).to be(true) }
28
+ it { expect((x * y).multiple_of?(z)).to be(false) }
26
29
  end
27
30
 
28
31
  context '#like_term?' do
29
- it{ expect(x.like_term?(x)).to be_true }
30
- it{ expect((2 * x).like_term?((3 * x))).to be_true }
32
+ it { expect(x.like_term?(x)).to be true }
33
+ it { expect((2 * x).like_term?((3 * x))).to be true }
31
34
  end
32
35
 
33
36
  context '#combinable?' do
34
- it{ expect(:x.combinable?(:x, :+)).to be_true }
35
- it{ expect(:x.combinable?(2 * :x, :+)).to be_true }
36
- it{ expect((2 * :x).combinable?(:x, :+)).to be_true }
37
- it{ expect((2 * :x).combinable?(2 * :x, :+)).to be_true }
38
- it{ expect(:x.combinable?(:y, :+)).to be_false }
39
- it{ expect(1.combinable?(2, :+)).to be_true }
40
- it{ expect(:x.combinable?(:x, :*)).to be_true }
41
- it{ expect(:x.combinable?(:y, :*)).to be_false }
42
- it{ expect(1.combinable?(2, :*)).to be_true }
43
- it{ expect(0.combinable?(:x, :^)).to be_true }
44
- it{ expect(1.combinable?(:y, :^)).to be_true }
37
+ it { expect(:x.combinable?(:x, :+)).to be true }
38
+ it { expect(:x.combinable?(2 * :x, :+)).to be true }
39
+ it { expect((2 * :x).combinable?(:x, :+)).to be true }
40
+ it { expect((2 * :x).combinable?(2 * :x, :+)).to be true }
41
+ it { expect(:x.combinable?(:y, :+)).to be false }
42
+ it { expect(1.combinable?(2, :+)).to be true }
43
+ it { expect(:x.combinable?(:x, :*)).to be true }
44
+ it { expect(:x.combinable?(:y, :*)).to be false }
45
+ it { expect(1.combinable?(2, :*)).to be true }
46
+ it { expect(0.combinable?(:x, :**)).to be true }
47
+ it { expect(1.combinable?(:y, :**)).to be true }
45
48
  end
46
49
 
47
50
  context '#distributive?' do
48
- it{ expect(distributive?(:+, :*)).to be_true }
49
- it{ expect(distributive?(:+, :/)).to be_true }
50
- it{ expect(distributive?(:-, :*)).to be_true }
51
- it{ expect(distributive?(:-, :/)).to be_true }
52
- it{ expect(distributive?(:*, :^)).to be_true }
53
- it{ expect(distributive?(:/, :^)).to be_true }
54
- it{ expect(distributive?(:*, :+)).to be_false }
55
- it{ expect(distributive?(:^, :*)).to be_false }
51
+ it { expect(distributive?(:+, :*)).to be true }
52
+ it { expect(distributive?(:+, :/)).to be true }
53
+ it { expect(distributive?(:-, :*)).to be true }
54
+ it { expect(distributive?(:-, :/)).to be true }
55
+ it { expect(distributive?(:*, :**)).to be true }
56
+ it { expect(distributive?(:/, :**)).to be true }
57
+ it { expect(distributive?(:*, :+)).to be false }
58
+ it { expect(distributive?(:**, :*)).to be false }
56
59
  end
57
60
 
58
- let(:addition) { (:x + :y) }
59
- let(:subtraction) { (:x - :y) }
60
- let(:multiplication){ (:x * :y) }
61
- let(:division) { (:x / :y) }
62
- let(:exponentiation){ (:x ^ :y) }
63
-
64
- it{ expect(addition.addition?).to be_true }
65
- it{ expect(multiplication.multiplication?).to be_true }
66
- it{ expect(exponentiation.exponentiation?).to be_true }
67
-
68
- it{ expect(inverse(:x, :+).inverse?(:+, :x)).to be_true }
69
- it{ expect(:x.inverse?(:+, inverse(:x, :+))).to be_true }
70
- it{ expect(inverse(:x, :*).inverse?(:*, :x)).to be_true }
71
- it{ expect(:x.inverse?(:*, inverse(:x, :*))).to be_true }
61
+ it { expect(inverse(x, :+).inverse?(:+, x)).to be true }
62
+ it { expect(x.inverse?(:+, inverse(x, :+))).to be true }
63
+ it { expect(inverse(x, :*).inverse?(:*, x)).to be true }
64
+ it { expect(x.inverse?(:*, inverse(x, :*))).to be true }
72
65
  end
@@ -1,16 +1,14 @@
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
- expect(integrand.var).to eq(:x)
13
- expect{integrand[4, 3]}.to raise_error(ArgumentError)
10
+ expect(integrand.var).to eq(x)
11
+ expect { integrand[4, 3] }.to raise_error(ArgumentError)
14
12
  end
15
13
 
16
14
  it 'ex2' do
@@ -34,20 +32,24 @@ 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
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) )
43
+ f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
46
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 * Math::PI ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
48
+ f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
51
49
  expect(S(f(x), dx)[-oo, oo]).to eq(1.0)
52
50
  end
51
+
52
+ it 'ex9' do
53
+ expect(S(log(x), dx)[0, 1]).to eq(-oo)
54
+ end
53
55
  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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dydx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.314
4
+ version: 0.1.412
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-01 00:00:00.000000000 Z
11
+ date: 2014-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,7 +55,7 @@ dependencies:
55
55
  description: Dydx is new math DSL in Ruby. The most important thing in this DSL is
56
56
  we can handle math in the same sense sense of the math on paper.
57
57
  email:
58
- - qlli.illb@gmail.com
58
+ - mail@tanakakazuki.com
59
59
  executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
@@ -63,6 +63,7 @@ files:
63
63
  - ".gitignore"
64
64
  - ".pryrc"
65
65
  - ".rspec"
66
+ - ".rubocop.yml"
66
67
  - ".travis.yml"
67
68
  - Gemfile
68
69
  - LICENSE.txt
@@ -77,11 +78,9 @@ files:
77
78
  - lib/dydx/algebra/operator/general.rb
78
79
  - lib/dydx/algebra/operator/inverse.rb
79
80
  - lib/dydx/algebra/operator/num.rb
80
- - lib/dydx/algebra/operator/parts.rb
81
81
  - lib/dydx/algebra/operator/parts/base.rb
82
82
  - lib/dydx/algebra/operator/parts/formula.rb
83
83
  - lib/dydx/algebra/operator/parts/general.rb
84
- - lib/dydx/algebra/operator/parts/interface.rb
85
84
  - lib/dydx/algebra/operator/parts/inverse.rb
86
85
  - lib/dydx/algebra/operator/parts/num.rb
87
86
  - lib/dydx/algebra/operator/parts/symbol.rb
@@ -102,7 +101,7 @@ files:
102
101
  - spec/lib/helper_spec.rb
103
102
  - spec/lib/integrand_spec.rb
104
103
  - spec/spec_helper.rb
105
- homepage: https://github.com/gogotanaka
104
+ homepage: http://gogotanaka.me/
106
105
  licenses:
107
106
  - MIT
108
107
  metadata: {}
@@ -122,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
121
  version: '0'
123
122
  requirements: []
124
123
  rubyforge_project:
125
- rubygems_version: 2.2.2
124
+ rubygems_version: 2.4.1
126
125
  signing_key:
127
126
  specification_version: 4
128
127
  summary: We can enjoy the math.
@@ -1,6 +0,0 @@
1
- require 'dydx/algebra/operator/parts/base'
2
- require 'dydx/algebra/operator/parts/general'
3
- require 'dydx/algebra/operator/parts/interface'
4
- require 'dydx/algebra/operator/parts/formula'
5
- require 'dydx/algebra/operator/parts/inverse'
6
- require 'dydx/algebra/operator/parts/num'
@@ -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