dydx 0.1.28 → 0.1.29

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.
data/dydx.gemspec CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["gogotanaka"]
10
10
  spec.email = ["qlli.illb@gmail.com"]
11
11
  spec.homepage = "https://github.com/gogotanaka"
12
- spec.summary = %q{We can enjoy the derivative.}
13
- spec.description = %q{It is possible to use the differential using the Symbol and Fixnum by including the Dydx. And, we can use the natural logarithm and log.}
12
+ spec.summary = %q{We can enjoy the math.}
13
+ spec.description = %q{Dydx is new math DSL in Ruby. The most important thing in this DSL is we can handle math in the same sense sense of the math on paper.}
14
14
 
15
15
  spec.license = "MIT"
16
16
 
@@ -11,10 +11,8 @@ module Dydx
11
11
 
12
12
  def differentiate(sym=:x)
13
13
  case @operator
14
- when :+
15
- f.d(sym) + g.d(sym)
16
- when :*
17
- (f.d(sym) * g) + (f * g.d(sym))
14
+ when :+ then f.d(sym) + g.d(sym)
15
+ when :* then (f.d(sym) * g) + (f * g.d(sym))
18
16
  when :^
19
17
  # TODO:
20
18
  if g.is_num?
@@ -31,18 +29,14 @@ module Dydx
31
29
  alias_method :d, :differentiate
32
30
 
33
31
  def to_s
34
- if (multiplication? && (f.is_minus1? || g.is_minus1?) )
32
+ if (formula?(:*) && (f.is_minus1? || g.is_minus1?) )
35
33
  "( - #{g.to_s} )"
36
- elsif multiplication? && g.inverse?(:*)
37
- "( #{f.to_s} / #{g.x.to_s} )"
38
- elsif multiplication? && f.inverse?(:*)
39
- "( #{g.to_s} / #{f.x.to_s} )"
40
- elsif addition? && g.inverse?(:+)
41
- "( #{f.to_s} - #{g.x.to_s} )"
42
- elsif addition? && f.inverse?(:+)
43
- "( #{g.to_s} - #{f.x.to_s} )"
34
+ elsif g.inverse?(operator)
35
+ "( #{f.to_s} #{inverse_ope(operator)} #{g.x.to_s} )"
36
+ elsif f.inverse?(operator)
37
+ "( #{g.to_s} #{inverse_ope(operator)} #{f.x.to_s} )"
44
38
  else
45
- "( #{f.to_s} #{@operator} #{g.to_s} )"
39
+ "( #{f.to_s} #{operator} #{g.to_s} )"
46
40
  end
47
41
  end
48
42
 
@@ -9,12 +9,9 @@ module Dydx
9
9
  end
10
10
 
11
11
  def to_s
12
- # sym = {'*'=>'/', '+'=>'-'}[operator.to_s]
13
12
  case operator
14
- when :+
15
- "( - #{x} )"
16
- when :*
17
- "( 1 / #{x} )"
13
+ when :+ then "( - #{x} )"
14
+ when :* then "( 1 / #{x} )"
18
15
  end
19
16
  end
20
17
 
@@ -27,10 +24,6 @@ module Dydx
27
24
  end
28
25
  end
29
26
  alias_method :d, :differentiate
30
-
31
- def ==(x)
32
- to_s == x.to_s
33
- end
34
27
  end
35
28
  end
36
- end
29
+ end
@@ -13,6 +13,8 @@ module Dydx
13
13
  else
14
14
  super(x)
15
15
  end
16
+ elsif formula?(sub_ope(operator)) && openable?(operator, x)
17
+ f.send(operator, x).send(sub_ope(operator), g.send(operator, x))
16
18
  elsif formula?(super_ope(operator)) && x.formula?(super_ope(operator))
17
19
  w1, w2 = common_factors(x)
18
20
  return super(x) unless (w1 && w2) && (super_ope(operator).commutative? || w1 == w2)
@@ -49,11 +51,13 @@ module Dydx
49
51
  end
50
52
  end
51
53
 
52
- def ^(x)
53
- if multiplication? && openable?(:^, x)
54
- (f ^ x).send(self.operator, (g ^ x))
55
- else
56
- super(x)
54
+ %w(^).map(&:to_sym).each do |operator|
55
+ define_method(operator) do |x|
56
+ if formula?(sub_ope(operator)) && openable?(operator, x)
57
+ f.send(operator, x).send(sub_ope(operator), g.send(operator, x))
58
+ else
59
+ super(x)
60
+ end
57
61
  end
58
62
  end
59
63
  end
@@ -43,8 +43,8 @@ module Dydx
43
43
  else
44
44
  super(x)
45
45
  end
46
- elsif [:*].include?(operator) && x.inverse?(:+)
47
- inverse(::Algebra::Formula.new(self, x.x, operator.to_sym), :+)
46
+ elsif operator == :* && x.inverse?(:+)
47
+ -(self * x.x)
48
48
  else
49
49
  super(x)
50
50
  end
@@ -4,7 +4,7 @@ module Dydx
4
4
  module Parts
5
5
  module Symbol
6
6
  def *(x)
7
- if x.exponentiation? &&
7
+ if x.formula?(:^) &&
8
8
  self == x.f
9
9
 
10
10
  self ^ (1 + x.g)
@@ -16,10 +16,6 @@ module Dydx
16
16
  def to_s
17
17
  @n.to_s
18
18
  end
19
-
20
- def ==(x)
21
- to_s == x.to_s
22
- end
23
19
  end
24
20
  end
25
21
  end
@@ -12,10 +12,11 @@ module Dydx
12
12
  "sin( #{x.to_s} )"
13
13
  end
14
14
 
15
- def d(sym=:x)
15
+ def differentiate(sym=:x)
16
16
  cos(x) * x.d(sym)
17
17
  end
18
+ alias_method :d, :differentiate
18
19
  end
19
20
  end
20
21
  end
21
- end
22
+ end
data/lib/dydx/helper.rb CHANGED
@@ -62,6 +62,7 @@ module Dydx
62
62
  case operator
63
63
  when :+
64
64
  (is_num? && x.is_num?) ||
65
+ (formula?(:*) && (f.is_num? || g.is_num?)) && x.is_num? ||
65
66
  like_term?(x) ||
66
67
  inverse?(:+, x)
67
68
  when :*
@@ -110,9 +111,6 @@ module Dydx
110
111
  ([:f, :g] - [f_or_g]).first
111
112
  end
112
113
 
113
- def commutative?
114
- end
115
-
116
114
  def distributable?(operator)
117
115
  end
118
116
 
data/lib/dydx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = "0.1.28"
2
+ VERSION = "0.1.29"
3
3
  end
@@ -47,6 +47,11 @@ describe Dydx::Algebra::Operator::Parts::Formula do
47
47
  it{ expect((:y - (:x - :y)).to_s).to eq('( ( 2 * y ) - x )') }
48
48
  it{ expect((:y - (:y - :x)).to_s).to eq('x') }
49
49
 
50
+ it{ expect((x + 3) * 2).to eq(x * 2 + 6) }
51
+ # it{ expect((x - 3) * 2).to eq(x * 2 - 6) }
52
+ it{ expect((x + 3) * 2).to eq(x * 2 + 6) }
53
+ it{ expect((x + 3) * 2).to eq(x * 2 + 6) }
54
+
50
55
  it{ expect(((:x * 2) ^ 2).to_s).to eq('( 4 * ( x ^ 2 ) )') }
51
56
  it{ expect(((:x / 2) ^ 2).to_s).to eq('( ( x ^ 2 ) / 4 )') }
52
57
 
@@ -28,8 +28,8 @@ describe Dydx:Function do
28
28
 
29
29
  it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq(h(a, b, c)) }
30
30
  it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq($h) }
31
- it{ expect(h(a, b, c)).to eq(( ( 2 * b ) + a )) }
32
- it{ expect(h(a, b, c).algebra).to eq(( ( 2 * b ) + a )) }
31
+ it{ expect(h(a, b, c)).to eq(( a + ( 2 * b ) )) }
32
+ it{ expect(h(a, b, c).algebra).to eq(( a + ( 2 * b ) )) }
33
33
 
34
34
  it 'ex.4' do
35
35
  $f = nil
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.1.28
4
+ version: 0.1.29
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - gogotanaka
@@ -13,56 +14,62 @@ 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
- 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.
62
+ description: Dydx is new math DSL in Ruby. The most important thing in this DSL is
63
+ we can handle math in the same sense sense of the math on paper.
57
64
  email:
58
65
  - qlli.illb@gmail.com
59
66
  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
@@ -125,27 +132,34 @@ files:
125
132
  homepage: https://github.com/gogotanaka
126
133
  licenses:
127
134
  - MIT
128
- metadata: {}
129
135
  post_install_message:
130
136
  rdoc_options: []
131
137
  require_paths:
132
138
  - lib
133
139
  required_ruby_version: !ruby/object:Gem::Requirement
140
+ none: false
134
141
  requirements:
135
- - - ">="
142
+ - - ! '>='
136
143
  - !ruby/object:Gem::Version
137
144
  version: '0'
145
+ segments:
146
+ - 0
147
+ hash: -4040478879646027093
138
148
  required_rubygems_version: !ruby/object:Gem::Requirement
149
+ none: false
139
150
  requirements:
140
- - - ">="
151
+ - - ! '>='
141
152
  - !ruby/object:Gem::Version
142
153
  version: '0'
154
+ segments:
155
+ - 0
156
+ hash: -4040478879646027093
143
157
  requirements: []
144
158
  rubyforge_project:
145
- rubygems_version: 2.2.2
159
+ rubygems_version: 1.8.23
146
160
  signing_key:
147
- specification_version: 4
148
- summary: We can enjoy the derivative.
161
+ specification_version: 3
162
+ summary: We can enjoy the math.
149
163
  test_files:
150
164
  - spec/dydx_spec.rb
151
165
  - spec/lib/algebra/formula_spec.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: a53690ed9d47e90702608c9276bdf2dd76af42f4
4
- data.tar.gz: eb525a3c66c33109a6c70a621c1dfaff1fe31bb4
5
- SHA512:
6
- metadata.gz: afc1fabc722750af74ff12f064479928cbc3863066d76f20bb74aa46317bd556c3d90d92abf0365c528feaa76029c00e245b5ee31140a5ad2721e9145172b6c6
7
- data.tar.gz: a1f587f80289788da9b414af04c3efe270a49b5a4e84287c88a6c58a3d7fc2bcb6619fb6e95b9a00650e2782f4ef0cf4749bac894d34790b5b80144561c094fe