Skip to content

Commit

Permalink
Merge pull request #99 from sumiya11/fix-in-linalg
Browse files Browse the repository at this point in the history
(probably) improve modular arithmetic
  • Loading branch information
sumiya11 authored Dec 17, 2023
2 parents f2f8b58 + de1856b commit 148b12f
Show file tree
Hide file tree
Showing 133 changed files with 4,736 additions and 8,040 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.5.1"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Atomix = "a9b6321e-bd34-4604-b9c9-b65b8de01458"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
ExprTools = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
1 change: 1 addition & 0 deletions benchmark/CI-scripts/run-on-nightly/run_benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Pkg
Pkg.status()
Pkg.develop(path=(@__DIR__) * "/../../../")

include("../run_benchmarks.jl")
Expand Down
5 changes: 3 additions & 2 deletions benchmark/CI-scripts/run-on-stable/run_benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Pkg
Pkg.add("Groebner")
Pkg.update("Groebner")
Pkg.status()
Pkg.add(url="https://github.com/sumiya11/Groebner.jl")
# Pkg.update("Groebner")

include("../run_benchmarks.jl")

Expand Down
38 changes: 35 additions & 3 deletions benchmark/CI-scripts/run_benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,37 @@ push!(
suite,
(
problem_name="groebner, AA, GF(2^31-1), katsura 10",
result=compute_gb(Groebner.katsuran(10, ordering=:degrevlex, ground=GF(2^31 - 1)))
result=compute_gb(
Groebner.katsuran(10, ordering=:degrevlex, ground=GF(2^31 - 1)),
5
)
)
)
push!(
suite,
(
problem_name="groebner, AA, GF(2^27+29), katsura 10",
result=compute_gb(
Groebner.katsuran(10, ordering=:degrevlex, ground=GF(2^27 + 29)),
5
)
)
)
push!(
suite,
(
problem_name="groebner, AA, GF(2^27+29), cyclic 8",
result=compute_gb(
Groebner.cyclicn(8, ordering=:degrevlex, ground=GF(2^27 + 29)),
5
)
)
)
push!(
suite,
(
problem_name="groebner, AA, GF(2^31-1), cyclic 8",
result=compute_gb(Groebner.cyclicn(8, ordering=:degrevlex, ground=GF(2^31 - 1)))
result=compute_gb(Groebner.cyclicn(8, ordering=:degrevlex, ground=GF(2^31 - 1)), 5)
)
)
push!(
Expand Down Expand Up @@ -109,6 +132,15 @@ push!(
)
)
)
push!(
suite,
(
problem_name="groebner_apply!, AA, GF(2^27+29), katsura 10",
result=learn_and_apply(
Groebner.katsuran(10, ordering=:degrevlex, ground=GF(2^27 + 29))
)
)
)
push!(
suite,
(
Expand Down Expand Up @@ -158,7 +190,7 @@ push!(

function multimodular_gb_problem(nbits; np=AbstractAlgebra)
R, (x1, x2, x3, x4) =
PolynomialRing(np.QQ, ["x1", "x2", "x3", "x4"], ordering=:degrevlex)
polynomial_ring(np.QQ, ["x1", "x2", "x3", "x4"], ordering=:degrevlex)
nbits_per_prime = 31
nprimes = max(div(nbits, nbits_per_prime), 1)
N = prod(map(BigInt, Primes.nextprimes(2^31 - 100, nprimes)))
Expand Down
2 changes: 2 additions & 0 deletions benchmark/CI-scripts/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
using Test
using TestSetExtensions
using InteractiveUtils
using Base.Threads

const MAX_ACCEPTABLE_RELATIVE_DEVIATION = 0.1
const IGNORE_SMALL_ABSOLUTE_DEVIATION = 1e-3

@info "Start benchmarking.."
@info "Using $(nthreads()) threads in Groebner.jl"

# Run benchmarks on the latest stable version of Groebner.jl
dir_stable = (@__DIR__) * "/run-on-stable"
Expand Down
2 changes: 1 addition & 1 deletion benchmark/benchmark_systems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function benchmark_set_2()
end

function dummy_system(ground_field)
ring, (x, y) = AbstractAlgebra.PolynomialRing(ground_field, ["x", "y"])
ring, (x, y) = AbstractAlgebra.polynomial_ring(ground_field, ["x", "y"])
("dummy", [x^2 + y^2 - 1, x + y])
end

Expand Down
2 changes: 1 addition & 1 deletion benchmark/generate/basis_certificate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function extract_ring(line1, line2)
char = parse(BigInt, strip(line2))
@assert char < typemax(UInt)
base_field = iszero(char) ? Nemo.QQ : Nemo.GF(UInt(char))
ring_nemo, vars_nemo = Nemo.PolynomialRing(base_field, vars_str, ordering=:degrevlex)
ring_nemo, vars_nemo = Nemo.polynomial_ring(base_field, vars_str, ordering=:degrevlex)
base_field, ring_nemo, vars_nemo
end

Expand Down
2 changes: 1 addition & 1 deletion benchmark/generate/benchmark_generators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function generate_benchmark_source_for_groebner(
"GF($(characteristic(field)))"
end
vars_repr_quoted = map(s -> "$s", map(string, gens(ring)))
ring_repr = """ring, ($vars_repr) = PolynomialRing(
ring_repr = """ring, ($vars_repr) = polynomial_ring(
$field_repr,
$vars_repr_quoted,
ordering=:degrevlex
Expand Down
2 changes: 1 addition & 1 deletion benchmark/generate/benchmark_systems/MQ/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function read_MQ_GF(filename)
ne = parse(Int, line3[(findfirst(':', line3) + 1):end])

R, xs =
AbstractAlgebra.PolynomialRing(AbstractAlgebra.GF(ch), nv, ordering=:degrevlex)
AbstractAlgebra.polynomial_ring(AbstractAlgebra.GF(ch), nv, ordering=:degrevlex)
@info "Created ring" R xs

labels = sort!(union([x * y for x in xs for y in xs], xs, [R(1)]), rev=true)
Expand Down
2 changes: 1 addition & 1 deletion benchmark/generate/benchmark_systems/biomodels/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function read_BIOMDs(nspecies)
symvs = map(x -> Symbol(x), vs)
expvs = Meta.parse(join(symvs, ","))
R, xs = eval(
:((R, $expvs) = AbstractAlgebra.PolynomialRing(AbstractAlgebra.QQ, $symvs))
:((R, $expvs) = AbstractAlgebra.polynomial_ring(AbstractAlgebra.QQ, $symvs))
)

for p in params
Expand Down
10 changes: 5 additions & 5 deletions benchmark/generate/benchmark_systems/for_gleb/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function read_SEAIJRC()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
for (i, s) in enumerate(rrr)
Expand All @@ -33,7 +33,7 @@ function read_SIWR()
body = readline(f)
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
for (i, s) in enumerate(rrr)
Expand All @@ -57,7 +57,7 @@ function read_MAPK()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
l = length(rrr)
Expand Down Expand Up @@ -100,7 +100,7 @@ function read_MAPK_include()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))

collect(include(apath))
end
Expand All @@ -109,7 +109,7 @@ function parse_include(filename)
head = "x, y, z"
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse("x, y, z")
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))

include(abspath("benchmark\\data\\$filename"))
end
10 changes: 5 additions & 5 deletions benchmark/generate/benchmark_systems/standard/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function read_SEAIJRC()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
for (i, s) in enumerate(rrr)
Expand All @@ -33,7 +33,7 @@ function read_SIWR()
body = readline(f)
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
for (i, s) in enumerate(rrr)
Expand All @@ -57,7 +57,7 @@ function read_MAPK()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))
@info "Created ring" R xs
rrr = split(body, ",")
l = length(rrr)
Expand Down Expand Up @@ -100,7 +100,7 @@ function read_MAPK_include()
@info "First line" head
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse(join(headv, ","))
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))

collect(include(apath))
end
Expand All @@ -109,7 +109,7 @@ function parse_include(filename)
head = "x, y, z"
headv = map(x -> Symbol(x), split(head, ", "))
e = Meta.parse("x, y, z")
R, xs = eval(:((R, $e) = Nemo.PolynomialRing(Nemo.QQ, $headv)))
R, xs = eval(:((R, $e) = Nemo.polynomial_ring(Nemo.QQ, $headv)))

include(abspath("benchmark\\data\\$filename"))
end
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Pkg.add("AbstractAlgebra") # hide
```julia:aaimport
using AbstractAlgebra
R, (x, y, z) = PolynomialRing(GF(2^31 - 1), ["x", "y", "z"])
R, (x, y, z) = polynomial_ring(GF(2^31 - 1), ["x", "y", "z"])
polys = [x^2 + y + z, x*y + z];
```

Expand Down
6 changes: 3 additions & 3 deletions docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ The Groebner basis of the above with $t > x > y$ in lexicographic order is

```julia:impl1
using AbstractAlgebra
_, (t, x, y) = PolynomialRing(QQ, ["t", "x", "y"], ordering=:lex)
_, (t, x, y) = polynomial_ring(QQ, ["t", "x", "y"], ordering=:lex)
groebner([t^2*y - 2t + y, t^2*x + t^2 + x - 1])
```
Expand All @@ -257,7 +257,7 @@ Groebner bases can be used to solve systems *exactly*, given the number of solut
In this section we assume the usual lexicographic ordering of variables and consider the case with three variables (i.e, $x > y > z$). Same method generalizes naturally for $n$ indeterminates.

```julia:sys0
_, (x, y, z) = PolynomialRing(QQ, ["x", "y", "z"], ordering=:lex);
_, (x, y, z) = polynomial_ring(QQ, ["x", "y", "z"], ordering=:lex);
```

To illustrate the method, we consider the following polynomial system to solve
Expand Down Expand Up @@ -316,7 +316,7 @@ F = \{p^5 - n, p^10 - d, p^25 - q\}
The idea is to construct a more useful set of constraints using a Groebner basis

```julia:coins1
_, (p, n, d, q) = PolynomialRing(QQ, ["p","n","d","q"], ordering=:deglex)
_, (p, n, d, q) = polynomial_ring(QQ, ["p","n","d","q"], ordering=:deglex)
F = [p^5 - n, p^10 - d, p^25 - q] # initial constraints
Expand Down
2 changes: 1 addition & 1 deletion experimental/SI/si.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ flag, gb_2 = Groebner.groebner_apply!(graph, G_zp)
end
end

R, x = PolynomialRing(Nemo.GF(2^31 - 1), ["x$i" for i in 1:15], ordering=:degrevlex)
R, x = polynomial_ring(Nemo.GF(2^31 - 1), ["x$i" for i in 1:15], ordering=:degrevlex)

f = [a^rand(1:3) * b^rand(1:3) + c^rand(1:2) for a in x for b in x for c in x];

Expand Down
99 changes: 0 additions & 99 deletions experimental/SI_bug.jl

This file was deleted.

3 changes: 0 additions & 3 deletions experimental/allocator/Project.toml

This file was deleted.

Loading

0 comments on commit 148b12f

Please sign in to comment.