Interface to 4ti2#
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)[source]#
Bases:
object
An interface to the program 4ti2.
Each 4ti2 command is exposed as a method of this class.
- call(command, project, verbose, options=True)[source]#
Run the 4ti2 program
command
on the project namedproject
in the directorydirectory()
.INPUT:
command
– The 4ti2 program to run.project
– The file name of the project to run on.verbose
– Display the output of 4ti2 ifTrue
.options
– A list of strings to pass to the program.
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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.write_matrix([[Integer(6),Integer(10),Integer(15)]], "test_file") >>> four_ti_2.call("groebner", "test_file", False) # optional - 4ti2 >>> four_ti_2.read_matrix("test_file.gro") # optional - 4ti2 [-5 0 2] [-5 3 0]
- circuits(mat=None, project=None)[source]#
Run the 4ti2 program
circuits
on the parameters.See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.circuits([Integer(1),Integer(2),Integer(3)]) # optional - 4ti2 [ 0 3 -2] [ 2 -1 0] [ 3 0 -1]
- directory()[source]#
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/'
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import FourTi2 >>> f = FourTi2("/tmp/") >>> f.directory() '/tmp/'
- graver(mat=None, lat=None, project=None)[source]#
Run the 4ti2 program
graver
on the parameters.See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.graver([Integer(1),Integer(2),Integer(3)]) # optional - 4ti2 [ 2 -1 0] [ 3 0 -1] [ 1 1 -1] [ 1 -2 1] [ 0 3 -2] >>> four_ti_2.graver(lat=[[Integer(1),Integer(2),Integer(3)],[Integer(1),Integer(1),Integer(1)]]) # optional - 4ti2 [ 1 0 -1] [ 0 1 2] [ 1 1 1] [ 2 1 0]
- groebner(mat=None, lat=None, project=None)[source]#
Run the 4ti2 program
groebner
on the parameters.This computes a toric Groebner basis of a matrix.
See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> A = [Integer(6),Integer(10),Integer(15)] >>> four_ti_2.groebner(A) # optional - 4ti2 [-5 0 2] [-5 3 0] >>> four_ti_2.groebner(lat=[[Integer(1),Integer(2),Integer(3)],[Integer(1),Integer(1),Integer(1)]]) # optional - 4ti2 [-1 0 1] [ 2 1 0]
- hilbert(mat=None, lat=None, project=None)[source]#
Run the 4ti2 program
hilbert
on the parameters.See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> 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] >>> four_ti_2.hilbert(lat=[[Integer(1),Integer(2),Integer(3)],[Integer(1),Integer(1),Integer(1)]]) # optional - 4ti2 [2 1 0] [0 1 2] [1 1 1]
- minimize(mat=None, lat=None)[source]#
Run the 4ti2 program
minimize
on the parameters.See 4ti2 website 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.
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.minimize() # optional - 4ti2 Traceback (most recent call last): ... NotImplementedError: 4ti2 command 'minimize' not implemented in Sage.
- ppi(n)[source]#
Run the 4ti2 program
ppi
on the parameters.See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.ppi(Integer(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)[source]#
Run the 4ti2 program
qsolve
on the parameters.See 4ti2 website 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]]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> A = [[Integer(1),Integer(1),Integer(1)],[Integer(1),Integer(2),Integer(3)]] >>> four_ti_2.qsolve(A) # optional - 4ti2 [[], [ 1 -2 1]]
- rays(mat=None, project=None)[source]#
Run the 4ti2 program
rays
on the parameters.See 4ti2 website 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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> 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)[source]#
Read a matrix in 4ti2 format from the file
filename
in directorydirectory()
.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]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.write_matrix([[Integer(1),Integer(2),Integer(3)],[Integer(3),Integer(4),Integer(6)]], "test_file") >>> four_ti_2.read_matrix("test_file") [1 2 3] [3 4 6]
- temp_project()[source]#
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_...'
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.temp_project() 'project_...'
- write_array(array, nrows, ncols, filename)[source]#
Write the integer matrix
array
to the filefilename
in directorydirectory()
in 4ti2 format.The matrix must have
nrows
rows andncols
columns. It can be provided as a list of lists.INPUT:
array
– A matrix of integers. Can be represented as a list of lists.nrows
– The number of rows inarray
.ncols
– The number of columns inarray
.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")
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.write_array([[Integer(1),Integer(2),Integer(3)],[Integer(3),Integer(4),Integer(5)]], Integer(2), Integer(3), "test_file")
- write_matrix(mat, filename)[source]#
Write the matrix
mat
to the filefilename
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")
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.write_matrix([[Integer(1),Integer(2)],[Integer(3),Integer(4)]], "test_file")
- write_single_row(row, filename)[source]#
Write the list
row
to the filefilename
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")
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> four_ti_2.write_single_row([Integer(1),Integer(2),Integer(3),Integer(4)], "test_file")
- zsolve(mat=None, rel=None, rhs=None, sign=None, lat=None, project=None)[source]#
Run the 4ti2 program
zsolve
on the parameters.See 4ti2 website 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] ]
>>> from sage.all import * >>> from sage.interfaces.four_ti_2 import four_ti_2 >>> A = [[Integer(1),Integer(1),Integer(1)],[Integer(1),Integer(2),Integer(3)]] >>> rel = ['<', '<'] >>> rhs = [Integer(2), Integer(3)] >>> sign = [Integer(1),Integer(0),Integer(1)] >>> 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], [] ] >>> four_ti_2.zsolve(lat=[[Integer(1),Integer(2),Integer(3)],[Integer(1),Integer(1),Integer(1)]]) # optional - 4ti2 [ [1 2 3] [0 0 0], [], [1 1 1] ]