Skip to content

Commit

Permalink
arithmetic in QQ
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Jul 12, 2023
1 parent 7011948 commit c46c361
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
26 changes: 26 additions & 0 deletions benchmark/experiments/normalform_f4.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

include("../../src/Groebner.jl")

if !isdefined(Main, :Groebner)
import Groebner
end

import AbstractAlgebra
using Nemo
using BenchmarkTools
using Logging
global_logger(ConsoleLogger(stderr, Logging.Error))

BenchmarkTools.DEFAULT_PARAMETERS.samples = 4

system = Groebner.cyclicn(7, ground=Nemo.QQ, ordering=:degrevlex)
gb = Groebner.groebner(system);
xs = gens(parent(system[1]))

@time Groebner.normalform(gb, system, check=false);
collect([AbstractAlgebra.normal_form(s, gb) for s in system])

@benchmark Groebner.normalform($gb, $system, check=false)
@benchmark for s in system
AbstractAlgebra.normal_form(s, gb)
end
13 changes: 12 additions & 1 deletion src/arithmetic/QQ.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@
# All implementations of arithmetic in QQ are a subtype of it.
abstract type AbstractArithmeticQQ end

struct BuiltinArithmeticQQ <: AbstractArithmeticQQ end
struct BuiltinArithmeticQQ <: AbstractArithmeticQQ
buf1::BigInt
buf2::Rational{BigInt}
function BuiltinArithmeticQQ()
new(BigInt(0), Rational{BigInt}(0))
end
end

# arithmetic over rational numbers
function select_arithmetic(coeffs::Vector{Vector{T}}, ch) where {T <: CoeffQQ}
BuiltinArithmeticQQ()
end
5 changes: 0 additions & 5 deletions src/arithmetic/Zp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,3 @@ end
function select_arithmetic(coeffs::Vector{Vector{T}}, ch) where {T <: CoeffFF}
SpecializedBuiltinArithmeticZp(convert(T, ch))
end

# arithmetic over rational numbers
function select_arithmetic(coeffs::Vector{Vector{T}}, ch) where {T <: CoeffQQ}
ch
end
7 changes: 4 additions & 3 deletions src/f4/matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ function reduce_by_pivot!(
row::Vector{T},
indices::Vector{ColumnIdx},
cfs::Vector{T},
ch
arithmetic::BuiltinArithmeticQQ
) where {T <: CoeffQQ}
@inbounds mul = -row[indices[1]]

buf2 = arithmetic.buf2
@inbounds for j in 1:length(indices)
idx = indices[j]
row[idx] = row[idx] + mul * cfs[j]
# Base.GMP.MPQ.mul!(buf2, cfs[j], mul)
# row[idx] = row[idx] + buf2
end

nothing
end

Expand Down

0 comments on commit c46c361

Please sign in to comment.