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
E Debugging MatricesForHomalg
3
4
Beside the GAP builtin debugging facilities (--> 'Reference: Debugging and
5
Profiling Facilities') MatricesForHomalg provides two ways to debug the
6
computations.
7
8
9
E.1 Increase the assertion level
10
11
MatricesForHomalg comes with numerous builtin assertion checks. They are
12
activated if the user increases the assertion level using
13
SetAssertionLevel( level );
14
(--> 'Reference: SetAssertionLevel'), where level is one of the values
15
below:
16
17
level │ description
18
──────┼──────────────────────────────────────────────────────────────────────
19
20
0 │ no assertion checks whatsoever
21
22
4 │ assertions about basic matrix operations are checked (--> Appendix A)
23
│ (these are among the operations often delegated to external systems)
24
25
──────┴──────────────────────────────────────────────────────────────────────
26
27
In particular, if MatricesForHomalg delegates matrix operations to an
28
external system then SetAssertionLevel( 4 ); can be used to let
29
MatricesForHomalg debug the external system.
30
Below you can find the record of the available level-4 assertions, which is
31
a GAP-component of every homalg ring. Each assertion can thus be overwritten
32
by package developers or even ordinary users.
33
34
 Code 
35
asserts :=
36
 rec(
37
 BasisOfRowModule :=
38
 function( B ) return ( NrRows( B ) = 0 ) = IsZero( B ); end,
39
 
40
 BasisOfColumnModule :=
41
 function( B ) return ( NrColumns( B ) = 0 ) = IsZero( B ); end,
42
 
43
 BasisOfRowsCoeff :=
44
 function( B, T, M ) return B = T * M; end,
45
 
46
 BasisOfColumnsCoeff :=
47
 function( B, M, T ) return B = M * T; end,
48
 
49
 DecideZeroRows_Effectively :=
50
 function( M, A, B ) return M = DecideZeroRows( A, B ); end,
51
 
52
 DecideZeroColumns_Effectively :=
53
 function( M, A, B ) return M = DecideZeroColumns( A, B ); end,
54
 
55
 DecideZeroRowsEffectively :=
56
 function( M, A, T, B ) return M = A + T * B; end,
57
 
58
 DecideZeroColumnsEffectively :=
59
 function( M, A, B, T ) return M = A + B * T; end,
60
 
61
 DecideZeroRowsWRTNonBasis :=
62
 function( B )
63
 local R;
64
 R := HomalgRing( B );
65
 if not ( HasIsBasisOfRowsMatrix( B ) and
66
 IsBasisOfRowsMatrix( B ) ) and
67
 IsBound( R!.DecideZeroWRTNonBasis ) then
68
 if R!.DecideZeroWRTNonBasis = "warn" then
69
 Info( InfoWarning, 1,
70
 "about to reduce with respect to a matrix",
71
 "with IsBasisOfRowsMatrix not set to true" );
72
 elif R!.DecideZeroWRTNonBasis = "error" then
73
 Error( "about to reduce with respect to a matrix",
74
 "with IsBasisOfRowsMatrix not set to true\n" );
75
 fi;
76
 fi;
77
 end,
78
 
79
 DecideZeroColumnsWRTNonBasis :=
80
 function( B )
81
 local R;
82
 R := HomalgRing( B );
83
 if not ( HasIsBasisOfColumnsMatrix( B ) and
84
 IsBasisOfColumnsMatrix( B ) ) and
85
 IsBound( R!.DecideZeroWRTNonBasis ) then
86
 if R!.DecideZeroWRTNonBasis = "warn" then
87
 Info( InfoWarning, 1,
88
 "about to reduce with respect to a matrix",
89
 "with IsBasisOfColumnsMatrix not set to true" );
90
 elif R!.DecideZeroWRTNonBasis = "error" then
91
 Error( "about to reduce with respect to a matrix",
92
 "with IsBasisOfColumnsMatrix not set to true\n" );
93
 fi;
94
 fi;
95
 end,
96
 
97
 ReducedBasisOfRowModule :=
98
 function( M, B )
99
 return GenerateSameRowModule( B, BasisOfRowModule( M ) );
100
 end,
101
 
102
 ReducedBasisOfColumnModule :=
103
 function( M, B )
104
 return GenerateSameColumnModule( B, BasisOfColumnModule( M ) );
105
 end,
106
 
107
 ReducedSyzygiesGeneratorsOfRows :=
108
 function( M, S )
109
 return GenerateSameRowModule( S, SyzygiesGeneratorsOfRows( M ) );
110
 end,
111
 
112
 ReducedSyzygiesGeneratorsOfColumns :=
113
 function( M, S )
114
 return GenerateSameColumnModule( S, SyzygiesGeneratorsOfColumns( M ) );
115
 end,
116
 
117
 );
118

119
120
121
E.2 Using homalgMode
122
123
E.2-1 homalgMode
124
125
homalgMode( str[, str2] )  method
126
127
This function sets different modes which influence how much of the basic
128
matrix operations and the logical matrix methods become visible (-->
129
Appendices A, C). Handling the string str is not case-sensitive. If a second
130
string str2 is given, then homalgMode( str2 ) is invoked at the end. In case
131
you let homalg delegate matrix operations to an external system the you
132
might also want to check homalgIOMode in the HomalgToCAS package manual.
133
134
str │ str (long form) │ mode description
135
────┼─────────────────┼────────────────────────────────────────────────────────────────────
136
│ │
137
"" │ "" │ the default mode, i.e. the computation protocol won't be visible
138
│ │ (homalgMode( ) is a short form for homalgMode( "" ))
139
│ │
140
"b" │ "basic" │ make the basic matrix operations visible + homalgMode( "logic" )
141
│ │
142
"d" │ "debug" │ same as "basic" but also makes Row/ColumnReducedEchelonForm visible
143
│ │
144
"l" │ "logic" │ make the logical methods in LIMAT and COLEM visible
145
│ │
146
────┴─────────────────┴────────────────────────────────────────────────────────────────────
147
148
All modes other than the "default"-mode only set their specific values and
149
leave the other values untouched, which allows combining them to some
150
extent. This also means that in order to get from one mode to a new mode
151
(without the aim to combine them) one needs to reset to the "default"-mode
152
first. This can be done using homalgMode( "", new_mode );
153
154
 Code 
155
InstallGlobalFunction( homalgMode,
156
 function( arg )
157
 local nargs, mode, s;
158
 
159
 nargs := Length( arg );
160
 
161
 if nargs = 0 or ( IsString( arg[1] ) and arg[1] = "" ) then
162
 mode := "default";
163
 elif IsString( arg[1] ) then ## now we know, the string is not empty
164
 s := arg[1];
165
 if LowercaseString( s{[1]} ) = "b" then
166
 mode := "basic";
167
 elif LowercaseString( s{[1]} ) = "d" then
168
 mode := "debug";
169
 elif LowercaseString( s{[1]} ) = "l" then
170
 mode := "logic";
171
 else
172
 mode := "";
173
 fi;
174
 else
175
 Error( "the first argument must be a string\n" );
176
 fi;
177
 
178
 if mode = "default" then
179
 HOMALG_MATRICES.color_display := false;
180
 for s in HOMALG_MATRICES.matrix_logic_infolevels do
181
 SetInfoLevel( s, 1 );
182
 od;
183
 SetInfoLevel( InfoHomalgBasicOperations, 1 );
184
 elif mode = "basic" then
185
 SetInfoLevel( InfoHomalgBasicOperations, 3 );
186
 homalgMode( "logic" );
187
 elif mode = "debug" then
188
 SetInfoLevel( InfoHomalgBasicOperations, 4 );
189
 homalgMode( "logic" );
190
 elif mode = "logic" then
191
 HOMALG_MATRICES.color_display := true;
192
 for s in HOMALG_MATRICES.matrix_logic_infolevels do
193
 SetInfoLevel( s, 2 );
194
 od;
195
 fi;
196
 
197
 if nargs > 1 and IsString( arg[2] ) then
198
 homalgMode( arg[2] );
199
 fi;
200
 
201
end );
202

203
204
205