congruence_solver 0.3.0 → 0.3.1
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 +4 -4
- data/.gitignore +2 -2
- data/.gitmodules +3 -2
- data/Gemfile +4 -0
- data/README.md +17 -10
- data/Rakefile +59 -25
- data/bench/bench_tools.rb +26 -26
- data/bench/solve_congruence_bm.rb +35 -35
- data/bin/csolve.rb +21 -21
- data/congruence_solver.gemspec +6 -6
- data/ext/congruence_solver/arith_utils.c +72 -75
- data/ext/congruence_solver/congruence_solver.c +43 -43
- data/ext/congruence_solver/congruences.c +175 -147
- data/ext/congruence_solver/extconf.rb +0 -13
- data/ext/congruence_solver/prime_gen.c +83 -83
- data/ext/congruence_solver/test/arith_utils_test.h +7 -7
- data/ext/congruence_solver/test/congruences_test.c +2 -2
- data/ext/congruence_solver/test/congruences_test.h +36 -1
- data/lib/congruence_solver/version.rb +1 -1
- data/lib/polynomial_interpreter.rb +114 -114
- data/spec/congruence_solver_spec.rb +34 -34
- data/spec/csolve_spec.rb +74 -74
- metadata +18 -3
data/spec/csolve_spec.rb
CHANGED
@@ -1,89 +1,89 @@
|
|
1
1
|
require "polynomial_interpreter"
|
2
2
|
|
3
3
|
RSpec.describe PolynomialInterpreter do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
describe "::read_congruence" do
|
5
|
+
context "when input contains no '\='" do
|
6
|
+
it "raises an ArgumentError" do
|
7
|
+
not_congruence = "x^2 (mod 5)"
|
8
|
+
expect {PolynomialInterpreter.read_congruence not_congruence}.to raise_error ArgumentError, "congruence invalid"
|
9
|
+
end
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
context "when input contains no mod" do
|
13
|
+
it "raises an ArgumentError" do
|
14
|
+
not_congruence = "x^2 = 3"
|
15
|
+
expect {PolynomialInterpreter.read_congruence not_congruence}.to raise_error ArgumentError, "congruence invalid"
|
16
|
+
end
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
context "when input contains an invalid mod" do
|
20
|
+
it "raises an ArgumentError" do
|
21
|
+
not_congruence = "x = 5 (mod)"
|
22
|
+
expect {PolynomialInterpreter.read_congruence not_congruence}.to raise_error ArgumentError, "congruence invalid"
|
23
|
+
end
|
24
|
+
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
context "when lhs is empty" do
|
27
|
+
it "raises an ArgumentError" do
|
28
|
+
congruence = "= 3 (mod 4)"
|
29
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "lhs polynomial invalid"
|
30
|
+
end
|
31
|
+
end
|
32
32
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
33
|
+
context "when lhs contains invalid characters" do
|
34
|
+
it "raises an ArgumentError" do
|
35
|
+
congruence = "x! = 3 (mod 5)"
|
36
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "lhs polynomial invalid"
|
37
|
+
end
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
context "when lhs contains more than one distinct variables" do
|
41
|
+
it "raises an ArgumentError" do
|
42
|
+
congruence = "x^2 + y = 0 (mod 6)"
|
43
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "lhs polynomial invalid"
|
44
|
+
end
|
45
|
+
end
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
47
|
+
context "when lhs contains negative power" do
|
48
|
+
it "raises an ArgumentError" do
|
49
|
+
congruence = "x^-1 = 2 (mod 35)"
|
50
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "lhs polynomial invalid"
|
51
|
+
end
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
54
|
+
context "when rhs is empty" do
|
55
|
+
it "raises an ArgumentError" do
|
56
|
+
congruence = "x^3 = (mod 4)"
|
57
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "rhs polynomial invalid"
|
58
|
+
end
|
59
|
+
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
context "when rhs contains invalid characters" do
|
62
|
+
it "raises an ArgumentError" do
|
63
|
+
congruence = "3 = x! (mod 5)"
|
64
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "rhs polynomial invalid"
|
65
|
+
end
|
66
|
+
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
68
|
+
context "when rhs contains more than one distinct variables" do
|
69
|
+
it "raises an ArgumentError" do
|
70
|
+
congruence = "0 = x^2 + y (mod 6)"
|
71
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "rhs polynomial invalid"
|
72
|
+
end
|
73
|
+
end
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
75
|
+
context "when rhs contains negative power" do
|
76
|
+
it "raises an ArgumentError" do
|
77
|
+
congruence = "2 = x^-1 (mod 35)"
|
78
|
+
expect {PolynomialInterpreter.read_congruence congruence}.to raise_error ArgumentError, "rhs polynomial invalid"
|
79
|
+
end
|
80
|
+
end
|
81
81
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
context "when input is a valid polynomial congruence" do
|
83
|
+
it "formats congruence as a single polynomial congruent to 0" do
|
84
|
+
congruence = "45x^5 + 5 + 3x ^6 + 5x^2 + x + 3x^5=x^9 + 9 x (mod 16)"
|
85
|
+
expect( PolynomialInterpreter.read_congruence(congruence)).to eq [[-1, 0, 0, 3, 48, 0, 0, 5, -8, 5].reverse, 16]
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
89
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: congruence_solver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lane
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: os
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.9'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.9'
|
69
83
|
description: "Provides a class (CongruenceSolver) for finding the modular zeros of
|
70
84
|
a \n polynomial (given the coefficients and modulus) and
|
71
85
|
a binary (csolve) to \n to solve your congruences at the
|
@@ -83,6 +97,7 @@ files:
|
|
83
97
|
- ".gitmodules"
|
84
98
|
- ".rspec"
|
85
99
|
- ".travis.yml"
|
100
|
+
- Gemfile
|
86
101
|
- README.md
|
87
102
|
- Rakefile
|
88
103
|
- bench/bench_tools.rb
|
@@ -131,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
146
|
version: '0'
|
132
147
|
requirements: []
|
133
148
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
149
|
+
rubygems_version: 2.6.7
|
135
150
|
signing_key:
|
136
151
|
specification_version: 4
|
137
152
|
summary: A gem for solving polynomial congruences.
|