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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331
|
# Copyright (c) 1997-2015
# Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
# http://www.polymake.org
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version: http://www.gnu.org/licenses/gpl.txt.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#-------------------------------------------------------------------------------
# @topic category property_types/Algebraic Types
# This category contains all "algebraic" types, such as matrices, vectors, polynomials, rings, ...
# @category Algebraic Types
# A type for vectors with entries of type //Element//.
#
# You can perform algebraic operations such as addition or scalar multiplication.
#
# You can create a new Vector by entering its elements, e.g.:
# $v = new Vector<Int>(1,2,3);
# or
# $v = new Vector<Int>([1,2,3]);
# @tparam Element
declare property_type Vector<Element=Rational> : c++ (include => ["polymake/Vector.h", "polymake/Matrix.h"], operators => '@arith:wary |:anchor |= @compare:wary') {
method construct(Int) : c++;
type_method init {
my ($proto)=@_;
if ($proto->params->[0] == typeof Float) {
$proto->equal=\&compare_float_sequences;
}
}
# The length of the vector
# @return Int
user_method dim() : c++;
# Returns a [[Vector]] containing only the entries after //i//.
# @param Int i
# @return Vector
user_method slice(*:anchor) : lvalue_opt : wary : c++;
# Returns a [[Vector]] containing only the entries from //i// to //j//-1.
# @param Int i
# @param Int j
# @return Vector
user_method slice($$) : lvalue_opt : wary : c++;
# Divides every entry by //a// (assuming that every entry is divisible by //a//).
# @param Int a
# @return Vector
user_method div_exact(*) : lvalue : c++;
}
function permuted(Vector, *) : c++;
function permuted_inv(Vector, *) : c++;
# @category Arithmetic
# Compute the __greatest common divisor__ of the elements of the given vector.
# @param Vector<Element> v
# @return Element
# @example > $v = new Vector<Int>(3,6,9);
# > print gcd($v);
# | 3
user_function gcd(Vector) : c++ (include => "polymake/linalg.h");
# @category Arithmetic
# Compute the least common multiple of the elements of the given vector.
# @param Vector<Element> v
# @return Element
# @example > $v = new Vector<Integer>(1,3,6,9);
# > print lcm($v);
# | 18
user_function lcm(Vector) : c++ (include => "polymake/linalg.h");
##################################################################################
# @category Algebraic Types
# @tparam Scalar default: [[Rational]]
declare property_type Plucker<Scalar=Rational> : c++ \
(operators => '+ *', include => "polymake/Plucker.h") {
method construct(Vector) : c++;
method construct(Int, Int, Vector) : c++;
method construct(Int, Int) : c++;
method point() : c++;
user_method permuted(*) : c++;
user_method coordinates() : c++;
}
##################################################################################
# @category Algebraic Types
# @tparam Element default: [[Rational]]
# @tparam Sym default: [[NonSymmetric]]
declare property_type Matrix<Element=Rational, Sym=NonSymmetric> : \
c++ (name => "Matrix<%1>", include => "polymake/Matrix.h", operators => '@arith_nodiv:wary /:wary:anchor |:wary:anchor /=:wary |=:wary @compare:wary') {
method construct(Int,Int) : c++;
method construct(Vector+) {
my ($proto, $vectors)=@_;
my $M=$proto->construct->(scalar(@$vectors), $vectors->[0]->dim);
my $i=0;
$M->[$i++]=$_ for @$vectors;
$M;
}
type_method init {
my ($proto)=@_;
if ($proto->params->[0] == typeof Float) {
$proto->equal=sub : method {
(undef, my $m1, my $m2)=@_;
my $vec_proto=typeof Vector<Float>;
if ($m1->rows==$m2->rows) {
my $i=0;
foreach my $v1 (@$m1) {
$vec_proto->equal->($v1, $m2->row($i++)) or return 0;
}
1
}
};
}
}
# Returns the number of rows.
# @return Int
user_method rows() : c++;
# Returns the number of columns.
# @return Int
user_method cols() : c++;
# Returns the //i//-th row.
# @param Int i
# @return Vector<Element>
user_method row($) : lvalue_opt : wary : c++;
# Returns the //i//-th column.
# @param Int i
# @return Vector<Element>
user_method col($) : lvalue_opt : wary : c++;
# Returns a __minor__ of the matrix containing the rows in //r// and the columns in //c//. You can pass [[all_rows_or_cols|All]] if you want all rows or columns and ~ for the complement of a set. E.g.
# $A->minor(All, ~[0]);
# will give you the minor of a matrix containing all rows and all but the 0-th column.
# @param Set r the rows
# @param Set c the columns
# @return Matrix
user_method minor(*:anchor,*:anchor) : lvalue_opt : wary : 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.
# @param Int r the row index
# @param Int c the column index
# @return Element
user_method elem($,$) : lvalue_opt : wary : c++(name => '()');
# Returns the __diagonal__ of the matrix.
# @param 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
# @return Vector<Element>
user_method diagonal(;$=0) : lvalue_opt : wary : c++;
# Returns the __anti-diagonal__ of the matrix.
# @param 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
# @return Vector<Element>
user_method anti_diagonal(;$=0) : lvalue_opt : wary : c++;
# Divides every entry by //a// (assuming that every entry is divisible by //a//).
# @param Int a
# @return Matrix
user_method div_exact(*) : lvalue : c++;
# backward compatibility, see issue #864
use overload '&{}' => \&deprecated_elem_access;
}
# @category Linear Algebra
# Projects points into the [[null_space|orthogonal complement]] of a subspace given via an orthogonal basis.
# The given points will be overwitten.
# @param Matrix points will be changed to orthogonal ones
# @param Matrix orthogonal basis of the subspace
user_function project_to_orthogonal_complement(Matrix:lvalue,Matrix) : void : c++ (include => "polymake/linalg.h");
# @category Algebraic Types
# Use the keyword "All" for all rows or columns, e.g. when constructing a [[minor]].
declare property_type all_rows_or_cols : c++ (name => 'pm::all_selector', include => ["polymake/Matrix.h"], builtin => enum { All });
# @category Data Conversion
# Explicit conversion to a different element type.
# @param Vector v
# @tparam Target
# @return Vector<Target>
# @example > $v = new Vector<Rational>(1/2,2/3,3/4);
# > $vf = convert_to<Float>($v);
# > print $vf;
# | 0.5 0.6666666667 0.75
user_function convert_to<Element>(Vector) : c++ {
if ($_[0]->type->params->[0]==typeof Element) {
return $_[0];
}
}
# @category Data Conversion
# Explicit conversion to a different element type.
# @param Matrix m
# @tparam Target
# @return Matrix<Target>
# @example > $M = new Matrix<Rational>([1/2,2],[3,2/3]);
# > $Mf = convert_to<Float>($M);
# > print $Mf;
# | 0.5 2
# | 3 0.6666666667
user_function convert_to<Element>(Matrix) : c++ {
if ($_[0]->type->params->[0]==typeof Element) {
return $_[0];
}
}
# @category Data Conversion
# Create a [[Matrix]] by repeating the given [[Vector]] as rows.
# @param Vector v
# @param Int i
# @example > $v = new Vector(23,42,666);
# > $M = repeat_row($v,3);
# > print $M;
# | 23 42 666
# | 23 42 666
# | 23 42 666
user_function repeat_row(Vector:anchor,$) : c++ (include => "polymake/Matrix.h");
# @category Data Conversion
# Create a [[Matrix]] by repeating the given [[Vector]] as cols.
# @param Vector v
# @param Int i
# @example > $v = new Vector(23,42,666);
# > $M = repeat_col($v,3);
# > print $M;
# | 23 23 23
# | 42 42 42
# | 666 666 666
user_function repeat_col(Vector:anchor,$) : c++ (include => "polymake/Matrix.h");
# @category Data Conversion
# Convert a [[Vector]] to a [[Matrix]] with a single row.
# @param Vector v
# @return Matrix
# @example This converts a vector into a row and prints it and its type:
# > $v = new Vector([1,2,3,4]);
# > $V = vector2row($v);
# > print $V;
# | 1 2 3 4
# > print $V->type->full_name;
# | Matrix<Rational, NonSymmetric>
user_function vector2row(Vector:anchor) : c++ (include => "polymake/Matrix.h");
# @category Data Conversion
# Convert a [[Vector]] to a [[Matrix]] with a single column.
# @param Vector v
# @return Matrix
# @example This converts a vector into a column and prints it and its type:
# > $v = new Vector([1,2,3,4]);
# > $V = vector2col($v);
# > print $V;
# | 1
# | 2
# | 3
# | 4
# > print $V->type->full_name;
# | Matrix<Rational, NonSymmetric>
user_function vector2col(Vector:anchor) : c++ (include => "polymake/Matrix.h");
# @category Linear Algebra
# Produces a [[SparseMatrix]] from its diagonal.
# @param Vector d the diagonal entries
# @return 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)
user_function diag(Vector:anchor) : c++ (include => "polymake/SparseMatrix.h");
# @category Linear Algebra
# Returns a __block diagonal matrix__ with blocks //m1// and //m2//.
# @param Matrix m1
# @param Matrix m2
# @return 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
user_function diag(*:anchor,*:anchor) : c++ (include => "polymake/SparseMatrix.h");
# @category Linear Algebra
# Produces a [[SparseMatrix]] from its anti-diagonal.
# @param Vector d the anti-diagonal entries
# @return SparseMatrix
user_function anti_diag(Vector:anchor) : c++ (include => "polymake/SparseMatrix.h");
# @category Linear Algebra
# Returns a __block anti-diagonal matrix__ with blocks //m1// and //m2//.
# @param Matrix m1
# @param Matrix m2
# @return SparseMatrix
user_function anti_diag(*:anchor,*:anchor) : c++ (include => "polymake/SparseMatrix.h");
# @category Data Conversion
# Returns an array containing the rows of //A//.
# @param Matrix A
# @return ARRAY<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(cube(2)->VERTICES);
# > foreach( @$w ){
# > print @{$_}," ";
# > }
# | 1-1-1 11-1 1-11 111
user_function rows(Matrix) : c++;
# @category Data Conversion
# Returns an array containing the columns of //A//.
# @param Matrix A
# @return ARRAY<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 = rows(cube(2)->VERTICES);
# > foreach( @$w ){
# > print @{$_}," ";
# > }
# | 1111 -11-11 -1-111
user_function cols(Matrix) : c++;
# @category Data Conversion
# Concatenates the rows of //A//.
# @param Matrix A
# @return Vector
# @example Make a vector out of the rows of the vertex matrix of a cube:
# > $v = concat_rows(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)
user_function concat_rows(Matrix:lvalue_opt:anchor) : c++;
function permuted_rows(Matrix, *) : c++;
function permuted_inv_rows(Matrix, *) : c++;
function permuted_cols(Matrix, *) : c++;
function permuted_inv_cols(Matrix, *) : c++;
# @category Linear Algebra
# Computes the __transpose__ //A//<sup>T</sup> of a matrix //A//, i.e., (a<sup>T</sup>)<sub>ij</sub> = a<sub>ji</sub>.
# @param Matrix A
# @return Matrix
# @example > $M = new Matrix([1,2,23],[23,22,21]);
# > $Mt = transpose($M);
# > print $Mt;
# | 1 23
# | 2 22
# | 23 21
user_function transpose(Matrix:anchor) : c++ (name => 'T');
# @category Linear Algebra
# Computes the __determinant__ of a matrix using Gauss elimination.
# @param Matrix A
# @return Int det(A)
# @example > print det(unit_matrix(3));
# | 1
user_function det(Matrix:wary) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes the __trace__ of a matrix.
# @param Matrix A
# @return Int trace(A)
# @example > $M = new Matrix([1,2,3],[23,24,25],[0,0,1]);
# > print trace($M);
# | 26
user_function trace(Matrix:wary) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes the __rank__ of a matrix.
# @param Matrix A
# @return Int
user_function rank(Matrix) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes the __inverse__ //A//<sup>-1</sup> of an invertible matrix //A// using Gauss elimination.
# @param Matrix A
# @return 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
user_function inv(Matrix:wary) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Reduce a vector with a given matrix using Gauss elimination.
# @param Matrix A
# @param Vector b
# @return Vector
user_function reduce(Matrix:wary, Vector:wary) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Normalize a matrix by dividing each row by its length (l2-norm).
# @param Matrix<Float> A
# @return Matrix<Float>
# @example > $A = new Matrix<Float>([1.5,2],[2.5,2.5]);
# > print normalized($A);
# | 0.6 0.8
# | 0.7071067812 0.7071067812
user_function normalized(Matrix) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes subsets of the rows and columns of //A// that form a basis for the linear space spanned by //A//.
# @param Matrix A
# @return Pair<Set<Int>, Set<Int>> The first set corresponds to the rows, the second to the columns.
# @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
user_function basis(Matrix) : returns(@) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Does the same as [[basis]] ignoring the first column of the matrix.
# @param Matrix A
# @return Pair<Set<Int>, Set<Int>> The first set corresponds to the rows, the second to the columns.
user_function basis_affine(Matrix) : returns(@) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes a subset of the rows of //A// that form a basis for the linear space spanned by //A//.
# @param Matrix A
# @return Set<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 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
user_function basis_rows(Matrix) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes a subset of the columns of //A// that form a basis for the linear space spanned by //A//.
# @param Matrix A
# @return Set<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 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
user_function basis_cols(Matrix) : c++ (include => "polymake/linalg.h");
function numerators(Vector<Rational>) : c++ (include => "polymake/linalg.h");
function numerators(Matrix<Rational>) : c++ (include => "polymake/linalg.h");
function denominators(Vector<Rational>) : c++ (include => "polymake/linalg.h");
function denominators(Matrix<Rational>) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Creates a unit matrix of given dimension
# @tparam Element default: [[Rational]]
# @param Int d dimension of the matrix
# @return SparseMatrix<Element>
# @example The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) in a variable
# and prints it:
# > $M = unit_matrix(3);
# > print $M;
# | (3) (0 1)
# | (3) (1 1)
# | (3) (2 1)
# @example The following stores the 3-dimensional unit matrix (ones on the diagonal and zeros otherwise) from type Int
# in a variable and prints it:
# > $M = unit_matrix<Int>(3);
# > print $M->type->full_name;
# | SparseMatrix<Int, Symmetric>
user_function unit_matrix<Element=Rational>($) : c++ (include => "polymake/linalg.h") {
if ($_[0] < 0) {
croak( "unit_matrix - invalid dimension" );
}
}
# @category Linear Algebra
# Creates a zero matrix of given dimensions
# @tparam Element default: [[Rational]]
# @param Int i number of rows
# @param Int j number of columns
# @return SparseMatrix<Element>
# @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
# @example The following stores a 2x3 matrix with 0 as entries from type Int in a variable and prints its type:
# > $M = zero_matrix<Int>(2,3);
# > print $M->type->full_name;
# | Matrix<Int, NonSymmetric>
user_function zero_matrix<Element=Rational>($$) : c++ (include => "polymake/linalg.h") {
if ($_[0] < 0 || $_[1] < 0) {
croak( "zero_matrix - invalid dimension" );
}
}
# @category Linear Algebra
# Creates a [[SparseVector]] of given length //d// with a one entry at position //pos// and zeroes elsewhere.
# @tparam Element default: [[Rational]]
# @param Int d the dimension of the vector
# @param Int pos the position of the 1
# @return SparseVector<Element>
# # @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)
# @example The following stores a vector of dimension 5 with a single 1 (as a Int) at position 2:
# > $v = unit_vector<Int>(5,2);
# > print $v->type->full_name;
# | SparseVector<Int>
# @example The following concatenates a unit vector of dimension 3 with a 1 at position 2 and a
# unit vector of dimension 2 with a 1 at position 1:
# > $v = unit_vector(3,2) | unit_vector(2,1);
# > print $v;
# | (5) (2 1) (4 1)
user_function unit_vector<Element=Rational>($$) : c++ (include => "polymake/linalg.h") {
if ($_[1] < 0 || $_[1] >= $_[0]) {
croak( "unit_vector - invalid dimension or index out of range" );
}
}
# @category Linear Algebra
# Creates a vector with all elements equal to zero.
# @param Int d vector dimension. If omitted, a vector of dimension 0 is created,
# which can adjust itself when involved in a block matrix operation.
# @tparam Element default: [[Rational]]
# @return Vector<Element>
# @example The following stores a vector of dimension 5 with 0 as entries (from type Rational) in a variable and prints it:
# > $v = zero_vector(5);
# > print $v;
# | 0 0 0 0 0
# @example The following stores a vector of dimension 5 with 0 as entries from type Int in a variable and prints its type:
# > $v = zero_vector<Int>(5);
# > print $v->type->full_name;
# | Vector<Int>
# @example The following concatenates a vector of dimension 2 of ones and a vector of length 2 of zeros:
# > $v = ones_vector(2) | zero_vector(2);
# > print $v;
# | 1 1 0 0
user_function zero_vector<Element=Rational>(;$=0) : c++ (include => "polymake/linalg.h") {
if ($_[0] < 0) {
croak( "zero_vector - invalid dimension");
}
}
# @category Linear Algebra
# Creates a vector with all elements equal to 1.
# @param Int d vector dimension. If omitted, a vector of dimension 0 is created, which can adjust itself when involved in a block matrix operation.
# @tparam Element default: [[Rational]].
# @return Vector<Element>
# @example To create the all-ones Int vector of dimension 3, do this:
# > $v = ones_vector<Int>(3);
# You can print the result using the print statement:
# > print $v;
# | 1 1 1
user_function ones_vector<Element=Rational>(;$=0) : c++ (include => "polymake/linalg.h") {
if ($_[0] < 0) {
croak( "ones_vector - invalid dimension");
}
}
# @category Linear Algebra
# Compute the __null space__ of a matrix //A//.
# @param Matrix A
# @return Matrix
# @example > $A = new Matrix([1,2,0],[2,0,2]);
# > print null_space($A);
# | -1 1/2 1
user_function null_space(Matrix) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Compute the __null space__ of a vector //b//.
# @param Vector b
# @return Matrix
# @example > $b = new Vector(1,2,3);
# polytope > print null_space($b);
# | -2 1 0
# | -3 0 1
user_function null_space(Vector) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Compute the __lineality space__ of a matrix //A//.
# @param Matrix A
# @return Matrix
# @example > $M = new Matrix([1,1,0,0],[1,0,1,0]);
# > print lineality_space($M);
# | 0 0 0 1
user_function lineality_space(Matrix) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Computes the solution of the system //A//x = //b//
# @param Matrix A must be invertible
# @param Vector b
# @return 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
user_function lin_solve(Matrix:wary, Vector:wary) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# The matrix //A// is totally unimodular if the determinant of each square submatrix equals 0, 1, or -1.
# This is the naive test (exponential in the size of the matrix).
#
# For a better implementation try Matthias Walter's polymake extension at
# [[https://github.com/xammy/unimodularity-test/wiki/Polymake-Extension]].
# @param Matrix A
# @return Bool
# @example > $M = new Matrix<Int>([-1,-1,0,0,0,1],[1,0,-1,-1,0,0],[0,1,1,0,-1,0],[0,0,0,1,1,-1]);
# > print totally_unimodular($M);
# | 1
user_function totally_unimodular(Matrix) : c++ (include => "polymake/totally_unimodular.h");
# @category Linear Algebra
# Check whether both matrices are bases of the same linear subspace.
# Note: It is assumed that they are *bases* of the row space.
# @param Matrix M1
# @param Matrix M2
# @return 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);
# | 1
user_function equal_bases(Matrix, Matrix) {
my ($M1, $M2)=@_;
# we first need to check for full rank matrices as null_space gives an empty matrix in that case
return $M1 == $M2 || $M1->rows==$M2->rows &&
($M1->rows == $M1->cols || is_zero(null_space($M1) * transpose($M2)));
}
# @category Linear Algebra
# Householder tranformation of Vector b. Only the orthogonal matrix reflection H is returned.
# @param Vector b
# @return Vector
user_function householder_trafo(Vector<Float>) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# QR decomposition of a Matrix //M// with rows > cols
# @param Matrix<Float> M
# @return Pair<Matrix,Matrix>
# @example > $M = new Matrix<Float>([23,4],[6,42]);
# > $qr = qr_decomp($M);
# > print $qr->first;
# | 0.9676172724 0.2524218971
# | 0.2524218971 -0.9676172724
# > print $qr->second;
# | 23.76972865 14.47218877
# | 0 -39.63023785
# > print $qr->first * $qr->second ;
# | 23 4
# | 6 42
user_function qr_decomp(Matrix<Float>) : c++ (include => "polymake/linalg.h");
# @topic category property_types/Linear Algebra
# These types are needed as return types of algebraic computations.
# @category Linear Algebra
# Complete result of the __singular value decomposition__ of a matrix //M//,
# such that left_companion * sigma * transpose(right_companion) = //M//
# Contains the following fields:
# Matrix<Float> sigma: the diagonalized matrix
# Matrix<Float> left_companion: matrix of left singular vectors
# Matrix<Float> right_companion: matrix of right singular vectors
declare property_type SingularValueDecomposition : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# SVD decomposition of a Matrix. Computes the SVD of a matrix into a diagonal Marix (S), orthogonal square Matrix (U), orthogonal square Matrix (V), such that U*S*V^T=M
# The first element of the output array is S, the second U and the thrid V.
# @param Matrix<Float> M
# @return SingularValueDecomposition
# @example > $M = new Matrix<Float>([1,2],[23,24]);
# > $SVD = singular_value_decomposition($M);
# The following prints the three matrices, seperated by newline characters.
# > print $SVD->left_companion ,"\n", $SVD->sigma ,"\n", $SVD->right_companion;
# | 0.06414638608 0.9979404998
# | 0.9979404998 -0.06414638608
# |
# | 33.31011547 0
# | 0 0.6604600341
# |
# | 0.6909846321 -0.7228694476
# | 0.7228694476 0.6909846321
user_function singular_value_decomposition(Matrix<Float>) : c++ (include => "polymake/linalg.h");
# @category Linear Algebra
# Moore-Penrose Inverse of a Matrix
# @param Matrix M
# @return Matrix<Float>
user_function moore_penrose_inverse(Matrix<Float>) : c++ (include => "polymake/linalg.h");
# @category Data Conversion
# Return the input vector (which is already in dense form).
# @param Vector v
# @return Vector
user_function dense(Vector) { $_[0] }
# @category Data Conversion
# Return the input matrix (which is already in dense form).
# @param Matrix m
# @return Matrix
user_function dense(Matrix) { $_[0] }
# @category Combinatorics
# Returns the __permuation matrix__ of the permutation given by //p//.
# @tparam Scalar default: [[Int]]
# @param Array<Int> p
# @return Matrix<Scalar>
# @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)
user_function permutation_matrix<Scalar=Int>(*:anchor) : c++ (include => [ "polymake/permutations.h", "polymake/SparseMatrix.h" ]);
##################################################################################
# @category Algebraic Types
# A SparseVector is an associative container with element indices (coordinates) as keys; elements equal to the default value (ElementType(), which is 0 for most numerical types) are not stored, but implicitly encoded by the gaps in the key set. It is based on an AVL tree.
#
# The printable representation of a SparseVector looks like a sequence (l) (p<sub>1</sub> v<sub>1</sub>) ... (p<sub>k</sub> v<sub>k</sub>),
# where l is the dimension of the vector and each pair (p<sub>i</sub> v<sub>i</sub>) denotes an entry with value
# v<sub>i</sub> at position p<sub>i</sub>. All other entries are zero.
#
# Use [[dense]] to convert this into its dense form.
#
# You can create a new SparseVector by entering its printable encoding as described above, e.g.:
# $v = new SparseVector<Int>(<< '.');
# (6) (1 1) (2 2)
# .
# @tparam Element
declare property_type SparseVector<Element=Rational> : Vector<Element> : c++ (include => ["polymake/SparseVector.h", "polymake/SparseMatrix.h"]) {
# The number of non-zero entries.
# @return Int
user_method size() : c++;
}
property_type Vector {
# accept a SparseVector of a different type as a value of Vector property but substitute the desired element type
type_method coherent_type {
my ($self, $value)=@_;
instanceof SparseVector($value) ? typeof SparseVector($self->params->[0]) : undef;
}
}
# @category Algebraic Types
# A SparseMatrix is a two-dimensional associative array with row and column indices as keys; elements equal to the default value (ElementType(), which is 0 for most numerical types) are not stored, but implicitly encoded by the gaps in the key set. Each row and column is organized as an AVL-tree.
#
# Use [[dense]] to convert this into its dense form.
#
# You can create a new SparseMatrix by entering its entries row by row, as a list of [[SparseVector|SparseVectors]] e.g.:
# $A = new SparseMatrix<Int>(<< '.');
# (5) (1 1)
# (5) (4 2)
# (5)
# (5) (0 3) (1 -1)
# .
# @tparam Element
# @tparam Sym one of [[Symmetric]] or [[NonSymmetric]], default: [[NonSymmetric]]
declare property_type SparseMatrix<Element=Rational, Sym=NonSymmetric> : Matrix<Element,Sym> : c++ (include => ["polymake/SparseMatrix.h"]) {
# Removes empty rows and columns.
# The remaining rows and columns are renumbered without gaps.
user_method squeeze() : non_const : void : c++;
# Removes empty rows.
# The remaining rows are renumbered without gaps.
user_method squeeze_rows() : non_const : void : c++;
# Removes empty columns.
# The remaining columns are renumbered without gaps.
user_method squeeze_cols() : non_const : void : c++;
# Resize the matrix
user_method resize($$) : non_const : void : c++;
}
property_type Matrix {
# accept a SparseMatrix of a different type as a value of Matrix property but substitute the desired element type
type_method coherent_type {
my ($self, $value)=@_;
instanceof SparseMatrix($value) ? typeof SparseMatrix(@{$self->params}) : undef;
}
}
function entire(SparseVector:anchor) : c++ : returns(SparseIterator);
# @category Data Conversion
# Convert to an equivalent dense vector of the same element type.
# @tparam Element
# @param SparseVector<Element> v
# @return Vector<Element>
user_function dense<Element>(SparseVector<Element>) { new Vector<Element>(shift) }
# @category Data Conversion
# Convert to an equivalent dense matrix of the same element type.
# @tparam Element
# @param SparseMatrix<Element> m
# @return Matrix<Element>
user_function dense<Element>(SparseMatrix<Element,_>) { new Matrix<Element>(shift) }
# @category Data Conversion
# @param Set S
# @tparam Scalar
user_function toVector<Scalar>(Set:wary:anchor $) : c++ (name => 'same_element_sparse_vector', include => "polymake/SparseVector.h");
# @category Data Conversion
# Convert an IncidenceMatrix to a SparseMatrix.
# @param IncidenceMatrix A
# @tparam Scalar
# @return SparseMatrix<Scalar>
# @example > $M = toMatrix<Int>(cube(2)->VERTICES_IN_FACETS);
# > print $M->type->full_name;
# | SparseMatrix<Int, NonSymmetric>
user_function toMatrix<Scalar>(IncidenceMatrix:anchor) : c++ (name => 'same_element_sparse_matrix', include => "polymake/SparseMatrix.h");
# @category Data Conversion
# Convert to a dense 0/1 matrix.
# @param IncidenceMatrix m
# @return Matrix<Int>
user_function dense(IncidenceMatrix) { dense(toMatrix<Int>(@_)); }
# @category Data Conversion
# Convert to a dense 0/1 vector of a given dimension.
# @param Set s
# @param Int dim
# @return Vector<Int>
user_function dense(Set $) { dense(toVector<Int>(@_)); }
# @category Data Conversion
# Get the positions of non-zero entries of a sparse vector.
# @param SparseVector v
# @return Set<Int>
# @example > $v = new SparseVector(0,1,1,0,0,0,2,0,3);
# > print indices($v);
# | {1 2 6 8}
user_function indices(SparseVector:anchor) : c++ (include => "polymake/Set.h");
# @category Data Conversion
# Get the positions of non-zero entries of a vector.
# @param Vector v
# @return Set<Int>
# @example > print support(new Vector(0,23,0,0,23,0,23,0,0,23));
# | {1 4 6 9}
user_function support(Vector:anchor) : c++ (include => "polymake/linalg.h");
# @category Data Conversion
# Get the positions of non-zero entries of a sparse matrix.
# @param SparseMatrix m
# @return 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}
user_function index_matrix(SparseMatrix:anchor) : c++ (include => "polymake/IncidenceMatrix.h");
##################################################################################
# types for tropical addition
# @category Arithmetic
# tropical addition: min
declare property_type Min : c++ (special => 'Min', include => "polymake/TropicalNumber.h") {
user_method orientation() { return 1; }
user_method apply {my ($o,$x,$y) = @_; return min($x,$y);}
}
# @category Arithmetic
# tropical addition: max
declare property_type Max : c++ (special => 'Max', include => "polymake/TropicalNumber.h") {
user_method orientation() { return -1; }
user_method apply {my ($o,$x,$y) = @_; return max($x,$y);}
}
# @category Arithmetic
# @tparam Addition
# @tparam Scalar default: [[Rational]]
declare property_type TropicalNumber<Addition, Scalar=Rational> : upgrades( Scalar ) : c++ \
(operators => '++ + += * *= / /= neg - @compare', include => "polymake/TropicalNumber.h") {
# The orientation of the associated addition, i.e.
# +1 if the corresponding 0 is +inf
# -1 if the corresponding 0 is -inf
# @return Int
user_method orientation() {
return Addition->orientation();
}
# The zero element of the tropical semiring of this element.
# @return Scalar
user_method zero() : static : c++ (include => "polymake/TropicalNumber.h");
};
# function is_tropical_addition(Min) {1}
# function is_tropical_addition(Max) {1}
# function is_tropical_addition() {0}
##################################################################################
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type Ring<Coefficient=Rational, Exponent=Int> \
: c++ (include => "polymake/Ring.h", operators => '@eq', default_constructor => 'Deserializing') {
# number of variables and the name stem
method construct(Int, String) : c++;
# list of names
method construct(String+) : c++;
# ring with polynomial coefficients
method construct(Ring, Int, String) : c++;
method construct(Ring, String+) : c++;
user_method variables() : returns(@) : c++ (include => "polymake/Polynomial.h");
user_method variable() : c++ (include => "polymake/Polynomial.h");
user_method n_vars() : c++ (include => "polymake/Polynomial.h");
user_method names() : c++;
method id() : c++;
type_method toXML { &Core::CPlusPlus::serialized_with_id_toXML }
}
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type Monomial<Coefficient=Rational, Exponent=Int> \
: c++ (operators => '@arith_nodiv / ^ ^= @compare', include => "polymake/Polynomial.h", default_constructor => 'Deserializing') {
method construct(Ring) : c++;
method construct(Vector,Ring) : c++;
}
# @category Algebraic Types
# A class for __univariate__ monomials.
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type UniMonomial<Coefficient=Rational, Exponent=Int> \
: c++ (operators => '@arith_nodiv / ^ ^= @compare', include => "polymake/RationalFunction.h") {
method construct(Ring) : c++;
method construct(*,Ring) : c++;
}
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type Term<Coefficient=Rational, Exponent=Int> \
: upgrades( Coefficient, Monomial<Coefficient, Exponent> ) \
: c++ (operators => '@arith @compare', include => "polymake/Polynomial.h", default_constructor => 'Deserializing') {
method construct(Ring) : c++;
method construct(Vector,*,Ring) : c++;
}
# @category Algebraic Types
# A class for __univariate__ terms.
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type UniTerm<Coefficient=Rational, Exponent=Int> \
: upgrades( Coefficient, UniMonomial<Coefficient, Exponent> ) \
: c++ (operators => '@arith @compare', include => "polymake/RationalFunction.h") {
method construct(Ring) : c++;
method construct(*,Ring) : c++;
}
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type Polynomial<Coefficient=Rational, Exponent=Int> \
: upgrades( Term<Coefficient, Exponent> ) \
: c++ (operators => '@arith @compare', include => "polymake/Polynomial.h", default_constructor => 'Deserializing') {
method construct(Ring) : c++;
method construct(*,Ring) : c++;
method construct(Matrix,*,Ring) : c++;
# The exponent of the leading monomial.
# @return Int
user_method lm_exp() : c++;
# The __leading coefficient__.
# @return Int
user_method lc() : c++;
user_method print_ordered(Matrix) : c++ : void;
user_method monomials_as_matrix() : c++;
user_method get_ring() : c++;
user_method trivial() : c++;
user_method coefficients_as_vector() : c++;
}
# @category Algebraic Types
# A class for __univariate__ polynomials.
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type UniPolynomial<Coefficient=Rational, Exponent=Int> \
: upgrades( UniTerm<Coefficient, Exponent> ) \
: c++ (operators => '@arith % %= @compare', include => "polymake/RationalFunction.h") {
method construct(Ring) : c++;
method construct(*,Ring) : c++;
method construct(*,*,Ring) : c++;
user_method deg() : c++;
user_method lower_deg() : c++;
# The __leading coefficient__.
# @return Int
user_method lc() : c++;
user_method print_ordered(Matrix) : c++ : void;
user_method evaluate_float($) : c++;
user_method evaluate(*;$=1) : c++;
}
# @category Arithmetic
# Returns the __greatest common divisor__ of two univariate polynomials.
# @param UniPolynomial p
# @param UniPolynomial q
# @return UniPolynomial
# @example We first create the polynomial ring with one variable, Rational coefficients and Int exponents.
# $r=new Ring<Rational, Int>(1);
# Then we create two UniPolynomials with said coefficient and exponent type:
# > $p = new UniPolynomial<Rational,Int>([2,2],[3,2],$r);
# > $q = new UniPolynomial<Rational,Int>([6,4],[4,2],$r);
# Printing them reveals what the constructor does:
# > print $p;
# | 2*x^3 + 2*x^2
# > print $q;
# | 4*x^4 + 6*x^2
# Now we can calculate their gcd:
# > print gcd($p,$q);
# | x^2
user_function gcd(UniPolynomial, UniPolynomial) : c++;
# @category Algebraic Types
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Int]]
declare property_type RationalFunction<Coefficient=Rational, Exponent=Int> \
: upgrades( UniPolynomial<Coefficient, Exponent> ) \
: c++ (operators => '@arith @eq', include => "polymake/RationalFunction.h") {
method construct(Ring) : c++;
method construct(*,*) : c++;
method construct(*,*,Ring) : c++;
}
# @category Arithmetic
# Returns the __numerator__ of a [[RationalFunction]] //f//.
# @param RationalFunction f
# @return Polynomial
user_function numerator(RationalFunction) : c++;
# @category Arithmetic
# Returns the __denominator__ of a [[RationalFunction]] //f//.
# @param RationalFunction f
# @return Polynomial
user_function denominator(RationalFunction) : c++;
# @category Algebraic Types
# @tparam MinMax type of tropical addition: either [[Min]] or [[Max]]
# @tparam Coefficient default: [[Rational]]
# @tparam Exponent default: [[Rational]]
declare property_type PuiseuxFraction<MinMax, Coefficient=Rational, Exponent=Rational> \
: upgrades( Coefficient ) \
: c++ (operators => '@arith @compare', include => "polymake/PuiseuxFraction.h") {
method construct(type_upgrades_to< RationalFunction<Coefficient,Exponent> >) : c++;
method construct(type_upgrades_to< UniPolynomial<Coefficient,Exponent> >,type_upgrades_to< UniPolynomial<Coefficient,Exponent> >) : c++;
# The __valuation__.
# @return TropicalNumber<MinMax>
user_method val() : c++;
# Approximate evaluation at //x//
# @param Float x
# @return Float
user_method evaluate_float($) : c++;
# Approximate evaluation of a [[Matrix]] at //x//
# @param Matrix m
# @param Float x
# @return Float
user_method evaluate_float(Matrix,*) : static : c++;
# Approximate evaluation of a [[Vector]] at //x//
# @param Vector v
# @param Float x
# @return Float
user_method evaluate_float(Vector,*) : static : c++;
# Evaluate all [[PuiseuxFraction]]s in a [[Matrix]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Matrix m
# @param Coefficient x
# @param Int exp (default: 1)
# @return Matrix<Coefficient>
user_method evaluate(Matrix,*;$=1) : static : c++;
# Evaluate all [[PuiseuxFraction]]s in a [[Vector]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Vector v
# @param Coefficient x
# @param Int exp (default: 1)
# @return Vector<Coefficient>
user_method evaluate(Vector,*;$=1) : static : c++;
# Evaluate a [[PuiseuxFraction]] at a [[Rational]] number (//x^exp//).
# Let //explcm// be the lcm of the denominators of all exponents.
# If there are no denominators or //explcm// divides //exp//, then the evaluation
# is computed exactly.
# Otherwise, some rational number close to the root //(x^exp)^-explcm// will be chosen
# via an intermediate floating point number.
# @param Coefficient x
# @param Int exp (default: 1)
# @return Coefficient
user_method evaluate(*;$=1) : c++;
}
function is_ordered_field_with_unlimited_precision(PuiseuxFraction) { 1 }
# @category Arithmetic
# Returns the __numerator__ of a [[PuiseuxFraction]] //f//.
# @param PuiseuxFraction f
# @return Polynomial
user_function numerator(PuiseuxFraction) : c++;
# @category Arithmetic
# Returns the __denominator__ of a [[PuiseuxFraction]] //f//.
# @param PuiseuxFraction f
# @return Polynomial
user_function denominator(PuiseuxFraction) : c++;
# @topic category property_types/Linear Algebra
# These types are needed as return types of algebraic computations.
# @category Linear Algebra
# Complete result of the __Smith normal form__ computation.
# Contains the following fields:
# SparseMatrix<Scalar> form: the Smith normal form S of the given matrix //M//
# List<Pair<Scalar, Int>> torsion: absolute values of the entries greater than 1 of the diagonal together with their multiplicity
# Int rank: rank of //M//
# SparseMatrix<Scalar> left_companion, right_companion: unimodular matrices L and R such that
# M = LSR in normal case, or S = LMR in inverted case (as specified in the call to [[smith_normal_form]] function).
declare property_type SmithNormalForm<Scalar> : c++ (include => "polymake/Smith_normal_form.h");
# @category Linear Algebra
# Compute the __Smith normal form__ of a given matrix //M//.
# @param Matrix M must be of integer type
# @param Bool inv optional, if true, compute the inverse of the companion matrices
# @return SmithNormalForm<Integer>
# @example > $M = new Matrix<Integer>([1,2],[23,24]);
# > $SNF = smith_normal_form($M);
# The following line prints the three matrices seperated by newline characters.
# > print $SNF->left_companion ,"\n", $SNF->form ,"\n", $SNF->right_companion;
# | 1 0
# | 23 1
# |
# | 1 0
# | 0 -22
# |
# | 1 2
# | 0 1
user_function smith_normal_form(Matrix; $=0) : c++ (include => "polymake/Smith_normal_form.h");
# Local Variables:
# mode: perl
# cperl-indent-level: 3
# indent-tabs-mode:nil
# End:
|