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
|
############################################################################
##
#W vec8bit.gi GAP Library Steve Linton
##
#H @(#)$Id: vec8bit.gi,v 4.46 2002/06/10 19:39:39 gap Exp $
##
#Y Copyright (C) 1997, Lehrstuhl D fuer 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 mainly installs the kernel methods for 8 bit vectors
##
Revision.vec8bit_gi :=
"@(#)$Id: vec8bit.gi,v 4.46 2002/06/10 19:39:39 gap Exp $";
#############################################################################
##
#V `TYPES_VEC8BIT . . . . . . . . prepared types for compressed GF(q) vectors
##
## A length 2 list of length 257 lists. TYPES_VEC8BIT[1][q] will be the type
## of mutable vectors over GF(q), TYPES_VEC8BIT[2][q] is the type of
## immutable vectors and TYPES_VEC8BIT[3][q] the type of locked vectors
## The 257th position is bound to 1 to stop the lists
## shrinking.
##
## It is accessed directly by the kernel, so the format cannot be changed
## without changing the kernel.
##
InstallValue(TYPES_VEC8BIT , [[],[], [], []]);
TYPES_VEC8BIT[1][257] := 1;
TYPES_VEC8BIT[2][257] := 1;
TYPES_VEC8BIT[3][257] := 1;
TYPES_VEC8BIT[4][257] := 1;
#############################################################################
##
#F TYPE_VEC8BIT( <q>, <mut> ) . . computes type of compressed GF(q) vectors
##
## Normally called by the kernel, caches results in TYPES_VEC8BIT,
## which is directly accessed by the kernel
##
InstallGlobalFunction(TYPE_VEC8BIT,
function( q, mut)
local col,filts;
if mut then col := 1; else col := 2; fi;
if not IsBound(TYPES_VEC8BIT[col][q]) then
filts := IsHomogeneousList and IsListDefault and IsCopyable and
Is8BitVectorRep and IsSmallList and
IsNoImmediateMethodsObject and
IsRingElementList and HasLength;
if mut then filts := filts and IsMutable; fi;
TYPES_VEC8BIT[col][q] := NewType(FamilyObj(GF(q)),filts);
fi;
return TYPES_VEC8BIT[col][q];
end);
InstallGlobalFunction(TYPE_VEC8BIT_LOCKED,
function( q, mut)
local col,filts;
if mut then col := 3; else col := 4; fi;
if not IsBound(TYPES_VEC8BIT[col][q]) then
filts := IsHomogeneousList and IsListDefault and IsCopyable and
Is8BitVectorRep and IsSmallList and
IsNoImmediateMethodsObject and
IsLockedRepresentationVector and
IsRingElementList and HasLength;
if mut then filts := filts and IsMutable; fi;
TYPES_VEC8BIT[col][q] := NewType(FamilyObj(GF(q)),filts);
fi;
return TYPES_VEC8BIT[col][q];
end);
#############################################################################
##
#V TYPE_FIELDINFO_8BIT type of the fieldinfo bags
##
## These bags are created by the kernel and accessed by the kernel. The type
## doesn't really say anything, because there are no applicable operations.
##
InstallValue( TYPE_FIELDINFO_8BIT,
NewType(NewFamily("FieldInfo8BitFamily", IsObject),
IsObject and IsDataObjectRep));
#############################################################################
##
#M Length( <vec> )
##
InstallMethod( Length, "For a compressed VecFFE",
true, [IsList and Is8BitVectorRep], 0, LEN_VEC8BIT);
#############################################################################
##
#M <vec> [ <pos> ]
##
InstallMethod( \[\], "For a compressed VecFFE",
true, [IsList and Is8BitVectorRep, IsPosInt], 0, ELM_VEC8BIT);
#############################################################################
##
#M <vec> [ <pos> ] := <val>
##
## This may involve turning <vec> into a plain list, if <val> does
## not lie in the appropriate field.
##
## <vec> may also be converted back into vector rep over a bigger field.
##
InstallMethod( \[\]\:\=, "For a compressed VecFFE",
true, [IsMutable and IsList and Is8BitVectorRep, IsPosInt, IsObject],
0, ASS_VEC8BIT);
#############################################################################
##
#M Unbind( <vec> [ <pos> ] )
##
## Unless the last position is being unbound, this will result in <vec>
## turning into a plain list
##
InstallMethod( Unbind\[\], "For a compressed VecFFE",
true, [IsMutable and IsList and Is8BitVectorRep, IsPosInt],
0, UNB_VEC8BIT);
#############################################################################
##
#M ViewObj( <vec> )
##
## Up to length 10, GF(q) vectors are viewed in full, over that a
## description is printed
##
InstallMethod( ViewObj, "For a compressed VecFFE",
true, [Is8BitVectorRep and IsSmallList], 0,
function( vec )
local len;
len := LEN_VEC8BIT(vec);
if (len = 0 or len > 10) then
Print("< ");
if not IsMutable(vec) then
Print("im");
fi;
Print("mutable compressed vector length ",
LEN_VEC8BIT(vec)," over GF(",Q_VEC8BIT(vec),") >");
else
PrintObj(vec);
fi;
end);
#############################################################################
##
#M PrintObj( <vec> )
##
## Same method as for lists in internal rep.
##
InstallMethod( PrintObj, "For a compressed VecFFE",
true, [Is8BitVectorRep and IsSmallList], 0,
function( vec )
local i,l;
Print("\>\>[ \>\>");
l := Length(vec);
if l <> 0 then
PrintObj(vec[1]);
for i in [2..l] do
Print("\<,\<\>\> ");
PrintObj(vec[i]);
od;
fi;
Print(" \<\<\<\<]");
end);
#############################################################################
##
#M ShallowCopy(<vec>)
##
## kernel method produces a copy in the same representation
##
InstallMethod(ShallowCopy, "For a compressed VecFFE",
true, [Is8BitVectorRep and IsSmallList], 0,
SHALLOWCOPY_VEC8BIT);
#############################################################################
##
#M <vec1> + <vec2>
##
## The method installation enforced same
## characteristic. Compatability of fields and vector lengths is
## handled in the method
InstallMethod( \+, "For two 8 bit vectors in same characteristic",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep], 0,
SUM_VEC8BIT_VEC8BIT);
InstallMethod( \+, "For a GF2 vector and an 8 bit vector of char 2",
IsIdenticalObj, [IsRowVector and IsGF2VectorRep,
IsRowVector and Is8BitVectorRep], 0,
function(v,w)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return v+w;
fi;
end);
InstallMethod( \+, "For an 8 bit vector of char 2 and a GF2 vector",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and IsGF2VectorRep ], 0,
function(w,v)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return w+v;
fi;
end);
#############################################################################
##
#M `PlainListCopyOp( <vec> )
##
## Make the vector into a plain list (in place)
##
InstallMethod( PlainListCopyOp, "For an 8 bit vector",
true, [IsSmallList and Is8BitVectorRep], 0,
function (v)
PLAIN_VEC8BIT(v);
return v;
end);
#############################################################################
##
#M ELM0_LIST( <vec> )
##
## alternatibe element access interface, returns fail when unbound
##
InstallMethod(ELM0_LIST, "For an 8 bit vector",
true, [IsList and Is8BitVectorRep, IsPosInt], 0,
ELM0_VEC8BIT);
#############################################################################
##
#M DegreeFFE( <vector> )
##
BindGlobal("Q_TO_DEGREE", # discrete logarithm list
[0,1,1,2,1,0,1,3,2,0,1,0,1,0,0,4,1,0,1,0,0,0,1,0,2,0,3,0,1,0,1,5,0,0,0,0,
1,0,0,0,1,0,1,0,0,0,1,0,2,0,0,0,1,0,0,0,0,0,1,0,1,0,0,6,0,0,1,0,0,0,1,0,
1,0,0,0,0,0,1,0,4,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,
1,0,0,0,1,0,0,0,0,0,0,0,2,0,0,0,3,0,1,7,0,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,
0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,2,0,0,0,1,0,0,0,0,0,1,0,
1,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,
0,0,0,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,1,0,1,0,5,0,0,0,0,0,0,0,1,0,
0,0,0,8]);
InstallOtherMethod( DegreeFFE, "for 8 bit vectors", true,
[ IsRowVector and IsFFECollection and Is8BitVectorRep], 0,
function( vec )
local q, deg, i, maxdeg;
q:=Q_VEC8BIT(vec);
maxdeg:=Q_TO_DEGREE[q];
# the degree could be smaller. Check or prove.
if Length(vec) = 0 then
return 0;
fi;
deg := DegreeFFE( vec[1] );
for i in [ 2 .. Length( vec ) ] do
deg := LcmInt( deg, DegreeFFE( vec[i] ) );
if deg=maxdeg then
return deg;
fi;
od;
return deg;
end );
#############################################################################
##
#M <vec>{<poss>}
##
## multi-element access
##
InstallMethod(ELMS_LIST, "For an 8 bit vector and a plain list",
true, [IsList and Is8BitVectorRep,
IsPlistRep and IsDenseList ], 0,
ELMS_VEC8BIT);
InstallMethod(ELMS_LIST, "For an 8 bit vector and a range",
true, [IsList and Is8BitVectorRep,
IsRange and IsInternalRep ], 0,
ELMS_VEC8BIT_RANGE);
#############################################################################
##
#M <vec>*<ffe>
##
InstallMethod(\*, "For an 8 bit vector and an FFE",
IsCollsElms, [IsRowVector and Is8BitVectorRep,
IsFFE and IsInternalRep], 0,
PROD_VEC8BIT_FFE);
#############################################################################
##
#M <vec>*<mat>
##
InstallMethod(\*, "For an 8 bit vector and a compatible matrix",
IsElmsColls, [IsRowVector and Is8BitVectorRep and IsSmallList
and IsRingElementList,
IsRingElementTable and IsPlistRep], 0,
PROD_VEC8BIT_MATRIX);
#############################################################################
##
#M \*( <ffe>, <gf2vec> ) . . . . . . . . . . . product of FFE and GF2 vector
##
## This is here to catch the case of an element in GF(2^k) 1 < k <= 8,
## in which case we can convert to an 8 bit vector. There is a
## higher-priority method in vecmat.gi which handles GF(2) elements.
##
InstallMethod( \*,
"for FFE and GF2 vector",
IsElmsColls,
[ IsFFE,
IsRingElementList and IsRowVector and IsGF2VectorRep ],
0,
function( a, b )
if DegreeFFE(a) > 8 or IsLockedRepresentationVector(b) then
TryNextMethod();
else
ConvertToVectorRepNC(b,Field(a));
return a*b;
fi;
end );
#############################################################################
##
#M <ffe>*<vec>
##
InstallMethod(\*, "For an FFE and an 8 bit vector ",
IsElmsColls, [IsFFE and IsInternalRep,
IsRowVector and Is8BitVectorRep],
0,
PROD_FFE_VEC8BIT);
#############################################################################
##
#M \*( <ffe>, <gf2vec> ) . . . . . . . . . . . product of FFE and GF2 vector
##
## This is here to catch the case of an element in GF(2^k) 1 < k <= 8,
## in which case we can convert to an 8 bit vector. There is a
## higher-priority method in vecmat.gi which handles GF(2) elements.
##
InstallMethod( \*,
"for FFE and GF2 vector",
IsElmsColls,
[ IsFFE,
IsRingElementList and IsRowVector and IsGF2VectorRep ],
0,
function( b, a )
if DegreeFFE(b) > 8 or IsLockedRepresentationVector(a) then
TryNextMethod();
else
ConvertToVectorRepNC(a,Field(b));
return b*a;
fi;
end );
#############################################################################
##
#M <vecl> - <vecr>
##
InstallMethod(\-, "For two 8bit vectors",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep],
0,
DIFF_VEC8BIT_VEC8BIT );
InstallMethod( \-, "For a GF2 vector and an 8 bit vector of char 2",
IsIdenticalObj, [IsRowVector and IsGF2VectorRep ,
IsRowVector and Is8BitVectorRep], 0,
function(v,w)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return v-w;
fi;
end);
InstallMethod( \-, "For an 8 bit vector of char 2 and a GF2 vector",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep ,
IsRowVector and IsGF2VectorRep], 0,
function(w,v)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return w-v;
fi;
end);
#############################################################################
##
#M -<vec>
##
InstallMethod( AdditiveInverseOp, "For an 8 bit vector",
true, [IsRowVector and Is8BitVectorRep],
0,
AINV_VEC8BIT_MUTABLE);
#############################################################################
##
#M -<vec>
##
InstallMethod( AdditiveInverseSameMutability, "For an 8 bit vector",
true, [IsRowVector and Is8BitVectorRep],
0,
AINV_VEC8BIT_SAME_MUTABILITY );
#############################################################################
##
#M -<vec>
##
InstallMethod( AdditiveInverseImmutable, "For an 8 bit vector",
true, [IsRowVector and Is8BitVectorRep],
0,
AINV_VEC8BIT_IMMUTABLE );
#############################################################################
##
#M ZeroOp( <vec> )
##
## A mutable zero vector of the same field and length
##
InstallMethod( ZeroOp, "For an 8 bit vector",
true, [IsRowVector and Is8BitVectorRep],
0,
ZERO_VEC8BIT);
#############################################################################
##
#M ZEROOp( <vec> )
##
## A zero vector of the same field and length and mutability
##
InstallMethod( ZeroSameMutability, "For an 8 bit vector",
true, [IsRowVector and Is8BitVectorRep],
0,
function(v)
local z;
z := ZERO_VEC8BIT(v);
if not IsMutable(v) then
MakeImmutable(z);
fi;
return z;
end );
#############################################################################
##
#M <vec1> = <vec2>
##
InstallMethod( \=, "For 2 8 bit vectors",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep],
0,
EQ_VEC8BIT_VEC8BIT);
#############################################################################
##
#M <vec1> < <vec2>
##
## Usual lexicographic ordering
##
InstallMethod( \<, "For 2 8 bit vectors",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep],
0,
LT_VEC8BIT_VEC8BIT);
#############################################################################
##
#M <vec1>*<vec2>
##
## scalar product
#'
InstallMethod( \*, "For 2 8 bit vectors",
IsIdenticalObj, [IsRingElementList and Is8BitVectorRep,
IsRingElementList and Is8BitVectorRep],
0,
PROD_VEC8BIT_VEC8BIT);
InstallMethod( \*, "For a GF2 vector and an 8 bit vector of char 2",
IsIdenticalObj, [IsRowVector and IsGF2VectorRep,
IsRowVector and Is8BitVectorRep], 0,
function(v,w)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return v*w;
fi;
end);
InstallMethod( \*, "For an 8 bit vector of char 2 and a GF2 vector",
IsIdenticalObj, [IsRowVector and Is8BitVectorRep,
IsRowVector and IsGF2VectorRep ], 0,
function(w,v)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v,GF(Q_VEC8BIT(w)));
return w*v;
fi;
end);
#############################################################################
##
#M AddRowVector( <vec1>, <vec2>, <mult>, <from>, <to> )
##
## add <mult>*<vec2> to <vec1> in place
##
InstallOtherMethod( AddRowVector, "For 2 8 bit vectors and a field element and from and to",
IsCollsCollsElmsXX, [ IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep,
IsFFE and IsInternalRep, IsPosInt, IsPosInt ], 0,
ADD_ROWVECTOR_VEC8BITS_5);
#############################################################################
##
#M AddRowVector( <vec1>, <vec2>, <mult> )
##
## add <mult>*<vec2> to <vec1> in place
##
InstallOtherMethod( AddRowVector, "For 2 8 bit vectors and a field element",
IsCollsCollsElms, [ IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep,
IsFFE and IsInternalRep ], 0,
ADD_ROWVECTOR_VEC8BITS_3);
#############################################################################
##
#M AddRowVector( <vec1>, <vec2> )
##
## add <vec2> to <vec1> in place
##
InstallOtherMethod( AddRowVector, "For 2 8 bit vectors",
IsIdenticalObj, [ IsRowVector and Is8BitVectorRep,
IsRowVector and Is8BitVectorRep], 0,
ADD_ROWVECTOR_VEC8BITS_2);
#############################################################################
##
#M MultRowVector( <vec>, <ffe> )
##
## multiply <vec> by <ffe> in place
##
InstallOtherMethod( MultRowVector, "For an 8 bit vector and an ffe",
IsCollsElms, [ IsRowVector and Is8BitVectorRep,
IsFFE and IsInternalRep], 0,
MULT_ROWVECTOR_VEC8BITS);
#############################################################################
##
#M PositionNot( <vec>, <zero )
#M PositionNot( <vec>, <zero>, 0)
##
##
InstallOtherMethod( PositionNot, "for 8-bit vector and 0*Z(p)",
IsCollsElms, [Is8BitVectorRep and IsRowVector , IsFFE and
IsZero], 0,
POSITION_NONZERO_VEC8BIT);
InstallMethod( PositionNot, "for 8-bit vector and 0*Z(p) and 0",
IsCollsElmsX, [Is8BitVectorRep and IsRowVector , IsFFE and
IsZero, IsZero and IsInt], 0,
function(v,z,z1)
return POSITION_NONZERO_VEC8BIT(v,z);
end);
InstallMethod( PositionNonZero, "for 8-bit vector",true,
[Is8BitVectorRep and IsRowVector],0,
# POSITION_NONZERO_VEC8BIT ignores the second argument
v->POSITION_NONZERO_VEC8BIT(v,0));
#############################################################################
##
#M Append( <vecl>, <vecr> )
##
InstallMethod( Append, "for 8bitm vectors",
IsIdenticalObj, [Is8BitVectorRep and IsMutable and IsList,
Is8BitVectorRep and IsList], 0,
APPEND_VEC8BIT);
#############################################################################
##
#M NumberFFVector(<<vec>,<sz>)
##
InstallMethod(NumberFFVector,"8bit-vector",true,
[Is8BitVectorRep and IsRowVector and IsFFECollection,IsPosInt],0,
function(v,n)
if n<>Q_VEC8BIT(v) then TryNextMethod();fi;
return NUMBER_VEC8BIT(v);
end);
#############################################################################
##
#M IsSubset(<finfield>,<8bitvec>)
##
InstallMethod(IsSubset,"field, 8bit-vector",IsIdenticalObj,
[ IsField and IsFinite and IsFFECollection,
Is8BitVectorRep and IsRowVector and IsFFECollection],0,
function(F,v)
local q;
q:=Q_VEC8BIT(v);
if Size(F)=q then
return true;
fi;
# otherwise we must be a bit more clever
if 0 = DegreeOverPrimeField(F) mod LogInt(q,Characteristic(F)) then
return true; # degrees ovber prime field OK
fi;
TryNextMethod(); # the vector still might be written over a too-large
# field, so we can't say `no'.
end);
#############################################################################
##
#M DistanceVecFFE(<vecl>,<vecr>)
##
InstallMethod(DistanceVecFFE,"8bit-vector",true,
[Is8BitVectorRep and IsRowVector,
Is8BitVectorRep and IsRowVector],0,
DISTANCE_VEC8BIT_VEC8BIT);
#############################################################################
##
#M AddCoeffs( <vec1>, <vec2>, <mult> )
##
InstallOtherMethod( AddCoeffs, "two 8 bit vectors", IsCollsCollsElms,
[Is8BitVectorRep and IsRowVector,
Is8BitVectorRep and IsRowVector,
IsFFE], 0,
ADD_COEFFS_VEC8BIT_3);
InstallOtherMethod( AddCoeffs, "8 bit vector and GF2 vector", IsCollsCollsElms,
[Is8BitVectorRep and IsRowVector,
IsGF2VectorRep and IsRowVector,
IsFFE], 0,
function(v,w, x)
if IsLockedRepresentationVector(w) then
TryNextMethod();
else
ConvertToVectorRepNC(w, Q_VEC8BIT(v));
return ADD_COEFFS_VEC8BIT_3(v,w,x);
fi;
end);
InstallOtherMethod( AddCoeffs, "GF2 vector and 8 bit vector", IsCollsCollsElms,
[IsGF2VectorRep and IsRowVector,
Is8BitVectorRep and IsRowVector,
IsFFE], 0,
function(v,w, x)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v, Q_VEC8BIT(w));
return ADD_COEFFS_VEC8BIT_3(v,w,x);
fi;
end);
#############################################################################
##
#M AddCoeffs( <vec1>, <vec2> )
##
InstallOtherMethod( AddCoeffs, "two 8 bit vectors", IsIdenticalObj,
[Is8BitVectorRep and IsRowVector,
Is8BitVectorRep and IsRowVector], 0,
ADD_COEFFS_VEC8BIT_2);
InstallOtherMethod( AddCoeffs, "8 bit vector and GF2 vector", IsIdenticalObj,
[Is8BitVectorRep and IsRowVector,
IsGF2VectorRep and IsRowVector], 0,
function(v,w)
if IsLockedRepresentationVector(w) then
TryNextMethod();
else
ConvertToVectorRepNC(w, Q_VEC8BIT(v));
return ADD_COEFFS_VEC8BIT_2(v,w);
fi;
end);
InstallOtherMethod( AddCoeffs, "GF2 vector and 8 bit vector", IsIdenticalObj,
[IsGF2VectorRep and IsRowVector,
Is8BitVectorRep and IsRowVector], 0,
function(v,w)
if IsLockedRepresentationVector(v) then
TryNextMethod();
else
ConvertToVectorRepNC(v, Q_VEC8BIT(w));
return ADD_COEFFS_VEC8BIT_2(v,w);
fi;
end);
#############################################################################
##
#M LeftShiftRowVector( <vec>, <shift> )
##
InstallMethod( LeftShiftRowVector, "8bit vector", true,
[IsMutable and IsRowVector and Is8BitVectorRep,
IsPosInt], 0,
SHIFT_VEC8BIT_LEFT);
#############################################################################
##
#M RightShiftRowVector( <vec>, <shift>, <zero> )
##
InstallMethod( RightShiftRowVector, "8bit vector, fill with zeros", IsCollsXElms,
[IsMutable and IsRowVector and Is8BitVectorRep,
IsPosInt,
IsFFE and IsZero], 0,
SHIFT_VEC8BIT_RIGHT);
#############################################################################
##
#M ShrinkCoeffs( <vec> )
##
InstallMethod( ShrinkCoeffs, "8 bit vector", true,
[IsMutable and IsRowVector and Is8BitVectorRep ],
0,
function(vec)
local r;
r := RIGHTMOST_NONZERO_VEC8BIT(vec);
RESIZE_VEC8BIT(vec, r);
return r;
end);
#############################################################################
##
#M ShrinkRowVector( <vec> )
InstallMethod( ShrinkRowVector, "8 bit vector", true,
[IsMutable and IsRowVector and Is8BitVectorRep ],
0,
function(vec)
local r;
r := RIGHTMOST_NONZERO_VEC8BIT(vec);
RESIZE_VEC8BIT(vec, r);
end);
#############################################################################
##
#M RemoveOuterCoeffs( <vec>, <zero> )
##
InstallMethod( RemoveOuterCoeffs, "vec8bit and zero", IsCollsElms,
[ IsMutable and Is8BitVectorRep and IsRowVector, IsFFE and
IsZero], 0,
function (v,z)
local shift;
shift := POSITION_NONZERO_VEC8BIT(v,z) -1;
if shift <> 0 then
SHIFT_VEC8BIT_LEFT( v, shift);
fi;
if v <> [] then
RESIZE_VEC8BIT(v,RIGHTMOST_NONZERO_VEC8BIT(v));
fi;
return shift;
end);
#############################################################################
##
#M ProductCoeffs( <vec>, <len>, <vec>, <len>)
##
##
InstallMethod( ProductCoeffs, "8 bit vectors, kernel method", IsFamXFamY,
[Is8BitVectorRep and IsRowVector, IsInt, Is8BitVectorRep and
IsRowVector, IsInt ], 0,
PROD_COEFFS_VEC8BIT);
InstallOtherMethod( ProductCoeffs, "8 bit vectors, kernel method (2 arg)",
IsIdenticalObj,
[Is8BitVectorRep and IsRowVector, Is8BitVectorRep and
IsRowVector ], 0,
function(v,w)
return PROD_COEFFS_VEC8BIT(v, Length(v), w, Length(w));
end);
#############################################################################
##
#M ReduceCoeffs( <vec>, <len>, <vec>, <len>)
##
##
BindGlobal("ADJUST_FIELDS_VEC8BIT",
function(v,w)
local p,e;
if Q_VEC8BIT(v)<>Q_VEC8BIT(w) then
p:=Characteristic(v);
e:=Lcm(LogInt(Q_VEC8BIT(v),p),LogInt(Q_VEC8BIT(w),p));
if p^e > 256 or
p^e <> ConvertToVectorRepNC(v,p^e) or
p^e <> ConvertToVectorRepNC(w,p^e) then
return fail;
fi;
fi;
return true;
end);
InstallMethod( ReduceCoeffs, "8 bit vectors, kernel method", IsFamXFamY,
[Is8BitVectorRep and IsRowVector and IsMutable, IsInt, Is8BitVectorRep and
IsRowVector, IsInt ], 0,
function(vl, ll, vr, lr)
local res;
if ADJUST_FIELDS_VEC8BIT(vl, vr) = fail then
TryNextMethod();
fi;
res := REDUCE_COEFFS_VEC8BIT( vl, ll,
MAKE_SHIFTED_COEFFS_VEC8BIT(vr, lr));
if res = fail then
TryNextMethod();
else
return res;
fi;
end);
InstallOtherMethod( ReduceCoeffs, "8 bit vectors, kernel method (2 arg)",
IsIdenticalObj,
[Is8BitVectorRep and IsRowVector and IsMutable, Is8BitVectorRep and
IsRowVector ], 0,
function(v,w)
if ADJUST_FIELDS_VEC8BIT(v, w) = fail then
TryNextMethod();
fi;
return REDUCE_COEFFS_VEC8BIT(v, Length(v),
MAKE_SHIFTED_COEFFS_VEC8BIT(w, Length(w)));
end);
#############################################################################
##
#M PowerModCoeffs( <vec1>, <len1>, <exp>, <vec2>, <len2> )
##
IsFamXYFamZ := function(F1, F2, F3, F4, F5) return
IsIdenticalObj(F1,F4); end;
InstallMethod( PowerModCoeffs,
"for 8 bit vectors",
IsFamXYFamZ,
[ Is8BitVectorRep and IsRowVector, IsInt, IsPosInt,
Is8BitVectorRep and IsRowVector, IsInt ],
0,
function( v, lv, exp, w, lw)
local wshifted, pow, lpow, bits, i,p,e;
# ensure both vectors are in the same field
if ADJUST_FIELDS_VEC8BIT(v, w) = fail then
TryNextMethod();
fi;
wshifted := MAKE_SHIFTED_COEFFS_VEC8BIT(w, lw);
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_VEC8BIT(pow,lpow, pow, lpow);
lpow := Length(pow);
lpow := REDUCE_COEFFS_VEC8BIT( pow, lpow, wshifted);
if lpow = 0 then
return pow;
fi;
if bits[i] = 1 then
pow := PROD_COEFFS_VEC8BIT(pow, lpow, v, lv);
lpow := Length(pow);
lpow := REDUCE_COEFFS_VEC8BIT( pow, lpow, wshifted);
if lpow = 0 then
return pow;
fi;
fi;
od;
return pow;
end);
#############################################################################
##
#E
##
|