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 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054
|
#############################################################################
##
## This file is part of GAP, a system for computational discrete algebra.
##
## SPDX-License-Identifier: GPL-2.0-or-later
##
## Copyright of GAP belongs to its developers, whose names are too numerous
## to list here. Please refer to the COPYRIGHT file for details.
##
#############################################################################
##
## This file together with 'matobj1.gd' formally define the interface to
## those vector and matrix objects in GAP that are not represented
## by plain lists.
## In this file all the operations and attributes are defined.
## It is read later in the GAP library reading process.
##
#############################################################################
##
## <#GAPDoc Label="MatObj_Overview">
##
## Traditionally, vectors and matrices in &GAP; have been represented by
## (lists of) lists, see the chapters
## <Ref Chap="Row Vectors"/> and <Ref Chap="Matrices"/>.
## More precisely, the term <Q>vector</Q>
## (corresponding to the filter <Ref Filt="IsVector"/>)
## is used in the abstract sense of an <Q>element of a vector space</Q>,
## the term <Q>row vector</Q> (corresponding to <Ref Filt="IsRowVector"/>)
## is used to denote a <Q>coordinate vector</Q> which is represented by
## a &GAP; list (see <Ref Filt="IsList"/>),
## and the term <Q>matrix</Q> is used to denote a list of lists, with
## additional properties (see <Ref Filt="IsMatrix"/>).
## <P/>
## Unfortunately, such lists (objects in <Ref Filt="IsPlistRep"/>)
## cannot store their type,
## and so it is impossible to use the advantages of &GAP;'s method selection
## on them.
## This situation is unsustainable in the long run
## since more special representations (compressed, sparse, etc.)
## have already been and even more will be implemented.
## Here we describe a programming interface to vectors and matrices,
## which solves this problem,
## <P/>
## The idea of this interface is that &GAP; should be able to
## represent vectors and matrices by objects that store their type,
## in order to benefit from method selection.
## These objects are created by <Ref Func="Objectify"/>,
## we therefore refer to the them as <Q>vector objects</Q> and
## <Q>matrix objects</Q> respectively.
## <P/>
## (Of course the terminology is somewhat confusing:
## An <Q>abstract matrix</Q> in &GAP; can be represented either by a list of
## lists or by a matrix object.
## It can be detected from the filter <Ref Filt="IsMatrixOrMatrixObj"/>;
## this is the union of the filters <Ref Filt="IsMatrix"/>
## –which denotes those matrices that are represented by lists of
## lists–
## and the filter <Ref Filt="IsMatrixObj"/>
## –which defines <Q>proper</Q> matrix objects in the above sense.
## In particular, we do <E>not</E> regard the objects in
## <Ref Filt="IsMatrix"/> as special cases of objects in
## <Ref Filt="IsMatrixObj"/>, or vice versa.
## Thus one can install specific methods for all three situations:
## just for <Q>proper</Q> matrix objects, just for matrices represented
## by lists of lists, or for both kinds of matrices.
## For example, a &GAP; package may decide to accept only <Q>proper</Q>
## matrix objects as arguments of its functions, or it may try to support
## also objects in <Ref Filt="IsMatrix"/> as far as this is possible.)
## <P/>
## We want to be able to write (efficient) code that is independent of the
## actual representation (in the sense of &GAP;'s representation filters,
## see Section <Ref Sect="Representation"/>)
## and preserves it.
## <P/>
## This latter requirement makes it necessary to distinguish between
## different representations of matrices:
## <Q>Row list</Q> matrices (see <Ref Filt="IsRowListMatrix"/>
## behave basically like lists of rows,
## in particular the rows are individual &GAP; objects that can
## be shared between different matrix objects.
## One can think of other representations of matrices,
## such as matrices whose subobjects represent columns,
## or <Q>flat</Q> matrices which do not have subobjects like rows or
## columns at all.
## The different kinds of matrices have to be distinguished
## already with respect to the definition of the operations for them.
## <P/>
## In particular vector and matrix objects know their base domain
## (see <Ref Attr="BaseDomain" Label="for a vector object"/>)
## and their dimensions.
## The basic condition is that the entries of vector and matrix objects
## must either lie in the base domain or naturally embed in the sense that
## addition and multiplication automatically work with elements of the
## base domain;
## for example, a matrix object over a polynomial ring may also contain
## entries from the coefficient ring.
## <P/>
## Vector and matrix objects may be mutable or immutable.
## Of course all operations changing an object are only allowed/implemented
## for mutable variants.
## <P/>
## Vector objects are equal with respect to <Ref Oper="\="/>
## if they have the same length and the same entries.
## It is not necessary that they have the same base domain.
## Matrices are equal with respect to <Ref Oper="\="/>
## if they have the same dimensions and the same entries.
## <P/>
## For a row list matrix object, it is not guaranteed that all its rows
## have the same vector type.
## It is for example thinkable that a matrix object stores some of its rows
## in a sparse representation and some in a dense one.
## However, it is guaranteed that the rows of two matrices in the same
## representation are compatible in the sense that all vector operations
## defined in this interface can be applied to them and that new matrices
## in the same representation as the original matrix can be formed out of
## them.
## <P/>
## Note that there is neither a default mapping from the set of
## matrix object representations to the set of vector representations
## nor one in the reverse direction.
## There is in general no <Q>associated</Q> vector object representation
## to a matrix object representation or vice versa.
## (However,
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/>
## may describe a vector object representation that is compatible with a
## given matrix object.)
## <P/>
## The recommended way to write code that preserves the representation
## basically works by using constructing operations that take template
## objects to decide about the intended representation for the new object.
## <P/>
## Vector and matrix objects do not have to be &GAP; lists in the sense of
## <Ref Filt="IsList"/>.
## Note that objects not in the filter <Ref Filt="IsList"/> need not
## support all list operations, and their behaviour is not prescribed by the
## rules for lists, e.g., behaviour w.r.t. arithmetic operations.
## However, row list matrices behave nearly like lists of row vectors
## that insist on being dense and containing only vectors of the same
## length and with the same base domain.
## <P/>
## Vector and matrix objects are not likely to benefit from &GAP;'s
## immediate methods (see section <Ref Sect="Immediate Methods"/>).
## Therefore it may be useful to set the filter
## <Ref Filt="IsNoImmediateMethodsObject"/> in the definition of new kinds
## of vector and matrix objects.
## <P/>
## For information on how to implement new <Ref Filt="IsMatrixObj"/> and
## <Ref Filt="IsVectorObj"/> representations see Section
## <Ref Sect="Implementing New Vector and Matrix Objects Types"/>.
## <#/GAPDoc>
##
#############################################################################
##
#A Length( <v> )
##
## <#GAPDoc Label="Length_IsVectorObj">
## <ManSection>
## <Attr Name="Length" Arg='v' Label="for a vector object"/>
##
## <Description>
## returns the length of the vector object <A>v</A>,
## which is defined to be the number of entries of <A>v</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "Length", IsVectorObj );
#############################################################################
##
#A ConstructingFilter( <v> )
#A ConstructingFilter( <M> )
##
## <#GAPDoc Label="ConstructingFilter">
## <ManSection>
## <Heading>ConstructingFilter</Heading>
## <Attr Name="ConstructingFilter" Arg="v" Label="for a vector object"/>
## <Attr Name="ConstructingFilter" Arg="M" Label="for a matrix object"/>
##
## <Returns>a filter</Returns>
## <Description>
## Called with a vector object <A>v</A> or a matrix object <A>M</A>,
## respectively,
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> returns
## a filter <C>f</C> such that when
## <Ref Oper="NewVector"/> or <Ref Oper="NewMatrix"/>, respectively,
## is called with <C>f</C> then a vector object or a matrix object,
## respectively, in the same representation as the argument is produced.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value of <A>v</A> or <A>M</A> implies <Ref Filt="IsCopyable"/> then
## mutable versions of <A>v</A> or <A>M</A> can be created,
## otherwise all vector or matrix objects with this filter are immutable.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "ConstructingFilter", IsVecOrMatObj );
#############################################################################
##
#A CompatibleVectorFilter( <M> )
##
## <#GAPDoc Label="CompatibleVectorFilter">
## <ManSection>
## <Heading>CompatibleVectorFilter</Heading>
## <Attr Name="CompatibleVectorFilter" Arg="M" Label="for a matrix object"/>
##
## <Returns>a filter</Returns>
## <Description>
## Called with a matrix object <A>M</A>,
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> returns
## either a filter <C>f</C> such that vector objects with
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> value
## <C>f</C> are compatible in the sense that <A>M</A> can be multiplied with
## these vector objects, of <K>fail</K> if no such filter is known.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareAttribute( "CompatibleVectorFilter", IsMatrixOrMatrixObj );
#############################################################################
##
## List Like Operations for Vector Objects
##
#############################################################################
##
#O \[\]( <v>, <i> )
#O \[\]\:\=( <v>, <i>, <obj> )
#O \{\}( <v>, <list> )
##
## <#GAPDoc Label="ElementAccessVectorObj">
## <ManSection>
## <Heading>Element Access and Assignment for Vector Objects</Heading>
##
## <Oper Name="\[\]" Arg="v,i" Label="for a vector object and an integer"/>
## <Oper Name="\[\]\:\=" Arg="v,i,obj"
## Label="for a vector object and an integer"/>
## <Oper Name="\{\}" Arg="v,list" Label="for a vector object and a list"/>
##
## <Description>
## For a vector object <A>v</A> and a positive integer <A>i</A> that is
## not larger than the length of <A>v</A>
## (see <Ref Attr="Length" Label="for a vector object"/>),
## <A>v</A><C>[</C><A>i</A><C>]</C> is the entry at position <A>i</A>.
## <P/>
## If <A>v</A> is mutable, <A>i</A> is as above, and <A>obj</A> is an object
## from the base domain of <A>v</A> then
## <A>v</A><C>[</C><A>i</A><C>]:= </C><A>obj</A> assigns <A>obj</A> to the
## <A>i</A>-th position of <A>v</A>.
## <P/>
## If <A>list</A> is a list of positive integers that are not larger than
## the length of <A>v</A> then
## <A>v</A><C>{</C><A>list</A><C>}</C> returns a new mutable vector object
## in the same representation as <A>v</A>
## (see <Ref Attr="ConstructingFilter" Label="for a vector object"/>)
## that contains the <A>list</A><M>[ k ]</M>-th entry of <A>v</A> at
## position <M>k</M>.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="\[\]\:\=" Label="for a vector object and an integer"/>
## need not perform consistency checks.
## <P/>
## Note that the sublist assignment operation <Ref Oper="\{\}\:\="/>
## is left out here since it tempts the programmer to use constructions like
## <C>v{ [ 1 .. 3 ] }:= w{ [ 4 .. 6 ] }</C>
## which produces an unnecessary intermediate object;
## one should use <Ref Oper="CopySubVector"/> instead.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "[]", [ IsVectorObj, IsPosInt ] );
DeclareOperation( "[]:=", [ IsVectorObj, IsPosInt, IsObject ] );
DeclareOperation( "{}", [ IsVectorObj, IsList ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_PositionNonZero">
## <ManSection>
## <Oper Name="PositionNonZero" Arg="v" Label="for a vector object"/>
##
## <Returns>An integer</Returns>
## <Description>
## Returns the index of the first entry in the vector object <A>v</A>
## that is not zero.
## If all entries are zero,
## the function returns <C>Length(<A>v</A>) + 1</C>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "PositionNonZero", [ IsVectorObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_PositionLastNonZero">
## <ManSection>
## <Oper Name="PositionLastNonZero" Arg="v"
## Label="for a vector object"/>
##
## <Returns>An integer</Returns>
## <Description>
## Returns the index of the last entry in the vector object <A>v</A>
## that is not zero.
## If all entries are zero, the function returns <M>0</M>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "PositionLastNonZero", [ IsVectorObj ] );
#############################################################################
##
#O ListOp( <v>[, <func>] )
##
## <#GAPDoc Label="MatObj_ListOp">
## <ManSection>
## <Oper Name="ListOp" Arg="v[, func]"
## Label="for vector object and function"/>
##
## <Returns>A plain list</Returns>
## <Description>
## Applies the function <A>func</A> to each entry of the vector object
## <A>v</A> and returns the results as a mutable plain list.
## This allows for calling <Ref Func="List" Label="for a collection"/>
## on vector objects.
## <P/>
## If the argument <A>func</A> is not given,
## applies <Ref Func="IdFunc"/> to all entries.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ListOp", [ IsVectorObj ] );
DeclareOperation( "ListOp", [ IsVectorObj, IsFunction ] );
#############################################################################
##
#O Unpack( <v> )
#O Unpack( <M> )
##
## <#GAPDoc Label="Unpack">
## <ManSection>
## <Heading>Unpack</Heading>
## <Oper Name="Unpack" Arg="v" Label="for a vector object"/>
## <Oper Name="Unpack" Arg="M" Label="for a matrix object"/>
##
## <Returns>A plain list</Returns>
## <Description>
## Returns a new mutable plain list (see <Ref Filt="IsPlistRep"/>)
## containing the entries of the vector object <A>v</A> or the matrix object
## <A>M</A>, respectively.
## In the case of a matrix object,
## the result is a plain list of plain lists.
## <P/>
## Changing the result does not change <A>v</A> or <A>M</A>, respectively.
## The entries themselves are not copied.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
## Note that 'AsList' would not be suitable in the case of vector objects
## because its result would be immutable.
##
DeclareOperation( "Unpack", [ IsVecOrMatObj ] );
#DeclareOperation( "Unpack", [ IsVectorObj ] );
#DeclareOperation( "Unpack", [ IsMatrixOrMatrixObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_ConcatenationOfVectors">
## <ManSection>
## <Heading>ConcatenationOfVectors</Heading>
## <Func Name="ConcatenationOfVectors" Arg="v1,v2,..."
## Label="for arbitrary many vector objects"/>
## <Func Name="ConcatenationOfVectors" Arg="vlist"
## Label="for a list of vector objects"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## Returns a new mutable vector object in the representation of <A>v1</A>
## or the first entry of the nonempty list <A>vlist</A> of vector objects,
## respectively,
## such that the entries are the concatenation of the given vector objects.
## <P/>
## (Note that <Ref Func="Concatenation" Label="for several lists"/>
## is a function for which no methods can be installed.)
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareGlobalFunction( "ConcatenationOfVectors" );
#############################################################################
##
## <#GAPDoc Label="MatObj_ExtractSubVector">
## <ManSection>
## <Oper Name="ExtractSubVector" Arg="v,l"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## Returns a new mutable vector object of the same vector representation
## as <A>v</A>, containing the entries of <A>v</A> at the positions in
## the list <A>l</A>.
## <P/>
## This is the same as <A>v</A><C>{</C><A>l</A><C>}</C>,
## the name <Ref Oper="ExtractSubVector"/> was introduced in analogy to
## <Ref Oper="ExtractSubMatrix"/>, for which no equivalent syntax using
## curly brackets is available.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ExtractSubVector", [ IsVectorObj, IsList ] );
#############################################################################
##
## Arithmetical operations for vector objects
##
#############################################################################
##
#O AddVector( <dst>, <src>[, <mul>[, <from>, <to>]] )
#O AddVector( <dst>, <mul>, <src>[, <from>, <to>] )
##
## <#GAPDoc Label="MatObj_AddVector">
## <ManSection>
## <Oper Name="AddVector" Arg='dst, src[, mul[, from, to]]'
## Label="for two vector objects"/>
## <Oper Name="AddVector" Arg='dst, mul, src[, from, to]'
## Label="for two vector objects and a scalar"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## Called with two vector objects <A>dst</A> and <A>src</A>,
## this function replaces the entries of <A>dst</A> in-place
## by the entries of the sum <A>dst</A><C> + </C><A>src</A>.
## <P/>
## If a scalar <A>mul</A> is given as the third or second argument,
## respectively, then the entries of <A>dst</A> get replaced by those of
## <A>dst</A><C> + </C><A>src</A><C> * </C><A>mul</A> or
## <A>dst</A><C> + </C><A>mul</A><C> * </C><A>src</A>, respectively.
## <P/>
## If the optional parameters <A>from</A> and <A>to</A> are given then
## only the index range <C>[<A>from</A>..<A>to</A>]</C> is guaranteed to be
## affected.
## Other indices <E>may</E> be affected, if it is more convenient to do so.
## This can be helpful if entries of <A>src</A> are known to be zero.
## <P/>
## If <A>from</A> is bigger than <A>to</A>, the operation does nothing.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj, IsObject ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsObject, IsVectorObj ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsVectorObj, IsObject, IsPosInt, IsPosInt ] );
DeclareOperation( "AddVector",
[ IsVectorObj and IsMutable, IsObject, IsVectorObj, IsPosInt, IsPosInt ] );
#############################################################################
##
#O MultVector( <v>, <mul>[, <from>, <to>] )
#O MultVectorLeft( <v>, <mul>[, <from>, <to>] )
#O MultVectorRight( <v>, <mul>[, <from>, <to>] )
##
## <#GAPDoc Label="MatObj_MultVectorLeft">
## <ManSection>
## <Oper Name="MultVector" Arg='v, mul[, from, to]'
## Label="for a vector object"/>
## <Oper Name="MultVectorLeft" Arg='v, mul[, from, to]'
## Label="for a vector object"/>
## <Oper Name="MultVectorRight" Arg='v, mul[, from, to]'
## Label="for a vector object"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## These operations multiply <A>v</A> by <A>mul</A> in-place
## where <Ref Oper="MultVectorLeft" Label="for a vector object"/>
## multiplies with <A>mul</A> from the left
## and <Ref Oper="MultVectorRight" Label="for a vector object"/>
## does so from the right.
## <P/>
## Note that <Ref Oper="MultVector" Label="for a vector object"/>
## is just a synonym for
## <Ref Oper="MultVectorLeft" Label="for a vector object"/>.
## This was chosen because vectors in &GAP; are by default row vectors
## and scalar multiplication is usually written as
## <M>a \cdot v = a \cdot [v_1, ..., v_n] = [a \cdot v_1, ..., a \cdot v_n]</M>
## with scalars being applied from the left.
## <P/>
## If the optional parameters <A>from</A> and <A>to</A> are given then
## only the index range <C>[<A>from</A>..<A>to</A>]</C> is guaranteed to be
## affected. Other indices <E>may</E> be affected, if it is more convenient
## to do so.
## This can be helpful if entries of <A>v</A> are known to be zero.
## If <A>from</A> is bigger than <A>to</A>, the operation does nothing.
## <P/>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultVectorLeft",
[ IsVectorObj and IsMutable, IsObject ] );
DeclareOperation( "MultVectorLeft",
[ IsVectorObj and IsMutable, IsObject, IsInt, IsInt ] );
DeclareOperation( "MultVectorRight",
[ IsVectorObj and IsMutable, IsObject ] );
DeclareOperation( "MultVectorRight",
[ IsVectorObj and IsMutable, IsObject, IsInt, IsInt ] );
# This is defined for two vectors of equal length,
# it returns the standard scalar product.
# (The documentation is in the section about arithm. operations.)
DeclareOperation( "ScalarProduct", [ IsVectorObj, IsVectorObj ] );
#############################################################################
##
#O ZeroVector( <filt>, <R>, <len> )
#O ZeroVector( <R>, <len> )
#O ZeroVector( <len>, <v> )
#O ZeroVector( <len>, <M> )
##
## <#GAPDoc Label="VectorObj_ZeroVector">
## <ManSection>
## <Heading>ZeroVector</Heading>
## <Oper Name="ZeroVector" Arg="filt,R,len" Label="for filter, base domain and length"/>
## <Oper Name="ZeroVector" Arg="R,len" Label="for base domain and length"/>
## <Oper Name="ZeroVector" Arg="len,v" Label="for length and vector object"/>
## <Oper Name="ZeroVector" Arg="len,M" Label="for length and matrix object"/>
##
## <Returns>a vector object</Returns>
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A> and a nonnegative integer <A>len</A>,
## this operation returns a new vector object of length <A>len</A> over <A>R</A>
## in the representation <A>filt</A> containing only zeros.
## <P/>
## If only <A>R</A> and <A>len</A> are given,
## then &GAP; guesses a suitable representation.
## <P/>
## For a vector object <A>v</A> and a nonnegative integer <A>len</A>,
## this operation returns a new vector object of length <A>len</A>
## in the same representation as <A>v</A> containing only zeros.
## <P/>
## For a matrix object <A>M</A> and a nonnegative integer <A>len</A>,
## this operation returns a new zero vector object of length
## <A>len</A> in the representation given by the
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> value
## of <A>M</A>, provided that such a representation exists.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## mutable.
## <P/>
## Default methods for
## <Ref Oper="ZeroVector" Label="for filter, base domain and length"/>
## delegate to <Ref Oper="NewZeroVector"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ZeroVector", [ IsOperation, IsSemiring, IsInt ] );
DeclareOperation( "ZeroVector", [ IsSemiring, IsInt ] );
DeclareOperation( "ZeroVector", [ IsInt, IsVecOrMatObj ] );
#DeclareOperation( "ZeroVector", [ IsInt, IsVectorObj ] );
#DeclareOperation( "ZeroVector", [ IsInt, IsMatrixOrMatrixObj ] );
#############################################################################
##
#O Vector( <filt>, <R>, <list> )
#O Vector( <filt>, <R>, <v> )
#O Vector( <R>, <list> )
#O Vector( <R>, <v> )
#O Vector( <list>, <v> )
#O Vector( <v1>, <v2> )
##
## <#GAPDoc Label="Vector">
## <ManSection>
## <Heading>Vector</Heading>
## <Oper Name="Vector" Arg='filt,R,list'
## Label="for filter, base domain, and list"/>
## <Oper Name="Vector" Arg='filt,R,v'
## Label="for filter, base domain, and vector object"/>
## <Oper Name="Vector" Arg='R,list'
## Label="for base domain and list"/>
## <Oper Name="Vector" Arg='R,v'
## Label="for base domain and vector object"/>
## <Oper Name="Vector" Arg='list,v'
## Label="for a list and a vector object"/>
## <Oper Name="Vector" Arg='v1,v2'
## Label="for two vector objects"/>
## <Oper Name="Vector" Arg='list'
## Label="for a list"/>
##
## <Returns>a vector object</Returns>
## <Description>
## If a filter <A>filt</A> is given as the first argument then
## a vector object is returned that has
## <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value <A>filt</A>, is defined over the base domain <A>R</A>,
## and has the entries given by the list <A>list</A> or the vector object
## <A>v</A>, respectively.
## <P/>
## If a semiring <A>R</A> is given as the first argument then
## a vector object is returned whose
## <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value is guessed from <A>R</A>, again with base domain <A>R</A>
## and entries given by the last argument.
## <P/>
## In the remaining cases with two arguments,
## the first argument is a list or a vector object
## that defines the entries of the result,
## and the second argument is a vector object whose
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> are taken for the
## result.
## <P/>
## If only a list <A>list</A> is given then both the
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and the
## <Ref Attr="BaseDomain" Label="for a vector object"/> are guessed from
## this list.
## <P/>
## The variant <C>Vector( </C><A>v1</A><C>, </C><A>v2</A><C> )</C>
## is supported also for the case that <A>v2</A> is a row vector but not
## a vector object.
## In this situation, the result is a row vector that is equal to
## <A>v1</A> and whose internal representation fits to that of <A>v2</A>.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="Vector" Label="for filter, base domain, and list"/>
## need not perform consistency checks.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## mutable if and only if the argument that determines the entries of the
## result (<A>list</A>, <A>v</A>, <A>v1</A>) is mutable.
## <P/>
## In the case of a mutable result, it is <E>not</E> guaranteed that
## the given list of entries is copied.
## <P/>
## Default methods for
## <Ref Oper="Vector" Label="for filter, base domain, and list"/>
## delegate to <Ref Oper="NewVector"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Vector", [ IsOperation, IsSemiring, IsList ] );
DeclareOperation( "Vector", [ IsOperation, IsSemiring, IsVectorObj ] );
DeclareOperation( "Vector", [ IsSemiring, IsList ] );
DeclareOperation( "Vector", [ IsSemiring, IsVectorObj ] );
DeclareOperation( "Vector", [ IsList, IsVectorObj ] );
DeclareOperation( "Vector", [ IsVectorObj, IsVectorObj ] );
DeclareOperation( "Vector", [ IsList ] );
#############################################################################
##
#O NewVector( <filt>, <R>, <list> )
#O NewZeroVector( <filt>, <R>, <n> )
##
## <#GAPDoc Label="NewVector">
## <ManSection>
## <Heading>NewVector and NewZeroVector</Heading>
## <Oper Name="NewVector" Arg='filt,R,list'/>
## <Oper Name="NewZeroVector" Arg='filt,R,n'/>
##
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A>, and a list <A>list</A>
## of elements that belong to <A>R</A>,
## <Ref Oper="NewVector"/> returns a vector object which has
## the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## <A>filt</A>,
## the <Ref Attr="BaseDomain" Label="for a vector object"/> <A>R</A>,
## and the entries in <A>list</A>.
## The list <A>list</A> is guaranteed not to be changed by this operation.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="NewVector"/> need not perform consistency checks.
## <P/>
## Similarly, <Ref Oper="NewZeroVector"/> returns a vector object
## of length <A>n</A> which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values,
## and contains the zero of <A>R</A> in each position.
## <P/>
## The returned object is mutable if and only if <A>filt</A> implies
## <Ref Filt="IsCopyable"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareTagBasedOperation( "NewVector", [ IsOperation, IsSemiring, IsList ] );
DeclareTagBasedOperation( "NewZeroVector",
[ IsOperation, IsSemiring, IsInt ] );
#############################################################################
##
#O NewMatrix( <filt>, <R>, <ncols>, <list> )
#O NewZeroMatrix( <filt>, <R>, <m>, <n> )
#O NewIdentityMatrix( <filt>, <R>, <n> )
##
## <#GAPDoc Label="NewMatrix">
## <ManSection>
## <Heading>NewMatrix, NewZeroMatrix, NewIdentityMatrix</Heading>
## <Oper Name="NewMatrix" Arg='filt,R,ncols,list'/>
## <Oper Name="NewZeroMatrix" Arg='filt,R,m,n'/>
## <Oper Name="NewIdentityMatrix" Arg='filt,R,n'/>
##
## <Description>
## For a filter <A>filt</A>, a semiring <A>R</A>,
## a positive integer <A>ncols</A>, and a list <A>list</A>,
## <Ref Oper="NewMatrix"/> returns a matrix object which has
## the <Ref Attr="ConstructingFilter" Label="for a vector object"/>
## <A>filt</A>,
## the <Ref Attr="BaseDomain" Label="for a matrix object"/> <A>R</A>,
## <A>n</A> columns
## (see <Ref Attr="NumberColumns" Label="for a matrix object"/>),
## and the entries described by <A>list</A>,
## which can be either a plain list of vector objects of length <A>ncols</A>
## or a plain list of plain lists of length <A>ncols</A>
## or a plain list of length a multiple of <A>ncols</A> containing the
## entries in row major order.
## The list <A>list</A> is guaranteed not to be changed by this operation.
## <P/>
## The corresponding entries must be in or compatible with <A>R</A>.
## If <A>list</A> already contains vector objects, they are copied.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="NewMatrix"/> need not perform consistency checks.
## <P/>
## Similarly, <Ref Oper="NewZeroMatrix"/> returns a zero matrix
## object with <A>m</A> rows and <A>n</A> columns
## which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values.
## <P/>
## Similarly, <Ref Oper="NewIdentityMatrix"/> returns an identity
## matrix object with <A>n</A> rows and columns
## which has <A>filt</A> and <A>R</A> as
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> and
## <Ref Attr="BaseDomain" Label="for a vector object"/> values,
## and contains the identity element of <A>R</A> in the diagonal
## and the zero of <A>R</A> in each off-diagonal position.
## <P/>
## The returned object is mutable if and only if <A>filt</A> implies
## <Ref Filt="IsCopyable"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareTagBasedOperation( "NewMatrix",
[ IsOperation, IsSemiring, IsInt, IsList] );
DeclareTagBasedOperation( "NewZeroMatrix",
[ IsOperation, IsSemiring, IsInt, IsInt ] );
DeclareTagBasedOperation( "NewIdentityMatrix",
[ IsOperation, IsSemiring, IsInt ] );
#############################################################################
##
#O ChangedBaseDomain( <v>, <R> )
#O ChangedBaseDomain( <M>, <R> )
##
## <#GAPDoc Label="ChangedBaseDomain">
## <ManSection>
## <Heading>ChangedBaseDomain</Heading>
## <Oper Name="ChangedBaseDomain" Arg='v,R' Label="for a vector object"/>
## <Oper Name="ChangedBaseDomain" Arg='M,R' Label="for a matrix object"/>
##
## <Description>
## For a vector object <A>v</A> (a matrix object <A>M</A>)
## and a semiring <A>R</A>,
## <Ref Oper="ChangedBaseDomain" Label="for a vector object"/> returns
## a new vector object (matrix object)
## with <Ref Attr="BaseDomain" Label="for a vector object"/> value <A>R</A>,
## <Ref Attr="ConstructingFilter" Label="for a vector object"/> value
## equal to that of <A>v</A> (<A>M</A>),
## and the same entries as <A>v</A> (<A>M</A>).
## <P/>
## The result is mutable if and only if <A>v</A> (<A>M</A>) is mutable.
## <P/>
## For example, one can create a vector defined over <C>GF(4)</C>
## from a vector defined over <C>GF(2)</C> with this operation.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ChangedBaseDomain", [ IsVecOrMatObj, IsSemiring ] );
#DeclareOperation( "ChangedBaseDomain", [ IsVectorObj, IsSemiring ] );
#DeclareOperation( "ChangedBaseDomain", [ IsMatrixOrMatrixObj, IsSemiring ] );
############################################################################
##
#O Randomize( [Rs, ]v )
#O Randomize( [Rs, ]M )
##
## <#GAPDoc Label="Randomize">
## <ManSection>
## <Heading>Randomize</Heading>
## <Oper Name="Randomize" Arg="[Rs,]v" Label="for a vector object"/>
## <Oper Name="Randomize" Arg="[Rs,]M" Label="for a matrix object"/>
## <Description>
## Replaces every entry in the mutable vector object <A>v</A>
## or matrix object <A>M</A>, respectively, with
## a random one from the base domain of <A>v</A> or <A>M</A>,
## respectively, and returns the argument.
## <P/>
## If given, the random source <A>Rs</A> is used to compute the
## random elements.
## Note that in this case,
## a <Ref Oper="Random" Label="for random source and collection"/>
## method must be available that takes a random source as its first
## argument and the base domain as its second argument.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Randomize", [ IsVectorObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsRandomSource, IsVectorObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsMatrixOrMatrixObj and IsMutable ] );
DeclareOperation( "Randomize", [ IsRandomSource, IsMatrixOrMatrixObj and IsMutable ] );
#############################################################################
##
#O CopySubVector( <src>, <dst>, <scols>, <dcols> )
##
## <#GAPDoc Label="CopySubVector">
## <ManSection>
## <Oper Name="CopySubVector" Arg='src, dst, scols, dcols'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For two vector objects <A>src</A> and <A>dst</A>,
## such that <A>dst</A> is mutable,
## and two lists <A>scols</A> and <A>dcols</A> of positions,
## <Ref Oper="CopySubVector"/> assigns the entries
## <A>src</A><C>{ </C><A>scols</A><C> }</C>
## (see <Ref Oper="ExtractSubVector"/>)
## to the positions <A>dcols</A> in <A>dst</A>,
## but without creating an intermediate object and thus
## –at least in special cases–
## much more efficiently.
## <P/>
## For certain objects like compressed vectors this might be significantly
## more efficient if <A>scols</A> and <A>dcols</A> are ranges
## with increment 1.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="CopySubVector"/> need not perform consistency checks.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "CopySubVector",
[ IsVectorObj, IsVectorObj and IsMutable, IsList, IsList ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_WeightOfVector">
## <ManSection>
## <Oper Name="WeightOfVector" Arg="v" Label="for a vector object"/>
## <Returns>an integer</Returns>
## <Description>
## returns the Hamming weight of the vector object <A>v</A>,
## i.e., the number of nonzero entries in <A>v</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "WeightOfVector", [ IsVectorObj ] );
#############################################################################
##
## <#GAPDoc Label="MatObj_DistanceOfVectors">
## <ManSection>
## <Oper Name="DistanceOfVectors" Arg="v1,v2"
## Label="for two vector objects"/>
## <Returns>an integer</Returns>
## <Description>
## returns the Hamming distance of the vector objects <A>v1</A> and
## <A>v2</A>, i.e., the number of entries in which the vectors differ.
## The vectors must have equal length.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "DistanceOfVectors", [ IsVectorObj, IsVectorObj ] );
#############################################################################
##
#O ExtractSubMatrix( <M>, <rows>, <cols> )
##
## <#GAPDoc Label="ExtractSubMatrix">
## <ManSection>
## <Oper Name="ExtractSubMatrix" Arg='M, rows, cols'/>
##
## <Description>
## Creates a copy of the submatrix described by the two
## lists, which mean subsets of row and column positions, respectively.
## This does <A>M</A>{<A>rows</A>}{<A>cols</A>} and returns the result.
## It preserves the representation of the matrix.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## fully mutable.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ExtractSubMatrix", [ IsMatrixOrMatrixObj, IsList, IsList ] );
#############################################################################
##
#O MutableCopyMatrix( <M> )
##
## <#GAPDoc Label="MutableCopyMatrix">
## <ManSection>
## <Oper Name="MutableCopyMatrix" Arg='M' Label="for a matrix object"/>
##
## <Description>
## For a matrix object <A>M</A>, this operation returns a fully mutable
## copy of <A>M</A>, with the same
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> values,
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MutableCopyMatrix", [ IsMatrixOrMatrixObj ] );
#############################################################################
##
#O CopySubMatrix( <src>, <dst>, <srows>, <drows>, <scols>, <dcols> )
##
## <#GAPDoc Label="CopySubMatrix">
## <ManSection>
## <Oper Name="CopySubMatrix" Arg='src, dst, srows, drows, scols, dcols'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## Does <C><A>dst</A>{<A>drows</A>}{<A>dcols</A>} :=
## <A>src</A>{<A>srows</A>}{<A>scols</A>}</C>
## without creating an intermediate object and thus
## –at least in special cases–
## much more efficiently.
## For certain objects like compressed vectors this might be
## significantly more efficient if <A>scols</A> and <A>dcols</A> are
## ranges with increment 1.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="CopySubMatrix"/> need not perform consistency checks.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "CopySubMatrix",
[ IsMatrixOrMatrixObj, IsMatrixOrMatrixObj, IsList, IsList, IsList, IsList ] );
#############################################################################
##
#O MatElm( <M>, <row>, <col> ) . . . . . . select an entry from a matrix
#O <M>[ <row>, <col> ] . . . . . . . . . . select an entry from a matrix
##
## <#GAPDoc Label="MatObj_MatElm">
## <ManSection>
## <Oper Name="MatElm" Arg='M, row, col'/>
##
## <Returns>an entry of the matrix object</Returns>
##
## <Description>
## For a matrix object <A>M</A>, this operation returns the entry in
## row <A>row</A> and column <A>col</A>.
## <P/>
## Also the syntax <A>M</A><C>[ </C><A>row</A><C>, </C><A>col</A><C> ]</C>
## is supported.
## <P/>
## Note that this is <E>not</E> equivalent to
## <A>M</A><C>[ </C><A>row</A><C> ][ </C><A>col</A><C> ]</C>,
## which would first try to access <A>M</A><C>[ </C><A>row</A><C> ]</C>,
## and this is in general not possible.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperationKernel( "[,]", [ IsMatrixOrMatrixObj, IS_INT, IS_INT ], ELM_MAT );
DeclareSynonym( "MatElm", ELM_MAT );
#############################################################################
##
#O SetMatElm( <M>, <row>, <col>, <obj> ) . . . . set an entry in a matrix
#O <M>[ <row>, <col> ]:= <obj> . . . . . . . . . set an entry in a matrix
##
## <#GAPDoc Label="MatObj_SetMatElm">
## <ManSection>
## <Oper Name="SetMatElm" Arg='M, row, col, obj'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For a mutable matrix object <A>M</A>, this operation assigns the object
## <A>obj</A> to the position in row <A>row</A> and column <A>col</A>,
## provided that <A>obj</A> is compatible with the
## <Ref Attr="BaseDomain" Label="for a matrix object"/> value of <A>M</A>.
## <P/>
## Also the syntax
## <A>M</A><C>[ </C><A>row</A><C>, </C><A>col</A><C> ]:= </C><A>obj</A>
## is supported.
## <P/>
## Note that this is <E>not</E> equivalent to
## <A>M</A><C>[ </C><A>row</A><C> ][ </C><A>col</A><C> ]:= </C><A>obj</A>,
## which would first try to access <A>M</A><C>[ </C><A>row</A><C> ]</C>,
## and this is in general not possible.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="SetMatElm"/> need not perform consistency checks.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperationKernel( "[,]:=", [ IsMatrixOrMatrixObj, IsInt, IsInt, IsObject ],
ASS_MAT );
#T We want to require also 'IsMutable' for the first argument,
#T but some package may have installed methods without this requirement.
#T Note that if we declare the operation twice, once with requirement
#T 'IsMutable' and once without, each method installation will show
#T a complaint that it matches more than one declaration.
DeclareSynonym( "SetMatElm", ASS_MAT );
#############################################################################
##
#O ZeroMatrix( <m>, <n>, <M> )
#O ZeroMatrix( <R>, <m>, <n> )
#O ZeroMatrix( <filt>, <R>, <m>, <n> )
##
## <#GAPDoc Label="MatObj_ZeroMatrix">
## <ManSection>
## <Heading>ZeroMatrix</Heading>
## <Oper Name="ZeroMatrix" Arg="m, n, M"
## Label="for dimensions and matrix object"/>
## <Oper Name="ZeroMatrix" Arg="R, m, n"
## Label="for base domain and dimensions"/>
## <Oper Name="ZeroMatrix" Arg="filt, R, m, n"
## Label="for filter, base domain, and dimensions"/>
##
## <Returns>a matrix object</Returns>
## <Description>
## For a matrix object <A>M</A> and two nonnegative integers <A>m</A>
## and <A>n</A>, this operation returns a new matrix object
## with <A>m</A> rows and <A>n</A> columns
## in the same representation and over the same base domain as <A>M</A>
## containing only zeros.
## <P/>
## If a semiring <A>R</A> and two nonnegative integers <A>m</A> and
## <A>n</A> are given,
## the representation of the result is guessed from <A>R</A>.
## <P/>
## If a filter <A>filt</A> and a semiring <A>R</A> are given as the first
## and second argument, they are taken as the values of
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> of the result.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## fully mutable.
## <P/>
## Default methods for
## <Ref Oper="ZeroMatrix" Label="for dimensions and matrix object"/>
## delegate to <Ref Oper="NewZeroMatrix"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ZeroMatrix", [ IsInt, IsInt, IsMatrixOrMatrixObj ] );
DeclareOperation( "ZeroMatrix", [ IsSemiring, IsInt, IsInt ] );
DeclareOperation( "ZeroMatrix", [ IsOperation, IsSemiring, IsInt, IsInt ] );
#############################################################################
##
#O IdentityMatrix( <n>, <M> )
#O IdentityMatrix( <R>, <n> )
#O IdentityMatrix( <filt>, <R>, <n> )
##
## <#GAPDoc Label="MatObj_IdentityMatrix">
## <ManSection>
## <Heading>IdentityMatrix</Heading>
## <Oper Name="IdentityMatrix" Arg="n, M"
## Label="for dimension and matrix object"/>
## <Oper Name="IdentityMatrix" Arg="R, n"
## Label="for base domain and dimension"/>
## <Oper Name="IdentityMatrix" Arg="filt, R, n"
## Label="for filter, base domain, and dimension"/>
##
## <Returns>a matrix object</Returns>
## <Description>
## For a matrix object <A>M</A> and a nonnegative integer <A>n</A>,
## this operation returns a new identity matrix object
## with <A>n</A> rows and columns
## in the same representation and over the same base domain as <A>M</A>.
## <P/>
## If a semiring <A>R</A> and a nonnegative integer <A>n</A> is given,
## the representation of the result is guessed from <A>R</A>.
## <P/>
## If a filter <A>filt</A> and a semiring <A>R</A> are given as the first
## and second argument, they are taken as the values of
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> of the result.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## fully mutable.
## <P/>
## Default methods for
## <Ref Oper="IdentityMatrix" Label="for dimension and matrix object"/>
## delegate to <Ref Oper="NewIdentityMatrix"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "IdentityMatrix", [ IsInt, IsMatrixOrMatrixObj ] );
DeclareOperation( "IdentityMatrix", [ IsSemiring, IsInt ] );
DeclareOperation( "IdentityMatrix", [ IsOperation, IsSemiring, IsInt ] );
#############################################################################
##
#O CompanionMatrix( <pol>, <M> )
#O CompanionMatrix( [<filt>, ]<pol>, <R> )
##
## <#GAPDoc Label="MatObj_CompanionMatrix">
## <ManSection>
## <Heading>CompanionMatrix</Heading>
## <Oper Name="CompanionMatrix" Arg='pol, M'
## Label="for polynomial and matrix object"/>
## <Oper Name="CompanionMatrix" Arg='filt, pol, R'
## Label="for filter, polynomial, and semiring"/>
## <Oper Name="CompanionMatrix" Arg='pol, R'
## Label="for polynomial and semiring"/>
##
## <Returns>a matrix object</Returns>
## <Description>
## For a monic, univariate polynomial <A>pol</A> whose coefficients lie in
## the base domain of the matrix object <A>M</A>,
## <Ref Oper="CompanionMatrix" Label="for polynomial and matrix object"/>
## returns the companion matrix of <A>pol</A>,
## as a matrix object with the same
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> values as <A>M</A>.
## <P/>
## We use column convention, that is, the negatives of the coefficients of
## <A>pol</A> appear in the last column of the result.
## <P/>
## If a filter <A>filt</A> and a semiring <A>R</A> are given then the
## companion matrix is returned as a matrix object with
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> value
## <A>filt</A> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> value <A>R</A>.
## <P/>
## If only <A>pol</A> and a semiring <A>R</A> are given,
## the representation of the result is guessed from <A>R</A>.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## fully mutable.
## <P/>
## <Example><![CDATA[
## gap> x:= X( GF(5) );; pol:= x^3 + x^2 + 2*x + 3;;
## gap> M:= CompanionMatrix( IsPlistMatrixRep, pol, GF(25) );;
## gap> Display( M );
## <3x3-matrix over GF(5^2):
## [[ 0*Z(5), 0*Z(5), Z(5) ]
## [ Z(5)^0, 0*Z(5), Z(5)^3 ]
## [ 0*Z(5), Z(5)^0, Z(5)^2 ]
## ]>
## ]]></Example>
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "CompanionMatrix",
[ IsUnivariatePolynomial, IsMatrixOrMatrixObj ] );
DeclareOperation( "CompanionMatrix",
[ IsOperation, IsUnivariatePolynomial, IsSemiring ] );
DeclareOperation( "CompanionMatrix",
[ IsUnivariatePolynomial, IsSemiring ] );
#############################################################################
##
#O Matrix( <filt>, <R>, <list>, <ncols> )
#O Matrix( <filt>, <R>, <list> )
#O Matrix( <filt>, <R>, <M> )
#O Matrix( <R>, <list>, <ncols> )
#O Matrix( <R>, <list> )
#O Matrix( <R>, <M> )
#O Matrix( <list>, <ncols>, <M> )
#O Matrix( <list>, <M> )
#O Matrix( <M1>, <M2> )
#O Matrix( <list>, <ncols> )
#O Matrix( <list> )
##
## <#GAPDoc Label="MatObj_Matrix">
## <ManSection>
## <Heading>Matrix</Heading>
## <Oper Name="Matrix" Arg='filt,R,list,ncols'
## Label="for filter, base domain, list, ncols"/>
## <Oper Name="Matrix" Arg='filt,R,list'
## Label="for filter, base domain, and list"/>
## <Oper Name="Matrix" Arg='filt,R,M'
## Label="for filter, base domain, and matrix object"/>
## <Oper Name="Matrix" Arg='R,list,ncols'
## Label="for base domain, list, ncols"/>
## <Oper Name="Matrix" Arg='R,list'
## Label="for base domain and list"/>
## <Oper Name="Matrix" Arg='R,M'
## Label="for base domain and matrix object"/>
## <Oper Name="Matrix" Arg='list,ncols,M'
## Label="for a list, ncols, and a matrix object"/>
## <Oper Name="Matrix" Arg='list,M'
## Label="for a list and a matrix object"/>
## <Oper Name="Matrix" Arg='M1,M2'
## Label="for two matrix objects"/>
## <Oper Name="Matrix" Arg='list,ncols'
## Label="for a list and ncols"/>
## <Oper Name="Matrix" Arg='list'
## Label="for a list"/>
##
## <Returns>a matrix object</Returns>
## <Description>
## If a filter <A>filt</A> is given as the first argument then
## a matrix object is returned that has
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value <A>filt</A>, is defined over the base domain <A>R</A>,
## and has the entries given by the list <A>list</A> or the matrix object
## <A>M</A>, respectively.
## Here <A>list</A> can be either a list of plain lists that describe the
## entries of the rows, or a flat list of the entries in row major order,
## where <A>ncols</A> defines the number of columns.
## <P/>
## If a semiring <A>R</A> is given as the first argument then
## a matrix object is returned whose
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value is guessed from <A>R</A>, again with base domain <A>R</A>
## and entries given by the last argument.
## <P/>
## In those remaining cases where the last argument is a matrix object,
## the first argument is a list or a matrix object
## that defines (together with <A>ncols</A> if applicable) the entries of
## the result, and the
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> of the last argument
## are taken for the result.
## <P/>
## Finally, if only a list <A>list</A> and perhaps <A>ncols</A> is given
## then both the
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and the
## <Ref Attr="BaseDomain" Label="for a vector object"/> are guessed from
## the list.
## <P/>
## If the global option <C>check</C> is set to <K>false</K> then
## <Ref Oper="Matrix" Label="for filter, base domain, list, ncols"/>
## need not perform consistency checks.
## <P/>
## If the <Ref Attr="ConstructingFilter" Label="for a matrix object"/>
## value of the result implies <Ref Filt="IsCopyable"/> then the result is
## mutable if and only if the argument that determines the entries of the
## result (<A>list</A>, <A>M</A>, <A>M1</A>) is mutable.
## <P/>
## In the case of a mutable result, it is guaranteed that the given list
## <A>list</A> is copied in the sense of <Ref Oper="ShallowCopy"/>,
## and if <A>list</A> is a nested list then it is <E>not</E> guaranteed
## that also the entries of <A>list</A> are copied.
## <P/>
## Default methods for
## <Ref Oper="Matrix" Label="for filter, base domain, list, ncols"/>
## delegate to <Ref Oper="NewMatrix"/>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Matrix", [ IsOperation, IsSemiring, IsList, IsInt ] );
DeclareOperation( "Matrix", [ IsOperation, IsSemiring, IsList ] );
DeclareOperation( "Matrix", [ IsOperation, IsSemiring, IsMatrixOrMatrixObj ] );
DeclareOperation( "Matrix", [ IsSemiring, IsList, IsInt ] );
DeclareOperation( "Matrix", [ IsSemiring, IsList ] );
DeclareOperation( "Matrix", [ IsSemiring, IsMatrixOrMatrixObj ] );
DeclareOperation( "Matrix", [ IsList, IsInt, IsMatrixOrMatrixObj ] );
DeclareOperation( "Matrix", [ IsList, IsMatrixOrMatrixObj ] );
DeclareOperation( "Matrix", [ IsMatrixOrMatrixObj, IsMatrixOrMatrixObj ] );
DeclareOperation( "Matrix", [ IsList, IsInt ] );
DeclareOperation( "Matrix", [ IsList ]);
############################################################################
##
#A CompatibleVector( <M> )
##
## <#GAPDoc Label="CompatibleVector">
## <ManSection>
## <Oper Name="CompatibleVector" Arg='M' Label="for a matrix object"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## Called with a matrix object <A>M</A> with <M>m</M> rows,
## this operation returns a mutable zero vector object <M>v</M> of length
## <M>m</M> and in the representation given by the
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> value
## of <A>M</A> (provided that such a representation exists).
## <P/>
## The idea is that there should be an efficient way to
## form the product <M>v</M><A>M</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "CompatibleVector", [ IsMatrixOrMatrixObj ] );
############################################################################
##
#A RowsOfMatrix( <M> )
##
## <#GAPDoc Label="RowsOfMatrix">
## <ManSection>
## <Attr Name="RowsOfMatrix" Arg='M' Label="for a matrix object"/>
##
## <Returns>a plain list</Returns>
##
## <Description>
## Called with a matrix object <A>M</A>, this operation
## returns a plain list of objects in the representation given by the
## <Ref Attr="CompatibleVectorFilter" Label="for a matrix object"/> value
## of <A>M</A> (provided that such a representation exists),
## where the <M>i</M>-th entry describes the <M>i</M>-th row of the input.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
## This function is used for creating an isomorphic permutation group
## of a matrix group that consists of matrix objects.
## <!-- If 'NicomorphismOfGeneralMatrixGroup' would be documented then
## one could insert a reference to it. -->
##
## We assume that the matrix knows how to create suitable vector objects;
## entering a template vector as the second argument is not an option
## in this situation.
##
DeclareAttribute( "RowsOfMatrix", IsMatrixOrMatrixObj );
#############################################################################
##
#F DefaultVectorRepForBaseDomain( <D> )
#F DefaultMatrixRepForBaseDomain( <D> )
##
## currently undocumented
##
DeclareGlobalFunction( "DefaultVectorRepForBaseDomain" );
DeclareGlobalFunction( "DefaultMatrixRepForBaseDomain" );
#############################################################################
##
## Operations for Row List Matrix Objects
##
############################################################################
##
#O <M>[ <pos> ]<v>
##
## <#GAPDoc Label="RowListMatObj_[]">
## <ManSection>
## <Heading>List Access for a Row List Matrix</Heading>
## <Oper Name="\[\]" Arg='M, pos' Label="for a row list matrix"/>
##
## <Returns>a vector object</Returns>
##
## <Description>
## If <A>M</A> is a row list matrix and if <A>pos</A> is a
## positive integer not larger than the number of rows of <A>M</A>,
## this operation returns the <A>pos</A>-th row of <A>M</A>.
## <P/>
## It is not specified what happens if <A>pos</A> is larger.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "[]", [ IsRowListMatrix, IsPosInt ] );
############################################################################
##
#O <M>[ <pos> ]:= <v>
##
## <#GAPDoc Label="RowListMatObj_[]_ASS">
## <ManSection>
## <Heading>List Assignment for a Row List Matrix</Heading>
## <Oper Name="\[\]\:\=" Arg='M, pos, v'
## Label="for a row list matrix and a vector object"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## If <A>M</A> is a row list matrix, <A>v</A> is a vector object
## that can occur as a row in <A>M</A>
## (that is, <A>v</A> has the same base domain, the right length,
## and the right vector representation),
## and if <A>pos</A> is a positive integer not larger than
## the number of rows of <A>M</A> plus 1,
## this operation sets <A>v</A> as the <A>pos</A>-th row of
## <A>M</A>.
## <P/>
## In all other situations, it is not specified what happens.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "[]:=", [ IsRowListMatrix, IsPosInt, IsVectorObj ] );
#############################################################################
##
#O <M>{ <pos> }
##
## <#GAPDoc Label="RowListMatObj_{}">
## <ManSection>
## <Heading>Sublist Access for a Row List Matrix</Heading>
## <Oper Name="\{\}" Arg='M, poss' Label="for a row list matrix"/>
##
## <Returns>a row list matrix</Returns>
##
## <Description>
## For a row list matrix <A>M</A> and a list <A>poss</A> of positions,
## <A>M</A><C>{ </C><A>poss</A><C> }</C> returns a new mutable
## row list matrix with the same representation as <A>M</A>,
## whose rows are identical to the rows at the positions
## in the list <A>poss</A> in <A>M</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "{}", [IsRowListMatrix,IsList] );
#############################################################################
##
#O <M>{ <poss> }:= <M2>
##
## <#GAPDoc Label="RowListMatObj_{}_ASS">
## <ManSection>
## <Heading>Sublist Assignment for a Row List Matrix</Heading>
## <Oper Name="\{\}\:\=" Arg='M, poss, M2' Label="for row list matrices"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For a mutable row list matrix <A>M</A>, a list <A>poss</A> of
## positions, and a row list matrix <A>M2</A> of the same vector type
## and with the same base domain,
## <A>M</A><C>{ </C><A>poss</A><C> }:= </C><A>M2</A> assigns the rows
## of <A>M2</A> to the positions <A>poss</A> in the list of rows of
## <A>M</A>.
## <P/>
## It is not specified what happens if the resulting range of row positions
## is not dense.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "{}:=", [IsRowListMatrix,IsList,IsRowListMatrix] );
#############################################################################
##
#O IsBound\[\]( <M>, <pos> )
##
## <#GAPDoc Label="RowListMatObj_IsBound">
## <ManSection>
## <Oper Name="IsBound\[\]" Arg='M, pos' Label="for a row list matrix"/>
##
## <Returns><K>true</K> or <K>false</K></Returns>
##
## <Description>
## For a row list matrix <A>M</A> and a positive integer <A>pos</A>,
## <C>IsBound( </C><A>M</A><C>[ </C><A>pos</A><C> ] )</C> returns
## <K>true</K> if <A>pos</A> is at most the number of rows of <A>M</A>,
## and <K>false</K> otherwise.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "IsBound[]", [ IsRowListMatrix, IsPosInt ] );
#############################################################################
##
#O Unbind\[\]( <M>, <pos> )
##
## <#GAPDoc Label="RowListMatObj_Unbind">
## <ManSection>
## <Oper Name="Unbind\[\]" Arg='M, pos' Label="for a row list matrix"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For a mutable row list matrix <A>M</A> with <A>pos</A> rows,
## <C>Unbind( </C><A>M</A><C>[ </C><A>pos</A><C> ] )</C> removes the last
## row.
## It is not specified what happens if <A>pos</A> has another value.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Unbind[]", [ IsRowListMatrix, IsPosInt ] );
#############################################################################
##
#O Add( <M>, <v>[, <pos>] )
##
## <#GAPDoc Label="RowListMatObj_Add">
## <ManSection>
## <Oper Name="Add" Arg='M, v[, pos]'
## Label="for a row list matrix and a vector object"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For a mutable row list matrix <A>M</A> and a vector object <A>v</A>
## that is compatible with the rows of <A>M</A>,
## the two argument version adds <A>v</A> at the end of the list of rows
## of <A>M</A>.
## <P/>
## If a positive integer <A>pos</A> is given then <A>v</A> is added in
## position <A>pos</A>, and all later rows are shifted up by one position.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Add", [ IsRowListMatrix, IsVectorObj ] );
DeclareOperation( "Add", [ IsRowListMatrix, IsVectorObj, IsPosInt ] );
#############################################################################
##
#O Remove( <M>[, <pos>] )
##
## <#GAPDoc Label="RowListMatObj_Remove">
## <ManSection>
## <Oper Name="Remove" Arg='M[, pos]' Label="for a row list matrix"/>
##
## <Returns>a vector object if the removed row exists,
## otherwise nothing</Returns>
##
## <Description>
## For a mutable row list matrix <A>M</A>,
## this operation removes the <A>pos</A>-th row and shifts the later rows
## down by one position.
## The default for <A>pos</A> is the number of rows of <A>M</A>.
## <P/>
## If the <A>pos</A>-th row existed in <A>M</A> then it is returned,
## otherwise nothing is returned.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Remove", [ IsRowListMatrix ] );
DeclareOperation( "Remove", [ IsRowListMatrix, IsPosInt ] );
#############################################################################
##
#O Append( <rowlistmat1>, <rowlistmat2> )
##
## <#GAPDoc Label="RowListMatObj_Append">
## <ManSection>
## <Oper Name="Append" Arg='M1, M2' Label="for two row list matrices"/>
##
## <Returns>nothing</Returns>
##
## <Description>
## For two row list matrices <A>M1</A>, <A>M2</A>
## such that <A>M1</A> is mutable and such that the
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> values are equal,
## this operation appends the rows of <A>M2</A> to the
## rows of <A>M1</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "Append", [ IsRowListMatrix, IsRowListMatrix ] );
#############################################################################
##
#O ShallowCopy( <M> )
##
## <#GAPDoc Label="RowListMatObj_ShallowCopy">
## <ManSection>
## <Oper Name="ShallowCopy" Arg='M' Label="for a row list matrix"/>
##
## <Returns>a matrix object</Returns>
##
## <Description>
## For a row list matrix <A>M</A>,
## this operation returns a new mutable matrix with the same
## <Ref Attr="ConstructingFilter" Label="for a matrix object"/> and
## <Ref Attr="BaseDomain" Label="for a matrix object"/> values as <A>M</A>,
## which shares its rows with <A>M</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
#############################################################################
##
#O ListOp( <M>[ <func> ] )
##
## <#GAPDoc Label="RowListMatObj_ListOp">
## <ManSection>
## <Oper Name="ListOp" Arg='M[, func]' Label="for a row list matrix"/>
##
## <Returns>a plain list</Returns>
##
## <Description>
## For a row list matrix <A>M</A>,
## the variant with one argument returns the plain list
## (see <Ref Filt="IsPlistRep"/>) of its rows,
## and the variant with two arguments returns the plain list of values
## of these rows under the function <A>func</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "ListOp", [ IsRowListMatrix ] );
DeclareOperation( "ListOp", [ IsRowListMatrix, IsFunction ] );
#############################################################################
##
## IsEmptyMatrix( <matobj> )
##
## <#GAPDoc Label="MatObj_IsEmptyMatrix">
## <ManSection>
## <Prop Name="IsEmptyMatrix" Arg='M' Label="for a matrix object"/>
## <Returns>A boolean</Returns>
## <Description>
## Is <K>true</K> if the matrix object <A>M</A> either has zero columns
## or zero rows, and <K>false</K> otherwise.
## In other words, a matrix object is empty if it has no entries.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareProperty( "IsEmptyMatrix", IsMatrixOrMatrixObj );
#############################################################################
##
## TODO:
##
## Do we REALLY want to support and document the following feature?
## If yes then it is intended as permanent,
## although it contradicts the intended use of matrix objects.
##
## Is this a feature with a generic solution,
## such that the implementors of new kinds of matrix objects need not
## care about it?
## If not then it will be very annoying to be forced to support something
## which will not be used at all as long as the code is used as intended.
## (In particular, the documentation claims on the one hand that it is not
## compulsory to provide a compatible vector object representation for one's
## matrix object implementation, but the ``row access'' will force one to
## provide one.)
############################################################################
# In the following sense matrices behave like lists:
############################################################################
DeclareOperation( "[]", [IsMatrixOrMatrixObj,IsPosInt] ); # <mat>, <pos>
# This is guaranteed to return a vector object that has the property
# that changing it changes <pos>th row (?) of the matrix <mat>!
# A matrix which is not a row-lists internally has to create an intermediate object that refers to some
# row within it to allow the old GAP syntax M[i][j] for read and write
# access to work. Note that this will never be particularly efficient
# for matrices which are not row-lists. Efficient code will have to use MatElm and
# SetMatElm instead.
# TODO: ... resp. it will use use M[i,j]
# TODO: provide a default method which creates a proxy object for the given row
# and translates accesses to it to corresponding MatElm / SetMatElm calls;
# creating such a proxy object prints an InfoWarning;
# but for the method for plist matrices, no warning is shown, as it is efficient
# anyway
# TODO: maybe also add GetRow(mat, i) and GetColumn(mat, i) ???
# these return IsVectorObj objects.
# these again must be objects which are "linked" to the original matrix, as above...
# TODO: perhaps also have ExtractRow(mat, i) and ExtractColumn(mat, i)
#############################################################################
##
## Backwards compatibility
##
## We have to declare the operations/synonyms because otherwise
## the method installations in some packages may not work.
## We should remove them as soon as they are not used anymore.
##
#############################################################################
##
#C IsRowVectorObj( <obj> )
##
## Existing code which uses this name (most notably, the cvec package)
## should be supported for some time.
##
DeclareSynonym( "IsRowVectorObj", IsVectorObj );
#############################################################################
##
#A DimensionsMat( <matobj> )
##
## only for backwards compatibility with existing code:
## <matobj> -> [ NrRows( <matobj> ), NrCols( <matobj> ) ]
##
DeclareAttribute( "DimensionsMat", IsMatrixOrMatrixObj );
#############################################################################
##
#A Length( <matobj> )
#A RowLength( <matobj> )
##
## They had been used in older versions.
##
DeclareAttribute( "Length", IsMatrixOrMatrixObj );
DeclareSynonymAttr( "RowLength", NumberColumns );
#############################################################################
##
#O NewCompanionMatrix( <filt>, <pol>, <R> )
##
## This operation is intended for the installation of tag based methods for
## 'CompanionMatrix', such that 'CompanionMatrix' admits method dispatch
## based on <filt>.
##
## (Currently 'NewCompanionMatrix' is undocumented.
## Perhaps we can simply declare 'CompanionMatrix' itself as a tag based
## operation for the given requirement.
## This would work also for `DiagonalMatrix`, `RandomMatrix`,
## `ReflectionMatrix`, etc.
## We could even get rid of `NewMatrix`, `NewZeroMatrix`,
## `NewIdentityMatrix`, by declaring `Matrix`, `ZeroMatrix`,
## `IdentityMatrix` as tag based operations for the requirements in
## question, except that the ordering of the arguments for the four
## argument versions of `NewMatrix` and `Matrix` does not fit.)
##
DeclareTagBasedOperation( "NewCompanionMatrix",
[ IsOperation, IsUnivariatePolynomial, IsSemiring ] );
#############################################################################
##
#O NewRowVector( ... )
##
DeclareSynonym( "NewRowVector", NewVector );
#############################################################################
##
#O Randomize( ... )
##
## for backwards compatibility with the cvec package
##
DeclareOperation( "Randomize", [ IsVectorObj and IsMutable, IsRandomSource ] );
DeclareOperation( "Randomize", [ IsMatrixOrMatrixObj and IsMutable, IsRandomSource ] );
#############################################################################
##
#O <matobj>[ <i>, <j> ]
#O <matobj>[ <i>, <j> ]:= <obj>
##
DeclareOperation( "[]", [ IsMatrixOrMatrixObj, IsPosInt, IsPosInt ] );
DeclareOperation( "[]:=", [ IsMatrixOrMatrixObj, IsPosInt, IsPosInt, IsObject ] );
############################################################################
# Elementary matrix operations
############################################################################
#
############################################################################
##
## <#GAPDoc Label="MultMatrixRow">
## <ManSection>
## <Oper Name="MultMatrixRowLeft" Arg='mat,i,elm'/>
## <Oper Name="MultMatrixRow" Arg='mat,i,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Multiplies the <A>i</A>-th row of the mutable matrix <A>mat</A> with the scalar
## <A>elm</A> from the left in-place.
## <P/>
## <Ref Oper="MultMatrixRow"/> is a synonym of <Ref Oper="MultMatrixRowLeft"/>. This was chosen
## because linear combinations of rows of matrices are usually written as
## <M> v \cdot A = [v_1, ... ,v_n] \cdot A</M> which multiplies scalars from the left.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultMatrixRowLeft", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsObject ] );
DeclareSynonym( "MultMatrixRow", MultMatrixRowLeft);
############################################################################
##
## <#GAPDoc Label="MultMatrixRowRight">
## <ManSection>
## <Oper Name="MultMatrixRowRight" Arg='M,i,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Multiplies the <A>i</A>-th row of the mutable matrix <A>M</A> with the scalar
## <A>elm</A> from the right in-place.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultMatrixRowRight", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsObject ]);
############################################################################
##
## <#GAPDoc Label="MultMatrixColumn">
## <ManSection>
## <Oper Name="MultMatrixColumnRight" Arg='M,i,elm'/>
## <Oper Name="MultMatrixColumn" Arg='M,i,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Multiplies the <A>i</A>-th column of the mutable matrix <A>M</A> with the scalar
## <A>elm</A> from the right in-place.
## <P/>
## <Ref Oper="MultMatrixColumn"/> is a synonym of <Ref Oper="MultMatrixColumnRight"/>. This was
## chosen because linear combinations of columns of matrices are usually written as
## <M>A \cdot v^T = A \cdot [v_1, ... ,v_n]^T</M> which multiplies scalars from the right.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultMatrixColumnRight", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsObject ] );
DeclareSynonym( "MultMatrixColumn", MultMatrixColumnRight);
############################################################################
##
## <#GAPDoc Label="MultMatrixColumnLeft">
## <ManSection>
## <Oper Name="MultMatrixColumnLeft" Arg='M,i,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Multiplies the <A>i</A>-th column of the mutable matrix <A>M</A> with the scalar
## <A>elm</A> from the left in-place.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "MultMatrixColumnLeft", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsObject ] );
############################################################################
##
## <#GAPDoc Label="AddMatrixRows">
## <ManSection>
## <Oper Name="AddMatrixRowsLeft" Arg='M,i,j,elm'/>
## <Oper Name="AddMatrixRows" Arg='M,i,j,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Adds the product of <A>elm</A> with the <A>j</A>-th row of the mutable matrix <A>M</A> to its <A>i</A>-th
## row in-place. The <A>j</A>-th row is multiplied with <A>elm</A> from the left.
## <P/>
## <Ref Oper="AddMatrixRows"/> is a synonym of <Ref Oper="AddMatrixRowsLeft"/>. This was chosen
## because linear combinations of rows of matrices are usually written as
## <M> v \cdot A = [v_1, ... ,v_n] \cdot A</M> which multiplies scalars from the left.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddMatrixRowsLeft", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt, IsObject ] );
DeclareSynonym( "AddMatrixRows", AddMatrixRowsLeft);
############################################################################
##
## <#GAPDoc Label="AddMatrixRowsRight">
## <ManSection>
## <Oper Name="AddMatrixRowsRight" Arg='M,i,j,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Adds the product of <A>elm</A> with the <A>j</A>-th row of the mutable matrix <A>M</A> to its <A>i</A>-th
## row in-place. The <A>j</A>-th row is multiplied with <A>elm</A> from the right.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddMatrixRowsRight", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt, IsObject ] );
############################################################################
##
## <#GAPDoc Label="AddMatrixColumns">
## <ManSection>
## <Oper Name="AddMatrixColumnsRight" Arg='M,i,j,elm'/>
## <Oper Name="AddMatrixColumns" Arg='M,i,j,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Adds the product of <A>elm</A> with the <A>j</A>-th column of the mutable matrix <A>M</A> to its <A>i</A>-th
## column in-place. The <A>j</A>-th column is multiplied with <A>elm</A> from the right.
## <P/>
## <Ref Oper="AddMatrixColumns"/> is a synonym of <Ref Oper="AddMatrixColumnsRight"/>. This was
## chosen because linear combinations of columns of matrices are usually written as
## <M>A \cdot v^T = A \cdot [v_1, ... ,v_n]^T</M> which multiplies scalars from the right.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddMatrixColumnsRight", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt, IsObject ] );
DeclareSynonym( "AddMatrixColumns", AddMatrixColumnsRight);
############################################################################
##
## <#GAPDoc Label="AddMatrixColumnsLeft">
## <ManSection>
## <Oper Name="AddMatrixColumnsLeft" Arg='M,i,j,elm'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Adds the product of <A>elm</A> with the <A>j</A>-th column of the mutable matrix <A>M</A> to its <A>i</A>-th
## column in-place. The <A>j</A>-th column is multiplied with <A>elm</A> from the left.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperation( "AddMatrixColumnsLeft", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt, IsObject ] );
############################################################################
##
## <#GAPDoc Label="SwapMatrixRows">
## <ManSection>
## <Oper Name="SwapMatrixRows" Arg='M,i,j'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Swaps the <A>i</A>-th row and <A>j</A>-th row of a mutable matrix <A>M</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperationKernel( "SwapMatrixRows", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt ], SWAP_MAT_ROWS );
############################################################################
##
## <#GAPDoc Label="SwapMatrixColumns">
## <ManSection>
## <Oper Name="SwapMatrixColumns" Arg='M,i,j'/>
##
## <Returns>nothing</Returns>
##
## <Description>
## <P/>
## Swaps the <A>i</A>-th column and <A>j</A>-th column of a mutable matrix <A>M</A>.
## </Description>
## </ManSection>
## <#/GAPDoc>
##
DeclareOperationKernel( "SwapMatrixColumns", [ IsMatrixOrMatrixObj and IsMutable, IsInt, IsInt ], SWAP_MAT_COLS );
|