dydx 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.pryrc +2 -0
- data/.rubocop.yml +25 -0
- data/Gemfile +3 -0
- data/README.md +29 -64
- data/Rakefile +5 -8
- data/dydx.gemspec +13 -13
- data/lib/dydx.rb +20 -29
- data/lib/dydx/algebra.rb +8 -76
- data/lib/dydx/algebra/formula.rb +67 -29
- data/lib/dydx/algebra/inverse.rb +16 -2
- data/lib/dydx/algebra/operator/formula.rb +0 -4
- data/lib/dydx/algebra/operator/general.rb +0 -4
- data/lib/dydx/algebra/operator/inverse.rb +0 -4
- data/lib/dydx/algebra/operator/num.rb +0 -4
- data/lib/dydx/algebra/operator/parts/base.rb +2 -2
- data/lib/dydx/algebra/operator/parts/formula.rb +61 -40
- data/lib/dydx/algebra/operator/parts/general.rb +83 -30
- data/lib/dydx/algebra/operator/parts/inverse.rb +4 -4
- data/lib/dydx/algebra/operator/parts/num.rb +16 -11
- data/lib/dydx/algebra/operator/parts/symbol.rb +2 -2
- data/lib/dydx/algebra/set.rb +271 -34
- data/lib/dydx/delta.rb +1 -1
- data/lib/dydx/function.rb +1 -1
- data/lib/dydx/helper.rb +53 -67
- data/lib/dydx/integrand.rb +22 -10
- data/lib/dydx/version.rb +1 -1
- data/spec/dydx_spec.rb +10 -29
- data/spec/lib/algebra/formula_spec.rb +44 -38
- data/spec/lib/algebra/operator/parts/base_spec.rb +5 -5
- data/spec/lib/algebra/operator/parts/formula_spec.rb +57 -57
- data/spec/lib/algebra/operator/parts/inverse_spec.rb +8 -8
- data/spec/lib/algebra/set_spec.rb +263 -0
- data/spec/lib/delta_spec.rb +32 -8
- data/spec/lib/function_spec.rb +60 -34
- data/spec/lib/helper_spec.rb +44 -51
- data/spec/lib/integrand_spec.rb +13 -15
- data/spec/spec_helper.rb +2 -1
- metadata +20 -64
- data/lib/dydx/algebra/operator/common_parts.rb +0 -3
- data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
- data/lib/dydx/algebra/operator/symbol.rb +0 -15
- data/lib/dydx/algebra/set/base.rb +0 -9
- data/lib/dydx/algebra/set/cos.rb +0 -22
- data/lib/dydx/algebra/set/e.rb +0 -16
- data/lib/dydx/algebra/set/fixnum.rb +0 -14
- data/lib/dydx/algebra/set/float.rb +0 -14
- data/lib/dydx/algebra/set/log.rb +0 -22
- data/lib/dydx/algebra/set/num.rb +0 -22
- data/lib/dydx/algebra/set/pi.rb +0 -16
- data/lib/dydx/algebra/set/sin.rb +0 -22
- data/lib/dydx/algebra/set/symbol.rb +0 -14
- data/lib/dydx/algebra/set/tan.rb +0 -17
- data/spec/lib/algebra/set/cos_spec.rb +0 -18
- data/spec/lib/algebra/set/e_spec.rb +0 -27
- data/spec/lib/algebra/set/fixnum_spec.rb +0 -65
- data/spec/lib/algebra/set/float_spec.rb +0 -65
- data/spec/lib/algebra/set/log_spec.rb +0 -15
- data/spec/lib/algebra/set/num_spec.rb +0 -23
- data/spec/lib/algebra/set/pi_spec.rb +0 -25
- data/spec/lib/algebra/set/sin_spec.rb +0 -14
- data/spec/lib/algebra/set/symbol_spec.rb +0 -22
- data/spec/lib/algebra/set/tan_spec.rb +0 -13
data/lib/dydx/algebra/set/sin.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
module Dydx
|
2
|
-
module Algebra
|
3
|
-
module Set
|
4
|
-
class Sin < Base
|
5
|
-
attr_accessor :x
|
6
|
-
|
7
|
-
def initialize(x)
|
8
|
-
@x = x
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"sin( #{x.to_s} )"
|
13
|
-
end
|
14
|
-
|
15
|
-
def differentiate(sym=:x)
|
16
|
-
cos(x) * x.d(sym)
|
17
|
-
end
|
18
|
-
alias_method :d, :differentiate
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/lib/dydx/algebra/set/tan.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::Cos do
|
4
|
-
it{ expect(cos(0).to_s).to eq('1') }
|
5
|
-
it{ expect(cos(pi).to_s).to eq('-1') }
|
6
|
-
it{ expect(cos(2 * pi).to_s).to eq('1') }
|
7
|
-
|
8
|
-
describe '#to_s' do
|
9
|
-
it{ expect(cos(:x).to_s).to eq('cos( x )') }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe '#differentiate' do
|
13
|
-
it{ expect(cos(:x).d.to_s).to eq('( - sin( x ) )') }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'Calculate' do
|
17
|
-
end
|
18
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::E do
|
4
|
-
it{ expect(e).to eq(e) }
|
5
|
-
|
6
|
-
describe '#to_s' do
|
7
|
-
it{ expect(e.to_s).to eq('e') }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#differentiate' do
|
11
|
-
it{ expect(e.d(:x).to_s).to eq(_(0).to_s) }
|
12
|
-
it{ expect((e ^ :x).d(:x).to_s).to eq('( e ^ x )') }
|
13
|
-
it{ expect((e ^ (:x + :y)).d(:x).to_s).to eq('( e ^ ( x + y ) )') }
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'Calculate' do
|
17
|
-
context 'With Fixnum' do
|
18
|
-
it{ expect(e + 0).to eq(e) }
|
19
|
-
it{ expect(e - 0).to eq(e) }
|
20
|
-
it{ expect((e * 0).to_s).to eq('0') }
|
21
|
-
it{ expect(e * 1).to eq(e) }
|
22
|
-
it{ expect{(e / 0).to_s}.to raise_error(ZeroDivisionError) }
|
23
|
-
it{ expect(e / 1).to eq(e) }
|
24
|
-
it{ expect((e ^ 0).to_s).to eq('1') }
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Fixnum do
|
4
|
-
describe '#to_s' do
|
5
|
-
it{ expect(1.to_s).to eq('1') }
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '#differentiate' do
|
9
|
-
it{ expect(3.d(:x).to_s).to eq('0') }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'Calculate' do
|
13
|
-
context 'With Formula' do
|
14
|
-
let(:formula) { (:x + :y) }
|
15
|
-
it{ expect((0 + formula).to_s).to eq(formula.to_s) }
|
16
|
-
it{ expect((0 - formula).to_s).to eq('( - ( x + y ) )') }
|
17
|
-
it{ expect((0 * formula).to_s).to eq('0') }
|
18
|
-
it{ expect((1 * formula).to_s).to eq(formula.to_s) }
|
19
|
-
it{ expect((0 / formula).to_s).to eq('0') }
|
20
|
-
it{ expect((1 / formula).to_s).to eq('( 1 / ( x + y ) )') }
|
21
|
-
it{ expect((0 ^ formula).to_s).to eq('0') }
|
22
|
-
it{ expect((1 ^ formula).to_s).to eq('1') }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'With Symbol' do
|
26
|
-
it{ expect(0 + :x).to eq(:x) }
|
27
|
-
it{ expect((0 - :x).to_s).to eq('( - x )') }
|
28
|
-
it{ expect((0 * :x).to_s).to eq('0') }
|
29
|
-
it{ expect(1 * :x).to eq(:x) }
|
30
|
-
it{ expect((0 / :x).to_s).to eq('0') }
|
31
|
-
it{ expect((1 / :x).to_s).to eq('( 1 / x )') }
|
32
|
-
it{ expect((0 ^ :x).to_s).to eq('0') }
|
33
|
-
it{ expect((1 ^ :x).to_s).to eq('1') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'With Fixnum' do
|
37
|
-
it{ expect(0 + 3).to eq(3) }
|
38
|
-
it{ expect(3 + 0).to eq(3) }
|
39
|
-
it{ expect(2 + 3).to eq(5) }
|
40
|
-
|
41
|
-
it{ expect(0 - 3).to eq(-3) }
|
42
|
-
it{ expect(3 - 0).to eq(3) }
|
43
|
-
it{ expect(2 - 3).to eq(-1) }
|
44
|
-
|
45
|
-
it{ expect(0 * 3).to eq(0) }
|
46
|
-
it{ expect(3 * 0).to eq(0) }
|
47
|
-
it{ expect(1 * 3).to eq(3) }
|
48
|
-
it{ expect(3 * 1).to eq(3) }
|
49
|
-
it{ expect(3 * 2).to eq(6) }
|
50
|
-
|
51
|
-
it{ expect((0 / 3).to_s).to eq('0') }
|
52
|
-
it{ expect{(3 / 0).to_s}.to raise_error(ZeroDivisionError) }
|
53
|
-
it{ expect((3 / 1).to_s).to eq('3') }
|
54
|
-
# TODO:
|
55
|
-
it{ expect((2 / 3).to_s).to eq('0') }
|
56
|
-
|
57
|
-
|
58
|
-
it{ expect((0 ^ 3).to_s).to eq('0') }
|
59
|
-
it{ expect((3 ^ 0).to_s).to eq('1') }
|
60
|
-
it{ expect((1 ^ 3).to_s).to eq('1') }
|
61
|
-
it{ expect((3 ^ 1).to_s).to eq('3') }
|
62
|
-
it{ expect((3 ^ 2).to_s).to eq('9') }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,65 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Float do
|
4
|
-
describe '#to_s' do
|
5
|
-
it{ expect(1.0.to_s).to eq('1.0') }
|
6
|
-
end
|
7
|
-
|
8
|
-
describe '#differentiate' do
|
9
|
-
it{ expect(3.0.d(:x).to_s).to eq('0') }
|
10
|
-
end
|
11
|
-
|
12
|
-
describe 'Calculate' do
|
13
|
-
context 'With Formula' do
|
14
|
-
let(:formula) { (:x + :y) }
|
15
|
-
it{ expect((0.0 + formula).to_s).to eq(formula.to_s) }
|
16
|
-
it{ expect((0.0 - formula).to_s).to eq('( - ( x + y ) )') }
|
17
|
-
it{ expect((0.0 * formula).to_s).to eq('0') }
|
18
|
-
it{ expect((1.0 * formula).to_s).to eq(formula.to_s) }
|
19
|
-
it{ expect((0.0 / formula).to_s).to eq('0') }
|
20
|
-
it{ expect((1.0 / formula).to_s).to eq('( 1 / ( x + y ) )') }
|
21
|
-
it{ expect((0.0 ^ formula).to_s).to eq('0') }
|
22
|
-
it{ expect((1.0 ^ formula).to_s).to eq('1') }
|
23
|
-
end
|
24
|
-
|
25
|
-
context 'With Symbol' do
|
26
|
-
it{ expect(0.0 + :x).to eq(:x) }
|
27
|
-
it{ expect((0.0 - :x).to_s).to eq('( - x )') }
|
28
|
-
it{ expect((0.0 * :x).to_s).to eq('0') }
|
29
|
-
it{ expect(1.0 * :x).to eq(:x) }
|
30
|
-
it{ expect((0.0 / :x).to_s).to eq('0') }
|
31
|
-
it{ expect((1.0 / :x).to_s).to eq('( 1 / x )') }
|
32
|
-
it{ expect((0.0 ^ :x).to_s).to eq('0') }
|
33
|
-
it{ expect((1.0 ^ :x).to_s).to eq('1') }
|
34
|
-
end
|
35
|
-
|
36
|
-
context 'With Float' do
|
37
|
-
it{ expect(0.0 + 3.0).to eq(3.0) }
|
38
|
-
it{ expect(3.0 + 0.0).to eq(3.0) }
|
39
|
-
it{ expect(2.0 + 3.0).to eq(5.0) }
|
40
|
-
|
41
|
-
it{ expect(0.0 - 3.0).to eq(-3.0) }
|
42
|
-
it{ expect(3.0 - 0.0).to eq(3.0) }
|
43
|
-
it{ expect(2.0 - 3.0).to eq(-1.0) }
|
44
|
-
|
45
|
-
it{ expect(0.0 * 3.0).to eq(0.0) }
|
46
|
-
it{ expect(3.0 * 0.0).to eq(0.0) }
|
47
|
-
it{ expect(1.0 * 3.0).to eq(3.0) }
|
48
|
-
it{ expect(3.0 * 1.0).to eq(3.0) }
|
49
|
-
it{ expect(3.0 * 2.0).to eq(6.0) }
|
50
|
-
|
51
|
-
it{ expect(0.0 / 3.0).to eq(0.0) }
|
52
|
-
it{ expect(3.0 / 0.0).to eq(oo) }
|
53
|
-
it{ expect(3.0 / 1.0).to eq(3.0) }
|
54
|
-
# TODO:
|
55
|
-
it{ expect(2.0 / 3.0).to eq(0.6666666666666666) }
|
56
|
-
|
57
|
-
|
58
|
-
it{ expect(0.0 ^ 3.0).to eq(0.0) }
|
59
|
-
it{ expect(3.0 ^ 0.0).to eq(1.0) }
|
60
|
-
it{ expect(1.0 ^ 3.0).to eq(1.0) }
|
61
|
-
it{ expect(3.0 ^ 1.0).to eq(3.0) }
|
62
|
-
it{ expect(3.0 ^ 2.0).to eq(9.0) }
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::Log do
|
4
|
-
it{ expect(log(1)).to eq(_(0)) }
|
5
|
-
it{ expect(log(e)).to eq(_(1)) }
|
6
|
-
it{ expect(log(e ^ :n)).to eq(:n) }
|
7
|
-
|
8
|
-
describe '#to_s' do
|
9
|
-
end
|
10
|
-
describe '#differentiate' do
|
11
|
-
it{ expect(log(:x).d(:x).to_s).to eq('( 1 / x )') }
|
12
|
-
end
|
13
|
-
describe 'Calculate' do
|
14
|
-
end
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::Num 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
|
-
describe '#to_s' do
|
10
|
-
it{ expect(_(1).to_s).to eq('1') }
|
11
|
-
end
|
12
|
-
|
13
|
-
describe '#differentiate' do
|
14
|
-
it{ expect(_(1).d(:x).to_s).to eq(_(0).to_s) }
|
15
|
-
end
|
16
|
-
|
17
|
-
describe '#==' do
|
18
|
-
it{ expect(_(1) == _(1)).to be_true }
|
19
|
-
end
|
20
|
-
|
21
|
-
describe 'Calculate' do
|
22
|
-
end
|
23
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::Pi do
|
4
|
-
it{ expect(pi).to eq(pi) }
|
5
|
-
|
6
|
-
describe '#to_s' do
|
7
|
-
it{ expect(pi.to_s).to eq('pi') }
|
8
|
-
end
|
9
|
-
|
10
|
-
describe '#differentiate' do
|
11
|
-
it{ expect(pi.d(:x).to_s).to eq(_(0).to_s) }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'Calculate' do
|
15
|
-
context 'With Fixnum' do
|
16
|
-
it{ expect(pi + 0).to eq(pi) }
|
17
|
-
it{ expect(pi - 0).to eq(pi) }
|
18
|
-
it{ expect((pi * 0).to_s).to eq('0') }
|
19
|
-
it{ expect(pi * 1).to eq(pi) }
|
20
|
-
it{ expect{(pi / 0).to_s}.to raise_error(ZeroDivisionError) }
|
21
|
-
it{ expect(pi / 1).to eq(pi) }
|
22
|
-
it{ expect((pi ^ 0).to_s).to eq('1') }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Dydx::Algebra::Set::Sin do
|
4
|
-
it{ expect(sin(pi)).to eq(_(0)) }
|
5
|
-
|
6
|
-
describe '#to_s' do
|
7
|
-
it{ expect(sin(:x).to_s).to eq('sin( x )') }
|
8
|
-
end
|
9
|
-
describe '#differentiate' do
|
10
|
-
it{ expect(sin(:x).d.to_s).to eq('cos( x )') }
|
11
|
-
end
|
12
|
-
describe 'Calculate' do
|
13
|
-
end
|
14
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Symbol do
|
4
|
-
describe '#to_s' do
|
5
|
-
it{ expect(:x.to_s).to eq('x') }
|
6
|
-
end
|
7
|
-
describe '#differentiate' do
|
8
|
-
it{ expect(:x.d(:x).to_s).to eq('1') }
|
9
|
-
end
|
10
|
-
describe 'Calculate' do
|
11
|
-
context 'With Fixnum' do
|
12
|
-
it{ expect(:x + 0).to eq(:x) }
|
13
|
-
it{ expect(:x - 0).to eq(:x) }
|
14
|
-
it{ expect((:x * 0).to_s).to eq('0') }
|
15
|
-
it{ expect(:x * 1).to eq(:x) }
|
16
|
-
it{ expect{(:x / 0).to_s}.to raise_error(ZeroDivisionError) }
|
17
|
-
it{ expect(:x / 1).to eq(:x) }
|
18
|
-
it{ expect((:x ^ 0).to_s).to eq('1') }
|
19
|
-
it{ expect(:x ^ 1).to eq(:x) }
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|