dydx 0.1.314 → 0.1.412
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +25 -0
- data/.travis.yml +3 -1
- data/Gemfile +1 -0
- data/README.md +4 -2
- data/Rakefile +5 -8
- data/dydx.gemspec +13 -13
- data/lib/dydx.rb +20 -27
- data/lib/dydx/algebra.rb +8 -6
- data/lib/dydx/algebra/formula.rb +53 -28
- data/lib/dydx/algebra/inverse.rb +2 -2
- data/lib/dydx/algebra/operator/formula.rb +0 -1
- data/lib/dydx/algebra/operator/general.rb +0 -1
- data/lib/dydx/algebra/operator/inverse.rb +0 -1
- data/lib/dydx/algebra/operator/num.rb +0 -1
- 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 -32
- 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 +82 -122
- data/lib/dydx/delta.rb +1 -1
- data/lib/dydx/function.rb +1 -1
- data/lib/dydx/helper.rb +43 -66
- data/lib/dydx/integrand.rb +7 -6
- data/lib/dydx/version.rb +1 -1
- data/spec/dydx_spec.rb +3 -3
- data/spec/lib/algebra/formula_spec.rb +41 -41
- 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 +193 -150
- data/spec/lib/delta_spec.rb +23 -25
- data/spec/lib/function_spec.rb +4 -6
- data/spec/lib/helper_spec.rb +44 -51
- data/spec/lib/integrand_spec.rb +12 -10
- data/spec/spec_helper.rb +2 -1
- metadata +6 -7
- data/lib/dydx/algebra/operator/parts.rb +0 -6
- data/lib/dydx/algebra/operator/parts/interface.rb +0 -22
data/spec/lib/function_spec.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Dydx
|
4
|
-
before
|
5
|
-
reset
|
6
|
-
end
|
3
|
+
describe Dydx::Function do
|
4
|
+
before { reset }
|
7
5
|
|
8
6
|
it 'ex1' do
|
9
7
|
expect(f(x, y)).to eq(f(x, y))
|
10
8
|
expect(f(x, y)).to eq($f)
|
11
9
|
expect(f(x, y).algebra).to be_nil
|
12
10
|
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)
|
11
|
+
expect { f(x, y, z) }.to raise_error(ArgumentError)
|
12
|
+
expect { f(x) }.to raise_error(ArgumentError)
|
15
13
|
end
|
16
14
|
|
17
15
|
it 'ex2' do
|
data/spec/lib/helper_spec.rb
CHANGED
@@ -3,70 +3,63 @@ require 'spec_helper'
|
|
3
3
|
describe Helper do
|
4
4
|
include Helper
|
5
5
|
context '#is_n?' do
|
6
|
-
it{ expect(0.
|
7
|
-
it{ expect(_(0).
|
8
|
-
it{ expect(inverse(0, :+).
|
9
|
-
it{ expect(1.
|
10
|
-
it{ expect(_(1).
|
11
|
-
it{ expect(inverse(1, :*).
|
12
|
-
it{ expect(-1.
|
13
|
-
it{ expect(_(-1).
|
6
|
+
it { expect(0.zero?).to be true }
|
7
|
+
it { expect(_(0).zero?).to be true }
|
8
|
+
it { expect(inverse(0, :+).zero?).to be true }
|
9
|
+
it { expect(1.one?).to be true }
|
10
|
+
it { expect(_(1).one?).to be true }
|
11
|
+
it { expect(inverse(1, :*).one?).to be true }
|
12
|
+
it { expect(-1.minus1?).to be true }
|
13
|
+
it { expect(_(-1).minus1?).to be true }
|
14
14
|
end
|
15
15
|
|
16
|
-
context '#
|
17
|
-
it{ expect(0.
|
18
|
-
it{ expect(_(0).is_multiple_of(:y).to_s).to eq('0')}
|
16
|
+
context '#multiple_of?' do
|
17
|
+
it { expect(0.multiple_of?(x)).to be(true) }
|
19
18
|
|
20
|
-
it{ expect(
|
21
|
-
it{ expect(
|
19
|
+
it { expect(4.multiple_of?(_(2))).to be(true) }
|
20
|
+
it { expect(_(4).multiple_of?(2)).to be(true) }
|
21
|
+
it { expect(_(4).multiple_of?(_(2))).to be(true) }
|
22
22
|
|
23
|
-
it{ expect(
|
24
|
-
it{ expect(
|
25
|
-
|
23
|
+
it { expect(x.multiple_of?(x)).to be(true) }
|
24
|
+
it { expect(x.multiple_of?(y)).to be(false) }
|
25
|
+
|
26
|
+
it { expect((x * y).multiple_of?(x)).to be(true) }
|
27
|
+
it { expect((x * y).multiple_of?(x)).to be(true) }
|
28
|
+
it { expect((x * y).multiple_of?(z)).to be(false) }
|
26
29
|
end
|
27
30
|
|
28
31
|
context '#like_term?' do
|
29
|
-
it{ expect(x.like_term?(x)).to
|
30
|
-
it{ expect((2 * x).like_term?((3 * x))).to
|
32
|
+
it { expect(x.like_term?(x)).to be true }
|
33
|
+
it { expect((2 * x).like_term?((3 * x))).to be true }
|
31
34
|
end
|
32
35
|
|
33
36
|
context '#combinable?' do
|
34
|
-
it{ expect(:x.combinable?(:x, :+)).to
|
35
|
-
it{ expect(:x.combinable?(2 * :x, :+)).to
|
36
|
-
it{ expect((2 * :x).combinable?(:x, :+)).to
|
37
|
-
it{ expect((2 * :x).combinable?(2 * :x, :+)).to
|
38
|
-
it{ expect(:x.combinable?(:y, :+)).to
|
39
|
-
it{ expect(1.combinable?(2, :+)).to
|
40
|
-
it{ expect(:x.combinable?(:x, :*)).to
|
41
|
-
it{ expect(:x.combinable?(:y, :*)).to
|
42
|
-
it{ expect(1.combinable?(2, :*)).to
|
43
|
-
it{ expect(0.combinable?(:x,
|
44
|
-
it{ expect(1.combinable?(:y,
|
37
|
+
it { expect(:x.combinable?(:x, :+)).to be true }
|
38
|
+
it { expect(:x.combinable?(2 * :x, :+)).to be true }
|
39
|
+
it { expect((2 * :x).combinable?(:x, :+)).to be true }
|
40
|
+
it { expect((2 * :x).combinable?(2 * :x, :+)).to be true }
|
41
|
+
it { expect(:x.combinable?(:y, :+)).to be false }
|
42
|
+
it { expect(1.combinable?(2, :+)).to be true }
|
43
|
+
it { expect(:x.combinable?(:x, :*)).to be true }
|
44
|
+
it { expect(:x.combinable?(:y, :*)).to be false }
|
45
|
+
it { expect(1.combinable?(2, :*)).to be true }
|
46
|
+
it { expect(0.combinable?(:x, :**)).to be true }
|
47
|
+
it { expect(1.combinable?(:y, :**)).to be true }
|
45
48
|
end
|
46
49
|
|
47
50
|
context '#distributive?' do
|
48
|
-
it{ expect(distributive?(:+, :*)).to
|
49
|
-
it{ expect(distributive?(:+, :/)).to
|
50
|
-
it{ expect(distributive?(:-, :*)).to
|
51
|
-
it{ expect(distributive?(:-, :/)).to
|
52
|
-
it{ expect(distributive?(:*,
|
53
|
-
it{ expect(distributive?(:/,
|
54
|
-
it{ expect(distributive?(:*, :+)).to
|
55
|
-
it{ expect(distributive?(
|
51
|
+
it { expect(distributive?(:+, :*)).to be true }
|
52
|
+
it { expect(distributive?(:+, :/)).to be true }
|
53
|
+
it { expect(distributive?(:-, :*)).to be true }
|
54
|
+
it { expect(distributive?(:-, :/)).to be true }
|
55
|
+
it { expect(distributive?(:*, :**)).to be true }
|
56
|
+
it { expect(distributive?(:/, :**)).to be true }
|
57
|
+
it { expect(distributive?(:*, :+)).to be false }
|
58
|
+
it { expect(distributive?(:**, :*)).to be false }
|
56
59
|
end
|
57
60
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
let(:exponentiation){ (:x ^ :y) }
|
63
|
-
|
64
|
-
it{ expect(addition.addition?).to be_true }
|
65
|
-
it{ expect(multiplication.multiplication?).to be_true }
|
66
|
-
it{ expect(exponentiation.exponentiation?).to be_true }
|
67
|
-
|
68
|
-
it{ expect(inverse(:x, :+).inverse?(:+, :x)).to be_true }
|
69
|
-
it{ expect(:x.inverse?(:+, inverse(:x, :+))).to be_true }
|
70
|
-
it{ expect(inverse(:x, :*).inverse?(:*, :x)).to be_true }
|
71
|
-
it{ expect(:x.inverse?(:*, inverse(:x, :*))).to be_true }
|
61
|
+
it { expect(inverse(x, :+).inverse?(:+, x)).to be true }
|
62
|
+
it { expect(x.inverse?(:+, inverse(x, :+))).to be true }
|
63
|
+
it { expect(inverse(x, :*).inverse?(:*, x)).to be true }
|
64
|
+
it { expect(x.inverse?(:*, inverse(x, :*))).to be true }
|
72
65
|
end
|
data/spec/lib/integrand_spec.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Dydx
|
4
|
-
before
|
5
|
-
reset
|
6
|
-
end
|
3
|
+
describe Dydx::Integrand do
|
4
|
+
before { reset }
|
7
5
|
|
8
6
|
it 'ex1' do
|
9
7
|
f(x, y) <= x * y
|
10
8
|
integrand = S(f(x, y), dx)
|
11
9
|
expect(integrand.function).to eq(f(x, y))
|
12
|
-
expect(integrand.var).to eq(
|
13
|
-
expect{integrand[4, 3]}.to raise_error(ArgumentError)
|
10
|
+
expect(integrand.var).to eq(x)
|
11
|
+
expect { integrand[4, 3] }.to raise_error(ArgumentError)
|
14
12
|
end
|
15
13
|
|
16
14
|
it 'ex2' do
|
@@ -34,20 +32,24 @@ describe Dydx:Integrand do
|
|
34
32
|
end
|
35
33
|
|
36
34
|
it 'ex6' do
|
37
|
-
f(x) <= e
|
35
|
+
f(x) <= e ** -x ** 2
|
38
36
|
expect(f(0)).to eq(1)
|
39
|
-
expect(f(1)).to eq(1.0/Math::E)
|
37
|
+
expect(f(1)).to eq(1.0 / Math::E)
|
40
38
|
expect(f(1000)).to eq(0)
|
41
39
|
expect(S(f(x), dx)[-1000, 1000, 3000]).to eq(1.77239273)
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'ex7' do
|
45
|
-
f(x) <= (1.0 / (
|
43
|
+
f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
|
46
44
|
expect(S(f(x), dx)[-1000, 1000]).to eq(1.0)
|
47
45
|
end
|
48
46
|
|
49
47
|
it 'ex8' do
|
50
|
-
f(x) <= (1.0 / (
|
48
|
+
f(x) <= (1.0 / ( 2.0 * Math::PI ) ** 0.5) * e ** (- x ** 2 / 2)
|
51
49
|
expect(S(f(x), dx)[-oo, oo]).to eq(1.0)
|
52
50
|
end
|
51
|
+
|
52
|
+
it 'ex9' do
|
53
|
+
expect(S(log(x), dx)[0, 1]).to eq(-oo)
|
54
|
+
end
|
53
55
|
end
|
data/spec/spec_helper.rb
CHANGED
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.
|
4
|
+
version: 0.1.412
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gogotanaka
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
description: Dydx is new math DSL in Ruby. The most important thing in this DSL is
|
56
56
|
we can handle math in the same sense sense of the math on paper.
|
57
57
|
email:
|
58
|
-
-
|
58
|
+
- mail@tanakakazuki.com
|
59
59
|
executables: []
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- ".gitignore"
|
64
64
|
- ".pryrc"
|
65
65
|
- ".rspec"
|
66
|
+
- ".rubocop.yml"
|
66
67
|
- ".travis.yml"
|
67
68
|
- Gemfile
|
68
69
|
- LICENSE.txt
|
@@ -77,11 +78,9 @@ files:
|
|
77
78
|
- lib/dydx/algebra/operator/general.rb
|
78
79
|
- lib/dydx/algebra/operator/inverse.rb
|
79
80
|
- lib/dydx/algebra/operator/num.rb
|
80
|
-
- lib/dydx/algebra/operator/parts.rb
|
81
81
|
- lib/dydx/algebra/operator/parts/base.rb
|
82
82
|
- lib/dydx/algebra/operator/parts/formula.rb
|
83
83
|
- lib/dydx/algebra/operator/parts/general.rb
|
84
|
-
- lib/dydx/algebra/operator/parts/interface.rb
|
85
84
|
- lib/dydx/algebra/operator/parts/inverse.rb
|
86
85
|
- lib/dydx/algebra/operator/parts/num.rb
|
87
86
|
- lib/dydx/algebra/operator/parts/symbol.rb
|
@@ -102,7 +101,7 @@ files:
|
|
102
101
|
- spec/lib/helper_spec.rb
|
103
102
|
- spec/lib/integrand_spec.rb
|
104
103
|
- spec/spec_helper.rb
|
105
|
-
homepage:
|
104
|
+
homepage: http://gogotanaka.me/
|
106
105
|
licenses:
|
107
106
|
- MIT
|
108
107
|
metadata: {}
|
@@ -122,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
121
|
version: '0'
|
123
122
|
requirements: []
|
124
123
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
124
|
+
rubygems_version: 2.4.1
|
126
125
|
signing_key:
|
127
126
|
specification_version: 4
|
128
127
|
summary: We can enjoy the math.
|
@@ -1,6 +0,0 @@
|
|
1
|
-
require 'dydx/algebra/operator/parts/base'
|
2
|
-
require 'dydx/algebra/operator/parts/general'
|
3
|
-
require 'dydx/algebra/operator/parts/interface'
|
4
|
-
require 'dydx/algebra/operator/parts/formula'
|
5
|
-
require 'dydx/algebra/operator/parts/inverse'
|
6
|
-
require 'dydx/algebra/operator/parts/num'
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Dydx
|
2
|
-
module Algebra
|
3
|
-
module Operator
|
4
|
-
module Parts
|
5
|
-
module Interface
|
6
|
-
%w(+ - * / ^).map(&:to_sym).each do |operator|
|
7
|
-
define_method(operator) do |x|
|
8
|
-
x = ::Set::Num.new(x) if x.is_a?(Fixnum)
|
9
|
-
if operator == :/ && x.is_0?
|
10
|
-
raise ZeroDivisionError
|
11
|
-
elsif [:-, :/].include?(operator)
|
12
|
-
send(inverse_ope(operator), inverse(x, inverse_ope(operator)))
|
13
|
-
else
|
14
|
-
super(x)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|