A Sage interface for FGb¶
This package is a SageMath interface to FGb andcan be installed as a Python package for use with Sage. It provides a simplelink between the C-interface of FGb and polynomials and ideals in Sage.
FGb is a C-library by J. C. Faugère for Gröbner basis computations, withsupport for:
Gröbner bases over ℚ and finite prime fields
parallel computations (over finite fields)
elimination/block orders (degree-reverse-lexicographic, only)
Examples¶
See the examples and documentation athttps://fgb-sage.readthedocs.io.
Installation¶
Requirements: Linux with a recent version of Sage(tested with Sage 9.5.rc0 on Ubuntu 20.04 as well as with Sage 9.6 from Arch Linux).
First, clone the repository from GitHub and then compile andrun the tests:
git clone https://github.com/mwageringel/fgb_sage.git && cd fgb_sagesage setup.py test
After the tests passed successfully, run the following command to install thepackage for use with Sage:
sage -python -m pip install --upgrade --no-index -v .
Alternatively, to install into the Python user install directory (no rootaccess required), run:
sage -python -m pip install --upgrade --no-index -v --user .
Installing into a virtual environment, assuming Sage is installed system-wide:
python -m venv --system-site-packages ./sage-venv # assumes that sage and python-setuptools are available system-widesource ./sage-venv/bin/activate # redefines `python` and `pip` using virtual environmentpython -m pip install --upgrade --no-index -v .cd sage-venv && python -m IPython # changing directory is important In [1]: from sage.all import * In [2]: R = PolynomialRing(QQ, 5, 'x', order="degrevlex(2),degrevlex(3)") In [3]: I = sage.rings.ideal.Cyclic(R) In [4]: import fgb_sage In [5]: gb = fgb_sage.groebner_basis(I)
Packaged versions of Sage¶
If Sage was installed by the package manager of your Linux distribution, youmay need to install a few more dependencies in order to compile this package.For example, on
Arch Linux:
pacman -S --asdeps cython python-pkgconfig
Ubuntu:
libgsl-dev liblinbox-dev libsingular4-dev libntl-dev libflint-dev libmpfr-dev libpari-dev python3-ipywidgets
Alternatively, you can download aSage binary,use Sage via Docker orinstall Sage from source.See also issue #2.
Issues¶
macOS: Support for macOS has been dropped for the time being due to difficulties incompiling this package with
-fopenmp
since Sage version 8.8. Compilingthe entirety of Sage with GCC support might make this work, but this was nottested. See issue #3.Memory leaks: The underlying FGb program leaks memory, which can be a problemwhen computing many Gröbner bases in a single long-lived process. In thiscase, it might be better to split the computation into several processes oruse a different Gröbner basis algorithm available in Sage.
Documentation for fgb_sage
¶
This interface has two main functions:
groebner_basis() - compute a Groebner basis
eliminate() - compute an elimination ideal
- fgb_sage.groebner_basis(polys, **kwds)¶
Compute a Groebner basis of an ideal using FGb.
Supported term orders of the underlying polynomial ring are
degrevlex
orders, as well as block orders with twodegrevlex
blocks (eliminationorders). Supported coefficient fields are QQ and finite prime fields ofsize up toMAX_PRIME
= 65521 < 2^16.INPUT:
polys
– an ideal or a polynomial sequence, the generators of anideal.threads
– integer (default: 1); only seems to work in positivecharacteristic.force_elim
– integer (default: 0); ifforce_elim=1
, then thecomputation will return only the result of the elimination, if anelimination order is used.verbosity
– integer (default: 1), display progress info.matrix_bound
– integer (default: 500000); this is is the maximalsize of the matrices generated by F4. This value can be increasedaccording to available memory.max_base
– integer (default: 100000); maximum number ofpolynomials in output.
OUTPUT: the Groebner basis.
EXAMPLES:
This example computes a Groebner basis with respect to an eliminationorder:
sage: R = PolynomialRing(QQ, 5, 'x', order="degrevlex(2),degrevlex(3)")sage: I = sage.rings.ideal.Cyclic(R)sage: import fgb_sage # optional fgb_sagesage: gb = fgb_sage.groebner_basis(I) # optional fgb_sage, random...sage: gb.is_groebner(), gb.ideal() == I # optional fgb_sage(True, True)
Over finite fields, parallel computations are supported:
sage: R = PolynomialRing(GF(fgb_sage.MAX_PRIME), 4, 'x') # optional fgb_sagesage: I = sage.rings.ideal.Katsura(R) # optional fgb_sagesage: gb = fgb_sage.groebner_basis(I, threads=2, verbosity=0) # optional fgb_sage, randomsage: gb.is_groebner(), gb.ideal() == I # optional fgb_sage(True, True)
If fgb_sage.groebner_basis() is called with an ideal, the result iscached on
MPolynomialIdeal.groebner_basis()
so that othercomputations on the ideal do not need to recompute a Groebner basis:sage: I.groebner_basis.is_in_cache() # optional fgb_sageTruesage: I.groebner_basis() is gb # optional fgb_sageTrue
However, note that
gb.ideal()
returns a new ideal and, thus, does nothave a Groebner basis in cache:sage: gb.ideal().groebner_basis.is_in_cache() # optional fgb_sageFalse
TESTS:
Check that the result is not cached if it is only a basis of anelimination ideal:
sage: R = PolynomialRing(QQ, 5, 'x', order="degrevlex(2),degrevlex(3)")sage: I = sage.rings.ideal.Cyclic(R)sage: import fgb_sagesage: gb = fgb_sage.groebner_basis(I, force_elim=1) # optional fgb_sage, random...sage: I.groebner_basis.is_in_cache() # optional fgb_sageFalse
- fgb_sage.eliminate(polys, elim_variables, **kwds)¶
Compute a Groebner basis with respect to an elimination order defined bythe given variables.
INPUT:
polys
– an ideal or a polynomial sequence.elim_variables
– the variables to eliminate.force_elim
– integer (default: 1).kwds
– same as in groebner_basis().
OUTPUT: a Groebner basis of the elimination ideal.
EXAMPLES:
sage: R.<x,y,t,s,z> = PolynomialRing(QQ,5)sage: I = R * [x-t,y-t^2,z-t^3,s-x+y^3]sage: import fgb_sage # optional - fgb_sagesage: gb = fgb_sage.eliminate(I, [t,s], verbosity=0) # optional - fgb_sage, randomopen simulationsage: gb # optional - fgb_sage[x^2 - y, x*y - z, y^2 - x*z]sage: gb.is_groebner() # optional - fgb_sageTruesage: gb.ideal() == I.elimination_ideal([t,s]) # optional - fgb_sageTrue
Note
In some cases, this function fails to set the correct eliminationorder, see trac ticket #24981. This was fixed in Sage 8.7.
- fgb_sage.internal_version()¶
Get the internal version of FGb.
OUTPUT: a dictionary containing the versions of FGb for
FGb_int
andFGb_modp
, characteristic 0 and positive characteristic, respectively.These versions differ between Linux and macOS.EXAMPLES:
sage: import fgb_sage # optional - fgb_sagesage: fgb_sage.internal_version() # optional - fgb_sage{'FGb_int': ..., 'FGb_modp': ...}
License¶
MIT for this package fgb_sage. However, note that FGb is licensed foracademic use only.
Links¶
fgb_sage
on GitHubdocumentation for Gröbner bases in Sage