Skip to content

Commit

Permalink
Merge pull request #155 from sumiya11/cleanup-f4
Browse files Browse the repository at this point in the history
Cleanup f4
  • Loading branch information
sumiya11 committed Sep 20, 2024
2 parents 98805b3 + efb76ee commit ce6de6d
Show file tree
Hide file tree
Showing 31 changed files with 901 additions and 1,521 deletions.
11 changes: 1 addition & 10 deletions src/Groebner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,13 @@ It is useful to enable this when debugging the Groebner package.
"""
invariants_enabled() = false

"""
logging_enabled() -> Bool
Specifies if logging is enabled. If `false`, then all logging in Groebner is
disabled, and entails **(almost)** no runtime overhead.
"""
logging_enabled() = true

###
# Imports

# Groebner does not provide a polynomial implementation of its own but relies on
# existing symbolic computation packages in Julia for communicating with the
# user. Groebner accepts as its input polynomials from the Julia packages
# AbstractAlgebra.jl, Nemo.jl (Oscar.jl), and MultivariatePolynomials.jl.
# AbstractAlgebra.jl, Nemo.jl, and MultivariatePolynomials.jl.
import AbstractAlgebra
import AbstractAlgebra: base_ring, elem_type

Expand Down Expand Up @@ -145,7 +137,6 @@ include("reconstruction/crt.jl")
include("reconstruction/ratrec.jl")

#= more high level functions =#
include("groebner/primes.jl")
include("groebner/modular.jl")
include("groebner/groebner.jl")
include("groebner/groebner_with_change_matrix.jl")
Expand Down
88 changes: 0 additions & 88 deletions src/arithmetic/Zp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,84 +309,6 @@ function inv_mod_p(a::T, arithm::SignedCompositeArithmeticZp{T}) where {T}
CompositeNumber(invmod.(a.data, arithm.ps.data))
end

###
# FloatingPointArithmeticZp

struct FloatingPointArithmeticZp{AccumType, CoeffType} <: AbstractArithmeticZp{AccumType, CoeffType}
multiplier::AccumType
divisor::AccumType

function FloatingPointArithmeticZp(
::Type{AccumType},
::Type{CoeffType},
p::CoeffType
) where {AccumType <: CoeffZp, CoeffType <: CoeffZp}
@invariant AccumType === Float64
@invariant 0 < p < 2^25 # < 52 / 2 - 1
@invariant Primes.isprime(Int(p))
multiplier = 1 / p
new{AccumType, CoeffType}(multiplier, p)
end
end

divisor(arithm::FloatingPointArithmeticZp) = arithm.divisor

@inline function mod_p(a::T, mod::FloatingPointArithmeticZp{T, C}) where {T, C}
b = a * mod.multiplier
c = floor(b)
a - mod.divisor * c # may be fused
end

@inline function fma_mod_p(a1::T, a2::C, a3::T, mod::FloatingPointArithmeticZp{T, C}) where {T, C}
b = muladd(a1, a2, a3)
mod_p(b, mod)
end

inv_mod_p(a::T, arithm::FloatingPointArithmeticZp{T}) where {T} =
T(invmod(Int(a), Int(divisor(arithm))))

###
# FloatingPointCompositeArithmeticZp

struct FloatingPointCompositeArithmeticZp{AccumType, CoeffType, T, N} <:
AbstractArithmeticZp{AccumType, CoeffType}
multiplier::CompositeNumber{N, T}
divisor::CompositeNumber{N, T}

function FloatingPointCompositeArithmeticZp(
::Type{CompositeNumber{N, AT}},
::Type{CompositeNumber{N, CT}},
ps::CompositeNumber{N, CT}
) where {N, AT <: CoeffZp, CT <: CoeffZp}
@invariant AT === Float64
@invariant all(0 .< ps.data .< 2^25) # < 52 / 2 - 1
@invariant all(Primes.isprime.(Int.(ps.data)))
multiplier = inv(ps)
new{CompositeNumber{N, AT}, CompositeNumber{N, CT}, AT, N}(multiplier, ps)
end
end

divisor(arithm::FloatingPointCompositeArithmeticZp) = arithm.divisor

@inline function mod_p(a::T, mod::FloatingPointCompositeArithmeticZp{T, C}) where {T, C}
b = a * mod.multiplier
c = T(floor.(b.data))
a - mod.divisor * c # may be fused
end

@inline function fma_mod_p(
a1::T,
a2::C,
a3::T,
mod::FloatingPointCompositeArithmeticZp{T, C}
) where {T, C}
b = CompositeNumber(muladd.(a1.data, a2.data, a3.data))
mod_p(b, mod)
end

inv_mod_p(a::T, arithm::FloatingPointCompositeArithmeticZp{T}) where {T} =
T(invmod.(Int.(a.data), Int.(divisor(arithm).data)))

###
# Selection of arithmetic

Expand Down Expand Up @@ -418,21 +340,11 @@ function select_arithmetic(
if CoeffType <: CompositeCoeffZp
if hint === :signed || CoeffType <: CompositeNumber{N, T} where {N, T <: Signed}
return SignedCompositeArithmeticZp(AccumType, CoeffType, CoeffType(characteristic))
elseif hint === :floating
return FloatingPointCompositeArithmeticZp(
AccumType,
CoeffType,
CoeffType(characteristic)
)
else
return CompositeArithmeticZp(AccumType, CoeffType, CoeffType(characteristic))
end
end

if hint === :floating
return FloatingPointArithmeticZp(AccumType, CoeffType, CoeffType(characteristic))
end

if hint === :signed
return SignedArithmeticZp(AccumType, CoeffType, CoeffType(characteristic))
end
Expand Down
Loading

0 comments on commit ce6de6d

Please sign in to comment.