dydx 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,6 +20,10 @@ module Dydx
20
20
  g.is_a?(Base)
21
21
 
22
22
  Num.new(self).send(operator.to_sym, g)
23
+ elsif operator == '^' && g.is_a?(Fixnum)
24
+ result = 1
25
+ g.times{ result *= self }
26
+ result
23
27
  else
24
28
  (to_f.send(operator.to_sym, g)).to_i
25
29
  end
@@ -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
@@ -44,6 +44,8 @@ module Dydx
44
44
  def ^(x)
45
45
  if (n == 0) || (n == 1)
46
46
  self
47
+ elsif x.is_a?(Num)
48
+ _(n ^ x.n)
47
49
  else
48
50
  super(x)
49
51
  end
@@ -16,6 +16,10 @@ module Dydx
16
16
  def to_s
17
17
  @n.to_s
18
18
  end
19
+
20
+ def ==(x)
21
+ x.is_a?(Num) && n == x.n
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
@@ -12,6 +12,10 @@ describe Dydx::Algebra::Set::Num do
12
12
  it{ expect(_(1).d(:x).to_s).to eq(_(0).to_s) }
13
13
  end
14
14
 
15
+ describe '#==' do
16
+ it{ expect(_(1) == _(1)).to be_true }
17
+ end
18
+
15
19
  describe 'Calculate' do
16
20
  end
17
21
  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.2
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
- - ".gitignore"
64
- - ".rspec"
65
- - ".travis.yml"
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: 2.2.2
147
+ rubygems_version: 1.8.23
134
148
  signing_key:
135
- specification_version: 4
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