/usr/share/polymake/demo/matrix_classes.ipynb is in polymake-common 3.2r2-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | {
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dealing with matrices and vectors\n",
"\n",
"The following list gives an overview over the operators and basic constructions for working with matrices in `polymake`. Some of them also apply to vectors. Operators and functions are described in `C++`-syntax, but most of them can also be used in the interactive shell on `Perl` side, compare [release_docs/common](http://polymake.org/release_docs/2.12/common.html). \n",
"\n",
"\n",
"### Operations\n",
"\n",
"#### C++\n",
"\n",
" \n",
" const GenericMatrix operator- (const GenericMatrix&); \n",
" const GenericMatrix operator+ (const GenericMatrix&, const GenericMatrix&); \n",
" const GenericMatrix operator- (const GenericMatrix&, const GenericMatrix&); \n",
" const GenericMatrix operator* (const Scalar&, const GenericMatrix&); \n",
" const GenericMatrix operator* (const GenericMatrix&, const Scalar&); \n",
" const GenericMatrix operator/ (const GenericMatrix&, const Scalar&); \n",
" const GenericMatrix operator* (const GenericMatrix&, const GenericMatrix&); \n",
" const GenericMatrix operator* (const GenericMatrix&, const GenericVector&); \n",
" const GenericMatrix operator* (const GenericVector&, const GenericMatrix&);\n",
"\n",
"\n",
"Do exactly what the mnemonics suggest. Every type combination is allowed, including mixing of sparse and dense vectors and matrices. ElementType of matrix and vector operands, and Scalar type can be different, provided the arithmetic operator with corresponding arguments exists.\n",
"\n",
" The dimensions of the operands must match.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" _Matrix& GenericMatrix::negate(); \n",
" _Matrix& GenericMatrix::operator+= (const GenericMatrix&); \n",
" _Matrix& GenericMatrix::operator-= (const GenericMatrix&); \n",
" _Matrix& GenericMatrix::operator*= (const Scalar&); \n",
" _Matrix& GenericMatrix::operator/= (const Scalar&);\n",
"\n",
"\n",
"Corresponding assignment versions of the arithmetic operators.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" bool operator== (const GenericMatrix&, const GenericMatrix&); \n",
" bool operator!= (const GenericMatrix&, const GenericMatrix&); \n",
" bool operator< (const GenericMatrix&, const GenericMatrix&); \n",
" bool operator> (const GenericMatrix&, const GenericMatrix&); \n",
" bool operator<= (const GenericMatrix&, const GenericMatrix&); \n",
" bool operator>= (const GenericMatrix&, const GenericMatrix&);\n",
"\n",
"\n",
"Compare two matrices lexicographically (iterating over elements in row order). The dimensions of the operands must match.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericMatrix::operator bool() const; bool GenericMatrix::operator! () const;\n",
"\n",
"\n",
"Look for a non-zero element. \n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"\n",
"#### Perl\n",
"\n",
"The operators given above in `C++`-syntax can be translated to `Perl` in the following way. Consider e.g. the operator\n",
"\n",
" \n",
" const GenericMatrix operator+ (const GenericMatrix&, const GenericMatrix&);\n",
"\n",
"In `Perl` you can apply this operator via\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$m1=new Matrix(3,3); $m2=new Matrix(3,3);\n",
"$m1+=$m2; # changing the variable $m1"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"or\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$m1=unit_matrix(4); $m2=3*unit_matrix(4);\n",
"$m=$m1+$m2; print $m; print dense($m);"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"All other operators are translated in a similar way.\n",
"\n",
"### Other constructions\n",
"\n",
"#### C++\n",
"\n",
" \n",
" GenericMatrix GenericMatrix::minor(const RowIndexSet& row_indices, const ColIndexSet& column_indices);\n",
"\n",
"\n",
"Select a matrix minor lying on the intersection of the given row and column subsets. The const variant of this method creates an immutable minor object.\n",
"\n",
" The indices must lie in the valid ranges.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericVector GenericMatrix::diagonal (int i=0); \n",
" GenericVector GenericMatrix::anti_diagonal (int i=0);\n",
"\n",
"\n",
"Select the diagonal or anti-diagonal of a matrix:\n",
"\n",
"* i=0 the main diagonal (anti-diagonal)\n",
"\n",
"* i>0 the i-th diagonal below the main\n",
"\n",
"* i<0 the (-i)-th diagonal above the main\n",
"The const variants of these methods create immutable slice objects.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericMatrix T (GenericMatrix&);\n",
"\n",
"\n",
"Transpose the matrix. The roles of Rows and Cols get swapped. (**Perl:** `transpose()`)\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericMatrix operator/ (const GenericMatrix&, const GenericMatrix&); \n",
" GenericMatrix operator/ (const GenericVector&, const GenericMatrix&); \n",
" GenericMatrix operator/ (const GenericMatrix&, const GenericVector&); \n",
" GenericMatrix operator/ (const GenericVector&, const GenericVector&);\n",
"\n",
"\n",
"Create a block matrix, virtually appending the rows of the second matrix after the last row of the first matrix. A vector argument is treated as a matrix with one row. Column dimensions of the operands must be equal.\n",
"ElementType of the operands must be identical, otherwise you will get a rather cryptic message from the compiler.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericMatrix operator| (const GenericMatrix&, const GenericMatrix&); \n",
" GenericMatrix operator| (const GenericVector&, const GenericMatrix&); \n",
" GenericMatrix operator| (const GenericMatrix&, const GenericVector&);\n",
"\n",
"\n",
"Create a block matrix, virtually appending the columns of the second matrix after the last column of the first matrix. A vector argument is treated as a matrix with one column. Row dimensions of the operands must be equal.\n",
"\n",
" ElementType of the operands must be identical, otherwise you will get a rather cryptic message from the compiler.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" Matrix& Matrix::operator/= (const GenericMatrix&); \n",
" Matrix& Matrix::operator/= (const GenericVector&); \n",
" Matrix& Matrix::operator|= (const GenericMatrix&); \n",
" Matrix& Matrix::operator|= (const GenericVector&);\n",
"\n",
"\n",
"Append rows or columns to the matrix. All constraints for the non-assigning operators apply here too.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix diag(const GenericMatrix&, const GenericMatrix&); \n",
" const GenericMatrix diag(const GenericMatrix&, const GenericVector&); \n",
" const GenericMatrix diag(const GenericVector&, const GenericMatrix&);\n",
"\n",
"\n",
"Create a block-diagonal matrix. Vector arguments are treated as square diagonal matrices.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" GenericMatrix vector2row(const GenericVector& v); \n",
" GenericMatrix vector2col(const GenericVector& v);\n",
"\n",
"\n",
"Disguise v as a matrix with 1 row (column).\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix diag(const GenericVector& v);\n",
"\n",
"\n",
"Create a square diagonal matrix. The elements of v appear on the main diagonal.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix repeat_row(const GenericVector& v, int n); \n",
" const GenericMatrix repeat_col(const GenericVector& v, int n);\n",
"\n",
"\n",
"Create a matrix with n rows (columns), each equal to v.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix same_element_matrix(const ElementType& x, int m, int n); \n",
" const GenericMatrix ones_matrix<ElementType>(int m, int n); \n",
" const GenericMatrix zero_matrix<ElementType>(int m, int n);\n",
"\n",
"\n",
"Create a dense matrix with m rows and n columns, with all elements equal to x, 1, or 0, respectively. Note the obligatory explicit specification of the template parameter ElementType, where it cannot be deduced from the function arguments.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix same_element_sparse_matrix<ElementType>(const GenericIncidenceMatrix& M); \n",
" const GenericMatrix same_element_sparse_matrix(const GenericIncidenceMatrix& M, const ElementType& x);\n",
"\n",
"\n",
"Create a sparse matrix with the same structure as M, with elements equal to x in true cells and 0 in false cells.\n",
"If omitted, x is taken equal to 1; note the obligatory explicit template parameter specification in this case.\n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
" \n",
" const GenericMatrix unit_matrix<ElementType>(int n);\n",
"\n",
"\n",
"Create a unit matrix n×n. \n",
"\n",
"\n",
" \n",
"\n",
"\n",
"\n",
"#### Perl\n",
"\n",
"Many of the `C++`-functions also exist on `Perl` side (under the same name), compare [release_docs/common](http://polymake.org/release_docs/2.12/common.html). To append rows or columns in `Perl`, you can also use the operators `/` and `|`:\n",
"\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"$m1 = new Matrix(3,4); $v1 = new Vector(4);\n",
"$m1_ext = $m1/$v1;\n",
"$m2 = new Matrix(2,4);\n",
"$m = $m1_ext / $m2; print $m;\n",
"$zero_vec6 = ones_vector<Rational>(6);\n",
"print $zero_vec6|$m;"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "polymake",
"language": "polymake",
"name": "polymake"
},
"language_info": {
"codemirror_mode": "perl",
"file_extension": ".pm",
"mimetype": "text/x-polymake",
"name": "polymake"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|