CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
3 Watch and Influence the Communication
3
4
5
3.1 Functions
6
7
3.1-1 homalgIOMode
8
9
homalgIOMode( str[, str2[, str3]] )  function
10
11
This function sets different modes which influence how much of the
12
communication becomes visible. Handling the string str is not
13
case-sensitive. homalgIOMode invokes the global function homalgMode defined
14
in the homalg package with an appropriate argument (see code below).
15
Alternatively, if a second or more strings are given, then homalgMode is
16
invoked with the remaining strings str2, str3, ... at the end. In
17
particular, you can use homalgIOMode( str, "" ) to reset the effect of
18
invoking homalgMode.
19
20
str │ str (long form) │ mode description
21
────┼─────────────────┼───────────────────────────────────────────────────────────────────
22
│ │
23
"" │ "" │ the default mode, i.e. the communication protocol won't be visible
24
│ │ (homalgIOMode( ) is a short form for homalgIOMode( "" ))
25
│ │
26
"a" │ "all" │ combine the modes "debug" and "file"
27
│ │
28
"b" │ "basic" │ the same as "picto" + homalgMode( "basic" )
29
│ │
30
"d" │ "debug" │ view the complete communication protocol
31
│ │
32
"f" │ "file" │ dump the communication protocol into a file with the name
33
│ │ Concatenation( "commands_file_of_", CAS, "_with_PID_", PID )
34
│ │
35
"p" │ "picto" │ view the abbreviated communication protocol
36
│ │ using the preassigned pictograms
37
│ │
38
────┴─────────────────┴───────────────────────────────────────────────────────────────────
39
40
All modes other than the "default"-mode only set their specific values and
41
leave the other values untouched, which allows combining them to some
42
extent. This also means that in order to get from one mode to a new mode
43
(without the aim to combine them) one needs to reset to the "default"-mode
44
first.
45
Caution:
46
47
 In case you choose one of the modes "file" or "all" you might want to
48
set the global variable HOMALG_IO.DoNotDeleteTemporaryFiles := true;
49
this is only important if during the computations some matrices get
50
converted via files (using ConvertHomalgMatrixViaFile), as reading
51
these files will be part of the protocol!
52
53
 It makes sense for the dumped communication protocol to be
54
(re)executed with the respective external system, only in case the
55
latter is deterministic (i.e. same-input-same-output).
56
57
 Code 
58
InstallGlobalFunction( homalgIOMode,
59
 function( arg )
60
 local nargs, mode, s;
61
 
62
 nargs := Length( arg );
63
 
64
 if nargs = 0 or ( IsString( arg[1] ) and arg[1] = "" ) then
65
 mode := "default";
66
 elif IsString( arg[1] ) then ## now we know, the string is not empty
67
 s := arg[1];
68
 if LowercaseString( s{[1]} ) = "a" then
69
 mode := "all";
70
 elif LowercaseString( s{[1]} ) = "b" then
71
 mode := "basic";
72
 elif LowercaseString( s{[1]} ) = "d" then
73
 mode := "debug";
74
 elif LowercaseString( s{[1]} ) = "f" then
75
 mode := "file";
76
 elif LowercaseString( s{[1]} ) = "p" then
77
 mode := "picto";
78
 else
79
 mode := "";
80
 fi;
81
 else
82
 Error( "the first argument must be a string\n" );
83
 fi;
84
 
85
 if mode = "default" then
86
 ## reset to the default values
87
 HOMALG_IO.color_display := false;
88
 HOMALG_IO.show_banners := true;
89
 HOMALG_IO.save_CAS_commands_to_file := false;
90
 HOMALG_IO.DoNotDeleteTemporaryFiles := false;
91
 HOMALG_IO.SaveHomalgMaximumBackStream := false;
92
 HOMALG_IO.InformAboutCASystemsWithoutActiveRings := true;
93
 SetInfoLevel( InfoHomalgToCAS, 1 );
94
 homalgMode( );
95
 elif mode = "all" then
96
 homalgIOMode( "debug" );
97
 homalgIOMode( "file" );
98
 elif mode = "basic" then
99
 HOMALG_IO.color_display := true;
100
 HOMALG_IO.show_banners := true;
101
 SetInfoLevel( InfoHomalgToCAS, 4 );
102
 homalgMode( "basic" ); ## use homalgIOMode( "basic", "" ) to reset
103
 elif mode = "debug" then
104
 HOMALG_IO.color_display := true;
105
 HOMALG_IO.show_banners := true;
106
 SetInfoLevel( InfoHomalgToCAS, 8 );
107
 homalgMode( "debug" ); ## use homalgIOMode( "debug", "" ) to reset
108
 elif mode = "file" then
109
 HOMALG_IO.save_CAS_commands_to_file := true;
110
 elif mode = "picto" then
111
 HOMALG_IO.color_display := true;
112
 HOMALG_IO.show_banners := true;
113
 SetInfoLevel( InfoHomalgToCAS, 4 );
114
 homalgMode( "logic" ); ## use homalgIOMode( "picto", "" ) to reset
115
 fi;
116
 
117
 if nargs > 1 and IsString( arg[2] ) then
118
 CallFuncList( homalgMode, arg{[ 2 .. nargs ]} );
119
 fi;
120
 
121
end );
122

123
124
This is the part of the global function homalgSendBlocking that controls the
125
visibility of the communication.
126
127
 Code 
128
io_info_level := InfoLevel( InfoHomalgToCAS );
129

130
if not IsBound( pictogram ) then
131
 pictogram := HOMALG_IO.Pictograms.unknown;
132
 picto := pictogram;
133
elif io_info_level >= 3 then
134
 picto := pictogram;
135
 ## add colors to the pictograms
136
 if pictogram = HOMALG_IO.Pictograms.ReducedEchelonForm and
137
 IsBound( HOMALG_MATRICES.color_BOE ) then
138
 pictogram := Concatenation( HOMALG_MATRICES.color_BOE, pictogram, "\033[0m" );
139
 elif pictogram = HOMALG_IO.Pictograms.BasisOfModule and
140
 IsBound( HOMALG_MATRICES.color_BOB ) then
141
 pictogram := Concatenation( HOMALG_MATRICES.color_BOB, pictogram, "\033[0m" );
142
 elif pictogram = HOMALG_IO.Pictograms.DecideZero and
143
 IsBound( HOMALG_MATRICES.color_BOD ) then
144
 pictogram := Concatenation( HOMALG_MATRICES.color_BOD, pictogram, "\033[0m" );
145
 elif pictogram = HOMALG_IO.Pictograms.SyzygiesGenerators and
146
 IsBound( HOMALG_MATRICES.color_BOH ) then
147
 pictogram := Concatenation( HOMALG_MATRICES.color_BOH, pictogram, "\033[0m" );
148
 elif pictogram = HOMALG_IO.Pictograms.BasisCoeff and
149
 IsBound( HOMALG_MATRICES.color_BOC ) then
150
 pictogram := Concatenation( HOMALG_MATRICES.color_BOC, pictogram, "\033[0m" );
151
 elif pictogram = HOMALG_IO.Pictograms.DecideZeroEffectively and
152
 IsBound( HOMALG_MATRICES.color_BOP ) then
153
 pictogram := Concatenation( HOMALG_MATRICES.color_BOP, pictogram, "\033[0m" );
154
 elif need_output or need_display then
155
 pictogram := Concatenation( HOMALG_IO.Pictograms.color_need_output,
156
 pictogram, "\033[0m" );
157
 else
158
 pictogram := Concatenation( HOMALG_IO.Pictograms.color_need_command,
159
 pictogram, "\033[0m" );
160
 fi;
161
else
162
 picto := pictogram;
163
fi;
164

165
if io_info_level >= 3 then
166
 if ( io_info_level >= 7 and not need_display ) or io_info_level >= 8 then
167
 ## print the pictogram, the prompt of the external system,
168
 ## and the sent command
169
 Info( InfoHomalgToCAS, 7, pictogram, " ", stream.prompt,
170
 L{[ 1 .. Length( L ) - 1 ]} );
171
 elif io_info_level >= 4 then
172
 ## print the pictogram and the prompt of the external system
173
 Info( InfoHomalgToCAS, 4, pictogram, " ", stream.prompt, "..." );
174
 else
175
 ## print the pictogram only
176
 Info( InfoHomalgToCAS, 3, pictogram );
177
 fi;
178
 
179
fi;
180

181
182
183
3.2 The Pictograms
184
185
3.2-1 HOMALG_IO.Pictograms
186
187
HOMALG_IO.Pictograms global variable
188
189
The record of pictograms is a component of the record HOMALG_IO.
190
191
 Code 
192
Pictograms := rec(
193
 
194
 ##
195
 ## colors:
196
 ##
197
 
198
 ## pictogram color of a "need_command" or assignment operation:
199
 color_need_command := "\033[1;33;44m",
200
 
201
 ## pictogram color of a "need_output" or "need_display" operation:
202
 color_need_output := "\033[1;34;43m",
203
 
204
 ##
205
 ## good morning computer algebra system:
206
 ##
207
 
208
 ## initialize:
209
 initialize := "ini",
210
 
211
 ## define macros:
212
 define := "def",
213
 
214
 ## get time:
215
 time := ":ms",
216
 
217
 ## memory usage:
218
 memory := "mem",
219
 
220
 ## unknown:
221
 unknown := "???",
222
 
223
 ##
224
 ## external garbage collection:
225
 ##
226
 
227
 ## delete a variable:
228
 delete := "xxx",
229
 
230
 ## delete serveral variables:
231
 multiple_delete := "XXX",
232
 
233
 ## trigger the garbage collector:
234
 garbage_collector := "grb",
235
 
236
 ##
237
 ## create lists:
238
 ##
239
 
240
 ## define a list:
241
 CreateList := "lst",
242
 
243
 ##
244
 ## create rings:
245
 ##
246
 
247
 ## define a ring:
248
 CreateHomalgRing := "R:=",
249
 
250
 ## get the names of the "variables" defining the ring:
251
 variables := "var",
252
 
253
 ## define zero:
254
 Zero := "0:=",
255
 
256
 ## define one:
257
 One := "1:=",
258
 
259
 ## define minus one:
260
 MinusOne := "-:=",
261
 
262
 ##
263
 ## mandatory ring operations:
264
 ##
265
 
266
 ## get the name of an element:
267
 ## (important if the CAS pretty-prints ring elements,
268
 ## we need names that can be used as input!)
269
 ## (install a method instead of a homalgTable entry)
270
 homalgSetName := "\"a\"",
271
 
272
 ## a = 0 ?
273
 IsZero := "a=0",
274
 
275
 ## a = 1 ?
276
 IsOne := "a=1",
277
 
278
 ## substract two ring elements
279
 ## (needed by SimplerEquivalentMatrix in case
280
 ## CopyRow/ColumnToIdentityMatrix are not defined):
281
 Minus := "a-b",
282
 
283
 ## divide the element a by the unit u
284
 ## (needed by SimplerEquivalentMatrix in case
285
 ## DivideEntryByUnit is not defined):
286
 DivideByUnit := "a/u",
287
 
288
 ## important ring operations:
289
 ## (important for performance since existing
290
 ## fallback methods cause a lot of traffic):
291
 
292
 ## is u a unit?
293
 ## (mainly needed by the fallback methods for matrices, see below):
294
 IsUnit := "?/u",
295
 
296
 ##
297
 ## optional ring operations:
298
 ##
299
 
300
 ## copy an element:
301
 CopyElement := "a>a",
302
 
303
 ## add two ring elements:
304
 Sum := "a+b",
305
 
306
 ## multiply two ring elements:
307
 Product := "a*b",
308
 
309
 ## the (greatest) common divisor:
310
 Gcd := "gcd",
311
 
312
 ## cancel the (greatest) common divisor:
313
 CancelGcd := "ccd",
314
 
315
 ## random polynomial:
316
 RandomPol := "rpl",
317
 
318
 ## numerator:
319
 Numerator := "num",
320
 
321
 ## denominator:
322
 Denominator := "den",
323
 
324
 ## evaluate polynomial:
325
 Evaluate := "evl",
326
 
327
 ## degree of a multivariate polynomial
328
 DegreeOfRingElement := "deg",
329
 
330
 ## is irreducible:
331
 IsIrreducible := "irr",
332
 
333
 ##
334
 ## create matrices:
335
 ##
336
 
337
 ## define a matrix:
338
 HomalgMatrix := "A:=",
339
 
340
 ## copy a matrix:
341
 CopyMatrix := "A>A",
342
 
343
 ## load a matrix from file:
344
 LoadHomalgMatrixFromFile := "A<<",
345
 
346
 ## save a matrix to file:
347
 SaveHomalgMatrixToFile := "A>>",
348
 
349
 ## get a matrix entry as a string:
350
 MatElm := "<ij",
351
 
352
 ## set a matrix entry from a string:
353
 SetMatElm := ">ij",
354
 
355
 ## add to a matrix entry from a string:
356
 AddToMatElm := "+ij",
357
 
358
 ## get a list of the matrix entries as a string:
359
 GetListOfHomalgMatrixAsString := "\"A\"",
360
 
361
 ## get a listlist of the matrix entries as a string:
362
 GetListListOfHomalgMatrixAsString := "\"A\"",
363
 
364
 ## get a "sparse" list of the matrix entries as a string:
365
 GetSparseListOfHomalgMatrixAsString := ".A.",
366
 
367
 ## assign a "sparse" list of matrix entries to a variable:
368
 sparse := "spr",
369
 
370
 ## list of assumed inequalities:
371
 Inequalities := "<>0",
372
 
373
 ## list of assumed inequalities:
374
 MaximalIndependentSet := "idp",
375
 
376
 ##
377
 ## mandatory matrix operations:
378
 ##
379
 
380
 ## test if a matrix is the zero matrix:
381
 ## CAUTION: the external system must be able to check
382
 ## if the matrix is zero modulo possible ring relations
383
 ## only known to the external system!
384
 IsZeroMatrix := "A=0",
385
 
386
 ## number of rows:
387
 NrRows := "#==",
388
 
389
 ## number of columns:
390
 NrColumns := "#||",
391
 
392
 ## determinant of a matrix over a (commutative) ring:
393
 Determinant := "det",
394
 
395
 ## create a zero matrix:
396
 ZeroMatrix := "(0)",
397
 
398
 ## create a initial zero matrix:
399
 InitialMatrix := "[0]",
400
 
401
 ## create an identity matrix:
402
 IdentityMatrix := "(1)",
403
 
404
 ## create an initial identity matrix:
405
 InitialIdentityMatrix := "[1]",
406
 
407
 ## "transpose" a matrix (with "the" involution of the ring):
408
 Involution := "A^*",
409
 
410
 ## get certain rows of a matrix:
411
 CertainRows := "===",
412
 
413
 ## get certain columns of a matrix:
414
 CertainColumns := "|||",
415
 
416
 ## stack to matrices vertically:
417
 UnionOfRows := "A_B",
418
 
419
 ## glue to matrices horizontally:
420
 UnionOfColumns := "A|B",
421
 
422
 ## create a block diagonal matrix:
423
 DiagMat := "A\\B",
424
 
425
 ## the Kronecker (tensor) product of two matrices:
426
 KroneckerMat := "AoB",
427
 
428
 ## multiply a ring element with a matrix:
429
 MulMat := "a*A",
430
 
431
 ## multiply a matrix with a ring element:
432
 MulMatRight := "A*a",
433
 
434
 ## add two matrices:
435
 AddMat := "A+B",
436
 
437
 ## substract two matrices:
438
 SubMat := "A-B",
439
 
440
 ## multiply two matrices:
441
 Compose := "A*B",
442
 
443
 ## pullback a matrix by a ring map:
444
 Pullback := "pbk",
445
 
446
 ##
447
 ## important matrix operations:
448
 ## (important for performance since existing
449
 ## fallback methods cause a lot of traffic):
450
 ##
451
 
452
 ## test if two matrices are equal:
453
 ## CAUTION: the external system must be able to check
454
 ## equality of the two matrices modulo possible ring relations
455
 ## only known to the external system!
456
 AreEqualMatrices := "A=B",
457
 
458
 ## test if a matrix is the identity matrix:
459
 IsIdentityMatrix := "A=1",
460
 
461
 ## test if a matrix is diagonal (needed by the display method):
462
 IsDiagonalMatrix := "A=\\",
463
 
464
 ## get the positions of the zero rows:
465
 ZeroRows := "0==",
466
 
467
 ## get the positions of the zero columns:
468
 ZeroColumns := "0||",
469
 
470
 ## get "column-independent" unit positions
471
 ## (needed by ReducedBasisOfModule):
472
 GetColumnIndependentUnitPositions := "ciu",
473
 
474
 ## get "row-independent" unit positions
475
 ## (needed by ReducedBasisOfModule):
476
 GetRowIndependentUnitPositions := "riu",
477
 
478
 ## get the position of the "first" unit in the matrix
479
 ## (needed by SimplerEquivalentMatrix):
480
 GetUnitPosition := "gup",
481
 
482
 ## position of the first non-zero entry per row
483
 PositionOfFirstNonZeroEntryPerRow := "fnr",
484
 
485
 ## position of the first non-zero entry per column
486
 PositionOfFirstNonZeroEntryPerColumn := "fnc",
487
 
488
 ## indicator matrix of non-zero entries
489
 IndicatorMatrixOfNonZeroEntries := "<>0",
490
 
491
 ## transposed matrix:
492
 TransposedMatrix := "^tr",
493
 
494
 ## divide an entry of a matrix by a unit
495
 ## (needed by SimplerEquivalentMatrix in case
496
 ## DivideRow/ColumnByUnit are not defined):
497
 DivideEntryByUnit := "ij/",
498
 
499
 ## divide a row by a unit
500
 ## (needed by SimplerEquivalentMatrix):
501
 DivideRowByUnit := "-/u",
502
 
503
 ## divide a column by a unit
504
 ## (needed by SimplerEquivalentMatrix):
505
 DivideColumnByUnit := "|/u",
506
 
507
 ## divide a row by a unit
508
 ## (needed by SimplerEquivalentMatrix):
509
 CopyRowToIdentityMatrix := "->-",
510
 
511
 ## divide a column by a unit
512
 ## (needed by SimplerEquivalentMatrix):
513
 CopyColumnToIdentityMatrix := "|>|",
514
 
515
 ## set a column (except a certain row) to zero
516
 ## (needed by SimplerEquivalentMatrix):
517
 SetColumnToZero := "|=0",
518
 
519
 ## get the positions of the rows with a single one
520
 ## (needed by SimplerEquivalentMatrix):
521
 GetCleanRowsPositions := "crp",
522
 
523
 ## convert a single row matrix into a matrix
524
 ## with specified number of rows/columns
525
 ## (needed by the display methods for homomorphisms):
526
 ConvertRowToMatrix := "-%A",
527
 
528
 ## convert a single column matrix into a matrix
529
 ## with specified number of rows/columns
530
 ## (needed by the display methods for homomorphisms):
531
 ConvertColumnToMatrix := "|%A",
532
 
533
 ## convert a matrix into a single row matrix:
534
 ConvertMatrixToRow := "A%-",
535
 
536
 ## convert a matrix into a single column matrix:
537
 ConvertMatrixToColumn := "A%|",
538
 
539
 ##
540
 ## basic matrix operations:
541
 ##
542
 
543
 ## compute a (r)educed (e)chelon (f)orm:
544
 ReducedEchelonForm := "ref",
545
 
546
 ## compute a "(bas)is" of a given set of module elements:
547
 BasisOfModule := "bas",
548
 
549
 ## compute a reduced "(Bas)is" of a given set of module elements:
550
 ReducedBasisOfModule := "Bas",
551
 
552
 ## (d)e(c)ide the ideal/submodule membership problem,
553
 ## i.e. if an element is (0) modulo the ideal/submodule:
554
 DecideZero := "dc0",
555
 
556
 ## compute a generating set of (syz)ygies:
557
 SyzygiesGenerators := "syz",
558
 
559
 ## compute a generating set of reduced (Syz)ygies:
560
 ReducedSyzygiesGenerators := "Syz",
561
 
562
 ## compute a (R)educed (E)chelon (F)orm
563
 ## together with the matrix of coefficients:
564
 ReducedEchelonFormC := "REF",
565
 
566
 ## compute a "(BAS)is" of a given set of module elements
567
 ## together with the matrix of coefficients:
568
 BasisCoeff := "BAS",
569
 
570
 ## (D)e(C)ide the ideal/submodule membership problem,
571
 ## i.e. write an element effectively as (0) modulo the ideal/submodule:
572
 DecideZeroEffectively := "DC0",
573
 
574
 ##
575
 ## optional matrix operations:
576
 ##
577
 
578
 ## Hilbert-Poincare series of a module:
579
 HilbertPoincareSeries := "HPs",
580
 
581
 ## Hilbert polynomial of a module:
582
 HilbertPolynomial := "Hil",
583
 
584
 ## affine dimension of a module:
585
 AffineDimension := "dim",
586
 
587
 ## affine degree of a module:
588
 AffineDegree := "adg",
589
 
590
 ## the constant term of the hilbert polynomial:
591
 ConstantTermOfHilbertPolynomial := "P_0",
592
 
593
 ## primary decomposition:
594
 PrimaryDecomposition := "YxZ",
595
 
596
 ## eliminate variables:
597
 Eliminate := "eli",
598
 
599
 ## leading module:
600
 LeadingModule := "led",
601
 
602
 ## the i-th monomial matrix
603
 MonomialMatrix := "mon",
604
 
605
 ## matrix of symbols:
606
 MatrixOfSymbols := "smb",
607
 
608
 ## leading module:
609
 ## coefficients:
610
 Coefficients := "cfs",
611
 
612
 ##
613
 ## optional module operations:
614
 ##
615
 
616
 ## compute a better equivalent matrix
617
 ## (field -> row+col Gauss, PIR -> Smith, Dedekind domain -> Krull, etc ...):
618
 BestBasis := "(\\)",
619
 
620
 ## compute elementary divisors:
621
 ElementaryDivisors := "div",
622
 
623
 ##
624
 ## for the eye:
625
 ##
626
 
627
 ## display objects:
628
 Display := "dsp",
629
 
630
 ## the LaTeX code of the mathematical entity:
631
 homalgLaTeX := "TeX",
632
 
633
)
634

635
636
637