This is an old revision of the document!
application common
This artificial application gathers functionality shared by many “real” applications. While most users can probably do without looking into this, you may find some useful functions here.
Objects
- PermBase:
Base class for permutations of `big' objects - Visual::Container:
The common base class of all visual objects composed of several simpler objects. Instances of such classes can carry default decoration attributes applied to all contained objects. - Visual::Object:
The common base class of all visualization artifacts produced by various user methods like VISUAL, VISUAL_GRAPH, SCHLEGEL, etc. Visual objects can be passed to functions explicitly calling visualization software like jreality() or povray().
Functions
db_print_searchable_fields
- UNDOCUMENTED
db_get_type_information
- 20171204: Made type_information_key undef by default to allow users to pass the key “default” explicitly, otherwise default keys have the form “default.<collection>” as there may be more than one collection in the db with a default type information entry
Arithmetic
These are functions that perform arithmetic computations.
fac( Int n)
- Parameters:
- Int
n
: >=0
- Returns: Integer
- Computes the factorial n! = n·(n-1)·(n-2)·…·2·1.
is_zero(SCALAR s)
- Parameters:
- SCALAR
s
:
- Returns: Bool
- Compare with the zero (0) value of the corresponding data type.
- Parameters:
- Returns: Div
- Compute the quotient and remainder of a and b in one operation.
- Example:
> $d = div(10,3); > print $d->quot; 3
> print $d->rem; 1
isinf(SCALAR a)
- Parameters:
- SCALAR
a
:
- Returns: Int
- Check whether the given number has an infinite value. Return -1/+1 for infinity and 0 for all finite values.
- Example:
> print isinf('inf'); 1
> print isinf(23); 0
div_exact( Integer a, Integer b)
- Parameters:
- Returns: Integer
- Computes the ratio of two given integral numbers under the assumption that the dividend is a multiple of the divisor.
- Example:
> print div_exact(10,5); 2
ceil( Rational a)
- Parameters:
- Rational
a
:
- Returns: Rational
- The ceiling function. Returns the smallest integral number not smaller than a.
set_var_names( String names …)
- Parameters:
- String
names …
: variable names; may also be bundled in an array
an empty list resets to the default naming scheme
- Set the list of variable names used for pretty printing and string parsing of the given polynomial class
When the number of variables in a polynomial is greater than the size of the name list, the excess variable names
are produced from a template “${last_var_name}_{EXCESS}”, where EXCESS starts at 0 for the variable corresponding
to the last name in the list. If the last name already has a form “{Name}_{Number}”, the following variables are enumerated
starting from that Number plus 1.
The default naming scheme consists of a single letter “x”, “y”, “z”, “u”, “v”, or “w” chosen according to the nesting depth
of polynomial types in the coefficient type. That is, variables of simple polynomials (those with pure numerical coefficients)
are named x_0, x_1, …, variables of polynomials with simple polynomial coefficients are named y_0, y_1, etc.
monomials<Coefficient, Exponent>( Int n)
- Template Parameters:
Coefficient
: The polynomial coefficient type. Rational by default.
Exponent
: The exponent type. Int by default.
- Parameters:
- Int
n
: The number of variables - Returns: UniPolynomial < monomials
- Create degree one monomials of the desired polynomial type.
isfinite(SCALAR a)
- Parameters:
- SCALAR
a
:
- Returns: Bool
- Check whether the given number has a finite value.
- Example:
> print isfinite('inf'); false
> print isfinite(23); true
local_var_names( String names …)
- Parameters:
- Set the list of variable names for given polynomial class temporarily.
The existing name list or the default scheme is restored at the end of the current user cycle,
similarly to prefer_now.
numerator
get_var_names
- Get the current list of variable names used for pretty printing and string parsing of the given polynomial class
sum_of_square_roots_naive( Array < Rational > input_array)
- Parameters:
- Make a naive attempt to sum the square roots of the entries of the input array.
- Example:
To obtain sqrt{3/4} + sqrt{245}, type
> print sum_of_square_roots_naive(new Array<Rational>([3/4, 245])); {(3 1/2) (5 7)}
This output represents sqrt{3}/2 + 7 sqrt{5}.
If you are not satisfied with the result, please use a symbolic algebra package.
gcd
denominator
- Parameters:
- Returns: ExtGCD
- Compute the greatest common divisor of two numbers (a,b) and accompanying co-factors.
- Example:
> $GCD = ext_gcd(15,6);
The GCD of the numbers can then be accessed like this:
> print $GCD->g; 3
The ExtGCD type also stores the Bezout coefficients (thus integers p and q such that g=a*p+b*q)…
> print $GCD->p; 1
print $GCD->q; \\ \\ ...and the quotients k1 of a and k2 of b by g. \\ <code> > print $GCD→k1;
5
</code>
> print $GCD->k2; 2
floor( Rational a)
- Parameters:
- Rational
a
:
- Returns: Rational
- The floor function. Returns the smallest integral number not larger than a.
- Example:
> print floor(1.8); 1
is_one(SCALAR s)
- Parameters:
- SCALAR
s
:
- Returns: Bool
- Compare with the one (1) value of the corresponding data type.
lcm
Combinatorics
This category contains combinatorial functions.
permutation_order( Array < Int > p)
- Parameters:
- Returns: Int
- Returns the order of a permutation
- Example:
> print permutation_order(new Array<Int>([1,2,0,4,3])); 6
- Parameters:
- Returns: Int
- Computes the binomial coefficient n choose k.
Negative values of n (and k) are supported. - Example:
Print 6 choose 4 like this:
> print binomial(6,4); 15
permutation_sign( Array < Int > p)
- Parameters:
- Returns: Int
- Returns the sign of the permutation given by p.
- Example:
> print permutation_sign([1,0,3,2]); 1
permutation_matrix<Scalar>( Array < Int > p)
- Template Parameters:
Scalar
: default: Int
- Parameters:
- Returns: Matrix < permutation
- Returns the permutation matrix of the permutation given by p.
- Example:
The following prints the permutation matrix in sparse representation.
> print permutation_matrix([1,0,3,2]); (4) (1 1) (4) (0 1) (4) (3 1) (4) (2 1)
find_permutation( Array a, Array b)
- Parameters:
- Returns the permutation that maps a to b.
- Example:
> $p = find_permutation([1,8,3,4],[3,8,4,1]); > print $p; 2 1 3 0
all_permutations( Int n)
- Parameters:
- Int
n
:
- Returns: ARRAY
- Returns a list of all permutations of the set {0…n-1} as a perl-array
- Example:
To store the result in the perl array @a, type this:
> @a = all_permutations(3);
The array contains pointers to arrays. To access the 0-th pointer, do this:
> $a0 = $a[0];
To print the 0-th array itself, you have to dereference it as follows:
> print @{ $a0 }; 012
You can loop through @a using foreach. The print statement produces the string obtained by dereferencing
the current entry concatenated with the string “ ”.
> foreach( @a ){ > print @{ $_ }, " "; > } 012 102 201 021 120 210
n_fixed_points( Array < Int > p)
- Parameters:
- Returns: Int
- Returns the number of fixed points of the permutation given by p.
- Example:
> print n_fixed_points([1,0,2,4,3]); 1
are_permuted( Array a, Array b)
- Parameters:
- Returns: Bool
- Determine whether two arrays a and b are permuted copies of each other.
- Example:
> print are_permuted([1,8,3,4],[3,8,4,1]); true
permutation_cycles( Array < Int > p)
- Parameters:
- Returns: ARRAY
- Returns the cycles of a permutation given by p.
- Example:
> print permutation_cycles([1,0,3,2]); {0 1}{2 3}
permutation_cycle_lengths( Array < Int > p)
- Parameters:
- Returns the sorted cycle lengths of a permutation
- Example:
> print permutation_cycle_lengths(new Array<Int>([1,2,0,4,3])); 2 3
Data Conversion
This contains functions for data conversions and type casts.
rows
- Parameters:
- Example:
> $v = new Vector(23,42,666); > $M = repeat_col($v,3); > print $M; 23 23 23 42 42 42 666 666 666
cast<Target>( Core::Object object)
- Template Parameters:
Target
: the desired new type
- Parameters:
- Core::Object
object
: to be modified - Returns: Core::Object
- Change the type of the polymake object to one of its base types
(aka ancestor in the inheritance hierarchy).
The object loses all properties that are unknown in the target type.
concat_rows( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Vector
- Concatenates the rows of A.
- Example:
Make a vector out of the rows of the vertex matrix of a cube:
> $v = concat_rows(polytope::cube(2)->VERTICES); > print $v; 1 -1 -1 1 1 -1 1 -1 1 1 1 1
- Example:
For a sparse matrix, the resulting vector is sparse, too.
> $vs = concat_rows(unit_matrix(3)); > print $vs; (9) (0 1) (4 1) (8 1)
vector2col( Vector v)
- Parameters:
- Vector
v
:
- Returns: Matrix
- Example:
This converts a vector into a column and prints it and its type:
> $v = new Vector([1,2,3,4]); > $V = vector2col($v); > print $V; 1 2 3 4
> print $V->type->full_name; Matrix<Rational, NonSymmetric>
toTropicalPolynomial( String s, String vars)
- Parameters:
- This converts a string into a tropical polynomial. The syntax for the string is as follows:
It is of the form “min(…)” or “max(…)” or “min{…}” or “max{…}”, where …
is a comma-separated list of sums of the form “a + bx + c + dy + …”, where a,c are
rational numbers, b,d are Ints and x,y are variables.
Such a sum can contain several such terms for the same variable and they need not be in any order.
Any text that starts with a letter and does not contain any of +-*,(){} or whitespace can be a variable.
A term in a sum can be of the form “3x”, “3*x”, but “x3”will be interpreted as 1 * “x3”.
Coefficients should not contain letters and there is no evaluation of arithmetic, i.e. “(2+4)*x” does
not work (though “2x+4x” would be fine).
In fact, further brackets should only be used (but are not necessary!) for single coefficienst,
e.g. “(-3)*x”.
Warning: The parser will remove all brackets before parsing the individual sums.
If no further arguments are given, the function will take the number of occuring variables
as total number of variables and create a ring for the result. The variables will be sorted alphabetically.
toMatrix<Scalar>( IncidenceMatrix A)
- Template Parameters:
Scalar
:
- Parameters:
- IncidenceMatrix
A
:
- Returns: SparseMatrix < toMatrix
- Convert an IncidenceMatrix to a SparseMatrix.
- Example:
> $M = toMatrix<Int>(polytope::cube(2)->VERTICES_IN_FACETS); > print $M->type->full_name; SparseMatrix<Int, NonSymmetric>
indices( SparseVector v)
- Parameters:
- SparseVector
v
:
- Get the positions of non-zero entries of a sparse vector.
- Example:
> $v = new SparseVector(0,1,1,0,0,0,2,0,3); > print indices($v); {1 2 6 8}
- Parameters:
- Example:
> $v = new Vector(23,42,666); > $M = repeat_row($v,3); > print $M; 23 42 666 23 42 666 23 42 666
convert_to
support( Vector v)
- Parameters:
- Vector
v
:
- Get the positions of non-zero entries of a vector.
- Example:
> print support(new Vector(0,23,0,0,23,0,23,0,0,23)); {1 4 6 9}
toVector<Scalar>( Set S, Int d)
- Template Parameters:
Scalar
: type of apparent 1's
- Parameters:
- Set
S
: - Int
d
: dimension of the result - Returns: SparseVector < toVector
- Create a sparse vector having 1's at positions contained in the given set
vector2row( Vector v)
- Parameters:
- Vector
v
:
- Returns: Matrix
- Example:
This converts a vector into a row and prints it and its type:
> $v = new Vector([1,2,3,4]); > $V = vector2row($v); > print $V; 1 2 3 4
> print $V->type->full_name; Matrix<Rational, NonSymmetric>
cols
index_matrix( SparseMatrix m)
- Parameters:
- SparseMatrix
m
:
- Returns: IncidenceMatrix
- Get the positions of non-zero entries of a sparse matrix.
- Example:
> $S = new SparseMatrix([1,2,0,0,0,0],[0,0,5,0,0,32]); > print index_matrix($S); {0 1} {2 5}
dense
lex_ordered( FacetList f)
- Parameters:
- FacetList
f
:
- Visit the facets of f sorted lexicographically.
- Example:
> $f = new FacetList(polytope::cube(2)->VERTICES_IN_FACETS); > print lex_ordered($f); {{0 1} {0 2} {1 3} {2 3}}
Database
Here you can find the functions to access the polymake database.
db_write_db_info( String db)
- Parameters:
- String
db
: name of the database the description applies to
- Add a db documentation.
You need write access for this.
db_ids(HASH query)
- Parameters:
- HASH
query
:
- Returns the IDs of all objects in the database db in collection that match the query. This is only recommended for a reasonably small number of matching objects. If you expect many such objects you should instead construct a DBCursor.
db_query(HASH query)
- Parameters:
- HASH
query
:
- Returns: Array < Core::Object >
- Returns all objects in the database db in collection that match the query. This is only recommended for a reasonably small number of matching objects. If you expect many such objects you should instead use a database cursor.
db_metadata( Core::Object p)
- Parameters:
- Core::Object
p
: the polyDB object
- Returns: HASH
- Retrieve the metadata of an object
db_get_list_col_for_db
- Returns: Array
- Returns a list of available collections in a database.
db_info
- Print information about available databases and collections.
db_searchable_fields( String db, String collection)
- Parameters:
- Return the list of property names that can be searched in the database for a given database db,
collection col and optional template key.
db_get_list_db_col
- Returns: Array
- Returns a list of available databases and collections (in the form db.collection).
db_get_list_db
- Returns: Array
- Returns a list of available databases.
db_count(HASH query)
- Parameters:
- HASH
query
:
- Returns: Int
- Returns the number of objects in the database db in collection that match the query.
db_cursor(HASH query)
- Parameters:
- HASH
query
: database query
- Returns: DBCursor
- Returns a cursor on the entries for the database db in collection that match the query.
db_print_metadata( Core::Object p)
- Parameters:
- Core::Object
p
: the polyDB object
- print the metadata of an object
db_write_collection_info
- Add documentation for a collection
You need write access for this.
Database Admin
These are administrative functions. You need admin access to the database for these. This category also contains functions that I want to hide from the public because they are not yet completely presentable.
db_set_type_information
- Set or update type (and template) information for collection col in the database db.
Note that you need write access to the type database for this.
Database Write Access
These are the functions to insert and update objects. You need write access to the database for these.
db_insert( Core::Object obj)
- Parameters:
- Core::Object
obj
:
- Returns: String
- Adds an object obj to the collection col in the database db.
Note that you need write access to the database for this.
db_remove( String id)
- Parameters:
- String
id
:
- Returns: String
- Removes the object with a given id from the collection col in the database db.
Note that you need write access to the database for this.
Formatting
Functions for pretty printing, labels or latex output of polymake types.
latex( Matrix data, Array < String > elem_labels)
- Parameters:
- Matrix
data
: to be printed - Array < String >
elem_labels
: optional labels for elements;
if data is an IncidenceMatrix, playground, or similar, each element will be replaced by its label.
- Returns: String
- LaTeX output of a matrix.
numbered( Vector data)
- Parameters:
- Vector
data
: to be printed
- Returns: String
- Equivalent to labeled with omitted elem_labels argument.
- Example:
> $data = new Vector(23,42,666); > print numbered($data); 0:23 1:42 2:666
rows_numbered( Matrix data)
- Parameters:
- Matrix
data
: to be printed
- Equivalent to rows_labeled with omitted row_labels argument.
Formerly called “numbered”. - Example:
> print rows_numbered(polytope::cube(2)->VERTICES); 0:1 -1 -1 1:1 1 -1 2:1 -1 1 3:1 1 1
labeled( Vector data, Array < String > elem_labels)
- Parameters:
- Vector
data
: to be printed
- Returns: String
- Prepares a vector for printing, prepends each element with a label and a colon.
- Example:
> $v = new Vector(0,1,2); > print labeled($v,["zeroth","first","second"]); zeroth:0 first:1 second:2
rows_labeled
print_constraints( Matrix < print M)
- Parameters:
- Write the rows of a matrix M as inequalities (equations=0)
or equations (equations=1) in a readable way.
It is possible to specify labels for the coordinates via
an optional array coord_labels. - Example:
> $M = new Matrix([1,2,3],[4,5,23]); > print_constraints($M,equations=>1); 0: 2 x1 + 3 x2 = -1 1: 5 x1 + 23 x2 = -4
Graph Operations
Operations on graphs.
node_edge_incidences<Coord>( Graph graph)
- Template Parameters:
Coord
: coordinate type for the resulting matrix, default: Int
- Parameters:
- Graph
graph
: - Returns: SparseMatrix < node
- Returns the node-edge incidence matrix of a graph.
- Example:
> print node_edge_incidences(graph::cycle_graph(5)->ADJACENCY); (5) (0 1) (3 1) (5) (0 1) (1 1) (5) (1 1) (2 1) (5) (2 1) (4 1) (5) (3 1) (4 1)
adjacency_matrix( Graph graph)
- Parameters:
- Graph
graph
:
- Returns: IncidenceMatrix
- Returns the adjacency matrix of graph nodes.
For a normal graph, it will be a kind of IncidenceMatrix,
for multigraph, it will be a playground, with entries encoding the number of parallel edges between two nodes.
induced_subgraph( Graph graph, Set set)
- Parameters:
- Returns: Graph
- Creates an induced subgraph for the given subset of nodes.
- Example:
> $g = new props::Graph(graph::cycle_graph(5)->ADJACENCY); > $s1 = new Set(1,2,3); > print induced_subgraph($g,$s1); (5) (1 {2}) (2 {1 3}) (3 {2})
edges( Graph graph)
- Parameters:
- Graph
graph
:
- Returns: EdgeList
- Returns the sequence of all edges of a graph.
The edges will appear in ascending order of their tail and head nodes.
In the Undirected case, the edges will appear once, ordered by the larger index of their incident nodes.
nodes( Graph graph)
- Parameters:
- Graph
graph
:
- Returns the sequence of all valid nodes of a graph.
- Example:
> print nodes(graph::cycle_graph(5)->ADJACENCY); {0 1 2 3 4}
Lattice Tools
Functions for lattice related computations.
eliminate_denominators_entire( Matrix v)
- Parameters:
- Matrix
v
:
- Scales entire matrix with the least common multiple of the denominators of its coordinates.
- Example:
> $M = new Matrix([1/2,1/3],[1/5,7],[1/4,4/3]); > $Me = eliminate_denominators_entire($M); > print $Me; 30 20 12 420 15 80
eliminate_denominators( Vector v)
- Parameters:
- Vector
v
:
- Scale a vector with the least common multiple of the denominators of its coordinates.
- Example:
> $v = new Vector(1/2,1/3,1/4,1/5); > $ve = eliminate_denominators($v); > print $ve; 30 20 15 12
eliminate_denominators_entire_affine( Matrix v)
- Parameters:
- Matrix
v
:
- Scales entire matrix with the least common multiple of the denominators of its coordinates (ignore first column).
- Example:
> $M = new Matrix([1,1/2,1/3],[1,1/5,7],[1,1/4,4/3]); > $Me = eliminate_denominators_entire_affine($M); > print $Me; 1 30 20 1 12 420 1 15 80
eliminate_denominators_in_rows( Matrix M)
- Parameters:
- Matrix
M
:
- Scale a matrix row-wise with the least common multiple of the denominators of its coordinates.
- Example:
> $M = new Matrix([1/2,1/3],[1/5,7],[1/4,4/3]); > $Me = eliminate_denominators_in_rows($M); > print $Me; 3 2 1 35 3 16
primitive
primitive_affine
is_integral
Linear Algebra
These functions are for algebraic computations and constructions of special matrices.
null_space
unit_vector<Element>( Int d, Int pos)
- Template Parameters:
Element
: default: Rational
- Parameters:
- Int
d
: the dimension of the vector - Int
pos
: the position of the 1 - Returns: SparseVector < unit
- Creates a SparseVector of given length d with a one entry at position pos and zeroes elsewhere.
- Example:
The following stores a vector of dimension 5 with a single 1 (as a Int) at position 2:
> $v = unit_vector<Int>(5,2); > print $v->type->full_name; SparseVector<Int>
- Example:
The following concatenates a unit vector of dimension 3 with a 1 at position 2 and a
unit vector of dimension 2 with a 1 at position 1:
> $v = unit_vector(3,2) | unit_vector(2,1); > print $v; (5) (2 1) (4 1)
null_space_integer( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: SparseMatrix
- Computes the lattice null space of the integer matrix A.
inv( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Matrix
- Computes the inverse A-1 of an invertible matrix A using Gauss elimination.
- Example:
We save the inverse of a small matrix M in the variable $iM: \\ <code> > $M = new Matrix([1,2],[3,4]);
> $iM = inv($M);
</code>
To print the result, type this:
> print $iM; -2 1 3/2 -1/2
As we can see, that is in fact the inverse of M.
> print $M * $iM; 1 0 0 1
rank( Matrix A)
det( Matrix < A)
- Parameters:
- Matrix <
A
:
- Returns: SCALAR
- Computes the determinant of a matrix using Gaussian elimination.
If Scalar is not of field type, but element of a Euclidean ring R,
type upgrade to element of the quotient field is performed.
The result is recast as a Scalar, which is possible without roundoff
since the so-computed determinant is an element of the (embedded) ring R. - Example:
> print det(unit_matrix(3)); 1
- Example:
> $p = new UniPolynomial<Rational,Int>("x2+3x"); > $M = new Matrix<UniPolynomial<Rational,Int>>([[$p, $p+1],[$p+1,$p]]); > print det($M); -2*x^2 -6*x - 1
qr_decomp( Matrix < Float > M)
- Parameters:
- QR decomposition of a Matrix M with rows > cols
- Example:
> $M = new Matrix<Float>([23,4],[6,42]); > $qr = qr_decomp($M); > print $qr->first; 0.9676172724 0.2524218971 0.2524218971 -0.9676172724
> print $qr->second; 23.76972865 14.47218877 0 -39.63023785
> print $qr->first * $qr->second ; 23 4 6 42
lin_solve( Matrix A, Vector b)
- Parameters:
- Returns: Vector
- Computes the vector x that solves the system Ax = b
- Example:
from the Wikipedia:
> $A = new Matrix([3,2,-1],[2,-2,4],[-1,1/2,-1]); > $b = new Vector(1,-2,0); > print lin_solve($A,$b); 1 -2 -2
zero_matrix<Element>( Int i, Int j)
- Template Parameters:
Element
: default: Rational
- Parameters:
- Int
i
: number of rows - Int
j
: number of columns - Returns: SparseMatrix < zero
- Creates a zero matrix of given dimensions
- Example:
The following stores a 2×3 matrix with 0 as entries (from type Rational) in a variable and prints it:
> $M = zero_matrix(2,3); > print $M; 0 0 0 0 0 0
- Example:
The following stores a 2×3 matrix with 0 as entries from type Int in a variable and prints its type:
> $M = zero_matrix<Int>(2,3); > print $M->type->full_name; Matrix<Int, NonSymmetric>
basis_affine( Matrix A)
smith_normal_form( Matrix M, Bool inv)
- Parameters:
- Returns: SmithNormalForm < Integer >
- Compute the Smith normal form of a given matrix M.
M = LSR in normal case, or S = LMR in inverted case. - Example:
> $M = new Matrix<Integer>([1,2],[23,24]); > $SNF = smith_normal_form($M);
The following line prints the three matrices seperated by newline characters.
> print $SNF->left_companion ,"\n", $SNF->form ,"\n", $SNF->right_companion; 1 0 23 1 1 0 0 -22 1 2 0 1
ones_matrix<Element>( Int m, Int n)
- Template Parameters:
Element
: default: Rational.
- Parameters:
- Int
m
: number of rows - Int
n
: number of columns - Creates a matrix with all elements equal to 1.
- Example:
The following creates an all-ones matrix with Rational coefficients.
> $M = ones_matrix<Rational>(2,3); > print $M; 1 1 1 1 1 1
eigenvalues( Matrix < Float > A)
- Parameters:
- Eigenvalues of a matrix
barycenter( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Vector
- Calculate the average over the rows of a matrix.
- Example:
> $A = new Matrix([3,0,0],[0,3,0],[0,0,3]); > print barycenter($A); 1 1 1
basis( Matrix A)
- Parameters:
- Matrix
A
:
- Computes subsets of the rows and columns of A that form a basis for the linear space spanned by A.
- Example:
Here we have a nice matrix:
> $M = new Matrix([[1,0,0,0],[2,0,0,0],[0,1,0,0],[0,0,1,0]]);
Let's print bases for the row and column space:
> ($row,$col) = basis($M); > print $M->minor($row,All); 1 0 0 0 0 1 0 0 0 0 1 0
> print $M->minor(All,$col); 1 0 0 2 0 0 0 1 0 0 0 1
lineality_space( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Matrix
- Compute the lineality space of a matrix A.
- Example:
> $M = new Matrix([1,1,0,0],[1,0,1,0]); > print lineality_space($M); 0 0 0 1
singular_value_decomposition( Matrix < Float > M)
- Parameters:
- Returns: SingularValueDecomposition
- SVD decomposition of a Matrix. Computes the SVD of a matrix into a diagonal Marix (S), orthogonal square Matrix (U), orthogonal square Matrix (V), such that U*S*V^T=M
The first element of the output array is S, the second U and the thrid V. - Example:
> $M = new Matrix<Float>([1,2],[23,24]); > $SVD = singular_value_decomposition($M);
The following prints the three matrices, seperated by newline characters.
> print $SVD->left_companion ,"\n", $SVD->sigma ,"\n", $SVD->right_companion; 0.06414638608 0.9979404998 0.9979404998 -0.06414638608 33.31011547 0 0 0.6604600341 0.6909846321 -0.7228694476 0.7228694476 0.6909846321
diag
- Parameters:
- Returns: Vector
- Reduce a vector with a given matrix using Gauss elimination.
hadamard_product( Matrix M1, Matrix M2)
- Parameters:
- Returns: Matrix
- Compute the Hadamard product of two matrices with same dimensions.
basis_cols( Matrix A)
- Parameters:
- Matrix
A
:
- Computes a subset of the columns of A that form a basis for the linear space spanned by A.
- Example:
Here we have a nice matrix:
> $M = new Matrix([[1,0,0,0],[2,0,0,0],[0,1,0,0],[0,0,1,0]]);
Let's print a basis of its column space:
> print $M->minor(All,basis_cols($M)); 1 0 0 2 0 0 0 1 0 0 0 1
equal_bases( Matrix M1, Matrix M2)
- Parameters:
- Returns: Bool
- Check whether both matrices are bases of the same linear subspace.
Note: It is assumed that they are *bases* of the row space. - Example:
> $M1 = new Matrix([1,1,0],[1,0,1],[0,0,1]); > $M2 = new Matrix([1,0,0],[0,1,0],[0,0,1]); > print equal_bases($M1,$M2); true
normalized( Matrix < Float > A)
- Parameters:
- Normalize a matrix by dividing each row by its length (l2-norm).
- Example:
> $A = new Matrix<Float>([1.5,2],[2.5,2.5]); > print normalized($A); 0.6 0.8 0.7071067812 0.7071067812
- Parameters:
- Returns: Vector
- Computes the solution of the system Ax = b by applying Cramer's rule
- Example:
from the Wikipedia:
> $A = new Matrix([3,2,-1],[2,-2,4],[-1,1/2,-1]); > $b = new Vector(1,-2,0); > print cramer($A,$b); 1 -2 -2
unit_matrix<Element>( Int d)
- Template Parameters:
Element
: default: Rational
- Parameters:
- Int
d
: dimension of the matrix - Returns: SparseMatrix < unit
- Creates a unit matrix of given dimension
- Example:
The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) in a variable
and prints it:
> $M = unit_matrix(3); > print $M; (3) (0 1) (3) (1 1) (3) (2 1)
- Example:
The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) from type Int
in a variable and prints it:
> $M = unit_matrix<Int>(3); > print $M->type->full_name; SparseMatrix<Int, Symmetric>
trace( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Int
- Computes the trace of a matrix.
- Example:
> $M = new Matrix([1,2,3],[23,24,25],[0,0,1]); > print trace($M); 26
sqr( Vector < v)
- Parameters:
- Vector <
v
:
- Returns: SCALAR
- Return the sum of the squared entries of a vector v.
remove_zero_rows( Matrix m)
pluecker( Matrix V)
- Parameters:
- Matrix
V
:
- Returns: Vector
- Compute the vector of maximal minors of a matrix.
WARNING: interpretation different in lifted_pluecker
totally_unimodular( Matrix A)
- Parameters:
- Matrix
A
:
- Returns: Bool
- The matrix A is totally unimodular if the determinant of each square submatrix equals 0, 1, or -1.
This is the naive test (exponential in the size of the matrix).
For a better implementation try Matthias Walter's polymake extension at
https://github.com/xammy/unimodularity-test/wiki/Polymake-Extension. - Example:
> $M = new Matrix<Int>([-1,-1,0,0,0,1],[1,0,-1,-1,0,0],[0,1,1,0,-1,0],[0,0,0,1,1,-1]); > print totally_unimodular($M); true
basis_rows_integer( Matrix A)
- Parameters:
- Matrix
A
:
- Computes a lattice basis of the span of the rows of A.
moore_penrose_inverse( Matrix M)
- Parameters:
- Matrix
M
:
- Moore-Penrose Inverse of a Matrix
basis_rows( Matrix A)
- Parameters:
- Matrix
A
:
- Computes a subset of the rows of A that form a basis for the linear space spanned by A.
- Example:
Here we have a nice matrix:
> $M = new Matrix([[1,0,0,0],[2,0,0,0],[0,1,0,0],[0,0,1,0]]);
Let's print a basis of its row space:
> print $M->minor(basis_rows($M),All); 1 0 0 0 0 1 0 0 0 0 1 0
householder_trafo( Vector < Float > b)
- Parameters:
- Householder transformation of Vector b. Only the orthogonal matrix reflection H is returned.
transpose
ones_vector<Element>( Int d)
- Template Parameters:
Element
: default: Rational.
- Parameters:
- Int
d
: vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation. - Creates a vector with all elements equal to 1.
- Example:
To create the all-ones Int vector of dimension 3, do this:
> $v = ones_vector<Int>(3);
You can print the result using the print statement:
> print $v; 1 1 1
solve_left( Matrix A, Matrix B)
- Parameters:
- Returns: Matrix
- Computes a matrix X that solves the system XA = B. This is useful, for instance, for computing the coordinates of some vectors
with respect to a basis. The rows of the matrix solve_left(B,V) are the coordinates of the rows of V with respect to the rows of B. - Example:
Define the matrices
> $V = new Matrix([[-4,2,2],[3,-2,-1]]); > $B = new Matrix([[-1,1,0],[0,-1,1]]);
so that the rows of B are a basis of the subspace of vectors with zero coordinate sum. Then the rows of
> print solve_left($B, $V); 4 2 -3 -1
contain the coordinates of the rows of V with respect to the rows of B.
zero_vector<Element>( Int d)
- Template Parameters:
Element
: default: Rational
- Parameters:
- Int
d
: vector dimension. If omitted, a vector of dimension 0 is created,
which can adjust itself when involved in a block matrix operation. - Creates a vector with all elements equal to zero.
- Example:
The following stores a vector of dimension 5 with 0 as entries (from type Rational) in a variable and prints it:
> $v = zero_vector(5); > print $v; 0 0 0 0 0
- Example:
The following stores a vector of dimension 5 with 0 as entries from type Int in a variable and prints its type:
> $v = zero_vector<Int>(5); > print $v->type->full_name; Vector<Int>
- Example:
The following concatenates a vector of dimension 2 of ones and a vector of length 2 of zeros:
> $v = ones_vector(2) | zero_vector(2); > print $v; 1 1 0 0
hermite_normal_form( Matrix M)
- Parameters:
- Matrix
M
: Matrix to be transformed.
- Returns: HermiteNormalForm
- Computes the (column) Hermite normal form of an integer matrix.
Pivot entries are positive, entries to the left of a pivot are non-negative and strictly smaller than the pivot. - Example:
The following stores the result for a small matrix M in H and then prints both hnf and companion:
> $M = new Matrix<Integer>([1,2],[2,3]); > $H = hermite_normal_form($M); > print $H->hnf; 1 0 0 1
> print $H->companion; -3 2 2 -1
anti_diag
project_to_orthogonal_complement( Matrix points, Matrix orthogonal)
- Parameters:
- Projects points into the orthogonal complement of a subspace given via an orthogonal basis.
The given points will be overwitten.
solve_right( Matrix A, Matrix B)
- Parameters:
- Returns: Matrix
- Computes a matrix X that solves the system AX = B
- Example:
A non-degenerate example:
> $A = new Matrix([[1,0,0],[1,1,0],[1,0,1],[1,1,1]]); > $B = new Matrix([[1,0,0],[1,0,1],[1,1,0],[1,1,1]]); > print solve_right($A,$B); 1 0 0 0 0 1 0 1 0
- Example:
A degenerate example:
> $A = new Matrix([[1,0,0,0,0],[0,1,0,0,0],[1,0,1,0,0],[0,1,1,0,0]]); > $B = new Matrix([[0,1,0,0,0],[1,0,0,0,0],[0,1,1,0,0],[1,0,1,0,0]]); > print solve_right($A,$B); 0 1 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
Set Operations
This category contains functions performing operations on Sets.
scalar2set(SCALAR s)
- Parameters:
- SCALAR
s
:
- Returns: Set <
- Returns the singleton set {s}.
- Example:
> print scalar2set(23); {23}
- Parameters:
- Create the Set {a, a+1, …, b-1, b} for a ≤ b. See also: sequence
- Example:
> print range(23,27); {23 24 25 26 27}
range_from( Int a)
- Parameters:
- Int
a
: start index
- Create an index range starting at a, the last index is implied by the context.
To be used with minor, slice, and similar methods selecting a subset of elements. - Example:
> $v=new Vector<Int>(10,20,30,40); > print $v->slice(range_from(2)); 30 40
- Parameters:
- Create the Set {a, a+1, …, a+c-1}. See also: range
- Example:
> print sequence(23,6); {23 24 25 26 27 28}
select_subset( Set s, Set < Int > indices)
- Parameters:
- Set
s
:
- Returns: Set
- Returns the subset of s given by the indices.
- Example:
> $s = new Set<Int>(23,42,666,789); > $ind = new Set<Int>(0,2); > $su = select_subset($s,$ind); > print $su; {23 666}
- Parameters:
- Returns: Int
- Analyze the inclusion relation of two sets.
- Example:
> $s1 = new Set(1,2,3); > $s2 = $s1 - 1; > print incl($s1, $s2); 1
> print incl($s2, $s1); -1
> print incl($s1, $s1); 0
> print incl($s2, $s1-$s2); 2
Utilities
Miscellaneous functions.
fibonacci( Int m)
- Parameters:
- Int
m
:
- Returns: ARRAY
- Returns the first m Fibonacci numbers.
average(ARRAY array)
- Parameters:
- ARRAY
array
:
- Returns the average value of the array elements.
- Example:
> print average([1,2,3]); 2
histogram(ARRAY data)
- Parameters:
- ARRAY
data
:
- Returns: Map <
- Produce a histogram of an array: each different element value is mapped on the number of its occurences.
- Example:
> $H = histogram([1,1,2,2,2,3,3,2,3,3,1,1,1,3,2,3]); > print $H; {(1 5) (2 5) (3 6)}
index_of( Array < Set < Int > > array)
- Parameters:
- Return a map indexing an array of sets
- Example:
> $s1 = new Set(1,2,3); > $s2 = $s1 - 1; > $a = new Array<Set>($s1,$s2,$s1); > print index_of($a); {({1 2 3} 2) ({2 3} 1)}
minimum(ARRAY array)
- Parameters:
- ARRAY
array
:
- Returns the minimal element of an array.
- Example:
> print minimum([23,42,666]); 23
is_unimodal(ARRAY data)
- Parameters:
- ARRAY
data
:
- Returns: Bool
- Checks if a given sequence is unimodal
- Example:
> print is_unimodal([1,1,2,3,3,2,2,1]); 1
> print is_unimodal([3,3,2,-1]); 1
> print is_unimodal([1,3,2,3]); 0
median(ARRAY array)
- Parameters:
- ARRAY
array
:
- Returns the median value of the array elements.
- Example:
> print median([1,2,3,9]); 2.5
bounding_box( Matrix m)
rand_perm( Int n)
- Parameters:
- Int
n
:
- gives a random permutation
maximum(ARRAY array)
- Parameters:
- ARRAY
array
:
- Returns the maximal element of an array.
- Example:
> print maximum([1,2,3,4,5,6,7,23]); 23
distance_matrix( Matrix S, CODE d)
- Parameters:
- Matrix
S
: - CODE
d
:
- Returns: Matrix
- Given a metric, return a triangle matrix whose (i,j)-entry contains the distance between point i and j of the point set S for i<j. All entrys below the diagonal are zero. The metric is passed as a perl subroutine mapping two input vectors to a real value.
- Example:
The following defines the perl subroutine dist as the euclidean metric and then saves the distance matrix of the 3-cubes vertices in the variable $M: \\ <code> > sub dist($$) {
> my $v = $_[0] - $_[1]; > return sqrt(new Float($v*$v)); } > $M = distance_matrix(polytope::cube(3)→VERTICES, \&dist); </code>
is_nonnegative(ARRAY data)
- Parameters:
- ARRAY
data
:
- Returns: Bool
- Checks if a given sequence is nonnegative
- Example:
> print is_nonnegative([1,0,3]); 1
perturb_matrix( Matrix M, Float eps, Bool not_hom)
- Parameters:
- Returns: Matrix
- Perturb a given matrix M by adding a random matrix.
The random matrix consists of vectors that are uniformly distributed
on the unit sphere. Optionally, the random matrix can be scaled by
a factor eps.
Visualization
These functions are for visualization.
threejs( Visual::Object vis_obj)
- Parameters:
- Visual::Object
vis_obj
: object to display
- Produce an html file with given visual objects.
postscript( Visual::Object vis_obj …)
- Parameters:
- Visual::Object
vis_obj …
: objects to draw
- Create a Postscript ™ drawing with the given visual objects.
povray( Visual::Object vis_obj …)
- Parameters:
- Visual::Object
vis_obj …
: objects to display
- Run POVRAY to display given visual objects.
static( Visual::Object vis_obj)
- Parameters:
- Returns: Visual::Object
- Suppress creation of dynamic (interactive) scenes.
jreality( Visual::Object vis_obj …)
- Parameters:
- Visual::Object
vis_obj …
: objects to display
- Run jReality to display given visual objects.
compose
sketch( Visual::Object vis_obj …)
- Parameters:
- Visual::Object
vis_obj …
: objects to display
- Produce a Sketch input file with given visual objects.
x3d( Visual::Object vis_obj …)
- Parameters:
- Visual::Object
vis_obj …
: objects to draw
- Create an X3D drawing with the given visual objects.
tikz( Visual::Object vis_obj)
- Parameters:
- Visual::Object
vis_obj
: object to display
- Produce a TikZ file with given visual objects.
Small Object Types
Algebraic Types
This category contains all “algebraic” types, such as matrices, vectors, polynomials, rings, …
RationalFunction<Coefficient, Exponent>
- Template Parameters:
Coefficient
: default: Rational
Exponent
: default: Int
- the same with type deduction
Matrix<Element, Sym>
- Template Parameters:
Element
: default: Rational
Sym
: default: NonSymmetric
- Methods of Matrix:
diagonal( Int i)
- Parameters:
- Int
i
: i=0: the main diagonal (optional)
i>0: the i-th diagonal below the main diagonal
i<0: the i-th diagonal above the main diagonal
- Returns the diagonal of the matrix.
row( Int i)
- Parameters:
- Int
i
:
- Returns the i-th row.
rows
- Returns: Int
- Returns the number of rows.
anti_diagonal( Int i)
- Parameters:
- Int
i
: i=0: the main anti_diagonal (optional)
i>0: the i-th anti_diagonal below the main anti_diagonal
i<0: the i-th anti_diagonal above the main anti_diagonal
- Returns the anti-diagonal of the matrix.
col( Int i)
- Parameters:
- Int
i
:
- Returns the i-th column.
cols
- Returns: Int
- Returns the number of columns.
div_exact( Int a)
SparseMatrix<Element, Sym>
- Template Parameters:
Element
:
- A SparseMatrix is a two-dimensional associative array with row and column indices as keys; elements equal to the default value (ElementType(), which is 0 for most numerical types) are not stored, but implicitly encoded by the gaps in the key set. Each row and column is organized as an AVL-tree.
Use dense to convert this into its dense form.
You can create a new SparseMatrix by entering its entries row by row, as a list of SparseVectors e.g.:
$A = new SparseMatrix<Int>(« '.');
(5) (1 1)
(5) (4 2)
(5)
(5) (0 3) (1 -1)
. - Methods of SparseMatrix:
squeeze_rows
- Removes empty rows.
The remaining rows are renumbered without gaps.
squeeze_cols
- Removes empty columns.
The remaining columns are renumbered without gaps.
squeeze
- Removes empty rows and columns.
The remaining rows and columns are renumbered without gaps.
Vector<Element>
- Template Parameters:
Element
:
- A type for vectors with entries of type Element.
You can perform algebraic operations such as addition or scalar multiplication.
You can create a new Vector by entering its elements, e.g.:
$v = new Vector<Int>(1,2,3);\\ or\\ $v = new Vector<Int>([1,2,3]); - Methods of Vector:
SparseVector<Element>
- Template Parameters:
Element
:
- A SparseVector is an associative container with element indices (coordinates) as keys; elements equal to the default value (ElementType(), which is 0 for most numerical types) are not stored, but implicitly encoded by the gaps in the key set. It is based on an AVL tree.
The printable representation of a SparseVector looks like a sequence (l) (p1 v1) … (pk vk),
where l is the dimension of the vector and each pair (pi vi) denotes an entry with value
vi at position pi. All other entries are zero.
Use dense to convert this into its dense form.
You can create a new SparseVector by entering its printable encoding as described above, e.g.:
$v = new SparseVector<Int>(« '.');
(6) (1 1) (2 2)
. - Methods of SparseVector:
size
- Returns: Int
- The number of non-zero entries.
Polynomial<Coefficient, Exponent>
- Template Parameters:
Coefficient
: default: Rational
Exponent
: default: Int
- Methods of Polynomial:
-
- Parameters:
- Int
nvars
: new number of variables, default: maximal index
- Returns: Polynomial
- Map the variables of the Polynomial to the given indices.
The same index may bei given multiple times and also some may be omitted
for embedding with a higher number of variables.
The length of the given Array must be the same as the number of variables
of the original polynomial.
-
- Example:
> $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3"); > print $pm->mapvars([0,1,1,4],6); x_0^2*x_4 + x_1 + 3*x_4 + 1
project
- Returns: Polynomial
- Project the Polynomial to the given list of variables.
The number of variables will be reduced to the number of indices,
i.e. the variables will be renamed.
Keeping the names of the variables is possible by using substitute
with a Map.
- Example:
> $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3"); > print $pm->project([1,3]); x_0 + 4*x_1 + 1
print_ordered( Matrix m)
coefficients_as_vector
- Returns: Vector < Polynomial
- The vector of all coefficients.
The sorting agrees with monomials_as_matrix.
lm
- Returns: Int
- The exponent of the leading monomial.
lc
- Returns: Int
- The leading coefficient.
get_var_names
- set the variable names
deg
- Returns: Int
- The degree of the polynomial
n_vars
- Returns: Int
- Number of variables
trivial
- Returns: Bool
- The polynomial is zero.
embed( Int nvars)
- Parameters:
- Int
nvars
: new number of variables
- Returns: Polynomial
- Embed the Polynomial in a polynomial ring with the given
number of variables.
The old variables will be put at the beginning, for more control use mapvars.
- Example:
> $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3"); > print $pm->project([1,3]); x_0 + 4*x_1 + 1
set_var_names
- set the variable names
initial_form( Vector < Polynomial v)
- Parameters:
- Returns: Polynomial
- The initial form with respect to a weight-vector v
monomials_as_matrix
- Returns: SparseMatrix < Polynomial
- The matrix of all exponent vectors (row-wise).
The sorting agrees with coefficients_as_vector.
constant_coefficient
- Returns: Int
- The constant coefficient.
substitute
- Substitute a list of values in a Polynomial with Int exponents.
Either with an array of values, or with a Map mapping variable indices
to values.
- Example:
> $pm = new Polynomial("1+x_0^2*x_3+x_1+3*x_3"); > print $pm->substitute([0,11,2,3]); 21
> $map = new Map<Int,Rational>([0,5/2],[1,1/5],[2,new Rational(7/3)]); > print $pm->substitute($map); 37/4*x_3 + 6/5
reset_var_names
- reset the variable names according to the default naming scheme
UniPolynomial<Coefficient, Exponent>
- Template Parameters:
Coefficient
: default: Rational
Exponent
: default: Int
- A class for univariate polynomials.
- Methods of UniPolynomial:
lower_deg
- Returns: UniPolynomial
- The lowest degree occuring in the polynomial.
set_var_names
- set the variable name
monomials_as_vector
- Returns: Vector < UniPolynomial
- The vector of all exponents.
The order agrees with coefficients_as_vector.
constant_coefficient
- Returns: Int
- The constant coefficient.
reset_var_names
- reset the variable name according to the default naming scheme
substitute
- Substitute some value in a UniPolynomial with Int exponents.
When all exponents are positive the argument can be any scalar, matrix or polynomial type.
With negative exponents, polynomials are not supported (use RationalFunction instead)
and any given matrix must be invertible
evaluate( UniPolynomial x, UniPolynomial exp)
- Parameters:
- UniPolynomial
x
: - UniPolynomial
exp
: (default: 1)
- Returns: UniPolynomial
- Evaluate a UniPolynomial at a number (x^exp).
Note that for non-integral exponents this may require intermediate floating point
computations depending on the input:
Let explcm be the lcm of the denominators of all exponents.
If there are no denominators or explcm divides exp, then the evaluation
is computed exactly.
Otherwise, some rational number close to the root (x^exp)^-explcm will be chosen
via an intermediate floating point number.
lc
- Returns: Int
- The leading coefficient.
deg
- Returns: UniPolynomial
- The highest degree occuring in the polynomial.
get_var_names
- get the variable name
print_ordered( UniPolynomial x)
- Parameters:
- UniPolynomial
x
:
- Print a polynomial with terms sorted according to exponent*x.
coefficients_as_vector
- Returns: Vector < UniPolynomial
- The vector of all coefficients.
The sorting agrees with monomials_as_vector.
monomial
- create a monomial of degree 1
n_vars
- Number of variables
evaluate_float( Float x)
Plucker<Scalar>
- Template Parameters:
Scalar
: default: Rational
- Methods of Plucker:
permuted
- UNDOCUMENTED
coordinates
- UNDOCUMENTED
all_rows_or_cols
- Use the keyword “All” for all rows or columns, e.g. when constructing a minor.
PuiseuxFraction<MinMax, Coefficient, Exponent>
- Template Parameters:
Coefficient
: default: Rational
Exponent
: default: Rational
- Methods of PuiseuxFraction:
evaluate_float
val
- Returns: TropicalNumber < PuiseuxFraction
- The valuation.
evaluate
Arithmetic
These types are needed as return types of arithmetic computations.
Div<Scalar>
- Template Parameters:
Scalar
:
- Methods of Div:
Max
- tropical addition: max
- Methods of Max:
apply
- UNDOCUMENTED
orientation
- UNDOCUMENTED
Min
- tropical addition: min
- Methods of Min:
orientation
- UNDOCUMENTED
apply
- UNDOCUMENTED
TropicalNumber<Addition, Scalar>
- Template Parameters:
Addition
:Scalar
: default: Rational
- Methods of TropicalNumber:
zero
- Returns: TropicalNumber
- The zero element of the tropical semiring of this element.
orientation
- Returns: Int
- The orientation of the associated addition, i.e.
+1 if the corresponding 0 is +inf
-1 if the corresponding 0 is -inf
ExtGCD
- Methods of ExtGCD:
Addition
Artificial
These types are auxiliary artifacts helping to build other classes, primarily representing template parameters or enumeration constants. They should not be used alone as property types or function arguments. In the most cases they won't even have user-accessible constructors.
Symmetric
- Labels a Matrix or an IncidenceMatrix as symmetric.
DirectedMulti
- Type tag for a directed multigraph.
LocalFloatEpsilon
Serialized<X>
- Template Parameters:
X
:
UndirectedMulti
- Type tag for an undirected multigraph.
CachedObjectPointer
EdgeIterator
NonSymmetric
- Labels a Matrix or an IncidenceMatrix as non-symmetric.
EdgeList
Directed
- Type tag for a directed Graph.
Container
- One-dimensional collection of objects, aka container in STL
It can be accessed like a perl array. Sequential iteration via foreach() is always supported;
random access might be supported depending on the underlying C++ object.
Iterator<Element>
- Template Parameters:
Element
:
- An iterator over a sequence of objects.
The objects may be stored in a container or be generated on the fly.
Undirected
- Type tag for an undirected Graph.
Basic Types
This category contains all basic types, in particular those that wrap C++, GMP or perl types such as Int, Integer, Rational, Long, Float, Array, String, …
Bool
- Corresponds to the C++ type bool.
AccurateFloat
- A wrapper for AccurateFloat.
Long
- Corresponds to the C++ type long.
This type is primarily needed for automatic generated function wrappers,
because perl integral constants are always kept as a long.
String
- Corresponds to the C++ type std::string.
Float
- Corresponds to the C++ type double.
- Methods of Float:
minus_inf
- produce an infinitely large negative value
inf
- produce an infinitely large positive value
Pair<First, Second>
- Template Parameters:
First
:Second
:
- Corresponds to the C++ type std::pair.
Int
- Corresponds to the C++ type int.
QuadraticExtension<Field>
- Template Parameters:
Field
: default: Rational
- Realizes quadratic extensions of fields.
You can construct the value a+b\(\sqrt r\) via QuadraticExtension(a, b, r) (where a, b, r are of type Field).
Integer
- An integer of arbitrary size.
- Methods of Integer:
inf
- produce an infinitely large positive value
minus_inf
- produce an infinitely large negative value
Rational
- A class for rational numbers.
You can easily create a Rational like that: $x = 1/2; - Methods of Rational:
inf
- Produce an infinitely large positive value.
minus_inf
- Produce an infinitely large negative value.
Text
- Plain text without any imposed structure.
List<Element>
- Template Parameters:
Element
:
- Corresponds to the C++ type std::list.
Array<Element>
- Template Parameters:
Element
:
- An array with elements of type Element.
Corresponds to the C++ type Array. - Methods of Array:
size
- Returns: Int
- Returns the size.
Database
Here you can find the functions to access the polymake database.
DBCursor
- A database cursor. Initialize it with a database name, a collection name and a query.
You can then iterate over the objects matching the query with next.
It lazily fetches more objects from the database server.
(Note that you have to create a new cursor if you want to start from the beginning.)
MongoClient
- A handler for the polyDB database internally controlling the connection to the MongoDB database
Graph Types
This contains all property types that are related to graphs.
EdgeHashMap<Dir, Element>
- Template Parameters:
Element
: data associated with edges
- Sparse mapping of edges to data items.
- Methods of EdgeHashMap:
NodeHashMap<Dir, Element>
- Template Parameters:
Element
: data associated with nodes
- Sparse mapping of nodes to data items.
NodeMap<Dir, Element>
- Template Parameters:
Element
: data associated with nodes
- Dense mapping of nodes to data items.
EdgeMap<Dir, Element>
- Template Parameters:
Element
: data associated with edges
- Dense mapping of edges to data items.
- Methods of EdgeMap:
Graph<Dir>
- Template Parameters:
- Methods of Graph:
out_adjacent_nodes( Int node)
node_out_of_range( Int node)
invalid_node( Int node)
squeeze
- Renumbers the valid nodes as to eliminate all gaps left after deleting.
degree( Int node)
adjacent_nodes( Int node)
out_degree( Int node)
in_degree( Int node)
dim
add_node
- Returns: Int
- Add a new node without incident edes.
out_edges( Int node)
edges
- Returns: Int
- Get the total number of edges.
squeeze_isolated
- Deletes all nodes of degree 0,
then renumbers the remaining nodes without gaps.
in_edges( Int node)
nodes
- Returns: Int
- Get the total number of nodes.
permute_nodes
- permute the nodes
param perm permutation of node indexes
node_exists( Int node)
permute_inv_nodes
- permute the nodes
param perm inverse permutation of node indexes
delete_edge
in_adjacent_nodes( Int node)
has_gaps
delete_node( Int node)
- Parameters:
- Int
node
:
- Deletes all edges incident to the given node and marks it as invalid.
The numeration of other nodes stays unchanged.
GraphMap<Dir, Element>
- Template Parameters:
Element
: data associated with nodes or edges
- The common abstract base class for all kinds of associative containers that can be attached to a Graph.
Linear Algebra
These types are needed as return types of algebraic computations.
HermiteNormalForm
- Complete result of the Hermite normal form computation.
Contains the following fields:
Matrix<Scalar> hnf: the Hermite normal form N of M
SparseMatrix<Scalar> companion: unimodular Matrix R such that M*R = N.
Int rank: rank of M
SingularValueDecomposition
- Complete result of the singular value decomposition of a matrix M,
such that left_companion * sigma * transpose(right_companion) = M
Contains the following fields:
Matrix<Float> sigma: the diagonalized matrix
Matrix<Float> left_companion: matrix of left singular vectors
Matrix<Float> right_companion: matrix of right singular vectors
SmithNormalForm
- Complete result of the Smith normal form computation.
Contains the following fields:
SparseMatrix<Scalar> form: the Smith normal form S of the given matrix M
List<Pair<Scalar, Int» torsion: absolute values of the entries greater than 1 of the diagonal together with their multiplicity
Int rank: rank of M
SparseMatrix<Scalar> left_companion, right_companion: unimodular matrices L and R such that
M = LSR in normal case, or S = LMR in inverted case (as specified in the call to smith_normal_form function).
Set Types
In this category you find all property types related to sets, such as Set, Map, HashMap, IncidenceMatrix, …
IncidenceMatrix<Sym>
- Template Parameters:
- A 0/1 incidence matrix.
- Methods of IncidenceMatrix:
rows
- Returns: Int
- Returns the number of rows.
squeeze_rows
- Removes empty rows.
The remaining rows are renumbered without gaps.
row( Int i)
- Parameters:
- Int
i
:
- Returns: SparseVector < Int >
- Returns the i-th row.
squeeze
- Removes empty rows and columns.
The remaining rows and columns are renumbered without gaps.
cols
- Returns: Int
- Returns the number of columns.
-
- Parameters:
- Returns: IncidenceMatrix
- Returns a minor of the matrix containing the rows in r and the columns in c.
You can pass All if you want all rows or columns and ~ for the complement of a set.
For example,
$A→minor(All, ~[0]);
will give you the minor of a matrix containing all rows and all but the 0-th column.
col( Int i)
- Parameters:
- Int
i
:
- Returns: SparseVector < Int >
- Returns the i-th column.
squeeze_cols
- Removes empty columns.
The remaining columns are renumbered without gaps.
Bitset
- Container class for dense sets of integers.
A special class optimized for representation of a constrained range of
non-negative integer numbers.
HashMap<Key, Value>
- Template Parameters:
Key
: type of the key values
Value
: type of the mapped value
- An unordered map based on a hash table. Its interface is similar to that of Map,
but the order of elements is not stable across polymake sessions and does not correlate with key values.
Accessing and inserting a value by its key works in constant time O(1).
You can create a new HashMap mapping Ints to Strings by
$myhashmap = new HashMap<Int, String>([1, “Monday”], [2, “Tuesday”]);
On the perl side HashMaps are treated like hashrefs.
You can work with a HashMap like you work with a Map (keeping in mind differences in performance
and memory demand). - Methods of HashMap:
size
- Returns: Int
- Size of the map
PowerSet<Element>
- Template Parameters:
Element
: default: Int
- A Set whose elements are of type Set<Element>.
Map<Key, Value>
- Template Parameters:
Key
: type of the key values
Value
: type of the mapped value
- Maps are sorted associative containers that contain unique key/value pairs.
Maps are sorted by their keys.
Accessing or inserting a value needs logarithmic time O(log n), where n is the size of the map.
You can create a new Map mapping Ints to Strings by
$mymap = new Map<Int, String>([1, "Monday"], [2, "Tuesday"]);\\ On the perl side Maps are treated like hashrefs.\\ You can add a new key/value pair by\\$mymap→{3} = “Wednesday”;
(If the key is already contained in the Map, the corresponding value is replaced by the new one.)
or ask for the value of a key by
print $mymap→{1};
Set<Element>
- Template Parameters:
Element
: default: Int
- A type for ordered sets containing elements of type Element.
You can for example create a new Set by:
$s = new Set(2, 3, 5, 7);\\ You can perform set theoretic operations:\\ $s1 + $s2 union\\ $s1 * $s2 intersection\\ $s1 - $s2 difference\\ $s1 ^ $s2 symmetric difference - Methods of Set:
ApproximateSet<Element>
- Template Parameters:
Element
: default: Float
- A specialization of Sets containing elements of type Element,
but where equality is enforced only up to a global epsilon.
You can for example create a new ApproximateSet with two elements by:
$s = new ApproximateSet(1.1, 1.2, 1.200000001);
FacetList
- A FacetList is a collection of sets of integral numbers from a closed contiguous range [0..n-1].
The contained sets usually encode facets of a simplicial complex,
with set elements corresponding to vertices of a complex, therefore the name.
From the structural perspective, FacetList is interchangeable with IncidenceMatrix,
but they significantly differ in supported operations and their performance.
IncidenceMatrix offers fast random access to elements, while FacetList is optimized
for finding, inserting, and deleting facets fulfilling certain conditions like
all subsets or supersets of a given vertex set.
On perl side, FacetList behaves like a sequence of playground without random access to facets.
Facets are visited in chronological order.
Each facet has a unique integral ID generated at the moment of insertion.
The IDs can be obtained via call to index() of iterators created by find() methods. - Methods of FacetList:
eraseSupersets( Set s)
eraseSubsets( Set s)
findSubsets( Set s)
n_vertices
- Returns: Int
- The number of vertices
insertMin( Set f)
size
- Returns: Int
- The number of facets in the list.
find( Set f)
insert( Set f)
- Parameters:
- Set
f
: facet to add.
- Add a new facet. It may be a proper subset or a proper superset of existing facets.
It must not be empty or coincide with any existing facet.
findSupersets( Set s)
erase( Set f)
insertMax( Set f)
HashSet<Element>
- Template Parameters:
Element
:
- An unordered set of elements based on a hash table.
Can be traversed as a normal container, but the order of elements is not stable across polymake sessions,
even if the set is restored from the same data file every time. - Methods of HashSet:
size
- Returns: Int
- The cardinality of the set.
Visualization
These property_types are for visualization.
HSV
- A color described as a Hue-Saturation-Value triple.
Is convertible to and from an RGB representation.
Color
Flexible
- This is a pseudo-type for documentation purposes only.
Many options of visualization functions modifying the appearance of some set of graphical elements
like points, edges, facets, etc. accept a wide range of possible values, allowing for different grades
of flexibility (and complexity):
SCALAR the same attribute value is applied to all elements
ARRAY each element gets its individual attribute value
HASH elements found in the hash get their individual attribute values, for the rest the appropriate default applies
SUB a piece of code computing the attribute value for the given element
Unless specified explicitly in the detailed option description, the indices, keys, or
subroutine arguments used for retrieval of the attribute values are just the zero-based ordinal numbers of the elements.
RGB
- A color described as a Red-Green-Blue triple.
Can be constructed from a list of three integral values from the range 0..255,
or a hex triplet with a leading # symbol,
or a list of three floating-point values from the range 0..1,
or a symbolic name from the X11 color names.