dydx 0.1.25 → 0.1.28

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 50e18dda6ca41f30bb45fdbc2f73c906c6e01c94
4
- data.tar.gz: 14094dd2083a888d715e93eb0a1faa8aa6f9cf13
3
+ metadata.gz: a53690ed9d47e90702608c9276bdf2dd76af42f4
4
+ data.tar.gz: eb525a3c66c33109a6c70a621c1dfaff1fe31bb4
5
5
  SHA512:
6
- metadata.gz: abbe8199d94ede3e5568aaf41c5d4dba0996af0b2da53e8313372d96d67c401c64e802f30777995f92fc966cb4e81740ffae5228ce352f711856793615435d3c
7
- data.tar.gz: 12087ca360a5da0e9fa6c32ed5818d8b40c3044a1f9efa2da4bbf75772fad9794a5b7660eb6239009c051ebe30ac7f8ef293611caf16b3610c265709a6f5e7c8
6
+ metadata.gz: afc1fabc722750af74ff12f064479928cbc3863066d76f20bb74aa46317bd556c3d90d92abf0365c528feaa76029c00e245b5ee31140a5ad2721e9145172b6c6
7
+ data.tar.gz: a1f587f80289788da9b414af04c3efe270a49b5a4e84287c88a6c58a3d7fc2bcb6619fb6e95b9a00650e2782f4ef0cf4749bac894d34790b5b80144561c094fe
data/README.md CHANGED
@@ -1,115 +1,95 @@
1
- # Dydx
2
- It always happens you want to differentiate some formulas with ruby. right?.....
1
+ # Dydx is new math DSL in Ruby
3
2
 
4
- After `inlcude Dydx` , ruby become like other language.
3
+ ### Since you report a bug, I will fix it within 24 hours.
4
+
5
+ The most important thing in this DSL is
5
6
 
6
- ## Dydx is new math DSL in Ruby
7
+ we can handle math in the same sense sense of the math on paper.
7
8
 
8
- I'm going to add for more explanation.
9
+ ex. limit, trigonometric functions and logarithmic.
9
10
 
10
11
 
12
+ After `inlcude Dydx` , ruby become like other language.
11
13
 
14
+ ## Outline
12
15
  ```ruby:
13
16
  require 'dydx'
14
17
  include Dydx
15
18
 
19
+ # Define the function. syntax is not good enough...
16
20
  f(x) <= x ^ 2
17
21
 
18
22
  f(3)
19
- # => 9
23
+ => 9
20
24
 
21
25
  f(x).to_s
22
- # => "( x ^ 2 )"
26
+ => "( x ^ 2 )"
23
27
 
24
28
  f(x) == eval('f(x).to_s')
25
- # => true
29
+ => true
26
30
 
31
+ # Differentiate
27
32
  g(x) <= d/dx(f(x))
28
33
 
29
34
  g(3)
30
- # => 6
35
+ => 6
31
36
 
32
- # => '2 * x'
37
+ g(x).to_s
38
+ => '2 * x'
33
39
 
40
+ # Integrate
34
41
  S(f(x), dx)[0, 1]
35
- # => 0.3333333333333334
42
+ => 0.3333333333333334
43
+ ```
44
+
45
+
46
+ #### limit, trigonometric functions and logarithmic.
47
+ ```ruby:
48
+
49
+ f(z) <= log(z)
50
+ S(f(z), dz)[0,1]
51
+ => -Infinity
36
52
 
37
53
  ( d/dx(log(x)) ).to_s
38
- # => "( 1 / x )"
54
+ => "( 1 / x )"
39
55
 
40
56
  ( d/dx(cos(x)) ).to_s
41
- # => "( - sin( x ) )"
57
+ => "( - sin( x ) )"
42
58
 
43
59
  ( d/dx(e ^ x) ).to_s
44
- # => "( e ^ x )"
60
+ => "( e ^ x )"
45
61
 
46
62
  f(x) <= sin(x)
47
63
  S(f(x), dx)[0, Math::PI/2]
48
- # => 1.000000000021139
64
+ => 1.000000000021139
49
65
 
66
+ # standard normal distribution;
50
67
  f(x) <= (1.0 / ( ( 2.0 * pi ) ^ 0.5 ) ) * ( e ^ (- (x ^ 2) / 2) )
51
68
  S(f(x), dx)[-oo, oo]
52
- # => 0.9952054164466917
69
+ => 0.9952054164466917
70
+ ```
71
+
72
+ #### it's like a magic...
53
73
 
74
+ ```ruby:
54
75
  f(x) <= x ^ 2
55
76
 
56
77
  f(a + b).to_s
57
- # => "( ( a + b ) ^ 2 )"
78
+ => "( ( a + b ) ^ 2 )"
58
79
 
80
+ #↓it"s magic!!!
59
81
  g(a, b) <= f(a + b)
60
82
 
61
83
  g(a, b).to_s
62
- # => "( ( a + b ) ^ 2 )"
84
+ => "( ( a + b ) ^ 2 )"
63
85
 
64
86
  g(2, 2)
65
- # => 16
87
+ => 16
66
88
 
67
89
  ( d/da(g(a, b)) ).to_s
68
90
  => "( 2 * ( a + b ) )"
69
- ```
70
-
71
-
72
-
73
-
74
-
75
- ```
76
- require 'dydx'
77
- include Dydx
78
-
79
- # There are three types of differential interface
80
-
81
- ( d/dx(x^2) ).to_s
82
- => "( 2 * x )"
83
-
84
- log(z).d(z).to_s
85
- => "( 1 / z )"
86
91
 
87
- $y = e ^ x
88
- (dy/dx).to_s
89
- => "( e ^ x )"
90
-
91
- ```
92
-
93
- You may wonder why undefined `x` , `e` and `z` are handleable?
94
-
95
- `method_missing` solve this problem by converting undefine variable into internal class object.
96
-
97
- Like this.
98
-
99
- ```
100
- x + x
101
- => #<Dydx::Algebra::Formula:0x007fb0a4039fb0 @f=#<Dydx::Algebra::Set::Num:0x007fb0a48169e0 @n=2>, @operator=:*, @g=:x>
102
-
103
- e
104
- => #<Dydx::Algebra::Set::E:0x007fb0a383e9f0>
105
-
106
- log(sin(x))
107
- => #<Dydx::Algebra::Set::Log:0x007fe7cd971528 @f=#<Dydx::Algebra::Set::Sin:0x007fe7cd971550 @x=:x>>
108
- ```
109
-
110
- And this DSL has strong simplify.
111
-
112
- ```
92
+ # simplify
113
93
  ((x * y) + (z * x)).to_s
114
94
  => "( x * ( y + z ) )"
115
95
 
@@ -120,38 +100,30 @@ And this DSL has strong simplify.
120
100
  => "( 2 * x )"
121
101
  ```
122
102
 
123
- I show some differential calculus.
124
-
125
- ```
126
- # pretermit '#to_s'
127
-
128
- d/dz(log(z))
129
- => "( 1 / z )"
130
-
131
- d/dx(x^n)
132
- => "( n * ( x ^ ( n - 1 ) ) )"
133
-
134
- $y = cos(x)
135
- dy/dx
136
- => "( - sin( x ) )"
137
103
 
138
- $x = a * ( (t ^ 2) / 2 )
139
- dx/dt
140
- => "( a * t )"
104
+ ## Documents
105
+ I'm going to write now...cominng soon....
141
106
 
142
- d/dt(dx/dt)
143
- =>"a"
144
-
145
- ((x ^ 2) * y).d(x)
146
- => "( ( 2 * x ) * y )"
147
-
148
- ((x ^ 2) * y).d(x).d(y)
149
- => "( 2 * x )"
107
+ ### Module, class configuration
150
108
 
151
109
  ```
152
-
153
-
154
- (That's wonderful!!!!! ..............)
110
+ Dydx
111
+ |- Algebra
112
+ | |- Set
113
+ | | |- Num
114
+ | | |- ....
115
+ | |
116
+ | |- Operator
117
+ | | |- Interface
118
+ | | |- ....
119
+ | |
120
+ | |- Formula
121
+ | |- inverse
122
+ |
123
+ |- Function
124
+ |- Delta
125
+ |- Integrand
126
+ ```
155
127
 
156
128
  ## Installation
157
129
 
@@ -5,6 +5,7 @@ module Dydx
5
5
  attr_accessor :f, :operator, :g
6
6
 
7
7
  def initialize(f, g, operator)
8
+ g, f = f, g if g.is_num? && operator.commutative?
8
9
  @f, @g, @operator = f, g, operator
9
10
  end
10
11
 
@@ -61,10 +61,8 @@ module Dydx
61
61
  def combinable?(x, operator)
62
62
  case operator
63
63
  when :+
64
- self == x ||
65
64
  (is_num? && x.is_num?) ||
66
- (multiplication? && (f == x || g == x)) ||
67
- (x.multiplication? && (x.f == self || x.g == self)) ||
65
+ like_term?(x) ||
68
66
  inverse?(:+, x)
69
67
  when :*
70
68
  self == x ||
@@ -75,6 +73,18 @@ module Dydx
75
73
  end
76
74
  end
77
75
 
76
+ def like_term?(x)
77
+ boolean = if self == x
78
+ elsif formula?(:*) && include?(x)
79
+ elsif x.formula?(:*) && x.include?(self)
80
+ elsif ((formula?(:*) && formula?(:*)) && (([f, g] & [x.f, x.g]).any?{|x| x.is_a?(Symbol)}))
81
+ else
82
+ true
83
+ end
84
+
85
+ !boolean
86
+ end
87
+
78
88
  def is_multiple_of(x)
79
89
  if is_0?
80
90
  e0
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = "0.1.25"
2
+ VERSION = "0.1.28"
3
3
  end
@@ -17,8 +17,8 @@ describe Dydx do
17
17
  $b = (:x ^ (:x * 2))
18
18
  let(:d1){ db/dx }
19
19
  let(:d2){ d/dx($b) }
20
- it{ expect(d1.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
21
- it{ expect(d2.to_s).to eq('( ( x * 2 ) * ( x ^ ( ( x * 2 ) - 1 ) ) )') }
20
+ it{ expect(d1.to_s).to eq('( ( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) ) )') }
21
+ it{ expect(d2.to_s).to eq('( ( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) ) )') }
22
22
  end
23
23
 
24
24
  context 'ex3' do
@@ -47,10 +47,12 @@ 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 * 2) ^ 2).to_s).to eq('( ( x ^ 2 ) * 4 )') }
50
+ it{ expect(((:x * 2) ^ 2).to_s).to eq('( 4 * ( x ^ 2 ) )') }
51
51
  it{ expect(((:x / 2) ^ 2).to_s).to eq('( ( x ^ 2 ) / 4 )') }
52
52
 
53
+ it{ expect((3*x + 4*(x^2)+ 4*x).to_s).to eq('( ( 7 * x ) + ( 4 * ( x ^ 2 ) ) )') }
54
+
53
55
  # TODO:
54
- it{ expect((2 ^ (:x * 2)).to_s).to eq('( 2 ^ ( x * 2 ) )') }
56
+ it{ expect((2 ^ (:x * 2)).to_s).to eq('( 2 ^ ( 2 * x ) )') }
55
57
  it{ expect((2 ^ (:x / 2)).to_s).to eq('( 2 ^ ( x / 2 ) )') }
56
58
  end
@@ -25,6 +25,11 @@ describe Helper do
25
25
  it{ expect((:x * :y).is_multiple_of(:z)).to be_false }
26
26
  end
27
27
 
28
+ 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 }
31
+ end
32
+
28
33
  context '#combinable?' do
29
34
  it{ expect(:x.combinable?(:x, :+)).to be_true }
30
35
  it{ expect(:x.combinable?(2 * :x, :+)).to be_true }
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.25
4
+ version: 0.1.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - gogotanaka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-26 00:00:00.000000000 Z
11
+ date: 2014-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler