====== 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 ===== ** ''[[.:common:PermBase |PermBase]]'':\\ Base class for permutations of `big' objects ** ''[[.:common:PolyDB_Client |PolyDB::Client]]'':\\ A live connection to a PolyDB server. This is a starting point for all operations on the database. ** ''[[.:common:PolyDB_Collection |PolyDB::Collection]]'':\\ Represents a collection in PolyDB ** ''[[.:common:PolyDB_Cursor |PolyDB::Cursor]]'':\\ Database cursor over the results of a query operation. Objects can be retrieved in a loop, fetching one at a time, or all at once. ** ''[[.:common:Visual_Container |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. ** ''[[.:common:Visual_Object |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 ===== ==== Arithmetic ==== These are functions that perform arithmetic computations. ---- {{anchor:ceil:}} ? **''ceil([[.:common#Rational |Rational]] a)''** :: The __ceiling function__. Returns the smallest integral number not smaller than //a//. ? Parameters: :: ''[[.:common#Rational |Rational]]'' ''a'' ? Returns: :''[[.:common#Rational |Rational]]'' ---- {{anchor:denominator:}} ? **''denominator([[.:common#Rational |Rational]] a)''** :: Returns the __denominator__ of //a// in a reduced representation. ? Parameters: :: ''[[.:common#Rational |Rational]]'' ''a'' ? Returns: :''[[.:common#Integer |Integer]]'' ? **''denominator([[.:common#RationalFunction |RationalFunction]] f)''** :: Returns the __denominator__ of a ''[[.:common#RationalFunction |RationalFunction]]'' //f//. ? Parameters: :: ''[[.:common#RationalFunction |RationalFunction]]'' ''f'' ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? **''denominator([[.:common#PuiseuxFraction |PuiseuxFraction]] f)''** :: Returns the __denominator__ of a ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' //f//. ? Parameters: :: ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' ''f'' ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ---- {{anchor:div:}} ? **''div(//Scalar// a, //Scalar// b)''** :: Compute the quotient and remainder of //a// and //b// in one operation. ? Parameters: :: ''//Scalar//'' ''a'' :: ''//Scalar//'' ''b'' ? Returns: :''[[.:common#Div |Div]]'' ? Example: :: > $d = div(10,3); > print $d->quot; 3 :: > print $d->rem; 1 ---- {{anchor:div_exact:}} ? **''div_exact([[.:common#Integer |Integer]] a, [[.:common#Integer |Integer]] b)''** :: Computes the ratio of two given integral numbers under the assumption that the dividend is a multiple of the divisor. ? Parameters: :: ''[[.:common#Integer |Integer]]'' ''a'' :: ''[[.:common#Integer |Integer]]'' ''b'': a divisor of //a// ? Returns: :''[[.:common#Integer |Integer]]'' ? Example: :: > print div_exact(10,5); 2 ---- {{anchor:ext_gcd:}} ? **''ext_gcd(//Scalar// a, //Scalar// b)''** :: Compute the greatest common divisor of two numbers (a,b) and accompanying co-factors. ? Parameters: :: ''//Scalar//'' ''a'' :: ''//Scalar//'' ''b'' ? Returns: :''[[.:common#ExtGCD |ExtGCD]]'' ? 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; -2 :: ...and the quotients k1 of a and k2 of b by g. :: > print $GCD->k1; 5 :: > print $GCD->k2; 2 ---- {{anchor:fac:}} ? **''fac([[.:common#Int |Int]] n)''** :: Computes the factorial //n//! = n·(n-1)·(n-2)·...·2·1. ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'': >=0 ? Returns: :''[[.:common#Integer |Integer]]'' ---- {{anchor:floor:}} ? **''floor([[.:common#Rational |Rational]] a)''** :: The __floor function__. Returns the smallest integral number not larger than //a//. ? Parameters: :: ''[[.:common#Rational |Rational]]'' ''a'' ? Returns: :''[[.:common#Rational |Rational]]'' ? Example: :: > print floor(1.8); 1 ---- {{anchor:gcd:}} ? **''gcd([[.:common#Int |Int]] a, [[.:common#Int |Int]] b)''** :: Computes the __greatest common divisor__ of two integers. ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'' :: ''[[.:common#Int |Int]]'' ''b'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print gcd(6,9); 3 ? **''gcd([[.:common#Vector |Vector]] v)''** :: Compute the __greatest common divisor__ of the elements of the given vector. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''//Scalar//'' ? Example: :: > $v = new Vector(3,6,9); > print gcd($v); 3 ? **''gcd([[.:common#UniPolynomial |UniPolynomial]] p, [[.:common#UniPolynomial |UniPolynomial]] q)''** :: Returns the __greatest common divisor__ of two univariate polynomials. ? Parameters: :: ''[[.:common#UniPolynomial |UniPolynomial]]'' ''p'' :: ''[[.:common#UniPolynomial |UniPolynomial]]'' ''q'' ? Returns: :''[[.:common#UniPolynomial |UniPolynomial]]'' ? Example: :: We create two UniPolynomials with said coefficient and exponent type: :: > $p = new UniPolynomial([2,2],[3,2]); > $q = new UniPolynomial([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 ---- {{anchor:get_var_names:}} ? **''get_var_names()''** :: Get the current list of variable names used for pretty printing and string parsing of the given polynomial class ? Returns: :''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ---- {{anchor:is_one:}} ? **''is_one(//Scalar// s)''** :: Compare with the one (1) value of the corresponding data type. ? Parameters: :: ''//Scalar//'' ''s'' ? Returns: :''[[.:common#Bool |Bool]]'' ---- {{anchor:is_zero:}} ? **''is_zero(//Scalar// s)''** :: Compare with the zero (0) value of the corresponding data type. ? Parameters: :: ''//Scalar//'' ''s'' ? Returns: :''[[.:common#Bool |Bool]]'' ---- {{anchor:isfinite:}} ? **''isfinite(//Scalar// a)''** :: Check whether the given number has a finite value. ? Parameters: :: ''//Scalar//'' ''a'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: > print isfinite('inf'); false :: > print isfinite(23); true ---- {{anchor:isinf:}} ? **''isinf(//Scalar// a)''** :: Check whether the given number has an infinite value. Return -1/+1 for infinity and 0 for all finite values. ? Parameters: :: ''//Scalar//'' ''a'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print isinf('inf'); 1 :: > print isinf(23); 0 ---- {{anchor:lcm:}} ? **''lcm([[.:common#Int |Int]] a, [[.:common#Int |Int]] b)''** :: Computes the __least common multiple__ of two integers. ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'' :: ''[[.:common#Int |Int]]'' ''b'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print lcm(6,9); 18 ? **''lcm([[.:common#Vector |Vector]] v)''** :: Compute the __least common multiple__ of the elements of the given vector. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''//Scalar//'' ? Example: :: > $v = new Vector(1,3,6,9); > print lcm($v); 18 ---- {{anchor:local_var_names:}} ? **''local_var_names([[.:common#String |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 ''[[.:core#prefer_now |prefer_now]]''. ? Parameters: :: ''[[.:common#String |String]]'' ''names ...'': variable names, see ''[[.:common#set_var_names |set_var_names]]''. ---- {{anchor:monomials:}} ? **''monomials([[.:common#Int |Int]] n)''** :: Create degree one monomials of the desired polynomial type. ? Type Parameters: :: ''Coefficient'': The polynomial coefficient type. Rational by default. :: ''Exponent'': The exponent type. Int by default. ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'': The number of variables ? Returns: :''[[.:common#UniPolynomial |UniPolynomial]]'' ---- {{anchor:numerator:}} ? **''numerator([[.:common#Rational |Rational]] a)''** :: Returns the __numerator__ of //a// in a reduced representation. ? Parameters: :: ''[[.:common#Rational |Rational]]'' ''a'' ? Returns: :''[[.:common#Integer |Integer]]'' ? **''numerator([[.:common#RationalFunction |RationalFunction]] f)''** :: Returns the __numerator__ of a ''[[.:common#RationalFunction |RationalFunction]]'' //f//. ? Parameters: :: ''[[.:common#RationalFunction |RationalFunction]]'' ''f'' ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? **''numerator([[.:common#PuiseuxFraction |PuiseuxFraction]] f)''** :: Returns the __numerator__ of a ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' //f//. ? Parameters: :: ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' ''f'' ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ---- {{anchor:set_var_names:}} ? **''set_var_names([[.:common#String |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. ? Parameters: :: ''[[.:common#String |String]]'' ''names ...'': variable names; may also be bundled in an array an empty list resets to the default naming scheme ---- {{anchor:sum_of_square_roots_naive:}} ? **''sum_of_square_roots_naive([[.:common#Array |Array]]<[[.:common#Rational |Rational]]> input_array)''** :: Make a naive attempt to sum the square roots of the entries of the input array. ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Rational |Rational]]>'' ''input_array'': a list of rational numbers (other coefficients are not implemented). ? Returns: :''[[.:common#Map |Map]]<[[.:common#Rational |Rational]],[[.:common#Rational |Rational]]>'' ? from extension: : [[:external_software|bundled:flint]] ? Example: :: To obtain sqrt{3/4} + sqrt{245}, type :: > print sum_of_square_roots_naive(new Array([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. ---- ==== Combinatorics ==== Combinatorial functions. ---- {{anchor:all_permutations:}} ? **''all_permutations([[.:common#Int |Int]] n)''** :: Returns a list of all permutations of the set {0...n-1} as a perl-array ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'' ? Returns: :''[[.:common#Array |Array]]<[[.:common#Array |Array]]<[[.:common#Int |Int]]%%>>%%'' ? Example: :: > print all_permutations(3); 0 1 2 1 0 2 2 0 1 0 2 1 1 2 0 2 1 0 ---- {{anchor:are_permuted:}} ? **''are_permuted([[.:common#Array |Array]] a, [[.:common#Array |Array]] b)''** :: Determine whether two arrays //a// and //b// are permuted copies of each other. ? Parameters: :: ''[[.:common#Array |Array]]'' ''a'' :: ''[[.:common#Array |Array]]'' ''b'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: > print are_permuted([1,8,3,4],[3,8,4,1]); true ---- {{anchor:binomial:}} ? **''binomial([[.:common#Int |Int]] n, [[.:common#Int |Int]] k)''** :: Compute the binomial coefficient __//n// choose //k//__. Negative values of //n// (and //k//) are supported. ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'' :: ''[[.:common#Int |Int]]'' ''k'' ? Returns: :''[[.:common#Integer |Integer]]'' ? Example: :: Print 6 choose 4 like this: :: > print binomial(6,4); 15 ---- {{anchor:fibonacci:}} ? **''fibonacci([[.:common#Int |Int]] n)''** :: Compute the __n__-th Fibonacci number ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'' ? Returns: :''[[.:common#Integer |Integer]]'' ? Example: :: > print fibonacci(6); 8 ---- {{anchor:fibonacci2:}} ? **''fibonacci2([[.:common#Int |Int]] n)''** :: Compute the __n__-th and __n__-1-th Fibonacci numbers ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'' ? Returns: :''[[.:common#List |List]]<[[.:common#Integer |Integer]]>'' ? Example: :: > print join " ", fibonacci2(6); 8 5 ---- {{anchor:find_permutation:}} ? **''find_permutation([[.:common#Array |Array]] a, [[.:common#Array |Array]] b)''** :: Returns the permutation that maps //a// to //b//. ? Parameters: :: ''[[.:common#Array |Array]]'' ''a'' :: ''[[.:common#Array |Array]]'' ''b'' ? Returns: :''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ? Example: :: > $p = find_permutation([1,8,3,4],[3,8,4,1]); > print $p; 2 1 3 0 ---- {{anchor:n_fixed_points:}} ? **''n_fixed_points([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the number of fixed points of the permutation given by //p//. ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print n_fixed_points([1,0,2,4,3]); 1 ---- {{anchor:permutation_cycle_lengths:}} ? **''permutation_cycle_lengths([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the sorted cycle lengths of a permutation ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ? Example: :: > print permutation_cycle_lengths(new Array([1,2,0,4,3])); 2 3 ---- {{anchor:permutation_cycles:}} ? **''permutation_cycles([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the __cycles__ of a permutation given by //p//. ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''ARRAY'' ? Example: :: > print permutation_cycles([1,0,3,2]); {0 1}{2 3} ---- {{anchor:permutation_matrix:}} ? **''permutation_matrix([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the __permutation matrix__ of the permutation given by //p//. ? Type Parameters: :: ''Scalar'': default: ''[[.:common#Int |Int]]'' ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? 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) ---- {{anchor:permutation_order:}} ? **''permutation_order([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the order of a permutation ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print permutation_order(new Array([1,2,0,4,3])); 6 ---- {{anchor:permutation_sign:}} ? **''permutation_sign([[.:common#Array |Array]]<[[.:common#Int |Int]]> p)''** :: Returns the __sign__ of the permutation given by //p//. ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''p'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > print permutation_sign([1,0,3,2]); 1 ---- ==== Data Conversion ==== This contains functions for data conversions and type casts. ---- {{anchor:cast:}} ? **''cast([[.:core:Core_BigObject |Core::BigObject]] 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. ? Type Parameters: :: ''Target'': the desired new type ? Parameters: :: ''[[.:core:Core_BigObject |Core::BigObject]]'' ''object'': to be modified ? Returns: :''[[.:core:Core_BigObject |Core::BigObject]]'' ---- {{anchor:cols:}} ? **''cols''** ::UNDOCUMENTED ? **''cols([[.:common#Matrix |Matrix]] A)''** :: Returns a ''[[.:common#Container |Container]]'' with the columns of the ''[[.:common#Matrix |Matrix]]'' //A//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#Container |Container]]<[[.:common#Vector |Vector]]>'' ? Example: :: 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 ---- {{anchor:concat_rows:}} ? **''concat_rows([[.:common#Matrix |Matrix]] M)''** :: Concatenates the rows of the ''[[.:common#Matrix |Matrix]]'' //M//. If //M// is a ''[[.:common#SparseMatrix |SparseMatrix]]'', then the resulting vector is sparse as well. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Vector |Vector]]'' ? 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) ---- {{anchor:convert_to:}} ? **''convert_to(//Scalar// s)''** :: Explicit conversion to a different scalar type. ? Type Parameters: :: ''Target'' ? Parameters: :: ''//Scalar//'' ''s'' ? Returns: :''Target'' ? **''convert_to([[.:common#Vector |Vector]] v)''** :: Explicit conversion to a different element type. ? Type Parameters: :: ''Target'' ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $v = new Vector(1/2,2/3,3/4); > $vf = convert_to($v); > print $vf; 0.5 0.6666666667 0.75 ? **''convert_to([[.:common#Matrix |Matrix]] m)''** :: Explicit conversion to a different element type. ? Type Parameters: :: ''Target'' ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1/2,2],[3,2/3]); > $Mf = convert_to($M); > print $Mf; 0.5 2 3 0.6666666667 ? **''convert_to([[.:common#Polynomial |Polynomial]] m)''** :: Explicit conversion to a different coefficient type. ? Type Parameters: :: ''Target'' ? Parameters: :: ''[[.:common#Polynomial |Polynomial]]'' ''m'' ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? **''convert_to([[.:common#UniPolynomial |UniPolynomial]] m)''** :: Explicit conversion to a different coefficient type. ? Type Parameters: :: ''Target'' ? Parameters: :: ''[[.:common#UniPolynomial |UniPolynomial]]'' ''m'' ? Returns: :''[[.:common#UniPolynomial |UniPolynomial]]'' ---- {{anchor:dense:}} ? **''dense([[.:common#Vector |Vector]] v)''** :: Return the input ''[[.:common#Vector |Vector]]'' (which is already in the dense form). ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]'' ? **''dense([[.:common#Matrix |Matrix]] M)''** :: Return the input ''[[.:common#Matrix |Matrix]]'' (which is already in dense form). ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? **''dense([[.:common#SparseVector |SparseVector]] v)''** :: Convert to an equivalent dense vector of the same element type. Returns the input ''[[.:common#SparseVector |SparseVector]]'' as a dense ''[[.:common#Vector |Vector]]'' of the same element type. ? Type Parameters: :: ''Element'' ? Parameters: :: ''[[.:common#SparseVector |SparseVector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $v = new SparseVector([0,1,2,0,0,0]); > print($v); (6) (1 1) (2 2) :: > print(dense($v)); 0 1 2 0 0 0 ? **''dense([[.:common#SparseMatrix |SparseMatrix]] M)''** :: Returns the input ''[[.:common#SparseMatrix |SparseMatrix]]'' as a dense ''[[.:common#Matrix |Matrix]]'' of the same element type. ? Type Parameters: :: ''Element'' ? Parameters: :: ''[[.:common#SparseMatrix |SparseMatrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new SparseMatrix([[0,0,1],[0,0,0],[0,2,0]]); > print($M); (3) (2 1) (3) (3) (1 2) :: > print(dense($M)); 0 0 1 0 0 0 0 2 0 ? **''dense([[.:common#IncidenceMatrix |IncidenceMatrix]] M)''** :: Converts an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' to a dense 0/1 ''[[.:common#Matrix |Matrix]]''. ? Parameters: :: ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Int |Int]]>'' ? Example: :: > $M = polytope::cube(2)->VERTICES_IN_FACETS; > print(dense($M)); 1 0 1 0 0 1 0 1 1 1 0 0 0 0 1 1 ? **''dense([[.:common#Set |Set]] S, [[.:common#Int |Int]] dim)''** :: Converts the given ''[[.:common#Set |Set]]'' to a dense 0/1 ''[[.:common#Vector |Vector]]'' of a given dimension. ? Parameters: :: ''[[.:common#Set |Set]]'' ''S'' :: ''[[.:common#Int |Int]]'' ''dim'' ? Returns: :''[[.:common#Vector |Vector]]<[[.:common#Int |Int]]>'' ? Example: :: > $S = new Set([0,1]); > print(dense($S,3)); 1 1 0 ---- {{anchor:index_matrix:}} ? **''index_matrix([[.:common#SparseMatrix |SparseMatrix]] M)''** :: Gets the positions of non-zero entries of a ''[[.:common#SparseMatrix |SparseMatrix]]''. ? Parameters: :: ''[[.:common#SparseMatrix |SparseMatrix]]'' ''M'' ? Returns: :''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ? Example: :: > $S = new SparseMatrix([1,2,0,0,0,0],[0,0,5,0,0,32]); > print index_matrix($S); {0 1} {2 5} ---- {{anchor:indices:}} ? **''indices([[.:common#SparseVector |SparseVector]] v)''** :: Get the positions of non-zero entries of a ''[[.:common#SparseVector |SparseVector]]''. ? Parameters: :: ''[[.:common#SparseVector |SparseVector]]'' ''v'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > $v = new SparseVector(0,1,1,0,0,0,2,0,3); > print indices($v); {1 2 6 8} ---- {{anchor:lex_ordered:}} ? **''lex_ordered([[.:common#FacetList |FacetList]] f)''** :: Visit the facets of //f// sorted lexicographically. ? Parameters: :: ''[[.:common#FacetList |FacetList]]'' ''f'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%%'' ? Example: :: > $f = new FacetList(polytope::cube(2)->VERTICES_IN_FACETS); > print lex_ordered($f); {{0 1} {0 2} {1 3} {2 3}} ---- {{anchor:repeat_col:}} ? **''repeat_col([[.:common#Vector |Vector]] v, [[.:common#Int |Int]] i)''** :: Create a ''[[.:common#Matrix |Matrix]]'' by repeating the given ''[[.:common#Vector |Vector]]'' as cols. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $v = new Vector(23,42,666); > $M = repeat_col($v,3); > print $M; 23 23 23 42 42 42 666 666 666 ---- {{anchor:repeat_row:}} ? **''repeat_row([[.:common#Vector |Vector]] v, [[.:common#Int |Int]] i)''** :: Create a ''[[.:common#Matrix |Matrix]]'' by repeating the given ''[[.:common#Vector |Vector]]'' //v// as rows //i// many times. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $v = new Vector(23,42,666); > $M = repeat_row($v,3); > print $M; 23 42 666 23 42 666 23 42 666 ---- {{anchor:rows:}} ? **''rows''** ::UNDOCUMENTED ? **''rows([[.:common#Matrix |Matrix]] A)''** :: Returns a ''[[.:common#Container |Container]]'' with the rows of the ''[[.:common#Matrix |Matrix]]'' //A//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#Container |Container]]<[[.:common#Vector |Vector]]>'' ? Example: :: 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 ---- {{anchor:support:}} ? **''support([[.:common#Vector |Vector]] v)''** :: Gets the positions of non-zero entries of a ''[[.:common#Vector |Vector]]''. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > print support(new Vector(0,23,0,0,23,0,23,0,0,23)); {1 4 6 9} ---- {{anchor:tomatrix:}} ? **''toMatrix([[.:common#IncidenceMatrix |IncidenceMatrix]] M)''** :: Converts an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' to a ''[[.:common#SparseMatrix |SparseMatrix]]''. ? Type Parameters: :: ''Scalar'' ? Parameters: :: ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ''M'' ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $M = polytope::cube(2)->VERTICES_IN_FACETS; > print $M->type->full_name; IncidenceMatrix :: > print(toMatrix($M)->type->full_name); SparseMatrix ---- {{anchor:totropicalpolynomial:}} ? **''toTropicalPolynomial([[.:common#String |String]] s, [[.:common#String |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 occurring variables as total number of variables and create a ring for the result. The variables will be sorted alphabetically. ? Parameters: :: ''[[.:common#String |String]]'' ''s'': The string to be parsed :: ''[[.:common#String |String]]'' ''vars'': Optional list of variables. If this is given, all variables used in s must match one of the variables in this list. ? Returns: :''[[.:common#Polynomial |Polynomial]]<[[.:common#TropicalNumber |TropicalNumber]]>%%'' ---- {{anchor:tovector:}} ? **''toVector([[.:common#Set |Set]] S, [[.:common#Int |Int]] d)''** :: Creates a ''[[.:common#SparseVector |SparseVector]]'' with dimension //d// and having 1's at positions contained in the given ''[[.:common#Set |Set]]'' //S//. ? Type Parameters: :: ''Scalar'': type of apparent 1's ? Parameters: :: ''[[.:common#Set |Set]]'' ''S'' :: ''[[.:common#Int |Int]]'' ''d'': dimension of the result ? Returns: :''[[.:common#SparseVector |SparseVector]]'' ? Example: :: > $v = toVector(new Set([0,1]), 5); > print($v); (5) (0 1) (1 1) ---- {{anchor:vector2col:}} ? **''vector2col([[.:common#Vector |Vector]] v)''** :: Convert a ''[[.:common#Vector |Vector]]'' to a ''[[.:common#Matrix |Matrix]]'' with a single column. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Matrix |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 ---- {{anchor:vector2row:}} ? **''vector2row([[.:common#Vector |Vector]] v)''** :: Convert a ''[[.:common#Vector |Vector]]'' to a ''[[.:common#Matrix |Matrix]]'' with a single row. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Matrix |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 ---- ==== Database Access ==== Core methods for connecting to the database and retrieving metadata. ---- {{anchor:polydb:}} ? **''polyDB([[.:common#String |String]] host)''** :: Connect to PolyDB server, create a session object ? Parameters: :: ''[[.:common#String |String]]'' ''host'': Host address of the PolyDB server in form "hostname" or "hostname:port"; default location is db.polymake.org, can be customized in $PolyDB::default::db_host ? Options: : :: ''[[.:common#String |String]]'' ''user'': user name for the database; default is "polymake" with read-only access to all public collections, can be customized in $PolyDB::default::db_user :: ''[[.:common#String |String]]'' ''password'': password for the database; when omitted, will be prompted for in the polymake shell; can be customized in $PolyDB::default::db_pwd :: ''[[.:common#String |String]]'' ''auth_db'': name of the authentication database where the user is defined; default is "admin", can be customized in $PolyDB::default::db_auth_db :: ''[[.:common#Bool |Bool]]'' ''useSSL'': use tls for connection; default is true, can be customized in $PolyDB::default::useSSL :: ''[[.:common#Bool |Bool]]'' ''tlsAllowInvalidHostnames'': validate ; default is true, can be customized in $PolyDB::default::tlsAllowInvalidHostnames :: ''[[.:common#Bool |Bool]]'' ''tlsAllowInvalidCertificates'': validate ; default is true, can be customized in $PolyDB::default::tlsAllowInvalidCertificates :: ''[[.:common#String |String]]'' ''port'': of the database; default is 27017, can be customized in $PolyDB::default::db_port :: ''[[.:common#Int |Int]]'' ''serverSelectionTimeout'': timeout for new server connections; default is 0 to use mongodb default, can be customized in $PolyDB::default::serverSelectionTimeout ? Returns: :''[[.:common:PolyDB_Client |PolyDB::Client]]'' ? from extension: : [[:external_software|bundled:polydb]] ? Example: :: Connect to the public polymake server as a user "polymake" with read-only permissions :: > $polyDB=polyDB(); :: Connect to a local PolyDB server for testing purposes without authentication :: > $testDB=polyDB("localhost"); :: Connect to a custom server with authentication, prompting for a password input :: > $otherDB=polyDB("otherdb.my.domain", user=>"myname"); ---- ==== Formatting ==== Functions for pretty printing, labels or [[.:common#latex |latex output]] of polymake types. ---- {{anchor:labeled:}} ? **''labeled([[.:common#Vector |Vector]] data, [[.:common#Array |Array]]<[[.:common#String |String]]> elem_labels)''** :: Prepares a vector for printing, prepends each element with a label and a colon. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''data'': to be printed :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''elem_labels'': optional labels for elements; if //data// is a ''[[.:common#Set |Set]]'', or similar, each element will be replaced by its label. ? Returns: :''[[.:common#String |String]]'' ? Example: :: > $v = new Vector(0,1,2); > print labeled($v,["zeroth","first","second"]); zeroth:0 first:1 second:2 ---- {{anchor:latex:}} ? **''latex([[.:common#Matrix |Matrix]] data, [[.:common#Array |Array]]<[[.:common#String |String]]> elem_labels)''** :: LaTeX output of a matrix. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''data'': to be printed :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''elem_labels'': optional labels for elements; if //data// is an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'', [[]], or similar, each element will be replaced by its label. ? Returns: :''[[.:common#String |String]]'' ---- {{anchor:numbered:}} ? **''numbered([[.:common#Vector |Vector]] data)''** :: Equivalent to ''[[.:common#labeled |labeled]]'' with omitted //elem_labels// argument. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''data'': to be printed ? Returns: :''[[.:common#String |String]]'' ? Example: :: > $data = new Vector(23,42,666); > print numbered($data); 0:23 1:42 2:666 ---- {{anchor:print_constraints:}} ? **''print_constraints([[.:common#Matrix |Matrix]] 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//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': the matrix whose rows are to be written ? Options: : :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''coord_labels'': changes the labels of the coordinates :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''row_labels'': changes the labels of the rows :: ''[[.:common#Bool |Bool]]'' ''homogeneous'': false if the first coordinate should be interpreted as right hand side :: ''[[.:common#Bool |Bool]]'' ''equations'': true if the rows represent equations instead of inequalities ? 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 ---- {{anchor:rows_labeled:}} ? **''rows_labeled([[.:common#Matrix |Matrix]] data, [[.:common#Array |Array]]<[[.:common#String |String]]> row_labels, [[.:common#Array |Array]]<[[.:common#String |String]]> elem_labels)''** :: Prepares a matrix for printing, prepends each row with a label and a colon. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''data'': to be printed :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''row_labels'': labels for the rows :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''elem_labels'': optional labels for elements; if //data// is an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'', [[]], or similar, each element will be replaced by its label. ? Returns: :''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ? Example: :: > 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([[.:common#GraphAdjacency |GraphAdjacency]] graph, [[.:common#Array |Array]]<[[.:common#String |String]]> elem_labels)''** :: Like above, but specialized for Graphs (defined for convenience: a PTL Graph is not a container) ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'': to be printed :: ''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ''elem_labels'': labels for the elements ? Returns: :''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ? Example: :: > print rows_labeled(graph::cycle_graph(4)->ADJACENCY, ['a','b','c','d']); a:b d b:a c c:b d d:a c ---- {{anchor:rows_numbered:}} ? **''rows_numbered([[.:common#Matrix |Matrix]] data)''** :: Equivalent to ''[[.:common#rows_labeled |rows_labeled]]'' with omitted //row_labels// argument. Formerly called "numbered". ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''data'': to be printed ? Returns: :''[[.:common#Array |Array]]<[[.:common#String |String]]>'' ? Example: :: > print rows_numbered(polytope::cube(2)->VERTICES); 0:1 -1 -1 1:1 1 -1 2:1 -1 1 3:1 1 1 ---- ==== Graph Operations ==== Operations on graphs. ---- {{anchor:adjacency_matrix:}} ? **''adjacency_matrix([[.:common#GraphAdjacency |GraphAdjacency]] graph)''** :: Returns the adjacency matrix of graph nodes. For a normal graph, it will be a kind of ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'', for multigraph, it will be a [[]], with entries encoding the number of parallel edges between two nodes. ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'' ? Returns: :''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ---- {{anchor:edges:}} ? **''edges([[.:common#GraphAdjacency |GraphAdjacency]] 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. ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'' ? Returns: :''[[.:common#EdgeList |EdgeList]]'' ---- {{anchor:induced_subgraph:}} ? **''induced_subgraph([[.:common#GraphAdjacency |GraphAdjacency]] graph, [[.:common#Set |Set]] set)''** :: Creates an induced subgraph for the given subset of nodes. ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'' :: ''[[.:common#Set |Set]]'' ''set'': indices of selected nodes ? Returns: :''[[.:common#GraphAdjacency |GraphAdjacency]]'' ? Example: :: > $g = new GraphAdjacency(graph::cycle_graph(5)->ADJACENCY); > $s1 = new Set(1,2,3); > print induced_subgraph($g,$s1); (5) (1 {2}) (2 {1 3}) (3 {2}) ---- {{anchor:node_edge_incidences:}} ? **''node_edge_incidences([[.:common#GraphAdjacency |GraphAdjacency]] graph)''** :: Returns the node-edge incidence matrix of a graph. ? Type Parameters: :: ''Coord'': coordinate type for the resulting matrix, default: ''[[.:common#Int |Int]]'' ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'' ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? 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) ---- {{anchor:nodes:}} ? **''nodes([[.:common#GraphAdjacency |GraphAdjacency]] graph)''** :: Returns the sequence of all valid nodes of a graph. ? Parameters: :: ''[[.:common#GraphAdjacency |GraphAdjacency]]'' ''graph'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > print nodes(graph::cycle_graph(5)->ADJACENCY); {0 1 2 3 4} ---- ==== Lattice Tools ==== Functions for lattice related computations. ---- {{anchor:eliminate_denominators:}} ? **''eliminate_denominators([[.:common#Vector |Vector]] v)''** :: Scale a vector with the least common multiple of the denominators of its coordinates. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]<[[.:common#Integer |Integer]]>'' ? Example: :: > $v = new Vector(1/2,1/3,1/4,1/5); > $ve = eliminate_denominators($v); > print $ve; 30 20 15 12 ---- {{anchor:eliminate_denominators_entire:}} ? **''eliminate_denominators_entire([[.:common#Matrix |Matrix]] v)''** :: Scales entire matrix with the least common multiple of the denominators of its coordinates. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''v'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? 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 ---- {{anchor:eliminate_denominators_entire_affine:}} ? **''eliminate_denominators_entire_affine([[.:common#Matrix |Matrix]] v)''** :: Scales entire matrix with the least common multiple of the denominators of its coordinates (ignore first column). ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''v'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? 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 ---- {{anchor:eliminate_denominators_in_rows:}} ? **''eliminate_denominators_in_rows([[.:common#Matrix |Matrix]] M)''** :: Scale a matrix row-wise with the least common multiple of the denominators of its coordinates. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? 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 ---- {{anchor:is_integral:}} ? **''is_integral([[.:common#Vector |Vector]] v)''** :: Checks whether all coordinates of a rational vector are integral. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: This rational vector has only integral entries: :: > $v = new Vector(1,2,3,4); :: polytope > print is_integral($v); :: But if we append 1/2, it isn't anymore: :: > print is_integral($v|1/2); false ? **''is_integral([[.:common#Matrix |Matrix]] m)''** :: Checks whether all coordinates of a rational matrix are integral. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: This rational matrix has only integral entries: :: > $m = new Matrix([1,2],[3,4]); > print is_integral($m); true :: But if we multiply it with 1/2, that is not the case anymore. :: > print is_integral(1/2 * $m); false ---- {{anchor:primitive:}} ? **''primitive([[.:common#Vector |Vector]] v)''** :: Scales the vector to a primitive integral vector. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]<[[.:common#Integer |Integer]]>'' ? Example: :: > print primitive(new Vector(3,3/2,3,3)); 2 1 2 2 ? **''primitive([[.:common#Matrix |Matrix]] M)''** :: Scales each row of the matrix to a primitive integral vector. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? Example: :: > print primitive(new Matrix([1,3/2],[3,1])); 2 3 3 1 ---- {{anchor:primitive_affine:}} ? **''primitive_affine([[.:common#Vector |Vector]] v)''** :: Scales the affine part of a vector to a primitive integral vector. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Vector |Vector]]<[[.:common#Integer |Integer]]>'' ? Example: :: > print primitive_affine(new Vector(1,3/2,1,1)); 1 3 2 2 ? **''primitive_affine([[.:common#Matrix |Matrix]] M)''** :: Scales the affine part of each row of the matrix to a primitive integral vector. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? Example: :: > print primitive_affine(new Matrix([1,1,3/2],[1,3,1])); 1 2 3 1 3 1 ---- ==== Linear Algebra ==== These functions are for algebraic computations and constructions of special matrices. ---- {{anchor:anti_diag:}} ? **''anti_diag([[.:common#Vector |Vector]] d)''** :: Produces a ''[[.:common#SparseMatrix |SparseMatrix]]'' with the given ''[[.:common#Vector |Vector]]'' //d// as anti-diagonal. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''d'': the anti-diagonal entries ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $M = anti_diag(new Vector([0,1,2])); > print $M; (3) (2 2) (3) (1 1) (3) :: To print a more human-readable representation, use the dense() function: :: > print dense($M); 0 0 2 0 1 0 0 0 0 ? **''anti_diag([[.:common#Matrix |Matrix]] M1, [[.:common#Matrix |Matrix]] M2)''** :: Returns a __block anti-diagonal matrix__ with blocks //M1// and //M2//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M1'' :: ''[[.:common#Matrix |Matrix]]'' ''M2'' ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $M = anti_diag(unit_matrix(2),unit_matrix(3)); > print $M; (5) (2 1) (5) (3 1) (5) (4 1) (5) (0 1) (5) (1 1) :: To print a more human-readable representation, use the dense() function: :: > print dense($M); 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 0 ---- {{anchor:barycenter:}} ? **''barycenter([[.:common#Matrix |Matrix]] M)''** :: Calculate the average over the rows of a ''[[.:common#Matrix |Matrix]]'', i.e., where i-th entry corrsponds to the mean of i-th column vector. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $M = new Matrix([2,-3,-2],[1,-1,1],[-1,2,2]); > print barycenter($M); 2/3 -2/3 1/3 ---- {{anchor:basis:}} ? **''basis([[.:common#Matrix |Matrix]] A)''** :: Computes subsets of the rows and columns of the ''[[.:common#Matrix |Matrix]]'' //A// that form a basis for the linear space spanned by //A//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#Pair |Pair]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]>,[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%%'' ? 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 ---- {{anchor:basis_affine:}} ? **''basis_affine([[.:common#Matrix |Matrix]] A)''** :: Does the same as ''[[.:common#basis |basis]]'' ignoring the first column of the matrix. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#Pair |Pair]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]>,[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%%'' ? Example: :: Let us illustrate this using the same matrix in the example for ''[[.:common#basis |basis]]''. :: > $M = new Matrix ([[1,0,0,0],[2,0,0,0],[0,1,0,0],[0,0,1,0]]); > ($row,$col) = basis_affine($M); > print"$row \n$col"; {2 3} {1 2} :: > print $M->minor($row,All); 0 1 0 0 0 0 1 0 :: > print $M->minor(All,$col); 0 0 0 0 1 0 0 1 ---- {{anchor:basis_cols:}} ? **''basis_cols([[.:common#Matrix |Matrix]] M)''** :: Computes a subset of the columns of the ''[[.:common#Matrix |Matrix]]'' //M// that form a basis for the linear space spanned by //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? 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]]); > print(basis_cols($M)); {0 1 2} :: 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 ---- {{anchor:basis_rows:}} ? **''basis_rows([[.:common#Matrix |Matrix]] M)''** :: Computes a subset of the rows of the ''[[.:common#Matrix |Matrix]]'' //M// that form a basis for the linear space spanned by the rows of //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? 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]]); > print(basis_rows($M)); {0 2 3} :: 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 ---- {{anchor:cramer:}} ? **''cramer([[.:common#Matrix |Matrix]] A, [[.:common#Vector |Vector]] b)''** :: Computes the solution of the system //A//x = //b// for a given invertible ''[[.:common#Matrix |Matrix]]'' //A// and a ''[[.:common#Vector |Vector]]'' //b// by applying Cramer's rule. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'': must be invertible :: ''[[.:common#Vector |Vector]]'' ''b'' ? Returns: :''[[.:common#Vector |Vector]]'' ? 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 ---- {{anchor:det:}} ? **''det([[.:common#Matrix |Matrix]] A)''** :: Computes the __determinant__ of a ''[[.:common#Matrix |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. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''//Scalar//'' ? Example: :: > print det(unit_matrix(3)); 1 ? Example: :: > $p = new UniPolynomial("x2+3x"); > $M = new Matrix>([[$p, $p+1],[$p+1,$p]]); > print det($M); -2*x^2 -6*x - 1 ---- {{anchor:diag:}} ? **''diag([[.:common#Vector |Vector]] d)''** :: Produces a ''[[.:common#SparseMatrix |SparseMatrix]]'' with given ''[[.:common#Vector |Vector]]'' //d// as diagonal. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''d'': the diagonal entries ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $v = new Vector(1,2,3,4); > $D = diag($v); > print $D; (4) (0 1) (4) (1 2) (4) (2 3) (4) (3 4) :: To print a more human-readable representation, use the dense() function: :: > print dense($D); 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 4 ? **''diag([[.:common#Matrix |Matrix]] m1, [[.:common#Matrix |Matrix]] m2)''** :: Returns a __block diagonal matrix__ with blocks //m1// and //m2//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m1'' :: ''[[.:common#Matrix |Matrix]]'' ''m2'' ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $m1 = new Matrix([1,2],[3,4]); > $m2 = new Matrix([1,0,2],[3,4,0]); > $D = diag($m1,$m2); > print $D; (5) (0 1) (1 2) (5) (0 3) (1 4) 0 0 1 0 2 0 0 3 4 0 :: To print a more human-readable representation, use the dense() function: :: > print dense($D); 1 2 0 0 0 3 4 0 0 0 0 0 1 0 2 0 0 3 4 0 ---- {{anchor:eigenvalues:}} ? **''eigenvalues([[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]> M)''** :: Returns the eigenvalues of the given ''[[.:common#Matrix |Matrix]]'' //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ''M'' ? Returns: :''[[.:common#Vector |Vector]]<[[.:common#Float |Float]]>'' ? Example: :: > $M = new Matrix([[2,0,0],[0,3,4],[0,4,9]]); > print(eigenvalues($M)); 2 11 1 ---- {{anchor:equal_bases:}} ? **''equal_bases([[.:common#Matrix |Matrix]] M1, [[.:common#Matrix |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. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M1'' :: ''[[.:common#Matrix |Matrix]]'' ''M2'' ? Returns: :''[[.:common#Bool |Bool]]'' ? 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 ---- {{anchor:hadamard_product:}} ? **''hadamard_product([[.:common#Matrix |Matrix]] M1, [[.:common#Matrix |Matrix]] M2)''** :: Compute the Hadamard product of two matrices with same dimensions. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M1'' :: ''[[.:common#Matrix |Matrix]]'' ''M2'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ---- {{anchor:hermite_normal_form:}} ? **''hermite_normal_form([[.:common#Matrix |Matrix]] M)''** :: Computes the (column) Hermite normal form of an integer ''[[.:common#Matrix |Matrix]]''. Pivot entries are positive, entries to the left of a pivot are non-negative and strictly smaller than the pivot. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': matrix to be transformed. ? Options: : :: ''[[.:common#Bool |Bool]]'' ''reduced'': If this is false, entries to the left of a pivot are left untouched. True by default ? Returns: :''[[.:common#HermiteNormalForm |HermiteNormalForm]]'' ? Example: :: The following stores the result for a small matrix M in H and then prints both hnf and companion: :: > $M = new Matrix([1,2],[2,3]); > $H = hermite_normal_form($M); > print $H->hnf; 1 0 0 1 :: > print $H->companion; -3 2 2 -1 ---- {{anchor:householder_trafo:}} ? **''householder_trafo([[.:common#Vector |Vector]]<[[.:common#Float |Float]]> b)''** :: Householder transformation of ''[[.:common#Vector |Vector]]'' //b//. Only the orthogonal matrix reflection H is returned. ? Parameters: :: ''[[.:common#Vector |Vector]]<[[.:common#Float |Float]]>'' ''b'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ---- {{anchor:inv:}} ? **''inv([[.:common#Matrix |Matrix]] M)''** :: Computes the __inverse__ //M//-1 of an invertible ''[[.:common#Matrix |Matrix]]'' //M// using Gauss elimination. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: We save the inverse of a small matrix M in the variable $iM: :: > $M = new Matrix([1,2],[3,4]); > $iM = inv($M); :: 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 ---- {{anchor:lattice_basis:}} ? **''lattice_basis([[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]> A)''** :: Computes a lattice basis of the span of the rows of //A//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ''A'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Integer |Integer]]>'' ? Example: :: No two of the rows of the following matrix form a basis. :: > $A = new Matrix([[2,3],[1,3],[2,4]]); > print lattice_basis($A); 2 3 -1 -1 ---- {{anchor:lin_solve:}} ? **''lin_solve([[.:common#Matrix |Matrix]] A, [[.:common#Vector |Vector]] b)''** :: Computes the ''[[.:common#Vector |Vector]]'' x that solves the system //A//x = //b// for an invertible ''[[.:common#Matrix |Matrix]]'' A. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'': must be invertible :: ''[[.:common#Vector |Vector]]'' ''b'' ? Returns: :''[[.:common#Vector |Vector]]'' ? 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 ---- {{anchor:lineality_space:}} ? **''lineality_space([[.:common#Matrix |Matrix]] M)''** :: Computes the __lineality space__ of a ''[[.:common#Matrix |Matrix]]'' //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,1,0,0],[1,0,1,0]); > print lineality_space($M); 0 0 0 1 ---- {{anchor:moore_penrose_inverse:}} ? **''moore_penrose_inverse([[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]> M)''** :: Computes the Moore-Penrose Inverse of a ''[[.:common#Matrix |Matrix]]'' //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ? Example: :: > $M = new Matrix([1,0],[0,1],[0,1]); > print(moore_penrose_inverse($M)); 1 0 0 0 0.5 0.5 ---- {{anchor:normalized:}} ? **''normalized([[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]> M)''** :: Normalize a ''[[.:common#Matrix |Matrix]]'' by dividing each row by its length (l2-norm). ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ? Example: :: > $M = new Matrix([1.5,2],[2.5,2.5]); > print normalized($M); 0.6 0.8 0.7071067812 0.7071067812 ---- {{anchor:null_space:}} ? **''null_space([[.:common#Matrix |Matrix]] M)''** :: Computes the __null space__ of a ''[[.:common#Matrix |Matrix]]'' //M//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,2,0],[2,0,2]); > print null_space($M); -1 1/2 1 ? **''null_space([[.:common#Vector |Vector]] v)''** :: Computes the __null space__ of a ''[[.:common#Vector |Vector]]'' //v//. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $v = new Vector(1,2,3); > print null_space($v); -2 1 0 -3 0 1 ---- {{anchor:null_space_integer:}} ? **''null_space_integer([[.:common#Matrix |Matrix]] A)''** :: Computes the __lattice null space__ of the integer ''[[.:common#Matrix |Matrix]]'' //A//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: > $M = new Matrix([1,0,0,0],[1,0,1,0],[0,0,1,0]); > print null_space_integer($M); (4) (1 1) (4) (3 1) ---- {{anchor:ones_matrix:}} ? **''ones_matrix([[.:common#Int |Int]] m, [[.:common#Int |Int]] n)''** :: Creates a ''[[.:common#Matrix |Matrix]]'' with \\n\\ rows and \\m\\ columns such that all elements equal to 1. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]''. ? Parameters: :: ''[[.:common#Int |Int]]'' ''m'': number of rows :: ''[[.:common#Int |Int]]'' ''n'': number of columns ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: The following creates an all-ones matrix with Rational coefficients. :: > $M = ones_matrix(2,3); > print $M; 1 1 1 1 1 1 ---- {{anchor:ones_vector:}} ? **''ones_vector([[.:common#Int |Int]] d)''** :: Creates a ''[[.:common#Vector |Vector]]'' with all elements equal to 1. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]''. ? Parameters: :: ''[[.:common#Int |Int]]'' ''d'': vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation. ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: The following stores and prints an integer vector of dimension 3 with all entries equal to 1: :: > $v = ones_vector(3); > print $v; 1 1 1 ---- {{anchor:pluecker:}} ? **''pluecker([[.:common#Matrix |Matrix]] M)''** :: Compute the vector of maximal minors of the matrix //M//. See also ''[[.:tropical#tpluecker |tpluecker]]'' which is related. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: with parameters (2,4) :: > $M = new Matrix([[1,0],[0,1],[1,1],[1,3]]); > print pluecker($M); 1 1 3 -1 -1 2 ---- {{anchor:project_to_orthogonal_complement:}} ? **''project_to_orthogonal_complement([[.:common#Matrix |Matrix]] M, [[.:common#Matrix |Matrix]] N)''** :: Projects the row ''[[.:common#Matrix |Matrix]]'' //M// of points into the [[.:common#null_space |orthogonal complement]] of a subspace given by the rows of the ''[[.:common#Matrix |Matrix]]'' //N//. The points of //M// will be overwitten. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': row matrix of the points that will be projected :: ''[[.:common#Matrix |Matrix]]'' ''N'': row matrix of the basis elements ? Example: :: > $M = new Matrix([1,0,2],[2,0,1],[3,2,3]); > $N = new Matrix([1,0,0],[0,1,0]); > project_to_orthogonal_complement($M,$N); > print $M; 0 0 2 0 0 1 0 0 3 ---- {{anchor:qr_decomp:}} ? **''qr_decomp([[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]> M)''** :: QR decomposition of a mxn ''[[.:common#Matrix |Matrix]]'' //M// with m greater than or equal to n. ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ''M'' ? Returns: :''[[.:common#Pair |Pair]]<[[.:common#Matrix |Matrix]],[[.:common#Matrix |Matrix]]>'' ? Example: :: > $M = new Matrix([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 ---- {{anchor:rank:}} ? **''rank([[.:common#Matrix |Matrix]] A)''** :: Computes the __rank__ of a ''[[.:common#Matrix |Matrix]]''. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > $M = new Matrix([[1,2,3],[2,3,2],[3,4,2]]); > print rank($M); 3 ---- {{anchor:rank_mod_p:}} ? **''rank_mod_p([[.:common#Matrix |Matrix]] M, [[.:common#Integer |Integer]] p)''** :: Computes the rank of a given matrix //M// in GF(p), where //p// is a prime number. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': must be of integer type :: ''[[.:common#Integer |Integer]]'' ''p'': must be a prime, the modulus. ? Returns: :''[[.:common#Integer |Integer]]'' ? from extension: : [[:external_software|bundled:flint]] ? Example: :: > $M = new Matrix([0,1,1],[1,0,1],[1,1,0]); > $RK = rank_mod_p($M, 2); > print $RK; 2 ---- {{anchor:reduce:}} ? **''reduce([[.:common#Matrix |Matrix]] A, [[.:common#Vector |Vector]] b)''** :: Reduce a vector with a given ''[[.:common#Matrix |Matrix]]'' using Gauss elimination. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' :: ''[[.:common#Vector |Vector]]'' ''b'' ? Returns: :''[[.:common#Vector |Vector]]'' ---- {{anchor:remove_zero_rows:}} ? **''remove_zero_rows([[.:common#Matrix |Matrix]] M)''** :: Remove all zero rows from a ''[[.:common#Matrix |Matrix]]''. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,2,0],[0,0,0],[1,1,0]); > print(remove_zero_rows($M)); 1 2 0 1 1 0 ---- {{anchor:singular_value_decomposition:}} ? **''singular_value_decomposition([[.:common#Matrix |Matrix]]<[[.:common#Float |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 third V. ? Parameters: :: ''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ''M'' ? Returns: :''[[.:common#SingularValueDecomposition |SingularValueDecomposition]]'' ? Example: :: > $M = new Matrix([1,2],[23,24]); > $SVD = singular_value_decomposition($M); :: The following prints the three matrices, separated 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 :: > print $SVD->left_companion * $SVD->sigma * transpose($SVD->right_companion); 1 2 23 24 ---- {{anchor:smith_normal_form:}} ? **''smith_normal_form([[.:common#Matrix |Matrix]] M, [[.:common#Bool |Bool]] inv)''** :: Computes the __Smith normal form__ of a given ''[[.:common#Matrix |Matrix]]'' //M//. M = L*S*R in normal case, or S = L*M*R in inverted case. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': must be of integer type :: ''[[.:common#Bool |Bool]]'' ''inv'': if true, the companion matrices in the result will be inverted ? Returns: :''[[.:common#SmithNormalForm |SmithNormalForm]]'' ? Example: :: > $M = new Matrix([1,2],[23,24]); > $SNF = smith_normal_form($M); :: The following line prints the three matrices separated 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 ---- {{anchor:smith_normal_form_flint:}} ? **''smith_normal_form_flint([[.:common#Matrix |Matrix]] M)''** :: Compute the __Smith normal form__ of a given matrix //M// via flint. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'': must be of integer type ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]<[[.:common#Integer |Integer]]>'' ? from extension: : [[:external_software|bundled:flint]] ? Example: :: > $M = new Matrix([1,2],[23,24]); > $SNF = smith_normal_form_flint($M); > print $SNF; 1 0 0 22 ---- {{anchor:solve_left:}} ? **''solve_left([[.:common#Matrix |Matrix]] A, [[.:common#Matrix |Matrix]] B)''** :: Computes a ''[[.:common#Matrix |Matrix]]'' X that solves the system //XA// = //B//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' :: ''[[.:common#Matrix |Matrix]]'' ''B'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: This is useful, for instance, for computing the coordinates of some vectors with respect to a basis. The rows of the matrix solve_left(A,B) are the coordinates of the rows of //B// with respect to the rows of //A//. Define the matrices :: > $A = new Matrix([[-1,1,0],[0,-1,1]]); > $B = new Matrix([[-4,2,2],[3,-2,-1]]); :: so that the rows of //A// are a basis of the subspace of vectors with zero coordinate sum. Then the rows of :: > print solve_left($A, $B); 4 2 -3 -1 :: contain the coordinates of the rows of //B// with respect to the rows of //A//. ---- {{anchor:solve_right:}} ? **''solve_right([[.:common#Matrix |Matrix]] A, [[.:common#Matrix |Matrix]] B)''** :: Computes a ''[[.:common#Matrix |Matrix]]'' X that solves the system //AX// = //B// ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''A'' :: ''[[.:common#Matrix |Matrix]]'' ''B'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? 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 ---- {{anchor:sqr:}} ? **''sqr([[.:common#Vector |Vector]] v)''** :: Return the sum of the squared entries of a ''[[.:common#Vector |Vector]]'' //v//. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' ? Returns: :''//Scalar//'' ? Example: :: > $v = new Vector([1,-1,2]); > print(sqr($v)); 6 ---- {{anchor:totally_unimodular:}} ? **''totally_unimodular([[.:common#Matrix |Matrix]] M)''** :: A naive test(exponential in the size of matrix) to check if a ''[[.:common#Matrix |Matrix]]'' //M// is totally unimodular. The matrix //M// is totally unimodular if the determinant of each square submatrix equals 0, 1, or -1. For a better implementation try Matthias Walter's polymake extension at [[https://github.com/xammy/unimodularity-test/wiki/Polymake-Extension]]. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: > $M = new Matrix([-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 ---- {{anchor:trace:}} ? **''trace([[.:common#Matrix |Matrix]] M)''** :: Computes the __trace__ of a ''[[.:common#Matrix |Matrix]]''. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''//Scalar//'' ? Example: :: > $M = new Matrix([1,2,3],[23,24,25],[0,0,1]); > print trace($M); 26 ---- {{anchor:transpose:}} ? **''transpose([[.:common#IncidenceMatrix |IncidenceMatrix]] A)''** :: Computes the __transpose__ //A//T of an incidence matrix //A//, i.e., (aT)ij = aji. ? Parameters: :: ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ''A'' ? Returns: :''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ? **''transpose([[.:common#Matrix |Matrix]] M)''** :: Computes the __transpose__ //M//T of a ''[[.:common#Matrix |Matrix]]'' //M//, i.e., (MT)ij = Mji. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,2,23],[23,22,21]); > $Mt = transpose($M); > print $Mt; 1 23 2 22 23 21 ---- {{anchor:unit_matrix:}} ? **''unit_matrix([[.:common#Int |Int]] d)''** :: Creates a unit matrix of given dimension. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]'' ? Parameters: :: ''[[.:common#Int |Int]]'' ''d'': dimension of the matrix ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? Example: :: The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) and prints it: :: > $M = unit_matrix(3); > print $M; (3) (0 1) (3) (1 1) (3) (2 1) :: > print $M->type->full_name; SparseMatrix ? Example: :: The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) of type Int in a variable and prints it: :: > $M = unit_matrix(3); > print $M->type->full_name; SparseMatrix ---- {{anchor:unit_vector:}} ? **''unit_vector([[.:common#Int |Int]] d, [[.:common#Int |Int]] pos)''** :: Creates a ''[[.:common#SparseVector |SparseVector]]'' of given length //d// with an entry 1 at position //pos// and zeroes elsewhere. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]'' ? Parameters: :: ''[[.:common#Int |Int]]'' ''d'': the dimension of the vector :: ''[[.:common#Int |Int]]'' ''pos'': the position of the 1 ? Returns: :''[[.:common#SparseVector |SparseVector]]'' ? Example: :: The following stores a vector of dimension 5 with a single 1 (as a Rational) at position 2: :: > $v = unit_vector(5,2); > print $v; (5) (2 1) :: > print(dense($v)); 0 0 1 0 0 ? Example: :: The following stores a vector of dimension 5 with a single 1 (as a Int) at position 2: :: > $v = unit_vector(5,2); > print $v->type->full_name; SparseVector ? 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) ---- {{anchor:zero_matrix:}} ? **''zero_matrix([[.:common#Int |Int]] i, [[.:common#Int |Int]] j)''** :: Creates a zero matrix of given dimensions. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]'' ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'': number of rows :: ''[[.:common#Int |Int]]'' ''j'': number of columns ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: The following stores a 2x3 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 :: > print $M->type->full_name; Matrix ? Example: :: The following stores a 2x3 matrix with 0 as entries from type Int in a variable and prints its type: :: > $M = zero_matrix(2,3); > print $M->type->full_name; Matrix ---- {{anchor:zero_vector:}} ? **''zero_vector([[.:common#Int |Int]] d)''** :: Creates a ''[[.:common#Vector |Vector]]'' with all elements equal to zero. ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]'' ? Parameters: :: ''[[.:common#Int |Int]]'' ''d'': vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation. ? Returns: :''[[.:common#Vector |Vector]]'' ? 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(5); > print $v->type->full_name; Vector ? 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 ---- ==== Set Operations ==== This category contains functions performing operations on [[.:common#Set |Sets]]. ---- {{anchor:all_subsets:}} ? **''all_subsets(Any c)''** :: Returns all subsets of size k of a given container as perl-array. ? Parameters: :: ''Any'' ''c'': any container type, e.g. ''[[.:common#Set |Set]]'' or ''[[.:common#Array |Array]]'' ? Returns: :''[[.:common#Array |Array]]<[[.:common#Array |Array]]>%%'' ---- {{anchor:all_subsets_of_k:}} ? **''all_subsets_of_k(Any c, [[.:common#Int |Int]] k)''** :: Returns all subsets of size k of a given container as perl-array. ? Parameters: :: ''Any'' ''c'': any container type, e.g. ''[[.:common#Set |Set]]'' or ''[[.:common#Array |Array]]'' :: ''[[.:common#Int |Int]]'' ''k'': size of the subsets ? Returns: :''[[.:common#Array |Array]]<[[.:common#Array |Array]]>%%'' ---- {{anchor:incl:}} ? **''incl([[.:common#Set |Set]] s1, [[.:common#Set |Set]] s2)''** :: Analyze the inclusion relation of two sets. ? Parameters: :: ''[[.:common#Set |Set]]'' ''s1'' :: ''[[.:common#Set |Set]]'' ''s2'' ? Returns: :''[[.:common#Int |Int]]'' ? 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 ---- {{anchor:range:}} ? **''range([[.:common#Int |Int]] a, [[.:common#Int |Int]] b)''** :: Create the ''[[.:common#Set |Set]]'' {//a//, //a//+1, ..., //b//-1, //b//} for //a// ≤ //b//. See also: sequence ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'': minimal element of the set :: ''[[.:common#Int |Int]]'' ''b'': maximal element of the set ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > print range(23,27); {23 24 25 26 27} ---- {{anchor:range_from:}} ? **''range_from([[.:common#Int |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. ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'': start index ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > $v=new Vector(10,20,30,40); > print $v->slice(range_from(2)); 30 40 ---- {{anchor:scalar2set:}} ? **''scalar2set(//Scalar// s)''** :: Returns the singleton set {//s//}. ? Parameters: :: ''//Scalar//'' ''s'' ? Returns: :''[[.:common#Set |Set]]'' ? Example: :: > print scalar2set(23); {23} ---- {{anchor:select_subset:}} ? **''select_subset([[.:common#Set |Set]] s, [[.:common#Set |Set]]<[[.:common#Int |Int]]> indices)''** :: Returns the subset of //s// given by the //indices//. ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'' :: ''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ''indices'' ? Returns: :''[[.:common#Set |Set]]'' ? Example: :: > $s = new Set(23,42,666,789); > $ind = new Set(0,2); > $su = select_subset($s,$ind); > print $su; {23 666} ---- {{anchor:sequence:}} ? **''sequence([[.:common#Int |Int]] a, [[.:common#Int |Int]] c)''** :: Create the ''[[.:common#Set |Set]]'' {//a//, //a//+1, ..., //a//+//c//-1}. See also: range ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'': the smallest element :: ''[[.:common#Int |Int]]'' ''c'': the cardinality ? Returns: :''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ? Example: :: > print sequence(23,6); {23 24 25 26 27 28} ---- ==== Utilities ==== Miscellaneous functions. ---- {{anchor:average:}} ? **''average(ARRAY array)''** :: Returns the average value of the array elements. ? Parameters: :: ''ARRAY'' ''array'' ? Example: :: > print average([1,2,3]); 2 ---- {{anchor:bounding_box:}} ? **''bounding_box([[.:common#Matrix |Matrix]] m)''** :: Compute the column-wise bounds for the given Matrix //m//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ---- {{anchor:distance_matrix:}} ? **''distance_matrix([[.:common#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 > sub dist($$) { > my $v = $_[0] - $_[1]; > return sqrt(new Float($v*$v)); } > $M = distance_matrix(polytope::cube(3)->VERTICES, \&dist); ---- {{anchor:expand:}} ? **''expand([[.:common#Map |Map]]<[[.:common#Integer |Integer]],[[.:common#Int |Int]]> factorization)''** :: Use flint to expand the prime factorization of an Integer This is the inverse operation of ''[[.:common#factor |factor]]'' ? Parameters: :: ''[[.:common#Map |Map]]<[[.:common#Integer |Integer]],[[.:common#Int |Int]]>'' ''factorization'' ? Returns: :''[[.:common#Integer |Integer]]'' ? from extension: : [[:external_software|bundled:flint]] ---- {{anchor:factor:}} ? **''factor([[.:common#Integer |Integer]] n)''** :: Use flint to compute the prime factorization of an Integer ? Parameters: :: ''[[.:common#Integer |Integer]]'' ''n'' ? Returns: :''[[.:common#Map |Map]]<[[.:common#Integer |Integer]],[[.:common#Int |Int]]>'' ? from extension: : [[:external_software|bundled:flint]] ---- {{anchor:fibonacci_numbers:}} ? **''fibonacci_numbers([[.:common#Int |Int]] m)''** :: Returns the first //m// Fibonacci numbers. ? Parameters: :: ''[[.:common#Int |Int]]'' ''m'' ? Returns: :''ARRAY'' ---- {{anchor:histogram:}} ? **''histogram(ARRAY data)''** :: Produce a histogram of an array: each different element value is mapped on the number of its occurences. ? Parameters: :: ''ARRAY'' ''data'' ? Returns: :''[[.:common#Map |Map]]'' ? 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)} ---- {{anchor:index_of:}} ? **''index_of([[.:common#Array |Array]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%% array)''** :: Return a map indexing an array of sets ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%%'' ''array'' ? Returns: :''[[.:common#HashMap |HashMap]]<[[.:common#Array |Array]]<[[.:common#Set |Set]]<[[.:common#Int |Int]]%%>>%%,[[.:common#Int |Int]]>'' ? Example: :: > $s1 = new Set(1,2,3); > $s2 = $s1 - 1; > $a = new Array($s1,$s2,$s1); > print index_of($a); {({1 2 3} 2) ({2 3} 1)} ---- {{anchor:is_nonnegative:}} ? **''is_nonnegative(ARRAY data)''** :: Checks if a given sequence is nonnegative ? Parameters: :: ''ARRAY'' ''data'' ? Returns: :''[[.:common#Bool |Bool]]'' ? Example: :: > print is_nonnegative([1,0,3]); 1 ---- {{anchor:is_unimodal:}} ? **''is_unimodal(ARRAY data)''** :: Checks if a given sequence is unimodal ? Parameters: :: ''ARRAY'' ''data'' ? Returns: :''[[.:common#Bool |Bool]]'' ? 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 ---- {{anchor:maximum:}} ? **''maximum(ARRAY array)''** :: Returns the maximal element of an array. ? Parameters: :: ''ARRAY'' ''array'' ? Example: :: > print maximum([1,2,3,4,5,6,7,23]); 23 ---- {{anchor:median:}} ? **''median(ARRAY array)''** :: Returns the median value of the array elements. Running time O(n log(n)) if n is the length of the input. ? Parameters: :: ''ARRAY'' ''array'' ? Example: :: > print median([1,2,3,9]); 2.5 ---- {{anchor:minimum:}} ? **''minimum(ARRAY array)''** :: Returns the minimal element of an array. ? Parameters: :: ''ARRAY'' ''array'' ? Example: :: > print minimum([23,42,666]); 23 ---- {{anchor:perturb_matrix:}} ? **''perturb_matrix([[.:common#Matrix |Matrix]] M, [[.:common#Float |Float]] eps, [[.:common#Bool |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//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''M'' :: ''[[.:common#Float |Float]]'' ''eps'': the factor by which the random matrix is multiplied default value: 1 :: ''[[.:common#Bool |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) ? Options: : :: ''[[.:common#Int |Int]]'' ''seed'': controls the outcome of the random number generator; fixing a seed number guarantees the same outcome. ? Returns: :''[[.:common#Matrix |Matrix]]'' ---- {{anchor:rand_perm:}} ? **''rand_perm([[.:common#Int |Int]] n)''** :: gives a random permutation ? Parameters: :: ''[[.:common#Int |Int]]'' ''n'' ? Options: : :: ''[[.:common#Int |Int]]'' ''Seed'' ? Returns: :''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ---- {{anchor:sum:}} ? **''sum(ARRAY array)''** :: Returns the sum of the array elements. ? Parameters: :: ''ARRAY'' ''array'' ? Example: :: > print sum([1,2,3]); 6 ---- {{anchor:valuation:}} ? **''valuation([[.:common#Rational |Rational]] x, [[.:common#Integer |Integer]] p)''** :: Use flint's Integer factorization to compute the //p//-adic valuation of a Rational //x// ? Parameters: :: ''[[.:common#Rational |Rational]]'' ''x'' :: ''[[.:common#Integer |Integer]]'' ''p'' ? Returns: :''[[.:common#TropicalNumber |TropicalNumber]]<[[.:common#Min |Min]]>'' ? from extension: : [[:external_software|bundled:flint]] ---- ==== Visualization ==== These functions are for visualization. ---- {{anchor:compose:}} ? **''compose([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Create a composite drawing of several objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to be drawn together ? Options: : :: ''[[.:common#String |String]]'' ''Title'': name of the whole drawing; per default the name of the first Object is taken. : option list ''[[.:common#Visual_Polygons_decorations |Visual::Polygons::decorations]]'' ? Returns: :''[[.:common:Visual_Container |Visual::Container]]'' ? Example: :: Draw a pretty 8-pointed star: :: > compose(cube(2)->VISUAL, cross(2,sqrt(2))->VISUAL, Title=>"A pretty star.", VertexLabels=>"hidden"); ? **''compose([[.:common:Visual_Container |Visual::Container]] vis_container, [[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Add new objects to a composite drawing. ? Parameters: :: ''[[.:common:Visual_Container |Visual::Container]]'' ''vis_container'': drawing produced by some visualization function :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to be added ? Options: : :: ''[[.:common#String |String]]'' ''Title'': new name for the drawing :: ''Any'' ''decorations'': to be applied to all components as default values. ? Returns: :''[[.:common:Visual_Container |Visual::Container]]'' ---- {{anchor:geomview:}} ? **''geomview([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Run [[:external_software#geomview|geomview]] to display given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to display ? Options: : :: ''[[.:common#String |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. ---- {{anchor:javaview:}} ? **''javaview([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Run [[:external_software#javaview|JavaView]] with the given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to display ? Options: : :: ''[[.:common#String |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. ? from extension: : [[:external_software|bundled:javaview]] ---- {{anchor:jreality:}} ? **''jreality([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Run [[:external_software#jreality|jReality]] to display given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to display ? Options: : :: ''[[.:common#String |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. ? from extension: : [[:external_software|bundled:jreality]] ---- {{anchor:postscript:}} ? **''postscript([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Create a Postscript (tm) drawing with the given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to draw ? Options: : :: ''[[.:common#String |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. ---- {{anchor:povray:}} ? **''povray([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Run [[:external_software#povray|POVRAY]] to display given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to display ? Options: : :: ''[[.:common#String |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. ---- {{anchor:sketch:}} ? **''sketch([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Produce a Sketch input file with given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to display ? Options: : :: ''[[.:common#String |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. ---- {{anchor:static:}} ? **''static([[.:common:Visual_Object |Visual::Object]] vis_obj)''** :: Suppress creation of dynamic (interactive) scenes. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj'': drawing, e.g. created by ''VISUAL_GRAPH'' or ''SCHLEGEL''. ? Returns: :''[[.:common:Visual_Object |Visual::Object]]'' ---- {{anchor:svg:}} ? **''svg([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Create a Svg drawing with the given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to draw ? Options: : :: ''[[.:common#String |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. ---- {{anchor:threejs:}} ? **''threejs([[.:common:Visual_Object |Visual::Object]] vis_obj)''** :: Produce an html file with given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj'': object to display ? Options: : :: ''[[.:common#String |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. ---- {{anchor:tikz:}} ? **''tikz([[.:common:Visual_Object |Visual::Object]] vis_obj)''** :: Produce a TikZ file with given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj'': object to display ? Options: : :: ''[[.:common#String |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. ---- {{anchor:x3d:}} ? **''x3d([[.:common:Visual_Object |Visual::Object]] vis_obj ...)''** :: Create an X3D drawing with the given visual objects. ? Parameters: :: ''[[.:common:Visual_Object |Visual::Object]]'' ''vis_obj ...'': objects to draw ? Options: : :: ''[[.:common#String |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. ---- ==== no category ==== {{anchor:evaluate:}} ? **''evaluate([[.:common#PuiseuxFraction |PuiseuxFraction]] f, //Coefficient// x, [[.:common#Int |Int]] exp)''** :: Evaluate a ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' at a ''[[.:common#Rational |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. ? Parameters: :: ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' ''f'' :: ''//Coefficient//'' ''x'' :: ''[[.:common#Int |Int]]'' ''exp'': (default: 1) ? Returns: :''//Coefficient//'' ? **''evaluate([[.:common#Matrix |Matrix]] m, Coefficient x, [[.:common#Int |Int]] exp)''** :: Evaluate all ''[[.:common#PuiseuxFraction |PuiseuxFraction]]''s in a ''[[.:common#Matrix |Matrix]]'' at a ''[[.:common#Rational |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. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' :: ''Coefficient'' ''x'' :: ''[[.:common#Int |Int]]'' ''exp'': (default: 1) ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $m = long_and_winding(2)->FACETS; > print 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([[.:common#Vector |Vector]] v, Coefficient x, [[.:common#Int |Int]] exp)''** :: Evaluate all ''[[.:common#PuiseuxFraction |PuiseuxFraction]]''s in a ''[[.:common#Vector |Vector]]'' at a ''[[.:common#Rational |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. ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' :: ''Coefficient'' ''x'' :: ''[[.:common#Int |Int]]'' ''exp'': (default: 1) ? Returns: :''[[.:common#Vector |Vector]]'' ---- {{anchor:evaluate_float:}} ? **''evaluate_float([[.:common#PuiseuxFraction |PuiseuxFraction]] f, [[.:common#Float |Float]] x)''** :: Approximate evaluation at //x// ? Parameters: :: ''[[.:common#PuiseuxFraction |PuiseuxFraction]]'' ''f'' :: ''[[.:common#Float |Float]]'' ''x'' ? Returns: :''[[.:common#Float |Float]]'' ? **''evaluate_float([[.:common#Matrix |Matrix]] m, [[.:common#Float |Float]] x)''** :: Approximate evaluation of a ''[[.:common#Matrix |Matrix]]'' at //x// ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' :: ''[[.:common#Float |Float]]'' ''x'' ? Returns: :''[[.:common#Float |Float]]'' ? **''evaluate_float([[.:common#Vector |Vector]] v, [[.:common#Float |Float]] x)''** :: Approximate evaluation of a ''[[.:common#Vector |Vector]]'' at //x// ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'' :: ''[[.:common#Float |Float]]'' ''x'' ? Returns: :''[[.:common#Float |Float]]'' ---- ===== Small Object Types ===== ==== Algebraic Types ==== This category contains all "algebraic" types, such as matrices, vectors, polynomials, rings, ... ---- {{anchor:matrix:}} ? **''Matrix''** :: A type for matrices with entries of type //Element//. You can create a new Matrix by entering its entries as an array of row vectors: ? Type Parameters: :: ''Element'': default: ''[[.:common#Rational |Rational]]'' :: ''Sym'': not implemented - for internal type compatibility only ? Example: :: > $M = new Matrix([1,3],[6,9]); > print $M; 1 3 6 9 ? Methods of Matrix: : ? **''anti_diagonal([[.:common#Int |Int]] i)''** :: Returns the __anti-diagonal__ of the matrix. ? Parameters: :: ''[[.:common#Int |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: :''[[.:common#Vector |Vector]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6],[7,8,9]); > print $M->anti_diagonal; 3 5 7 :: > print $M->anti_diagonal(-1); 2 4 ? **''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]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->col(1); 2 5 ? **''cols()''** :: Returns the number of columns. ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->cols; 3 ? **''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]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6],[7,8,9]); > print $M->diagonal; 1 5 9 :: > print $M->diagonal(1); 4 8 ? **''div_exact([[.:common#Int |Int]] a)''** :: Divides every entry of ''[[.:common#Matrix |Matrix]]'' //M// by ''[[.:common#Int |Int]]'' //a//. If type of //M// is ''[[.:common#Int |Int]]'', then only the integer part of the each entry is taken into account. ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'' ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,2],[2,1]); > print $M->div_exact(2); 1/2 1 1 1/2 ? **''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'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->elem(1,1); 5 ? **''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. ? Parameters: :: ''[[.:common#Set |Set]]'' ''r'': the rows :: ''[[.:common#Set |Set]]'' ''c'': the columns ? Returns: :''[[.:common#Matrix |Matrix]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->minor([0,1],[0,1]); 1 2 4 5 :: > print $M->minor(All,~[0]); 2 3 5 6 ? **''resize([[.:common#Int |Int]] r, [[.:common#Int |Int]] c)''** :: Resizes the dimension of ''[[.:common#Matrix |Matrix]]'' //M// to //r// x //c//; missing entries are filled with zero and for all i > //r// or j > //c// the (i,j)-th entry of //M// is forgotten. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': new number of rows :: ''[[.:common#Int |Int]]'' ''c'': new number of columns ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > $M->resize(3,2); > print $M; 1 2 4 5 0 0 ? **''row([[.:common#Int |Int]] i)''** :: Returns the //i//-th row. ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->row(1); 4 5 6 ? **''rows()''** :: Returns the number of rows. ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > $M = new Matrix([1,2,3],[4,5,6]); > print $M->rows; 2 ---- {{anchor:plucker:}} ? **''Plucker''** :: A class to hold and process Plücker coordinates of a subspace. ? Type Parameters: :: ''Scalar'': default: ''[[.:common#Rational |Rational]]'' ? Methods of Plucker: : ? **''coordinates''** ::UNDOCUMENTED ? **''permuted''** ::UNDOCUMENTED ---- {{anchor:polynomial:}} ? **''Polynomial''** :: ? Type Parameters: :: ''Coefficient'': default: ''[[.:common#Rational |Rational]]'' :: ''Exponent'': default: ''[[.:common#Int |Int]]'' ? Methods of Polynomial: : ? **''coefficients_as_vector()''** :: The vector of all coefficients. The sorting agrees with ''[[.:common#Polynomial |monomials_as_matrix]]''. ? Returns: :''[[.:common#Vector |Vector]]'' ? **''constant_coefficient()''** :: The __constant coefficient__. ? Returns: :''[[.:common#Int |Int]]'' ? **''deg()''** :: The degree of the polynomial ? Returns: :''[[.:common#Int |Int]]'' ? **''embed([[.:common#Int |Int]] nvars)''** :: Embed the ''[[.:common#Polynomial |Polynomial]]'' in a polynomial ring with the given number of variables. The old variables will be put at the beginning, for more control use ''[[.:common#Polynomial |mapvars]]''. ? Parameters: :: ''[[.:common#Int |Int]]'' ''nvars'': new number of variables ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? 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 ? **''get_var_names''** :: set the variable names ? **''homogeneous()''** :: Check if the polynomial is homogeneous ? Returns: :''[[.:common#Bool |Bool]]'' ? **''initial_form([[.:common#Vector |Vector]] v)''** :: The initial form with respect to a weight-vector //v// ? Parameters: :: ''[[.:common#Vector |Vector]]'' ''v'': weights ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? **''lc()''** :: The __leading coefficient__. ? Returns: :''[[.:common#Int |Int]]'' ? **''lm()''** :: The exponent of the leading monomial. ? Returns: :''[[.:common#Int |Int]]'' ? **''mapvars([[.:common#Array |Array]]<[[.:common#Int |Int]]> indices, [[.:common#Int |Int]] nvars)''** :: Map the variables of the ''[[.:common#Polynomial |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 ''[[.:common#Array |Array]]'' must be the same as the number of variables of the original polynomial. ? Parameters: :: ''[[.:common#Array |Array]]<[[.:common#Int |Int]]>'' ''indices'': indices of the target variables :: ''[[.:common#Int |Int]]'' ''nvars'': new number of variables, default: maximal index ? Returns: :''[[.:common#Polynomial |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 ? **''monomial([[.:common#Int |Int]] var_index, [[.:common#Int |Int]] n_vars)''** :: construct a monomial of degree 1 with a given variable ? Parameters: :: ''[[.:common#Int |Int]]'' ''var_index'': index of the variable :: ''[[.:common#Int |Int]]'' ''n_vars'': number of variables ? **''monomials_as_matrix()''** :: The matrix of all exponent vectors (row-wise). The sorting agrees with ''[[.:common#Polynomial |coefficients_as_vector]]''. ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? **''n_vars()''** :: Number of variables ? Returns: :''[[.:common#Int |Int]]'' ? **''print_ordered([[.:common#Matrix |Matrix]] m)''** :: Print a polynomial with terms sorted according to a given ''[[.:common#Matrix |Matrix]]'' //m//. ? Parameters: :: ''[[.:common#Matrix |Matrix]]'' ''m'' ? **''project()''** :: Project the ''[[.:common#Polynomial |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 ''[[.:common#Polynomial |substitute]]'' with a ''[[.:common#Map |Map]]''. ? Returns: :''[[.:common#Polynomial |Polynomial]]'' ? 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 ? **''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 ''[[.:common#Polynomial |Polynomial]]'' with ''[[.:common#Int |Int]]'' exponents. Either with an array of values, or with a ''[[.:common#Map |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([0,5/2],[1,1/5],[2,new Rational(7/3)]); > print $pm->substitute($map); 37/4*x_3 + 6/5 ? **''trivial()''** :: The polynomial is zero. ? Returns: :''[[.:common#Bool |Bool]]'' ---- {{anchor:puiseuxfraction:}} ? **''PuiseuxFraction''** :: ? Type Parameters: :: ''MinMax'': type of tropical addition: either ''[[.:common#Min |Min]]'' or ''[[.:common#Max |Max]]'' :: ''Coefficient'': default: ''[[.:common#Rational |Rational]]'' :: ''Exponent'': default: ''[[.:common#Rational |Rational]]'' ? Methods of PuiseuxFraction: : ? **''val()''** :: The __valuation__. ? Returns: :''[[.:common#TropicalNumber |TropicalNumber]]'' ? Example: :: > $x = monomials(1); > print new PuiseuxFraction(2*$x*$x-$x+2)->val; 2 ? Example: :: The valuation can also be applied to Containers via convert_to :: > $m = long_and_winding(3)->FACETS; > print convert_to>($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) ---- {{anchor:rationalfunction:}} ? **''RationalFunction''** :: ? Type Parameters: :: ''Coefficient'': default: ''[[.:common#Rational |Rational]]'' :: ''Exponent'': default: ''[[.:common#Int |Int]]'' ---- {{anchor:sparsematrix:}} ? **''SparseMatrix''** :: A SparseMatrix is a special form of a ''[[.:common#Matrix |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 ''[[.:common#dense |dense]]'' to convert a SparseMatrix into the [[.:common#Matrix |dense form]]. ? Type Parameters: :: ''Element'' :: ''Sym'': one of ''[[.:common#Symmetric |Symmetric]]'' or ''[[.:common#NonSymmetric |NonSymmetric]]'', default: ''[[.:common#NonSymmetric |NonSymmetric]]'' ? derived from: : ''[[.:common#Matrix |Matrix]]'' ? Example: :: 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. :: > $M = new SparseMatrix( > [0, 1, 0, 0, 0], > {4 => 2}, > {}, > [3, -1, 0, 0, 0]); > print $M; (5) (1 1) (5) (4 2) (5) (5) (0 3) (1 -1) ? Example: :: construct a SparseMatrix with explicitly given number of columns: :: > $M = new SparseMatrix( > {1 => 10}, > {2 => 20}, > {cols => 5}); > print $M; (5) (1 10) (5) (2 20) ? Methods of SparseMatrix: : ? **''resize([[.:common#Int |Int]] r, [[.:common#Int |Int]] c)''** :: Resizes the ''[[.:common#Matrix |Matrix]]'' according to given number of rows and columns. All elements in added rows and/or columns are implicit zeros. If the number of rows and/or columns of the original matrix is less than the given number or rows and/or columns, the extra entries are deleted. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': new number of rows :: ''[[.:common#Int |Int]]'' ''c'': new number of columns ? Example: :: > $M = new SparseMatrix({1 =>2, _dim => 6},{5 => 3, _dim => 6}, {}); :: print(dense($M)); :: > $M->resize(3,4); > print(dense($M)); 0 2 0 0 0 0 0 0 0 0 0 0 ? **''squeeze''** :: Adjusts the given ''[[.:common#SparseMatrix |SparseMatrix]]'' by removing empty rows and columns. The remaining rows and columns are renumbered without gaps. ? Example: :: > $M = new SparseMatrix({1 =>2, _dim => 6},{5 => 3, _dim => 6}, {}); :: print(dense($M)); :: > $M->squeeze(); > print(dense($M)); 2 0 0 3 ? **''squeeze_cols''** :: Adjusts the given ''[[.:common#SparseMatrix |SparseMatrix]]'' by removing empty columns. The remaining columns are renumbered without gaps. ? Example: :: > $M = new SparseMatrix({1 =>2, _dim => 6},{5 => 3, _dim => 6}, {}); > print(dense($M)); 0 2 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 :: > $M->squeeze_cols(); > print(dense($M)); 2 0 0 3 0 0 ? **''squeeze_rows''** :: Adjusts the given ''[[.:common#SparseMatrix |SparseMatrix]]'' by removing empty rows. The remaining rows are renumbered without gaps. ? Example: :: > $M = new SparseMatrix({1 =>2, _dim => 6},{5 => 3, _dim => 6}, {}); :: print(dense($M)); :: > $M->squeeze_rows(); > print(dense($M)); 0 2 0 0 0 0 0 0 0 0 0 3 ---- {{anchor:sparsevector:}} ? **''SparseVector''** :: A SparseVector is a special form of a ''[[.:common#Vector |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 ''[[.:common#dense |dense]]'' to convert a sparse vector into the [[.:common#Vector |dense form]]. ? Type Parameters: :: ''Element'' ? derived from: : ''[[.:common#Vector |Vector]]'' ? Example: :: construct a SparseVector from a contiguous list of scalars; zero values are filtered out automatically: :: > $v = new SparseVector(0, 1, 2, 0, 0, 0); > print $v, "\n"; (6) (1 1) (2 2) ? Example: :: construct a SparseVector from a hash map with non-zero values; dimension is provided explicitly: :: > $v = new SparseVector({ 1 => 1, 2 => 2, _dim => 6 }); > print $v, "\n"; (6) (1 1) (2 2) ? Methods of SparseVector: : ? **''size()''** :: The number of non-zero entries of a sparse vector. ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > $v = new SparseVector(0, 1, 2, 0, 0, 0); > print($v->size()); 2 ---- {{anchor:unipolynomial:}} ? **''UniPolynomial''** :: A class for __univariate__ polynomials. ? Type Parameters: :: ''Coefficient'': default: ''[[.:common#Rational |Rational]]'' :: ''Exponent'': default: ''[[.:common#Int |Int]]'' ? Methods of UniPolynomial: : ? **''coefficients_as_vector()''** :: The vector of all coefficients. The sorting agrees with ''[[.:common#UniPolynomial |monomials_as_vector]]''. ? Returns: :''[[.:common#Vector |Vector]]'' ? **''constant_coefficient()''** :: The __constant coefficient__. ? Returns: :''[[.:common#Int |Int]]'' ? **''deg()''** :: The highest degree occurring in the polynomial. ? Returns: :''Exponent'' ? **''evaluate(Coefficient x, Exponent exp)''** :: Evaluate a ''[[.:common#UniPolynomial |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. ? Parameters: :: ''Coefficient'' ''x'' :: ''Exponent'' ''exp'': (default: 1) ? Returns: :''Coefficient'' ? **''evaluate_float([[.:common#Float |Float]] x)''** :: Approximate evaluation of the polynomial at a ''[[.:common#Float |Float]]'' //x//. ? Parameters: :: ''[[.:common#Float |Float]]'' ''x'' ? Returns: :''[[.:common#Float |Float]]'' ? **''get_var_names''** :: get the variable name ? **''lc()''** :: The __leading coefficient__. ? Returns: :''[[.:common#Int |Int]]'' ? **''lower_deg()''** :: The lowest degree occurring in the polynomial. ? Returns: :''Exponent'' ? **''monomial''** :: create a monomial of degree 1 ? **''monomials_as_vector()''** :: The vector of all exponents. The order agrees with ''[[.:common#UniPolynomial |coefficients_as_vector]]''. ? Returns: :''[[.:common#Vector |Vector]]'' ? **''n_vars''** :: Number of variables ? **''print_ordered(Exponent x)''** :: Print a polynomial with terms sorted according to //exponent*x//. ? Parameters: :: ''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 ''[[.:common#UniPolynomial |UniPolynomial]]'' with ''[[.:common#Int |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 ''[[.:common#RationalFunction |RationalFunction]]'' instead) and any given matrix must be invertible ---- {{anchor:vector:}} ? **''Vector''** :: A type for vectors with entries of type //Element//. You can perform algebraic operations such as addition or scalar multiplication. ? Type Parameters: :: ''Element'' ? Example: :: You can create a new Vector by entering its elements, e.g.: :: > $v = new Vector(1,2,3); :: or :: >$v = new Vector([1,2,3]); ? Methods of Vector: : ? **''dim()''** :: Returns the length of the given ''[[.:common#Vector |Vector]]''. ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: > $v = new Vector(1,2,3,4); > print $v->dim; 4 ? **''div_exact([[.:common#Int |Int]] a)''** :: Divides every entry of ''[[.:common#Vector |Vector]]'' //v// by ''[[.:common#Int |Int]]'' //a//. If type of //v// is ''[[.:common#Int |Int]]'', then only the integer part of the each entry is taken into account. ? Parameters: :: ''[[.:common#Int |Int]]'' ''a'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $v = new Vector(1/2,2); > print $v->div_exact(2); 1/4 1 :: > $v = new Vector(1,2,3,4); > print $v->div_exact(2); 0 1 1 2 ? **''slice([[.:common#Set |Set]] s)''** :: Returns a ''[[.:common#Vector |Vector]]'' containing all entries whose index is in a ''[[.:common#Set |Set]]'' //s//. ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'' ? Returns: :''[[.:common#Vector |Vector]]'' ? Example: :: > $v = new Vector(1,2,3,4); > $s = new Set(0,2); > print $v->slice($s); 1 3 ---- {{anchor:all_rows_or_cols:}} ? **''all_rows_or_cols''** :: Allows the use of the keyword "All" for all rows or columns, e.g. when constructing a ''[[.:common#Matrix |minor]]''. ---- ==== Arithmetic ==== These types are needed as return types of arithmetic computations. ---- {{anchor:div:}} ? **''Div''** :: The complete result of an integral division ? Type Parameters: :: ''Scalar'': type supporting modulo division, e.g. ''[[.:common#Integer |Integer]]'' or ''[[.:common#UniPolynomial |UniPolynomial]]'' ? Methods of Div: : ? **''quot()''** ::the quotient ? Returns: :''Scalar'' ? **''rem()''** ::the remainder ? Returns: :''Scalar'' ---- {{anchor:extgcd:}} ? **''ExtGCD''** :: The complete result of the calculation of the __greatest common divisor__ of two numbers //a// and //b//: ? Type Parameters: :: ''Scalar'': type of operands, must be a GCD domain ? Methods of ExtGCD: : ? **''g()''** ::The greatest common divisor, gcd(//a//,//b//) ? Returns: :''Scalar'' ? **''k1()''** ::The __factor__ of //a//: //a//=''[[.:common#ExtGCD |g]]''*k1 ? Returns: :''Scalar'' ? **''k2()''** ::The __factor__ of //b//: //b//=''[[.:common#ExtGCD |g]]''*k2 ? Returns: :''Scalar'' ? **''p()''** ::The __co-factor__ of //a//: ''[[.:common#ExtGCD |g]]''=//a//*p+//b//*''[[.:common#ExtGCD |q]]'' ? Returns: :''Scalar'' ? **''q()''** ::The __co-factor__ of //b//: ''[[.:common#ExtGCD |g]]''=//a//*''[[.:common#ExtGCD |p]]''+//b//*q ? Returns: :''Scalar'' ---- {{anchor:max:}} ? **''Max''** :: tropical addition: max ? Methods of Max: : ? **''apply''** ::UNDOCUMENTED ? **''orientation''** ::UNDOCUMENTED ---- {{anchor:min:}} ? **''Min''** :: tropical addition: min ? Methods of Min: : ? **''apply''** ::UNDOCUMENTED ? **''orientation''** ::UNDOCUMENTED ---- {{anchor:tropicalnumber:}} ? **''TropicalNumber''** :: ? Type Parameters: :: ''Addition'' :: ''Scalar'': default: ''[[.:common#Rational |Rational]]'' ? Methods of TropicalNumber: : ? **''orientation()''** :: The orientation of the associated addition, i.e. +1 if the corresponding 0 is +inf -1 if the corresponding 0 is -inf ? Returns: :''[[.:common#Int |Int]]'' ? **''zero()''** :: The zero element of the tropical semiring of this element. ? Returns: :''Scalar'' ---- ==== 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. ---- {{anchor:cachedobjectpointer:}} ? **''CachedObjectPointer''** :: ---- {{anchor:container:}} ? **''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. ---- {{anchor:directed:}} ? **''Directed''** :: Type tag for a __directed__ graph. ---- {{anchor:directedmulti:}} ? **''DirectedMulti''** :: Type tag for a __directed multigraph__. ---- {{anchor:edgeiterator:}} ? **''EdgeIterator''** :: ---- {{anchor:edgelist:}} ? **''EdgeList''** :: ---- {{anchor:iterator:}} ? **''Iterator''** :: An iterator over a sequence of objects. The objects may be stored in a container or be generated on the fly. ? Type Parameters: :: ''Element'' ---- {{anchor:localfloatepsilon:}} ? **''LocalFloatEpsilon''** :: ---- {{anchor:nonsymmetric:}} ? **''NonSymmetric''** :: Labels a ''[[.:common#Matrix |Matrix]]'' or an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' as __non-symmetric__. ---- {{anchor:serialized:}} ? **''Serialized''** :: ? Type Parameters: :: ''X'' ---- {{anchor:symmetric:}} ? **''Symmetric''** :: Labels a ''[[.:common#Matrix |Matrix]]'' or an ''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' as __symmetric__. ---- {{anchor:undirected:}} ? **''Undirected''** :: Type tag for an __undirected__ graph. ---- {{anchor:undirectedmulti:}} ? **''UndirectedMulti''** :: Type tag for an __undirected multigraph__. ---- ==== Basic Types ==== This category contains all basic types, in particular those that wrap C++, GMP or perl types such as ''[[.:common#Int |Int]]'', ''[[.:common#Integer |Integer]]'', ''[[.:common#Rational |Rational]]'', ''[[.:common#Float |Float]]'', ''[[.:common#Array |Array]]'', ''[[.:common#String |String]]'', ... ---- {{anchor:accuratefloat:}} ? **''AccurateFloat''** :: A wrapper for AccurateFloat. ---- {{anchor:array:}} ? **''Array''** :: An array with elements of type //Element//. Corresponds to the C++ type ''[[.:common#Array |Array]]''. ? Type Parameters: :: ''Element'' ? Methods of Array: : ? **''size()''** :: Returns the size. ? Returns: :''[[.:common#Int |Int]]'' ---- {{anchor:bool:}} ? **''Bool''** :: Corresponds to the C++ type __bool__. ---- {{anchor:float:}} ? **''Float''** :: Corresponds to the C++ type __double__. ? Methods of Float: : ? **''inf''** :: produce an infinitely large positive value ? **''minus_inf''** :: produce an infinitely large negative value ---- {{anchor:gf2:}} ? **''GF2''** :: The Galois field of order 2 ---- {{anchor:int:}} ? **''Int''** :: Corresponds to the C++ type __Int__. ? Methods of Int: : ? **''max''** :: produce the highest possible value ? **''min''** :: produce the lowest possible value ---- {{anchor:integer:}} ? **''Integer''** :: An integer of arbitrary size. ? Methods of Integer: : ? **''inf''** :: produce an infinitely large positive value ? **''minus_inf''** :: produce an infinitely large negative value ---- {{anchor:list:}} ? **''List''** :: Corresponds to the C++ type __std::list__. ? Type Parameters: :: ''Element'' ---- {{anchor:pair:}} ? **''Pair''** :: Corresponds to the C++ type __std::pair__. ? Type Parameters: :: ''First'' :: ''Second'' ---- {{anchor:quadraticextension:}} ? **''QuadraticExtension''** :: 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//). Caution: QuadraticExtension requires [[:external_software#flint]] for normalization. For example, the input (1,1,4) will not be reduced to 3 without flint. ? Type Parameters: :: ''Field'': default: ''[[.:common#Rational |Rational]]'' ---- {{anchor:rational:}} ? **''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. ---- {{anchor:string:}} ? **''String''** :: Corresponds to the C++ type __std::string__. ---- {{anchor:text:}} ? **''Text''** :: Plain text without any imposed structure. ---- ==== Graph Types ==== This contains all property types that are related to graphs. ---- {{anchor:edgehashmap:}} ? **''EdgeHashMap''** :: Sparse mapping of edges to data items. ? Type Parameters: :: ''Dir'': one of ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'' or ''[[.:common#DirectedMulti |DirectedMulti]]'' :: ''Element'': data associated with edges ? derived from: : ''[[.:common#GraphMap |GraphMap]]'' ? Methods of EdgeHashMap: : ? **''edge([[.:common#Int |Int]] from, [[.:common#Int |Int]] to)''** :: Access the data associated with an edge between two given nodes. The new data element is created on demand. ? Parameters: :: ''[[.:common#Int |Int]]'' ''from'': source node :: ''[[.:common#Int |Int]]'' ''to'': target node ? **''erase([[.:common#Int |Int]] from, [[.:common#Int |Int]] to)''** :: Delete the data associated with an edge between two given nodes. ? Parameters: :: ''[[.:common#Int |Int]]'' ''from'': source node :: ''[[.:common#Int |Int]]'' ''to'': target node ? **''find([[.:common#Int |Int]] from, [[.:common#Int |Int]] to)''** :: Access the data associated with an edge between two given nodes. ? Parameters: :: ''[[.:common#Int |Int]]'' ''from'': source node :: ''[[.:common#Int |Int]]'' ''to'': target node ? Returns: :''[[.:common#Iterator |Iterator]]'' ---- {{anchor:edgemap:}} ? **''EdgeMap''** :: Dense mapping of edges to data items. ? Type Parameters: :: ''Dir'': kind of the host graph, ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'', or ''[[.:common#DirectedMulti |DirectedMulti]]'' :: ''Element'': data associated with edges ? derived from: : ''[[.:common#GraphMap |GraphMap]]'' ? Methods of EdgeMap: : ? **''edge([[.:common#Int |Int]] from, [[.:common#Int |Int]] to)''** :: Access the data associated with an edge between two given nodes. ? Parameters: :: ''[[.:common#Int |Int]]'' ''from'': source node :: ''[[.:common#Int |Int]]'' ''to'': target node ---- {{anchor:graphadjacency:}} ? **''GraphAdjacency''** :: ? Type Parameters: :: ''Dir'': one of ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'' or ''[[.:common#DirectedMulti |DirectedMulti]]'', default: ''[[.:common#Undirected |Undirected]]'' ? Methods of GraphAdjacency: : ? **''add_edge([[.:common#Int |Int]] tail_node, [[.:common#Int |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. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? Returns: :''[[.:common#Int |Int]]'' ? **''add_node()''** :: Add a new node without incident edes. ? Returns: :''[[.:common#Int |Int]]'' ? **''adjacent_nodes([[.:common#Int |Int]] node)''** :: Returns the set of indices of nodes adjacent to //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Set |Set]]'' ? **''all_edges([[.:common#Int |Int]] tail_node, [[.:common#Int |Int]] head_node)''** :: Returns an iterator visiting all (parallel) edges connecting two given nodes. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? Returns: :''[[.:common#Iterator |Iterator]]'' ? **''contract_edge([[.:common#Int |Int]] node1, [[.:common#Int |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//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node1'' :: ''[[.:common#Int |Int]]'' ''node2'' ? **''degree([[.:common#Int |Int]] node)''** :: Returns the number of edges incident to //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Int |Int]]'' ? **''delete_all_edges([[.:common#Int |Int]] tail_node, [[.:common#Int |Int]] head_node)''** :: Deletes all edges in a multigraph connecting two given nodes. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? **''delete_edge([[.:common#Int |Int]] tail_node, [[.:common#Int |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. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? **''delete_edge([[.:common#Iterator |Iterator]] iterator)''** :: Delete the edge in a multigraph pointed to by the given iterator ? Parameters: :: ''[[.:common#Iterator |Iterator]]'' ''iterator'': as returned by ''[[.:common#GraphAdjacency |all_edges]]''. ? **''delete_node([[.:common#Int |Int]] node)''** :: Deletes all edges incident to the given node and marks it as invalid. The numeration of other nodes stays unchanged. ? Parameters: :: ''[[.:common#Int |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 ''[[.:common#GraphAdjacency |nodes]]''(). ? Returns: :''[[.:common#Int |Int]]'' ? **''edge([[.:common#Int |Int]] tail_node, [[.:common#Int |Int]] head_node)''** :: Returns the index of the edge connecting two given nodes. The edge is created if was not there and if the graph is not read-only. In a multigraph, an arbitrary edge from the parallel bundle will be picked. Warning: If there is no ''[[.:common#EdgeMap |EdgeMap]]'' attached to the graph, the returned number will always be zero. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? Returns: :''[[.:common#Int |Int]]'' ? Example: :: Get edge numbers for the ''[[.:polytope:Polytope#HASSE_DIAGRAM |HASSE_DIAGRAM]]'' of a square. :: > $c = polytope::cube(2); > $g = $c->HASSE_DIAGRAM->ADJACENCY; > print $g; {1 2 3 4} {5 7} {6 7} {5 8} {6 8} {9} {9} {9} {9} {} :: > $E = new EdgeMap($g); > print $g->edge(0,1); 0 :: > print $g->edge(1,5); 4 :: > print $g->edge(5,9); 12 ? Example: :: If there is no ''[[.:common#EdgeMap |EdgeMap]]'' the returned number is always zero. :: > $c = polytope::cube(2); > $g = $c->HASSE_DIAGRAM->ADJACENCY; > print $g->edge(0,1); 0 :: > print $g->edge(1,5); 0 :: > print $g->edge(5,9); 0 ? Example: :: If the graph is read-only it cannot add an edge. :: > $c = polytope::cube(2); > $g = $c->HASSE_DIAGRAM->ADJACENCY; > $E = new EdgeMap($g); > print $g->edge(0,1); 0 :: > print $g->edge(0,5); polymake: ERROR: non-existing edge :: > $gg = new GraphAdjacency($g); > $EE = new EdgeMap($gg); > print $gg->edge(0,5); 4 ? **''edge_exists([[.:common#Int |Int]] tail_node, [[.:common#Int |Int]] head_node)''** :: Checks whether two given nodes are connected by (at least) one edge. ? Parameters: :: ''[[.:common#Int |Int]]'' ''tail_node'' :: ''[[.:common#Int |Int]]'' ''head_node'' ? Returns: :''[[.:common#Bool |Bool]]'' ? **''edges()''** :: Get the total number of edges. ? Returns: :''[[.:common#Int |Int]]'' ? **''has_gaps()''** :: Returns true if some nodes have been deleted since the last ''[[.:common#GraphAdjacency |squeeze]]'' operation. ? Returns: :''[[.:common#Bool |Bool]]'' ? **''in_adjacent_nodes([[.:common#Int |Int]] node)''** :: Returns the set of indices of the nodes that have an edge heading to //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Set |Set]]'' ? **''in_degree([[.:common#Int |Int]] node)''** :: Returns the number of edges heading to //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Int |Int]]'' ? **''in_edges([[.:common#Int |Int]] node)''** :: Returns a sequence of edges heading to (in Directed case) or incident to (in Undirected case) //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#EdgeList |EdgeList]]'' ? **''invalid_node([[.:common#Int |Int]] node)''** :: Returns true if the given node index is either out of valid range or points to a formerly deleted node. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Bool |Bool]]'' ? **''node_exists([[.:common#Int |Int]] node)''** :: Check whether the node with given index exists. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Bool |Bool]]'' ? **''node_out_of_range([[.:common#Int |Int]] node)''** :: Returns true if the given node index is out of valid range. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Bool |Bool]]'' ? **''nodes()''** :: Get the total number of nodes. ? Returns: :''[[.:common#Int |Int]]'' ? **''out_adjacent_nodes([[.:common#Int |Int]] node)''** :: Returns the set of indices of the nodes with an edge arriving from //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Set |Set]]'' ? **''out_degree([[.:common#Int |Int]] node)''** :: Returns the number of edges leaving //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#Int |Int]]'' ? **''out_edges([[.:common#Int |Int]] node)''** :: Returns a sequence of edges leaving (in Directed case) or incident to (in Undirected case) //node//. ? Parameters: :: ''[[.:common#Int |Int]]'' ''node'' ? Returns: :''[[.:common#EdgeList |EdgeList]]'' ? **''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. ---- {{anchor:graphmap:}} ? **''GraphMap''** :: The common abstract base class for all kinds of associative containers that can be attached to a ''[[.:common#GraphAdjacency |GraphAdjacency]]''. ? Type Parameters: :: ''Dir'': kind of the host graph: ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'', or ''[[.:common#DirectedMulti |DirectedMulti]]'' :: ''Element'': data associated with nodes or edges ---- {{anchor:nodehashmap:}} ? **''NodeHashMap''** :: Sparse mapping of nodes to data items. ? Type Parameters: :: ''Dir'': one of ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'' or ''[[.:common#DirectedMulti |DirectedMulti]]'' :: ''Element'': data associated with nodes ? derived from: : ''[[.:common#GraphMap |GraphMap]]'' ---- {{anchor:nodemap:}} ? **''NodeMap''** :: Dense mapping of nodes to data items. ? Type Parameters: :: ''Dir'': kind of the host graph, ''[[.:common#Undirected |Undirected]]'', ''[[.:common#Directed |Directed]]'', ''[[.:common#UndirectedMulti |UndirectedMulti]]'', or ''[[.:common#DirectedMulti |DirectedMulti]]'' :: ''Element'': data associated with nodes ? derived from: : ''[[.:common#GraphMap |GraphMap]]'' ---- ==== Linear Algebra ==== These types are needed as return types of algebraic computations. ---- {{anchor:hermitenormalform:}} ? **''HermiteNormalForm''** :: Complete result of the __Hermite normal form__ computation of the input matrix //M//. ? Type Parameters: :: ''Scalar'': matrix element type ? Methods of HermiteNormalForm: : ? **''companion()''** ::unimodular matrix R such that M*R = H ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? **''hnf()''** ::the Hermite normal form ? Returns: :''[[.:common#Matrix |Matrix]]'' ? **''rank()''** ::rank of //M// ? Returns: :''[[.:common#Int |Int]]'' ---- {{anchor:singularvaluedecomposition:}} ? **''SingularValueDecomposition''** :: Complete result of the __singular value decomposition__ of a ''[[.:common#Matrix |Matrix]]'' //M//, such that left_companion * sigma * transpose(right_companion) = //M// Contains the following fields: ? Methods of SingularValueDecomposition: : ? **''left_companion()''** ::matrix of left singular vectors ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ? **''right_companion()''** ::matrix of right singular vectors ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ? **''sigma()''** ::the diagonalized matrix ? Returns: :''[[.:common#Matrix |Matrix]]<[[.:common#Float |Float]]>'' ---- {{anchor:smithnormalform:}} ? **''SmithNormalForm''** :: Complete result of the __Smith normal form__ computation of the input matrix //M//. ? Type Parameters: :: ''Scalar'': matrix element type ? Methods of SmithNormalForm: : ? **''form()''** ::the Smith normal form ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? **''left_companion()''** ::unimodular matrix L such that //M// = L*S*R ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? **''rank()''** ::rank of //M// ? Returns: :''[[.:common#Int |Int]]'' ? **''right_companion()''** ::unimodular matrix R such that //M// = L*S*R ? Returns: :''[[.:common#SparseMatrix |SparseMatrix]]'' ? **''torsion()''** ::absolute values of the entries greater than 1 of the diagonal together with their multiplicity ? Returns: :''[[.:common#List |List]]<[[.:common#Pair |Pair]]>%%'' ---- ==== Set Types ==== In this category you find all property types related to sets, such as Set, Map, HashMap, IncidenceMatrix, ... ---- {{anchor:approximateset:}} ? **''ApproximateSet''** :: A specialization of Sets containing elements of type //Element//, but where equality is enforced only up to a global epsilon. ? Type Parameters: :: ''Element'': default: ''[[.:common#Float |Float]]'' ? derived from: : ''[[.:common#Set |Set]]'' ? Example: :: You can for example create a new ApproximateSet with two elements by: :: > $s = new ApproximateSet(1.1, 1.2, 1.200000001); ---- {{anchor:bitset:}} ? **''Bitset''** :: Container class for dense sets of integers. A special class optimized for representation of a constrained range of non-negative integer numbers. ? derived from: : ''[[.:common#Set |Set]]<[[.:common#Int |Int]]>'' ---- {{anchor:facetlist:}} ? **''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 ''[[.:common#IncidenceMatrix |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 [[]] 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: : ? **''erase([[.:common#Set |Set]] f)''** :: Remove a facet. ? Parameters: :: ''[[.:common#Set |Set]]'' ''f'': facet to remove ? Returns: :''[[.:common#Bool |Bool]]'' ? **''eraseSubsets([[.:common#Set |Set]] s)''** :: Remove all subsets of a given set ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'': filter for removal ? Returns: :''[[.:common#Int |Int]]'' ? **''eraseSupersets([[.:common#Set |Set]] s)''** :: Remove all supersets of a given set ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'': filter for removal ? Returns: :''[[.:common#Int |Int]]'' ? **''find([[.:common#Set |Set]] f)''** :: Look up a facet. ? Parameters: :: ''[[.:common#Set |Set]]'' ''f'': facet to find ? Returns: :''[[.:common#Iterator |Iterator]]'' ? **''findSubsets([[.:common#Set |Set]] s)''** :: Find all subsets of a given set. ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'' ? Returns: :''[[.:common#Iterator |Iterator]]'' ? **''findSupersets([[.:common#Set |Set]] s)''** :: Find all supersets of a given set. ? Parameters: :: ''[[.:common#Set |Set]]'' ''s'' ? Returns: :''[[.:common#Iterator |Iterator]]'' ? **''insert([[.:common#Set |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. ? Parameters: :: ''[[.:common#Set |Set]]'' ''f'': facet to add. ? **''insertMax([[.:common#Set |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. ? Parameters: :: ''[[.:common#Set |Set]]'' ''f'': facet to add ? Returns: :''[[.:common#Bool |Bool]]'' ? **''insertMin([[.:common#Set |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. ? Parameters: :: ''[[.:common#Set |Set]]'' ''f'': facet to add ? Returns: :''[[.:common#Bool |Bool]]'' ? **''n_vertices()''** :: The number of vertices ? Returns: :''[[.:common#Int |Int]]'' ? **''size()''** :: The number of facets in the list. ? Returns: :''[[.:common#Int |Int]]'' ---- {{anchor:hashmap:}} ? **''HashMap''** :: An unordered map based on a hash table. Its interface is similar to that of ''[[.:common#Map |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 ''[[.:common#Map |Map]]'' (keeping in mind differences in performance and memory demand). ? Type Parameters: :: ''Key'': type of the key values :: ''Value'': type of the mapped value ? Example: :: You can create a new HashMap mapping Ints to Strings by :: > $myhashmap = new HashMap([1, "Monday"], [2, "Tuesday"]); ? Methods of HashMap: : ? **''size()''** :: Size of the map ? Returns: :''[[.:common#Int |Int]]'' ---- {{anchor:hashset:}} ? **''HashSet''** :: 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. ? Type Parameters: :: ''Element'' ? Methods of HashSet: : ? **''size()''** :: The cardinality of the set. ? Returns: :''[[.:common#Int |Int]]'' ---- {{anchor:incidencematrix:}} ? **''IncidenceMatrix''** :: A 0/1 incidence matrix. ? Type Parameters: :: ''Sym'': one of ''[[.:common#Symmetric |Symmetric]]'' or ''[[.:common#NonSymmetric |NonSymmetric]]'', default: ''[[.:common#NonSymmetric |NonSymmetric]]'' ? Methods of IncidenceMatrix: : ? **''col([[.:common#Int |Int]] i)''** :: Returns the //i//-th column. ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#SparseVector |SparseVector]]<[[.:common#Int |Int]]>'' ? **''cols()''** :: Returns the number of columns. ? Returns: :''[[.:common#Int |Int]]'' ? **''elem([[.:common#Int |Int]] r, [[.:common#Int |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. ? Parameters: :: ''[[.:common#Int |Int]]'' ''r'': the row index :: ''[[.:common#Int |Int]]'' ''c'': the column index ? Returns: :''[[.:common#Bool |Bool]]'' ? **''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. ? Parameters: :: ''[[.:common#Set |Set]]'' ''r'': the rows :: ''[[.:common#Set |Set]]'' ''c'': the columns ? Returns: :''[[.:common#IncidenceMatrix |IncidenceMatrix]]'' ? Example: :: For example, :: > print polytope::cube(2)->VERTICES_IN_FACETS->minor(All, ~[0]); {1} {0 2} {0} {1 2} :: will give you the minor of a matrix containing all rows and all but the 0-th column. ? **''row([[.:common#Int |Int]] i)''** :: Returns the //i//-th row. ? Parameters: :: ''[[.:common#Int |Int]]'' ''i'' ? Returns: :''[[.:common#SparseVector |SparseVector]]<[[.:common#Int |Int]]>'' ? **''rows()''** :: Returns the number of rows. ? Returns: :''[[.:common#Int |Int]]'' ? **''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. ---- {{anchor:map:}} ? **''Map''** :: 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. ? Type Parameters: :: ''Key'': type of the key values :: ''Value'': type of the mapped value ? Example: :: You can create a new Map mapping Ints to Strings by :: > $mymap = new Map([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 ---- {{anchor:set:}} ? **''Set''** :: A type for ordered sets containing elements of type //Element//. ? Type Parameters: :: ''Element'': default: ''[[.:common#Int |Int]]'' ? Example: :: 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} ? Methods of Set: : ? **''back()''** :: The last element of the set, that is, the largest element ? Returns: :''[[.:common#Int |Int]]'' ? **''collect(Element e)''** :: Add to the set, report true if existed formerly. ? Parameters: :: ''Element'' ''e'': element to insert into the set ? Returns: :''[[.:common#Bool |Bool]]'' ? **''contains(Element e)''** :: Check if e is contained in the set. ? Parameters: :: ''Element'' ''e'': element check for ? Returns: :''[[.:common#Bool |Bool]]'' ? **''front()''** :: The first element of the set, that is, the smallest element ? Returns: :''[[.:common#Int |Int]]'' ? **''size()''** :: The cardinality of the set. ? Returns: :''[[.:common#Int |Int]]'' ---- ==== Visualization ==== These property_types are for visualization. ---- {{anchor:color:}} ? **''Color''** :: This is a pseudo-type for documentation purposes only. A function expecting an argument or option of type //Color// can digest an object of type ''[[.:common#RGB |RGB]]'' or ''[[.:common#HSV |HSV]]'' as well as a string with an RGB value in hex notation "#RRGGBB" or a symbolic color name. ---- {{anchor:flexible:}} ? **''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. ---- {{anchor:hsv:}} ? **''HSV''** :: A color described as a Hue-Saturation-Value triple. Is convertible to and from an RGB representation. ---- {{anchor:rgb:}} ? **''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. ---- ==== no category ==== {{anchor:polydbclient:}} ? **''PolyDBClient''** ::UNDOCUMENTED ? from extension: : [[:external_software|bundled:polydb]] ---- {{anchor:polydbcollection:}} ? **''PolyDBCollection''** ::UNDOCUMENTED ? from extension: : [[:external_software|bundled:polydb]] ---- {{anchor:polydbcursor:}} ? **''PolyDBCursor''** ::UNDOCUMENTED ? from extension: : [[:external_software|bundled:polydb]] ---- {{anchor:polydbsection:}} ? **''PolyDBSection''** ::UNDOCUMENTED ? from extension: : [[:external_software|bundled:polydb]] ----