dydx 0.1.31 → 0.1.314

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +22 -59
  3. data/lib/dydx.rb +7 -4
  4. data/lib/dydx/algebra.rb +0 -66
  5. data/lib/dydx/algebra/formula.rb +15 -2
  6. data/lib/dydx/algebra/inverse.rb +14 -0
  7. data/lib/dydx/algebra/set.rb +253 -19
  8. data/lib/dydx/helper.rb +5 -0
  9. data/lib/dydx/integrand.rb +7 -2
  10. data/lib/dydx/version.rb +1 -1
  11. data/spec/dydx_spec.rb +10 -29
  12. data/spec/lib/algebra/formula_spec.rb +6 -0
  13. data/spec/lib/algebra/set_spec.rb +227 -0
  14. data/spec/lib/delta_spec.rb +26 -0
  15. data/spec/lib/function_spec.rb +61 -33
  16. data/spec/lib/integrand_spec.rb +2 -2
  17. metadata +4 -40
  18. data/lib/dydx/algebra/operator.rb +0 -5
  19. data/lib/dydx/algebra/set/base.rb +0 -9
  20. data/lib/dydx/algebra/set/cos.rb +0 -22
  21. data/lib/dydx/algebra/set/e.rb +0 -16
  22. data/lib/dydx/algebra/set/fixnum.rb +0 -14
  23. data/lib/dydx/algebra/set/float.rb +0 -14
  24. data/lib/dydx/algebra/set/log.rb +0 -22
  25. data/lib/dydx/algebra/set/log10.rb +0 -22
  26. data/lib/dydx/algebra/set/log2.rb +0 -22
  27. data/lib/dydx/algebra/set/num.rb +0 -22
  28. data/lib/dydx/algebra/set/pi.rb +0 -16
  29. data/lib/dydx/algebra/set/sin.rb +0 -22
  30. data/lib/dydx/algebra/set/symbol.rb +0 -14
  31. data/lib/dydx/algebra/set/tan.rb +0 -17
  32. data/spec/lib/algebra/set/cos_spec.rb +0 -18
  33. data/spec/lib/algebra/set/e_spec.rb +0 -27
  34. data/spec/lib/algebra/set/fixnum_spec.rb +0 -65
  35. data/spec/lib/algebra/set/float_spec.rb +0 -65
  36. data/spec/lib/algebra/set/log10_spec.rb +0 -16
  37. data/spec/lib/algebra/set/log2_spec.rb +0 -16
  38. data/spec/lib/algebra/set/log_spec.rb +0 -15
  39. data/spec/lib/algebra/set/num_spec.rb +0 -23
  40. data/spec/lib/algebra/set/pi_spec.rb +0 -25
  41. data/spec/lib/algebra/set/sin_spec.rb +0 -14
  42. data/spec/lib/algebra/set/symbol_spec.rb +0 -22
  43. data/spec/lib/algebra/set/tan_spec.rb +0 -13
data/lib/dydx/helper.rb CHANGED
@@ -141,5 +141,10 @@ module Dydx
141
141
  def ==(x)
142
142
  to_s == x.to_s
143
143
  end
144
+
145
+ # Refactor
146
+ def **(x)
147
+ self ^ (x)
148
+ end
144
149
  end
145
150
  end
@@ -7,13 +7,14 @@ module Dydx
7
7
  end
8
8
 
9
9
  def [](a, b, n = 1000)
10
- raise ArgumentError, 'b should be greater than a' if a > b
11
- f = function
12
10
  # HOT FIX: should implement Infinity class
13
11
  a = - 1000 if a == - Float::INFINITY
14
12
  b = 1000 if b == Float::INFINITY
15
13
 
16
14
  a, b = [a, b].map(&:to_f)
15
+ raise ArgumentError, 'b should be greater than a' if a > b
16
+ $int_f = function
17
+
17
18
  n = [n, (b - a) * 2].max
18
19
  n += 1 if n.to_i.odd?
19
20
  h = (b - a) / n
@@ -24,6 +25,10 @@ module Dydx
24
25
  round_8( (h / 3) * (f(a) + f(b) + 2 * even_sum + 4 * odd_sum) )
25
26
  end
26
27
 
28
+ def f(vars)
29
+ int_f(vars)
30
+ end
31
+
27
32
  def round_8(num)
28
33
  return num if num.abs == Float::INFINITY
29
34
  (num * 10 ** 8).round * 10.0 ** (-8)
data/lib/dydx/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dydx
2
- VERSION = "0.1.31"
2
+ VERSION = "0.1.314"
3
3
  end
data/spec/dydx_spec.rb CHANGED
@@ -5,35 +5,16 @@ describe Dydx do
5
5
  expect(Dydx::VERSION).not_to be nil
6
6
  end
7
7
 
8
- context 'ex1' do
9
- $a = (:x ^ :n)
10
- let(:d1){ da/dx }
11
- let(:d2){ d/dx($a) }
12
- it{ expect(d1.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
13
- it{ expect(d2.to_s).to eq('( n * ( x ^ ( n - 1 ) ) )') }
14
- end
15
-
16
- context 'ex2' do
17
- $b = (:x ^ (:x * 2))
18
- let(:d1){ db/dx }
19
- let(:d2){ d/dx($b) }
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
- end
23
-
24
- context 'ex3' do
25
- $c = (:t ^ 2) / 2
26
- let(:d1){ dc/dt }
27
- let(:d2){ d/dt($c) }
28
- it{ expect(d1.to_s).to eq('t') }
29
- it{ expect(d2.to_s).to eq('t') }
30
- end
8
+ it 'demo' do
9
+ f(x, y) <= x + x*y + y
10
+ expect(f(x, y)).to eq(x * (1 + y) + y)
11
+ expect(f(a, 2)).to eq(3*a + 2)
12
+ expect(f(1, a + b)).to eq(1 + 2 * ( a + b ))
13
+ expect(f(1, 2)).to eq(5)
14
+ expect(d/dx(f(x, y))).to eq(1 + y)
31
15
 
32
- context 'ex4' do
33
- $i = 2 * (e ^ (2 * :z))
34
- let(:d1){ di/dz }
35
- let(:d2){ d/dz($i) }
36
- it{ expect(d1.to_s).to eq('( 4 * ( e ^ ( 2 * z ) ) )') }
37
- it{ expect(d2.to_s).to eq('( 4 * ( e ^ ( 2 * z ) ) )') }
16
+ g(x) <= sin(x)
17
+ expect(d/dx(g(x))).to eq(cos(x))
18
+ expect(S(g(x), dx)[0, pi/2]).to eq(1.0)
38
19
  end
39
20
  end
@@ -28,6 +28,12 @@ describe Dydx::Algebra::Formula do
28
28
  it{ expect( (addition * multiplication).to_s ).to eq('( ( x + y ) * ( x * y ) )') }
29
29
  end
30
30
 
31
+ describe '#subst' do
32
+ it{ expect((x + y).subst(x: 3, y: 3)).to eq(6) }
33
+ it{ expect((x + y).subst(x: 3)).to eq(3 + y) }
34
+ it{ expect((x + y + pi).subst(x: 3, y: 3).to_f).to eq(Math::PI + 6) }
35
+ end
36
+
31
37
  describe '#differentiate' do
32
38
  it{ expect(addition.d(:x)).to eq(1) }
33
39
  it{ expect(addition.d(:y)).to eq(1) }
@@ -0,0 +1,227 @@
1
+ require 'spec_helper'
2
+ # HOTFIX: Refactor by using context or describe
3
+ describe Dydx::Algebra::Set do
4
+ it{ expect(_(1)).to eq(_(1)) }
5
+ it{ expect(_(-1)).to eq(_(-1)) }
6
+ it{ expect(e0).to eq(e0) }
7
+ it{ expect(e1).to eq(e1) }
8
+
9
+ it{ expect(e).to eq(e) }
10
+ it{ expect(pi).to eq(pi) }
11
+
12
+ it { expect(log10(1)).to eq(e0) }
13
+ it { expect(log10(10)).to eq(e1) }
14
+ it { expect(log10(10 ^ n)).to eq(n) }
15
+ it { expect(log10(3 ^ n)).to eq(n * log10( 3 )) }
16
+
17
+ it { expect(log2(1)).to eq(e0) }
18
+ it { expect(log2(2)).to eq(e1) }
19
+ it { expect(log2(2 ^ n)).to eq(n) }
20
+ it { expect(log2(3 ^ n)).to eq(n * log2( 3 )) }
21
+
22
+ it{ expect(log(1)).to eq(0) }
23
+ it{ expect(log(e)).to eq(1) }
24
+ it{ expect(log(e ^ n)).to eq(n) }
25
+
26
+ it{ expect(sin(pi)).to eq(0) }
27
+
28
+ it{ expect(cos(0)).to eq(1) }
29
+ it{ expect(cos(pi)).to eq(-1) }
30
+ it{ expect(cos(2 * pi)).to eq(1) }
31
+
32
+ describe '#to_s' do
33
+ it{ expect(e.to_s).to eq('e') }
34
+
35
+ it{ expect(1.to_s).to eq('1') }
36
+
37
+ it{ expect(1.0.to_s).to eq('1.0') }
38
+
39
+ it{ expect(e1.to_s).to eq('1') }
40
+
41
+ it{ expect(pi.to_s).to eq('pi') }
42
+
43
+ it{ expect(cos(x).to_s).to eq('cos( x )') }
44
+ it{ expect(sin(x).to_s).to eq('sin( x )') }
45
+ it{ expect(tan(x).to_s).to eq('tan( x )') }
46
+
47
+ it{ expect(x.to_s).to eq('x') }
48
+ end
49
+
50
+ describe '#==' do
51
+ it{ expect(_(1) == _(1)).to be_true }
52
+ end
53
+
54
+ describe '#subst' do
55
+ it{ expect(1.subst).to eq(1) }
56
+ it{ expect(1.0.subst).to eq(1.0) }
57
+ it{ expect(e.subst).to eq(e) }
58
+ it{ expect(pi.subst).to eq(pi) }
59
+ it{ expect(sin(x).subst(x: 3)).to eq(sin(3)) }
60
+ it{ expect(cos(x).subst(x: pi)).to eq(-1) }
61
+ it{ expect(tan(0).subst(x: pi)).to eq(0) }
62
+ it{ expect(log(x).subst(x: e)).to eq(1) }
63
+ it{ expect(log10(x).subst(x: 7)).to eq(log10(7)) }
64
+ it{ expect(log2(2).subst(x: 2)).to eq(1) }
65
+ it{ expect(x.subst(x: 2)).to eq(2) }
66
+ it{ expect(x.subst(y: 2)).to eq(x) }
67
+ end
68
+
69
+ describe '#differentiate' do
70
+ it { expect(e.d).to eq(0) }
71
+ it { expect((e ^ x).d).to eq(e ^ x) }
72
+ it { expect((e ^ (x + y)).d).to eq(e ^ ( x + y )) }
73
+
74
+ it { expect(pi.d(x)).to eq(0) }
75
+
76
+ it { expect(1.d).to eq(0) }
77
+ it { expect(3.d).to eq(0) }
78
+ it { expect(3.0.d).to eq(0) }
79
+
80
+ it { expect(sin(x).d).to eq(cos(x)) }
81
+ it { expect(cos(x).d).to eq(- sin(x)) }
82
+ it { expect(tan(x).d).to eq(1 / cos(x) ^ 2) }
83
+
84
+ it { expect(log(x).d).to eq(1 / x) }
85
+ it { expect(log10(x).d).to eq(1 / ( x * log( 10 ) )) }
86
+ it { expect(log2(x).d).to eq(1 / ( x * log( 2 ) )) }
87
+
88
+ it{ expect(x.d(x)).to eq(1) }
89
+ end
90
+
91
+ describe 'Calculate' do
92
+ context 'E with Fixnum' do
93
+ it{ expect(e + 0).to eq(e) }
94
+ it{ expect(e - 0).to eq(e) }
95
+ it{ expect((e * 0).to_s).to eq('0') }
96
+ it{ expect(e * 1).to eq(e) }
97
+ it{ expect{(e / 0).to_s}.to raise_error(ZeroDivisionError) }
98
+ it{ expect(e / 1).to eq(e) }
99
+ it{ expect((e ^ 0).to_s).to eq('1') }
100
+ end
101
+
102
+ context 'Fixnum with Formula' do
103
+ let(:formula) { (:x + :y) }
104
+ it{ expect((0 + formula).to_s).to eq(formula.to_s) }
105
+ it{ expect((0 - formula).to_s).to eq('( - ( x + y ) )') }
106
+ it{ expect((0 * formula).to_s).to eq('0') }
107
+ it{ expect((1 * formula).to_s).to eq(formula.to_s) }
108
+ it{ expect((0 / formula).to_s).to eq('0') }
109
+ it{ expect((1 / formula).to_s).to eq('( 1 / ( x + y ) )') }
110
+ it{ expect((0 ^ formula).to_s).to eq('0') }
111
+ it{ expect((1 ^ formula).to_s).to eq('1') }
112
+ end
113
+
114
+ context 'Fixnum with Symbol' do
115
+ it{ expect(0 + :x).to eq(:x) }
116
+ it{ expect((0 - :x).to_s).to eq('( - x )') }
117
+ it{ expect((0 * :x).to_s).to eq('0') }
118
+ it{ expect(1 * :x).to eq(:x) }
119
+ it{ expect((0 / :x).to_s).to eq('0') }
120
+ it{ expect((1 / :x).to_s).to eq('( 1 / x )') }
121
+ it{ expect((0 ^ :x).to_s).to eq('0') }
122
+ it{ expect((1 ^ :x).to_s).to eq('1') }
123
+ end
124
+
125
+ context 'Fixnum with Fixnum' do
126
+ it{ expect(0 + 3).to eq(3) }
127
+ it{ expect(3 + 0).to eq(3) }
128
+ it{ expect(2 + 3).to eq(5) }
129
+
130
+ it{ expect(0 - 3).to eq(-3) }
131
+ it{ expect(3 - 0).to eq(3) }
132
+ it{ expect(2 - 3).to eq(-1) }
133
+
134
+ it{ expect(0 * 3).to eq(0) }
135
+ it{ expect(3 * 0).to eq(0) }
136
+ it{ expect(1 * 3).to eq(3) }
137
+ it{ expect(3 * 1).to eq(3) }
138
+ it{ expect(3 * 2).to eq(6) }
139
+
140
+ it{ expect((0 / 3).to_s).to eq('0') }
141
+ it{ expect{(3 / 0).to_s}.to raise_error(ZeroDivisionError) }
142
+ it{ expect((3 / 1).to_s).to eq('3') }
143
+ # TODO:
144
+ it{ expect((2 / 3).to_s).to eq('0') }
145
+
146
+
147
+ it{ expect((0 ^ 3).to_s).to eq('0') }
148
+ it{ expect((3 ^ 0).to_s).to eq('1') }
149
+ it{ expect((1 ^ 3).to_s).to eq('1') }
150
+ it{ expect((3 ^ 1).to_s).to eq('3') }
151
+ it{ expect((3 ^ 2).to_s).to eq('9') }
152
+ end
153
+
154
+ context 'Float with Formula' do
155
+ let(:formula) { (:x + :y) }
156
+ it{ expect((0.0 + formula).to_s).to eq(formula.to_s) }
157
+ it{ expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
158
+ it{ expect((0.0 * formula).to_s).to eq('0') }
159
+ it{ expect((1.0 * formula).to_s).to eq(formula.to_s) }
160
+ it{ expect((0.0 / formula).to_s).to eq('0') }
161
+ it{ expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
162
+ it{ expect((0.0 ^ formula).to_s).to eq('0') }
163
+ it{ expect((1.0 ^ formula).to_s).to eq('1') }
164
+ end
165
+
166
+ context 'Float with Symbol' do
167
+ it{ expect(0.0 + :x).to eq(:x) }
168
+ it{ expect((0.0 - :x).to_s).to eq('( - x )') }
169
+ it{ expect((0.0 * :x).to_s).to eq('0') }
170
+ it{ expect(1.0 * :x).to eq(:x) }
171
+ it{ expect((0.0 / :x).to_s).to eq('0') }
172
+ it{ expect((1.0 / :x).to_s).to eq('( 1 / x )') }
173
+ it{ expect((0.0 ^ :x).to_s).to eq('0') }
174
+ it{ expect((1.0 ^ :x).to_s).to eq('1') }
175
+ end
176
+
177
+ context 'Float with Float' do
178
+ it{ expect(0.0 + 3.0).to eq(3.0) }
179
+ it{ expect(3.0 + 0.0).to eq(3.0) }
180
+ it{ expect(2.0 + 3.0).to eq(5.0) }
181
+
182
+ it{ expect(0.0 - 3.0).to eq(-3.0) }
183
+ it{ expect(3.0 - 0.0).to eq(3.0) }
184
+ it{ expect(2.0 - 3.0).to eq(-1.0) }
185
+
186
+ it{ expect(0.0 * 3.0).to eq(0.0) }
187
+ it{ expect(3.0 * 0.0).to eq(0.0) }
188
+ it{ expect(1.0 * 3.0).to eq(3.0) }
189
+ it{ expect(3.0 * 1.0).to eq(3.0) }
190
+ it{ expect(3.0 * 2.0).to eq(6.0) }
191
+
192
+ it{ expect(0.0 / 3.0).to eq(0.0) }
193
+ it{ expect(3.0 / 0.0).to eq(oo) }
194
+ it{ expect(3.0 / 1.0).to eq(3.0) }
195
+ # TODO:
196
+ it{ expect(2.0 / 3.0).to eq(0.6666666666666666) }
197
+
198
+
199
+ it{ expect(0.0 ^ 3.0).to eq(0.0) }
200
+ it{ expect(3.0 ^ 0.0).to eq(1.0) }
201
+ it{ expect(1.0 ^ 3.0).to eq(1.0) }
202
+ it{ expect(3.0 ^ 1.0).to eq(3.0) }
203
+ it{ expect(3.0 ^ 2.0).to eq(9.0) }
204
+ end
205
+
206
+ context 'Pi with Fixnum' do
207
+ it{ expect(pi + 0).to eq(pi) }
208
+ it{ expect(pi - 0).to eq(pi) }
209
+ it{ expect((pi * 0).to_s).to eq('0') }
210
+ it{ expect(pi * 1).to eq(pi) }
211
+ it{ expect{(pi / 0).to_s}.to raise_error(ZeroDivisionError) }
212
+ it{ expect(pi / 1).to eq(pi) }
213
+ it{ expect((pi ^ 0).to_s).to eq('1') }
214
+ end
215
+
216
+ context 'Symbol with Fixnum' do
217
+ it{ expect(:x + 0).to eq(:x) }
218
+ it{ expect(:x - 0).to eq(:x) }
219
+ it{ expect((:x * 0).to_s).to eq('0') }
220
+ it{ expect(:x * 1).to eq(:x) }
221
+ it{ expect{(:x / 0).to_s}.to raise_error(ZeroDivisionError) }
222
+ it{ expect(:x / 1).to eq(:x) }
223
+ it{ expect((:x ^ 0).to_s).to eq('1') }
224
+ it{ expect(:x ^ 1).to eq(:x) }
225
+ end
226
+ end
227
+ end
@@ -8,4 +8,30 @@ describe Dydx:Delta do
8
8
  it{ expect(dx(y).var).to eq(:x) }
9
9
  it{ expect(dx(y).function).to eq(:y) }
10
10
  it{ expect{dxy}.to raise_error(NameError) }
11
+
12
+ before(:each) do
13
+ $y = example
14
+ end
15
+
16
+ context 'ex1' do
17
+ let(:example) { x ^ n }
18
+ it { expect(dy/dx).to eq( n * ( x ^ ( n - 1 ) ) ) }
19
+ it { expect(d/dx($y)).to eq( n * ( x ^ ( n - 1 ) ) ) }
20
+ end
21
+
22
+ context 'ex2' do
23
+ let(:example) { x ^ (x * 2) }
24
+ it{ expect(dy/dx).to eq(( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) )) }
25
+ it{ expect(d/dx($y)).to eq(( 2 * x ) * ( x ^ ( ( 2 * x ) - 1 ) )) }
26
+ end
27
+
28
+ context 'ex3' do
29
+ let(:example) { (t ^ 2) / 2 }
30
+ it{ expect(dy/dt).to eq(t) }
31
+ end
32
+
33
+ context 'ex4' do
34
+ let(:example) { 2 * (e ^ (2 * z)) }
35
+ it{ expect(dy/dz).to eq(4 * ( e ^ ( 2 * z ) )) }
36
+ end
11
37
  end
@@ -1,39 +1,67 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Dydx:Function do
4
- # TODO: refactor
5
- it{ expect(f(x, y)).to eq(f(x, y)) }
6
- it{ expect(f(x, y)).to eq($f) }
7
- it{ expect(f(x, y).algebra).to be_nil }
8
- it{ expect(f(x, y).vars).to eq([:x, :y]) }
9
- it{ expect{f(x, y, z)}.to raise_error(ArgumentError) }
10
- it{ expect{f(x)}.to raise_error(ArgumentError) }
11
- it{ expect(f(x, y) <= x * y ).to eq(f(x, y)) }
12
- it{ expect(f(x, y)).to eq(f(x, y)) }
13
- it{ expect(f(x, y)).to eq($f) }
14
- it{ expect(f(x, y).algebra).to eq(x * y) }
15
- it{ expect(f(x, y)).to eq(x * y) }
16
- it{ expect(eval(f(x, y).to_s)).to eq(f(x, y)) }
17
- it{ expect(f(x, y)).to eq(eval(f(x, y).to_s)) }
18
- it{ expect(f(a, b)).to eq(a * b) }
19
- it{ expect(f(2, 3)).to eq(6) }
20
- it{ expect(f(a + b, c)).to eq((a + b) * c) }
21
- it{ expect(d/dx(f(x, y))).to eq(y) }
22
- it{ expect(d/dy(f(x, y))).to eq(x) }
23
- it{ expect(d/dz(f(x, y))).to eq(0) }
24
-
25
- it{ expect(g(a, b) <= f(a + b, b)).to eq(g(a, b)) }
26
- it{ expect(g(a, b)).to eq($g) }
27
- it{ expect(g(2, 3)).to eq(15) }
28
-
29
- it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq(h(a, b, c)) }
30
- it{ expect(h(a, b, c) <= d/db(g(a, b))).to eq($h) }
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
-
34
- it 'ex.4' do
35
- $f = nil
4
+ before(:each) do
5
+ reset
6
+ end
7
+
8
+ it 'ex1' do
9
+ expect(f(x, y)).to eq(f(x, y))
10
+ expect(f(x, y)).to eq($f)
11
+ expect(f(x, y).algebra).to be_nil
12
+ 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)
15
+ end
16
+
17
+ it 'ex2' do
18
+ expect(f(x, y) <= x * y ).to eq(f(x, y))
19
+ expect(f(x, y)).to eq(f(x, y))
20
+ expect(f(x, y)).to eq($f)
21
+ expect(f(x, y).algebra).to eq(x * y)
22
+ expect(f(x, y)).to eq(x * y)
23
+ expect(f(x, y)).to eq(eval(f(x, y).to_s))
24
+ expect(f(a, b)).to eq(a * b)
25
+ expect(f(2, x)).to eq(2 * x)
26
+ expect(f(2, 3)).to eq(6)
27
+ expect(f(a + b, c)).to eq((a + b) * c)
28
+ expect(d/dx(f(x, y))).to eq(y)
29
+ expect(d/dy(f(x, y))).to eq(x)
30
+ expect(d/dz(f(x, y))).to eq(0)
31
+ end
32
+
33
+ it 'ex3' do
34
+ f(x, y) <= x * y
35
+ g(a, b) <= f(a + b, b)
36
+ expect(g(a, b)).to eq((a + b) * b)
37
+ expect(g(a, 3)).to eq(9 + 3 * a)
38
+ expect(g(2, 3)).to eq(15)
39
+ end
40
+
41
+ it 'ex4' do
42
+ f(a, b) <= (a + b) * b
43
+ h(a, b, c) <= d/db(f(a, b))
44
+ expect(h(a, b, c)).to eq(( a + ( 2 * b ) ))
45
+ expect(h(a, b, c).algebra).to eq(( a + ( 2 * b ) ))
46
+ end
47
+
48
+ it 'ex5' do
36
49
  f(x) <= log(x)
37
- expect(f(a)).to eq(log(a))
50
+ expect(f(e)).to eq(1)
51
+ expect(f(0)).to eq(-oo)
52
+ expect(f(y)).to eq(log(y))
53
+
54
+ g(x) <= d/dx(f(x))
55
+ expect(g(1)).to eq(1)
56
+ end
57
+
58
+ it 'ex6' do
59
+ f(x) <= sin(x)
60
+ expect(f(pi)).to eq(0)
61
+ expect(f(pi / 2)).to eq(1)
62
+ expect(f(y)).to eq(sin(y))
63
+
64
+ g(x) <= d/dx(f(x))
65
+ expect(g(pi)).to eq(-1)
38
66
  end
39
67
  end