Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beautifulization #72

Merged
merged 11 commits into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

Minor bug fixes and improvements.

Versions of dependencies:
- Added depency on SIMD.jl.
- Updated version of MultivariatePolynomials.jl to 0.5.
- Updated version of AbstractAlgebra.jl to 0.31.

Changes in the interface:
- Keyword argument `rng` removed. Instead, now the `seed` keyword argument is provided for setting the seed of the internal random number generator.
- Changed keyword arguments `linalg`, `monoms`, and `loglevel`.
- Keyword argument `rng` removed. Instead, the `seed` keyword argument is provided for setting the seed of internal rng.
- Changed keyword arguments `check`, `linalg`, `monoms`, and `loglevel`.
In particular, now it is possible to specify `monom = :sparse` to use a sparse monomial representation.
- Added functions `grobner_learn` and `groebner_apply!`.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SIMD = "fdea26ae-647d-5447-a871-4b548cad5224"
SnoopPrecompile = "66db9d55-30c0-4569-8b51-7e840670fc0c"

[compat]
AbstractAlgebra = "0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30"
AbstractAlgebra = "0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.30, 0.31"
BenchmarkTools = "1"
Combinatorics = "1"
MultivariatePolynomials = "0.4, 0.5"
Expand Down
61 changes: 61 additions & 0 deletions experimental/nullstellensatz.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using AbstractAlgebra, Nemo
using Polymake

Nemo.height_bits(f::fmpq_mpoly) = maximum(Nemo.height_bits, collect(coefficients(f)))

newton_polytope(f) = newton_polytope([f])
function newton_polytope(I::Vector{T}) where {T}
R = parent(first(I))
I = deepcopy(I)
prepend!(I, gens(R))
prepend!(I, [one(R)])
points = splat(vcat)(map(collect ∘ exponent_vectors, I))
points = map(p -> prepend!(p, 1), points)
points = reduce(vcat, map(transpose, points))
polytope.Polytope(POINTS=points)
end

function effective_nullstellensatz_1(F)
R = parent(first(F))
s = length(F)
n = nvars(R)
d = maximum(Nemo.total_degree, F)
h = maximum(Nemo.height_bits, F)
n, d, h = map(BigInt, (n, d, h))
@info "" n d h
# bound on the degree
D = 4 * n * d^n
# bound on the height
H = 4 * n * (n + 1) * d^n * (h + log(s) + (n + 7) * log(n + 1) * d)
H = round(BigInt, H)
(D=D, H=H)
end

function effective_nullstellensatz_2(F)
R = parent(first(F))
s = length(F)
n = nvars(R)
d = maximum(Nemo.total_degree, F)
h = maximum(Nemo.height_bits, F)
P = newton_polytope(F)
V = Rational{BigInt}(P.VOLUME)
n, d, h = map(BigInt, (n, d, h))
@info "" n d h V
# bound on the degree
D = 2 * n^2 * d * V
# bound on the height
H = 2 * (n + 1)^3 * d * V * (h + log(s) + 2^(2n + 4) * d * log(d + 1))
H = round(BigInt, H)
(D=D, H=H)
end

R, (x1, x2) = Nemo.QQ["x1", "x2"]

I = [one(R), x1, x2, x1^2 * x2^2 - 1, x1 + x2]
I = Groebner.katsuran(2, np=Nemo) .^ 10
I = [x1]

P = newton_polytope(I)

effective_nullstellensatz_1(I)
effective_nullstellensatz_2(I)
18 changes: 0 additions & 18 deletions experimental/runge-kutta/maxpairs_1000.jl

This file was deleted.

11 changes: 11 additions & 0 deletions experimental/runge-kutta/run_2.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# using DynamicPolynomials, Nemo
# using Groebner

# include((@__DIR__) * "/rss_tracker.jl")
include((@__DIR__) * "/aa-runge-kutta-6-6.jl");

# setup_memuse_tracker()

Groebner.logging_enabled() = true

@time gb = Groebner.groebner(system, loglevel=-1, ordering=Groebner.DegRevLex());
3 changes: 2 additions & 1 deletion src/Groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ If `false`, then all checks are disabled, and entail no runtime overhead.

See also `@invariant` in `src/utils/invariants.jl`.
"""
invariants_enabled() = true
invariants_enabled() = false

"""
logging_enabled() -> Bool
Expand Down Expand Up @@ -63,6 +63,7 @@ include("monomials/common.jl")
include("monomials/packedutils.jl")
include("monomials/packedtuples.jl")
include("monomials/exponentvector.jl")
include("monomials/sparsevector.jl")

# Defines some type aliases for Groebner
include("utils/types.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/arithmetic/QQ.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Arithmetic in the rationals.

# All implementations of arithmetic in QQ are a subtype of it.
# All implementations of arithmetic in Q are a subtype of this
abstract type AbstractArithmeticQQ end

# Standard arithmetic that uses Base.GMP.MPQ
struct BuiltinArithmeticQQ <: AbstractArithmeticQQ
buf1::BigInt
buf2::Rational{BigInt}
Expand All @@ -11,7 +12,6 @@ struct BuiltinArithmeticQQ <: AbstractArithmeticQQ
end
end

# arithmetic over rational numbers
function select_arithmetic(coeffs::Vector{Vector{T}}, ch) where {T <: CoeffQQ}
BuiltinArithmeticQQ()
end
10 changes: 5 additions & 5 deletions src/arithmetic/Zp.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Arithmetic in Zp.

# All implementations of arithmetic in Zp are a subtype of it.
# All implementations of arithmetic in Zp are a subtype of this
abstract type AbstractArithmeticZp end

# Modular arithmetic implemented based on the Julia builtin classes in
# Modular arithmetic based on the Julia builtin classes in
# `Base.MultiplicativeInverses`. Used for primes smaller than 2^32.
struct BuiltinArithmeticZp{T <: Unsigned} <: AbstractArithmeticZp
# magic contains is a precomputed multiplicative inverse of the divisor
Expand All @@ -15,9 +15,9 @@ end

divisor(arithm::BuiltinArithmeticZp) = arithm.magic.divisor

# Same as the built-in implementation, by specializes on the type of the prime
# number being used and stores the fields inline. This implementation is
# preferred for primes up to 128 bit.
# Same as the built-in one, by specializes on the type of the prime number and
# stores the fields inline. This implementation is preferred for primes up to
# 64 bits.
struct SpecializedBuiltinArithmeticZp{T <: Unsigned, Add} <: AbstractArithmeticZp
multiplier::T
shift::UInt8
Expand Down
28 changes: 10 additions & 18 deletions src/f4/basis.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# Pairset and Basis

# Basis is a structure that stores a list of polynomials in F4. Each polynomial
# is represented as a sorted vector of monomials and a sorted vector of
# coefficients. Monomials and coefficients are stored in the basis separately.
# Each monomial is represented with an integer --- an index to a bucket in the
# hashtable (see f4/hashtable.jl).
# Basis is a structure that stores a list of polynomials. Each polynomial is
# represented with a sorted vector of monomials and a vector of coefficients.
# Monomials and coefficients are stored in the basis separately. Each monomial
# is represented with an integer --- an index to a bucket in the hashtable (see
# f4/hashtable.jl).

# Pairset is a list of SPairs.
# An SPair is a critical pair in F4.
# Pairset is a list of critical pairs (SPairs).

# S-pair{Degree}, a pair of polynomials,
# S-pair{Degree}, or a pair of polynomials,
struct SPair{Degree}
# First polynomial given by its index in the basis array
poly1::Int32
# Second polynomial -//-
poly2::Int32
# Index of lcm(lead(poly1), lead(poly2)) in hashtable
# Index of lcm(lead(poly1), lead(poly2)) in the hashtable
lcm::MonomIdx
# Total degree of lcm
deg::Degree
Expand All @@ -24,8 +23,7 @@ end
# Stores S-Pairs and some additional info.
mutable struct Pairset{Degree}
pairs::Vector{SPair{Degree}}
# For each pair (poly1, poly2) in array `pairs`, stores the lcm monomial of
# lcm(lead(poly1), lead(poly2)) as its index in hashtable
# A buffer of monomials represented with indices to a hashtable
lcms::Vector{MonomIdx}
# Number of filled pairs, initially zero
load::Int
Expand Down Expand Up @@ -224,8 +222,6 @@ function normalize_basis!(ring, basis::Basis{<:CoeffQQ})
basis
end

#------------------------------------------------------------------------------

# Generate new S-pairs from pairs of polynomials
# (basis[idx], basis[i])
# for every i < idx
Expand Down Expand Up @@ -441,8 +437,6 @@ function update!(
pairset_size
end

#------------------------------------------------------------------------------

# given input exponent and coefficient vectors hashes exponents into `ht`
# and then constructs hashed polynomials for `basis`
function fill_data!(
Expand Down Expand Up @@ -554,8 +548,6 @@ function export_basis_data(
exps, coeffs
end

#------------------------------------------------------------------------------

# For a given list of S-pairs and a list of indices `plcm`
# adds indices from plcm[ifirst:ilast]
# to the hashtable ht
Expand Down Expand Up @@ -594,7 +586,7 @@ function insert_lcms_in_basis_hash_table!(
ps[m] = ps[off + l]

h = update_ht.hashdata[plcm[l]].hash
ht.monoms[ht.load + 1] = copy(update_ht.monoms[plcm[l]])
ht.monoms[ht.load + 1] = copy_monom(update_ht.monoms[plcm[l]])
n = ht.monoms[ht.load + 1]

k = h
Expand Down
Loading
Loading