/usr/share/gap/lib/vecmat.gi is in gap-libs 4r6p5-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 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 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 | #############################################################################
##
#W vecmat.gi GAP Library Frank Celler
##
##
#Y Copyright (C) 1997, Lehrstuhl D für Mathematik, RWTH Aachen, Germany
#Y (C) 1998 School Math and Comp. Sci., University of St Andrews, Scotland
#Y Copyright (C) 2002 The GAP Group
##
## This file contains the basic methods for creating and doing arithmetic
## with GF2 vectors and matrices.
##
#############################################################################
##
#F IsLockedRepresentationVector . . filter used by GF2 and GF(q)
## matrix reps to stop their rows
## changing representation
DeclareFilter( "IsLockedRepresentationVector" );
#############################################################################
##
#V TYPE_LIST_GF2VEC . . . . . . . . . . . . . . type of mutable GF2 vectors
##
InstallValue( TYPE_LIST_GF2VEC,
NewType( CollectionsFamily( FFEFamily(2) ),
IsHomogeneousList and IsListDefault and IsNoImmediateMethodsObject
and IsMutable and IsCopyable and IsGF2VectorRep )
);
#############################################################################
##
#V TYPE_LIST_GF2VEC_IMM . . . . . . . . . . . type of immutable GF2 vectors
##
InstallValue( TYPE_LIST_GF2VEC_IMM,
NewType( CollectionsFamily( FFEFamily(2) ),
IsHomogeneousList and IsListDefault and IsNoImmediateMethodsObject
and IsCopyable and IsGF2VectorRep )
);
#############################################################################
##
#V TYPE_LIST_GF2VEC_IMM_LOCKED . . . . type of immutable locked GF2 vectors
##
InstallValue( TYPE_LIST_GF2VEC_IMM_LOCKED,
NewType( CollectionsFamily( FFEFamily(2) ),
IsHomogeneousList and IsListDefault and IsNoImmediateMethodsObject
and IsCopyable and IsGF2VectorRep and IsLockedRepresentationVector)
);
#############################################################################
##
#V TYPE_LIST_GF2VEC_LOCKED . . . . type of mutable locked GF2 vectors
##
InstallValue( TYPE_LIST_GF2VEC_LOCKED,
NewType( CollectionsFamily( FFEFamily(2) ),
IsHomogeneousList and IsListDefault and IsNoImmediateMethodsObject
and IsCopyable and IsGF2VectorRep and
IsLockedRepresentationVector and IsMutable)
);
#############################################################################
##
#V TYPE_LIST_GF2MAT . . . . . . . . . . . . . type of mutable GF2 matrices
##
InstallValue( TYPE_LIST_GF2MAT,
NewType( CollectionsFamily(CollectionsFamily(FFEFamily(2))),
IsMatrix and IsListDefault and IsSmallList and
IsFFECollColl and IsNoImmediateMethodsObject
and IsMutable and IsCopyable and IsGF2MatrixRep and
HasIsRectangularTable and IsRectangularTable )
);
#############################################################################
##
#V TYPE_LIST_GF2MAT_IMM . . . . . . . . . . type of immutable GF2 matrices
##
InstallValue( TYPE_LIST_GF2MAT_IMM,
NewType( CollectionsFamily(CollectionsFamily(FFEFamily(2))),
IsMatrix and IsListDefault and IsCopyable and IsGF2MatrixRep
and IsNoImmediateMethodsObject
and IsSmallList and IsFFECollColl and
HasIsRectangularTable and IsRectangularTable)
);
#############################################################################
##
#M Length( <gf2vec> ) . . . . . . . . . . . . . . . length of a GF2 vector
##
InstallOtherMethod( Length,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep ],
0,
LEN_GF2VEC );
#############################################################################
##
#M ELM0_LIST( <gf2vec>, <pos> ) . . . . select an element from a GF2 vector
##
InstallMethod( ELM0_LIST,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep,
IsPosInt ],
0,
ELM0_GF2VEC );
#############################################################################
##
#M ELM_LIST( <gf2vec>, <pos> ) . . . . . select an element from a GF2 vector
##
InstallOtherMethod( ELM_LIST,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep,
IsPosInt ],
0,
ELM_GF2VEC );
#############################################################################
##
#M ELMS_LIST( <gf2vec>, <poss> ) . . . . . select elements from a GF2 vector
##
InstallOtherMethod( ELMS_LIST,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep,
IsList and IsDenseList and IsInternalRep ],
0,
ELMS_GF2VEC );
#############################################################################
##
#M ASS_LIST( <gf2vec>, <pos>, <elm> ) . . assign an element to a GF2 vector
##
## We use an OtherMethod and trap assignment to immutable vectors in
## the kernel method.
InstallOtherMethod( ASS_LIST,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep,
IsPosInt,
IsObject ],
0,
ASS_GF2VEC );
#############################################################################
##
#M ASS_LIST( <empty-list>, <pos>, <ffe> ) . . . . . start a new GF2 vector
##
#InstallMethod( ASS_LIST,
# "for empty plain list and finite field element",
# true,
# [ IsMutable and IsList and IsPlistRep and IsEmpty,
# IsPosInt,
# IsFFE ],
# 0,
#function( list, pos, val )
# if pos = 1 and ( val = GF2Zero or val = GF2One ) then
# CONV_GF2VEC(list);
# ASS_GF2VEC( list, pos, val );
# else
# ASS_PLIST_DEFAULT( list, pos, val );
# # force kernel to notice that this is now a list of FFEs
# ConvertToVectorRep( list );
# fi;
#end );
#############################################################################
##
#M UNB_LIST( <gf2vec>, <pos> ) . . . . . . unbind a position of a GF2 vector
##
## We use an OtherMethod and trap assignment to immutable vectors in
## the kernel method.
InstallOtherMethod( UNB_LIST,
"for GF2 vector",
true,
[ IsList and IsGF2VectorRep,
IsPosInt ],
0,
UNB_GF2VEC );
#############################################################################
##
#M PrintObj( <gf2vec> ) . . . . . . . . . . . . . . . . print a GF2 vector
##
InstallMethod( PrintObj,
"for GF2 vector",
true,
[ IsGF2VectorRep ],
0,
function( vec )
local i;
Print( "[ " );
for i in [ 1 .. Length(vec) ] do
if 1 < i then Print( ", " ); fi;
Print( vec[i] );
od;
Print( " ]" );
end );
#############################################################################
##
#M ViewObj( <gf2vec> ) . . . . . . . . . . . . . . . . . . view a GF2 vector
##
InstallMethod( ViewObj,
"for GF2 vector",
true,
[ IsRowVector and IsFinite and IsGF2VectorRep ],
0,
function( vec )
if IsMutable(vec) then
Print( "<a GF2 vector of length ", Length(vec), ">" );
else
Print( "<an immutable GF2 vector of length ", Length(vec), ">" );
fi;
end );
#############################################################################
##
#M AdditiveInverseOp( <gf2vec> ) . mutable additive inverse of a GF2 vector
##
InstallMethod( AdditiveInverseMutable,
"for GF2 vector",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
ShallowCopy );
InstallMethod( AdditiveInverseSameMutability,
"for GF2 vector, mutable",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep and IsMutable],
0,
ShallowCopy );
InstallMethod( AdditiveInverseSameMutability,
"for GF2 vector, immutable",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep],
0,
function(v)
if IsMutable(v) then
TryNextMethod();
fi;
return v;
end );
#############################################################################
##
#M AdditiveInverse( <gf2vec> ) . . . . . . additive inverse of a GF2 vector
##
InstallMethod( AdditiveInverse,
"for GF2 vector",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
Immutable );
#############################################################################
##
#M ZeroOp( <gf2vec> ) . . . . . . . . . . . . . . . mutable zero GF2 vector
##
InstallMethod( ZeroOp,
"for GF2 vector",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
ZERO_GF2VEC );
#############################################################################
##
#M ZEROOp( <gf2vec> ) . . . . . . . . . . . same mutability zero GF2 vector
##
InstallMethod( ZeroSameMutability,
"for GF2 vector, mutable",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep and IsMutable],
0,
ZERO_GF2VEC );
InstallMethod( ZeroSameMutability,
"for GF2 vector, immutable",
true,
[ IsRowVector and IsListDefault and IsGF2VectorRep],
0,
function(v)
local z;
if IsMutable(v) then
TryNextMethod();
fi;
z := ZERO_GF2VEC(v);
MakeImmutable(z);
return z;
end);
#############################################################################
##
#M \=( <gf2vec>, <gf2vec> ) . . . . . . . . . . . . equality of GF2 vectors
##
InstallMethod( \=,"for GF2 vectors",IsIdenticalObj,
[ IsRowVector and IsGF2VectorRep,
IsRowVector and IsGF2VectorRep ], 0, EQ_GF2VEC_GF2VEC );
#############################################################################
##
#M \<( <gf2vec>, <gf2vec> ) . . . . . . . . . . . . equality of GF2 vectors
##
InstallMethod( \<,"for GF2 vectors",IsIdenticalObj,
[ IsRowVector and IsGF2VectorRep,
IsRowVector and IsGF2VectorRep ], 0, LT_GF2VEC_GF2VEC );
#############################################################################
##
#M \+( <gf2vec>, <gf2vec> ) . . . . . . . . . . . . sum of two GF2 vectors
##
InstallMethod( \+,
"for GF2 vectors",
IsIdenticalObj,
[ IsRowVector and IsListDefault and IsGF2VectorRep,
IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
SUM_GF2VEC_GF2VEC );
#############################################################################
##
#M \-( <gf2vec>, <gf2vec> ) . . . . . . . . . difference of two GF2 vectors
##
InstallMethod( \-,
"for GF2 vectors",
IsIdenticalObj,
[ IsRowVector and IsListDefault and IsGF2VectorRep,
IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
# we are in GF(2)
SUM_GF2VEC_GF2VEC );
#############################################################################
##
#M \*( <gf2vec>, <gf2vec> ) . . . . . . . . . . product of two GF2 vectors
##
InstallMethod( \*,
"for GF2 vectors",
IsIdenticalObj,
[ IsRingElementList and IsListDefault and IsRowVector and IsGF2VectorRep,
IsRingElementList and IsListDefault and IsRowVector and IsGF2VectorRep ],
0,
PROD_GF2VEC_GF2VEC );
#############################################################################
##
#M \*( <ffe>, <gf2vec> ) . . . . . . . . . . . product of FFE and GF2 vector
##
## This method is installed with positive rank because it is the
## specialised method for GF(2) elements and should fall through to
## the general method for GF(2^k).
##
InstallMethod( \*,
"for FFE and GF2 vector",
IsElmsColls,
[ IsFFE,
IsRingElementList and IsRowVector and IsGF2VectorRep ],
10,
function( a, b )
if a = GF2Zero then
return ZeroSameMutability(b);
elif a = GF2One then
if IsMutable(b) then
return ShallowCopy(b);
else
return b;
fi;
else
TryNextMethod();
fi;
end );
#############################################################################
##
#M \*( <gf2vec>, <ffe> ) . . . . . . . . . . . product of GF2 vector and FFE
##
## This method is installed with positive rank because it is the
## specialised method for GF(2) elements and should fall through to
## the general method for GF(2^k).
##
InstallMethod( \*,
"for GF2 vector and FFE",
IsCollsElms,
[ IsRingElementList and IsRowVector and IsGF2VectorRep,
IsFFE ],
10,
function( a, b )
if b = GF2Zero then
return ZeroSameMutability(a);
elif b = GF2One then
if IsMutable(a) then
return ShallowCopy(a);
else
return a;
fi;
else
TryNextMethod();
fi;
end );
#############################################################################
##
#M AddCoeffs( <gf2vec>, <gf2vec>, <mul> ) . . . . . . . . add coefficients
##
InstallOtherMethod( AddCoeffs,
"for GF2 vectors and FFE",
function(a,b,c) return IsIdenticalObj(a,b); end,
[ IsRowVector and IsGF2VectorRep and IsMutable,
IsRowVector and IsGF2VectorRep,
IsFFE ],
0,
ADDCOEFFS_GF2VEC_GF2VEC_MULT );
#############################################################################
##
#M AddCoeffs( <gf2vec>, <gf2vec> ) . . . . . . . . . . . . add coefficients
##
InstallOtherMethod( AddCoeffs,
"for GF2 vectors",
IsIdenticalObj,
[ IsRowVector and IsGF2VectorRep and IsMutable,
IsRowVector and IsGF2VectorRep ],
0,
ADDCOEFFS_GF2VEC_GF2VEC );
#############################################################################
##
#M AddCoeffs( <empty-list>, <gf2vec>, <mul> ) . . . . . . add coefficients
##
InstallOtherMethod( AddCoeffs,
"for empty list, GF2 vector and FFE",
true,
[ IsList and IsEmpty and IsMutable,
IsRowVector and IsGF2VectorRep,
IsFFE ],
0,
function( a, b, c )
CONV_GF2VEC(a);
return ADDCOEFFS_GF2VEC_GF2VEC_MULT( a, b, c );
end );
#############################################################################
##
#M AddCoeffs( <empty-list>, <gf2vec> ) . . . . . . . . . . add coefficients
##
InstallOtherMethod( AddCoeffs,
"for empty list, GF2 vector",
true,
[ IsList and IsEmpty and IsMutable,
IsRowVector and IsGF2VectorRep ],
0,
function( a, b )
CONV_GF2VEC(a);
return ADDCOEFFS_GF2VEC_GF2VEC(a,b);
end );
#############################################################################
##
#M PadCoeffs( <gf2vec>, <len> ) . . . . . . . . . . . expand a GF2 vector
##
InstallMethod( PadCoeffs,
"for GF2 vector",
true,
[ IsMutable and IsRowVector and IsAdditiveElementWithZeroCollection and IsGF2VectorRep,
IsPosInt ],
0,
function(v,len)
if len > LEN_GF2VEC(v) then
RESIZE_GF2VEC(v,len);
fi;
end);
#############################################################################
##
#M QuotRemCoeffs( <gf2vec>, <len>, <gf2vec>, <len> )
##
InstallMethod( QuotRemCoeffs,
"GF2 vectors",
[ IsRowVector and IsGF2VectorRep, IsInt, IsRowVector and IsGF2VectorRep, IsInt],
QUOTREM_COEFFS_GF2VEC);
#############################################################################
##
#M NormedRowVector( <v> )
##
InstallMethod( NormedRowVector, "for GF(2) vector", true,
[ IsRowVector and IsGF2VectorRep and IsScalarCollection ],0,
# Over GF(2) one can norm only to 1
x->x);
#############################################################################
##
#M Length( <list> ) . . . . . . . . . . . . . . . . length of a GF2 matrix
##
InstallOtherMethod( Length,
"for GF2 matrix",
true,
[ IsMatrix and IsGF2MatrixRep ],
0,
function( list )
return list![1];
end );
#############################################################################
##
#M ELM_LIST( <list>, <pos> ) . . . . . . . select an element of a GF2 matrix
##
InstallOtherMethod( ELM_LIST,
"for GF2 matrix",
true,
[ IsMatrix and IsGF2MatrixRep,
IsPosInt ],
0,
function( list, pos )
return list![pos+1];
end );
#############################################################################
##
#M ASS_LIST( <gf2mat>, <pos>, <elm> ) . . assign an element to a GF2 matrix
##
InstallOtherMethod( ASS_LIST,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep and IsMutable,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );
InstallOtherMethod( ASS_LIST,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep,
IsPosInt,
IsObject ],
0,
ASS_GF2MAT );
#############################################################################
##
#M ASS_LIST( <empty-list>, <pos>, <gf2vec> ) . . . . start a new GF2 matrix
##
#InstallMethod( ASS_LIST,
# "for empty plain list and GF2 vector",
# true,
# [ IsMutable and IsList and IsPlistRep and IsEmpty,
# IsPosInt,
# IsGF2VectorRep ],
# 0,
#function( list, pos, val )
# if pos = 1 and not IsMutable(val) then
# list[1] := 1;
# list[2] := val;
# SetFilterObj(val, IsLockedRepresentationVector);
# Objectify( TYPE_LIST_GF2MAT, list );
# else
# ASS_PLIST_DEFAULT( list, pos, val );
# fi;
#end );
#############################################################################
##
#M UNB_LIST( <gf2mat>, <pos> ) . . . . . . unbind a position of a GF2 matrix
##
InstallOtherMethod( UNB_LIST,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep and IsMutable,
IsPosInt ],
0,
UNB_GF2MAT );
InstallOtherMethod( UNB_LIST,
"for GF2 matrix",
true,
[ IsList and IsGF2MatrixRep,
IsPosInt ],
0,
function(m, pos)
if IsMutable(m) then
TryNextMethod();
elif pos <= Length(m) then
Error("Unbind: can't unbind an entry of an immutable GF2 Matrix" );
fi;
end);
#############################################################################
##
#M PrintObj( <gf2mat> ) . . . . . . . . . . . . . . . . print a GF2 matrix
##
InstallMethod( PrintObj,
"for GF2 matrix",
true,
[ IsGF2MatrixRep ],
0,
function( mat )
local i, j;
Print( "\>\>[ \>\>" );
for i in [ 1 .. Length(mat) ] do
if 1 < i then Print( "\<,\< \>\>" ); fi;
Print( "\>\>[ \>\>" );
for j in [ 1 .. Length(mat[i]) ] do
if 1 < j then Print( "\<,\< \>\>" ); fi;
Print( mat[i][j] );
od;
Print( " \<\<\<\<]" );
od;
Print( " \<\<\<\<]" );
end );
#############################################################################
##
#M ViewObj( <gf2mat> ) . . . . . . . . . . . . . . . . view a GF2 matrix
##
InstallMethod( ViewObj,
"for GF2 matrix",
true,
[ IsMatrix and IsFinite and IsGF2MatrixRep ],
0,
function( mat )
if Length(mat) = 0 then
if IsMutable(mat) then
Print( "<a 0x0 matrix over GF2>" );
else
Print( "<an immutable 0x0 matrix over GF2>" );
fi;
else
if IsMutable(mat) then
Print("<a ",Length(mat),"x",Length(mat[1])," matrix over GF2>");
else
Print( "<an immutable ", Length(mat), "x", Length(mat[1]),
" matrix over GF2>" );
fi;
fi;
end );
#############################################################################
##
#M ShallowCopy( <gf2mat> ) . . . . . . mutable shallow copy of a GF2 matrix
##
BindGlobal("SHALLOWCOPY_GF2MAT",
function(mat)
local copy, i, len;
len := mat![1];
copy := [ len ];
for i in [2..len+1] do
copy[i] := mat![i];
od;
Objectify( TYPE_LIST_GF2MAT, copy );
return copy;
end);
InstallMethod( ShallowCopy,
"for GF2 matrix",
true,
[ IsMatrix and IsGF2MatrixRep ],
0,
SHALLOWCOPY_GF2MAT);
InstallOtherMethod(TransposedMat,"GF2 matrix",true,
[IsMatrix and IsGF2MatrixRep],0,TRANSPOSED_GF2MAT);
InstallOtherMethod(MutableTransposedMat,"GF2 matrix",true,
[IsMatrix and IsGF2MatrixRep],0,TRANSPOSED_GF2MAT);
#############################################################################
##
#M AdditiveInverseOp( <gf2mat> ) . mutable additive inverse of a GF2 matrix
##
InstallMethod( AdditiveInverseOp,
"for GF2 matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function(mat)
local copy, i, len;
len := mat![1];
copy := [ len ];
for i in [2..len+1] do
copy[i] := ShallowCopy(mat![i]);
SetFilterObj(copy[i],IsLockedRepresentationVector);
od;
Objectify( TYPE_LIST_GF2MAT, copy );
return copy;
end);
#############################################################################
##
#M AdditiveInverseSameMutability( <gf2mat> ) . same mutability additive inverse
##
InstallMethod( AdditiveInverseSameMutability,
"for GF2 matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function(mat)
local copy, i, len,r ;
if not IsMutable(mat) then
return mat;
fi;
len := mat![1];
copy := [ len ];
for i in [2..len+1] do
r := mat![i];
if IsMutable(r) then
copy[i] := ShallowCopy(mat![i]);
SetFilterObj(copy[i],IsLockedRepresentationVector);
else
copy[i] := r;
fi;
od;
Objectify( TYPE_LIST_GF2MAT, copy );
return copy;
end);
#############################################################################
##
#M AdditiveInverse( <gf2mat> ) . . . . . . additive inverse of a GF2 matrix
##
InstallMethod( AdditiveInverse,
"for GF2 matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
# we are in GF2
Immutable );
#############################################################################
##
#M InverseOp( <gf2mat> ) . . . . . . . . . . mutable inverse of a GF2 matrix
##
InstallMethod( InverseOp,
"for GF2 matrix",
true,
[ IsMultiplicativeElementWithInverse and IsOrdinaryMatrix and
IsSmallList and IsFFECollColl
and IsGF2MatrixRep ],
0,
INV_GF2MAT_MUTABLE );
#############################################################################
##
#M InverseSameMutability( <gf2mat> ) same mutability inverse of a GF2 matrix
##
InstallMethod( InverseSameMutability,
"for GF2 matrix",
true,
[ IsMultiplicativeElementWithInverse and IsOrdinaryMatrix and
IsSmallList and IsFFECollColl
and IsGF2MatrixRep ],
0,
INV_GF2MAT_SAME_MUTABILITY );
#############################################################################
##
#M InverseOp( <list of gf2 vectors> ) . . . mutable inverse of a GF2 matrix
##
InstallMethod( InverseOp,
"for plain list of GF2 vectors",
true,
[ IsPlistRep and IsFFECollColl and IsMatrix],
0,
m->INV_PLIST_GF2VECS_DESTRUCTIVE(List(m, ShallowCopy)) );
#############################################################################
##
#M InverseSameMutability( <list of gf2 vectors> ) . same mutability inverse of a GF2 matrix
##
InstallMethod( InverseSameMutability,
"for plain list of GF2 vectors",
true,
[ IsPlistRep and IsFFECollColl and IsMatrix],
0,
function(m)
local inv,i;
inv := INV_PLIST_GF2VECS_DESTRUCTIVE(List(m, ShallowCopy));
if inv = TRY_NEXT_METHOD then
TryNextMethod();
fi;
if IsMutable(m) then
if not IsMutable(m[1]) then
for i in [1..Length(m)] do
MakeImmutable(inv[i]);
od;
fi;
else
MakeImmutable(inv);
fi;
return inv;
end );
#############################################################################
##
#M OneOp( <gf2mat> ) . . . . . . . . . . . . . . mutable identity GF2 matrix
##
## A fully mutable GF2 matrix cannot be in the special compressed rep.
## so return it as a plain list
##
BindGlobal("GF2IdentityMatrix", function(n, imm)
local i,id,line,o;
o := Z(2);
id := [n];
for i in [1..n] do
line := ZERO_GF2VEC_2(n);
line[i] := o;
SetFilterObj(line,IsLockedRepresentationVector);
if imm > 0 then
MakeImmutable(line);
fi;
Add(id, line);
od;
if imm > 1 then
Objectify(TYPE_LIST_GF2MAT_IMM, id);
else
Objectify(TYPE_LIST_GF2MAT, id);
fi;
return id;
end);
InstallMethod( OneOp,
"for GF2 Matrix",
true,
[ IsOrdinaryMatrix and IsGF2MatrixRep and IsMultiplicativeElementWithOne],
0,
function(mat)
local len;
len := Length(mat);
if len <> Length(mat[1]) then
return fail;
fi;
return GF2IdentityMatrix(len, 0);
end);
#############################################################################
##
#M One( <gf2mat> ) . . . . . . . . . . . . . . . . . . . identity GF2 matrix
##
InstallMethod( One,
"for GF2 Matrix",
true,
[ IsOrdinaryMatrix and IsGF2MatrixRep and IsMultiplicativeElementWithOne],
0,
function(mat)
local len;
len := Length(mat);
if len <> Length(mat[1]) then
return fail;
fi;
return GF2IdentityMatrix(len, 2);
end );
#############################################################################
##
#M OneSM( <gf2mat> ) . . . . . . . . . . . . . . . . . . . identity GF2 matrix
##
InstallMethod( OneSameMutability,
"for GF2 Matrix",
true,
[ IsOrdinaryMatrix and IsGF2MatrixRep and IsMultiplicativeElementWithOne],
0,
function(mat)
local len,row1;
len := Length(mat);
row1 := mat[1];
if len <> Length(row1) then
return fail;
fi;
if not IsMutable(mat) then
return GF2IdentityMatrix(len, 2);
elif IsMutable(mat) and not IsMutable(row1) then
return GF2IdentityMatrix(len, 1);
else
return GF2IdentityMatrix(len, 0);
fi;
end );
#############################################################################
##
#M ZeroOp( <gf2mat> ) . . . . . . . . . . . . . . . mutable zero GF2 matrix
##
##
InstallMethod( ZeroOp,
"for GF2 Matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function( mat )
local new, zero, i;
new := [ Length(mat) ];
if 0 < new[1] then
for i in [ 1 .. new[1] ] do
zero := ZeroOp(mat[1]);
SetFilterObj(zero, IsLockedRepresentationVector);
Add( new, zero );
od;
fi;
Objectify( TYPE_LIST_GF2MAT, new );
return new;
end );
#############################################################################
##
#M ZEROOp( <gf2mat> ) . . . . . . . . . . . . . . . matching mutabilitt
##
##
InstallMethod( ZeroSameMutability,
"for GF2 Matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function( mat )
local new, zero, i;
new := [ Length(mat) ];
if 0 < new[1] then
if IsMutable(mat![2]) then
for i in [ 1 .. new[1] ] do
zero := ZERO(mat![2]);
SetFilterObj(zero, IsLockedRepresentationVector);
Add( new, zero );
od;
else
zero := ZERO(mat![2]);
SetFilterObj(zero, IsLockedRepresentationVector);
for i in [ 1 .. new[1] ] do
Add( new, zero );
od;
fi;
fi;
Objectify( TypeObj(mat), new );
return new;
end );
#############################################################################
##
#M Zero( <gf2mat> ) . . . . . . . . . . . . . . . . . . . . zero GF2 matrix
##
InstallMethod( Zero,
"for GF2 Matrix",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function( mat )
local new, zero, i;
new := [ Length(mat) ];
if 0 < new[1] then
zero := Zero(mat[1]);
SetFilterObj(zero, IsLockedRepresentationVector);
for i in [ 1 .. new[1] ] do
Add( new, zero );
od;
fi;
Objectify( TYPE_LIST_GF2MAT_IMM, new );
return new;
end );
#############################################################################
##
#M \+( <gf2mat>, <gf2mat> ) . . . . . sum of a GF2 matrix and a GF2 matrix
##
InstallMethod( \+,
"for GF2 matrix and GF2 matrix",
IsIdenticalObj,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
SUM_GF2MAT_GF2MAT );
#############################################################################
##
#M \<( <gf2mat>, <gf2mat> ) . . . . . . . . . . .comparison of GF2 matrices
##
InstallMethod( \<,
"for GF2 matrix and GF2 matrix",
IsIdenticalObj,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
LT_GF2MAT_GF2MAT);
#############################################################################
##
#M \=( <gf2mat>, <gf2mat> ) . . . . . . . . . . .comparison of GF2 matrices
##
InstallMethod( \=,
"for GF2 matrix and GF2 matrix",
IsIdenticalObj,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
EQ_GF2MAT_GF2MAT);
#############################################################################
##
#M \-( <gf2mat>, <gf2mat> ) . . . . . sum of a GF2 matrix and a GF2 matrix
##
InstallMethod( \-,
"for GF2 matrix and GF2 matrix",
IsIdenticalObj,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
# we are in GF2
SUM_GF2MAT_GF2MAT );
#############################################################################
##
#M \*( <gf2vec>, <gf2mat> ) . . . product of a GF2 vector and a GF2 matrix
##
InstallMethod( \*,
"for GF2 vector and GF2 matrix",
true,
[ IsRingElementList and IsRowVector and IsListDefault and IsGF2VectorRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
PROD_GF2VEC_GF2MAT );
#############################################################################
##
#M <vec>*<mat> . . . general method for GF2 vector and a matrix
## works fast when the matrix is a plain list
## of compressed GF2 vectors, otherwise falls through
##
InstallMethod(\*, "For a GF2 vector and a compatible matrix",
IsElmsColls, [IsRowVector and IsGF2VectorRep and IsSmallList
and IsRingElementList,
IsRingElementTable and IsPlistRep], 0,
PROD_GF2VEC_ANYMAT);
#############################################################################
##
#M \*( <gf2mat>, <gf2vec> ) . . . product of a GF2 matrix and a GF2 vector
##
InstallMethod( \*,
"for GF2 matrix and GF2 vector",
true,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsRowVector and IsListDefault and IsGF2VectorRep ],
0,
PROD_GF2MAT_GF2VEC );
#############################################################################
##
#M \*( <gf2mat>, <gf2mat> ) . . . product of a GF2 matrix and a GF2 matrix
##
InstallMethod( \*,
"for GF2 matrix and GF2 matrix",
IsIdenticalObj,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
PROD_GF2MAT_GF2MAT );
#############################################################################
##
#M \*( <gf2elm>, <gf2mat> ) . . . product of a GF2 element and a GF2 matrix
##
InstallMethod( \*,
"for GF2 element and GF2 matrix",
IsElmsCollColls,
[ IsFFE,
IsMatrix and IsListDefault and IsGF2MatrixRep ],
0,
function(s,m)
if s = Z(2) then
return AdditiveInverseSameMutability(m);
elif IsZero(s) then
return ZeroSameMutability(m);
else
TryNextMethod();
fi;
end);
#############################################################################
##
#M \*( <gf2mat>, <gf2elm> ) . . . product of a GF2 matrix and a GF2 element
##
InstallMethod( \*,
"for GF2 matrix and GF2 element",
IsCollCollsElms,
[ IsMatrix and IsListDefault and IsGF2MatrixRep,
IsFFE ],
0,
function(m,s)
if s = Z(2) then
return AdditiveInverseSameMutability(m);
elif IsZero(s) then
return ZeroSameMutability(m);
else
TryNextMethod();
fi;
end);
#############################################################################
##
#F ConvertToVectorRep(<v>)
##
LOCAL_COPY_GF2 := GF(2);
InstallGlobalFunction(ConvertToVectorRepNC,function( arg )
local v, q, vc, common, field, q0;
if Length(arg) < 1 then
Error("ConvertToVectorRep: one or two arguments required");
fi;
v := arg[1];
#
# Handle fast, certain cases where there is no work. Microseconds count here
#
if IsGF2VectorRep(v) and (Length(arg) = 1 or arg[2] = 2 or arg[2] = LOCAL_COPY_GF2) then
return 2;
fi;
if Is8BitVectorRep(v) then
q0 := Q_VEC8BIT(v);
if Length(arg) = 1 then
return q0;
fi;
if IsInt(arg[2]) then
q := arg[2];
elif IsField(arg[2]) then
q := Size(arg[2]);
fi;
if q = q0 then
return q;
fi;
if IsLockedRepresentationVector(v) then
Error("Vector is locked over current field");
else
if q = 2 then
CONV_GF2VEC(v);
return 2;
elif q <= 256 then
CONV_VEC8BIT(v,q);
return q;
else
if q mod q0 <> 0 then
Error("New field size incompatible with vector entries");
else
PLAIN_VEC8BIT(v);
return q;
fi;
fi;
fi;
fi;
if (Length(v) = 0 and Length(arg) = 1) or
(Length(v) >0 and not IsRowVector(v)) then
return fail;
fi;
# if the representation of v is already locked, then
# we ignore a second arguments and just report on the vector
if IsLockedRepresentationVector(v) then
if IsGF2VectorRep(v) then
q := 2;
elif Is8BitVectorRep(v) then
q := Q_VEC8BIT(v);
else
Error("vector is locked in an unknown representation");
fi;
if not IsInt(arg[2]) then
arg[2] := Size(arg[2]);
fi;
if Length(arg) = 2 and q <> arg[2] then
Info(InfoWarning, 1,
"ConvertToVectorRep: locked vector not converted to different field");
fi;
return q;
fi;
#
# Ask the kernel to check the list for us.
# We have to do this, even in an NC version because the list might contain
# elements of large finite fields
#
if not IS_VECFFE(v) then
if IsFFECollection(v) then
# now we might have some elements in a large field representation
# or possibly a totally bad list
vc := ShallowCopy(v);
common := FFECONWAY.WriteOverSmallestCommonField(vc);
if common = fail or common > 256 then
#
# vector needs a field > 256, so can't be compressed
# or vector contains non-ffes or no common characteristic
#
return true;
fi;
CLONE_OBJ(v,vc); # horrible hack.
else
return true;
fi;
else
common := COMMON_FIELD_VECFFE(v);
fi;
#
# see if the user gave us q
#
if Length(arg) > 1 then
field := arg[2];
if IsInt(field) then
q := field;
Assert(2,IsPrimePowerInt(q));
elif IsField(field) then
q := Size(field);
else
Error("q not a field or integer");
fi;
else
q := fail;
fi;
#
# if there is a field, we go to work
#
if q = fail then
if common = fail then
return true;
fi;
if not IsPrimeInt(common) then
common := SMALLEST_FIELD_VECFFE(v);
fi;
if common = 2 then
CONV_GF2VEC(v);
return 2;
elif common <= 256 then
CONV_VEC8BIT(v,common);
return common;
else
return true;
fi;
elif q = 2 then
Assert(2, ForAll(v, elm -> elm in GF(2)));
if common > 2 and common mod 2 = 0 then
common := SMALLEST_FIELD_VECFFE(v);
fi;
if common <> 2 then
Error("ConvertToVectorRepNC: Vector cannot be written over GF(2)");
fi;
CONV_GF2VEC(v);
return 2;
elif q <= 256 then
if common <> q then
Assert(2, ForAll(v, elm -> elm in GF(q)));
if IsPlistRep(v) and GcdInt(common,q) > 1 then
common := SMALLEST_FIELD_VECFFE(v);
fi;
if common ^ LogInt(q, common) <> q then
Error("ConvertToVectorRepNC: Vector cannot be written over GF(",q,")");
fi;
fi;
CONV_VEC8BIT(v,q);
return q;
else
return true;
fi;
end);
#############################################################################
##
#F ConvertToMatrixRep(<v>)
##
#InstallGlobalFunction(ConvertToMatrixRep,function(arg)
# local m;
# m:=arg[1];
# if IsGF2MatrixRep(m) then
# return true;
# fi;
# if not IsMatrix(m) or Length(m)=0 then
# return fail;
# fi;
#
# # enforce to run `ConvertToVectorRep' over all vectors to make them
# # compressed.
# if Length(arg)=1 then
# if ForAny(List(m,i->ConvertToVectorRep(i)),i->i<>2) then
# return fail;
# fi;
# else
# if ForAny(List(m,i->ConvertToVectorRep(i,arg[2])),i->i<>2) then
# return fail;
# fi;
# fi;
# if IsMutable(m) and ForAny(m, IsMutable) then
# return fail;
# fi;
# CONV_GF2MAT(m);
# return true;
#end);
#############################################################################
##
#F ImmutableMatrix( <field>, <matrix> [,<change>] )
##
DoImmutableMatrix:=function(field,matrix,change)
local sf, rep, ind, ind2, row, i,big,l;
if not (IsPlistRep(matrix) or IsGF2MatrixRep(matrix) or
Is8BitMatrixRep(matrix)) then
# if empty of not list based, simply return `Immutable'.
return Immutable(matrix);
fi;
if IsInt(field) then
sf:=field;
else
if not IsField(field) then
# not a field
return matrix;
fi;
sf:=Size(field);
fi;
big:=sf>256 or sf=0;
# the representation we want the rows to be in
if sf=2 then
rep:=IsGF2VectorRep;
elif not big then
rep:=function(v) return Is8BitVectorRep(v) and Q_VEC8BIT(v) = sf; end;
else
rep:=IsPlistRep;
fi;
# get the indices of the rows that need changing the representation.
ind:=[]; # rows to convert
ind2:=[]; # rows to rebuild
for i in [1..Length(matrix)] do
if not rep(matrix[i]) then
if big or IsLockedRepresentationVector(matrix[i])
or (IsMutable(matrix[i]) and not change) then
Add(ind2,i);
else
# wrong rep, but can be converted
Add(ind,i);
fi;
elif (IsMutable(matrix[i]) and not change) then
# right rep but wrong mutability
Add(ind2,i);
fi;
od;
# do we need to rebuild outer matrix layer?
if (IsMutable(matrix) and not change) # matrix was mutable
or (Length(ind2)>0 and # we want to change rows
not IsMutable(matrix)) #but cannot change entries
or (Is8BitMatrixRep(matrix) # matrix is be compact rep
and (Length(ind)>0 or Length(ind2)>0) ) # and we change rows
then
l:=matrix;
matrix:=[];
for i in l do
Add(matrix,i);
od;
fi;
# rebuild some rows
if big then
for i in ind2 do
matrix[i]:=List(matrix[i],j->j); # plist conversion
od;
else
for i in ind2 do
row := ShallowCopy(matrix[i]);
ConvertToVectorRepNC(row, sf);
matrix[i] := row;
od;
fi;
# this can only happen if not big
for i in ind do
ConvertToVectorRepNC(matrix[i],sf);
od;
MakeImmutable(matrix);
if sf=2 and not IsGF2MatrixRep(matrix) then
CONV_GF2MAT(matrix);
elif sf>2 and sf<=256 and not Is8BitMatrixRep(matrix) then
CONV_MAT8BIT(matrix,sf);
fi;
return matrix;
end;
InstallMethod( ImmutableMatrix,"general,2",[IsObject,IsMatrix],0,
function(f,m)
return DoImmutableMatrix(f,m,false);
end);
InstallOtherMethod( ImmutableMatrix,"general,3",[IsObject,IsMatrix,IsBool],0,
DoImmutableMatrix);
InstallOtherMethod( ImmutableMatrix,"field,8bit",[IsField,Is8BitMatrixRep],0,
function(f,m)
if Q_VEC8BIT(m[1])<>Size(f) then
TryNextMethod();
fi;
return Immutable(m);
end);
InstallOtherMethod( ImmutableMatrix,"field,gf2",[IsField,IsGF2MatrixRep],0,
function(f,m)
if 2<>Size(f) then
TryNextMethod();
fi;
return Immutable(m);
end);
InstallOtherMethod( ImmutableMatrix,"fieldsize,8bit",[IsPosInt,Is8BitMatrixRep],0,
function(f,m)
if Q_VEC8BIT(m[1])<>f then
TryNextMethod();
fi;
return Immutable(m);
end);
InstallOtherMethod( ImmutableMatrix,"fieldsize,gf2",[IsPosInt,IsGF2MatrixRep],0,
function(f,m)
if 2<>f then
TryNextMethod();
fi;
return Immutable(m);
end);
InstallOtherMethod( ImmutableMatrix,"empty",[IsObject,IsEmpty],0,
function(f,m)
return Immutable(m);
end);
InstallOtherMethod( ImmutableMatrix,"transposed empty",[IsObject,IsList],0,
function(f,m)
if not ForAll(m,i->IsList(i) and Length(i)=0) then
TryNextMethod();
fi;
return Immutable(m);
end);
#############################################################################
##
#M PlainListCopyOp( <v> )
##
InstallMethod( PlainListCopyOp, "for a GF2 vector",
true, [IsGF2VectorRep and IsSmallList ],
0, function( v )
PLAIN_GF2VEC(v);
return v;
end);
#############################################################################
##
#M PlainListCopyOp( <m> )
##
InstallMethod( PlainListCopyOp, "for a GF2 matrix",
true, [IsSmallList and IsGF2MatrixRep ],
0, function( m )
PLAIN_GF2MAT(m);
return m;
end);
#############################################################################
##
#M MultRowVector( <vl>, <mul>)
##
InstallOtherMethod( MultRowVector, "for GF(2) vector and char 2 scalar",
IsCollsElms, [IsGF2VectorRep and IsRowVector and IsMutable,
IsFFE], 0,
MULT_ROW_VECTOR_GF2VECS_2);
#############################################################################
##
#M PositionNot( <vec>, GF2Zero )
#M PositionNot( <vec>, GF2Zero, 0)
##
InstallOtherMethod( PositionNot, "for GF(2) vector and 0*Z(2)",
IsCollsElms, [IsGF2VectorRep and IsRowVector , IsFFE and
IsZero], 0,
POSITION_NONZERO_GF2VEC);
InstallMethod( PositionNot, "for GF(2) vector and 0*Z(2) and offset",
IsCollsElmsX, [IsGF2VectorRep and IsRowVector , IsFFE and
IsZero, IsInt], 0,
function(v,z,z1)
return POSITION_NONZERO_GF2VEC3(v,z,z1);
end);
#############################################################################
##
#M Append( <vecl>, <vecr> )
##
InstallMethod( Append, "for GF2 vectors",
true, [IsGF2VectorRep and IsMutable and IsList,
IsGF2VectorRep and IsList], 0,
APPEND_GF2VEC);
#############################################################################
##
#M PositionCanonical( <list>, <obj> ) . . for GF2 matrices
##
InstallMethod( PositionCanonical,
"for internally represented lists, fall back on `Position'",
true, # the list may be non-homogeneous.
[ IsList and IsGF2MatrixRep, IsObject ], 0,
function( list, obj )
return Position( list, obj, 0 );
end );
#############################################################################
##
#M ShallowCopy( <vec> ) . . . for GF2 vectors
##
InstallMethod( ShallowCopy,
"for GF2 vectors",
true, [ IsGF2VectorRep and IsList and IsRowVector ], 0,
SHALLOWCOPY_GF2VEC);
#############################################################################
##
#M PositionNonZero( <vec> )
##
InstallOtherMethod(PositionNonZero, "for GF(2) vector",true,
[IsGF2VectorRep and IsRowVector],0,
# POSITION_NONZERO_GF2VEC ignores the second argument
v-> POSITION_NONZERO_GF2VEC(v,0));
InstallOtherMethod(PositionNonZero, "for GF(2) vector and offset",true,
[IsGF2VectorRep and IsRowVector, IsInt],0,
# POSITION_NONZERO_GF2VEC3 ignores the second argument
function(v, from)
return POSITION_NONZERO_GF2VEC3(v,0,from);
end);
#############################################################################
##
#M PositionNonZero( <vec> )
##
InstallOtherMethod(PositionNonZero,
"General method for a row vector",
true,[IsRowVector],0,
function(vec)
local i,z;
if Length(vec)=0 then return 1;fi;
z:=Zero(vec[1]);
for i in [1..Length(vec)] do
if vec[i]<>z then return i;fi;
od;
return Length(vec)+1;
end);
#############################################################################
##
#M NumberFFVector(<<vec>,<sz>)
##
InstallMethod(NumberFFVector,"GF2-Vector",true,
[IsGF2VectorRep and IsRowVector and IsFFECollection,IsPosInt],0,
function(v,n)
if n<>2 then TryNextMethod();fi;
return NUMBER_GF2VEC(v);
end);
#############################################################################
##
#M NumberFFVector(<<vec>,<sz>)
##
InstallMethod(NumberFFVector,"uncompressed vecffe",
[IsRowVector and IsFFECollection,IsPosInt],
function(v,n)
local qels, sy, p, x;
qels:= EnumeratorSorted( GF(n) );
sy := 0;
for x in v do
p := Position(qels, x);
if p = fail then
Info(InfoWarning,2,
"NumberFFVector: Vector not over specified field");
return fail;
fi;
sy := n*sy + (p-1);
od;
return sy;
end);
#############################################################################
##
#M IsSubset(<finfield>,<gf2vec>)
##
InstallMethod(IsSubset,"field, 8bit-vector",IsIdenticalObj,
[ IsField and IsFinite and IsFFECollection,
IsGF2VectorRep and IsRowVector and IsFFECollection],0,
function(F,v)
# the family ensures the field is in the correct characteristic.
return true;
end);
#############################################################################
##
#M DefaultFieldOfMatrix( <ffe-mat> )
##
InstallMethod( DefaultFieldOfMatrix,
"method for a matrix over GF(2)", true,
[ IsMatrix and IsFFECollColl and IsGF2MatrixRep ], 0,
function( mat )
return GF(2);
end );
#############################################################################
##
#M DegreeFFE( <vector> )
##
InstallOtherMethod( DegreeFFE, "for GF(2) vectors", true,
[ IsRowVector and IsFFECollection and IsGF2VectorRep ], 0, v->1);
#############################################################################
##
#M LeftShiftRowVector( <vec>, <shift> )
##
InstallMethod( LeftShiftRowVector, "gf2 vector", true,
[IsMutable and IsRowVector and IsGF2VectorRep,
IsPosInt], 0,
SHIFT_LEFT_GF2VEC);
#############################################################################
##
#M RightShiftRowVector( <vec>, <shift>, <zero> )
##
InstallMethod( RightShiftRowVector, "gf2 vector, fill with zeros", IsCollsXElms,
[IsMutable and IsRowVector and IsGF2VectorRep,
IsPosInt,
IsFFE and IsZero], 0,
SHIFT_RIGHT_GF2VEC);
#############################################################################
##
#M ShrinkRowVector( <vec> )
InstallMethod( ShrinkRowVector, "GF2 vector", true,
[IsMutable and IsRowVector and IsGF2VectorRep ],
0,
function(vec)
local r;
r := RIGHTMOST_NONZERO_GF2VEC(vec);
RESIZE_GF2VEC(vec, r);
end);
#############################################################################
##
#M RemoveOuterCoeffs( <vec>, <zero> )
##
InstallMethod( RemoveOuterCoeffs, "gf2vec and zero", IsCollsElms,
[ IsMutable and IsGF2VectorRep and IsRowVector, IsFFE and
IsZero], 0,
function (v,z)
local shift;
shift := POSITION_NONZERO_GF2VEC(v,z) -1;
if shift <> 0 then
SHIFT_LEFT_GF2VEC( v, shift);
fi;
if v <> [] then
RESIZE_GF2VEC(v, RIGHTMOST_NONZERO_GF2VEC(v));
fi;
return shift;
end);
#############################################################################
##
#M ProductCoeffs( <vec>, <len>, <vec>, <len>)
##
##
InstallMethod( ProductCoeffs, "GF2 vectors, kernel method", IsFamXFamY,
[IsGF2VectorRep and IsRowVector, IsInt, IsGF2VectorRep and
IsRowVector, IsInt ], 0,
PROD_COEFFS_GF2VEC);
InstallOtherMethod( ProductCoeffs, "Gf2 vectors, kernel method (2 arg)",
IsIdenticalObj,
[IsGF2VectorRep and IsRowVector, IsGF2VectorRep and
IsRowVector ], 0,
function(v,w)
return PROD_COEFFS_GF2VEC(v, Length(v), w, Length(w));
end);
#############################################################################
##
#M ReduceCoeffs( <vec>, <len>, <vec>, <len>)
##
##
InstallMethod( ReduceCoeffs, "GF2 vectors, kernel method", IsFamXFamY,
[IsGF2VectorRep and IsRowVector and IsMutable, IsInt, IsGF2VectorRep and
IsRowVector, IsInt ], 0,
REDUCE_COEFFS_GF2VEC);
InstallOtherMethod( ReduceCoeffs, "Gf2 vectors, kernel method (2 arg)",
IsIdenticalObj,
[IsGF2VectorRep and IsRowVector and IsMutable, IsGF2VectorRep and
IsRowVector ], 0,
function(v,w)
return REDUCE_COEFFS_GF2VEC(v, Length(v), w, Length(w));
end);
#############################################################################
##
#M PowerModCoeffs( <vec1>, <len1>, <exp>, <vec2>, <len2> )
##
InstallMethod( PowerModCoeffs, "for gf2vectors", IsFamXYFamZ,
[IsGF2VectorRep and IsRowVector, IsInt, IsPosInt,
IsGF2VectorRep and IsRowVector, IsInt], 0,
function( v, lv, exp, w, lw)
local pow, lpow, bits, i;
if exp = 1 then
pow := ShallowCopy(v);
ReduceCoeffs(pow,lv,w,lw);
return pow;
fi;
pow := v;
lpow := lv;
bits := [];
while exp > 0 do
Add(bits, exp mod 2);
exp := QuoInt(exp,2);
od;
bits := Reversed(bits);
for i in [2..Length(bits)] do
pow := PROD_COEFFS_GF2VEC(pow,lpow, pow, lpow);
lpow := Length(pow);
lpow := REDUCE_COEFFS_GF2VEC( pow, lpow, w, lw);
if lpow = 0 then
return pow;
fi;
if bits[i] = 1 then
pow := PROD_COEFFS_GF2VEC(pow, lpow, v, lv);
lpow := Length(pow);
lpow := REDUCE_COEFFS_GF2VEC( pow, lpow, w, lw);
if lpow = 0 then
return pow;
fi;
fi;
od;
return pow;
end);
#############################################################################
##
#M DomainForAction( <pnt>, <acts> )
##
InstallMethod(DomainForAction,"FFE vector/matrix",IsElmsCollCollsX,
# for technical reasons a matrix list is not automatically
# IsMatrixCollection -- thus we cannot use this filter here. AH
#T this method is only installed for finite fields. There ought to be a
#T method for finite rings and there could be one for infinite fields. AH
[IsVector and IsFFECollection,IsList,IsFunction],0,
function(pnt,acts,act)
local l,f;
if (not ForAll(acts,IsMatrix)) or
(act<>OnPoints and act<>OnLines and act<>OnRight
and act<>OnSubspacesByCanonicalBasisConcatenations) or
CollectionsFamily(CollectionsFamily(FamilyObj(pnt)))<>FamilyObj(acts) then
TryNextMethod(); # strange operation, might extend the domain
fi;
return NaturalActedSpace(acts,[pnt]);
# if Length(pnt)=0 or Length(acts)=0 then
# return fail;
# fi;
# l:=Concatenation(acts);
# Add(l,pnt);
# f:=DefaultFieldOfMatrix(l);
# if f = fail then
# return fail;
# fi;
# return f^Length(pnt);
end);
#############################################################################
##
#M DomainForAction( <pnt>, <acts> )
##
InstallMethod(DomainForAction,"matrix/matrix",IsElmsCollsX,
# for technical reasons a matrix list is not automatically
# IsMatrixCollection -- thus we cannot use this filter here. AH
#T this method is only installed for finite fields. There ought to be a
#T method for finite rings and there could be one for infinite fields. AH
[IsMatrix and IsFFECollColl,IsList,IsFunction],0,
function(pnt,acts,act)
local l,f,vkey;
if (not ForAll(acts,IsMatrix)) or
(act<>OnPoints and act<>OnSubspacesByCanonicalBasis and act<>OnRight) then
TryNextMethod(); # strange operation, might extend the domain
fi;
l:=NaturalActedSpace(acts,pnt);
f:=Size(LeftActingDomain(l));
l:=Size(l);
return rec(hashfun:=function(b)
local h,i;
h:=0;
for i in b do
h:=h*l+NumberFFVector(i,f);
od;
return h;
end);
end);
InstallMethod(DomainForAction,"vector/permgrp",true,
[IsList,IsList,IsFunction],0,
function(pnt,acts,act)
local l,f;
if (not (ForAll(acts,IsPerm) and ForAll(pnt,IsScalar)))
or (act<>Permuted) then
TryNextMethod(); # strange operation, might extend the domain
fi;
return DefaultField(pnt)^Length(pnt);
end);
#############################################################################
##
#M SemiEchelonMat( <GF2 matrix> )
#M SemiEchelonMatTransformation( <GF2 matrix> )
#M SemiEchelonMatDestructive( <plain list of GF2 vectors> )
#M SemiEchelonMatTransformationDestructive( <plain list of GF2 vectors> )
##
#
#
# This is the rank by which we increase the GF2 kernel methods,
# so that they get tried before the 8bit ones, as they will fall
# through faster.
#
#
BindGlobal("GF2_AHEAD_OF_8BIT_RANK", 10);
#
# If mat is in the GF2 special representation, then we do
# have to copy it, but we know that the rows of the result will
# already be in GF2 special representation, so we skip the conversion
# step in the generic method
#
InstallMethod(SemiEchelonMat, "shortcut method for GF2 matrices",
true,
[ IsMatrix and IsGF2MatrixRep and IsFFECollColl ],
0,
function(mat)
local res;
res := SemiEchelonMatDestructive( List(mat, ShallowCopy) ) ;
ConvertToMatrixRepNC(res.vectors,2);
return res;
end );
InstallMethod(SemiEchelonMatTransformation,
"kernel method for plain lists of GF2 vectors",
true,
[ IsMatrix and IsFFECollColl and IsGF2MatrixRep],
0,
function(mat)
local res;
res := SemiEchelonMatTransformationDestructive( List( mat, ShallowCopy) );
ConvertToMatrixRepNC(res.vectors,2);
ConvertToMatrixRepNC(res.coeffs,2);
ConvertToMatrixRepNC(res.relations,2);
return res;
end );
#
# The real kernel methods, which are destructive and want plain lists
# of GF2 vectors as their arguments, but will try next if they get other
# plain lists
#
InstallMethod(SemiEchelonMatDestructive,
"kernel method for plain lists of GF2 vectors",
true,
[ IsPlistRep and IsMatrix and IsMutable and IsFFECollColl ],
GF2_AHEAD_OF_8BIT_RANK,
SEMIECHELON_LIST_GF2VECS);
InstallMethod(SemiEchelonMatTransformationDestructive,
"kernel method for plain lists of GF2 vectors",
true,
[ IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
GF2_AHEAD_OF_8BIT_RANK,
SEMIECHELON_LIST_GF2VECS_TRANSFORMATIONS);
#############################################################################
##
#M TriangulizeMat( <plain list of GF2 vectors> )
##
## The method will fall through if the matrix is not a plain list of
## GF2 vectors
InstallMethod(TriangulizeMat,
"kernel method for plain list of GF2 vectors",
true,
[IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
GF2_AHEAD_OF_8BIT_RANK,
TRIANGULIZE_LIST_GF2VECS);
##
#T Really should sort this one in the kernel
## but this should fix the major inefficiency for now
##
InstallMethod(TriangulizeMat,
"for GF2 matrices",
true,
[IsMatrix and IsMutable and IsFFECollColl and IsGF2MatrixRep],
0,
function(m)
local i,imms;
PLAIN_GF2MAT(m);
imms := [];
for i in [1..Length(m)] do
if not IsMutable(m[i]) then
m[i] := ShallowCopy(m[i]);
imms[i] := true;
else
imms[i] := false;
fi;
od;
TRIANGULIZE_LIST_GF2VECS(m);
for i in [1..Length(m)] do
if not IsMutable(m[i]) then
m[i] := ShallowCopy(m[i]);
imms[i] := true;
else
imms[i] := false;
fi;
od;
CONV_GF2MAT(m);
end);
#############################################################################
##
#M DeterminantMatDestructive ( <plain list of GF2 vectors> )
##
InstallMethod(DeterminantMatDestructive,
"kernel method for plain list of GF2 vectors",
true,
[IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
GF2_AHEAD_OF_8BIT_RANK,
DETERMINANT_LIST_GF2VECS);
#############################################################################
##
#M RankMatDestructive ( <plain list of GF2 vectors> )
##
InstallMethod(RankMatDestructive,
"kernel method for plain list of GF2 vectors",
true,
[IsMatrix and IsPlistRep and IsFFECollColl and IsMutable],
GF2_AHEAD_OF_8BIT_RANK,
RANK_LIST_GF2VECS);
InstallMethod(NestingDepthM, [IsGF2MatrixRep], m->2);
InstallMethod(NestingDepthA, [IsGF2MatrixRep], m->2);
InstallMethod(NestingDepthM, [IsGF2VectorRep], m->1);
InstallMethod(NestingDepthA, [IsGF2VectorRep], m->1);
InstallMethod(PostMakeImmutable, [IsGF2MatrixRep],
function(m)
local i;
for i in [2..m![1]] do
MakeImmutable(m![i]);
od;
end);
#############################################################################
##
#M ZeroVector( len, <vector> )
##
InstallMethod( ZeroVector, "for an int and a gf2 vector",
[IsInt, IsGF2VectorRep],
function( len, v )
return ZERO_GF2VEC_2(len);
end );
InstallMethod( ZeroVector, "for an int and a gf2 matrix",
[IsInt, IsGF2MatrixRep],
function( len, m )
return ZERO_GF2VEC_2(len);
end );
#############################################################################
##
## Stuff to adhere to new vector/matrix interface:
##
InstallMethod( BaseDomain, "for a gf2 vector",
[ IsGF2VectorRep ], function( v ) return GF(2); end );
InstallMethod( BaseDomain, "for a gf2 matrix",
[ IsGF2MatrixRep ], function( m ) return GF(2); end );
InstallMethod( RowLength, "for a gf2 matrix",
[ IsGF2MatrixRep ], function( m ) return Length(m[1]); end );
# FIXME: this breaks down for matrices with 0 rows
InstallMethod( Vector, "for a list of gf2 elements and a gf2 vector",
[ IsList and IsFFECollection, IsGF2VectorRep ],
function( l, v )
local r; r := ShallowCopy(l); ConvertToVectorRep(r,2); return r;
end );
InstallMethod( Randomize, "for a mutable gf2 vector",
[ IsGF2VectorRep and IsMutable ],
function( v )
local i;
MultRowVector(v,0);
for i in [1..Length(v)] do
if Random(0,1) = 1 then v[i] := Z(2); fi;
od;
return v;
end );
InstallMethod( Randomize, "for a mutable gf2 vector and a random source",
[ IsGF2VectorRep and IsMutable, IsRandomSource ],
function( v, rs )
local i;
MultRowVector(v,0);
for i in [1..Length(v)] do
if Random(rs,0,1) = 1 then v[i] := Z(2); fi;
od;
return v;
end );
InstallMethod( MutableCopyMat, "for a gf2 matrix",
[ IsGF2MatrixRep ],
function( m )
local mm;
mm := List(m,ShallowCopy);
ConvertToMatrixRep(mm,2);
return mm;
end );
InstallMethod( MatElm, "for a gf2 matrix and two integers",
[ IsGF2MatrixRep, IsPosInt, IsPosInt ],
function( m, r, c ) return m[r][c]; end );
InstallMethod( SetMatElm, "for a gf2 matrix, two integers, and a ffe",
[ IsGF2MatrixRep, IsPosInt, IsPosInt, IsFFE ],
function( m, r, c, e ) m[r][c] := e; end );
InstallMethod( Matrix, "for a list of vecs, an integer, and a gf2 mat",
[IsList, IsInt, IsGF2MatrixRep],
function(l,rl,m)
local i,li;
if not(IsList(l[1])) then
li := [];
for i in [1..QuoInt(Length(l),rl)] do
li[i] := l{[(i-1)*rl+1..i*rl]};
od;
else
li:= ShallowCopy(l);
fi;
# FIXME: Does not work for matrices m with no rows
ConvertToMatrixRep(li,2);
return li;
end );
BindGlobal( "PositionLastNonZeroFunc",
function(l)
local i;
i := Length(l);
while i >= 1 and IsZero(l[i]) do i := i - 1; od;
return i;
end );
BindGlobal( "PositionLastNonZeroFunc2",
function(l,pos)
local i;
i := pos-1;
while i >= 1 and IsZero(l[i]) do i := i - 1; od;
return i;
end );
InstallMethod( PositionLastNonZero, "for a row vector obj",
[IsRowVectorObj], PositionLastNonZeroFunc );
InstallMethod( PositionLastNonZero, "for a matrix obj",
[IsMatrixObj], PositionLastNonZeroFunc );
InstallMethod( PositionLastNonZero, "for a matrix obj, and an index",
[IsMatrixObj, IsPosInt], PositionLastNonZeroFunc2 );
InstallMethod( ExtractSubMatrix, "for a gf2 matrix, and two lists",
[IsGF2MatrixRep, IsList, IsList],
function( m, rows, cols )
local mm,r;
mm := [];
for r in rows do
Add(mm, m![r+1]{cols});
od;
ConvertToMatrixRepNC(mm,2);
return mm;
end );
InstallMethod( CopySubVector, "for two gf2 vectors, and two ranges",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsRange, IsRange],
function( v, w, f, t )
local l;
l := Length(f);
Assert(2, l = Length(t));
if l <= 1 or (f[2] - f[1] = 1 and t[2] - t[1] = 1) then
COPY_SECTION_GF2VECS(v,w,f[1],t[1],l);
else
TryNextMethod();
fi;
end );
InstallMethod( CopySubVector, "for two gf2 vectors, and two lists",
[IsGF2VectorRep, IsGF2VectorRep and IsMutable, IsList, IsList],
function( v, w, f, t )
w{t} := v{f};
end );
InstallMethod( CopySubMatrix, "for two gf2 matrices, and four lists",
[IsGF2MatrixRep, IsGF2MatrixRep, IsList, IsList, IsList, IsList],
function( a, b, frows, trows, fcols, tcols )
local i;
for i in [1..Length(frows)] do
CopySubVector(a[frows[i]],b[trows[i]], fcols, tcols);
od;
end );
InstallMethod( CopySubMatrix, "for two gf2 matrices, two lists and two ranges",
[IsGF2MatrixRep, IsGF2MatrixRep, IsList, IsList, IsRange, IsRange],
function( a, b, frows, trows, fcols, tcols )
local l, i;
l := Length(fcols);
Assert(2, l = Length(tcols));
if l <= 1 or (fcols[2] - fcols[1] = 1 and tcols[2] - tcols[1] = 1) then
for i in [1..Length(frows)] do
COPY_SECTION_GF2VECS(a[frows[i]],b[trows[i]],fcols[1],tcols[1],l);
od;
else
TryNextMethod();
fi;
end );
InstallMethod( Randomize, "for a mutable gf2 matrix",
[IsGF2MatrixRep and IsMutable],
function( m )
local v;
for v in m do Randomize(v); od;
return m;
end );
InstallMethod( Randomize, "for a mutable gf2 matrix, and a random source",
[IsGF2MatrixRep and IsMutable, IsRandomSource],
function( m, rs )
local v;
for v in m do Randomize(v,rs); od;
return m;
end );
InstallMethod( Unpack, "for a gf2 matrix",
[IsGF2MatrixRep],
function( m )
return List(m,AsPlist);
end );
InstallMethod( Unpack, "for a gf2 vector",
[IsGF2VectorRep],
function( v ) return AsPlist(v); end );
InstallOtherMethod( KroneckerProduct, "for two gf2 matrices",
[IsGF2MatrixRep and IsMatrix, IsGF2MatrixRep and IsMatrix],
KRONECKERPRODUCT_GF2MAT_GF2MAT );
InstallMethod( Fold, "for a gf2 vector, a positive int, and a gf2 matrix",
[ IsRowVectorObj and IsGF2VectorRep, IsPosInt, IsGF2MatrixRep ],
function( v, rl, t )
local rows,i,tt,m;
m := [];
tt := ZeroVector(rl,v);
for i in [1..Length(v)/rl] do
CopySubVector(v,tt,[(i-1)*rl+1..i*rl],[1..rl]);
Add(m,ShallowCopy(tt));
od;
ConvertToMatrixRep(m,2);
return m;
end );
InstallMethod( ConstructingFilter, "for a gf2 vector",
[ IsGF2VectorRep ], function(v) return IsGF2VectorRep; end );
InstallMethod( ConstructingFilter, "for a gf2 matrix",
[ IsGF2MatrixRep ], function(v) return IsGF2MatrixRep; end );
InstallMethod( BaseField, "for a compressed gf2 matrix",
[IsGF2MatrixRep], function(m) return GF(2); end );
InstallMethod( BaseField, "for a compressed gf2 vector",
[IsGF2VectorRep], function(v) return GF(2); end );
InstallMethod( NewRowVector, "for IsGF2VectorRep, GF(2), and a list",
[ IsGF2VectorRep, IsField and IsFinite, IsList ],
function( filter, f, l )
local v;
v := ShallowCopy(l);
ConvertToVectorRepNC(v,2);
return v;
end );
InstallMethod( ZeroMatrix, "for a compressed gf2 matrix",
[IsInt, IsInt, IsGF2MatrixRep],
function( rows, cols, m )
local l,i,x;
l := [];
x := m[1];
for i in [1..rows] do
Add(l,ZeroVector(cols,x));
od;
ConvertToMatrixRepNC(l,2);
return l;
end );
InstallMethod( NewZeroVector, "for IsGF2VectorRep, GF(2), and an int",
[ IsGF2VectorRep, IsField and IsFinite, IsInt ],
function( filter, f, i )
return ZERO_GF2VEC_2(i);
end );
InstallMethod( IdentityMatrix, "for a compressed gf2 matrix",
[IsInt, IsGF2MatrixRep],
function(rows,m)
local n;
n := IdentityMat(rows,GF(2));
ConvertToMatrixRepNC(n,2);
return n;
end );
InstallMethod( NewMatrix, "for IsGF2MatrixRep, GF(2), an int, and a list",
[ IsGF2MatrixRep, IsField and IsFinite, IsInt, IsList ],
function( filter, f, rl, l )
local m;
m := List(l,ShallowCopy);
ConvertToMatrixRep(m,2);
return m;
end );
InstallMethod( NewZeroMatrix, "for IsGF2MatrixRep, GF(2), and two ints",
[ IsGF2MatrixRep, IsField and IsFinite, IsInt, IsInt ],
function( filter, f, rows, cols )
local m,i;
m := 0*[1..rows];
m[1] := NewZeroVector(IsGF2VectorRep,f,cols);
for i in [2..rows] do
m[i] := ShallowCopy(m[1]);
od;
ConvertToMatrixRep(m,2);
return m;
end );
InstallMethod( NewIdentityMatrix, "for IsGF2MatrixRep, GF(2), and an int",
[ IsGF2MatrixRep, IsField and IsFinite, IsInt ],
function( filter, f, rows )
local m,i,o;
m := 0*[1..rows];
o := Z(2);
m[1] := NewZeroVector(IsGF2VectorRep,f,rows);
for i in [2..rows] do
m[i] := ShallowCopy(m[1]);
m[i][i] := o;
od;
m[1][1] := o;
ConvertToMatrixRep(m,2);
return m;
end );
InstallMethod( ChangedBaseDomain, "for a gf2 vector and a finite field",
[ IsGF2VectorRep, IsField and IsFinite ],
function( v, f )
local w;
w := Unpack(v);
ConvertToVectorRep(w,Size(f));
return w;
end );
InstallMethod( ChangedBaseDomain, "for a gf2 matrix and a finite field",
[ IsGF2MatrixRep, IsField and IsFinite ],
function( v, f )
local w,i;
w := [];
for i in [1..Length(v)] do
Add(w,ChangedBaseDomain(v[i],f));
od;
ConvertToMatrixRep(w,Size(f));
return w;
end );
InstallMethod( CompatibleVector, "for a gf2 matrix",
[ IsGF2MatrixRep ],
function( m )
# This will break for a matrix with no rows
return ShallowCopy(m[1]);
end );
InstallMethod( CompatibleMatrix, "for a gf2 vector",
[ IsGF2VectorRep ],
function( v )
local m;
m := [ShallowCopy(v)];
ConvertToMatrixRep(m,2);
return m;
end );
InstallMethod( WeightOfVector, "for a gf2 vector",
[ IsGF2VectorRep ],
function( v )
return WeightVecFFE(v);
end );
InstallMethod( DistanceOfVectors, "for two gf2 vectors",
[ IsGF2VectorRep, IsGF2VectorRep ],
function( v, w )
return DistanceVecFFE(v,w);
end );
InstallMethod( NewCompanionMatrix,
"for IsGF2MatrixRep, a polynomial and a ring",
[ IsGF2MatrixRep, IsUnivariatePolynomial, IsRing ],
function( ty, po, bd )
local i,l,ll,n,one;
one := One(bd);
l := CoefficientsOfUnivariatePolynomial(po);
n := Length(l)-1;
if not(IsOne(l[n+1])) then
Error("CompanionMatrix: polynomial is not monic");
return fail;
fi;
l := -l{[1..n]};
ConvertToVectorRep(l,2);
ll := NewMatrix(ty,bd,n,[l]);
for i in [1..n-1] do
Add(ll,ZeroMutable(l),i);
ll[i][i+1] := one;
od;
return ll;
end );
#############################################################################
##
#E
##
|