Skip to content

Commit

Permalink
restore reverted commits
Browse files Browse the repository at this point in the history
  • Loading branch information
sumiya11 committed Oct 14, 2024
1 parent c62fbfb commit 1072de6
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 36 deletions.
8 changes: 5 additions & 3 deletions docs/_layout/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1 class="sidebar-title"><a href="/">Groebner<span style="opacity:0.4">.jl</spa
<nav class="sidebar-nav" style="opacity: 0.9">
<a class="sidebar-nav-item {{ispage index.html}}active{{end}}" href="/">Home</a>
<!-- <a class="sidebar-nav-item {{ispage tutorial.html}}active{{end}}" href="/tutorial/">Tutorials</a> -->
<li class="sidebar-nav-item {{ispage tutorial.html}}active{{end}}"><a href="/tutorial/">Introductory tutorial</a>
<!-- <li class="sidebar-nav-item {{ispage tutorial.html}}active{{end}}"><a href="/tutorial/">Introductory tutorial</a> -->
<!-- <ul class="menu-list-child-list ">
<li class="menu-list-item {{ispage tutorial.html}}active{{end}}"><a href="/tutorial/#introduction" class="menu-list-link">Introduction</a>
<li class="menu-list-item {{ispage tutorial.html}}active{{end}}"><a href="/tutorial/#gcd_rref" class="menu-list-link">Gcd & Rref</a>
Expand All @@ -50,8 +50,10 @@ <h1 class="sidebar-title"><a href="/">Groebner<span style="opacity:0.4">.jl</spa
class="menu-list-link">Monomial orderings</a>
<li class="menu-list-item {{ispage interface.html}}active{{end}}"><a href="/interface/#learn_and_apply"
class="menu-list-link">Learn and Apply</a>
<li class="menu-list-item {{ispage interface.html}}active{{end}}"><a href="/interface/#low-level_interface"
class="menu-list-link">Low-level interface</a>
</ul>
<li class="sidebar-nav-item {{ispage developer.html}}active{{end}}"><a href="/developer/">Development</a>
<!-- <li class="sidebar-nav-item {{ispage developer.html}}active{{end}}"><a href="/developer/">Development</a> -->
</nav>

</div>
Expand All @@ -64,4 +66,4 @@ <h1 class="sidebar-title"><a href="/">Groebner<span style="opacity:0.4">.jl</spa
powered.</a>
</div>
</div>
<div class="content container">
<div class="content container">
15 changes: 12 additions & 3 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ where appropriate -->
![](/assets/logo-with-text.svg)
@@

Groebner.jl is a package for fast and generic Gröbner bases computations based on Faugère's [F4 algorithm](https://www-polsys.lip6.fr/~jcf/Papers/F99a.pdf) written in Julia.
Groebner.jl is a package for Gröbner bases computations based on the Faugère's F4 algorithm written in Julia.

## Installation

Expand All @@ -26,10 +26,19 @@ using Pkg; Pkg.add("Groebner")

See [Interface](interface) for a description of all exported functions. For a quick introduction to Groebner bases we refer to [Tutorials](tutorial). Meanwhile, below are simple examples.

## Features

Groebner.jl features:

- Gröbner basis computation over integers modulo a prime and over the rationals
- Gröbner trace algorithms
- Multi-threading by default

See [Interface](interface) page for a list of all exported functions.

## Examples

Currently, polynomials from AbstractAlgebra.jl, DynamicPolynomials.jl, and Nemo.jl
are supported as input.
As input, Groebner.jl supports polynomials from AbstractAlgebra.jl, DynamicPolynomials.jl, and Nemo.jl.

### with AbstractAlgebra.jl

Expand Down
26 changes: 26 additions & 0 deletions docs/interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,29 @@ using Groebner # hide
{{doc groebner_learn groebner_learn fn}}

{{doc groebner_apply! groebner_apply! fn}}

## Low-level interface

```julia:load_groebner
using Groebner # hide
```

Some functions in the interface have a low-level entry point. Low-level functions accept and output ''raw'' exponent vectors and coefficients. This could be convenient when one does not want to depend on a frontend.

For example,

```julia:lowlevel
using Groebner
# define {x y - 1, x^3 + 7 y^2} modulo 65537 in DRL
ring = Groebner.PolyRing(2, Groebner.DegRevLex(), 65537)
monoms = [ [[1, 1], [0, 0]], [[3, 0], [0, 2]] ]
coeffs = [ [1, -1], [1, 7] ]
# compute a GB
gb_monoms, gb_coeffs = Groebner.groebner(ring, monoms, coeffs)
```

The list of functions that provide a low-level entry point: `groebner`, `normalform`, `isgroebner`, `groebner_learn`, `groebner_apply`.

The low-level functions may be faster than their user-facing analogues since they bypass internal checks and conversions. Low-level functions do not make any specific assumptions, that is, all of these are correctly handled in the input: unsorted monomials, nonnormalized coefficients, duplicate terms, aliasing memory.


5 changes: 5 additions & 0 deletions src/groebner/parameters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ function AlgorithmParameters(ring::PolyRing, kwargs::KeywordArguments; hint=:non
# TODO: In the future, it would be good to adapt randomized linear
# algebra to this case by taking more random samples
if ring.ch < 500
if linalg === :randomized
@info """
The option linalg=:randomized was ignored:
the ground field characteristic is small."""
end
linalg = :deterministic
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ flag, gb_2 = groebner_apply!(
@assert gb_2 == groebner([2x2*y2^2 + 3x2, 4y2*x2^2 + 5y2], ordering=DegRevLex())
```
Using `groebner_apply!` in batches (works only in `:degrevlex` at the moment):
Using `groebner_apply!` in batches:
```jldoctest
using Groebner, AbstractAlgebra
Expand Down
66 changes: 37 additions & 29 deletions src/utils/packed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,78 +5,86 @@
# One 64-bit integer packs 8 integers 8-bit each.

# checks that a[i] >= b[i] for all i.
@inline function _packed_vec_ge(a::UInt64, b::UInt64)
@inline @generated function _packed_vec_ge(a::UInt64, b::UInt64)
N = 8
textir = """
define i8 @entry(i64 %0, i64 %1) #0 {
top:
%av = bitcast i64 %0 to <8 x i8>
%bv = bitcast i64 %1 to <8 x i8>
%mask = icmp uge <8 x i8> %av, %bv
%mask.i = bitcast <8 x i1> %mask to i8
%res = icmp eq i8 %mask.i, 255
%av = bitcast i64 %0 to <$N x i8>
%bv = bitcast i64 %1 to <$N x i8>
%mask = icmp uge <$N x i8> %av, %bv
%mask.i = bitcast <$N x i1> %mask to i$N
%res = icmp eq i$N %mask.i, $(big(2)^N - 1)
%retval = zext i1 %res to i8
ret i8 %retval
}
attributes #0 = { alwaysinline }
"""
Base.llvmcall((textir, "entry"), Bool, Tuple{UInt64, UInt64}, a, b)
quote
Base.llvmcall(($textir, "entry"), Bool, Tuple{UInt64, UInt64}, a, b)
end
end

# checks that a, b are orthogonal
@inline function _packed_vec_is_orth(a::UInt64, b::UInt64)
@inline @generated function _packed_vec_is_orth(a::UInt64, b::UInt64)
N = 8
textir = """
define i8 @entry(i64 %0, i64 %1) #0 {
top:
%av = bitcast i64 %0 to <8 x i8>
%bv = bitcast i64 %1 to <8 x i8>
%zero = bitcast i64 0 to <8 x i8>
%mask.a = icmp ne <8 x i8> %av, %zero
%mask.b = icmp ne <8 x i8> %bv, %zero
%mask = and <8 x i1> %mask.a, %mask.b
%mask.i = bitcast <8 x i1> %mask to i8
%res = icmp eq i8 %mask.i, 0
%av = bitcast i64 %0 to <$N x i8>
%bv = bitcast i64 %1 to <$N x i8>
%zero = bitcast i64 0 to <$N x i8>
%mask.a = icmp ne <$N x i8> %av, %zero
%mask.b = icmp ne <$N x i8> %bv, %zero
%mask = and <$N x i1> %mask.a, %mask.b
%mask.i = bitcast <$N x i1> %mask to i$N
%res = icmp eq i$N %mask.i, 0
%retval = zext i1 %res to i8
ret i8 %retval
}
attributes #0 = { alwaysinline }
"""
Base.llvmcall((textir, "entry"), Bool, Tuple{UInt64, UInt64}, a, b)
quote
Base.llvmcall(($textir, "entry"), Bool, Tuple{UInt64, UInt64}, a, b)
end
end

# returns sum a[i]
@inline function _packed_vec_reduce(a::UInt64)
@inline @generated function _packed_vec_reduce(a::UInt64)
N = 8
textir = """
declare i8 @llvm.vector.reduce.add.v8i8(<8 x i8>)
declare i8 @llvm.vector.reduce.add.v$(N)i8(<$N x i8>)
define i8 @entry(i64 %0) #0 {
top:
%a.v = bitcast i64 %0 to <8 x i8>
%sum = call i8 @llvm.vector.reduce.add.v8i8(<8 x i8> %a.v)
%a.v = bitcast i64 %0 to <$N x i8>
%sum = call i8 @llvm.vector.reduce.add.v$(N)i8(<$N x i8> %a.v)
ret i8 %sum
}
attributes #0 = { alwaysinline }
"""
Base.llvmcall((textir, "entry"), UInt8, Tuple{UInt64}, a)
quote
Base.llvmcall(($textir, "entry"), UInt8, Tuple{UInt64}, a)
end
end

# returns c[i] = max a[i], b[i]
@inline function _packed_vec_max(a::UInt64, b::UInt64)
@inline @generated function _packed_vec_max(a::UInt64, b::UInt64)
N = 8
textir = """
declare <8 x i8> @llvm.umax.v8i8(<8 x i8>, <8 x i8>)
declare <$N x i8> @llvm.umax.v$(N)i8(<$N x i8>, <$N x i8>)
define i64 @entry(i64 %0, i64 %1) #0 {
top:
%a.v = bitcast i64 %0 to <8 x i8>
%b.v = bitcast i64 %1 to <8 x i8>
%max.v = call <8 x i8> @llvm.umax.v8i8(<8 x i8> %a.v, <8 x i8> %b.v)
%max = bitcast <8 x i8> %max.v to i64
%a.v = bitcast i64 %0 to <$N x i8>
%b.v = bitcast i64 %1 to <$N x i8>
%max.v = call <$N x i8> @llvm.umax.v$(N)i8(<$N x i8> %a.v, <$N x i8> %b.v)
%max = bitcast <$N x i8> %max.v to i64
ret i64 %max
}
attributes #0 = { alwaysinline }
"""
Base.llvmcall((textir, "entry"), UInt64, Tuple{UInt64, UInt64}, a, b)
quote
Base.llvmcall(($textir, "entry"), UInt64, Tuple{UInt64, UInt64}, a, b)
end
end

@inline @generated function _packed_vec_unpack!(
Expand Down

0 comments on commit 1072de6

Please sign in to comment.