Skip to content

Commit

Permalink
format ome files
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jul 11, 2023
1 parent eee1eb3 commit 7b565eb
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 232 deletions.
12 changes: 3 additions & 9 deletions src/input-output/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ function extract_ring(polynomials)
@assert hasmethod(AbstractAlgebra.characteristic, Tuple{T})
nv = AbstractAlgebra.nvars(R)
# lex is the default ordering on univariate polynomials
ord =
hasmethod(AbstractAlgebra.ordering, Tuple{T}) ? AbstractAlgebra.ordering(R) :
:lex
ord = hasmethod(AbstractAlgebra.ordering, Tuple{T}) ? AbstractAlgebra.ordering(R) : :lex
# type unstable:
ordT = ordering_sym2typed(ord)
ch = AbstractAlgebra.characteristic(R)
Expand Down Expand Up @@ -125,7 +123,7 @@ function extract_coeffs_raw!(graph, representation, polys::Vector{T}, kws) where
perm = graph.input_permutation
Ch = representation.coefftype
_extract_coeffs_raw!(basis, perm, polys, Ch)
@log level=-5 "Extracted coefficients from $(length(polys)) polynomials." basis perm
@log level = -5 "Extracted coefficients from $(length(polys)) polynomials." basis perm
ring
end

Expand All @@ -150,11 +148,7 @@ function extract_coeffs_qq(representation, ring::PolyRing, poly)
map(Rational, AbstractAlgebra.coefficients(poly))
end

function extract_monoms(
representation::PolynomialRepresentation,
ring::PolyRing,
poly
)
function extract_monoms(representation::PolynomialRepresentation, ring::PolyRing, poly)
exps = Vector{representation.monomtype}(undef, length(poly))
@inbounds for j in 1:length(poly)
exps[j] = construct_monom(
Expand Down
41 changes: 24 additions & 17 deletions test/groebner/groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,11 @@ end
x10^2 - 71551 // 26396 * x10 + 45155 // 26396
]

system = [x1 + BigInt(10)^100 // BigInt(7)^50 * x2,
BigInt(90) * x1*x2 + BigInt(19)^50 + x10^3,
BigInt(2^31-1)*x1^2 + BigInt(2^30 + 2)^10 * x2^2]
system = [
x1 + BigInt(10)^100 // BigInt(7)^50 * x2,
BigInt(90) * x1 * x2 + BigInt(19)^50 + x10^3,
BigInt(2^31 - 1) * x1^2 + BigInt(2^30 + 2)^10 * x2^2
]
@test Groebner.groebner(system) == Groebner.groebner(system, certify=true)
end

Expand Down Expand Up @@ -463,7 +465,8 @@ end
R, (x, y, z) = PolynomialRing(field, ["x", "y", "z"], ordering=:lex)

@test Groebner.normalform([R(0)], [R(0)]) == [R(0)]
@test Groebner.normalform([R(0), R(0), R(0)], [x + 2, x, x + 1]) == [x + 2, x, x + 1]
@test Groebner.normalform([R(0), R(0), R(0)], [x + 2, x, x + 1]) ==
[x + 2, x, x + 1]
@test Groebner.normalform([R(0), R(0), R(0)], R(0)) == R(0)

@test_throws AssertionError Groebner.normalform([], x)
Expand Down Expand Up @@ -497,7 +500,9 @@ end
[y, x]

fs = [x^2 + y, x * y]
@test Groebner.groebner(fs, linalg=linalg) == Groebner.groebner(fs) == [y^2, x * y, x^2 + y]
@test Groebner.groebner(fs, linalg=linalg) ==
Groebner.groebner(fs) ==
[y^2, x * y, x^2 + y]

root = Groebner.rootn(3, ground=GF(2^31 - 1), ordering=:degrevlex)
x1, x2, x3 = gens(parent(first(root)))
Expand All @@ -516,17 +521,19 @@ end
gb1 = Groebner.groebner(ku)
gb2 = Groebner.groebner(ku, linalg=linalg)

@test gb1 == gb2 == [
x9 + 1272065637 * x10 + 875418006,
x8 + 1529540685 * x10 + 617942964,
x7 + 1539832471 * x10 + 607651173,
x6 + 1314302432 * x10 + 833181218,
x5 + 1453635454 * x10 + 693848197,
x4 + 673118236 * x10 + 1474365406,
x3 + 269783061 * x10 + 1877700587,
x2 + 1042807874 * x10 + 1104675778,
x1 + 389079675 * x10 + 1758403970,
x10^2 + 1222705397 * x10 + 924778249
]
@test gb1 ==
gb2 ==
[
x9 + 1272065637 * x10 + 875418006,
x8 + 1529540685 * x10 + 617942964,
x7 + 1539832471 * x10 + 607651173,
x6 + 1314302432 * x10 + 833181218,
x5 + 1453635454 * x10 + 693848197,
x4 + 673118236 * x10 + 1474365406,
x3 + 269783061 * x10 + 1877700587,
x2 + 1042807874 * x10 + 1104675778,
x1 + 389079675 * x10 + 1758403970,
x10^2 + 1222705397 * x10 + 924778249
]
end
end
1 change: 0 additions & 1 deletion test/groebner/mod_reconstruction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ using Primes
@test Base.unsafe_rational(num, den) == a
end
end

end
8 changes: 6 additions & 2 deletions test/input-output/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ end
# R, (x, y) = AbstractAlgebra.GF(nextprime(BigInt(2)^100))["x","y"]

aa_orderings_to_test = [:lex, :degrevlex, :deglex]
aa_grounds_to_test =
[AbstractAlgebra.GF(2^62 + 135), AbstractAlgebra.GF(2^31 - 1), AbstractAlgebra.GF(17), AbstractAlgebra.QQ]
aa_grounds_to_test = [
AbstractAlgebra.GF(2^62 + 135),
AbstractAlgebra.GF(2^31 - 1),
AbstractAlgebra.GF(17),
AbstractAlgebra.QQ
]

for ord in aa_orderings_to_test
for ground in aa_grounds_to_test
Expand Down
24 changes: 12 additions & 12 deletions test/learn_and_apply/learn_and_apply.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const loglevel = 0

@testset "Learn & apply" begin
K = AbstractAlgebra.GF(2^31-1)
K = AbstractAlgebra.GF(2^31 - 1)
R, (x, y) = PolynomialRing(K, ["x", "y"], ordering=:degrevlex)
R2, xs = PolynomialRing(K, ["x$i" for i in 1:30], ordering=:degrevlex)

Expand Down Expand Up @@ -31,7 +31,7 @@ const loglevel = 0
(system=Groebner.kinema(ordering=:degrevlex, ground=K),),
(system=Groebner.sparse5(ordering=:degrevlex, ground=K),),
(system=Groebner.s9_1(ordering=:degrevlex, ground=K),),
(system=[sum(xs) + prod(xs), sum(xs)^2, prod(xs) - 1],),
(system=[sum(xs) + prod(xs), sum(xs)^2, prod(xs) - 1],)
]
for case in cases
# Learn and apply on the same system
Expand All @@ -46,7 +46,7 @@ const loglevel = 0
X = gens(parent(first(system)))
for _ in 1:N
point = map(t -> iszero(t) ? t + 1 : t, rand(K, length(X))) .* X
system_ = map(f -> evaluate(f, point), system)
system_ = map(f -> evaluate(f, point), system)
true_gb = Groebner.groebner(system_, loglevel=loglevel)
flag, gb_2 = Groebner.groebner_apply!(graph, system_, loglevel=loglevel)
@test flag && gb_2 == true_gb
Expand All @@ -55,11 +55,11 @@ const loglevel = 0
end

@testset "Learn & apply tricky" begin
K = AbstractAlgebra.GF(2^31-1)
K = AbstractAlgebra.GF(2^31 - 1)
R, (x, y) = PolynomialRing(K, ["x", "y"], ordering=:degrevlex)

# s-poly of x + 1 and x*y + 7y is y - 7y.
system_1 = [x + 1, x*y + 7y]
system_1 = [x + 1, x * y + 7y]
graph, gb_1 = Groebner.groebner_learn(system_1, loglevel=loglevel)
flag, gb_2 = Groebner.groebner_apply!(graph, system_1, loglevel=loglevel)
@test flag && gb_2 == gb_1
Expand All @@ -69,35 +69,35 @@ end

# Cancellation of a leading term:
# s-poly of x + 1 and x*y + y is 0 = y - y.
system_2 = [x + 1, x*y + y]
system_2 = [x + 1, x * y + y]
flag, gb_2 = Groebner.groebner_apply!(graph, system_2, loglevel=loglevel)
@test !flag

# s-poly of x + y + 1 and x*y + 7y is y^2 - 7y
system_1 = [x + y + 1, x*y + 7y]
system_1 = [x + y + 1, x * y + 7y]
graph, gb_1 = Groebner.groebner_learn(system_1, loglevel=loglevel)
flag, gb_2 = Groebner.groebner_apply!(graph, system_1, loglevel=loglevel)
@test flag && gb_2 == gb_1

# Cancellation of a trailing term:
# s-poly of x + y + 1 and x*y + y is y^2
# TODO: produce a warning here
system_2 = [x + y + 1, x*y + y]
system_2 = [x + y + 1, x * y + y]
flag, gb_2 = Groebner.groebner_apply!(graph, system_2, loglevel=loglevel)
@test !flag

# Input is a Groebner basis already:
N = 3
for system in [
Groebner.noonn(4, ordering=:degrevlex, ground=K),
Groebner.noonn(4, ordering=:degrevlex, ground=K),
Groebner.katsuran(5, ordering=:degrevlex, ground=K),
[x, x^2, y^2, x*y, x^3, y^4, x^10, y^10, x*y^10]
[x, x^2, y^2, x * y, x^3, y^4, x^10, y^10, x * y^10]
]
gb = Groebner.groebner(system, loglevel=loglevel)
for i in 1:N
graph, gb_1 = Groebner.groebner_learn(gb, loglevel=loglevel)
flag, gb_2 = Groebner.groebner_apply!(graph, gb, loglevel=loglevel)
@test flag && gb_2 == gb_1 == gb
end
end
end
end
Loading

0 comments on commit 7b565eb

Please sign in to comment.