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
|
###########################################################################
##
#W omput.gi OpenMath Package Andrew Solomon
#W Marco Costantini
##
#Y Copyright (C) 1999, 2000, 2001, 2006
#Y School Math and Comp. Sci., University of St. Andrews, Scotland
#Y Copyright (C) 2004, 2005, 2006 Marco Costantini
##
## High-level methods to output GAP objects in OpenMath
##
###########################################################################
#
# Functions and methods for OpenMathWriter
#
InstallGlobalFunction( OpenMathBinaryWriter, function( stream )
if IsStream( stream ) then
return Objectify( OpenMathBinaryWriterType, [ stream ] );
else
Error( "The argument of OpenMathBinaryWriter must be a stream" );
fi;
end);
InstallGlobalFunction( OpenMathXMLWriter, function( stream )
if IsStream( stream ) then
return Objectify( OpenMathXMLWriterType, [ stream ] );
else
Error( "The argument of OpenMathXMLWriter must be a stream" );
fi;
end);
###########################################################################
##
#M PrintObj( <IsOpenMathBinaryWriter> )
##
InstallMethod( PrintObj, "for IsOpenMathBinaryWriter",
[ IsOpenMathBinaryWriter ],
function( obj )
Print( "<OpenMath binary writer to ", obj![1], ">" );
end);
###########################################################################
##
#M PrintObj( <IsOpenMathXMLWriter> )
##
InstallMethod( PrintObj, "for IsOpenMathXMLWriter",
[ IsOpenMathXMLWriter ],
function( obj )
Print( "<OpenMath XML writer to ", obj![1], ">" );
end);
###########################################################################
#
# RandomString( <n> )
#
# This function generates a random string of the length n
# It is needed in particular to create references,
# and also used in SCSCP package to generate random call identifiers
# Creation of OpenMathRealRandomSource is placed inside the function
# to avoid its early call when IO is not fully loaded (Error happens
# if GAP is started with "gap -r -A" and then LoadPackage("scscp");
# is entered.
#
BindGlobal( "RandomString", function( n )
local symbols, i;
symbols := "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
if IsBound( OpenMathRealRandomSource ) then
if IsRandomSource( OpenMathRealRandomSource ) then
return List( [1..n], i -> Random( OpenMathRealRandomSource, symbols) );
fi;
fi;
MakeReadWriteGlobal( "OpenMathRealRandomSource" );
UnbindGlobal( "OpenMathRealRandomSource" );
BindGlobal( "OpenMathRealRandomSource", RandomSource( IsRealRandomSource, "urandom" ));
return List( [1..n], i -> Random( OpenMathRealRandomSource, symbols) );
end);
###########################################################################
##
## Compound OpenMath objects and main functionality
##
###########################################################################
##
#M OMPutError( <OMWriter>, <cd>, <name>, <list> )
##
## Input : cd, name as strings, list as a list
## Output:
## <OMA>
## <OMS cd=<cd> name=<name> />
## OMPut( <writer>, <list>[1] )
## OMPut( <writer>, <list>[2] )
## ...
## </OMA>
##
InstallGlobalFunction(OMPutError, function ( writer, cd, name, list )
local obj;
OMPutOME( writer );
OMPutSymbol( writer, cd, name );
for obj in list do
OMPut( writer, obj );
od;
OMPutEndOME( writer );
end);
###########################################################################
##
#M OMPutApplication( <OMWriter>, <cd>, <name>, <list> )
##
## Input : cd, name as strings, list as a list
## Output:
## <OMA>
## <OMS cd=<cd> name=<name> />
## OMPut( <writer>, <list>[1] )
## OMPut( <writer>, <list>[2] )
## ...
## </OMA>
##
InstallGlobalFunction(OMPutApplication, function ( writer, cd, name, list )
local obj;
OMPutOMA( writer );
OMPutSymbol( writer, cd, name );
for obj in list do
OMPut( writer, obj );
od;
OMPutEndOMA( writer );
end);
###########################################################################
##
#F OMPutObject( <OMWriter>, <obj> )
##
##
InstallGlobalFunction(OMPutObject, function( writer, x )
if IsClosedStream( writer![1] ) then
Error( "closed stream" );
fi;
if IsOutputTextStream( writer![1] ) then
SetPrintFormattingStatus( writer![1], false );
fi;
OMPutOMOBJ( writer );
OMPut( writer, x );
OMPutEndOMOBJ( writer );
end);
###########################################################################
##
#F OMPutObjectNoOMOBJtags( <OMWriter>, <obj> )
##
##
InstallGlobalFunction(OMPutObjectNoOMOBJtags, function( writer, x )
if IsClosedStream( writer![1] ) then
Error( "closed stream" );
fi;
if IsOutputTextStream( writer![1] ) then
SetPrintFormattingStatus( writer![1], false );
fi;
OMIndent := 0;
OMPut(writer, x);
end);
###########################################################################
##
#F OMPrint( <obj> ) ....................... Print <obj> as OpenMath object
##
##
InstallGlobalFunction( OMPrint, function( arg )
local str, outstream, writer;
str := "";
outstream := OutputTextString(str, true);
writer := OpenMathXMLWriter( outstream );
if Length( arg ) = 1 then
OMPutObject(writer, arg[1] );
elif Length( arg ) = 2 then
OMPutObject(writer, arg[1], arg[2] );
else
Error("OpenMath : OMPrint accepts only 1 or 2 arguments!!!\n");
fi;
CloseStream(outstream);
Print(str);
end);
###########################################################################
##
## OMString( <obj> ) .......... Return string with <obj> as OpenMath object
##
InstallGlobalFunction( OMString, function ( x )
local noomobj, str, outstream;
if ValueOption("noomobj") <> fail then
noomobj := true;
else
noomobj := false;
fi;
str := "";
outstream := OutputTextString( str, true );
if noomobj then
OMPutObjectNoOMOBJtags( OpenMathXMLWriter(outstream), x );
else
OMPutObject( OpenMathXMLWriter(outstream), x );
fi;
CloseStream( outstream );
NormalizeWhitespace( str );
return str;
end);
###########################################################################
##
## Various methods for OMPut
##
###########################################################################
##
#M OMPut( <OMWriter>, <bool> )
##
## Printing for booleans: specified in CD nums # now logic1
##
InstallMethod(OMPut, "for a boolean", true,
[ IsOpenMathWriter, IsBool ], 0,
function(writer, x)
if not x in [ true, false ] then
TryNextMethod();
fi;
OMPutSymbol( writer, "logic1", String(x) );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <rat> )
##
## Printing for rationals
##
InstallMethod( OMPut, "for a rational", true,
[ IsOpenMathWriter, IsRat ],0,
function( writer, x )
OMPutApplication( writer, "nums1", "rational",
[ NumeratorRat(x), DenominatorRat(x)] );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <resclass> )
##
## Printing for residue classes
##
InstallMethod( OMPut, "for a residue class", true,
[ IsOpenMathWriter, IsZmodnZObj ],0,
function( writer, x )
OMPutApplication( writer, "integer2", "class",
[ x![1], FamilyObj(x)!.modulus ] );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <cyc> )
##
## Printing for cyclotomics
##
InstallMethod( OMPut, "for a proper cyclotomic", true,
[ IsOpenMathWriter, IsCyc ],0,
function( writer, x )
local
real,
imaginary,
n, # Length(powlist)
i,
clist; # x = Sum_i clist[i]*E(n)^(i-1)
if IsGaussRat( x ) then
real := x -> (x + ComplexConjugate( x )) / 2;
imaginary := x -> (x - ComplexConjugate( x )) * -1 / 2 * E( 4 );
OMPutApplication( writer, "complex1", "complex_cartesian",
[ real(x), imaginary(x)] );
else
n := Conductor(x);
clist := CoeffsCyc(x, n);
OMPutOMA(writer);
OMPutSymbol( writer, "arith1", "plus" );
for i in [1 .. n] do
if clist[i] <> 0 then
OMPutOMA(writer); # times
OMPutSymbol( writer, "arith1", "times" );
OMPut(writer, clist[i]);
OMPutApplication( writer, "algnums", "NthRootOfUnity", [ n, i-1 ] );
OMPutEndOMA(writer); #times
fi;
od;
OMPutEndOMA(writer);
fi;
end);
###########################################################################
##
#M OMPut( <OMWriter>, <infinity> )
##
## Printing for infinity: specified in nums1.ocd
##
InstallMethod(OMPut, "for infinity", true,
[ IsOpenMathWriter, IsInfinity ],0,
function(writer, x)
OMPutSymbol( writer, "nums1", "infinity" );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <vector> )
##
## Printing for vectors: specified in linalg2.ocd
##
#InstallMethod(OMPut, "for a row vector", true,
#[IsOpenMathWriter, IsRowVector],0,
#function(writer, x)
#
# OMPutApplication( writer, "linalg2", "vector", x );
#
#end);
###########################################################################
##
#M OMPut( <OMWriter>, <matrix> )
##
## Printing for matrices: specified in linalg2.ocd
##
InstallMethod(OMPut, "for a matrix", true,
[IsOpenMathWriter, IsMatrix],0,
function(writer, x)
local r;
OMPutOMA(writer);
if ValueOption( "OMignoreMatrices" ) = true or not IsRectangularTable(x) then
OMPutSymbol( writer, "list1", "list" );
for r in x do
OMPutApplication( writer, "list1", "list", r );
od;
else
OMPutSymbol( writer, "linalg2", "matrix" );
for r in x do
OMPutApplication( writer, "linalg2", "matrixrow", r );
od;
fi;
OMPutEndOMA(writer);
end);
###########################################################################
##
#M OMPut( <OMWriter>, NonnegativeIntegers )
##
## Printing for the set N
##
InstallMethod(OMPut, "for NonnegativeIntegers", true,
[IsOpenMathWriter, IsNonnegativeIntegers],0,
function(writer, x)
OMPutSymbol( writer, "setname1", "N" );
end);
###########################################################################
##
#M OMPut( <OMWriter>, Integers )
##
## Printing for the set Z
##
InstallMethod(OMPut, "for Integers", true,
[IsOpenMathWriter, IsIntegers],0,
function(writer, x)
OMPutSymbol( writer, "setname1", "Z" );
end);
###########################################################################
##
#M OMPut( <OMWriter>, Rationals )
##
## Printing for the set Q
##
InstallMethod(OMPut, "for Rationals", true,
[IsOpenMathWriter, IsRationals],0,
function(writer, x)
OMPutSymbol( writer, "setname1", "Q" );
end);
###########################################################################
##
#F OMPutListVar( <stream>, <list> )
##
##
BindGlobal("OMPutListVar", function(writer, x)
local i;
OMPutOMA( writer );
OMPutSymbol( writer, "list1", "list" );
for i in x do
OMPutVar(writer, i);
od;
OMPutEndOMA( writer );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <list> )
##
## Printing for finite lists or collection. Prints them as lists.
##
##
InstallMethod(OMPut, "for a finite list or collection", true,
[IsOpenMathWriter, IsListOrCollection and IsFinite], 0,
function(writer, x)
if IsBlist(x) then
OMPutByteArray( writer, x);
else
OMPutApplication( writer, "list1", "list", x );
fi;
end);
###########################################################################
##
#M OMPut( <OMWriter>, <set> )
##
## Printing for finite set: specified in set1.ocd
##
InstallMethod(OMPut, "for a finite set", true,
[IsOpenMathWriter, IsDuplicateFreeList and IsFinite],0,
function(writer, x)
if IsString(x) and Length(x)>0 or IsEmptyString(x) then
# this doesn't include the empty list
TryNextMethod();
fi;
if ValueOption( "OMignoreSets" ) = true then
OMPutApplication( writer, "list1", "list", x );
else
if IsEmpty(x) then
OMPutSymbol( writer, "set1", "emptyset" );
else
OMPutApplication( writer, "set1", "set", x );
fi;
fi;
end);
###########################################################################
##
#M OMPut( <OMWriter>, <range> )
##
## Printing for ranges: specified in interval1.ocd
##
InstallMethod(OMPut, "for a range", true,
[IsOpenMathWriter, IsRange and IsRangeRep],0,
function ( writer, x )
if not x[2] - x[1] = 1 then
TryNextMethod();
fi;
OMPutApplication( writer, "interval1", "integer_interval",
[ x[1], x[Length( x )] ] );
end);
###########################################################################
##
#M OMPut( <OMWriter>, <group> )
##
## Printing permutation group as specified in permgp1.group symbol
##
InstallMethod(OMPut, "for a permutation group", true,
[IsOpenMathWriter, IsPermGroup],0,
function(writer, x)
local g;
OMPutOMA(writer);
OMPutSymbol( writer, "permgp1", "group" );
OMPutSymbol( writer, "permutation1", "right_compose" );
for g in GeneratorsOfGroup(x) do
OMPut( writer, g );
od;
OMPutEndOMA(writer);
end);
###########################################################################
##
#M OMPut( <OMWriter>, <semigrouphom> )
##
## this requires MONOID so will not work in GAP 4.5
if not CompareVersionNumbers( GAPInfo.Version, "4.5.0") then
InstallMethod(OMPut, "for a semigroup homomorphism given by images of generators", true,
[IsOpenMathWriter, IsSemigroupHomomorphism and IsSemigroupHomomorphismByImagesOfGensRep],0,
function(writer, x)
local g;
OMPutOMA(writer);
OMPutSymbol( writer, "semigroup4", "homomorphism_by_generators" );
OMPut(writer, Source(x) );
OMPut(writer, Range(x) );
if IsMonoid( Source(x) ) then
OMPut(writer, List( GeneratorsOfMonoid( Source( x ) ), g -> [ g, g^x ] ) );
elif IsSemigroup( Source(x) ) then
OMPut(writer, List( GeneratorsOfSemigroup( Source( x ) ), g -> [ g, g^x ] ) );
else
Error( "OMPut for a semigroup homomorphism given by images of generators: can not output ", x );
fi;
OMPutEndOMA(writer);
end);
fi;
###########################################################################
#
# OMPut for a univariate polynomial (polyu.poly_u_rep)
#
# This was written for Mickael Gastineau to quickly achieve compatibility
# with the TRIP system and later was commented out because of switching
# to the 'polyd1' CD.
#
#InstallMethod( OMPut, "for a univariate polynomial (polyu.poly_u_rep)",
#true,
#[ IsOpenMathWriter, IsUnivariatePolynomial ],
#0,
#function( writer, f )
#local coeffs, deg, nr;
#OMPutOMA(writer);
#OMPutSymbol( writer, "polyu", "poly_u_rep" );
#OMPutVar( writer, IndeterminateOfUnivariateRationalFunction(f) );
#coeffs := CoefficientsOfUnivariatePolynomial(f);
#deg := DegreeOfLaurentPolynomial(f);
#for nr in [ deg+1, deg .. 1 ] do
# if coeffs[nr] <> 0 then
# OMPutApplication( writer, "polyu", "term", [ nr-1, coeffs[nr] ] );
# fi;
#od;
#OMPutEndOMA(writer);
#end);
###########################################################################
#
# OMPut for an algebraic element of an algebraic extension
# (commented out because of switching to field4.field_by_poly_vector)
#
#InstallMethod( OMPut, "for an algebraic element of an algebraic extension",
#true,
#[ IsOpenMathWriter, IsAlgebraicElement ],
#0,
#function( writer, a )
#local fam, anam, ext, c, i, is_plus, is_times, is_power;
#fam := FamilyObj( a );
#anam := fam!.indeterminateName;
#ext := ExtRepOfObj(a);
#if Length( Filtered( ext, c -> not IsZero(c) ) ) > 1 then
# is_plus := true;
# OMPutOMA(writer);
# OMPutSymbol( writer, "arith1", "plus" );
#else
# is_plus := false;
#fi;
#for i in [ 1 .. Length(ext) ] do
# if ext[i] <> fam!.baseZero then
# if i=1 then
# OMPut( writer, ext[i] );
# else
# if ext[i] <> fam!.baseOne then
# is_times := true;
# OMPutOMA(writer);
# OMPutSymbol( writer, "arith1", "times" );
# OMPut( writer, ext[i] );
# else
# is_times := false;
# fi;
# if i>2 then
# is_power:=true;
# OMPutOMA(writer);
# OMPutSymbol( writer, "arith1", "power" );
# else
# is_power := false;
# fi;
# OMPutVar( writer, anam );
# if is_power then
# OMPut( writer, i-1 );
# OMPutEndOMA(writer);
# fi;
# if is_times then
# OMPutEndOMA(writer);
# fi;
# fi;
# fi;
#od;
#if is_plus then
# OMPutEndOMA(writer);
#fi;
#end);
###########################################################################
##
#M OMPut( <stream>, <hasse diagram> )
##
## Addendum to GAP OpenMath phrasebook.
##
InstallMethod(OMPut, "for a Hasse diagram", true,
[IsOpenMathWriter,IsHasseDiagram],0,
function(writer, x)
local d, i;
d := UnderlyingDomainOfBinaryRelation(x);
# OMWriteLine(writer![1], ["<OMBIND>"]);
OMPutOMBIND(writer);
OMIndent := OMIndent +1;
OMPutSymbol(writer, "fns2", "constant");
# OMWriteLine(writer![1], ["<OMBVAR>"]);
OMPutOMBVAR(writer);
OMIndent := OMIndent +1;
for i in d do
OMPutVar(writer, i);
od;
OMIndent := OMIndent -1;
# OMWriteLine(writer![1], ["</OMBVAR>"]);
OMPutEndOMBVAR(writer);
OMPutOMA( writer );
OMPutSymbol(writer, "relation2", "hasse_diagram");
for i in d do
OMPutOMA( writer );
OMPutSymbol(writer, "list1", "list");
OMPutVar(writer, i);
OMPutListVar(writer, ImagesElm(x, i));
OMPutEndOMA( writer );
od;
OMPutEndOMA( writer );
OMIndent := OMIndent -1;
# OMWriteLine(writer![1], ["</OMBIND>"]);
OMPutEndOMBIND(writer);
end);
###########################################################################
#
# OMPut for a polynomial ring (polyd1.poly_ring_d_named / polyd1.poly_ring_d)
#
InstallMethod( OMPut, "for a polynomial ring (polyd1.poly_ring_d_named or polyd1.poly_ring_d)",
true,
[ IsOpenMathWriter, IsPolynomialRing ],
0,
function( writer, r )
if Length( IndeterminatesOfPolynomialRing( r ) ) = 1 then
SetOMReference( r, Concatenation("polyring", RandomString(16) ) );
OMPutOMAWithId( writer, OMReference(r) );
OMIndent := OMIndent + 1;
OMPutSymbol( writer, "polyd1", "poly_ring_d_named" );
OMPut( writer, CoefficientsRing( r ) );
OMPutVar( writer, IndeterminatesOfPolynomialRing( r )[1] );
OMPutEndOMA(writer);
else
SetOMReference( r, Concatenation("polyring", RandomString(16) ) );
OMPutOMAWithId( writer, OMReference(r) );
OMIndent := OMIndent + 1;
OMPutSymbol( writer, "polyd1", "poly_ring_d" );
OMPut( writer, CoefficientsRing( r ) );
OMPut( writer, Length( IndeterminatesOfPolynomialRing( r ) ) );
OMPutEndOMA(writer);
fi;
end);
###########################################################################
#
# OMPut for a polynomial ring and a (uni/multivariate) polynomial (polyd1.DMP)
#
InstallOtherMethod( OMPut, "for a polynomial ring and a (uni- or multivariate) polynomial (polyd1.DMP)",
true,
[ IsOpenMathWriter, IsPolynomialRing, IsPolynomial ],
0,
function( writer, r, f )
local coeffs, deg, nr, coeffring, nrindet, extrep, nvars, pows, i, pos;
if not f in r then
Error( "OMPut : the polynomial ", f, " is not in the polynomial ring ", r, "\n" );
fi;
coeffring := CoefficientsRing( r );
if Length( IndeterminatesOfPolynomialRing( r ) ) = 1 then
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "DMP" );
OMPutReference( writer, r );
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "SDMP" );
coeffs := CoefficientsOfUnivariatePolynomial( f );
deg := DegreeOfLaurentPolynomial( f );
# The zero polynomial is represented by an SDMP with no terms.
if deg<>infinity then
if IsField(coeffring) and IsFinite(coeffring) then
# The part for polynomials over finite fields
# to tell which field to use. To speed up, the
# check is outside the loop
for nr in [ deg+1, deg .. 1 ] do
if coeffs[nr] <> 0 then
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "term" );
OMPut( writer, coeffring, coeffs[nr] );
OMPut( writer, nr-1 );
OMPutEndOMA(writer);
fi;
od;
else
for nr in [ deg+1, deg .. 1 ] do
if coeffs[nr] <> 0 then
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "term" );
OMPut( writer, coeffs[nr] );
OMPut( writer, nr-1 );
OMPutEndOMA(writer);
fi;
od;
fi;
fi;
OMPutEndOMA(writer);
OMPutEndOMA(writer);
else
nrindet := Length(IndeterminatesOfPolynomialRing( r ) );
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "DMP" );
OMPutReference( writer, r );
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "SDMP" );
extrep := ExtRepPolynomialRatFun( f );
if IsField(coeffring) and IsFinite(coeffring) then
# The part for polynomials over finite fields
# to tell which field to use
for nr in [ 1, 3 .. Length(extrep)-1 ] do
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "term" );
OMPut( writer, coeffring, extrep[nr+1] ); # the coefficient
nvars := extrep[nr]{[1,3..Length(extrep[nr])-1]};
pows := extrep[nr]{[2,4..Length(extrep[nr])]};
for i in [1..nrindet] do
pos := Position( nvars, i );
if pos=fail then
OMPut( writer, 0 );
else
OMPut( writer, pows[pos] );
fi;
od;
OMPutEndOMA(writer);
od;
else
for nr in [ 1, 3 .. Length(extrep)-1 ] do
OMPutOMA(writer);
OMPutSymbol( writer, "polyd1", "term" );
OMPut( writer, extrep[nr+1] ); # the coefficient
nvars := extrep[nr]{[1,3..Length(extrep[nr])-1]};
pows := extrep[nr]{[2,4..Length(extrep[nr])]};
for i in [1..nrindet] do
pos := Position( nvars, i );
if pos=fail then
OMPut( writer, 0 );
else
OMPut( writer, pows[pos] );
fi;
od;
OMPutEndOMA(writer);
od;
fi;
OMPutEndOMA(writer);
OMPutEndOMA(writer);
fi;
end);
###########################################################################
#
# OpenMathDefaultPolynomialRing and tools for its resetting
#
BindGlobal( "OpenMathDefaultPolynomialRing", [ ] );
BindGlobal( "SetOpenMathDefaultPolynomialRing", function( R )
if not IsPolynomialRing(R) then
Error("The argument must be a polynomial ring\n");
fi;
MakeReadWriteGlobal( "OpenMathDefaultPolynomialRing" );
OpenMathDefaultPolynomialRing := R;
MakeReadOnlyGlobal( "OpenMathDefaultPolynomialRing" );
end);
###########################################################################
#
# OMPut for a (uni/multivariate) polynomial in the default ring or
# in OpenMathDefaultPolynomialRing, using polyd1.DMP
#
InstallMethod( OMPut, "for a (uni- or multivariate) polynomial in the default ring (polyd1.DMP)",
true,
[ IsOpenMathWriter, IsPolynomial ],
0,
function( writer, f )
if f in OpenMathDefaultPolynomialRing then
OMPut( writer, OpenMathDefaultPolynomialRing, f );
else
Print("#I Warning : polynomial will be printed using its default ring \n",
"#I because the default OpenMath polynomial ring is not specified \n",
"#I or it is not contained in the default OpenMath polynomial ring.\n",
"#I You may ignore this or call SetOpenMathDefaultPolynomialRing to fix it.\n");
OMPut( writer, DefaultRing( f ), f );
fi;
end);
###########################################################################
#
# OMput for a two-sided ideal with known generators (ring3.ideal)
#
# This currently works only with polynomial rings!!!
#
InstallMethod( OMPut, "for a two-sided ideal with known generators (ring3.ideal)",
true,
[ IsOpenMathWriter,
IsRing and HasLeftActingRingOfIdeal and
HasRightActingRingOfIdeal and HasGeneratorsOfTwoSidedIdeal ],
0,
function( writer, r )
local f;
OMPutOMA(writer);
OMPutSymbol( writer, "ring3", "ideal" );
OMPut( writer, LeftActingRingOfIdeal( r ) );
OMPutOMA(writer);
OMPutSymbol( writer, "list1", "list" );
for f in GeneratorsOfTwoSidedIdeal( r ) do
OMPut( writer, LeftActingRingOfIdeal( r ), f );
od;
OMPutEndOMA(writer);
OMPutEndOMA(writer);
end);
###########################################################################
#
# OMPut for algebraic extensions (field3.field_by_poly)
#
InstallMethod( OMPut, "for algebraic extensions (field3.field_by_poly)",
true,
[ IsOpenMathWriter, IsAlgebraicExtension ],
0,
function( writer, f )
OMPutOMA(writer);
OMPutSymbol( writer, "field3", "field_by_poly" );
OMPut( writer, LeftActingDomain( f ) );
OMPut( writer, DefiningPolynomial( f ) );
OMPutEndOMA(writer);
end);
###########################################################################
#
# OMPut for an algebraic element of an algebraic extension
# (field4.field_by_poly_vector)
#
InstallMethod( OMPut, "for an algebraic element of an algebraic extension (field4.field_by_poly_vector)",
true,
[ IsOpenMathWriter, IsAlgebraicElement ],
0,
function( writer, a )
OMPutOMA(writer);
OMPutSymbol( writer, "field4", "field_by_poly_vector" );
OMPutOMA(writer);
OMPutSymbol( writer, "field3", "field_by_poly" );
OMPut( writer, FamilyObj(a)!.baseField );
OMPut( writer, FamilyObj(a)!.poly );
OMPutEndOMA(writer);
OMPut( writer, ExtRepOfObj(a) );
OMPutEndOMA(writer);
end);
###########################################################################
#
# OMPut for a finite field and its element using finfield1 CD
#
InstallOtherMethod( OMPut, "for for a finite field element using finfield1 CD",
true,
[ IsOpenMathWriter, IsField and IsFinite, IsFFE ],
0,
function( writer, f, a )
if IsZero(a) then
OMPutOMA(writer);
OMPutSymbol( writer, "arith1", "times" );
OMPutOMA(writer);
OMPutSymbol( writer, "finfield1", "primitive_element" );
OMPut( writer, Size( f ) );
OMPutEndOMA(writer);
OMPut( writer, 0 );
OMPutEndOMA(writer);
else
OMPutOMA(writer);
OMPutSymbol( writer, "arith1", "power" );
OMPutOMA(writer);
OMPutSymbol( writer, "finfield1", "primitive_element" );
OMPut( writer, Size( f ) );
OMPutEndOMA(writer);
OMPut( writer, LogFFE( a, PrimitiveRoot( f ) ) );
OMPutEndOMA(writer);
fi;
end);
###########################################################################
#
# OMPut for a finite field element in its default field
#
InstallMethod( OMPut, "for for a finite field element using finfield1 CD",
true,
[ IsOpenMathWriter, IsFFE ],
0,
function( writer, a )
OMPut( writer, DefaultField( a ), a );
end);
###########################################################################
#
# OMPut for a finite field using setname2.{GFp,GFpn}
#
InstallMethod( OMPut, "for for a finite field using setname2.GFp or setname2.GFpn",
true,
[ IsOpenMathWriter, IsField ],
0,
function( writer, f )
OMPutOMA(writer);
if IsPrimeInt( Size( f ) ) then
OMPutSymbol( writer, "setname2", "GFp" );
OMPut( writer, Size( f ) );
else
OMPutSymbol( writer, "setname2", "GFpn" );
OMPut( writer, Characteristic( f ) );
OMPut( writer, DegreeOverPrimeField( f ) );
fi;
OMPutEndOMA(writer);
end);
#######################################################################
##
#M OMPut( <OMWriter>, <perm> )
##
## Printing for permutations: specified in permut1.ocd
##
InstallMethod(OMPut, "for a permutation", true,
[IsOpenMathWriter, IsPerm],0,
function(writer, x)
OMPutApplication( writer, "permut1", "permutation", ListPerm(x) );
end);
# The method was commented out before OMsymTable was converted into
# OMsymRecord, however, it was updated it as well to save the changes
# for a case. Note that the search across all record components is very
# inefficient.
#
#InstallMethod(OMPut, "for a function", true,
#[IsOpenMathWriter, IsFunction],0,
#function ( writer, x )
# local cd, name;
# for cd in RecNames( OMsymRecord ) do
# for name in RecNames( OMsymRecord.(cd) ) do
# if x = OMsymRecord.(cd).(name) then
# OMPutSymbol( writer, cd, name );
# return;
# fi;
# od;
# od;
# TryNextMethod();
#end);
###########################################################################
##
#M OMPutList( <OMWriter>, <list> )
##
##
InstallMethod(OMPutList, "for a list of any type", true,
[IsOpenMathWriter, IsList],0,
function(writer, x)
local i;
OMPutOMA(writer);
OMPutSymbol( writer, "list1", "list" );
for i in x do
if IsString(i) then
OMPut(writer, i); # no such thing as characters in OpenMath
else
OMPutList(writer, i);
fi;
od;
OMPutEndOMA(writer);
end);
###########################################################################
##
#M OMPutList( <OMWriter>, <list> )
##
##
InstallMethod(OMPutList, "when we can find no way of regarding it as a list",
true, [IsOpenMathWriter, IsObject],0,
function(writer, x)
OMPut(writer, x);
end);
###########################################################################
#E
|