Interface to 4ti2

http://www.4ti2.de

You must have the 4ti2 Sage package installed on your computer for this interface to work.

Use sage -i 4ti2 to install the package.

AUTHORS:

  • Mike Hansen (2009): Initial version.

  • Bjarke Hammersholt Roune (2009-06-26): Added Groebner, made code usable as part of the Sage library and added documentation and some doctests.

  • Marshall Hampton (2011): Minor fixes to documentation.

class sage.interfaces.four_ti_2.FourTi2(directory=None)

Bases: object

This object defines an interface to the program 4ti2. Each command 4ti2 has is exposed as one method.

call(command, project, verbose=True)

Run the 4ti2 program command on the project named project in the directory directory().

INPUT:

  • command – The 4ti2 program to run.

  • project – The file name of the project to run on.

  • verbose – Display the output of 4ti2 if True.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.write_matrix([[6,10,15]], "test_file")
sage: four_ti_2.call("groebner", "test_file", False) # optional - 4ti2
sage: four_ti_2.read_matrix("test_file.gro") # optional - 4ti2
[-5  0  2]
[-5  3  0]
circuits(mat=None, project=None)

Run the 4ti2 program circuits on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.circuits([1,2,3]) # optional - 4ti2
[ 0  3 -2]
[ 2 -1  0]
[ 3  0 -1]
directory()

Return the directory where the input files for 4ti2 are written by Sage and where 4ti2 is run.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import FourTi2
sage: f = FourTi2("/tmp/")
sage: f.directory()
'/tmp/'
graver(mat=None, lat=None, project=None)

Run the 4ti2 program graver on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.graver([1,2,3]) # optional - 4ti2
[ 2 -1  0]
[ 3  0 -1]
[ 1  1 -1]
[ 1 -2  1]
[ 0  3 -2]
sage: four_ti_2.graver(lat=[[1,2,3],[1,1,1]])  # optional - 4ti2
[ 1  0 -1]
[ 0  1  2]
[ 1  1  1]
[ 2  1  0]
groebner(mat=None, lat=None, project=None)

Run the 4ti2 program groebner on the parameters. This computes a Toric Groebner basis of a matrix. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: A = [6,10,15]
sage: four_ti_2.groebner(A) # optional - 4ti2
[-5  0  2]
[-5  3  0]
sage: four_ti_2.groebner(lat=[[1,2,3],[1,1,1]]) # optional - 4ti2
[-1  0  1]
[ 2  1  0]
hilbert(mat=None, lat=None, project=None)

Run the 4ti2 program hilbert on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.hilbert(four_ti_2._magic3x3()) # optional - 4ti2
[2 0 1 0 1 2 1 2 0]
[1 0 2 2 1 0 0 2 1]
[0 2 1 2 1 0 1 0 2]
[1 2 0 0 1 2 2 0 1]
[1 1 1 1 1 1 1 1 1]
sage: four_ti_2.hilbert(lat=[[1,2,3],[1,1,1]])   # optional - 4ti2
[2 1 0]
[0 1 2]
[1 1 1]
minimize(mat=None, lat=None)

Run the 4ti2 program minimize on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.minimize() # optional - 4ti2
Traceback (most recent call last):
...
NotImplementedError: 4ti2 command 'minimize' not implemented in Sage.
ppi(n)

Run the 4ti2 program ppi on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.ppi(3) # optional - 4ti2
[-2  1  0]
[ 0 -3  2]
[-1 -1  1]
[-3  0  1]
[ 1 -2  1]
qsolve(mat=None, rel=None, sign=None, project=None)

Run the 4ti2 program qsolve on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: A = [[1,1,1],[1,2,3]]
sage: four_ti_2.qsolve(A) # optional - 4ti2
[[], [ 1 -2  1]]
rays(mat=None, project=None)

Run the 4ti2 program rays on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.rays(four_ti_2._magic3x3()) # optional - 4ti2
[0 2 1 2 1 0 1 0 2]
[1 0 2 2 1 0 0 2 1]
[1 2 0 0 1 2 2 0 1]
[2 0 1 0 1 2 1 2 0]
read_matrix(filename)

Read a matrix in 4ti2 format from the file filename in directory directory().

INPUT:

  • filename – The name of the file to read from.

OUTPUT:

The data from the file as a matrix over \(\ZZ\).

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.write_matrix([[1,2,3],[3,4,6]], "test_file")
sage: four_ti_2.read_matrix("test_file")
[1 2 3]
[3 4 6]
temp_project()

Return an input project file name that has not been used yet.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.temp_project()
'project_...'
write_array(array, nrows, ncols, filename)

Write the matrix array of integers (can be represented as a list of lists) to the file filename in directory directory() in 4ti2 format. The matrix must have nrows rows and ncols columns.

INPUT:

  • array – A matrix of integers. Can be represented as a list of lists.

  • nrows – The number of rows in array.

  • ncols – The number of columns in array.

  • file – A file name not including a path.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.write_array([[1,2,3],[3,4,5]], 2, 3, "test_file")
write_matrix(mat, filename)

Write the matrix mat to the file filename in 4ti2 format.

INPUT:

  • mat – A matrix of integers or something that can be converted to that.

  • filename – A file name not including a path.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.write_matrix([[1,2],[3,4]], "test_file")
write_single_row(row, filename)

Write the list row to the file filename in 4ti2 format as a matrix with one row.

INPUT:

  • row – A list of integers.

  • filename – A file name not including a path.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: four_ti_2.write_single_row([1,2,3,4], "test_file")
zsolve(mat=None, rel=None, rhs=None, sign=None, lat=None, project=None)

Run the 4ti2 program zsolve on the parameters. See http://www.4ti2.de/ for details.

EXAMPLES:

sage: from sage.interfaces.four_ti_2 import four_ti_2
sage: A = [[1,1,1],[1,2,3]]
sage: rel = ['<', '<']
sage: rhs = [2, 3]
sage: sign = [1,0,1]
sage: four_ti_2.zsolve(A, rel, rhs, sign) # optional - 4ti2
[
         [ 1 -1  0]
         [ 0 -1  0]
[0 0 1]  [ 0 -3  2]
[1 1 0]  [ 1 -2  1]
[0 1 0], [ 0 -2  1], []
]
sage: four_ti_2.zsolve(lat=[[1,2,3],[1,1,1]]) # optional - 4ti2
[
             [1 2 3]
[0 0 0], [], [1 1 1]
]