/usr/share/gap/pkg/guava/lib/codecr.gi is in gap-guava 3.13+ds-2.
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 | #############################################################################
##
#A codecr.gi GUAVA library Reinald Baart
#A Jasper Cramwinckel
#A Erik Roijackers
#A Eric Minkes
##
## This file contains functions for calculating with code covering radii
##
## changes 10-2004:
## 1. CalculateLinearCodeCoveringRadius changed to a slightly faster
## algorithm.
## 2. minor bug fix for ExhaustiveSearchCoveringRadius
## 2. minor bug fix for IncreaseCoveringRadiusLowerBound
##
########################################################################
##
#F CoveringRadius( <code> )
##
## Return the covering radius of <code>
## In case a special algorithm for this code exist, call
## it first.
##
## Not useful for large codes.
##
## That's why I changed it, see the manual for more details
## -- eric minkes.
##
## Calculation is done in this function, instead of in the method, so that
## users can override the redundancy restriction if desired. Note that
## this does not check the trivial cases checked in the method,
CalculateLinearCodeCoveringRadius := function( code )
local H, wts,CLs,i,rho;
if Redundancy(code) = 0 then
return 0;
else
#
#return Maximum( List( SyndromeTable( code ), i -> Weight( i[ 1 ] ) ) );
# (old version had line above in place of next 5)
H:=CheckMat(code);
CLs:=CosetLeadersMatFFE(H,LeftActingDomain(code));
wts:=List([1..Length(CLs)],i->WeightVecFFE(CLs[i]));
rho:=Maximum(wts);
return rho;
fi;
end;
InstallMethod(CoveringRadius, "method for linear code", true,
[IsLinearCode], 0,
function( code )
# call the special algorithm for this code, if it exists
if HasSpecialCoveringRadius( code ) then
code!.boundsCoveringRadius :=
SpecialCoveringRadius( code ) ( code );
fi;
if Length( BoundsCoveringRadius( code ) ) = 1 then
return code!.boundsCoveringRadius[ 1 ];
else
if Redundancy( code ) < 20 then
code!.boundsCoveringRadius :=
[ CalculateLinearCodeCoveringRadius( code ) ];
else
##LR - this sets CR to an interval
InfoCoveringRadius(
"CoveringRadius: warning, the covering radius of \n",
"this code cannot be computed straightforward. \n",
"Try to use IncreaseCoveringRadiusLowerBound( <code> ).\n",
"(see the manual for more details).\n",
"The covering radius of <code> lies in the interval:\n" );
return BoundsCoveringRadius( code );
fi;
fi;
return code!.boundsCoveringRadius[ 1 ];
end);
# For small codes in large spaces, this may take a very long time
InstallMethod(CoveringRadius, "method for unrestricted code", true,
[IsCode], 0,
function( code )
local Code, vector, d, curmax, n, q, one, count, size, t, i, j,
zero, large, gen;
if IsLinearCode( code ) then
return CoveringRadius( code );
elif Length(code!.boundsCoveringRadius) = 1 then
return code!.boundsCoveringRadius[1];
elif HasSpecialCoveringRadius( code ) then
code!.boundsCoveringRadius := SpecialCoveringRadius( code ) ( code );
else
q := Size(LeftActingDomain(code));
n := WordLength(code);
size := Size(code);
one := One(LeftActingDomain(code));
zero := Zero(LeftActingDomain(code));
Code := VectorCodeword(AsSSortedList(code));
vector := List([1..n], i-> zero);
large := one;
gen := Z(q);
curmax := n;
for t in Code do
d := DistanceVecFFE(t, vector);
if d < curmax then
curmax := d;
fi;
od;
for count in [2..q^n] do
t := n;
while vector[t] = large do
vector[t] := zero;
t := t - 1;
od;
if vector[t] = zero then
vector[t] := gen;
else
vector[t] := vector[t] * gen;
fi;
t := 1;
repeat
d := DistanceVecFFE(Code[t], vector);
t := t + 1;
until d <= curmax or t > size;
if d > curmax then
curmax := n;
for t in Code do
d := DistanceVecFFE(t, vector);
if d < curmax then
curmax := d;
fi;
od;
fi;
od;
code!.boundsCoveringRadius := [curmax];
fi;
return code!.boundsCoveringRadius[1];
end);
########################################################################
##
#F BoundsCoveringRadius( <code> )
##
## Find a lower and an upper bound for the covering radius of code.
##
InstallMethod(BoundsCoveringRadius, "method for unrestricted code", true,
[IsCode], 0,
function(code)
local bcr;
if HasCoveringRadius(code) then
code!.boundsCoveringRadius := [CoveringRadius(code)];
elif not IsBound(code!.boundsCoveringRadius) then
bcr := [GeneralLowerBoundCoveringRadius(code) ..
GeneralUpperBoundCoveringRadius(code)];
if Length(bcr) = 0 then
code!.boundsCoveringRadius := [0,WordLength(code)];
else
code!.boundsCoveringRadius := bcr;
fi;
fi;
return code!.boundsCoveringRadius;
end);
########################################################################
##
#F SetBoundsCoveringRadius( <code>, <cr> )
## SetBoundsCoveringRadius( <code>, <interval> )
##
## Enable the user to set the covering radius (or bounds) him/herself.
## Used to be SetCoveringRadius, before GAP4.
InstallOtherMethod(SetBoundsCoveringRadius,
"method for unrestricted code, integer",
true, [IsCode, IsInt], 0,
function(code, cr)
SetCoveringRadius(code, cr);
code!.boundsCoveringRadius := [cr];
end);
InstallMethod(SetBoundsCoveringRadius,
"method for unrestricted code, interval",
true, [IsCode, IsVector], 0,
function(code, cr)
code!.boundsCoveringRadius := IntersectionSet(
BoundsCoveringRadius( code ), cr );
if Length( code!.boundsCoveringRadius ) = 0 then
code!.boundsCoveringRadius := cr;
fi;
IsRange( code!.boundsCoveringRadius );
if Length(code!.boundsCoveringRadius) = 1 then
SetCoveringRadius(code, code!.boundsCoveringRadius[1]);
fi;
end);
########################################################################
##
#F IncreaseCoveringRadiusLowerBound(
## <code> [, <stopdistance> ] [, <startword> ] )
##
## small bug fix 10-2004
##
InstallMethod(IncreaseCoveringRadiusLowerBound,
"method for unrestricted code, stop distance, start vector",
true, [IsCode, IsInt, IsVector], 0,
function ( code, stopdistance, startvector )
local
n, # length of the code
k, # dimension of the code
genmat, # generator matrix of the code
field, # field of the code
q, # the size of field
fieldels, # elements of field
fieldzero, # zero element of field
nonzeroels, # non-zero elements of field
boundscr, # current bounds on the covering radius
lb, # current achieved lower bound
current, # the element of field^n that we are
# currently checking
cwcurrent, # current in Codeword form
distcurrenttocode, # the distance of current to the code
currentchanged, # did we change current during the loop ?
counterchanged, # number of changes we have made so far
countertotal, # number of iterations we have made so far
h, i, j, # indexes to make the first slice
slice, # the number of the current slice
numberofslices, # the elements of the code are handled in
# slices of 2^10 elements
slicedim, # the dimension of a slice
slicesize, # the size of a slice ( q^slicedim )
index, # to enumerate the codewords, the
# correct generator must be added
# index contains the generator number
satisfied, # are we satisfied with the results ?
words, # a list of codewords in the current slice
wordslist0, # a list of codewords with distance
# distcurrentocode + 0 from current
wordslist1, # a list of codewords with distance
# distcurrentocode + 1 from current
word, # a index for wordslist*
coord, # the coordinate where current will
# be changed
staychance, # chance that we stay at the same distance
downchance, # chance that we move closer to the code
bestdist, # best distance reached so far
bestword, # the corresponding word
newelement, # the new element for current[ coord ]
newdist; # the new distance of the changed current
# to the code
# extract some code parameters
n := WordLength( code );
if IsLinearCode( code ) then
k := Dimension( code );
fi;
field := LeftActingDomain( code );
q := Size( field );
# if we cannot compute the minimum distance of the code,
# this algorithm will not be of much help either.
# <lb> is a safe place to start searching
lb := IntFloor( MinimumDistance( code ) / 2 );
boundscr := BoundsCoveringRadius( code );
if lb > boundscr[ 1 ] then
code!.boundsCoveringRadius := Filtered( boundscr, n -> lb <= n );
IsRange( code!.boundsCoveringRadius );
boundscr := code!.boundsCoveringRadius;
fi;
if Length( boundscr ) = 1 then
# if there is nothing to compute,
# then just return the covering radius
return boundscr[ 1 ];
fi;
# starting vector
#
current := ShallowCopy(VectorCodeword( Codeword( startvector ) ));
# (old version has above in place of below)
# current := Codeword( startvector );
distcurrenttocode := MinimumDistance( code, Codeword( current) );
bestdist := distcurrenttocode;
bestword := ShallowCopy( current );
# initialise some parameters and useful variables
fieldels := AsSSortedList( field );
fieldzero := Zero(field);
nonzeroels := Difference( fieldels, [ fieldzero ] );
if IsLinearCode( code ) then
genmat := GeneratorMat( code );
# try to make the size of a group codewords to be about
# CRMemSize
slicedim := LogInt( CRMemSize, q );
numberofslices := Maximum( 1, q^( k-slicedim ) );
slicesize := q^slicedim;
fi;
satisfied := false;
currentchanged := true;
counterchanged := 0;
countertotal := 0;
staychance := 10; # maybe make arguments of these
downchance := 1;
# the words array contains all codewords generated by
# genmat[ 1 ] ... genmat[ slicedim ] ( or genmat[ k ], if
# slicedim > k )
if IsLinearCode( code ) then
words := [ NullVector( n, field ) ];
for i in [ 1 .. Minimum( slicedim, k ) ] do
for j in [ 1 .. q^( i-1 ) ] do
for h in [ 1 .. q-1 ] do
Add( words, words[ j ] + genmat[ i ] * nonzeroels[ h ] );
od;
od;
od;
else
# if the code is non-linear, the
# elements field is obligatory,
# so it fits in memory.
# no need for all the hassle as in the linear case,
# but the disadvantage is that we can't handle
# large non-linear codes.
# but then again, GUAVA can't handle these anyway.
words := VectorCodeword( AsSSortedList( code ) );
fi;
# start algorithm, stop when we are satisfied with the results
# (either we have a coset leader of weigth <stopweigth>,
# or lb = ub)
while not satisfied do
countertotal := countertotal + 1;
if countertotal mod 1000 = 0 then
InfoCoveringRadius( "Number of runs: ",
countertotal,
" best distance so far: ", bestdist, "\n" );
fi;
if currentchanged then
# current word has changed, generate three lists of
# codewords that have distance distcurrenttocode,
# distcurrenttocode + 1 and distcurrenttocode + 2
cwcurrent := Codeword( current );
if distcurrenttocode > bestdist then
bestdist := distcurrenttocode;
bestword := ShallowCopy( current );
InfoCoveringRadius(
"New best distance: ", bestdist, "\n" );
fi;
wordslist0 := [];
wordslist1 := [];
if IsLinearCode( code ) then
for slice in [ 0 .. numberofslices-1 ] do
if slice > 0 then
i := k - slicedim - 1;
while EuclideanRemainder( slice, q^i ) <> 0 do
i := i - 1;
od;
index := slicedim + i + 1;
words := List( words, x -> x + genmat[ index ] );
fi;
Append( wordslist0,
Filtered( words, x ->
DistanceVecFFE( x, current )
= distcurrenttocode ) );
Append( wordslist1,
Filtered( words, x ->
DistanceVecFFE( x, current )
= distcurrenttocode + 1 ) );
od;
else
wordslist0 := Filtered( words, x->
DistanceVecFFE( x, current )
= distcurrenttocode );
wordslist1 := Filtered( words, x->
DistanceVecFFE( x, current )
= distcurrenttocode + 1 );
fi;
currentchanged := false;
counterchanged := counterchanged + 1;
if EuclideanRemainder( counterchanged, 100 ) = 0 then
InfoCoveringRadius( "Number of changes: ",
counterchanged, "\n" );
fi;
fi;
# pick a coordinate
# the algorithm will look what happens if we change this coordinate
coord := Random( [ 1 .. n ] );
# the possible new element for this coordinate
# is picked at random from the field elements
newelement := Random( Difference( fieldels,
[ current[ coord ] ] ) );
# check the new word against the codewords that are
# at distance distcurrenttocode + 0 from current
# the result can be:
# 1) the distance to all words in wordslist0 is
# one more than distcurrenttocode
# (this is the situation that we hope for)
# 2) there is at least one word in wordslist0 that
# has distance distcurrenttocode - 1 to the
# new current
# 3) if the field is not GF(2):
# there is a word in wordslist0 that stays
# at the same distance
newdist := distcurrenttocode + 1;
for word in wordslist0 do
if word[ coord ] <> current[ coord ] then
if word[ coord ] = newelement then
newdist := distcurrenttocode - 1;
else
newdist := distcurrenttocode;
fi;
fi;
od;
# only check against other words if the previous tests
# did not fail
if newdist > distcurrenttocode then
# check the new word against the codewords that are at
# distance distcurrenttocode + 1 from current
# again, two results are possible
# 1) all words in wordslist1 are at distance
# distcurrenttocode + 1 or + 2 (this is good)
# 2) there is a word in wordslist1 that now has
# distance distcurrenttocode to current
# this means we did not find an improvement
for word in wordslist1 do
if word[ coord ] = newelement then
newdist := distcurrenttocode;
fi;
od;
fi;
if newdist > distcurrenttocode then
# we found a new coset leader with larger weight
# now change current
current[ coord ] := newelement;
currentchanged := true;
distcurrenttocode := newdist;
# also check whether the covering radius lower bound
# can be increased, this is what the whole
# algorithm is about !
if distcurrenttocode > boundscr[ 1 ] then
# write directly to the code to make the change
# permanent, even if the user interrupted us
code!.boundsCoveringRadius :=
Filtered( boundscr, x -> x >= distcurrenttocode );
# make it a range together if possible
IsRange( code!.boundsCoveringRadius );
boundscr := code!.boundsCoveringRadius;
# maybe we have reached the upper bound
# then we can stop altogether !
if Length( boundscr ) = 1 then
satisfied := true;
fi;
fi;
elif newdist = distcurrenttocode then
# the change to the word did not change the
# distance to the code
if Random( [ 1 .. 100 ] ) <= staychance then
current[ coord ] := newelement;
currentchanged := true;
fi;
else
# make it a 1 in 100 chance to get closer anyway
# because we do not want to get stuck in a
# suboptimal coset
if Random( [ 1 .. 100 ] ) <= downchance then
current[ coord ] := newelement;
currentchanged := true;
distcurrenttocode := newdist;
fi;
fi;
# maybe the distance of current to the code
# is high enough for the user
# then we should stop
if distcurrenttocode = stopdistance then
satisfied := true;
fi;
od;
# return the new covering radius bounds, and a coset leader
# that has weight equal to the lower bound
return rec( boundsCoveringRadius := code!.boundsCoveringRadius,
cosetLeader := Codeword( current ) );
end);
InstallOtherMethod(IncreaseCoveringRadiusLowerBound,
"method for unrestricted code, starting vector",
true, [IsCode, IsVector], 0,
function( code, startvector )
# stopdistance = -1 is the default: never stop, unless the lower
# bound meets the upper bound
return IncreaseCoveringRadiusLowerBound( code, -1, startvector );
end);
InstallOtherMethod(IncreaseCoveringRadiusLowerBound,
"method for unrestricted code, stopdistance",
true, [IsCode, IsInt], 0,
function( code, stopdistance )
local lb, current, distcurrenttocode;
lb := IntFloor( MinimumDistance( code ) / 2 );
current := RandomVector( WordLength( code ),
Random( [0..WordLength( code )] ),
LeftActingDomain( code ));
distcurrenttocode := MinimumDistance( code, Codeword(current) );
while distcurrenttocode < lb do
current := RandomVector( WordLength( code ),
Random( [0..WordLength( code )] ),
LeftActingDomain( code ));
distcurrenttocode := MinimumDistance( code, Codeword(current) );
od;
return IncreaseCoveringRadiusLowerBound( code, -1, current);
end);
InstallOtherMethod(IncreaseCoveringRadiusLowerBound,
"method for unrestricted code", true, [IsCode], 0,
function( code )
local lb, current, distcurrenttocode;
lb := IntFloor( MinimumDistance( code ) / 2 );
current := RandomVector( WordLength( code ),
Random( [0..WordLength( code )] ),
LeftActingDomain( code ));
# distcurrenttocode := MinimumDistance( code, current );
# (old version had above line)
distcurrenttocode := MinimumDistance( code, Codeword(current) );
while distcurrenttocode < lb do
current := RandomVector( WordLength( code ),
Random( [0..WordLength( code )] ),
LeftActingDomain( code ));
distcurrenttocode := MinimumDistance( code, Codeword(current) );
od;
return IncreaseCoveringRadiusLowerBound( code, -1, current);
end);
########################################################################
##
#F ExhaustiveSearchCoveringRadius( <code> )
##
## Try to compute the covering radius. Don't compute all coset
## leaders, but increment the lower bound as soon as a coset leader
## is found.
##
InstallMethod(ExhaustiveSearchCoveringRadius,
"unrestricted code, boolean stopsoon",
true, [IsCode,IsBool], 0,
function(C, stopsoon)
if IsLinearCode(C) then
return ExhaustiveSearchCoveringRadius(C, stopsoon);
else
Error("ExhaustiveSearchCoveringRadius: <code> must be a linear code");
fi;
end);
InstallMethod(ExhaustiveSearchCoveringRadius, "linear code, boolean stopsoon",
true, [IsLinearCode, IsBool], 0,
function(code, stopsoon)
local k, n, i, j, lastone, zerofound, IsCosetLeader,
lb, we, wd, vc, cont, codewords,
leaderfound, allexamined, supp, elmsC, elms, len, one, zero,
boundscr;
IsCosetLeader := function( codewords, len, word, wt, one )
local i, check, cw, wcw, j;
check := true;
i := 1;
while i <= len and check do
cw := codewords[ i ] + word;
wcw := 0;
for j in [ 1 .. Length( cw ) ] do
if cw[ j ] = one then
wcw := wcw + 1;
fi;
od;
if wcw < wt then
check := false;
fi;
i := i + 1;
od;
return check;
end;
if Size( LeftActingDomain( code ) ) <> 2 then
Error( "CoveringRadiusSearch: <code> must be a binary code" );
fi;
boundscr := BoundsCoveringRadius( code );
if Length( boundscr ) = 1 then
return boundscr[ 1 ];
fi;
lb := boundscr[ 1 ];
n := WordLength( code );
wd := WeightDistribution( code );
elms := [];
for i in [ 0 .. n ] do
if wd[ i + 1 ] > 0 then
elms[ i + 1 ] := ShallowCopy(AsSSortedList(
ConstantWeightSubcode( code, i ) ));
fi;
od;
for i in [ 1 .. n+1 ] do
if IsBound( elms[ i ] ) then
for j in [ 1 .. Length( elms[ i ] ) ] do
elms[ i ][ j ] := VectorCodeword( elms[ i ][ j ] );
#mutable error on:
# C:=RandomLinearCode(10,5,GF(2));
# ExhaustiveSearchCoveringRadius(C,true);
od;
fi;
od;
# try to find a coset leader with weight > lb
# if found, increase lb
one := One(GF(2));
zero := Zero(GF(2));
cont := true;
while cont do
k := BoundsCoveringRadius(code)[ 1 ] + 1;
InfoCoveringRadius( "Trying ", k, " ...\n" );
codewords := [ NullVector(n, GF(2) ) ];
for i in [ 1 .. Minimum( n, 2 * k - 1) ] do
if wd[ i + 1 ] <> 0 then
Append( codewords, elms[ i + 1 ] );
fi;
od;
len := Length( codewords );
vc := NullVector( n, GF(2) );
for i in [ 1 .. k ] do
vc[ i ] := one;
od;
lastone := k;
allexamined := false;
leaderfound := false;
while not leaderfound and not allexamined do
if not IsCosetLeader( codewords, len, vc, k, one ) then
if lastone = n then
zerofound := false;
i := lastone - 1;
while i > n - k and vc[ i ] = one do
i := i - 1;
od;
if i = n - k then
allexamined := true;
else
j := i;
i := i + 1;
while vc[ j ] = zero do
j := j - 1;
od;
vc[ j ] := zero;
vc[ j + 1 ] := one;
j := j + 2;
if i <> j then
while i <= lastone do
vc[ j ] := one;
vc[ i ] := zero;
i := i + 1;
j := j + 1;
od;
lastone := j - 1;
else
lastone := n;
fi;
fi;
else
vc[ lastone ] := zero;
lastone := lastone + 1;
vc[ lastone ] := one;
fi;
else
leaderfound := true;
fi;
od;
if leaderfound then
code!.boundsCoveringRadius :=
Filtered( code!.boundsCoveringRadius, x -> x >= k );
if stopsoon then
cont := false;
fi;
else
code!.boundsCoveringRadius :=
[ code!.boundsCoveringRadius[ 1 ] ];
cont := false;
fi;
od;
IsRange( code!.boundsCoveringRadius );
return( code!.boundsCoveringRadius );
end);
InstallOtherMethod(ExhaustiveSearchCoveringRadius, "unrestricted code", true,
[IsCode], 0,
function(C)
return ExhaustiveSearchCoveringRadius(C, true);
end);
########################################################################
##
#F CoveringRadiusLowerBoundTable
##
CoveringRadiusLowerBoundTable := [
[ 3, 2, , , , , , , , , # n = 13
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 3, 3, , , , , , , , , # n = 14
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 4, 3, 3, , , , , , , , # n = 15
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 4, 4, 3, 3, , , , , , , # n = 16
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 4, 4, 3, 3, 3, , , , , , # n = 17
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 5, 4, 4, 3, 3, 3, , , , , # n = 18
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 5, 4, 4, 4, 3, 3, 2, , , , # n = 19
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 6, 5, 4, 4, 4, 3, 3, 2, , , # n = 20
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 6, 5, 5, 4, 4, 3, 3, 3, , , # n = 21
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 6, 6, 5, 5, 4, 4, 3, 3, 3, , # n = 22
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 7, 6, 5, 5, 4, 4, 3, 3, 3, 3, # n = 23
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 7, 6, 6, 5, 5, 4, 4, 3, 3, 3, # n = 24
3, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 7, 7, 6, 6, 5, 5, 4, 4, 3, 3, # n = 25
3, 2, , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 8, 7, 7, 6, 6, 5, 5, 4, 4, 3, # n = 26
3, 3, 2, , , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 8, 8, 7, 6, 6, 5, 5, 4, 4, 4, # n = 27
3, 3, 3, 2, , , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 9, 8, 7, 7, 6, 6, 5, 5, 4, 4, # n = 28
4, 3, 3, 3, 2, , , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 9, 8, 8, 7, 7, 6, 6, 5, 5, 4, # n = 29
4, 4, 3, 3, 3, 2, , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 9, 9, 8, 7, 7, 6, 6, 5, 5, 5, # n = 30
4, 4, 4, 3, 3, 3, , , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 10, 9, 8, 8, 7, 7, 6, 6, 5, 5, # n = 31
5, 4, 4, 3, 3, 3, 3, , , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, # n = 32
5, 4, 4, 4, 3, 3, 3, 3, , ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 11, 10, 9, 9, 8, 7, 7, 6, 6, 6, # n = 33
5, 5, 4, 4, 4, 3, 3, 3, 3, ,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 11, 10, 10, 9, 8, 8, 7, 7, 6, 6, # n = 34
5, 5, 5, 4, 4, 4, 3, 3, 3, 2,
, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 11, 11, 10, 9, 9, 8, 8, 7, 7, 6, # n = 35
6, 5, 5, 5, 4, 4, 4, 3, 3, 3,
2, , , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 12, 11, 10, 10, 9, 9, 8, 8, 7, 7, # n = 36
6, 6, 5, 5, 5, 4, 4, 4, 3, 3,
3, 2, , , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 12, 11, 11, 10, 9, 9, 8, 8, 7, 7, # n = 37
6, 6, 6, 5, 5, 4, 4, 4, 4, 3,
3, 3, 2, , , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 13, 12, 11, 10, 10, 9, 9, 8, 8, 7, # n = 38
7, 6, 6, 6, 5, 5, 4, 4, 4, 3,
3, 3, 3, 2, , , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 13, 12, 12, 11, 10, 10, 9, 9, 8, 8, # n = 39
7, 7, 6, 6, 5, 5, 5, 4, 4, 4,
3, 3, 3, 3, 2, , , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 14, 13, 12, 11, 11, 10, 9, 9, 8, 8, # n = 40
7, 7, 7, 6, 6, 5, 5, 5, 4, 4,
4, 3, 3, 3, 3, 2, , , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 14, 13, 12, 12, 11, 10, 10, 9, 9, 8, # n = 41
8, 7, 7, 6, 6, 6, 5, 5, 5, 4,
4, 4, 3, 3, 3, 3, 2, , , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 14, 14, 13, 12, 11, 11, 10, 10, 9, 9, # n = 42
8, 8, 7, 7, 6, 6, 6, 5, 5, 5,
4, 4, 4, 3, 3, 3, 3, 2, , ,
, , , , , , , , , ,
, , , , , , , , ],
[ 15, 14, 13, 12, 12, 11, 10, 10, 9, 9, # n = 43
8, 8, 7, 7, 7, 6, 6, 6, 5, 5,
5, 4, 4, 4, 3, 3, 3, 3, 2, ,
, , , , , , , , , ,
, , , , , , , , ],
[ 15, 14, 14, 13, 12, 11, 11, 10, 10, 9, # n = 44
9, 8, 8, 7, 7, 7, 6, 6, 5, 5,
5, 4, 4, 4, 4, 3, 3, 3, 3, ,
, , , , , , , , , ,
, , , , , , , , ],
[ 16, 15, 14, 13, 12, 12, 11, 11, 10, 10, # n = 45
9, 9, 8, 8, 7, 7, 7, 6, 6, 5,
5, 5, 4, 4, 4, 4, 3, 3, 3, 3,
, , , , , , , , , ,
, , , , , , , , ],
[ 16, 15, 14, 14, 13, 12, 12, 11, 11, 10, # n = 46
9, 9, 8, 8, 8, 7, 7, 6, 6, 6,
5, 5, 5, 4, 4, 4, 4, 3, 3, 3,
3, , , , , , , , , ,
, , , , , , , , ],
[ 16, 16, 15, 14, 13, 13, 12, 11, 11, 10, # n = 47
10, 9, 9, 8, 8, 8, 7, 7, 6, 6,
6, 5, 5, 5, 4, 4, 4, 3, 3, 3,
3, 2, , , , , , , , ,
, , , , , , , , ],
[ 17, 16, 15, 14, 14, 13, 12, 12, 11, 11, # n = 48
10, 10, 9, 9, 8, 8, 7, 7, 7, 6,
6, 6, 5, 5, 5, 4, 4, 4, 3, 3,
3, 3, 2, , , , , , , ,
, , , , , , , , ],
[ 17, 16, 16, 15, 14, 13, 13, 12, 12, 11, # n = 49
11, 10, 9, 9, 9, 8, 8, 7, 7, 7,
6, 6, 6, 5, 5, 5, 4, 4, 4, 3,
3, 3, 3, 2, , , , , , ,
, , , , , , , , ],
[ 18, 17, 16, 15, 14, 14, 13, 13, 12, 11, # n = 50
11, 10, 10, 9, 9, 8, 8, 8, 7, 7,
7, 6, 6, 6, 5, 5, 5, 4, 4, 4,
3, 3, 3, 3, 2, , , , , ,
, , , , , , , , ],
[ 18, 17, 16, 16, 15, 14, 13, 13, 12, 12, # n = 51
11, 11, 10, 10, 9, 9, 8, 8, 8, 7,
7, 6, 6, 6, 5, 5, 5, 5, 4, 4,
4, 3, 3, 3, 3, 2, , , , ,
, , , , , , , , ],
[ 19, 18, 17, 16, 15, 15, 14, 13, 13, 12, # n = 52
12, 11, 11, 10, 10, 9, 9, 8, 8, 8,
7, 7, 6, 6, 6, 5, 5, 5, 5, 4,
4, 4, 3, 3, 3, 3, 2, , , ,
, , , , , , , , ],
[ 19, 18, 17, 16, 16, 15, 14, 14, 13, 12, # n = 53
12, 11, 11, 10, 10, 9, 9, 9, 8, 8,
7, 7, 7, 6, 6, 6, 5, 5, 5, 4,
4, 4, 4, 3, 3, 3, 3, 2, , ,
, , , , , , , , ],
[ 19, 18, 18, 17, 16, 15, 15, 14, 13, 13, # n = 54
12, 12, 11, 11, 10, 10, 9, 9, 9, 8,
8, 7, 7, 7, 6, 6, 6, 5, 5, 5,
4, 4, 4, 4, 3, 3, 3, 3, 2, ,
, , , , , , , , ],
[ 20, 19, 18, 17, 16, 16, 15, 14, 14, 13, # n = 55
13, 12, 12, 11, 11, 10, 10, 9, 9, 8,
8, 8, 7, 7, 7, 6, 6, 6, 5, 5,
5, 4, 4, 4, 4, 3, 3, 3, 3, 2,
, , , , , , , , ],
[ 20, 19, 18, 18, 17, 16, 15, 15, 14, 14, # n = 56
13, 12, 12, 11, 11, 10, 10, 10, 9, 9,
8, 8, 8, 7, 7, 7, 6, 6, 6, 5,
5, 5, 4, 4, 4, 4, 3, 3, 3, 3,
2, , , , , , , , ],
[ 21, 20, 19, 18, 17, 16, 16, 15, 14, 14, # n = 57
13, 13, 12, 12, 11, 11, 10, 10, 9, 9,
9, 8, 8, 7, 7, 7, 6, 6, 6, 5,
5, 5, 5, 4, 4, 4, 4, 3, 3, 3,
3, 2, , , , , , , ],
[ 21, 20, 19, 18, 18, 17, 16, 15, 15, 14, # n = 58
14, 13, 13, 12, 12, 11, 11, 10, 10, 9,
9, 9, 8, 8, 7, 7, 7, 6, 6, 6,
5, 5, 5, 5, 4, 4, 4, 4, 3, 3,
3, 3, 2, , , , , , ],
[ 22, 21, 20, 19, 18, 17, 17, 16, 15, 15, # n = 59
14, 14, 13, 12, 12, 11, 11, 11, 10, 10,
9, 9, 8, 8, 8, 7, 7, 7, 6, 6,
6, 5, 5, 5, 5, 4, 4, 4, 4, 3,
3, 3, 3, 2, , , , , ],
[ 22, 21, 20, 19, 18, 18, 17, 16, 16, 15, # n = 60
14, 14, 13, 13, 12, 12, 11, 11, 10, 10,
10, 9, 9, 8, 8, 8, 7, 7, 7, 6,
6, 6, 5, 5, 5, 5, 4, 4, 4, 3,
3, 3, 3, 3, 2, , , , ],
[ 23, 21, 20, 20, 19, 18, 17, 17, 16, 15, # n = 61
15, 14, 14, 13, 13, 12, 12, 11, 11, 10,
10, 10, 9, 9, 8, 8, 8, 7, 7, 7,
6, 6, 6, 5, 5, 5, 5, 4, 4, 4,
3, 3, 3, 3, 3, 2, , , ],
[ 23, 22, 21, 20, 19, 18, 18, 17, 16, 16, # n = 62
15, 15, 14, 14, 13, 12, 12, 12, 11, 11,
10, 10, 9, 9, 9, 8, 8, 8, 7, 7,
7, 6, 6, 6, 5, 5, 5, 4, 4, 4,
4, 3, 3, 3, 3, 3, 2, , ],
[ 23, 22, 21, 20, 20, 19, 18, 17, 17, 16, # n = 63
16, 15, 14, 14, 13, 13, 12, 12, 11, 11,
11, 10, 10, 9, 9, 9, 8, 8, 7, 7,
7, 6, 6, 6, 6, 5, 5, 5, 4, 4,
4, 4, 3, 3, 3, 3, 3, 2, ],
[ 24, 23, 22, 21, 20, 19, 18, 18, 17, 16, # n = 64
16, 15, 15, 14, 14, 13, 13, 12, 12, 11,
11, 10, 10, 10, 9, 9, 8, 8, 8, 7,
7, 7, 6, 6, 6, 6, 5, 5, 5, 4,
4, 4, 4, 3, 3, 3, 3, 3, 2 ]
];
########################################################################
##
#F GeneralLowerBoundCoveringRadius( <n>, <size> [, <F> ] )
## GeneralLowerBoundCoveringRadius( <code> )
##
InstallMethod(GeneralLowerBoundCoveringRadius, "unrestricted code", true,
[IsCode], 0,
function(code)
local n, size, field, listofbounds, max;
if IsLinearCode(code) then
return GeneralLowerBoundCoveringRadius(code);
fi;
n := WordLength( code );
size := Size( code );
field := LeftActingDomain( code );
listofbounds := [
LowerBoundCoveringRadiusSphereCovering( n, size, field, false ),
];
if field = GF(2) then
Append( listofbounds, [
LowerBoundCoveringRadiusVanWee1( n, size, field, false ),
LowerBoundCoveringRadiusVanWee2( n, size, false ),
LowerBoundCoveringRadiusCountingExcess( n, size, false )
] );
if n <= 200 then
Append( listofbounds, [
LowerBoundCoveringRadiusEmbedded1( n, size, field, false ),
LowerBoundCoveringRadiusEmbedded2( n, size, field, false )
] );
fi;
fi;
max := Maximum( listofbounds );
if IsBound(code!.boundsCoveringRadius) then
return Maximum ([ max, code!.boundsCoveringRadius[1] ]);
else
return max;
fi;
end);
InstallMethod(GeneralLowerBoundCoveringRadius, "linear code", true,
[IsLinearCode], 0,
function (code)
local n, size, field, k, listofbounds, return_value;
n := WordLength(code);
size := Size(code);
field := LeftActingDomain(code);
listofbounds := [
LowerBoundCoveringRadiusSphereCovering( n, size, field, false ),
];
return_value := -99; # Allows to check whether next set of if
# statements actually assign a value
if field = GF(2) then
k := Dimension( code );
# small codimensions (n-k)
if k = n then
return_value := 0;
elif k = n - 1 then
return_value := 1;
elif k = n - 2 then
return_value := 1;
elif k = n - 3 and n >= 7 then
return_value := 1;
elif k = n - 4 and n >= 5 then
if n >= 15 then
return_value := 1;
else
return_value := 2;
fi;
elif k = n - 5 and n >= 9 then
if n >= 31 then
return_value := 1;
else
return_value := 2;
fi;
elif k = n - 6 then
if n >= 63 then
return_value := 1;
elif n >= 14 then
return_value := 2;
elif n = 12 then
return_value := 3;
fi;
elif k = n - 7 and n >= 21 and n <= 64 then
return_value := 2;
elif k = n - 8 and n >= 30 and n <= 64 then
return_value := 2;
elif k = n - 9 and n >= 44 and n <= 64 then
return_value := 2;
elif k = 1 then
return_value := IntFloor( n/2 );
elif k = 2 then
return_value := IntFloor( (n-1)/2 );
elif k = 3 then
return_value := IntFloor( (n-2)/2 );
elif k = 4 then
return_value := IntFloor( (n-4)/2 );
elif k = 5 then
return_value := IntFloor( (n-5)/2 );
fi;
# use the table of Cohen, Litsyn, Lobstein and Mattson
if return_value < 0 and n >= 13 and n <= 64 and k>=6 and k<= 64 then
if IsBound(
CoveringRadiusLowerBoundTable[ n - 12 ][ k - 5 ] ) then
return_value :=
CoveringRadiusLowerBoundTable[ n - 12 ][ k - 5 ];
fi;
fi;
if return_value < 0 then
# not in the table. use the bounds
listofbounds := [
LowerBoundCoveringRadiusSphereCovering( n, size, field, false ),
LowerBoundCoveringRadiusVanWee1( n, size, field, false ),
LowerBoundCoveringRadiusVanWee2( n, size, false ),
LowerBoundCoveringRadiusCountingExcess( n, size, false )
];
if n <= 200 then
Append( listofbounds, [
LowerBoundCoveringRadiusEmbedded1( n, size, field, false ),
LowerBoundCoveringRadiusEmbedded2( n, size, field, false ),
] );
fi;
return_value := Maximum( listofbounds );
fi;
else # field is not GF(2)
listofbounds := [
LowerBoundCoveringRadiusSphereCovering( n, size, field, false ),
];
return_value := Maximum( listofbounds );
fi;
if IsBound(code!.boundsCoveringRadius) then
return Maximum([return_value, code!.boundsCoveringRadius[1]]);
else
return return_value;
fi;
end);
InstallOtherMethod(GeneralLowerBoundCoveringRadius, "n, k, field", true,
[IsInt, IsInt, IsField], 0,
function(n, size, field)
local listofbounds;
if n < 1 or size < 1 then
Error("GeneralLBCR: <n> and <size> must be positive");
fi;
listofbounds := [
LowerBoundCoveringRadiusSphereCovering( n, size, field, false ),
LowerBoundCoveringRadiusVanWee1( n, size, field, false ),
LowerBoundCoveringRadiusEmbedded1( n, size, field, false ),
LowerBoundCoveringRadiusEmbedded2( n, size, field, false )
];
if field = GF(2) then
Append( listofbounds, [
LowerBoundCoveringRadiusVanWee2( n, size, false ),
LowerBoundCoveringRadiusCountingExcess( n, size, false )
] );
fi;
return Maximum( listofbounds );
end);
InstallOtherMethod(GeneralLowerBoundCoveringRadius, "n, size", true,
[IsInt, IsInt], 0,
function(n, size)
return GeneralLowerBoundCoveringRadius(n, size, GF(2));
end);
########################################################################
##
#F LowerBoundCoveringRadiusSphereCovering( <n>, <r> [, <F> ] [, true ] )
##
InstallMethod(LowerBoundCoveringRadiusSphereCovering,
"n, r, fieldsize, usage",
true, [IsInt, IsInt, IsInt, IsBool], 0,
function(n, r, q, usage)
local m, lb, ub, tmpcr, tmpsize, t;
if n <= 0 then
Error("LBCRSphereCovering: <n> must be positive");
fi;
if usage = false then
# last argument is false, try to find a lower bound for
# the covering radius, given length and size of the code, and field
m := r;
if m <= 0 or m > q^n then
Error( "LBCRSphereCovering: <m> must be > 0 and <= q^n" );
fi;
# everything is set up. now compute the bound
lb := 0;
ub := n;
while lb <> ub do
tmpcr := IntFloor( ( lb + ub ) / 2 );
tmpsize := IntCeiling( q^n / SphereContent( n, tmpcr, q ) );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
od;
return ub;
else
# the last argument is not false
# now it is assumed that the first argument is the length
# of the code and the second argument is the covering radius
# of the code. a lower bound for the minimal size of the
# code is returned
t := r;
if t < 0 or t > n then
Error( "LBCRSphereCovering: <t> must be >= 0 and <= <n>" );
fi;
return IntCeiling( q^n / SphereContent( n, t, q ) );
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusSphereCovering,
"n, r, field, usage", true,
[IsInt, IsInt, IsField, IsBool], 0,
function(n, r, F, usage)
if not IsFinite(F) then
Error("LBCRSphereCovering: <F> must be a finite field");
else
return LowerBoundCoveringRadiusSphereCovering(n, r, Size(F), usage);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusSphereCovering,
"n, r, fieldsize", true, [IsInt, IsInt, IsInt], 0,
function(n, r, q)
return LowerBoundCoveringRadiusSphereCovering(n, r, q, true);
end);
InstallOtherMethod(LowerBoundCoveringRadiusSphereCovering,
"n, r, field", true, [IsInt, IsInt, IsField], 0,
function(n, r, F)
if not IsFinite(F) then
Error("LBCRSphereCovering: <F> must be a finite field");
else
return LowerBoundCoveringRadiusSphereCovering(n, r, Size(F), true);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusSphereCovering,
"n, r, usage", true, [IsInt, IsInt, IsBool], 0,
function(n, r, usage)
return LowerBoundCoveringRadiusSphereCovering(n, r, 2, usage);
end);
InstallOtherMethod(LowerBoundCoveringRadiusSphereCovering, "n, r", true,
[IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusSphereCovering(n, r, 2, true);
end);
########################################################################
##
#F LowerBoundCoveringRadiusVanWee1( ... )
##
InstallMethod(LowerBoundCoveringRadiusVanWee1,
"n, r, fieldsize, usage", true, [IsInt, IsInt, IsInt, IsBool], 0,
function(n, r, q, usage)
local m, lb, ub, tmpcr, tmpsize, t, tmp;
if n <= 0 then
Error("LBCRVanWee1: <n> must be positive");
fi;
if usage = false then
# last argument is false, try to find a lower bound for
# the covering radius, given length and size of the code, and field
m := r;
if m <= 0 or m > q^n then
Error( "LBCRVanWee1: <m> must be > 0 and <= q^n" );
fi;
# everything is set up. now compute the bound
lb := 0;
ub := n;
while lb <> ub do
tmpcr := IntFloor( (ub+lb) / 2 );
tmpsize := LowerBoundCoveringRadiusVanWee1( n, tmpcr, q );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
od;
return ub;
else
# the last argument is not false
# now it is assumed that the first argument is the length
# of the code and the second argument is the covering radius
# of the code. a lower bound for the minimal size of the
# code is returned
t := r;
if t < 0 or t > n then
Error( "LBCRVanWee1: <t> must be >= 0 and <= <n>" );
fi;
if t = n then
return 1;
fi;
tmp := (Binomial(n,t))/(IntCeiling((n-t)/(t+1)));
tmp := tmp * (IntCeiling((t+1)/(t+1)) - (t+1)/(t+1));
tmp := SphereContent( n, t, q ) - tmp;
return IntCeiling( q^n / tmp );
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee1,
"n, r, field, usage", true, [IsInt, IsInt, IsField, IsBool], 0,
function(n, r, F, usage)
if not IsFinite(F) then
Error("LBCRVanWee1: <F> must be a finite field");
else
return LowerBoundCoveringRadiusVanWee1(n, r, Size(F), usage);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee1, "n,r,fieldsize",
true, [IsInt, IsInt, IsInt], 0,
function(n, r, q)
return LowerBoundCoveringRadiusVanWee1(n, r, q, true);
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee1, "n, r, field",
true, [IsInt, IsInt, IsField], 0,
function(n, r, F)
if not IsFinite(F) then
Error("LBCRVanWee1: <F> must be a finite field");
else
return LowerBoundCoveringRadiusVanWee1(n, r, Size(F), true);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee1,
"n, r, usage", true, [IsInt, IsInt, IsBool], 0,
function(n, r, usage)
return LowerBoundCoveringRadiusVanWee1(n, r, 2, usage);
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee1,
"n, r", true, [IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusVanWee1(n, r, 2, true);
end);
#############################################################################
##
#F LowerBoundCoveringRadiusVanWee2( <n>, <r> ) Counting Excess bound
##
InstallMethod(LowerBoundCoveringRadiusVanWee2,
"code length, code size or covering radius, usage",
true, [IsInt, IsInt, IsBool], 0,
function(n, r, usage)
local m, lb, ub, tmpcr, eps, tmpsize, t, tmpb1, tmpb2;
if n<=0 then
Error( "LBCRVanWee2: <n> must be positive" );
fi;
if usage = false then
m := r;
if m <= 0 or m > 2^n then
Error( "LBCRVanWee2: <m> must be > 0 and <= 2^n" );
fi;
lb := 0;
ub := IntFloor( n/2 );
while lb <> ub do
tmpcr := IntFloor( ( ub + lb ) / 2 );
tmpb1 := (tmpcr+2)*(tmpcr+1)/2; # Binomial(tmpcr+2,2)
tmpb2 := (n-tmpcr+1)*(n-tmpcr)/2; # Binomial(n-tmpcr+1,2)
eps := tmpb1 * IntCeiling( tmpb2/tmpb1 ) - tmpb2;
tmpsize := 2^n * ( SphereContent( n, 2, 2 ) + eps
- 1/2*( tmpcr + 2 )*( tmpcr - 1 ) );
tmpsize := tmpsize / ( SphereContent( n, tmpcr, 2 ) *
( SphereContent( n, 2, 2 )
- 1/2*( tmpcr + 2 )*( tmpcr - 1 ) )
+ eps * SphereContent( n, tmpcr - 2 ) );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
od;
return ub;
else
t := r;
if t < 0 or t > n then
Error( "LBCRVanWee2: <t> must be >= 0 and <= <n>" );
fi;
if 2 * t > n then
return 0;
fi;
tmpb1 := (t+2)*(t+1)/2;
tmpb2 := (n-t+1)*(n-t)/2;
eps := tmpb1 * IntCeiling( tmpb2/tmpb1 ) - tmpb2;
tmpsize := 2^n * ( SphereContent( n, 2, 2 ) + eps
- 1/2*( t + 2 )*( t - 1 ) );
tmpsize := tmpsize / ( SphereContent( n, t, 2 )
* ( SphereContent( n, 2, 2 )
- 1/2*( t + 2 )*( t - 1 ) )
+ eps * SphereContent( n, t-2, 2 ) );
return IntCeiling(tmpsize);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusVanWee2,
"code length, code covering radius",
true, [IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusVanWee2(n, r, true);
end);
#############################################################################
##
#F LowerBoundCoveringRadiusCountingExcess( <n>, <r> )
##
InstallMethod(LowerBoundCoveringRadiusCountingExcess,
"code length, code size or covering radius, usage", true,
[IsInt, IsInt, IsBool], 0,
function(n, r, usage)
local m, lb, ub, tmpcr, tmpsize, t, rho, eps;
if n<=0 then
Error( "LBCRCountingExcess: <n> must be positive" );
fi;
if usage = false then
m := r;
if m<=0 or m > 2^n then
Error( "LBCRCountingExcess: <m> must be > 0 and <= 2^n" );
fi;
lb := 0;
ub := IntFloor( ( n-1 ) / 2 );
while lb <> ub do
tmpcr := IntFloor( ( ub + lb ) / 2 );
tmpsize := LowerBoundCoveringRadiusCountingExcess(
n, tmpcr, true );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
od;
return ub;
else
t := r;
if t < 0 or t > n then
Error( "LBCRCountingExcess: <t> must be >=0 and <= <n>" );
fi;
if t < 2 or 2 * t + 1 > n then
return 0;
fi;
if t = 2 then
rho := n - 3 + 2/n;
else
rho := n - t - 1;
fi;
eps := ( t+1 ) * IntCeiling( ( n+1 ) / ( t+1 ) ) - ( n+1 );
if eps > t then
return 0;
fi;
tmpsize := 2^n * ( rho + eps );
tmpsize := tmpsize / ( rho * SphereContent( n, t )
+ eps * SphereContent( n, t-1 ) );
return IntCeiling( tmpsize );
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusCountingExcess,
"code length, code covering radius", true,
[IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusCountingExcess(n, r, true);
end);
########################################################################
##
#F LowerBoundCoveringRadiusEmbedded1( <n>, <r> [, <givesize> ] )
##
InstallMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code size or covering radius, field size, usage",
true, [IsInt, IsInt, IsInt, IsBool], 0,
function(n, r, q, usage)
local m, lb, ub, tmpcr, tmpsize, t, upperb;
if n <= 0 then
Error("LBCREmbedded1: <n> must be positive");
fi;
if usage = false then
# last argument is false, try to find a lower bound for
# the covering radius, given length and size of the code, and field
m := r;
if m <= 0 or m > q^n then
Error( "LBCREmbedded1: <m> must be > 0 and <= q^n" );
fi;
# everything is set up. now compute the bound
if m = q^n then
return 0;
fi;
if n = 1 then
return 0;
fi;
lb := 1;
ub := n;
while lb <> ub do
tmpcr := IntFloor( (ub+lb) / 2 );
tmpsize := SphereContent( n, tmpcr, q )
- Binomial( 2*tmpcr, tmpcr );
if tmpsize = 0 then
lb := lb + 1;
elif tmpsize < 0 then
ub := tmpcr;
else
if 2*tmpcr+1 > n then
upperb := 1;
else
upperb := UpperBound( n, 2*tmpcr+1, q );
fi;
tmpsize := IntCeiling( ( q^n - upperb
* Binomial( 2 * tmpcr, tmpcr ) )
/ tmpsize );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
fi;
od;
return ub;
else
# the last argument is not false
# now it is assumed that the first argument is the length
# of the code and the second argument is the covering radius
# of the code. a lower bound for the minimal size of the
# code is returned
t := r;
if t < 0 or t > n then
Error( "LBCREmbedded1: <t> must be >= 0 and <= <n>" );
fi;
tmpsize := SphereContent( n, t, q ) - Binomial( 2*t, t );
if tmpsize <= 0 then
return 0;
else
if 2 * t + 1 > n then
upperb := 1;
else
upperb := UpperBound( n, 2*t+1, q );
fi;
return IntCeiling( ( q^n - upperb
* Binomial( 2*t, t ) ) / tmpsize );
fi;
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code size or covering radius, field, usage",
true, [IsInt, IsInt, IsField, IsBool], 0,
function(n, r, F, usage)
if not IsFinite(F) then
Error("LBCREmbedded1: <F> must be a finite field");
else
return LowerBoundCoveringRadiusEmbedded1(n, r, Size(F), usage);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code size or covering radius, usage",
true, [IsInt, IsInt, IsBool], 0,
function(n, r, usage)
return LowerBoundCoveringRadiusEmbedded1(n, r, 2, usage);
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code covering radius, field size", true,
[IsInt, IsInt, IsInt], 0,
function(n, r, q)
return LowerBoundCoveringRadiusEmbedded1(n, r, q, true);
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code covering radius, field", true,
[IsInt, IsInt, IsField], 0,
function(n, r, F)
if not IsFinite(F) then
Error("LBCREmbedded1: <F> must be a finite field");
else
return LowerBoundCoveringRadiusEmbedded1(n, r, Size(F), true);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded1,
"code length, code covering radius", true, [IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusEmbedded1(n, r, 2, true);
end);
########################################################################
##
#F LowerBoundCoveringRadiusEmbedded2( <n>, <r> [, <givesize> ] )
##
InstallMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code size or covering radius, field size, usage",
true, [IsInt, IsInt, IsInt, IsBool], 0,
function(n, r, q, usage)
local m, lb, ub, tmpcr, tmpsize, t, upperb;
if n <= 0 then
Error("LBCREmbedded2: <n> must be positive");
fi;
if usage = false then
# last argument is false, try to find a lower bound for
# the covering radius, given length and size of the code, and field
m := r;
if m <= 0 or m > q^n then
Error( "LBCREmbedded2: <m> must be > 0 and <= q^n" );
fi;
# everything is set up. now compute the bound
if m = q^n then
return 0;
fi;
if n = 1 or n = 2 then
return 0;
fi;
lb := 1;
ub := n;
while lb <> ub do
tmpcr := IntFloor( (ub+lb) / 2 );
tmpsize := SphereContent( n, tmpcr, q )
- 3/2 * Binomial( 2*tmpcr, tmpcr );
if tmpsize = -1/2 then
lb := lb + 1;
elif tmpsize <= 0 then
ub := tmpcr;
else
if 2*tmpcr+1 > n then
upperb := 1;
else
upperb := UpperBound( n, 2*tmpcr+1, q );
fi;
tmpsize := IntCeiling( ( q^n - 2 * upperb
* Binomial( 2*tmpcr, tmpcr ) )
/ tmpsize );
if tmpsize > m then
lb := tmpcr + 1;
else
ub := tmpcr;
fi;
fi;
od;
return ub;
else
# the last argument is not false
# now it is assumed that the first argument is the length
# of the code and the second argument is the covering radius
# of the code. a lower bound for the minimal size of the
# code is returned
t := r;
if t < 0 or t > n then
Error( "LBCREmbedded2: <t> must be >= 0 and <= <n>" );
fi;
tmpsize := SphereContent( n, t, q ) - 3/2*Binomial( 2*t, t );
if tmpsize <= 0 then
return 0;
else
if 2*t+1 > n then
upperb := 1;
else
upperb := UpperBound( n, 2*t+1, q );
fi;
return IntCeiling( ( q^n - 2*upperb
* Binomial( 2*t, t ) ) / tmpsize );
fi;
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code size or covering radius, field, usage",
true, [IsInt, IsInt, IsField, IsBool], 0,
function(n, r, F, usage)
if not IsFinite(F) then
Error("LBCREmbedded2: <F> must be a finite field");
else
return LowerBoundCoveringRadiusEmbedded2(n, r, Size(F), usage);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code size or covering radius, usage",
true, [IsInt, IsInt, IsBool], 0,
function(n, r, usage)
return LowerBoundCoveringRadiusEmbedded2(n, r, 2, usage);
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code covering radius, field size",
true, [IsInt, IsInt, IsInt], 0,
function(n, r, q)
return LowerBoundCoveringRadiusEmbedded2(n, r, q, true);
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code covering radius, field",
true, [IsInt, IsInt, IsField], 0,
function(n, r, F)
if not IsFinite(F) then
Error("LBCREmbedded2: <F> must be a finite field");
else
return LowerBoundCoveringRadiusEmbedded2(n, r, Size(F), true);
fi;
end);
InstallOtherMethod(LowerBoundCoveringRadiusEmbedded2,
"code length, code covering radius",
true, [IsInt, IsInt], 0,
function(n, r)
return LowerBoundCoveringRadiusEmbedded2(n, r, 2, true);
end);
#############################################################################
##
#F LowerBoundCoveringRadiusInduction( <n>, <r> ) Induction bound
##
InstallMethod(LowerBoundCoveringRadiusInduction,
"method for two integers", true, [IsInt, IsInt], 0,
function(n, t)
if n <= 0 then
Error( "LBCRInduction: <n> must be positive" );
fi;
if t < 0 or t > n then
Error( "LBCRInduction: <t> must be >= 0 and <= <n>" );
fi;
if n = 2 * t + 2 and t >= 1 then
return 4;
elif n = 2 * t + 3 and t >= 1 then
return 7;
elif n = 2 * t + 4 and t >= 4 then
return 8;
else
return 0;
fi;
end);
########################################################################
##
#F GeneralUpperBoundCoveringRadius( <code> )
##
InstallMethod(GeneralUpperBoundCoveringRadius, "unrestricted code", true,
[IsCode], 0,
function(code)
local listofbounds;
listofbounds := [ UpperBoundCoveringRadiusStrength( code ) ];
if WordLength( code ) <= 100 then
Append( listofbounds, [
UpperBoundCoveringRadiusDelsarte( code )
] );
fi;
if IsLinearCode( code ) then
Append( listofbounds, [
UpperBoundCoveringRadiusRedundancy( code ),
] );
if LeftActingDomain( code ) = GF(2) then
if ( IsBound( code!.lowerBoundMinimumDistance ) and
IsBound( code!.upperBoundMinimumDistance ) ) and
LowerBoundMinimumDistance( code ) =
UpperBoundMinimumDistance (code )
then
Append( listofbounds, [
UpperBoundCoveringRadiusGriesmerLike( code )
] );
fi;
fi;
fi;
if IsCyclicCode( code ) and LeftActingDomain( code ) = GF(2) then
Append( listofbounds, [
UpperBoundCoveringRadiusCyclicCode( code )
] );
fi;
if IsBound( code!.boundsCoveringRadius ) then
Add( listofbounds, Maximum( code!.boundsCoveringRadius ) );
fi;
return Minimum( listofbounds );
end);
########################################################################
##
#F UpperBoundCoveringRadiusRedundancy( <code> )
##
## Return the redundancy of the code as an upper bound for
## the covering radius.
##
## Only for linear codes.
##
InstallMethod(UpperBoundCoveringRadiusRedundancy, "unrestricted code", true,
[IsCode], 0,
function( code )
if IsLinearCode( code ) then
return UpperBoundCoveringRadiusRedundancy( code );
else
Error("UBCRRedundancy: <code> must be a linear code");
fi;
end);
InstallMethod(UpperBoundCoveringRadiusRedundancy, "linear code", true,
[IsLinearCode], 0,
function( code)
return Redundancy(code);
end);
########################################################################
##
#F UpperBoundCoveringRadiusDelsarte( <code> )
##
InstallMethod(UpperBoundCoveringRadiusDelsarte, "method for unrestricted codes", true, [IsCode], 0,
function(code)
local p;
p := CodeMacWilliamsTransform(code);
p := CoefficientsOfLaurentPolynomial(p);
p := ShiftedCoeffs(p[1], p[2]);
return WeightVector(p) - 1;
end);
InstallMethod(UpperBoundCoveringRadiusDelsarte, "method for linear codes",
true, [IsLinearCode], 0,
function(code)
local dual, wddual;
if not IsBound(code!.boundsCoveringRadius) then
# avoid recursion
code!.boundsCoveringRadius := [ 0 .. WordLength( code ) ];
fi;
dual := DualCode( code );
wddual := WeightDistribution( dual );
return WeightVector( wddual ) - 1;
end);
########################################################################
##
#F UpperBoundCoveringRadiusStrength( <code> )
##
## Return (q-1)n/q as an upper bound for <code>, if it
## has strength 1 (i.e. every coordinate contains each element
## of the field the same number of times).
##
InstallMethod(UpperBoundCoveringRadiusStrength, "method for unrestricted codes", true, [IsCode], 0,
function(code)
local q, n, stris1, i, j, els, fieldels, coordlist, number, zerocols;
if IsLinearCode(code) then
return UpperBoundCoveringRadiusStrength(code);
fi;
q := Size( LeftActingDomain( code ) );
n := WordLength( code );
stris1 := true;
i := 1;
els := VectorCodeword( AsSSortedList( code ) );
if not ( Length( els ) in List( [ 1 .. n ], x -> q^x ) ) then
stris1 := false;
fi;
fieldels := AsSSortedList(LeftActingDomain( code ) );
zerocols := 0;
while stris1 and i <= n do
coordlist := List( els, x -> x[ i ] );
for j in fieldels do
number := Length( Filtered( coordlist, x -> x = j ) );
if number = Length( els ) then
zerocols := zerocols + 1;
elif number <> Length( els ) / q then
stris1 := false;
fi;
od;
i := i + 1;
od;
if stris1 then
return IntFloor((q-1)*(n-zerocols)/q)+zerocols;
else
return n;
fi;
end);
InstallMethod(UpperBoundCoveringRadiusStrength, "method for linear code",
true, [IsLinearCode], 0,
function(code)
local q, zerocols, i, j, genmat, n, k, zero, onlyzeroes;
if Dimension(code) = 0 then
return WordLength(code);
fi;
q := Size(LeftActingDomain(code));
genmat := GeneratorMat( code );
n := WordLength( code );
k := Dimension( code );
zerocols := 0;
zero := Zero(LeftActingDomain(code));
for i in [ 1 .. n ] do
onlyzeroes := true;
j := 1;
while onlyzeroes and j <= k do
onlyzeroes := ( genmat[ j ][ i ] = zero );
j := j + 1;
od;
if onlyzeroes then
zerocols := zerocols + 1;
fi;
od;
return IntFloor((q-1)*(n-zerocols)/q) + zerocols;
end);
########################################################################
##
#F UpperBoundCoveringRadiusGriesmerLike( <code> )
##
InstallMethod(UpperBoundCoveringRadiusGriesmerLike, "unrestrictred code",
true, [IsCode], 0,
function( code )
if IsLinearCode( code ) then
return UpperBoundCoveringRadiusGriesmerLike(code);
else
Error("UBCRGriesmerLike: <code> must be a linear code");
fi;
end);
InstallMethod(UpperBoundCoveringRadiusGriesmerLike, "linear codes", true,
[IsLinearCode], 0,
function(code)
local q;
q := Size( LeftActingDomain( code ) );
return WordLength( code ) - Sum( [ 1 .. Dimension( code ) ],
x -> IntCeiling( MinimumDistance( code ) / q^x ) );
end);
########################################################################
##
#F UpperBoundCoveringRadiusCyclicCode( <code> )
##
InstallMethod(UpperBoundCoveringRadiusCyclicCode, "unrestricted code",
true, [IsCode], 0,
function( code )
if IsCyclicCode( code ) then
return UpperBoundCoveringRadiusCyclicCode( code );
else
Error("UBCRCyclicCode: <code> must be a cyclic code");
fi;
end);
InstallMethod(UpperBoundCoveringRadiusCyclicCode, "cyclic codes", true,
[IsCyclicCode], 0,
function(code)
return WordLength( code ) - Dimension( code ) + 1 -
IntCeiling( Weight( Codeword( GeneratorPol( code ) ) ) / 2 );
end);
|