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.
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().
These are functions that perform arithmetic computations.
ceil(Rational a)
The ceiling function. Returns the smallest integral number not smaller than a.
Rational
a
denominator(Rational a)
Returns the denominator of a in a reduced representation.
Rational
a
denominator(RationalFunction f)
Returns the denominator of a RationalFunction
f.
denominator(PuiseuxFraction f)
Returns the denominator of a PuiseuxFraction
f.
div(Scalar a, Scalar b)
Compute the quotient and remainder of a and b in one operation.
div_exact(Integer a, Integer b)
Computes the ratio of two given integral numbers under the assumption that the dividend is a multiple of the divisor.
ext_gcd(Scalar a, Scalar b)
Compute the greatest common divisor of two numbers (a,b) and accompanying co-factors.
Scalar
a
Scalar
b
> $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
…and the quotients k1 of a and k2 of b by g.
> print $GCD->k1; 5
> print $GCD->k2; 2
floor(Rational a)
The floor function. Returns the smallest integral number not larger than a.
gcd(Int a, Int b)
Computes the greatest common divisor of two integers.
gcd(Vector<Scalar> v)
Compute the greatest common divisor of the elements of the given vector.
gcd(UniPolynomial p, UniPolynomial q)
Returns the greatest common divisor of two univariate polynomials.
We create two UniPolynomials with said coefficient and exponent type:
> $p = new UniPolynomial<Rational,Int>([2,2],[3,2]); > $q = new UniPolynomial<Rational,Int>([6,4],[4,2]);
Printing them reveals what the constructor does:
> print $p; 2*x^3 + 2*x^2
> print $q; 6*x^4 + 4*x^2
Now we can calculate their gcd:
> print gcd($p,$q); x^2
get_var_names()
Get the current list of variable names used for pretty printing and string parsing of the given polynomial class
is_one(Scalar s)
Compare with the one (1) value of the corresponding data type.
Scalar
s
is_zero(Scalar s)
Compare with the zero (0) value of the corresponding data type.
Scalar
s
isfinite(Scalar a)
Check whether the given number has a finite value.
isinf(Scalar a)
Check whether the given number has an infinite value. Return -1/+1 for infinity and 0 for all finite values.
lcm(Int a, Int b)
Computes the least common multiple of two integers.
lcm(Vector<Scalar> v)
Compute the least common multiple of the elements of the given vector.
local_var_names(String names …)
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
.
String
names …
: variable names, see set_var_names
.
monomials<Coefficient, Exponent>(Int n)
Create degree one monomials of the desired polynomial type.
Coefficient
: The polynomial coefficient type. Rational by default.
Exponent
: The exponent type. Int by default.
Int
n
: The number of variables
UniPolynomial<Coefficient,Exponent>
numerator(Rational a)
Returns the numerator of a in a reduced representation.
Rational
a
numerator(RationalFunction f)
Returns the numerator of a RationalFunction
f.
numerator(PuiseuxFraction f)
Returns the numerator of a PuiseuxFraction
f.
set_var_names(String names …)
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.
String
names …
: variable names; may also be bundled in an array an empty list resets to the default naming scheme
sum_of_square_roots_naive(Array<Rational> input_array)
Make a naive attempt to sum the square roots of the entries of the input array.
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.
Combinatorial functions.
all_permutations(Int n)
Returns a list of all permutations of the set {0…n-1} as a perl-array
are_permuted(Array a, Array b)
Determine whether two arrays a and b are permuted copies of each other.
binomial(Int n, Int k)
Computes the binomial coefficient n choose k. Negative values of n (and k) are supported.
n_fixed_points(Array<Int> p)
Returns the number of fixed points of the permutation given by p.
> print n_fixed_points([1,0,2,4,3]); 1
permutation_cycle_lengths(Array<Int> p)
Returns the sorted cycle lengths of a permutation
> print permutation_cycle_lengths(new Array<Int>([1,2,0,4,3])); 2 3
permutation_cycles(Array<Int> p)
Returns the cycles of a permutation given by p.
ARRAY
> print permutation_cycles([1,0,3,2]); {0 1}{2 3}
permutation_matrix<Scalar>(Array<Int> p)
Returns the permutation matrix of the permutation given by p.
permutation_order(Array<Int> p)
Returns the order of a permutation
> print permutation_order(new Array<Int>([1,2,0,4,3])); 6
permutation_sign(Array<Int> p)
Returns the sign of the permutation given by p.
> print permutation_sign([1,0,3,2]); 1
This contains functions for data conversions and type casts.
cast<Target>(Core::Object 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.
Target
: the desired new type
Core::Object
object
: to be modified
cols
UNDOCUMENTED
cols(Matrix A)
Returns an array containing the columns of A.
Matrix
A
The following saves the columns of the vertex matrix of a square in the variable $w and then prints its contents using a foreach loop and concatenating each entry with the string “ ”.
> $w = cols(polytope::cube(2)->VERTICES); > foreach( @$w ){ > print @{$_}, " "; > } 1111 -11-11 -1-111
concat_rows(Matrix A)
Concatenates the rows of A.
Matrix
A
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
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)
convert_to<Target>(Scalar s)
Explicit conversion to a different scalar type.
Target
Scalar
s
Target
convert_to<Target>(Vector v)
Explicit conversion to a different element type.
convert_to<Target>(Matrix m)
Explicit conversion to a different element type.
convert_to<Target>(Polynomial m)
Explicit conversion to a different coefficient type.
Target
Polynomial<Target>
convert_to<Target>(UniPolynomial m)
Explicit conversion to a different coefficient type.
Target
UniPolynomial<Target>
dense(Vector v)
Return the input vector (which is already in dense form).
Vector
v
dense(Matrix m)
Return the input matrix (which is already in dense form).
Matrix
m
dense<Element>(SparseVector<Element> v)
Convert to an equivalent dense vector of the same element type.
Element
SparseVector<Element>
v
Vector<Element>
dense<Element>(SparseMatrix<Element> m)
Convert to an equivalent dense matrix of the same element type.
Element
SparseMatrix<Element>
m
Matrix<Element>
dense(IncidenceMatrix m)
Convert to a dense 0/1 matrix.
dense(Set s, Int dim)
Convert to a dense 0/1 vector of a given dimension.
index_matrix(SparseMatrix m)
Get the positions of non-zero entries of a sparse matrix.
> $S = new SparseMatrix([1,2,0,0,0,0],[0,0,5,0,0,32]); > print index_matrix($S); {0 1} {2 5}
indices(SparseVector v)
Get the positions of non-zero entries of a sparse vector.
> $v = new SparseVector(0,1,1,0,0,0,2,0,3); > print indices($v); {1 2 6 8}
lex_ordered(FacetList f)
Visit the facets of f sorted lexicographically.
> $f = new FacetList(polytope::cube(2)->VERTICES_IN_FACETS); > print lex_ordered($f); {{0 1} {0 2} {1 3} {2 3}}
rows
UNDOCUMENTED
rows(Matrix A)
Returns an array containing the rows of A.
Matrix
A
The following saves the rows of the vertex matrix of a square in the variable $w and then prints its contents using a foreach loop and concatenating each entry with the string “ ”.
> $w = rows(polytope::cube(2)->VERTICES); > foreach( @$w ){ > print @{$_}, " "; > } 1-1-1 11-1 1-11 111
support(Vector v)
Get the positions of non-zero entries of a vector.
toMatrix<Scalar>(IncidenceMatrix A)
Convert an IncidenceMatrix to a SparseMatrix.
Scalar
SparseMatrix<Scalar>
> $M = toMatrix<Int>(polytope::cube(2)->VERTICES_IN_FACETS); > print $M->type->full_name; SparseMatrix<Int, NonSymmetric>
toTropicalPolynomial(String s, String vars)
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.
String
s
: The string to be parsed
String
vars
: Optional list of variables. If this is given, all variables used in s must match one of the variables in this list.
Polynomial<TropicalNumber<Addition,Rational>>
toVector<Scalar>(Set S, Int d)
Create a sparse vector having 1's at positions contained in the given set
Scalar
: type of apparent 1's
Set
S
Int
d
: dimension of the result
SparseVector<Scalar>
vector2col(Vector v)
vector2row(Vector v)
Here you can find the functions to access the polymake database.
db_count(HASH query)
Returns the number of objects in the database db in collection that match the query.
HASH
query
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
String
username
: Some databases might have access control.
String
password
: Some databases might have access control.
MongoClient
client
db_cursor(HASH query)
Returns a cursor on the entries for the database db in collection that match the query.
HASH
query
: database query
String
db
: database name
String
collection
: collection name
Int
skip
: skip the first elements, default: 0
Int
limit
: limit the number of objects that will be returned (default: no limit)
HASH
sort_by
: sorting of the entries, default by _id
String
username
String
password
MongoClient
client
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
db_get_list_col_for_db()
Returns a list of available collections in a database.
db_get_list_db()
Returns a list of available databases.
db_get_list_db_col()
Returns a list of available databases and collections (in the form db.collection).
String
db
: name of the database, default: all available databases
String
collection
: name of the collection, default: all available collections
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
String
username
: necessary if reading a database with access control
db_ids(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
.
HASH
query
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
Int
limit
: limit the number of objects that will be returned (default: no limit)
HASH
sort_by
: specify a sorting order
Int
skip
: skip the first elements, default: 0
String
username
: Some databases might have access control.
String
password
: Some databases might have access control.
MongoClient
client
db_info()
Print information about available databases and collections.
String
db
: name of the database, default: all available databases
String
collection
: name of the collection, default: all available collections
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
String
username
: necessary if reading a database with access control
db_metadata(Core::Object p)
Retrieve the metadata of an object
Core::Object
p
: the polyDB object
HASH
db_print_metadata(Core::Object p)
print the metadata of an object
Core::Object
p
: the polyDB object
db_query(HASH query)
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.
HASH
query
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
Int
limit
: limit the number of objects that will be returned (default: no limit)
String
username
: Some databases might have access control.
String
password
: Some databases might have access control.
MongoClient
client
Int
skip
: skip the first elements, default: 0
HASH
sort_by
: specify a sorting order
db_searchable_fields(String db, String collection)
Return the list of property names that can be searched in the database for a given database db, collection col and optional template key.
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
db_write_collection_info()
Add documentation for a collection You need write access for this.
String
db
: name of the database the description applies to
String
collection
: name of the collection the description applies to
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
Bool
replace
: whether an existing documentation should be updated or replaced
String
file
: a file with the documentation in json format, only one of file and documentation is allowed
HASH
documentation
: a perl hash with the documentation, only one of documentation and file is allowed
String
username
String
password
String
polydb_version
: version number
Bool
verbose
: verbose mode
db_write_db_info(String db)
Add a db documentation. You need write access for this.
String
db
: name of the database the description applies to
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
Bool
replace
: whether an existing documentation should be updated or replaced
String
file
: a file with the documentation in json format, only one of file and documentation is allowed
HASH
documentation
: a perl hash with the documentation, only one of documentation and file is allowed
String
username
String
password
String
polydb_version
: version number
Bool
verbose
: verbose mode
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.
String
db
: database name
String
col
: collection name
String
key
: the key of the type information
Bool
replace
: type information for this database, collection and key already exists and should be replaced
String
file
: a filename containing the type information as json document (only one of file and type_information allowed)
HASH
type_information
: the type information as per hash (only one of file and type_information allowed)
String
username
String
password
String
polyDB_version
: the version of polyDB this type information applies to
Bool
verbose
These are the functions to insert and update objects. You need write access to the database for these.
db_insert(Core::Object obj)
Adds an object obj to the collection col in the database db. Note that you need write access to the database for this.
Core::Object
obj
String
db
: name of the database
String
collection
: name of the collection
String
id
: unique identifier, this is set to the name of the object, a different name should only be used in exceptional cases. This option is only valid if a single object is added.
String
contributor
: set the contributor
Bool
local
: set to 1 if you want to use a local database (on localhost), default 0
String
username
String
password
Bool
use_type_information
: set to 1 to match properties with a template object
HASH
type_information
: object template specifying the properties to store
String
type_information_key
: template name to load from the database
Bool
nonew
: set to 1 if you don't want to compute missing properties but only delete surplus ones (only takes effect if use_type_info is also set to 1)
Bool
keep_all_props
: keep all properties present in the polymake object in the stored xml. Does not effect representation in the db. For this, provide a type information without a property mask
Bool
noinsert
: dont insert anything, just try evaluate the template
MongoClient
client
db_remove(String id)
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.
Functions for pretty printing, labels or latex output of polymake types.
labeled(Vector data, Array<String> elem_labels)
Prepares a vector for printing, prepends each element with a label and a colon.
latex(Matrix data, Array<String> elem_labels)
LaTeX output of a matrix.
Matrix
data
: to be printed
Array<String>
elem_labels
: optional labels for elements; if data is an IncidenceMatrix
, common, or similar, each element will be replaced by its label.
print_constraints(Matrix<Scalar> M)
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.
Matrix<Scalar>
M
: the matrix whose rows are to be written
Bool
homogeneous
: false if the first coordinate should be interpreted as right hand side
Bool
equations
: true if the rows represent equations instead of inequalities
> $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
rows_labeled(Matrix data, Array<String> row_labels, Array<String> elem_labels)
Prepares a matrix for printing, prepends each row with a label and a colon.
Matrix
data
: to be printed
Array<String>
elem_labels
: optional labels for elements; if data is an IncidenceMatrix
, common, or similar, each element will be replaced by its label.
> print rows_labeled(polytope::cube(2)->VERTICES,['a','b','c','d']); a:1 -1 -1 b:1 1 -1 c:1 -1 1 d:1 1 1
rows_labeled(Graph graph, Array<String> elem_labels)
Like above, but specialized for Graphs (defined for convenience: a PTL Graph is not a container)
rows_numbered(Matrix data)
Equivalent to rows_labeled
with omitted row_labels argument. Formerly called “numbered”.
Operations on graphs.
adjacency_matrix(Graph graph)
Returns the adjacency matrix of graph nodes. For a normal graph, it will be a kind of IncidenceMatrix
, for multigraph, it will be a common, with entries encoding the number of parallel edges between two nodes.
Graph
graph
edges(Graph graph)
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.
Graph
graph
node_edge_incidences<Coord>(Graph graph)
Returns the node-edge incidence matrix of a graph.
Coord
: coordinate type for the resulting matrix, default: Int
Graph
graph
SparseMatrix<Coord>
> 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)
nodes(Graph graph)
Returns the sequence of all valid nodes of a graph.
Functions for lattice related computations.
eliminate_denominators(Vector v)
Scale a vector with the least common multiple of the denominators of its coordinates.
eliminate_denominators_entire(Matrix v)
Scales entire matrix with the least common multiple of the denominators of its coordinates.
eliminate_denominators_entire_affine(Matrix v)
Scales entire matrix with the least common multiple of the denominators of its coordinates (ignore first column).
eliminate_denominators_in_rows(Matrix M)
Scale a matrix row-wise with the least common multiple of the denominators of its coordinates.
is_integral(Vector v)
Checks whether all coordinates of a rational vector are integral.
is_integral(Matrix m)
Checks whether all coordinates of a rational matrix are integral.
primitive(Vector v)
Scales the vector to a primitive integral vector.
primitive(Matrix M)
Scales each row of the matrix to a primitive integral vector.
primitive_affine(Vector v)
Scales the affine part of a vector to a primitive integral vector.
primitive_affine(Matrix M)
Scales the affine part of each row of the matrix to a primitive integral vector.
These functions are for algebraic computations and constructions of special matrices.
anti_diag(Vector d)
Produces a SparseMatrix
from its anti-diagonal.
anti_diag(Matrix m1, Matrix m2)
Returns a block anti-diagonal matrix with blocks m1 and m2.
barycenter(Matrix A)
Calculate the average over the rows of a matrix.
basis(Matrix A)
Computes subsets of the rows and columns of A that form a basis for the linear space spanned by A.
Matrix
A
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
basis_affine(Matrix A)
Does the same as basis
ignoring the first column of the matrix.
Matrix
A
basis_cols(Matrix A)
Computes a subset of the columns of A that form a basis for the linear space spanned by A.
basis_rows(Matrix A)
Computes a subset of the rows of A that form a basis for the linear space spanned by A.
basis_rows_integer(Matrix A)
Computes a lattice basis of the span of the rows of A.
Matrix
A
det(Matrix<Scalar> A)
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.
diag(Vector d)
Produces a SparseMatrix
from its diagonal.
diag(Matrix m1, Matrix m2)
Returns a block diagonal matrix with blocks m1 and m2.
equal_bases(Matrix M1, Matrix M2)
Check whether both matrices are bases of the same linear subspace. Note: It is assumed that they are *bases* of the row space.
hadamard_product(Matrix M1, Matrix M2)
Compute the Hadamard product of two matrices with same dimensions.
hermite_normal_form(Matrix M)
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.
Matrix
M
: matrix to be transformed.
Bool
reduced
: If this is false, entries to the left of a pivot are left untouched. True by default
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
householder_trafo(Vector<Float> b)
Householder transformation of Vector b. Only the orthogonal matrix reflection H is returned.
inv(Matrix A)
Computes the inverse A-1 of an invertible matrix A using Gauss elimination.
lineality_space(Matrix A)
Compute the lineality space of a matrix A.
normalized(Matrix<Float> A)
Normalize a matrix by dividing each row by its length (l2-norm).
> $A = new Matrix<Float>([1.5,2],[2.5,2.5]); > print normalized($A); 0.6 0.8 0.7071067812 0.7071067812
null_space(Matrix A)
Compute the null space of a matrix A.
null_space(Vector b)
Compute the null space of a vector b.
null_space_integer(Matrix A)
Computes the lattice null space of the integer matrix A.
Matrix
A
ones_vector<Element>(Int d)
Creates a vector with all elements equal to 1.
Element
: default: Rational
.
Int
d
: vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation.
Vector<Element>
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
pluecker(Matrix V)
Compute the vector of maximal minors of a matrix. WARNING: interpretation different in lifted_pluecker
Matrix
V
project_to_orthogonal_complement(Matrix points, Matrix orthogonal)
Projects points into the orthogonal complement of a subspace given via an orthogonal basis. The given points will be overwitten.
singular_value_decomposition(Matrix<Float> M)
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.
> $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
smith_normal_form(Matrix M, Bool inv)
Compute the Smith normal form of a given matrix M. M = L*S*R in normal case, or S = L*M*R in inverted case.
Matrix
M
: must be of integer type
Bool
inv
: if true, the companion matrices in the result will be inverted
> $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
smith_normal_form_flint(Matrix M)
Compute the Smith normal form of a given matrix M via flint.
solve_left(Matrix A, Matrix B)
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.
Matrix
A
Matrix
B
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.
solve_right(Matrix A, Matrix B)
Computes a matrix X that solves the system AX = B
Matrix
A
Matrix
B
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
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
sqr(Vector<Scalar> v)
Return the sum of the squared entries of a vector v.
Vector<Scalar>
v
Scalar
totally_unimodular(Matrix A)
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.
trace(Matrix A)
Computes the trace of a matrix.
transpose(IncidenceMatrix A)
Computes the transpose AT of an incidence matrix A, i.e., (aT)ij = aji.
transpose(Matrix A)
Computes the transpose AT of a matrix A, i.e., (aT)ij = aji.
unit_matrix<Element>(Int d)
Creates a unit matrix of given dimension
Element
: default: Rational
Int
d
: dimension of the matrix
SparseMatrix<Element>
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)
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>
unit_vector<Element>(Int d, Int pos)
Creates a SparseVector
of given length d with a one entry at position pos and zeroes elsewhere.
Element
: default: Rational
Int
d
: the dimension of the vector
Int
pos
: the position of the 1
SparseVector<Element>
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>
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)
zero_matrix<Element>(Int i, Int j)
Creates a zero matrix of given dimensions
Element
: default: Rational
Int
i
: number of rows
Int
j
: number of columns
SparseMatrix<Element>
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
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>
zero_vector<Element>(Int d)
Creates a vector with all elements equal to zero.
Element
: default: Rational
Int
d
: vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation.
Vector<Element>
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
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>
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
This category contains functions performing operations on Sets.
all_subsets_of_k(Any c, Int k)
Returns all subsets of size k of a given container as perl-array.
Int
k
: size of the subsets
range_from(Int a)
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.
scalar2set(Scalar s)
Returns the singleton set {s}.
Miscellaneous functions.
average(ARRAY array)
Returns the average value of the array elements.
ARRAY
array
> print average([1,2,3]); 2
bounding_box(Matrix m)
Compute the column-wise bounds for the given Matrix m.
Matrix
m
distance_matrix(Matrix S, CODE d)
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.
Matrix
S
CODE
d
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:
histogram(ARRAY data)
Produce a histogram of an array: each different element value is mapped on the number of its occurences.
ARRAY
data
> $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)
Return a map indexing an array of sets
> $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)}
is_nonnegative(ARRAY data)
Checks if a given sequence is nonnegative
ARRAY
data
> print is_nonnegative([1,0,3]); 1
is_unimodal(ARRAY data)
Checks if a given sequence is unimodal
maximum(ARRAY array)
Returns the maximal element of an array.
ARRAY
array
> print maximum([1,2,3,4,5,6,7,23]); 23
median(ARRAY array)
Returns the median value of the array elements.
ARRAY
array
> print median([1,2,3,9]); 2.5
minimum(ARRAY array)
Returns the minimal element of an array.
ARRAY
array
> print minimum([23,42,666]); 23
perturb_matrix(Matrix M, Float eps, Bool not_hom)
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.
Matrix
M
Float
eps
: the factor by which the random matrix is multiplied default value: 1
Bool
not_hom
: if set to 1, the first column will also be perturbed; otherwise the first columns of the input matrix M and the perturbed one coincide (useful for working with homogenized coordinates); default value: 0 (homogen. coords)
Int
seed
: controls the outcome of the random number generator; fixing a seed number guarantees the same outcome.
These functions are for visualization.
compose(Visual::Object vis_obj …)
Create a composite drawing of several objects.
Visual::Object
vis_obj …
: objects to be drawn together
String
Title
: name of the whole drawing; per default the name of the first Object is taken.
Visual::Polygons::decorations
Draw a pretty 8-pointed star:
> compose(cube(2)->VISUAL, cross(2,sqrt(2))->VISUAL, Title=>"A pretty star.", VertexLabels=>"hidden");
compose(Visual::Container vis_container, Visual::Object vis_obj …)
Add new objects to a composite drawing.
Visual::Container
vis_container
: drawing produced by some visualization function
Visual::Object
vis_obj …
: objects to be added
String
Title
: new name for the drawing
Any
decorations
: to be applied to all components as default values.
geomview(Visual::Object vis_obj …)
Run geomview to display given visual objects.
Visual::Object
vis_obj …
: objects to display
String
File
: “filename” or “AUTO” Store the objects in a gcl
(geomview control language) file instead of starting the interactive GUI. The geometric data in OFF
format is embedded in the Lisp-style commands, but can be easily extracted using any text editor, if needed. The .gcl
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
javaview(Visual::Object vis_obj …)
Run JavaView with the given visual objects.
Visual::Object
vis_obj …
: objects to display
String
File
: “filename” or “AUTO” Store the object description in a JVX file without starting the interactive GUI. The .jvx
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
jreality(Visual::Object vis_obj …)
Run jReality to display given visual objects.
Visual::Object
vis_obj …
: objects to display
String
File
: “filename” or “AUTO” Store the object description in a bean shell source file without starting the interactive GUI. The .bsh
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
postscript(Visual::Object vis_obj …)
Create a Postscript ™ drawing with the given visual objects.
Visual::Object
vis_obj …
: objects to draw
String
File
: “filename” or “AUTO” Store the drawing in a file without starting the viewer. The .ps
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
povray(Visual::Object vis_obj …)
Run POVRAY to display given visual objects.
Visual::Object
vis_obj …
: objects to display
String
File
: “filename” or “AUTO” Store the object description in a POVRAY source file without actual rendering. The .pov
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
sketch(Visual::Object vis_obj …)
Produce a Sketch input file with given visual objects.
Visual::Object
vis_obj …
: objects to display
String
File
: “filename” or “AUTO” For the file name you can use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe. Real file names are automatically completed with the .sk
suffix if needed. An automatically generated file name is displayed in the verbose mode.
static(Visual::Object vis_obj)
Suppress creation of dynamic (interactive) scenes.
Visual::Object
vis_obj
: drawing, e.g. created by VISUAL_GRAPH
or SCHLEGEL
.
svg(Visual::Object vis_obj …)
Create a Svg drawing with the given visual objects.
Visual::Object
vis_obj …
: objects to draw
String
File
: “filename” or “AUTO” Store the drawing in a file without starting the viewer. The .svg
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
threejs(Visual::Object vis_obj)
Produce an html file with given visual objects.
Visual::Object
vis_obj
: object to display
String
File
: “filename” or “AUTO” For the file name you can use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe. Real file names are automatically completed with the .html
suffix if needed. An automatically generated file name is displayed in the verbose mode.
tikz(Visual::Object vis_obj)
Produce a TikZ file with given visual objects.
Visual::Object
vis_obj
: object to display
String
File
: “filename” or “AUTO” For the file name you can use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe. Real file names are automatically completed with the .tikz
suffix if needed. An automatically generated file name is displayed in the verbose mode.
x3d(Visual::Object vis_obj …)
Create an X3D drawing with the given visual objects.
Visual::Object
vis_obj …
: objects to draw
String
File
: “filename” or “AUTO” Store the drawing in a file without starting the viewer. The .x3d
suffix is automatically added to the file name. Specify AUTO if you want the filename be automatically derived from the drawing title. You can also use any expression allowed for the open
function, including “-” for terminal output, “&HANDLE” for an already opened file handle, or “| program” for a pipe.
db_aggregate
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
db_print_searchable_fields
UNDOCUMENTED
This category contains all “algebraic” types, such as matrices, vectors, polynomials, rings, …
Matrix<Element, Sym>
Element
: default: Rational
Sym
: default: NonSymmetric
> 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: :''[[.:common#Vector |Vector]]<Element>'' ? **''clear([[.:common#Int |Int]] r, [[.:common#Int |Int]] c)''** :: Change the dimensions setting all elements to 0. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': new number of rows :: ''[[.:common#Int |Int]]'' ''c'': new number of columns ? **''col([[.:common#Int |Int]] i)''** :: Returns the //i//-th column. ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#Vector |Vector]]<Element>'' ? **''cols()''** :: Returns the number of columns. ? Returns: :''[[.:common#Int |Int]]'' ? **''diagonal([[.:common#Int |Int]] i)''** :: Returns the __diagonal__ of the matrix. ? Parameters: :: ''[[.:common#Int |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: :''[[.:common#Vector |Vector]]<Element>'' ? **''div_exact([[.:common#Int |Int]] a)''** :: Divides every entry by //a// (assuming that every entry is divisible by //a//). ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? **''elem([[.:common#Int |Int]] r, [[.:common#Int |Int]] c)''** :: Returns an element of the matrix. The return value is an `lvalue', that is, it can be modified if the matrix object is mutable. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': the row index :: ''[[.:common#Int |Int]]'' ''c'': the column index ? Returns: :''Element'' ? **''minor([[.:common#Set |Set]] r, [[.:common#Set |Set]] c)''** :: Returns a __minor__ of the matrix containing the rows in //r// and the columns in //c//. You can pass [[.:common#all_rows_or_cols |All]] if you want all rows or columns and ~ for the complement of a set. E.g. ? Parameters: :: ''[[.:common#Set |Set]]'' ''r'': the rows :: ''[[.:common#Set |Set]]'' ''c'': the columns ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: The following will give you the minor of a matrix containing all rows and all but the 0-th column. :: <code perl> > print unit_matrix(3)->minor(All, ~[0]); (2) 1 0 0 1 </code> ? **''resize([[.:common#Int |Int]] r, [[.:common#Int |Int]] c)''** :: Change the dimensions; when growing, set added elements to 0. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': new number of rows :: ''[[.:common#Int |Int]]'' ''c'': new number of columns ? **''row([[.:common#Int |Int]] i)''** :: Returns the //i//-th row. ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#Vector |Vector]]<Element>'' ? **''rows()''** :: Returns the number of rows. ? Returns: :''[[.:common#Int |Int]]''
Plucker<Scalar>
Scalar
: default: Rational
coordinates
UNDOCUMENTED
permuted
UNDOCUMENTED
Polynomial<Coefficient, Exponent>
Coefficient
: default: Rational
Exponent
: default: Int
coefficients_as_vector()
The vector of all coefficients. The sorting agrees with monomials_as_matrix
.
Vector<Coefficient>
constant_coefficient()
The constant coefficient.
deg()
The degree of the polynomial
embed(Int nvars)
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
.
get_var_names
set the variable names
initial_form(Vector<Exponent> v)
The initial form with respect to a weight-vector v
Vector<Exponent>
v
: weights
lc()
The leading coefficient.
lm()
The exponent of the leading monomial.
mapvars(Array<Int> indices, Int nvars)
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.
monomial(Int var_index, Int n_vars)
construct a monomial of degree 1 with a given variable
monomials_as_matrix()
The matrix of all exponent vectors (row-wise). The sorting agrees with coefficients_as_vector
.
SparseMatrix<Exponent>
n_vars()
Number of variables
print_ordered(Matrix m)
Print a polynomial with terms sorted according to a given Matrix
m.
Matrix
m
project()
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
.
> $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
reset_var_names
reset the variable names according to the default naming scheme
set_var_names
set the variable names
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.
trivial()
The polynomial is zero.
PuiseuxFraction<MinMax, Coefficient, Exponent>
Coefficient
: default: Rational
Exponent
: default: Rational
evaluate(Matrix m, Coefficient x, Int exp)
Evaluate all PuiseuxFraction
s in a Matrix
at a Rational
number (x^exp). 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.
Matrix
m
Coefficient
x
Int
exp
: (default: 1)
Matrix<Coefficient>
The evaluation can also be applied to containers, unfortunately static methods dont play nicely with the perl interface but the following can be used:
> $m = long_and_winding(2)->FACETS; > print ((typeof PuiseuxFraction<Max>)->pkg->evaluate($m,2,4)); (5) (0 256) (1 -1) (5) (0 16) (2 -1) (5) (1 16) (3 -1) (5) (2 16) (3 -1) 0 4 4 0 -1 (5) (3 1) (5) (4 1)
evaluate(Vector v, Coefficient x, Int exp)
Evaluate all PuiseuxFraction
s in a Vector
at a Rational
number (x^exp). 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.
evaluate(Coefficient x, Int exp)
Evaluate a PuiseuxFraction
at a Rational
number (x^exp). 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.
Coefficient
x
Int
exp
: (default: 1)
Coefficient
evaluate_float(Float x)
Approximate evaluation at x
Float
x
evaluate_float(Matrix m, Float x)
Approximate evaluation of a Matrix
at x
evaluate_float(Vector v, Float x)
Approximate evaluation of a Vector
at x
val()
The valuation.
TropicalNumber<MinMax>
> $x = monomials<Rational,Rational>(1); > print new PuiseuxFraction<Max>(2*$x*$x-$x+2)->val; 2
The valuation can also be applied to Containers via convert_to
> $m = long_and_winding(3)->FACETS; > print convert_to<TropicalNumber<Max>>($m); (7) (0 2) (1 0) (7) (0 1) (2 0) (7) (1 1) (3 0) (7) (2 1) (3 0) (7) (1 1/2) (2 1/2) (4 0) (7) (3 1) (5 0) (7) (4 1) (5 0) (7) (3 3/4) (4 3/4) (6 0) (7) (5 0) (7) (6 0)
RationalFunction<Coefficient, Exponent>
the same with type deduction
SparseMatrix<Element, Sym>
A SparseMatrix is a special form of a Matrix
optimized for large matrices with few non-zero elements. Physically it is stored as a two-dimensional grid of balanced binary trees with row and column indexes as search keys. Use dense
to convert a sparsematric into the dense form.
Element
Sym
: one of Symmetric
or NonSymmetric
, default: NonSymmetric
construct a SparseMatrix from a list of row vectors. Each row can be specified in a dense or sparse form. Number of columns is determined by the size of dense rows or by the maximal index value in sparse rows.
> $A = new SparseMatrix<Integer>( > [0, 1, 0, 0, 0], > {4 => 2}, > {}, > [3, -1, 0, 0, 0]); > print $A; (5) (1 1) (5) (4 2) (5) (5) (0 3) (1 -1)
construct a SparseMatrix with explicitly given number of columns:
> $A = new SparseMatrix<Integer>( > {1 => 10}, > {2 => 20}, > {cols => 5}); > print $A; (5) (1 10) (5) (2 20)
resize(Int r, Int c)
Resize the matrix All elements in added rows and/or columns are implicit zeros.
squeeze
Removes empty rows and columns. The remaining rows and columns are renumbered without gaps.
squeeze_cols
Removes empty columns. The remaining columns are renumbered without gaps.
squeeze_rows
Removes empty rows. The remaining rows are renumbered without gaps.
SparseVector<Element>
A SparseVector is a special form of a Vector
optimized for large vectors with few non-zero elements. Physically it is stored as a balanced binary tree with element index as a search key. 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 a sparse vector into the dense form.
Element
construct a SparseVector from a contiguous list of scalars; zero values are filtered out automatically:
> $v = new SparseVector<Integer>(0, 1, 2, 0, 0, 0); > print $v, "\n"; (6) (1 1) (2 2)
construct a SparseVector from a hash map with non-zero values; dimension is provided explicitly:
> $v = new SparseVector<Integer>({ 1 => 1, 2 => 2, _dim => 6 }); > print $v, "\n"; (6) (1 1) (2 2)
size()
The number of non-zero entries.
UniPolynomial<Coefficient, Exponent>
A class for univariate polynomials.
Coefficient
: default: Rational
Exponent
: default: Int
coefficients_as_vector()
The vector of all coefficients. The sorting agrees with monomials_as_vector
.
Vector<Coefficient>
constant_coefficient()
The constant coefficient.
deg()
The highest degree occuring in the polynomial.
Exponent
evaluate(Coefficient x, Exponent exp)
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.
Coefficient
x
Exponent
exp
: (default: 1)
Coefficient
evaluate_float(Float x)
Approximate evaluation of the polynomial at a Float
x.
Float
x
get_var_names
get the variable name
lc()
The leading coefficient.
lower_deg()
The lowest degree occuring in the polynomial.
Exponent
monomial
create a monomial of degree 1
monomials_as_vector()
The vector of all exponents. The order agrees with coefficients_as_vector
.
Vector<Exponent>
n_vars
Number of variables
print_ordered(Exponent x)
Print a polynomial with terms sorted according to exponent*x.
Exponent
x
reset_var_names
reset the variable name according to the default naming scheme
set_var_names
set the variable name
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
Vector<Element>
A type for vectors with entries of type Element. You can perform algebraic operations such as addition or scalar multiplication.
Element
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]);
all_rows_or_cols
Use the keyword “All” for all rows or columns, e.g. when constructing a minor
.
These types are needed as return types of arithmetic computations.
Div<Scalar>
The complete result of an integral division
Scalar
: type supporting modulo division, e.g. Integer
or UniPolynomial
quot()
the quotient
Scalar
rem()
the remainder
Scalar
ExtGCD<Scalar>
The complete result of the calculation of the greatest common divisor of two numbers a and b:
Max
tropical addition: max
apply
UNDOCUMENTED
orientation
UNDOCUMENTED
Min
tropical addition: min
apply
UNDOCUMENTED
orientation
UNDOCUMENTED
TropicalNumber<Addition, Scalar>
Addition
Scalar
: default: Rational
orientation()
The orientation of the associated addition, i.e. +1 if the corresponding 0 is +inf -1 if the corresponding 0 is -inf
zero()
The zero element of the tropical semiring of this element.
Scalar
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.
CachedObjectPointer<>
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.
Directed
Type tag for a directed Graph
.
DirectedMulti
Type tag for a directed multigraph.
EdgeIterator
EdgeList
Iterator<Element>
An iterator over a sequence of objects. The objects may be stored in a container or be generated on the fly.
Element
LocalFloatEpsilon
NonSymmetric
Labels a Matrix
or an IncidenceMatrix
as non-symmetric.
Serialized<X>
X
Symmetric
Labels a Matrix
or an IncidenceMatrix
as symmetric.
Undirected
Type tag for an undirected Graph
.
UndirectedMulti
Type tag for an undirected multigraph.
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
, …
AccurateFloat
A wrapper for AccurateFloat.
Array<Element>
An array with elements of type Element. Corresponds to the C++ type Array
.
Element
size()
Returns the size.
Bool
Corresponds to the C++ type bool.
Float
Corresponds to the C++ type double.
inf
produce an infinitely large positive value
minus_inf
produce an infinitely large negative value
Int
Corresponds to the C++ type int.
Integer
An integer of arbitrary size.
inf
produce an infinitely large positive value
minus_inf
produce an infinitely large negative value
List<Element>
Corresponds to the C++ type std::list.
Element
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.
Pair<First, Second>
Corresponds to the C++ type std::pair.
First
Second
QuadraticExtension<Field>
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).
Field
: default: Rational
Rational
A class for rational numbers. You can easily create a Rational like that: $x = 1/2;
inf
Produce an infinitely large positive value.
minus_inf
Produce an infinitely large negative value.
String
Corresponds to the C++ type std::string.
Text
Plain text without any imposed structure.
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
This contains all property types that are related to graphs.
EdgeHashMap<Dir, Element>
Sparse mapping of edges to data items.
Dir
: one of Undirected
, Directed
, UndirectedMulti
or DirectedMulti
Element
: data associated with edges
edge(Int from, Int to)
Access the data associated with an edge between two given nodes. The new data element is created on demand.
erase(Int from, Int to)
Delete the data associated with an edge between two given nodes.
find(Int from, Int to)
Access the data associated with an edge between two given nodes.
EdgeMap<Dir, Element>
Dense mapping of edges to data items.
Dir
: kind of the host graph, Undirected
, Directed
, UndirectedMulti
, or DirectedMulti
Element
: data associated with edges
Graph<Dir>
Dir
: one of Undirected
, Directed
, UndirectedMulti
or DirectedMulti
, default: Undirected
add_edge(Int tail_node, Int head_node)
In a multigraph, creates a new edge connecting two given nodes. In a normal graph, creates a new edge only if the nodes were not connected yet. Returns the index of the (new) edge.
add_node()
Add a new node without incident edes.
adjacent_nodes(Int node)
Returns the set of indices of nodes adjacent to node.
Int
node
all_edges(Int tail_node, Int head_node)
Returns an iterator visiting all (parallel) edges connecting two given nodes.
contract_edge(Int node1, Int node2)
Contract the edge(s) between node1 and node2. Reconnects all edges from node2 to node1, deleting the edge(s) between them and, finally, deleting node2.
degree(Int node)
Returns the number of edges incident to node.
Int
node
delete_all_edges(Int tail_node, Int head_node)
Deletes all edges in a multigraph connecting two given nodes.
delete_edge(Int tail_node, Int head_node)
Deletes the edge connecting two given nodes, if there was one. In a multigraph, deletes one arbitrary edge from the parallel bundle.
delete_edge(Iterator iterator)
Delete the edge in a multigraph pointed to by the given iterator
delete_node(Int node)
Deletes all edges incident to the given node and marks it as invalid. The numeration of other nodes stays unchanged.
Int
node
dim()
Returns the maximal node index + 1. If the graph does not have gaps caused by node deletion, the result is equivalent to nodes
().
edge(Int tail_node, Int head_node)
Returns the index of the edge connecting two given nodes. The edge is created if was not there. In a multigraph, an arbitrary edge from the parallel bundle will be picked.
edge_exists(Int tail_node, Int head_node)
Checks whether two given nodes are connected by (at least) one edge.
edges()
Get the total number of edges.
has_gaps()
Returns true if some nodes have been deleted since the last squeeze
operation.
in_adjacent_nodes(Int node)
Returns the set of indices of the nodes that have an edge heading to node.
Int
node
in_degree(Int node)
Returns the number of edges heading to node.
Int
node
in_edges(Int node)
Returns a sequence of edges heading to (in Directed case) or incident to (in Undirected case) node.
Int
node
invalid_node(Int node)
Returns true if the given node index is either out of valid range or points to a formerly deleted node.
Int
node
node_exists(Int node)
Check whether the node with given index exists.
Int
node
node_out_of_range(Int node)
Returns true if the given node index is out of valid range.
Int
node
nodes()
Get the total number of nodes.
out_adjacent_nodes(Int node)
Returns the set of indices of the nodes with an edge arriving from node.
Int
node
out_degree(Int node)
Returns the number of edges leaving node.
Int
node
out_edges(Int node)
Returns a sequence of edges leaving (in Directed case) or incident to (in Undirected case) node.
Int
node
permute_inv_nodes
permute the nodes param perm inverse permutation of node indexes
permute_nodes
permute the nodes param perm permutation of node indexes
squeeze
Renumbers the valid nodes as to eliminate all gaps left after deleting.
squeeze_isolated
Deletes all nodes of degree 0, then renumbers the remaining nodes without gaps.
GraphMap<Dir, Element>
The common abstract base class for all kinds of associative containers that can be attached to a Graph
.
Dir
: kind of the host graph: Undirected
, Directed
, UndirectedMulti
, or DirectedMulti
Element
: data associated with nodes or edges
NodeHashMap<Dir, Element>
Sparse mapping of nodes to data items.
Dir
: one of Undirected
, Directed
, UndirectedMulti
or DirectedMulti
Element
: data associated with nodes
NodeMap<Dir, Element>
Dense mapping of nodes to data items.
Dir
: kind of the host graph, Undirected
, Directed
, UndirectedMulti
, or DirectedMulti
Element
: data associated with nodes
These types are needed as return types of algebraic computations.
HermiteNormalForm<Scalar>
Complete result of the Hermite normal form computation of the input matrix M.
Scalar
: matrix element type
companion()
unimodular matrix R such that M*R = H
SparseMatrix<Scalar>
hnf()
the Hermite normal form
Matrix<Scalar>
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:
left_companion()
matrix of left singular vectors
right_companion()
matrix of right singular vectors
sigma()
the diagonalized matrix
SmithNormalForm<Scalar>
Complete result of the Smith normal form computation of the input matrix M.
Scalar
: matrix element type
form()
the Smith normal form
SparseMatrix<Scalar>
left_companion()
unimodular matrix L such that M = L*S*R
SparseMatrix<Scalar>
rank()
rank of M
right_companion()
unimodular matrix R such that M = L*S*R
SparseMatrix<Scalar>
torsion()
absolute values of the entries greater than 1 of the diagonal together with their multiplicity
In this category you find all property types related to sets, such as Set, Map, HashMap, IncidenceMatrix, …
ApproximateSet<Element>
A specialization of Sets containing elements of type Element, but where equality is enforced only up to a global epsilon.
Element
: default: Float
You can for example create a new ApproximateSet with two elements by:
> $s = new ApproximateSet(1.1, 1.2, 1.200000001);
Bitset
Container class for dense sets of integers. A special class optimized for representation of a constrained range of non-negative integer numbers.
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 common 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.
erase(Set f)
Remove a facet.
Set
f
: facet to remove
eraseSubsets(Set s)
Remove all subsets of a given set
Set
s
: filter for removal
eraseSupersets(Set s)
Remove all supersets of a given set
Set
s
: filter for removal
find(Set f)
Look up a facet.
Set
f
: facet to find
findSubsets(Set s)
Find all subsets of a given set.
Set
s
findSupersets(Set s)
Find all supersets of a given set.
Set
s
insert(Set f)
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.
Set
f
: facet to add.
insertMax(Set f)
Add a new facet if and only if there are no facets including it. If this holds, remove all facets that are included in the new one.
Set
f
: facet to add
insertMin(Set f)
Add a new facet if and only if there are no facets included in it. If this holds, remove all facets including the new facet.
Set
f
: facet to add
n_vertices()
The number of vertices
size()
The number of facets in the list.
HashMap<Key, 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). 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).
Key
: type of the key values
Value
: type of the mapped value
You can create a new HashMap mapping Ints to Strings by
> $myhashmap = new HashMap<Int, String>([1, "Monday"], [2, "Tuesday"]);
size()
Size of the map
HashSet<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.
Element
size()
The cardinality of the set.
IncidenceMatrix<Sym>
A 0/1 incidence matrix.
Sym
: one of Symmetric
or NonSymmetric
, default: NonSymmetric
col(Int i)
Returns the i-th column.
Int
i
cols()
Returns the number of columns.
elem(Int r, Int c)
Returns an element of the matrix as a boolean value. The return value is an `lvalue', that is, it can be assigned to, flipped, etc. if the matrix object is mutable.
minor(Set r, Set c)
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.
row(Int i)
Returns the i-th row.
Int
i
rows()
Returns the number of rows.
squeeze
Removes empty rows and columns. The remaining rows and columns are renumbered without gaps.
squeeze_cols
Removes empty columns. The remaining columns are renumbered without gaps.
squeeze_rows
Removes empty rows. The remaining rows are renumbered without gaps.
Map<Key, 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.
Key
: type of the key values
Value
: type of the mapped value
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}; Monday
PowerSet<Element>
A Set
whose elements are of type Set<Element>.
Element
: default: Int
Set<Element>
A type for ordered sets containing elements of type Element.
Element
: default: Int
You can for example create a new Set by:
> $s1 = new Set(2, 3, 5, 7); > $s2 = new Set(4, 5);
You can perform set theoretic operations: union
> print $s1 + $s2; {2 3 4 5 7}
intersection
> print $s1 * $s2; {5}
difference
> print $s1 - $s2; {2 3 7}
symmetric difference
> print $s1 ^ $s2; {2 3 4 7}
back()
The last element of the set, that is, the largest element
collect(Element e)
Add to the set, report true if existed formerly.
Element
e
: element to insert into the set
contains(Element e)
Check if e is contained in the set.
Element
e
: element check for
front()
The first element of the set, that is, the smallest element
size()
The cardinality of the set.
These property_types are for visualization.
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):
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.
HSV
A color described as a Hue-Saturation-Value triple. Is convertible to and from an RGB representation.
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.