/usr/share/gap/lib/field.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 | #############################################################################
##
#W field.gi GAP library Martin Schönert
##
##
#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 generic methods for division rings.
##
#############################################################################
##
#M DivisionRingByGenerators( <gens> ) . . . . . . . . . . for a collection
#M DivisionRingByGenerators( <F>, <gens> ) . . for div.ring and collection
##
InstallOtherMethod( DivisionRingByGenerators,
"for a collection",
[ IsCollection ],
coll -> DivisionRingByGenerators(
FieldOverItselfByGenerators( [ One( Representative( coll ) ) ] ),
coll ) );
InstallMethod( DivisionRingByGenerators,
"for a division ring, and a collection",
IsIdenticalObj,
[ IsDivisionRing, IsCollection ],
function( F, gens )
local D;
D:= Objectify( NewType( FamilyObj( gens ),
IsField and IsAttributeStoringRep ),
rec() );
SetLeftActingDomain( D, F );
SetGeneratorsOfDivisionRing( D, AsList( gens ) );
return D;
end );
#############################################################################
##
#M FieldOverItselfByGenerators( <gens> )
##
InstallMethod( FieldOverItselfByGenerators,
"for a collection",
[ IsCollection ],
function( gens )
local F;
if IsEmpty( gens ) then
Error( "need at least one element" );
fi;
F:= Objectify( NewType( FamilyObj( gens ),
IsField and IsAttributeStoringRep ),
rec() );
SetLeftActingDomain( F, F );
SetGeneratorsOfDivisionRing( F, gens );
return F;
end );
#############################################################################
##
#M DefaultFieldByGenerators( <gens> ) . . . . . . . . . . for a collection
##
InstallMethod( DefaultFieldByGenerators,
"for a collection",
[ IsCollection ],
DivisionRingByGenerators );
#############################################################################
##
#F Field( <z>, ... ) . . . . . . . . . field generated by a list of elements
#F Field( [ <z>, ... ] )
#F Field( <F>, [ <z>, ... ] )
##
InstallGlobalFunction( Field, function ( arg )
local F; # field containing the elements of <arg>, result
# special case for one square matrix
if Length(arg) = 1
and IsMatrix( arg[1] ) and Length( arg[1] ) = Length( arg[1][1] )
then
F := FieldByGenerators( arg );
# special case for list of elements
elif Length(arg) = 1 and IsList(arg[1]) then
F := FieldByGenerators( arg[1] );
# special case for subfield and generators
elif Length(arg) = 2 and IsField(arg[1]) then
F := FieldByGenerators( arg[1], arg[2] );
# other cases
else
F := FieldByGenerators( arg );
fi;
# return the field
return F;
end );
#############################################################################
##
#F DefaultField( <z>, ... ) . . . . . default field containing a collection
##
InstallGlobalFunction( DefaultField, function ( arg )
local F; # field containing the elements of <arg>, result
# special case for one square matrix
if Length(arg) = 1
and IsMatrix( arg[1] ) and Length( arg[1] ) = Length( arg[1][1] )
then
F := DefaultFieldByGenerators( arg );
# special case for list of elements
elif Length(arg) = 1 and IsList(arg[1]) then
F := DefaultFieldByGenerators( arg[1] );
# other cases
else
F := DefaultFieldByGenerators( arg );
fi;
# return the default field
return F;
end );
#############################################################################
##
#F Subfield( <F>, <gens> ) . . . . . . . subfield of <F> generated by <gens>
#F SubfieldNC( <F>, <gens> )
##
InstallGlobalFunction( Subfield, function( F, gens )
local S;
if IsEmpty( gens ) then
return PrimeField( F );
elif IsHomogeneousList( gens )
and IsIdenticalObj( FamilyObj( F ), FamilyObj( gens ) )
and ForAll( gens, g -> g in F ) then
S:= FieldByGenerators( LeftActingDomain( F ), gens );
SetParent( S, F );
return S;
fi;
Error( "<gens> must be a list of elements in <F>" );
end );
InstallGlobalFunction( SubfieldNC, function( F, gens )
local S;
if IsEmpty( gens ) then
S:= Objectify( NewType( FamilyObj( F ),
IsDivisionRing and IsAttributeStoringRep ),
rec() );
SetLeftActingDomain( S, F );
SetGeneratorsOfDivisionRing( S, AsList( gens ) );
else
S:= DivisionRingByGenerators( LeftActingDomain( F ), gens );
fi;
SetParent( S, F );
return S;
end );
#############################################################################
##
#M ClosureDivisionRing( <D>, <d> ) . . . . . . . . . closure with an element
##
InstallMethod( ClosureDivisionRing,
"for a division ring and a scalar",
IsCollsElms,
[ IsDivisionRing, IsScalar ],
function( D, d )
# if possible test if the element lies in the division ring already,
if HasGeneratorsOfDivisionRing( D )
and d in GeneratorsOfDivisionRing( D ) then
return D;
# otherwise make a new division ring
else
return DivisionRingByGenerators( LeftActingDomain( D ),
Concatenation( GeneratorsOfDivisionRing( D ), [ d ] ) );
fi;
end );
InstallMethod( ClosureDivisionRing,
"for a division ring containing the whole family, and a scalar",
IsCollsElms,
[ IsDivisionRing and IsWholeFamily, IsScalar ],
SUM_FLAGS, # we can't be better than this
function( D, d )
return D;
end );
#############################################################################
##
#M ClosureDivisionRing( <D>, <C> ) . . . . . . . . closure of division ring
##
InstallMethod( ClosureDivisionRing,
"for division ring and collection of elements",
IsIdenticalObj,
[ IsDivisionRing, IsCollection ],
function( D, C )
local d; # one generator
if IsDivisionRing( C ) then
if not IsSubset( LeftActingDomain( D ), LeftActingDomain( C ) ) then
C:= AsDivisionRing( Intersection( LeftActingDomain( C ),
LeftActingDomain( D ) ), C );
fi;
C:= GeneratorsOfDivisionRing( C );
elif not IsList( C ) then
TryNextMethod();
fi;
for d in C do
D:= ClosureDivisionRing( D, d );
od;
return D;
end );
InstallMethod( ClosureDivisionRing,
"for division ring and empty list",
[ IsDivisionRing, IsList and IsEmpty ],
function( D, empty )
return D;
end );
#############################################################################
##
#M ViewString( <F> ) . . . . . . . . . . . . . . . . . . . . . . view a field
##
InstallMethod( ViewString,
"for a field",
[ IsField ],
function( F )
if HasSize( F ) and IsInt( Size( F ) ) then
return Concatenation("<field of size ", String(Size( F )), ">" );
else
return Concatenation( "<field in characteristic ",
String(Characteristic( F )), ">" );
fi;
end );
#############################################################################
##
#M PrintObj( <F> ) . . . . . . . . . . . . . . . . . . . . . . print a field
##
InstallMethod( PrintObj,
"for a field with known generators",
[ IsField and HasGeneratorsOfField ],
function( F )
if IsIdenticalObj(F,LeftActingDomain(F)) or
IsPrimeField( LeftActingDomain( F ) ) then
Print( "Field( ", GeneratorsOfField( F ), " )" );
elif F = LeftActingDomain( F ) then
Print( "FieldOverItselfByGenerators( ",
GeneratorsOfField( F ), " )" );
else
Print( "AsField( ", LeftActingDomain( F ),
", Field( ", GeneratorsOfField( F ), " ) )" );
fi;
end );
InstallMethod( PrintObj,
"for a field",
[ IsField ],
function( F )
if IsPrimeField( LeftActingDomain( F ) ) then
Print( "Field( ... )" );
elif F = LeftActingDomain( F ) then
Print( "AsField( ~, ... )" );
else
Print( "AsField( ", LeftActingDomain( F ), ", ... )" );
fi;
end );
#############################################################################
##
#M IsTrivial( <F> ) . . . . . . . . . . . . . . . . . . for a division ring
##
InstallMethod( IsTrivial,
"for a division ring",
[ IsDivisionRing ],
ReturnFalse );
#############################################################################
##
#M PrimeField( <F> ) . . . . . . . . . . . . . . . . . . for a division ring
##
InstallMethod( PrimeField,
"for a division ring",
[ IsDivisionRing ],
function( F )
local P;
P:= Field( One( F ) );
UseSubsetRelation( F, P );
SetIsPrimeField( P, true );
return P;
end );
InstallMethod( PrimeField,
"for a prime field",
[ IsField and IsPrimeField ],
IdFunc );
#############################################################################
##
#M IsPrimeField( <F> ) . . . . . . . . . . . . . . . . . for a division ring
##
InstallMethod( IsPrimeField,
"for a division ring",
[ IsDivisionRing ],
F -> DegreeOverPrimeField( F ) = 1 );
#############################################################################
##
#M IsNumberField( <F> ) . . . . . . . . . . . . . . . . . . . . for a field
##
InstallMethod( IsNumberField,
"for a field",
[ IsField ],
F -> Characteristic( F ) = 0 and IsInt( DegreeOverPrimeField( F ) ) );
#############################################################################
##
#M IsAbelianNumberField( <F> ) . . . . . . . . . . . . . . . . . for a field
##
InstallMethod( IsAbelianNumberField,
"for a field",
[ IsField ],
F -> IsNumberField( F ) and IsCommutative( GaloisGroup(
AsField( PrimeField( F ), F ) ) ) );
#############################################################################
##
#M IsCyclotomicField( <F> ) . . . . . . . . . . . . . . . . . . for a field
##
InstallMethod( IsCyclotomicField,
"for a field",
[ IsField ],
F -> IsAbelianNumberField( F )
and Conductor( F ) = DegreeOverPrimeField( F ) );
#############################################################################
##
#M IsNormalBasis( <B> ) . . . . . . . . . . . . . for a basis (of a field)
##
InstallMethod( IsNormalBasis,
"for a basis of a field",
[ IsBasis ],
function( B )
local vectors;
if not IsField( UnderlyingLeftModule( B ) ) then
Error( "<B> must be a basis of a field" );
fi;
vectors:= BasisVectors( B );
return Set( vectors )
= Set( Conjugates( UnderlyingLeftModule( B ), vectors[1] ) );
end );
#############################################################################
##
#M GeneratorsOfDivisionRing( <F> ) . . . . . . . . . . . . for a prime field
##
InstallMethod( GeneratorsOfDivisionRing,
"for a prime field",
[ IsField and IsPrimeField ],
F -> [ One( F ) ] );
#############################################################################
##
#M DegreeOverPrimeField( <F> ) . . . . . . . . . . . . . . for a prime field
##
InstallImmediateMethod( DegreeOverPrimeField, IsPrimeField, 20, F -> 1 );
#############################################################################
##
#M NormalBase( <F> ) . . . . . . . . . . for a field in characteristic zero
#M NormalBase( <F>, <elm> ) . . . . . . for a field in characteristic zero
##
## For fields in characteristic zero, a normal basis is computed
## as described on p.~65~f.~in~\cite{Art68}.
## Let $\Phi$ denote the polynomial of the field extension $L/L^{\prime}$,
## $\Phi^{\prime}$ its derivative and $\alpha$ one of its roots;
## then for all except finitely many elements $z \in L^{\prime}$,
## the conjugates of $\frac{\Phi(z)}{(z-\alpha)\cdot\Phi^{\prime}(\alpha)}$
## form a normal basis of $L/L^{\prime}$.
##
## When `NormalBase' is called for a field <F> in characteristic zero and
## an element <elm>,
## $z$ is chosen as <elm>, $<elm> + 1$, $<elm> + 2$, \ldots,
## until a normal basis is found.
## The default of <elm> is the identity of <F>.
##
InstallMethod( NormalBase,
"for a field (in characteristic zero)",
[ IsField ],
F -> NormalBase( F, One( F ) ) );
InstallMethod( NormalBase,
"for a field (in characteristic zero), and a scalar",
[ IsField, IsScalar ],
function( F, z )
local alpha, poly, i, val, normal;
# Check the arguments.
if Characteristic( F ) <> 0 then
TryNextMethod();
elif not z in F then
Error( "<z> must be an element in <F>" );
fi;
# Get a primitive element `alpha'.
alpha:= PrimitiveElement( F );
# Construct the polynomial
# $\prod_{\sigma\in `Gal( alpha )'\setminus \{1\} } (x-\sigma(`alpha') )
# for the primitive element `alpha'.
poly:= [ 1 ];
for i in Difference( Conjugates( F, alpha ), [ alpha ] ) do
poly:= ProductCoeffs( poly, [ -i, 1 ] );
#T ?
od;
# For the denominator, evaluate `poly' at `a'.
val:= Inverse( ValuePol( poly, alpha ) );
# There are only finitely many values `x' in the subfield
# for which `poly(x) * val' is not an element of a normal basis.
repeat
normal:= Conjugates( F, ValuePol( poly, z ) * val );
z:= z + 1;
until RankMat( List( normal, COEFFS_CYC ) ) = Dimension( F );
# Return the result.
return normal;
end );
#############################################################################
##
#M PrimitiveElement( <D> ) . . . . . . . . . . . . . . . for a division ring
##
InstallMethod( PrimitiveElement,
"for a division ring",
[ IsDivisionRing ],
function( D )
D:= GeneratorsOfDivisionRing( D );
if Length( D ) = 1 then
return D[1];
else
TryNextMethod();
fi;
end );
#############################################################################
##
#M Representative( <D> ) . . . . . for a division ring with known generators
##
InstallMethod( Representative,
"for a division ring with known generators",
[ IsDivisionRing and HasGeneratorsOfDivisionRing ],
RepresentativeFromGenerators( GeneratorsOfDivisionRing ) );
#############################################################################
##
#M Enumerator( <F> ) . . . . . . . . . . elements of a (finite) prime field
#M EnumeratorSorted( <F> ) . . . . . . . elements of a (finite) prime field
##
## We install a special method only for (finite) prime fields,
## since the other cases are handled by the vector space methods.
##
EnumeratorOfPrimeField := function( F )
local one;
one:= One( F );
if Size( F ) <= MAXSIZE_GF_INTERNAL then
return AsSSortedListList( List( [ 0 .. Size( F ) - 1 ], i -> i * one ) );
elif IsZmodnZObj( one ) then
return EnumeratorOfZmodnZ( F );
fi;
TryNextMethod();
end;
InstallMethod( Enumerator,
"for a finite prime field",
[ IsField and IsPrimeField and IsFinite ],
EnumeratorOfPrimeField );
InstallMethod( EnumeratorSorted,
"for a finite prime field",
[ IsField and IsPrimeField and IsFinite ],
EnumeratorOfPrimeField );
InstallMethod( AsList,
"for a finite prime field",
[ IsField and IsPrimeField and IsFinite ],
F -> AsList( Enumerator( F ) ) );
#############################################################################
##
#M IsSubset( <D>, <F> ) . . . . . . . . . . . . . . for two division rings
##
## We have to be careful not to run into an infinite recursion in the case
## that <F> is equal to its left acting domain.
## Also we must be aware of situations where the left acting domains are
## in a family different from that of the fields themselves,
## for example <D> could be given as a field over a field that is really
## a subset of <D>, whereas the left acting domain of <F> is not a subset
## of <F>.
##
BindGlobal( "DivisionRing_IsSubset", function( D, F )
local CF;
# Special case for when F equals the cyclotomics (and hence is infinite
# dimensional over its left acting domain).
if IsIdenticalObj(F, Cyclotomics) then
return IsIdenticalObj(D, Cyclotomics);
fi;
CF:= LeftActingDomain( F );
if not IsSubset( D, GeneratorsOfDivisionRing( F ) ) then
return false;
elif IsSubset( LeftActingDomain( D ), CF ) or IsPrimeField( CF ) then
return true;
elif FamilyObj( F ) = FamilyObj( CF ) then
return IsSubset( D, CF );
else
CF:= AsDivisionRing( PrimeField( CF ), CF );
return IsSubset( D, List( GeneratorsOfDivisionRing( CF ),
x -> x * One( F ) ) );
fi;
end );
InstallMethod( IsSubset,
"for two division rings",
IsIdenticalObj,
[ IsDivisionRing, IsDivisionRing ],
DivisionRing_IsSubset );
#############################################################################
##
#M \=( <D>, <F> ) . . . . . . . . . . . . . . . . . for two division rings
##
InstallMethod( \=,
"for two division rings",
IsIdenticalObj,
[ IsDivisionRing, IsDivisionRing ],
function( D, F )
return DivisionRing_IsSubset( D, F ) and DivisionRing_IsSubset( F, D );
end );
#############################################################################
##
#M AsDivisionRing( <C> ) . . . . . . . . . . . . . . . . . for a collection
##
InstallMethod( AsDivisionRing,
"for a collection",
[ IsCollection ],
function( C )
local one, F;
# A division ring contains at least two elements.
if IsEmpty( C ) or IsTrivial( C ) then
return fail;
fi;
# Construct the prime field.
one:= One( Representative( C ) );
if one = fail then
return fail;
fi;
F:= FieldOverItselfByGenerators( [ one ] );
# Delegate to the two-argument version.
return AsDivisionRing( F, C );
end );
#############################################################################
##
#M AsDivisionRing( <F>, <C> ) . . . . for a division ring, and a collection
##
InstallMethod( AsDivisionRing,
"for a division ring, and a collection",
IsIdenticalObj,
[ IsDivisionRing, IsCollection ],
function( F, C )
local D;
if not IsSubset( C, F ) then
return fail;
fi;
D:= DivisionRingByGenerators( F, C );
if D <> C then
return fail;
fi;
return D;
end );
#############################################################################
##
#M AsDivisionRing( <F>, <D> ) . . . . . . . . . . . for two division rings
##
InstallMethod( AsDivisionRing,
"for two division rings",
IsIdenticalObj,
[ IsDivisionRing, IsDivisionRing ],
function( F, D )
local E;
if F = LeftActingDomain( D ) then
return D;
elif not IsSubset( D, F ) then
return fail;
fi;
E:= DivisionRingByGenerators( F, GeneratorsOfDivisionRing( D ) );
UseIsomorphismRelation( D, E );
UseSubsetRelation( D, E );
return E;
end );
#############################################################################
##
#M AsLeftModule( <F1>, <F2> ) . . . . . . . . . . . for two division rings
##
## View the division ring <F2> as vector space over the division ring <F1>.
##
InstallMethod( AsLeftModule,
"for two division rings",
IsIdenticalObj,
[ IsDivisionRing, IsDivisionRing ],
AsDivisionRing );
#############################################################################
##
#M Conjugates( <F>, <z> ) . . . . . . . . . . conjugates of a field element
#M Conjugates( <z> ) . . . . . . . . . . . . . conjugates of a field element
##
InstallMethod( Conjugates,
"for a scalar (delegate to version with default field)",
[ IsScalar ],
z -> Conjugates( DefaultField( z ), z ) );
InstallMethod( Conjugates,
"for a field and a scalar (delegate to version with two fields)",
IsCollsElms,
[ IsField, IsScalar ],
function( F, z )
return Conjugates( F, LeftActingDomain( F ), z );
end );
#############################################################################
##
#M Conjugates( <L>, <K>, <z> ) . . for a field elm. (use `TracePolynomial')
##
InstallMethod( Conjugates,
"for two fields and a scalar (call `TracePolynomial')",
IsCollsXElms,
[ IsField, IsField, IsScalar ],
function( L, K, z )
local pol, lin, conj, mult, i;
# Check whether `Conjugates' is allowed to call `MinimalPolynomial'.
if IsFieldControlledByGaloisGroup( L ) then
TryNextMethod();
fi;
# Compute the roots in `L' of the minimal polynomial of `z' over `K'.
pol:= MinimalPolynomial( K, z );
lin:= List( Filtered( Factors( L, pol ),
x -> DegreeOfLaurentPolynomial( x ) = 1 ),
CoefficientsOfUnivariatePolynomial );
lin:= List( lin, x -> AdditiveInverse( lin[1] / lin[2] ) );
# Take the roots with the appropriate multiplicity.
conj:= [];
mult:= DegreeOverPrimeField( L ) / DegreeOverPrimeField( K );
mult:= mult / DegreeOfLaurentPolynomial( pol );
for i in [ 1 .. mult ] do
Append( conj, lin );
od;
return conj;
end );
#############################################################################
##
#M Conjugates( <L>, <K>, <z> ) . . . for a field element (use `GaloisGroup')
##
InstallMethod( Conjugates,
"for two fields and a scalar (call `GaloisGroup')",
IsCollsXElms,
[ IsFieldControlledByGaloisGroup, IsField, IsScalar ],
function( L, K, z )
local cnjs, # conjugates of <z> in <F>, result
aut; # automorphism of <F>
# Check the arguments.
if not z in L then
Error( "<z> must lie in <L>" );
fi;
# Compute the conjugates simply by applying all the automorphisms.
cnjs:= [];
for aut in GaloisGroup( AsField( L, K ) ) do
Add( cnjs, z ^ aut );
od;
# Return the conjugates.
return cnjs;
end );
#############################################################################
##
#M Norm( <F>, <z> ) . . . . . . . . . . . . . . . . norm of a field element
#M Norm( <z> ) . . . . . . . . . . . . . . . . . . . norm of a field element
##
InstallMethod( Norm,
"for a scalar (delegate to version with default field)",
[ IsScalar ],
z -> Norm( DefaultField( z ), z ) );
InstallMethod( Norm,
"for a field and a scalar (delegate to version with two fields)",
IsCollsElms,
[ IsField, IsScalar ],
function( F, z )
return Norm( F, LeftActingDomain( F ), z );
end );
#############################################################################
##
#M Norm( <L>, <K>, <z> ) . . . . norm of a field element (use `Conjugates')
##
InstallMethod( Norm,
"for two fields and a scalar (use `Conjugates')",
IsCollsXElms,
[ IsFieldControlledByGaloisGroup, IsField, IsScalar ],
function( L, K, z )
return Product( Conjugates( L, K, z ) );
end );
#############################################################################
##
#M Norm( <L>, <K>, <z> ) . . . norm of a field element (use the trace pol.)
##
InstallMethod( Norm,
"for two fields and a scalar (use the trace pol.)",
IsCollsXElms,
[ IsField, IsField, IsScalar ],
function( L, K, z )
local coeffs;
coeffs:= CoefficientsOfUnivariatePolynomial(
TracePolynomial( L, K, z, 1 ) );
return (-1)^(Length( coeffs )-1) * coeffs[1];
end );
#############################################################################
##
#M Trace( <z> ) . . . . . . . . . . . . . . . . . trace of a field element
#M Trace( <F>, <z> ) . . . . . . . . . . . . . . . trace of a field element
##
InstallMethod( Trace,
"for a scalar (delegate to version with default field)",
[ IsScalar ],
z -> Trace( DefaultField( z ), z ) );
InstallMethod( Trace,
"for a field and a scalar (delegate to version with two fields)",
IsCollsElms,
[ IsField, IsScalar ],
function( F, z )
return Trace( F, LeftActingDomain( F ), z );
end );
#############################################################################
##
#M Trace( <L>, <K>, <z> ) . . . trace of a field element (use `Conjugates')
##
InstallMethod( Trace,
"for two fields and a scalar (use `Conjugates')",
IsCollsXElms,
[ IsFieldControlledByGaloisGroup, IsField, IsScalar ],
function( L, K, z )
return Sum( Conjugates( L, K, z ) );
end );
#############################################################################
##
#M Trace( <L>, <K>, <z> ) . . trace of a field element (use the trace pol.)
##
InstallMethod( Trace,
"for two fields and a scalar (use the trace pol.)",
IsCollsXElms,
[ IsField, IsField, IsScalar ],
function( L, K, z )
local coeffs;
coeffs:= CoefficientsOfUnivariatePolynomial(
TracePolynomial( L, K, z, 1 ) );
return AdditiveInverse( coeffs[ Length( coeffs ) - 1 ] );
end );
#############################################################################
##
#M MinimalPolynomial( <F>, <z>, <nr> )
##
## If the default field of <z> knows how to get the Galois group then
## we compute the conjugates and from them the minimal polynomial.
## Otherwise we solve an equation system.
##
## Note that the family predicate `IsCollsElmsX' expresses that <z> may lie
## in an extension field of <F>;
## this guarantees that the method is *not* applicable for the case that <z>
## is a matrix.
##
InstallMethod( MinimalPolynomial,
"for field, scalar, and indet. number",
IsCollsElmsX,
[ IsField, IsScalar,IsPosInt ],
function( F, z, ind )
local L, coe, deg, zero, con, i, B, pow, mat, MB;
# Construct a basis of a field in which the computations happen.
# (This need not be the smallest such field.)
L:= DefaultField( z );
if IsFieldControlledByGaloisGroup( L ) then
# We may call `Conjugates'.
coe:= [ One( F ) ];
deg:= 0;
zero:= Zero( F );
for con in Conjugates( Field( F, [ z ] ), z ) do
coe[deg+2]:= coe[deg+1];
for i in [ deg+1, deg .. 2 ] do
coe[i]:= coe[i-1] - con * coe[i];
od;
coe[1]:= zero - con * coe[1];
deg:= deg + 1;
od;
else
# Solve an equation system.
B:= Basis( L );
# Compute coefficients of the powers of `z' until
# the rows are linearly dependent.
pow:= One( F );
coe:= Coefficients( B, pow );
mat:= [ coe ];
MB:= MutableBasis( F, [ coe ] );
repeat
CloseMutableBasis( MB, coe );
pow:= pow * z;
coe:= Coefficients( B, pow );
Add( mat, coe );
until IsContainedInSpan( MB, coe );
# The coefficients of the minimal polynomial
# are given by the linear relation.
coe:= NullspaceMat( mat )[1];
coe:= Inverse( coe[ Length( coe ) ] ) * coe;
fi;
# Construct the polynomial.
return UnivariatePolynomial( F, coe, ind );
end );
#############################################################################
##
#M TracePolynomial( <L>, <K>, <z> )
#M TracePolynomial( <L>, <K>, <z>, <ind> )
##
InstallMethod( TracePolynomial,
"using minimal polynomial",
IsCollsXElmsX,
[ IsField, IsField, IsScalar, IsPosInt ],
function( L, K, z, ind )
local minpol, mult;
minpol:= MinimalPolynomial( K, z, ind );
mult:= DegreeOverPrimeField( L ) / DegreeOverPrimeField( K );
mult:= mult / DegreeOfLaurentPolynomial( minpol );
return minpol ^ mult;
end );
InstallMethod( TracePolynomial,
"add default indet. 1",
IsCollsXElms,
[ IsField, IsField, IsScalar ],
function( L, K, z )
return TracePolynomial( L, K, z, 1 );
end );
#############################################################################
##
#M CharacteristicPolynomial( <L>, <K>, <z> )
#M CharacteristicPolynomial( <L>, <K>, <z>, <ind> )
##
InstallOtherMethod( CharacteristicPolynomial,
"call `TracePolynomial'",
IsCollsXElms,
[ IsField, IsField, IsScalar ],
function( L, K, z )
return TracePolynomial( L, K, z, 1 );
end );
InstallOtherMethod( CharacteristicPolynomial,
"call `TracePolynomial'",
IsCollsXElmsX,
[ IsField, IsField, IsScalar, IsPosInt ],
TracePolynomial );
#############################################################################
##
#M NiceFreeLeftModuleInfo( <V> )
#M NiceVector( <V>, <v> )
#M UglyVector( <V>, <r> )
##
InstallHandlingByNiceBasis( "IsFieldElementsSpace", rec(
detect := function( F, gens, V, zero )
return IsScalarCollection( V )
and IsIdenticalObj( FamilyObj( F ), FamilyObj( V ) )
and IsDivisionRing( F );
end,
NiceFreeLeftModuleInfo := function( V )
local lad, gens;
# Compute the default field of the vector space generators,
# and a basis of this field (over the left acting domain of `V').
lad:= LeftActingDomain( V );
if not IsIdenticalObj( FamilyObj( V ), FamilyObj( lad ) ) then
TryNextMethod();
fi;
return Basis( AsField( lad,
ClosureField( lad, GeneratorsOfLeftModule( V ) ) ) );
end,
NiceVector := function( V, v )
return Coefficients( NiceFreeLeftModuleInfo( V ), v );
end,
UglyVector := function( V, r )
local B;
B:= NiceFreeLeftModuleInfo( V );
if Length( r ) <> Length( B ) then
return fail;
fi;
return LinearCombination( B, r );
end ) );
#############################################################################
##
#M Quotient( <F>, <r>, <s> ) . . . . . . . . quotient of elements in a field
##
InstallMethod( Quotient,
"for a division ring, and two ring elements",
IsCollsElmsElms,
[ IsDivisionRing, IsRingElement, IsRingElement ],
function ( F, r, s )
return r/s;
end );
#############################################################################
##
#M IsUnit( <F>, <r> ) . . . . . . . . . . check for being a unit in a field
##
InstallMethod( IsUnit,
"for a division ring, and a ring element",
IsCollsElms,
[ IsDivisionRing, IsRingElement ],
function ( F, r )
return not IsZero( r ) and r in F;
end );
#############################################################################
##
#M Units( <F> )
##
InstallMethod( Units,
"for a division ring",
[ IsDivisionRing ],
function( D )
if IsFinite( D ) then
return Difference( AsList( D ), [ Zero( D ) ] );
else
TryNextMethod();
fi;
end );
#############################################################################
##
#M PrimitiveRoot( <F> ) . . . . . . . . . . . . for finite prime field <F>
##
## For a fields of prime order $p$, the multiplicative group corresponds to
## the group of residues modulo $p$, via `Int'.
## A primitive root is obtained as `PrimitiveRootMod( $p$ )' times the
## identity of <F>.
##
InstallMethod( PrimitiveRoot,
"for a finite prime field",
[ IsField and IsFinite ],
function( F )
if not IsPrimeField( F ) then
TryNextMethod();
fi;
return PrimitiveRootMod( Size( F ) ) * One( F );
end );
#############################################################################
##
#M IsAssociated( <F>, <r>, <s> ) . . . . . . check associatedness in a field
##
InstallMethod( IsAssociated,
"for a division ring, and two ring elements",
IsCollsElmsElms,
[ IsDivisionRing, IsRingElement, IsRingElement ],
function ( F, r, s )
return (r = Zero( F ) ) = (s = Zero( F ) );
end );
#############################################################################
##
#M StandardAssociate( <F>, <x> ) . . . . . . . standard associate in a field
##
InstallMethod( StandardAssociate,
"for a division ring and a ring element",
IsCollsElms,
[ IsDivisionRing, IsScalar ],
function ( R, r )
if r = Zero( R ) then
return Zero( R );
else
return One( R );
fi;
end );
#############################################################################
##
#M StandardAssociateUnit( <F>, <x> )
##
InstallMethod( StandardAssociateUnit,
"for a division ring and a ring element",
IsCollsElms,
[ IsDivisionRing, IsScalar ],
function ( R, r )
if r = Zero( R ) then
return One( R );
else
return r^-1;
fi;
end );
#############################################################################
##
#M IsIrreducibleRingElement( <F>, <x> )
##
InstallMethod(IsIrreducibleRingElement,"for field and ring element",
IsCollsElms, [ IsDivisionRing, IsScalar ],0,
function ( F, r )
if not r in F then
TryNextMethod();
fi;
# field elements are either zero or a unit
return false;
end );
#############################################################################
##
## Field homomorphisms
##
#############################################################################
##
#M IsFieldHomomorphism( <map> )
##
InstallMethod( IsFieldHomomorphism,
[ IsGeneralMapping ],
map -> IsRingHomomorphism( map ) and IsField( Source( map ) ) );
#############################################################################
##
#M KernelOfAdditiveGeneralMapping( <fldhom> ) . . for a field homomorphism
##
InstallMethod( KernelOfAdditiveGeneralMapping,
"for a field homomorphism",
[ IsFieldHomomorphism ],
#T higher rank?
#T (is this method ever used?)
function ( hom )
if ForAll( GeneratorsOfDivisionRing( Source( hom ) ),
x -> IsZero( ImagesRepresentative( hom, x ) ) ) then
return Source( hom );
else
return TrivialSubadditiveMagmaWithZero( Source( hom ) );
fi;
end );
#############################################################################
##
#M IsInjective( <fldhom> ) . . . . . . . . . . . . for a field homomorphism
##
InstallMethod( IsInjective,
"for a field homomorphism",
[ IsFieldHomomorphism ],
hom -> Size( KernelOfAdditiveGeneralMapping( hom ) ) = 1 );
#############################################################################
##
#M IsSurjective( <fldhom> ) . . . . . . . . . . . for a field homomorphism
##
InstallMethod( IsSurjective,
"for a field homomorphism",
[ IsFieldHomomorphism ],
function ( hom )
if IsFinite( Range( hom ) ) then
return Size( Range( hom ) ) = Size( Image( hom ) );
else
TryNextMethod();
fi;
end );
#############################################################################
##
#M \=( <hom1>, <hom2> ) . . . . . . . . . comparison of field homomorphisms
##
InstallMethod( \=,
"for two field homomorphisms",
IsIdenticalObj,
[ IsFieldHomomorphism, IsFieldHomomorphism ],
function ( hom1, hom2 )
# maybe the properties we already know determine the result
if ( HasIsInjective( hom1 ) and HasIsInjective( hom2 )
and IsInjective( hom1 ) <> IsInjective( hom2 ) )
or ( HasIsSurjective( hom1 ) and HasIsSurjective( hom2 )
and IsSurjective( hom1 ) <> IsSurjective( hom2 ) ) then
return false;
# otherwise we must really test the equality
else
return Source( hom1 ) = Source( hom2 )
and Range( hom1 ) = Range( hom2 )
and ForAll( GeneratorsOfField( Source( hom1 ) ),
elm -> Image(hom1,elm) = Image(hom2,elm) );
fi;
end );
#############################################################################
##
#M ImagesSet( <hom>, <elms> ) . . images of a set under a field homomorphism
##
InstallMethod( ImagesSet,
"for field homomorphism and field",
CollFamSourceEqFamElms,
[ IsFieldHomomorphism, IsField ],
function ( hom, elms )
elms:= FieldByGenerators( List( GeneratorsOfField( elms ),
gen -> ImagesRepresentative( hom, gen ) ) );
UseSubsetRelation( Range( hom ), elms );
return elms;
end );
#############################################################################
##
#M PreImagesElm( <hom>, <elm> ) . . . . . . . . . . . . preimage of an elm
##
InstallMethod( PreImagesElm,
"for field homomorphism and element",
FamRangeEqFamElm,
[ IsFieldHomomorphism, IsObject ],
function ( hom, elm )
if IsInjective( hom ) = 1 then
return [ PreImagesRepresentative( hom, elm ) ];
elif IsZero( elm ) then
return Source( hom );
else
return [];
fi;
end );
#############################################################################
##
#M PreImagesSet( <hom>, <elm> ) . . . . . . . . . . . . . preimage of a set
##
InstallMethod( PreImagesSet,
"for field homomorphism and field",
CollFamRangeEqFamElms,
[ IsFieldHomomorphism, IsField ],
function ( hom, elms )
elms:= FieldByGenerators( List( GeneratorsOfField( elms ),
gen -> PreImagesRepresentative( hom, gen ) ) );
UseSubsetRelation( Source( hom ), elms );
return elms;
end );
#############################################################################
##
#E
|