Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X6 [33X[0;0YExamples of Applications based on [10XNCurses.BrowseGeneric[110X[101X[1X[133X[101X23[33X[0;0YThis chapter introduces the operation [2XBrowse[102X ([14X6.1-1[114X) and lists several4examples how the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) can be utilized for5rendering [5XGAP[105X related data or for playing games. Each section describes the6relevant [5XGAP[105X functions and briefly sketches the technical aspects of the7implementation; more details can be found in the [5XGAP[105X files, in the [11Xapp[111X8directory of the package.[133X910[33X[0;0YOnly Section [14X6.4[114X describes a standard application in the sense of the11introduction to Chapter [14X4[114X, perhaps except for a special function that is12needed to compare table entries. The other examples in this chapter require13some of the programming described in Chapter [14X5[114X.[133X1415[33X[0;0YThe [5XGAP[105X examples in this chapter use the [21Xreplay[121X feature of16[2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X), see Section [14X4.1[114X. This means that the17[2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) based function is called between two calls of18[2XBrowseData.SetReplay[102X ([14X5.4-2[114X). If you want to paste these examples into the19[5XGAP[105X session with the mouse then do not paste the final [2XBrowseData.SetReplay[102X20([14X5.4-2[114X) call, since [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) would regard the21additional input as a user interrupt.[133X222324[1X6.1 [33X[0;0YThe Operation [10XBrowse[110X[101X[1X[133X[101X2526[1X6.1-1 Browse[101X2728[29X[2XBrowse[102X( [3Xobj[103X[, [3Xarec[103X] ) [32X operation2930[33X[0;0YThis operation displays the [5XGAP[105X object [3Xobj[103X in a nice, formatted way, similar31to the operation [2XDisplay[102X ([14XReference: Display[114X). The difference is that [2XBrowse[102X32is intended to use [10Xncurses[110X facilities.[133X3334[33X[0;0YCurrently there are methods for matrices (see [2XBrowse[102X ([14X6.2-2[114X)), for character35tables (see [2XBrowse[102X ([14X6.3-1[114X)) and for tables of marks (see [2XBrowse[102X ([14X6.4-1[114X)).[133X363738[1X6.2 [33X[0;0YMatrix Display[133X[101X3940[33X[0;0YThe [5XGAP[105X library provides several [2XDisplay[102X ([14XReference: Display[114X) methods for41matrices. In order to cover the functionality of these methods, [5XBrowse[105X42provides the function [2XNCurses.BrowseDenseList[102X ([14X6.2-1[114X) that uses the standard43facilities of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X), i. e., one can44scroll in the matrix, searching and sorting are provided etc.[133X4546[33X[0;0YThe idea is to customize this function for different special cases, and to47install corresponding [2XBrowse[102X ([14X6.1-1[114X) methods. Examples are methods for48matrices over finite fields and residue class rings of the rational49integers, see [2XBrowse[102X ([14X6.2-2[114X).[133X5051[33X[0;0YThe code can be found in the file [11Xapp/matdisp.g[111X of the package.[133X5253[1X6.2-1 NCurses.BrowseDenseList[101X5455[29X[2XNCurses.BrowseDenseList[102X( [3Xlist[103X, [3Xarec[103X ) [32X function56[6XReturns:[106X [33X[0;10Ynothing.[133X5758[33X[0;0YLet [3Xlist[103X be a dense list whose entries are lists, for example a matrix, and59let [3Xarec[103X be a record. This function displays [3Xlist[103X in a window, as a60two-dimensional array with row and column positions as row and column61labels, respectively.[133X6263[33X[0;0YThe following components of [3Xarec[103X are supported.[133X6465[8X[10Xheader[110X[8X[108X66[33X[0;6YIf bound, the value must be a valid value of the [10Xwork.header[110X component67of a browse table, see [2XBrowseData.IsBrowseTable[102X ([14X4.2-3[114X); for example,68the value can be a list of strings. If this component is not bound69then the browse table has no header.[133X7071[8X[10XconvertEntry[110X[8X[108X72[33X[0;6YIf bound, the value must be a unary function that returns a string73describing its argument. The default is the operation [2XString[102X74([14XReference: String[114X). Another possible value is75[10XNCurses.ReplaceZeroByDot[110X, which returns the string [10X"."[110X if the argument76is a zero element in the sense of [2XIsZero[102X ([14XReference: IsZero[114X), and77returns the [2XString[102X ([14XReference: String[114X) value otherwise. For each entry78in a row of [3Xlist[103X, the [10XconvertEntry[110X value is shown in the browse table.[133X7980[8X[10XlabelsRow[110X[8X[108X81[33X[0;6YIf bound, the value must be a list of row label rows for [3Xlist[103X, as82described in Section [2XBrowseData.IsBrowseTable[102X ([14X4.2-3[114X). The default is83[10X[ [ "1" ], [ "2" ], ... ][110X.[133X8485[8X[10XlabelsCol[110X[8X[108X86[33X[0;6YIf bound, the value must be a list of column label rows for [3Xlist[103X, as87described in Section [2XBrowseData.IsBrowseTable[102X ([14X4.2-3[114X). The default is88[10X[ [ "1", "2", ... ] ][110X.[133X8990[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is91available.[133X9293[1X6.2-2 Browse[101X9495[29X[2XBrowse[102X( [3Xlist[103X ) [32X method96[6XReturns:[106X [33X[0;10Ynothing.[133X9798[33X[0;0YSeveral methods for the operation [2XBrowse[102X ([14X6.1-1[114X) are installed for the case99that the argument is a list of lists. These methods cover a default method100for lists of lists and the [2XDisplay[102X ([14XReference: Display[114X) methods for matrices101over finite fields and residue class rings of the rational integers. Note102that matrices over finite prime fields, small extension fields, and large103extension fields are displayed differently, and the same holds for the104corresponding [2XBrowse[102X ([14X6.1-1[114X) methods.[133X105106[4X[32X Example [32X[104X107[4X[25Xgap>[125X [27Xn:= [ 14, 14, 14, 14 ];;[127X[104X108[4X[25Xgap>[125X [27Xinput:= Concatenation( n, n, n, "Q" );; # ``do nothing and quit''[127X[104X109[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X110[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, Integers ) );[127X[104X111[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X112[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, GF(3) ) );[127X[104X113[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X114[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, GF(4) ) );[127X[104X115[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X116[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, Integers mod 6 ) );[127X[104X117[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X118[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, GF( NextPrimeInt( 2^16 ) ) ) );[127X[104X119[4X[25Xgap>[125X [27XBrowseData.SetReplay( input );[127X[104X120[4X[25Xgap>[125X [27XBrowse( RandomMat( 10, 10, GF( 2^20 ) ) );[127X[104X121[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X122[4X[32X[104X123124125[1X6.3 [33X[0;0YCharacter Table Display[133X[101X126127[33X[0;0YThe [5XGAP[105X library provides a [2XDisplay[102X ([14XReference: Display[114X) method for character128tables that breaks the table into columns fitting on the screen. [5XBrowse[105X129provides an alternative, using the standard facilities of the function130[2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X), i. e., one can scroll in the matrix of131character values, searching and sorting are provided etc.[133X132133[33X[0;0YThe [2XBrowse[102X ([14X6.1-1[114X) method for character tables can be called instead of134[2XDisplay[102X ([14XReference: Display[114X). For convenience, one can additionally make135this function the default [2XDisplay[102X ([14XReference: Display[114X) method for character136tables, by assigning it to the [10XDisplay[110X component in the global record137[10XCharacterTableDisplayDefaults.User[110X, see [14X'Reference: Printing Character138Tables'[114X; for example, one can do this in one's [11Xgaprc[111X file, see [14X'Reference:139The gap.ini and gaprc files'[114X. (This can be undone by unbinding the component140[10XCharacterTableDisplayDefaults.User.Display[110X.)[133X141142[33X[0;0YThe function [2XBrowseDecompositionMatrix[102X ([14X6.3-2[114X) can be used to display143decomposition matrices for Brauer character tables.[133X144145[1X6.3-1 Browse[101X146147[29X[2XBrowse[102X( [3Xtbl[103X[, [3Xoptions[103X] ) [32X method148149[33X[0;0YThis method displays the character table [3Xtbl[103X in a window. The optional150record [3Xoptions[103X describes what shall be displayed, the supported components151and the default values are described in [14X'Reference: Printing Character152Tables'[114X.[133X153154[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is155available.[133X156157[4X[32X Example [32X[104X158[4X[25Xgap>[125X [27Xif TestPackageAvailability( "CTblLib" ) = true then[127X[104X159[4X[25X>[125X [27X BrowseData.SetReplay( Concatenation([127X[104X160[4X[25X>[125X [27X # scroll in the table[127X[104X161[4X[25X>[125X [27X "DRULdddddrrrrrlluu",[127X[104X162[4X[25X>[125X [27X # select an entry and move it around[127X[104X163[4X[25X>[125X [27X "seddrruuuddlll",[127X[104X164[4X[25X>[125X [27X # search for the pattern 135 (six times)[127X[104X165[4X[25X>[125X [27X "/135", [ NCurses.keys.ENTER ], "nnnnn",[127X[104X166[4X[25X>[125X [27X # deselect the entry, select the first column[127X[104X167[4X[25X>[125X [27X "qLsc",[127X[104X168[4X[25X>[125X [27X # sort and categorize by this column[127X[104X169[4X[25X>[125X [27X "sc",[127X[104X170[4X[25X>[125X [27X # select the first row, move down the selection[127X[104X171[4X[25X>[125X [27X "srdddd",[127X[104X172[4X[25X>[125X [27X # expand the selected category, scroll the selection down[127X[104X173[4X[25X>[125X [27X "xd",[127X[104X174[4X[25X>[125X [27X # and quit the application[127X[104X175[4X[25X>[125X [27X "Q" ) );[127X[104X176[4X[25X>[125X [27X Browse( CharacterTable( "HN" ) );[127X[104X177[4X[25X>[125X [27X BrowseData.SetReplay( false );[127X[104X178[4X[25X>[125X [27Xfi;[127X[104X179[4X[32X[104X180181[33X[0;0Y[13XImplementation remarks[113X: The first part of the code in the [2XBrowse[102X ([14X6.1-1[114X)182method for character tables is almost identical with the code for extracting183the data to be displayed from the input data in the [5XGAP[105X library function184[10XCharacterTableDisplayDefault[110X. The second part of the code transforms these185data into a browse table. Character names and (if applicable) indicator186values are used as row labels, and centralizer orders, power maps, and class187names are used as column labels. The identifier of the table is used as the188static header. When an irrational entry is selected, a description of this189entry is shown in the dynamic footer.[133X190191[33X[0;0YThe standard modes in [2XBrowseData[102X ([14X5.4-1[114X) (except the [10Xhelp[110X mode) have been192extended by three new actions. The first two of them open pagers giving an193overview of all irrationalities in the table, or of all those194irrationalities that have been shown on the screen in the current call,195respectively. The corresponding user inputs are the [12XI[112X and the [12Xi[112X key. (The196names assigned to the irrationalities are generated column-wise. If one just197scrolls through the table, without jumping, then these names coincide with198the names generated by the default [2XDisplay[102X ([14XReference: Display[114X) method for199character tables; this is in general [13Xnot[113X the case, for example when a200row-wise search in the table is performed.) The third new action, which is201associated with the [12Xp[112X key, toggles the visibility status of the column label202rows for centralizer orders and power maps.[133X203204[33X[0;0YAn individual [10Xminyx[110X function does not only check whether the desired table205fits into the window but also whether a table with too high column labels206(centralizer orders and power maps) would fit if these labels get collapsed207via the [12Xp[112X key. In this case, the labels are automatically collapsed, and the208[12Xp[112X key is disabled.[133X209210[33X[0;0YIn order to keep the required space small also for large character tables,211caching of formatted matrix entries is disabled, and the strings to be212displayed are computed on demand with a [10XMain[110X function in the [10Xwork[110X component213of the browse table. For the same reason, the constant height one for all214table rows is set in advance, so one need not inspect a whole character if215only a few values of it shall be shown.[133X216217[33X[0;0YSpecial functions are provided for sorting (concerning the comparison of218character values, which can be integers or irrationalities) and categorizing219the table by a column (the value in the category row involves the class name220of the column in question).[133X221222[33X[0;0YThe code can be found in the file [11Xapp/ctbldisp.g[111X of the package.[133X223224[1X6.3-2 BrowseDecompositionMatrix[101X225226[29X[2XBrowseDecompositionMatrix[102X( [3Xmodtbl[103X[, [3Xb[103X][, [3Xoptions[103X] ) [32X function227228[33X[0;0YThis method displays the decomposition matrix of (the [3Xb[103X-th block of) the229Brauer character table [3Xmodtbl[103X in a window. The arguments are the same as for230[2XLaTeXStringDecompositionMatrix[102X ([14XReference: LaTeXStringDecompositionMatrix[114X).[133X231232[33X[0;0YThe positions of the ordinary and modular irreducible characters are shown233in the labels of the rows and columns, respectively, that are indexed by234these characters. When an entry in the decomposition matrix is selected then235information about the degrees of these characters is shown in the table236footer.[133X237238[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is239available.[133X240241[4X[32X Example [32X[104X242[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X243[4X[25X>[125X [27X # select the first entry[127X[104X244[4X[25X>[125X [27X "se",[127X[104X245[4X[25X>[125X [27X # scroll in the table[127X[104X246[4X[25X>[125X [27X "drrrr",[127X[104X247[4X[25X>[125X [27X # keep the table open for a while[127X[104X248[4X[25X>[125X [27X [ 14, 14, 14, 14, 14 ],[127X[104X249[4X[25X>[125X [27X # and quit the application[127X[104X250[4X[25X>[125X [27X "Q" ) );[127X[104X251[4X[25Xgap>[125X [27XBrowseDecompositionMatrix( CharacterTable( "J1" ) mod 2 );[127X[104X252[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X253[4X[32X[104X254255[33X[0;0YThe code can be found in the file [11Xapp/ctbldisp.g[111X of the package.[133X256257258[1X6.4 [33X[0;0YTable of Marks Display[133X[101X259260[33X[0;0YThe [5XGAP[105X library provides a [2XDisplay[102X ([14XReference: Display[114X) method for tables of261marks that breaks the table into columns fitting on the screen. Similar to262the situation with character tables, see Section [14X6.3[114X, but with a much263simpler implementation, [5XBrowse[105X provides an alternative based on the function264[2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X).[133X265266[33X[0;0Y[2XBrowse[102X ([14X6.1-1[114X) can be called instead of [2XDisplay[102X ([14XReference: Display[114X) for267tables of marks, cf. [14X'Reference: Printing Tables of Marks'[114X.[133X268269[1X6.4-1 Browse[101X270271[29X[2XBrowse[102X( [3Xtom[103X[, [3Xoptions[103X] ) [32X method272273[33X[0;0YThis method displays the table of marks [3Xtom[103X in a window. The optional record274[3Xoptions[103X describes what shall be displayed, the supported components and the275default values are described in [14X'Reference: Printing Tables of Marks'[114X.[133X276277[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is278available.[133X279280[4X[32X Example [32X[104X281[4X[25Xgap>[125X [27Xif TestPackageAvailability( "TomLib" ) = true then[127X[104X282[4X[25X>[125X [27X BrowseData.SetReplay( Concatenation([127X[104X283[4X[25X>[125X [27X # scroll in the table[127X[104X284[4X[25X>[125X [27X "DDRRR",[127X[104X285[4X[25X>[125X [27X # search for the (exact) value 100 (three times)[127X[104X286[4X[25X>[125X [27X "/100",[127X[104X287[4X[25X>[125X [27X [ NCurses.keys.DOWN, NCurses.keys.DOWN, NCurses.keys.RIGHT ],[127X[104X288[4X[25X>[125X [27X [ NCurses.keys.DOWN, NCurses.keys.DOWN, NCurses.keys.DOWN ],[127X[104X289[4X[25X>[125X [27X [ NCurses.keys.RIGHT, NCurses.keys.ENTER ], "nn",[127X[104X290[4X[25X>[125X [27X # no more occurrences of 100, confirm[127X[104X291[4X[25X>[125X [27X [ NCurses.keys.ENTER ],[127X[104X292[4X[25X>[125X [27X # and quit the application[127X[104X293[4X[25X>[125X [27X "Q" ) );[127X[104X294[4X[25X>[125X [27X Browse( TableOfMarks( "A10" ) );[127X[104X295[4X[25X>[125X [27X BrowseData.SetReplay( false );[127X[104X296[4X[25X>[125X [27X fi;[127X[104X297[4X[32X[104X298299[33X[0;0Y[13XImplementation remarks[113X: Rows and columns are indexed by their positions. The300identifier of the table is used as the static header, there is no footer.[133X301302[33X[0;0YIn order to keep the required space small also for large tables of marks,303caching of formatted matrix entries is disabled, and the strings to be304displayed are computed on demand with a [10XMain[110X function in the [10Xwork[110X component305of the browse table. For the same reason, the constant height one for the306table rows is set in advance. (For example, the table of marks of the group307with identifier [10X"O8+(2)"[110X, with [22X11171[122X rows and columns, can be shown with308[2XBrowse[102X ([14X6.1-1[114X) in a [5XGAP[105X session requiring about [22X100[122X MB.)[133X309310[33X[0;0YThe code can be found in the file [11Xapp/tomdisp.g[111X of the package.[133X311312313[1X6.5 [33X[0;0YTable of Contents of [5XAtlasRep[105X[101X[1X[133X[101X314315[33X[0;0YThe [5XGAP[105X package [5XAtlasRep[105X (see [WPN+07]) is an interface to a database of316representations and related data. The table of contents of this database can317be displayed via the function [2XDisplayAtlasInfo[102X ([14XAtlasRep: DisplayAtlasInfo[114X)318of this package. The [5XBrowse[105X package provides an alternative based on the319function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X); one can scroll, search, and fetch320data for later use.[133X321322323[1X6.5-1 [33X[0;0YBrowseAtlasInfo[133X[101X324325[29X[2XBrowseAtlasInfo[102X( [[3Xlistofnames[103X, ][[3X"contents"[103X, [3Xsources[103X, ][[3X...[103X] ) [32X function326[29X[2XBrowseAtlasInfo[102X( [3Xgapname[103X[, [3Xstd[103X][, [3X...[103X] ) [32X function327[6XReturns:[106X [33X[0;10Ythe list of [21Xclicked[121X info records.[133X328329[33X[0;0YThis function shows the information available via the [5XGAP[105X package [5XAtlasRep[105X330in a browse table, cf. Section [14X'AtlasRep: Accessing Data of the AtlasRep331Package'[114X in the [5XAtlasRep[105X manual.[133X332333[33X[0;0YThe optional arguments can be used to restrict the table to public or334private data, or to show an overview for one particular group. The arguments335are the same as for [2XDisplayAtlasInfo[102X ([14XAtlasRep: DisplayAtlasInfo[114X), see the336documentation of this function for details. (Note that additional conditions337such as [2XIsPermGroup[102X ([14XReference: IsPermGroup[114X) can be entered also in the case338that no [3Xgapname[103X is given. In this situation, the additional conditions are339evaluated for the [21Xsecond level tables[121X that are opened by [21Xclicking[121X on a table340row or entry.)[133X341342[33X[0;0YWhen one [21Xclicks[121X on one of the table rows or entries then a browse table with343an overview of the information available for this group is shown, and344[21Xclicking[121X on one of the rows in these tables adds the corresponding info345record (see [2XOneAtlasGeneratingSetInfo[102X ([14XAtlasRep: OneAtlasGeneratingSetInfo[114X))346to the list of return values of [2XBrowseAtlasInfo[102X.[133X347348[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is349available.[133X350351[33X[0;0YThe following example shows how [2XBrowseAtlasInfo[102X can be used to fetch info352records about permutation representations of the alternating groups [22XA_5[122X and353[22XA_6[122X: We search for the group name [10X"A5"[110X in the overview table, and the first354cell in the table row for [22XA_5[122X becomes selected; hitting the [12XEnter[112X key causes355a new window to be opened, with an overview of the data available for [22XA_5[122X;356moving down two rows and hitting the [12XEnter[112X key again causes the second357representation to be added to the result list; hitting [12XQ[112X closes the second358window, and we are back in the overview table; we move the selection down359twice (to the row for the group [22XA_6[122X), and choose the first representation360for this group; finally we leave the table, and the return value is the list361with the data for the two representations.[133X362363[4X[32X Example [32X[104X364[4X[25Xgap>[125X [27Xd:= [ NCurses.keys.DOWN ];; r:= [ NCurses.keys.RIGHT ];;[127X[104X365[4X[25Xgap>[125X [27Xc:= [ NCurses.keys.ENTER ];;[127X[104X366[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X367[4X[25X>[125X [27X "/A5", # Find the string A5 ...[127X[104X368[4X[25X>[125X [27X d, d, r, # ... such that just the word matches,[127X[104X369[4X[25X>[125X [27X c, # start the search,[127X[104X370[4X[25X>[125X [27X c, # click the table entry A5,[127X[104X371[4X[25X>[125X [27X d, d, # move down two rows,[127X[104X372[4X[25X>[125X [27X c, # click the row for this representation,[127X[104X373[4X[25X>[125X [27X "Q", # quit the second level table,[127X[104X374[4X[25X>[125X [27X d, d, # move down two rows,[127X[104X375[4X[25X>[125X [27X c, # click the table entry A6,[127X[104X376[4X[25X>[125X [27X d, # move down one row,[127X[104X377[4X[25X>[125X [27X c, # click the first row,[127X[104X378[4X[25X>[125X [27X "Q", # quit the second level table,[127X[104X379[4X[25X>[125X [27X "Q" ) ); # and quit the application.[127X[104X380[4X[25Xgap>[125X [27Xif IsBound( BrowseAtlasInfo ) and IsBound( AtlasProgramInfo ) then[127X[104X381[4X[25X>[125X [27X tworeps:= BrowseAtlasInfo();[127X[104X382[4X[25X>[125X [27X else[127X[104X383[4X[25X>[125X [27X tworeps:= [ fail ];[127X[104X384[4X[25X>[125X [27X fi;[127X[104X385[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X386[4X[25Xgap>[125X [27Xif fail in tworeps then[127X[104X387[4X[25X>[125X [27X Print( "no access to the Web ATLAS\n" );[127X[104X388[4X[25X>[125X [27X else[127X[104X389[4X[25X>[125X [27X Print( List( tworeps, x -> x.identifier[1] ), "\n" );[127X[104X390[4X[28X[ "A5", "A6" ][128X[104X391[4X[25X>[125X [27X fi;[127X[104X392[4X[32X[104X393394[33X[0;0Y[13XImplementation remarks[113X: The first browse table shown has a static header, no395footer and row labels, one row of column labels describing the type of data396summarized in the columns.[133X397398[33X[0;0YRow and column separators are drawn as grids (cf. [2XNCurses.Grid[102X ([14X2.2-8[114X))399composed from the special characters described in Section [14X2.1-6[114X, using the400component [10Xwork.SpecialGrid[110X of the browse table, see [2XBrowseData[102X ([14X5.4-1[114X).[133X401402[33X[0;0YWhen a row is selected, the [21Xclick[121X functionality opens a new window (via a403second level call to [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X)), in which a browse table404with the list of available data for the given group is shown; in this table,405[21Xclick[121X results in adding the info for the selected row to the result list,406and a message about this addition is shown in the footer row. One can choose407further data, return to the first browse table, and perhaps iterate the408process for other groups. When the first level table is left, the list of409info records for the chosen data is returned.[133X410411[33X[0;0YFor the two kinds of browse tables, the standard modes in [2XBrowseData[102X ([14X5.4-1[114X)412(except the [10Xhelp[110X mode) have been extended by a new action that opens a pager413giving an overview of all data that have been chosen in the current call.414The corresponding user input is the [12XY[112X key.[133X415416[33X[0;0YThis function is available only if the [5XGAP[105X package [5XAtlasRep[105X is available.[133X417418[33X[0;0YThe code can be found in the file [11Xapp/atlasbrowse.g[111X of the package.[133X419420421[1X6.6 [33X[0;0YAccess to [5XGAP[105X[101X[1X Manuals–a Variant[133X[101X422423[33X[0;0YA [5XBrowse[105X adapted way to access several manuals is to show the hierarchy of424books, chapters, sections, and subsections as collapsible category rows, and425to regard the contents of each subsection as a data row of a matrix with426only one column.[133X427428[33X[0;0YThis application is mainly intended as an example with table cells that429exceed the screen, and as an example with several category levels.[133X430431[1X6.6-1 BrowseGapManuals[101X432433[29X[2XBrowseGapManuals[102X( [[3Xstart[103X] ) [32X function434435[33X[0;0YThis function displays the contents of the [5XGAP[105X manuals (the main [5XGAP[105X manuals436as well as the loaded package manuals) in a window. The optional argument437[3Xstart[103X describes the initial status, admissible values are the strings438[10X"inline/collapsed"[110X, [10X"inline/expanded"[110X, [10X"pager/collapsed"[110X, and439[10X"pager/expanded"[110X.[133X440441[33X[0;0YIn the [10Xinline[110X cases, the parts of the manuals are shown in the browse table,442and in the [10Xpager[110X case, the parts of the manuals are shown in a different443window when they are [21Xclicked[121X, using the user's favourite help viewer, see444[14X'Reference: Changing the Help Viewer'[114X.[133X445446[33X[0;0YIn the [10Xcollapsed[110X cases, all category rows are collapsed, and the first row447is selected; typical next steps are moving down the selection and expanding448single category rows. In the [10Xexpanded[110X cases, all category rows are expanded,449and nothing is selected; a typical next step in the [10Xinline/expanded[110X case is450a search for a string in the manuals. (Note that searching in quite slow:451For viewing a part of a manual, the file with the corresponding section is452read into [5XGAP[105X, the text is formatted, the relevant part is cut out from the453section, perhaps markup is stripped off, and finally the search is performed454in the resulting strings.)[133X455456[33X[0;0YIf no argument is given then the user is asked for selecting an initial457status, using [2XNCurses.Select[102X ([14X3.1-2[114X).[133X458459[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is460available.[133X461462[4X[32X Example [32X[104X463[4X[25Xgap>[125X [27Xn:= [ 14, 14, 14 ];; # ``do nothing''[127X[104X464[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X465[4X[25X>[125X [27X "xdxd", # expand a Tutorial section[127X[104X466[4X[25X>[125X [27X n, "Q" ) ); # and quit[127X[104X467[4X[25Xgap>[125X [27XBrowseGapManuals( "inline/collapsed" );[127X[104X468[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X469[4X[25X>[125X [27X "/Browse", [ NCurses.keys.ENTER ], # search for "Browse"[127X[104X470[4X[25X>[125X [27X "xdxddxd", # expand a section[127X[104X471[4X[25X>[125X [27X n, "Q" ) ); # and quit[127X[104X472[4X[25Xgap>[125X [27XBrowseGapManuals( "inline/collapsed" );[127X[104X473[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X474[4X[32X[104X475476[33X[0;0Y[13XImplementation remarks[113X: The browse table has a dynamic header showing the477name of the currently selected manual, no footer, no row or column labels,478and exactly one column of fixed width equal to the screen width. The479category rows are precomputed, i. e., they do not arise from a table column;480this way, the contents of each data cell can be computed on demand, as soon481as it is shown on the screen, in particular the category hierarchy is482computed without reading the manuals into [5XGAP[105X. Also, the data rows are not483cached. There is no return value. The heights of many cells are bigger than484the screen height, so scrolling is a mixture of scrolling to the next cell485and scrolling inside a cell. The different initial states are realized via486executing different initial steps before the table is shown to the user.[133X487488[33X[0;0YFor the variants that show the manuals in a pager, the code temporarily489replaces the [10Xshow[110X function of the default viewer [10X"screen"[110X (see [14X'Reference:490Changing the Help Viewer'[114X) by a function that uses [2XNCurses.Pager[102X ([14X3.1-4[114X).491Note that in the case that the manual bit in question fits into one screen,492the default [10Xshow[110X function writes this text directly to the screen, but this493is used already by the browse table.[133X494495[33X[0;0YThe implementation should be regarded as a sketch.[133X496497[33X[0;0YFor example, the markup available in the text file format of [5XGAPDoc[105X manuals498(using [12XEsc[112X sequences) is stripped off instead of being transferred to the499attribute lines that arise, because of the highlighting problem mentioned in500Section [14X2.2-3[114X.[133X501502[33X[0;0YSome heuristics used in the code are due to deficiencies of the manual503formats.[133X504505[33X[0;0YFor the inline variant of the browse table, the titles of chapters,506sections, and subsections are [13Xnot[113X regarded as parts of the actual text since507they appear already as category rows; however, the functions of the [5XGAP[105X help508system deliver the text [13Xtogether with[113X these titles, so these lines must be509stripped off afterwards.[133X510511[33X[0;0YThe category hierarchy representing the tables of contents is created from512the [11Xmanual.six[111X files of the manuals. These files do not contain enough513information for determining whether several functions define the same514subsection, in the sense that there is a common description text after a515series of manual lines introducing different functions. In such cases, the516browse table contains a category row for each of these functions (with its517own number), but the corresponding text appears only under the [13Xlast[113X of these518category rows, the data rows for the others are empty. (This problem does519not occur in the [5XGAPDoc[105X manual format because this introduces explicit520subsection titles, involving only the [13Xfirst[113X of several function521definitions.)[133X522523[33X[0;0YAlso, index entries and sectioning entries in [11Xmanual.six[111X files of manuals in524[5XGAPDoc[105X format are not explicitly distinguished.[133X525526[33X[0;0YThe code can be found in the file [11Xapp/manual.g[111X of the package.[133X527528529[1X6.7 [33X[0;0YOverview of Bibliographies[133X[101X530531[33X[0;0YThe function [2XBrowseBibliography[102X ([14X6.7-1[114X) can be used to turn the contents of532bibliography files in BibTeX or BibXMLext format (see [14X'GAPDoc: The BibXMLext533Format'[114X) into a Browse table, such that one can scroll in the list, search534for entries, sort by year, sort and categorize by authors etc.[133X535536[33X[0;0YThe default bibliography used by [2XBrowseBibliography[102X ([14X6.7-1[114X) is the537bibliography of [5XGAP[105X related publications, see [GAP]. The [5XBrowse[105X package538contains a (perhaps outdated) version of this bibliography. One can get an539updated version as follows.[133X540541[33X[0;0Y[10Xwget -N http://www.gap-system.org/Doc/Bib/gap-publishednicer.bib[110X[133X542543[33X[0;0YThe columns of the Browse table that is shown by [2XBrowseBibliography[102X ([14X6.7-1[114X)544can be customized, two examples for that are given by the functions545[2XBrowseBibliographySporadicSimple[102X ([14XAtlasRep:546BrowseBibliographySporadicSimple[114X) and [2XBrowseBibliographyGapPackages[102X ([14X6.7-2[114X).[133X547548[33X[0;0YThe function [2XBrowseMSC[102X ([14X6.7-3[114X) shows an overview of the AMS Mathematics549Subject Classification codes.[133X550551[1X6.7-1 BrowseBibliography[101X552553[29X[2XBrowseBibliography[102X( [[3Xbibfiles[103X] ) [32X function554[6XReturns:[106X [33X[0;10Ya record as returned by [2XParseBibXMLExtFiles[102X ([14XGAPDoc:555ParseBibXMLextFiles[114X).[133X556557[33X[0;0YThis function shows the list of bibliography entries in the files given by558[3Xbibfiles[103X, which may be a string or a list of strings (denoting a filename or559a list of filenames, respectively) or a record (see below for the supported560components).[133X561562[33X[0;0YIf no argument is given then the file [11Xbibl/gap-publishednicer.bib[111X in the563[5XBrowse[105X package directory is taken, and [10X"GAP Bibliography"[110X is used as the564header.[133X565566[33X[0;0YAnother perhaps interesting data file that should be available in the [5XGAP[105X567distribution is [11Xdoc/manualbib.xml[111X. This file can be located as follows.[133X568569[4X[32X Example [32X[104X570[4X[25Xgap>[125X [27Xfile:= Filename( DirectoriesLibrary( "doc" ), "manualbib.xml" );;[127X[104X571[4X[32X[104X572573[33X[0;0YBoth BibTeX format and the [5XXML[105X based extended format provided by the [5XGAPDoc[105X574package are supported by [2XBrowseBibliography[102X, see Chapter [14X'GAPDoc: Utilities575for Bibliographies'[114X.[133X576577[33X[0;0YIn the case of BibTeX format input, first a conversion to the extended578format takes place, via [2XStringBibAsXMLext[102X ([14XGAPDoc: StringBibAsXMLext[114X) and579[2XParseBibXMLextString[102X ([14XGAPDoc: ParseBibXMLextString[114X). Note that syntactically580incorrect entries are rejected in this conversion –this is signaled with581[2XInfoBibTools[102X ([14XGAPDoc: InfoBibTools[114X) warnings– and that only a subset of the582possible LaTeX markup is recognized –other markup appears in the browse583table except that the leading backslash is removed.[133X584585[33X[0;0YIn both cases of input, the problem arises that in visual mode, currently we586can show only ASCII characters (and the symbols in [10XNCurses.lineDraw[110X, but587these are handled differently, see Section [14X2.1-6[114X). Therefore, we use the588function [2XSimplifiedUnicodeString[102X ([14XGAPDoc: SimplifiedUnicodeString[114X) for589replacing other unicode characters by ASCII text.[133X590591[33X[0;0YThe return value is a record as returned by [2XParseBibXMLExtFiles[102X ([14XGAPDoc:592ParseBibXMLextFiles[114X), its [10Xentries[110X component corresponds to the bibliography593entries that have been [21Xclicked[121X in visual mode. This record can be used as594input for [2XWriteBibFile[102X ([14XGAPDoc: WriteBibFile[114X) or [2XWriteBibXMLextFile[102X ([14XGAPDoc:595WriteBibXMLextFile[114X), in order to produce a bibliography file, or it can be596used as input for [2XStringBibXMLEntry[102X ([14XGAPDoc: StringBibXMLEntry[114X), in order to597produce strings from the entries, in various formats.[133X598599[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is600available.[133X601602[4X[32X Example [32X[104X603[4X[25Xgap>[125X [27X# sort and categorize by year, scroll down, expand a category row[127X[104X604[4X[25Xgap>[125X [27XBrowseData.SetReplay( "scrrscsedddddxdddddQ" );[127X[104X605[4X[25Xgap>[125X [27XBrowseBibliography();;[127X[104X606[4X[25Xgap>[125X [27X# sort & categorize by authors, expand all category rows, scroll down[127X[104X607[4X[25Xgap>[125X [27XBrowseData.SetReplay( "scscXseddddddQ" );[127X[104X608[4X[25Xgap>[125X [27XBrowseBibliography();;[127X[104X609[4X[25Xgap>[125X [27X# sort and categorize by journal, search for a journal name, expand[127X[104X610[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation( "scrrrsc/J. Algebra",[127X[104X611[4X[25X>[125X [27X [ NCurses.keys.ENTER ], "nxdddQ" ) );[127X[104X612[4X[25Xgap>[125X [27XBrowseBibliography();;[127X[104X613[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X614[4X[32X[104X615616[33X[0;0Y[13XImplementation remarks[113X: The browse table has a dynamic header (showing the617number of entries, which can vary when the table is restricted), no footer618and row labels; one row of column labels is given by the descriptions of the619table columns (authors, title, year, journal, MSC code).[133X620621[33X[0;0YRow and column separators are drawn as grids (cf. [2XNCurses.Grid[102X ([14X2.2-8[114X))622composed from the special characters described in Section [14X2.1-6[114X, using the623component [10Xwork.SpecialGrid[110X of the browse table, see [2XBrowseData[102X ([14X5.4-1[114X).[133X624625[33X[0;0YFor categorizing by authors (or by MSC codes), the sort parameter [10X"split626rows on categorizing"[110X is set to [10X"yes"[110X, so the authors (codes) are627distributed to different category rows, hence each entry appears once for628each of its authors (or its MSC codes) in the categorized table. When a data629row or an entry in a data row is selected, [21Xclick[121X adds the corresponding630bibliographhy entry to the result.[133X631632[33X[0;0YThe width of the title column is preset; usually titles are too long for one633line, and the contents of this column is formatted as a paragraph, using the634function [2XFormatParagraph[102X ([14XGAPDoc: FormatParagraph[114X). For the authors and635journal columns, maximal widths are prescribed, and [2XFormatParagraph[102X ([14XGAPDoc:636FormatParagraph[114X) is used for longer entries.[133X637638[33X[0;0YFor four columns, the sort parameters are defined as follows: The [13Xauthors[113X639and [13XMSC code[113X columns do not become hidden when the table is categorized640according to this column, sorting by the [13Xyear[113X yields a [13Xde[113Xscending order, and641the category rows arising from these columns and the [13Xjournal[113X column show the642numbers of the data rows that belong to them.[133X643644[33X[0;0YThose standard modes in [2XBrowseData[102X ([14X5.4-1[114X) where an entry or a row of the645table is selected have been extended by three new actions, which open a646pager showing the BibTeX, HTML, and Text format of the selected entry,647respectively. The corresponding user inputs are the [12Xvb[112X, [12Xvh[112X, and [12Xvt[112X. If the648[13XMSC code[113X column is available then also the user input [12Xvm[112X is admissible; it649opens a pager showing the descriptions of the MSC codes attached to the650selected entry.[133X651652[33X[0;0YThis function requires some of the utilities provided by the [5XGAP[105X package653[5XGAPDoc[105X (see [LN07]), such as [2XFormatParagraph[102X ([14XGAPDoc: FormatParagraph[114X),654[2XNormalizeNameAndKey[102X ([14XGAPDoc: NormalizeNameAndKey[114X), [2XNormalizedNameAndKey[102X655([14XGAPDoc: NormalizedNameAndKey[114X), [2XParseBibFiles[102X ([14XGAPDoc: ParseBibFiles[114X),656[2XParseBibXMLextFiles[102X ([14XGAPDoc: ParseBibXMLextFiles[114X), [2XParseBibXMLextString[102X657([14XGAPDoc: ParseBibXMLextString[114X), [2XRecBibXMLEntry[102X ([14XGAPDoc: RecBibXMLEntry[114X), and658[2XStringBibAsXMLext[102X ([14XGAPDoc: StringBibAsXMLext[114X).[133X659660[33X[0;0YThe code can be found in the file [11Xapp/gapbibl.g[111X of the package.[133X661662[33X[0;0YThe browse table can be customized by entering a record as the argument of663[2XBrowseBibliography[102X, with the following supported components.[133X664665[8X[10Xfiles[110X[8X[108X666[33X[0;6Ya nonempty list of filenames containing the data to be shown; there is667no default for this component.[133X668669[8X[10Xfilesshort[110X[8X[108X670[33X[0;6Ya list of the same length as the [10Xfiles[110X component, the entries are671strings which are shown in the [10X"sourcefilename"[110X column of the table672(if this column is present); the default is the list of filenames.[133X673674[8X[10Xfilecontents[110X[8X[108X675[33X[0;6Ya list of the same length as the [10Xfiles[110X component, the entries are676strings which are shown as category values when the table is677categorized by the [10X"sourcefilename"[110X column; the default is the list of678filenames.[133X679680[8X[10Xheader[110X[8X[108X681[33X[0;6Yis the constant part of the header shown above the browse table, the682default is the first filename.[133X683684[8X[10Xcolumns[110X[8X[108X685[33X[0;6Yis a list of records that are valid as the second argument of686[2XDatabaseAttributeAdd[102X ([14XA.1-5[114X), where the first argument is a database687id enumerator created from the bibliography entries in the files in688question. Each entry (and also the corresponding identifier) of this689database id enumerator is a list of records obtained from690[2XParseBibXMLextFiles[102X ([14XGAPDoc: ParseBibXMLextFiles[114X) and [2XRecBibXMLEntry[102X691([14XGAPDoc: RecBibXMLEntry[114X), or from [2XParseBibFiles[102X ([14XGAPDoc:692ParseBibFiles[114X), such that the list elements are regarded as equal, in693the sense that their fingerprints (see below) are equal. The records694in the [10Xcolumns[110X list are available for constructing the desired browse695table, the actual appearance is controlled by the [10Xchoice[110X component696described below. Columns showing authors, title, year, journal, MSC697code, and filename are predefined and need not be listed here.[133X698699[8X[10Xchoice[110X[8X[108X700[33X[0;6Ya list of strings denoting the [10Xidentifier[110X components of those columns701that shall actually be shown in the table, the default is [10X[ "authors",702"title", "year", "journal", "mrclass" ][110X.[133X703704[8X[10Xfingerprint[110X[8X[108X705[33X[0;6Ya list of strings denoting component names of the entries of the706database id enumerator that is constructed from the data (see above);707two data records are regarded as equal if the values of these708components are equal; the default is [10X[ "mrnumber", "title",709"authorAsList", "editorAsList", "author" ][110X.[133X710711[8X[10XsortKeyFunction[110X[8X[108X712[33X[0;6Yeither [9Xfail[109X or a function that takes a record as returned by713[2XRecBibXMLEntry[102X ([14XGAPDoc: RecBibXMLEntry[114X) and returns a list that is714used for comparing and thus sorting the records; the default is [9Xfail[109X,715which means that the rows of the table appear in the same ordering as716in the source files.[133X717718[1X6.7-2 BrowseBibliographyGapPackages[101X719720[29X[2XBrowseBibliographyGapPackages[102X( ) [32X function721[6XReturns:[106X [33X[0;10Ya record as returned by [2XBrowseBibliography[102X ([14X6.7-1[114X).[133X722723[33X[0;0YThis function collects the information from the [10X*.bib[110X and [10X*bib.xml[110X files in724those subdirectories of installed [5XGAP[105X packages which contain the package725documentation, and shows it in a Browse table, using the function726[2XBrowseBibliography[102X ([14X6.7-1[114X).[133X727728[33X[0;0Y[13XThis function is experimental.[113X The result is not really satisfactory, for729the following reasons.[133X730731[30X [33X[0;6YDuplicate entries may occur, due to subtle differences in various732source files.[133X733734[30X [33X[0;6YThe source files may contain more than what is actually cited in the735package manuals.[133X736737[30X [33X[0;6YIt may happen that some [10X*.bib[110X or [10X*bib.xml[110X file is accidentally738distributed with the package but is not intended to serve as package739bibliography.[133X740741[30X [33X[0;6YThe heuristics for rewriting LaTeX code is of course not perfect; thus742strange symbols may occur in the Browse table.[133X743744[1X6.7-3 BrowseMSC[101X745746[29X[2XBrowseMSC[102X( ) [32X function747[6XReturns:[106X [33X[0;10Ynothing.[133X748749[33X[0;0YThis function shows the currently valid MSC codes in a browse table that is750categorized by the [10X..-XX[110X and the [10X...xx[110X codes. (Use [12XX[112X for expanding all751categories or [12Xx[112X for expanding the currently selected category.) Due to the752categorization, only two columns of the table are visible, showing the codes753and their descriptions.[133X754755756[1X6.8 [33X[0;0YProfiling [5XGAP[105X[101X[1X functions–a Variant[133X[101X757758[33X[0;0YA [5XBrowse[105X adapted way to evaluate profiling results is to show the overview759that is printed by the [5XGAP[105X function [2XDisplayProfile[102X ([14XReference:760DisplayProfile[114X) in a [5XBrowse[105X table, which allows one to sort the profiled761functions according to the numbers of calls, the time spent, etc., and to762search for certain functions one is interested in.[133X763764[1X6.8-1 BrowseProfile[101X765766[29X[2XBrowseProfile[102X( [[3Xfunctions[103X, ][[3Xmincount[103X, [3Xmintime[103X] ) [32X function767768[33X[0;0YThe arguments and their meaning are the same as for the function769[2XDisplayProfile[102X ([14XReference: DisplayProfile[114X), in the sense that the lines770printed by that function correspond to the rows of the list that is shown by771[2XBrowseProfile[102X. Initially, the table is sorted in the same way as the list772shown by [2XBrowseProfile[102X; sorting the table by any of the first five columns773will yield a non-increasing order of the rows.[133X774775[33X[0;0YThe threshold values [3Xmincount[103X and [3Xmintime[103X can be changed in visual mode via776the user input [12Xe[112X. If mouse events are enabled (see [2XNCurses.UseMouse[102X777([14X2.2-10[114X)) then one can also use a mouse click on the current parameter value778shown in the table header in order to enter the mode for changing the779parameters.[133X780781[33X[0;0YWhen a row or an entry in a row is selected, [21Xclick[121X shows the code of the782corresponding function in a pager (see [2XNCurses.Pager[102X ([14X3.1-4[114X)) whenever this783is possible, as follows. If the function was read from a file then this file784is opened, if the function was entered interactively then the code of the785function is shown in the format produced by [2XPrint[102X ([14XReference: Print[114X); other786functions (for example [5XGAP[105X kernel functions) cannot be shown, one gets an787alert message (see [2XNCurses.Alert[102X ([14X3.1-1[114X)) in such a case.[133X788789[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is790available.[133X791792[4X[32X Example [32X[104X793[4X[25Xgap>[125X [27Xn:= [ 14, 14, 14, 14, 14 ];; # ``do nothing''[127X[104X794[4X[25Xgap>[125X [27XProfileOperationsAndMethods( true ); # collect some data[127X[104X795[4X[25Xgap>[125X [27XConjugacyClasses( PrimitiveGroup( 24, 1 ) );;[127X[104X796[4X[25Xgap>[125X [27XProfileOperationsAndMethods( false );[127X[104X797[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X798[4X[25X>[125X [27X "scso", # sort by column 1,[127X[104X799[4X[25X>[125X [27X n,[127X[104X800[4X[25X>[125X [27X "rso", # sort by column 2,[127X[104X801[4X[25X>[125X [27X n,[127X[104X802[4X[25X>[125X [27X "rso", # sort by column 3,[127X[104X803[4X[25X>[125X [27X n,[127X[104X804[4X[25X>[125X [27X "q", # deselect the column,[127X[104X805[4X[25X>[125X [27X "/Centralizer", [ NCurses.keys.ENTER ], # search for a function,[127X[104X806[4X[25X>[125X [27X n, "Q" ) ); # and quit[127X[104X807[4X[25Xgap>[125X [27XBrowseProfile();[127X[104X808[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X809[4X[32X[104X810811[33X[0;0Y[13XImplementation remarks[113X: The browse table has a dynamic header, which shows812the current values of [3Xmincount[103X and [3Xmintime[103X, and a dynamic footer, which813shows the sums of counts and timings for the rows in the table (label [10XTOTAL[110X)814and if applicable the sums for the profiled functions not shown in the table815(label [10XOTHER[110X). There are no row labels, and the obvious column labels. There816is no return value.[133X817818[33X[0;0YThe standard modes in [2XBrowseData[102X ([14X5.4-1[114X) (except the [10Xhelp[110X mode) have been819modified by adding a new action for changing the threshold parameters820[3Xmincount[103X and [3Xmintime[103X (user input [12Xe[112X). The way how this in implemented made it821necessary to change the standard [21Xreset[121X action (user input [12X![112X) of the table;822note that resetting (a sorting or filtering of) the table must not make823those rows visible that shall be hidden because of the threshold parameters.[133X824825[33X[0;0YThe code can be found in the file [11Xapp/profile.g[111X of the package.[133X826827828[1X6.9 [33X[0;0YVariables defined in [5XGAP[105X[101X[1X packages–a Variant[133X[101X829830[33X[0;0YA [5XBrowse[105X adapted way to list the variables that are defined in a [5XGAP[105X package831is to show the overview that is printed by the [5XGAP[105X function832[2XShowPackageVariables[102X ([14XReference: ShowPackageVariables[114X) in a [5XBrowse[105X table.[133X833834[1X6.9-1 BrowsePackageVariables[101X835836[29X[2XBrowsePackageVariables[102X( [3Xpkgname[103X[, [3Xversion[103X][, [3Xarec[103X] ) [32X function837[6XReturns:[106X [33X[0;10Ynothing.[133X838839[33X[0;0YThe arguments can be the same as for [2XShowPackageVariables[102X ([14XReference:840ShowPackageVariables[114X), that is, [3Xpkgname[103X is the name of a [5XGAP[105X package, and841the optional arguments [3Xversion[103X and [3Xarec[103X are a version number of this package842and a record used for customizing the output, respectively.[133X843844[33X[0;0YAlternatively, the second argument can be the output [10Xinfo[110X of845[2XPackageVariablesInfo[102X ([14XReference: PackageVariablesInfo[114X) for the package in846question, instead of the version number.[133X847848[33X[0;0Y[2XBrowsePackageVariables[102X opens a browse table that shows the global variables849that become bound and the methods that become installed when [5XGAP[105X loads the850package [3Xpkgname[103X.[133X851852[33X[0;0YThe table is categorized by the kinds of variables (new or redeclared853operations, methods, info classes, synonyms, other globals). The column854[21XDoc.?[121X distinguishes undocumented and documented variables, so one can use855this column as a filter or for categorizing. The column [21XFilename[121X shows the856names of the package files. Clicking a selected row of the table opens the857relevant package file at the code in question.[133X858859[33X[0;0YThe idea behind the argument [10Xinfo[110X is that using the same arguments as for860[2XShowPackageVariables[102X ([14XReference: ShowPackageVariables[114X) does not allow one to861apply [2XBrowsePackageVariables[102X to packages that have been loaded before the862[5XBrowse[105X package. Thus one can compute the underlying data [10Xinfo[110X first, using863[2XPackageVariablesInfo[102X ([14XReference: PackageVariablesInfo[114X), then load the [5XBrowse[105X864package, and finally call [2XBrowsePackageVariables[102X.[133X865866[33X[0;0YFor example, the overview of package variables for [5XBrowse[105X can be shown by867starting [5XGAP[105X without packages and then entering the following lines.[133X868869[4X[32X Example [32X[104X870[4X[25Xgap>[125X [27Xpkgname:= "Browse";;[127X[104X871[4X[25Xgap>[125X [27Xinfo:= PackageVariablesInfo( pkgname, "" );;[127X[104X872[4X[25Xgap>[125X [27XLoadPackage( "Browse" );;[127X[104X873[4X[25Xgap>[125X [27XBrowsePackageVariables( pkgname, info );[127X[104X874[4X[32X[104X875876[33X[0;0YIf the arguments are the same as for [2XShowPackageVariables[102X ([14XReference:877ShowPackageVariables[114X) then this function is actually called, with the878consequence that the package gets loaded when [2XBrowsePackageVariables[102X is879called. This is not the case if the output of [2XPackageVariablesInfo[102X880([14XReference: PackageVariablesInfo[114X) is entered as the second argument.[133X881882883[1X6.10 [33X[0;0YConfiguring User preferences–a Variant[133X[101X884885[33X[0;0YA [5XBrowse[105X adapted way to show and edit [5XGAP[105X's user preferences is to show the886overview that is printed by the [5XGAP[105X function [2XShowUserPreferences[102X ([14XReference:887ShowUserPreferences[114X) in a [5XBrowse[105X table.[133X888889[1X6.10-1 BrowseUserPreferences[101X890891[29X[2XBrowseUserPreferences[102X( [3Xpackage1[103X, [3Xpackage2[103X, [3X...[103X ) [32X function892[6XReturns:[106X [33X[0;10Ynothing.[133X893894[33X[0;0YThe arguments are the same as for [2XShowUserPreferences[102X ([14XReference:895ShowUserPreferences[114X), that is, calling the function with no argument yields896an overview of all known user preferences, and if one or more strings897[3Xpackage1[103X, [22X...[122X are given then only the user preferences for these packages898are shown.[133X899900[33X[0;0Y[2XBrowseUserPreferences[102X opens a browse table with the following columns:[133X901902[8X[21XPackage[121X[108X903[33X[0;6Ycontains the names of the [5XGAP[105X packages to which the user preferences904belong,[133X905906[8X[21XPref. names[121X[108X907[33X[0;6Ycontains the names of the user preferences, and[133X908909[8X[21XDescription[121X[108X910[33X[0;6Ycontains the [10Xdescription[110X texts from the [2XDeclareUserPreference[102X911([14XReference: DeclareUserPreference[114X) calls and the default values (if912applicable), and the actual values.[133X913914[33X[0;0YWhen one [21Xclicks[121X on one of the table rows or entries then the values of the915user preference in question can be edited. If a list of admissible values is916known then this means that one can choose from this list via [2XNCurses.Select[102X917([14X3.1-2[114X), otherwise one can enter the desired value as text.[133X918919[33X[0;0YThe values of the user preferences are not changed before one closes the920browse table. When the table is left and if one has changed at least one921value, one is asked whether the changes shall be applied.[133X922923[4X[32X Example [32X[104X924[4X[25Xgap>[125X [27Xd:= [ NCurses.keys.DOWN ];; [127X[104X925[4X[25Xgap>[125X [27Xc:= [ NCurses.keys.ENTER ];; [127X[104X926[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X927[4X[25X>[125X [27X "/PackagesToLoad", # enter a search string,[127X[104X928[4X[25X>[125X [27X c, # start the search,[127X[104X929[4X[25X>[125X [27X c, # edit the entry (a list of choices),[127X[104X930[4X[25X>[125X [27X " ", d, # toggle the first four values,[127X[104X931[4X[25X>[125X [27X " ", d, #[127X[104X932[4X[25X>[125X [27X " ", d, #[127X[104X933[4X[25X>[125X [27X " ", d, #[127X[104X934[4X[25X>[125X [27X c, # submit the values,[127X[104X935[4X[25X>[125X [27X "Q", # quit the table,[127X[104X936[4X[25X>[125X [27X c ) ); # choose "cancel": do not apply the changes.[127X[104X937[4X[25Xgap>[125X [27XBrowseUserPreferences();[127X[104X938[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X939[4X[32X[104X940941[33X[0;0YThe code can be found in the file [11Xapp/userpref.g[111X of the package.[133X942943944[1X6.11 [33X[0;0YOverview of [5XGAP[105X[101X[1X Data[133X[101X945946[33X[0;0YThe [5XGAP[105X system contains several data collections such as libraries of groups947and character tables. Clearly the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) can948be used to visualize interesting information about such data collections, in949the form of an [21Xoverview table[121X whose rows correspond to the objects in the950collection; each column of the table shows a piece of information about the951objects. (One possibility to create such overviews is given by952[2XBrowseTableFromDatabaseIdEnumerator[102X ([14XA.2-2[114X).)[133X953954[1X6.11-1 BrowseGapData[101X955956[29X[2XBrowseGapData[102X( ) [32X function957[6XReturns:[106X [33X[0;10Ythe return value of the chosen application if there is one.[133X958959[33X[0;0YThe function [2XBrowseGapData[102X shows the choices in the list960[10XBrowseData.GapDataOverviews[110X, in a browse table with one column. When an961entry is [21Xclicked[121X then the associated function is called, and the table of962choices is closed.[133X963964[33X[0;0YThe idea is that each entry of [10XBrowseData.GapDataOverviews[110X describes an965overview of a data collection.[133X966967[33X[0;0YThe [5XBrowse[105X package provides overviews of[133X968969[30X [33X[0;6Ythe current AMS Mathematics Subject Classification codes (see970[2XBrowseMSC[102X ([14X6.7-3[114X)),[133X971972[30X [33X[0;6Ythe contents of the [5XAtlasRep[105X package [WPN+07] (only if this package is973loaded, see Section [14X6.5[114X),[133X974975[30X [33X[0;6Ythe Conway polynomials in [5XGAP[105X (calls [10XBrowseConwayPolynomials()[110X),[133X976977[30X [33X[0;6Yprofile information for [5XGAP[105X functions (see Section [14X6.8[114X),[133X978979[30X [33X[0;6Ythe list of [5XGAP[105X related bibliography entries in the file980[11Xbibl/gap-publishednicer.bib[111X of the [5XBrowse[105X package (see Section [14X6.7[114X),[133X981982[30X [33X[0;6Ythe [5XGAP[105X manuals (see Section [14X6.6[114X),[133X983984[30X [33X[0;6Y[5XGAP[105X operations and methods (calls [10XBrowseGapMethods()[110X),[133X985986[30X [33X[0;6Ythe installed [5XGAP[105X packages (calls [10XBrowseGapPackages()[110X),[133X987988[30X [33X[0;6Y[5XGAP[105X's user preferences (see Section [14X6.10[114X),[133X989990[30X [33X[0;6Ythe contents of the [5XTomLib[105X package [NMP13] (only if this package is991loaded, see Section [14XA.4[114X),[133X992993[33X[0;0YOther [5XGAP[105X packages may add more overviews, using the function994[2XBrowseGapDataAdd[102X ([14X6.11-2[114X). For example, there are overviews of[133X995996[30X [33X[0;6Ythe bibliographies in the [5XATLAS[105X of Finite Groups [CCN+85] and in the997[5XATLAS[105X of Brauer Characters [JLPW95] (see998[2XBrowseBibliographySporadicSimple[102X ([14XAtlasRep:999BrowseBibliographySporadicSimple[114X)),[133X10001001[30X [33X[0;6Yatomic irrationalities that occur in character tables in the [5XATLAS[105X of1002Finite Groups [CCN+85] or the [5XATLAS[105X of Brauer Characters [JLPW95] (see1003Section [2XBrowseCommonIrrationalities[102X ([14XCTblLib:1004BrowseCommonIrrationalities[114X)),[133X10051006[30X [33X[0;6Ythe differences between the versions of the character table data in1007the [5XCTblLib[105X package (see Section [2XBrowseCTblLibDifferences[102X ([14XCTblLib:1008BrowseCTblLibDifferences[114X)),[133X10091010[30X [33X[0;6Ythe information in the [5XGAP[105X Character Table Library (see Section1011[2XBrowseCTblLibInfo[102X ([14XCTblLib: BrowseCTblLibInfo[114X)),[133X10121013[30X [33X[0;6Yan overview of minimal degrees of representations of groups from the1014[5XATLAS[105X of Group Representations (see Section [2XBrowseMinimalDegrees[102X1015([14XAtlasRep: BrowseMinimalDegrees[114X)).[133X10161017[33X[0;0YExcept that always one table cell is selected, the full functionality of the1018function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is available.[133X10191020[4X[32X Example [32X[104X1021[4X[25Xgap>[125X [27Xn:= [ 14, 14, 14 ];; # ``do nothing''[127X[104X1022[4X[25Xgap>[125X [27X# open the overview of Conway polynomials[127X[104X1023[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation( "/Conway Polynomials",[127X[104X1024[4X[25X>[125X [27X [ NCurses.keys.ENTER, NCurses.keys.ENTER ], "srdddd", n, "Q" ) );[127X[104X1025[4X[25Xgap>[125X [27XBrowseGapData();;[127X[104X1026[4X[25Xgap>[125X [27X# open the overview of GAP packages[127X[104X1027[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation( "/GAP Packages",[127X[104X1028[4X[25X>[125X [27X [ NCurses.keys.ENTER, NCurses.keys.ENTER ], "/Browse",[127X[104X1029[4X[25X>[125X [27X [ NCurses.keys.ENTER ], "n", n, "Q" ) );[127X[104X1030[4X[25Xgap>[125X [27XBrowseGapData();;[127X[104X1031[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1032[4X[32X[104X10331034[33X[0;0Y[13XImplementation remarks[113X: The browse table has a static header, a dynamic1035footer showing the description of the currently selected entry, no row or1036column labels, and exactly one column of fixed width equal to the screen1037width. If the chosen application has a return value then this is returned by1038[2XBrowseGapData[102X, otherwise nothing is returned. The component [10Xwork.SpecialGrid[110X1039of the browse table is used to draw a border around the list of choices and1040another border around the footer. Only one mode is needed in which an entry1041is selected.[133X10421043[33X[0;0YThe code can be found in the file [11Xapp/gapdata.g[111X of the package.[133X10441045[1X6.11-2 BrowseGapDataAdd[101X10461047[29X[2XBrowseGapDataAdd[102X( [3Xtitle[103X, [3Xcall[103X, [3Xret[103X, [3Xdocumentation[103X ) [32X function10481049[33X[0;0YThis function extends the list [10XBrowseData.GapDataOverviews[110X by a new entry.1050The list is used by [2XBrowseGapData[102X ([14X6.11-1[114X).[133X10511052[33X[0;0Y[3Xtitle[103X must be a string of length at most [22X76[122X; it will be shown in the browse1053table that is opened by [2XBrowseGapData[102X ([14X6.11-1[114X). [3Xcall[103X must be a function that1054takes no arguments; it will be called when [3Xtitle[103X is [21Xclicked[121X. [3Xret[103X must be1055[9Xtrue[109X if [3Xcall[103X has a return value and if [2XBrowseGapData[102X ([14X6.11-1[114X) shall return1056this value, and [9Xfalse[109X otherwise. [3Xdocumentation[103X must be a string that1057describes what happens when the function [3Xcall[103X is called; it will be shown in1058the footer of the table opened by [2XBrowseGapData[102X ([14X6.11-1[114X) when [3Xtitle[103X is1059selected.[133X106010611062[1X6.12 [33X[0;0YNavigating in a Directory Tree[133X[101X10631064[33X[0;0YA natural way to visualize the contents of a directory is via a tree whose1065leaves denote plain files, and the other vertices denote subdirectories.1066[5XBrowse[105X provides a function based on [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) for1067displaying such trees; the leaves correspond to the data rows, and the other1068vertices correspond to category rows.[133X10691070[1X6.12-1 BrowseDirectory[101X10711072[29X[2XBrowseDirectory[102X( [[3Xdir[103X] ) [32X function1073[6XReturns:[106X [33X[0;10Ya list of the [21Xclicked[121X filenames.[133X10741075[33X[0;0YIf no argument is given then the contents of the current directory is shown,1076see [2XDirectoryCurrent[102X ([14XReference: DirectoryCurrent[114X). If a directory object1077[3Xdir[103X (see [2XDirectory[102X ([14XReference: Directory[114X)) is given as the only argument1078then the contents of this directory is shown; alternatively, [3Xdir[103X may also be1079a string which is then understood as a directory path.[133X10801081[33X[0;0YThe full functionality of the function [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) is1082available.[133X10831084[4X[32X Example [32X[104X1085[4X[25Xgap>[125X [27Xn:= [ 14, 14, 14 ];; # ``do nothing''[127X[104X1086[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X1087[4X[25X>[125X [27X "q", # leave the selection[127X[104X1088[4X[25X>[125X [27X "X", # expand all categories[127X[104X1089[4X[25X>[125X [27X "/filetree", [ NCurses.keys.ENTER ], # search for "filetree"[127X[104X1090[4X[25X>[125X [27X n, "Q" ) ); # and quit[127X[104X1091[4X[25Xgap>[125X [27Xdir:= DirectoriesPackageLibrary( "Browse", "" )[1];;[127X[104X1092[4X[25Xgap>[125X [27Xif IsBound( BrowseDirectory ) then[127X[104X1093[4X[25X>[125X [27X BrowseDirectory( dir );[127X[104X1094[4X[25X>[125X [27X fi;[127X[104X1095[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1096[4X[32X[104X10971098[33X[0;0Y[13XImplementation remarks[113X: The browse table has a static header, no footer, no1099row or column labels, and exactly one data column. The category rows are1100precomputed, i. e., they do not arise from a table column. The tree1101structure is visualized via a special grid that is shown in the separator1102column in front of the table column; the width of this column is computed1103from the largest nesting depth of files. For technical reasons, category1104rows representing [13Xempty[113X directories are realized via [21Xdummy[121X table rows; a1105special [10XShowTables[110X function guarantees that these rows are always hidden.[133X11061107[33X[0;0YWhen a data row or an entry in this row is selected, [21Xclick[121X adds the1108corresponding filename to the result list. Initially, the first row is1109selected. (So if you want to search in the whole tree then you should quit1110this selection by hitting the [12Xq[112X key.)[133X11111112[33X[0;0YThe category hierarchy is computed using [2XDirectoryContents[102X ([14XReference:1113DirectoryContents[114X).[133X11141115[33X[0;0YThis function is available only if the [5XGAP[105X package [5XIO[105X (see [Neu07]) is1116available, because the check for cycles uses the function [2XIO_stat[102X ([14XIO:1117IO_stat[114X) from this package.[133X11181119[33X[0;0YThe code can be found in the file [11Xapp/filetree.g[111X of the package.[133X112011211122[1X6.13 [33X[0;0YA Puzzle[133X[101X11231124[33X[0;0YWe consider an [22Xm[122X by [22Xn[122X rectangle of squares numbered from [22X1[122X to [22Xm n - 1[122X, the1125bottom right square is left empty. The numbered squares are permuted by1126successively exchanging the empty square and a neighboring square such that1127in the end, the empty cell is again in the bottom right corner.[133X11281129┌────┬────┬────┬────┐1130│ [22X7[122X │ [22X13[122X │ [22X14[122X │ [22X2[122X │1131├────┼────┼────┼────┤1132│ [22X1[122X │ [22X4[122X │ [22X15[122X │ [22X11[122X │1133├────┼────┼────┼────┤1134│ [22X6[122X │ [22X8[122X │ [22X3[122X │ [22X9[122X │1135├────┼────┼────┼────┤1136│ [22X10[122X │ [22X5[122X │ [22X12[122X │ [22X[122X │1137└────┴────┴────┴────┘11381139[33X[0;0YThe aim of the game is to order the numbered squares via these moves.[133X11401141[33X[0;0YFor the case [22Xm = n = 4[122X, the puzzle is (erroneously?) known under the name1142[21XSam Loyd's Fifteen[121X, see [Bog] and [OR] for more information and references.[133X11431144[1X6.13-1 BrowsePuzzle[101X11451146[29X[2XBrowsePuzzle[102X( [[3Xm[103X, [3Xn[103X[, [3Xpi[103X]] ) [32X function1147[6XReturns:[106X [33X[0;10Ya record describing the initial and final status of the puzzle.[133X11481149[33X[0;0YThis function shows the rectangle in a window.[133X11501151[33X[0;0YThe arguments [3Xm[103X and [3Xn[103X are the dimensions of the rectangle, the default for1152both values is [22X4[122X. The initial distribution of the numbers in the squares can1153be prescribed via a permutation [3Xpi[103X, the default is a random element in the1154alternating group on the points [22X1, 2, ..., [3Xm[103X [3Xn[103X - 1[122X. (Note that the game has1155not always a solution.)[133X11561157[33X[0;0YIn any case, the empty cell is selected, and the selection can be moved to1158neighboring cells via the arrow keys, or to any place in the same row or1159column via a mouse click.[133X11601161[33X[0;0YThe return value is a record with the components [10Xdim[110X (the pair [10X[ m, n ][110X),1162[10Xinit[110X (the initial permutation), [10Xfinal[110X (the final permutation), and [10Xsteps[110X1163(the number of transpositions that were needed).[133X11641165[4X[32X Example [32X[104X1166[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X1167[4X[25X>[125X [27X BrowsePuzzleSolution.steps, "Q" ) );[127X[104X1168[4X[25Xgap>[125X [27XBrowsePuzzle( 4, 4, BrowsePuzzleSolution.init );;[127X[104X1169[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1170[4X[32X[104X11711172[33X[0;0YAn implementation using only mouse clicks but no key strokes is available in1173the [5XGAP[105X package [5XXGAP[105X (see [CN04]).[133X11741175[33X[0;0Y[13XImplementation remarks[113X: The game board is implemented via a browse table,1176without row and column labels, with static header, dynamic footer, and1177individual [10Xminyx[110X function. Only one mode is needed in which one cell is1178selected, and besides the standard actions for quitting the table, asking1179for help, and saving the current window contents, only the four moves via1180the arrow keys and mouse clicks are admissible.[133X11811182[33X[0;0YSome standard [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) functionality, such as1183scrolling, selecting, and searching, are not available in this application.[133X11841185[33X[0;0YThe code can be found in the file [11Xapp/puzzle.g[111X of the package.[133X118611871188[1X6.14 [33X[0;0YPeg Solitaire[133X[101X11891190[33X[0;0YPeg solitaire is a board game for one player. The game board consists of1191several holes some of which contain pegs. In each step of the game, one peg1192is moved horizontally or vertically to an empty hole at distance two, by1193jumping over a neighboring peg which is then removed from the board.[133X11941195┌───┬───┬───┐1196│ o │ o │ o │1197├───┼───┼───┤1198│ o │ o │ o │1199┌───┬───┼───┼───┼───┼───┬───┐1200│ o │ o │ o │ o │ o │ o │ o │1201├───┼───┼───┼───┼───┼───┼───┤1202│ o │ o │ o │ │ o │ o │ o │1203├───┼───┼───┼───┼───┼───┼───┤1204│ o │ o │ o │ o │ o │ o │ o │1205└───┴───┼───┼───┼───┼───┴───┘1206│ o │ o │ o │1207├───┼───┼───┤1208│ o │ o │ o │1209└───┴───┴───┘12101211[33X[0;0YWe consider the game that in the beginning, exactly one hole is empty, and1212in the end, exactly one peg is left.[133X12131214[1X6.14-1 PegSolitaire[101X12151216[29X[2XPegSolitaire[102X( [[3Xformat[103X, ][[3Xnrholes[103X, ][[3XtwoModes[103X] ) [32X function12171218[33X[0;0YThis function shows the game board in a window.[133X12191220[33X[0;0YIf the argument [3Xformat[103X is one of the strings [10X"small"[110X or [10X"large"[110X then small1221or large pegs are shown, the default is [10X"small"[110X.[133X12221223[33X[0;0YThree shapes of the game board are supported, with [22X33[122X, [22X37[122X, and [22X45[122X holes,1224respectively; this number can be specified via the argument [3Xnrholes[103X, the1225default is [22X33[122X. In the cases of [22X33[122X and [22X45[122X holes, the position of both the1226initial hole and the destination of the final peg is the middle cell,1227whereas in the case of [22X37[122X holes, the initial hole is in the top left1228position and the final peg has to be placed in the bottom right position.[133X12291230[33X[0;0YIf a Boolean [3XtwoModes[103X is entered as an argument then it determines whether a1231browse table with one or two modes is used; the default [9Xfalse[109X yields a1232browse table with only one mode.[133X12331234[33X[0;0YIn any case, one cell of the board is selected, and the selection can be1235moved to neighboring cells via the arrow keys. A peg in the selected cell1236jumps over a neighboring peg to an adjacent hole via the [10Xj[110X key followed by1237the appropriate arrow key.[133X12381239[4X[32X Example [32X[104X1240[4X[25Xgap>[125X [27Xfor n in [ 33, 37, 45 ] do[127X[104X1241[4X[25X>[125X [27X BrowseData.SetReplay( Concatenation([127X[104X1242[4X[25X>[125X [27X PegSolitaireSolutions.( String( n ) ), "Q" ) );[127X[104X1243[4X[25X>[125X [27X PegSolitaire( n );[127X[104X1244[4X[25X>[125X [27X PegSolitaire( "large", n );[127X[104X1245[4X[25X>[125X [27X PegSolitaire( n, true );[127X[104X1246[4X[25X>[125X [27X PegSolitaire( "large", n, true );[127X[104X1247[4X[25X>[125X [27Xod;[127X[104X1248[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1249[4X[32X[104X12501251[33X[0;0YFor more information such as variations of the game and references,1252see [Köla]. Also the solutions stored in the variable [10XPegSolitaireSolutions[110X1253have been taken from this web page.[133X12541255[33X[0;0Y[13XImplementation remarks[113X: The game board is implemented via a browse table,1256without row and column labels, with static header, dynamic footer, and1257individual [10Xminyx[110X function. In fact, two implementations are provided. The1258first one needs only one mode in which one cell is selected; moving the1259selection and jumping with the peg in the selected cell in one of the four1260directions are the supported user actions. The second implementation needs1261two modes, one for moving the selection and one for jumping.[133X12621263[33X[0;0YSome standard [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) functionality, such as1264scrolling, selecting, and searching, are not available in this application.[133X12651266[33X[0;0YThe code can be found in the file [11Xapp/solitair.g[111X of the package.[133X126712681269[1X6.15 [33X[0;0YRubik's Cube[133X[101X12701271[33X[0;0YWe visualize the transformations of Rubik's magic cube in a model that is1272given by [21Xunfolding[121X the faces and numbering them as follows.[133X12731274┌──────────────┐1275│ 1 2 3 │1276│ 4 top 5 │1277│ 6 7 8 │1278┌──────────────┼──────────────┼──────────────┬──────────────┐1279│ 9 10 11 │ 17 18 19 │ 25 26 27 │ 33 34 35 │1280│ 12 left 13 │ 20 front 21 │ 28 right 29 │ 36 back 37 │1281│ 14 15 16 │ 22 23 24 │ 30 31 32 │ 38 39 40 │1282└──────────────┼──────────────┼──────────────┴──────────────┘1283│ 41 42 43 │1284│ 44 down 45 │1285│ 46 47 48 │1286└──────────────┘12871288[33X[0;0YClockwise turns of the six layers (top, left, front, right, back, and down)1289are represented by the following permutations.[133X12901291[4X[32X Example [32X[104X1292[4X[25Xgap>[125X [27Xcubegens := [[127X[104X1293[4X[25X>[125X [27X ( 1, 3, 8, 6)( 2, 5, 7, 4)( 9,33,25,17)(10,34,26,18)(11,35,27,19),[127X[104X1294[4X[25X>[125X [27X ( 9,11,16,14)(10,13,15,12)( 1,17,41,40)( 4,20,44,37)( 6,22,46,35),[127X[104X1295[4X[25X>[125X [27X (17,19,24,22)(18,21,23,20)( 6,25,43,16)( 7,28,42,13)( 8,30,41,11),[127X[104X1296[4X[25X>[125X [27X (25,27,32,30)(26,29,31,28)( 3,38,43,19)( 5,36,45,21)( 8,33,48,24),[127X[104X1297[4X[25X>[125X [27X (33,35,40,38)(34,37,39,36)( 3, 9,46,32)( 2,12,47,29)( 1,14,48,27),[127X[104X1298[4X[25X>[125X [27X (41,43,48,46)(42,45,47,44)(14,22,30,38)(15,23,31,39)(16,24,32,40)[127X[104X1299[4X[25X>[125X [27X];;[127X[104X1300[4X[32X[104X13011302[33X[0;0Y[5XGAP[105X computations analyzing this permutation group have been part of the1303announcements of [5XGAP[105X 3 releases. For a [5XGAP[105X 4 equivalent, see [Sch]. For more1304information and references (not [5XGAP[105X related) about Rubik's cube, see [Kölb].[133X13051306[1X6.15-1 BrowseRubiksCube[101X13071308[29X[2XBrowseRubiksCube[102X( [[3Xformat[103X, ][[3Xpi[103X] ) [32X function13091310[33X[0;0YThis function shows the model of the cube in a window.[133X13111312[33X[0;0YIf the argument [3Xformat[103X is one of the strings [10X"small"[110X or [10X"large"[110X then small1313or large cells are shown, the default is [10X"small"[110X.[133X13141315[33X[0;0YThe argument [3Xpi[103X is the initial permutation of the faces, the default is a1316random permutation in the cube group, see [14X'Reference: Random'[114X.[133X13171318[33X[0;0YSupported user inputs are the keys [12Xt[112X, [12Xl[112X, [12Xf[112X, [12Xr[112X, [12Xb[112X, and [12Xd[112X for clockwise turns1319of the six layers, and the corresponding capital letters for1320counter-clockwise turns. If the terminal supports colors, according to the1321global variable [2XNCurses.attrs.has_colors[102X ([14X2.2-1[114X), the input [12Xs[112X switches1322between a screen that shows only the colors of the faces and a screen that1323shows the numbers; the color screen is the default.[133X13241325[33X[0;0YThe return value is a record with the components [10Xinputs[110X (a string describing1326the user inputs), [10Xinit[110X, and [10Xfinal[110X (the initial and final permutation of the1327faces, respectively). (The [10Xinputs[110X component can be used for the replay1328feature, see the example below.)[133X13291330[33X[0;0YIn the following example, a word in terms of the generators is used to1331initialize the browse table, and then the letters in this word are used as a1332series of input steps, except that in between, the display is switched once1333from colors to numbers and back.[133X13341335[4X[32X Example [32X[104X1336[4X[25Xgap>[125X [27Xchoice:= List( [ 1 .. 30 ], i -> Random( [ 1 .. 6 ] ) );;[127X[104X1337[4X[25Xgap>[125X [27Xinput:= List( "tlfrbd", IntChar ){ choice };;[127X[104X1338[4X[25Xgap>[125X [27XBrowseData.SetReplay( Concatenation([127X[104X1339[4X[25X>[125X [27X input{ [ 1 .. 20 ] },[127X[104X1340[4X[25X>[125X [27X "s", # switch to number display[127X[104X1341[4X[25X>[125X [27X input{ [ 21 .. 25 ] },[127X[104X1342[4X[25X>[125X [27X "s", # switch to color display[127X[104X1343[4X[25X>[125X [27X input{ [ 26 .. 30 ] },[127X[104X1344[4X[25X>[125X [27X "Q" ) );; # quit the browse table[127X[104X1345[4X[25Xgap>[125X [27XBrowseRubiksCube( Product( cubegens{ choice } ) );;[127X[104X1346[4X[25Xgap>[125X [27XBrowseRubiksCube( "large", Product( cubegens{ choice } ) );;[127X[104X1347[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1348[4X[32X[104X13491350[33X[0;0Y[13XImplementation remarks[113X: The cube is implemented via a browse table, without1351row and column labels, with static header, dynamic footer, and individual1352[10Xminyx[110X function. Only one mode is needed, and besides the standard actions1353for quitting the table, asking for help, and saving the current window1354contents, only the twelve moves and the switch between color and number1355display are admissible.[133X13561357[33X[0;0YSwitching between the two display formats is implemented via a function1358[10Xwork.Main[110X, so this relies on [13Xnot[113X caching the formatted cells in [10Xwork.main[110X.[133X13591360[33X[0;0YRow and column separators of the browse table are whitespace of height and1361width one. The separating lines are drawn using an individual [10XSpecialGrid[110X1362function in the browse table. Note that the relevant cells do not form a1363rectangular array.[133X13641365[33X[0;0YSome standard [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) functionality, such as1366scrolling, selecting, and searching, are not available in this application.[133X13671368[33X[0;0YThe code can be found in the file [11Xapp/rubik.g[111X of the package.[133X136913701371[1X6.16 [33X[0;0YChanging Sides[133X[101X13721373[33X[0;0YWe consider a [22X5[122X by [22X5[122X board of squares filled with two types of stones, as1374follows. The square in the middle is left empty.[133X13751376┌───┬───┬───┬───┬───┐1377│ x │ x │ x │ x │ x │1378├───┼───┼───┼───┼───┤1379│ o │ x │ x │ x │ x │1380├───┼───┼───┼───┼───┤1381│ o │ o │ │ x │ x │1382├───┼───┼───┼───┼───┤1383│ o │ o │ o │ o │ x │1384├───┼───┼───┼───┼───┤1385│ o │ o │ o │ o │ o │1386└───┴───┴───┴───┴───┘13871388[33X[0;0YThe aim of the game is to exchange the two types of stones via a sequence of1389single steps that move one stone to the empty position on the board. Only1390those moves are allowed that increase or decrease one coordinate by [22X2[122X and1391increase or decrease the other by [22X1[122X; these are the allowed moves of the1392knight in chess.[133X13931394[33X[0;0YThis game has been part of the MacTutor system [OR00].[133X13951396[1X6.16-1 BrowseChangeSides[101X13971398[29X[2XBrowseChangeSides[102X( ) [32X function13991400[33X[0;0YThis function shows the game board in a window.[133X14011402[33X[0;0YEach move is encoded as a sequence of three arrow keys; there are [22X24[122X1403admissible inputs.[133X14041405[4X[32X Example [32X[104X1406[4X[25Xgap>[125X [27Xfor entry in BrowseChangeSidesSolutions do[127X[104X1407[4X[25X>[125X [27X BrowseData.SetReplay( Concatenation( entry, "Q" ) );[127X[104X1408[4X[25X>[125X [27X BrowseChangeSides();[127X[104X1409[4X[25X>[125X [27Xod;[127X[104X1410[4X[25Xgap>[125X [27XBrowseData.SetReplay( false );[127X[104X1411[4X[32X[104X14121413[33X[0;0Y[13XImplementation remarks[113X: The game board is implemented via a browse table,1414without row and column labels, with static header, dynamic footer, and1415individual [10Xminyx[110X function. Only one mode is needed, and besides the standard1416actions for quitting the table, asking for help, and saving the current1417window contents, only moves via combinations of the four arrow keys are1418admissible.[133X14191420[33X[0;0YThe separating lines are drawn using an individual [10XSpecialGrid[110X function in1421the browse table.[133X14221423[33X[0;0YSome standard [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) functionality, such as1424scrolling, selecting, and searching, are not available in this application.[133X14251426[33X[0;0YThe code can be found in the file [11Xapp/knight.g[111X of the package.[133X142714281429[1X6.17 [33X[0;0YSudoku[133X[101X14301431[33X[0;0YWe consider a [22X9[122X by [22X9[122X board of squares. Some squares are initially filled1432with numbers from [22X1[122X to [22X9[122X. The aim of the game is to fill the empty squares1433in such a way that each row, each column, and each of the marked [22X3[122X by [22X3[122X1434subsquares contains all numbers from [22X1[122X to [22X9[122X. A [13Xproper Sudoku game[113X is defined1435as one with a unique solution. Here is an example.[133X14361437┏━━━┯━━━┯━━━┳━━━┯━━━┯━━━┳━━━┯━━━┯━━━┓1438┃ │ │ ┃ │ │ ┃ 5 │ │ ┃1439┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1440┃ │ 1 │ 5 ┃ 4 │ │ 6 ┃ │ 2 │ ┃1441┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1442┃ 9 │ │ ┃ │ 5 │ ┃ 3 │ │ ┃1443┣━━━┿━━━┿━━━╋━━━┿━━━┿━━━╋━━━┿━━━┿━━━┫1444┃ 6 │ │ 4 ┃ │ │ ┃ │ │ ┃1445┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1446┃ │ │ ┃ 8 │ │ ┃ │ │ ┃1447┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1448┃ 8 │ │ ┃ 9 │ │ ┃ │ 5 │ 3 ┃1449┣━━━┿━━━┿━━━╋━━━┿━━━┿━━━╋━━━┿━━━┿━━━┫1450┃ │ │ ┃ │ │ 5 ┃ │ │ ┃1451┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1452┃ │ 4 │ ┃ │ │ 7 ┃ │ │ 2 ┃1453┠───┼───┼───╂───┼───┼───╂───┼───┼───┨1454┃ │ │ 9 ┃ 1 │ │ ┃ 8 │ │ ┃1455┗━━━┷━━━┷━━━┻━━━┷━━━┷━━━┻━━━┷━━━┷━━━┛14561457[33X[0;0YThe [5XBrowse[105X package contains functions to create, play and solve these games.1458There are basic command line functions for this, which we describe first,1459and there is a user interface [2XPlaySudoku[102X ([14X6.17-8[114X) which is implemented using1460the generic browse functionality described in Chapter [14X4[114X.[133X14611462[1X6.17-1 Sudoku.Init[101X14631464[29X[2XSudoku.Init[102X( [[3Xarg[103X] ) [32X function1465[6XReturns:[106X [33X[0;10YA record describing a Sudoku board or [9Xfail[109X.[133X14661467[33X[0;0YThis function constructs a record describing a Sudoku game. This is used by1468the other functions described below. There a several possibilities for the1469argument [3Xarg[103X.[133X14701471[8X[3Xarg[103X[8X is a string[108X1472[33X[0;6YThe entries of a Sudoku board are numbered row-wise from 1 to 81. A1473board is encoded as a string as follows. If one of the numbers 1 to 91474is in entry [22Xi[122X then the corresponding digit character is written in1475position [22Xi[122X of the string. If an entry is empty any character, except1476[10X'1'[110X to [10X'9'[110X or [10X'|'[110X is written in position [22Xi[122X of the string. Trailing1477empty entries can be left out. Afterwards [10X'|'[110X-characters can be1478inserted in the string (for example to mark line ends). Such strings1479can be used for [3Xarg[103X.[133X14801481[8X[3Xarg[103X[8X is a matrix[108X1482[33X[0;6YA Sudoku board can also be encoded as a 9 by 9-matrix, that is a list1483of 9 lists of length 9, whose (i,j)-th entry is the (i,j)-th entry of1484the board as integer if it is not empty. Empty entries of the board1485correspond to unbound entries in the matrix.[133X14861487[8X[3Xarg[103X[8X is a list of integers[108X1488[33X[0;6YInstead of the matrix just described the argument can also be given by1489the concatenation of the rows of the matrix (so, a list of integers1490and holes).[133X14911492[4X[32X Example [32X[104X1493[4X[25Xgap>[125X [27Xgame := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\[127X[104X1494[4X[25X>[125X [27X 6 47 |45 2 |89 2 1 | 4 8 7 | ");;[127X[104X1495[4X[32X[104X14961497[1X6.17-2 Sudoku.Place[101X14981499[29X[2XSudoku.Place[102X( [3Xgame[103X, [3Xi[103X, [3Xn[103X ) [32X function1500[29X[2XSudoku.Remove[102X( [3Xgame[103X, [3Xi[103X ) [32X function1501[6XReturns:[106X [33X[0;10YThe changed [3Xgame[103X.[133X15021503[33X[0;0YHere [3Xgame[103X is a record describing a Sudoku board, as returned by [2XSudoku.Init[102X1504([14X6.17-1[114X). The argument [3Xi[103X is the number of an entry, counted row-wise from 11505to 81, and [3Xn[103X is an integer from 1 to 9 to be placed on the board. These1506functions change [3Xgame[103X.[133X15071508[33X[0;0Y[2XSudoku.Place[102X tries to place number [3Xn[103X on entry [3Xi[103X. It is an error if entry [3Xi[103X1509is not empty. The number is not placed if [3Xn[103X is already used in the row,1510column or subsquare of entry [3Xi[103X. In this case the component [10Xgame.impossible[110X1511is bound.[133X15121513[33X[0;0Y[2XSudoku.Remove[102X tries to remove the number placed on position [3Xi[103X of the board.1514It does not change the board if entry [3Xi[103X is empty, or if entry [3Xi[103X was given1515when the board [3Xgame[103X was created. In the latter case [10Xgame.impossible[110X is1516bound.[133X15171518[4X[32X Example [32X[104X1519[4X[25Xgap>[125X [27Xgame := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\[127X[104X1520[4X[25X>[125X [27X 6 47 |45 2 |89 2 1 | 4 8 7 | ");;[127X[104X1521[4X[25Xgap>[125X [27XSudoku.Place(game, 1, 3);; # 3 is already in first row[127X[104X1522[4X[25Xgap>[125X [27XIsBound(game.impossible);[127X[104X1523[4X[28Xtrue[128X[104X1524[4X[25Xgap>[125X [27XSudoku.Place(game, 1, 2);; # 2 is not in row, col or subsquare[127X[104X1525[4X[25Xgap>[125X [27XIsBound(game.impossible);[127X[104X1526[4X[28Xfalse[128X[104X1527[4X[32X[104X15281529[1X6.17-3 Sudoku.RandomGame[101X15301531[29X[2XSudoku.RandomGame[102X( [[3Xseed[103X] ) [32X function1532[6XReturns:[106X [33X[0;10YA pair [10X[str, seed][110X of string and seed.[133X15331534[33X[0;0YThe optional argument [3Xseed[103X, if given, must be an integer. If not given some1535random integer from the current [5XGAP[105X session is used. This function returns a1536random proper Sudoku game, where the board is described by a string [10Xstr[110X, as1537explained in [2XSudoku.Init[102X ([14X6.17-1[114X). With the same [3Xseed[103X the same board is1538returned.[133X15391540[33X[0;0YThe games computed by this function have the property that after removing1541any given entry the puzzle does no longer have a unique solution.[133X15421543[4X[32X Example [32X[104X1544[4X[25Xgap>[125X [27XSudoku.RandomGame(5833750);[127X[104X1545[4X[28X[ " 1 2 43 2 68 72 8 6 2 1 9 8 8 3 9 \[128X[104X1546[4X[28X47 3 7 18 ", 5833750 ][128X[104X1547[4X[25Xgap>[125X [27Xlast = Sudoku.RandomGame(last[2]);[127X[104X1548[4X[28Xtrue[128X[104X1549[4X[32X[104X15501551[1X6.17-4 Sudoku.SimpleDisplay[101X15521553[29X[2XSudoku.SimpleDisplay[102X( [3Xgame[103X ) [32X function15541555[33X[0;0YDisplays a Sudoku board on the terminal. (But see [2XPlaySudoku[102X ([14X6.17-8[114X) for a1556fancier interface.)[133X15571558[4X[32X Example [32X[104X1559[4X[25Xgap>[125X [27Xgame := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\[127X[104X1560[4X[25X>[125X [27X 6 47 |45 2 |89 2 1 | 4 8 7 | ");;[127X[104X1561[4X[25Xgap>[125X [27XSudoku.SimpleDisplay(game);[127X[104X1562[4X[28X 3 | 6|8 [128X[104X1563[4X[28X 85| 1| 69[128X[104X1564[4X[28X 9|7 | 53[128X[104X1565[4X[28X-----------[128X[104X1566[4X[28X | |79 [128X[104X1567[4X[28X 6 | 47| [128X[104X1568[4X[28X45 | 2 | [128X[104X1569[4X[28X-----------[128X[104X1570[4X[28X89 | 2| 1 [128X[104X1571[4X[28X 4 | 8| 7 [128X[104X1572[4X[28X | | [128X[104X1573[4X[32X[104X15741575[1X6.17-5 Sudoku.DisplayString[101X15761577[29X[2XSudoku.DisplayString[102X( [3Xgame[103X ) [32X function15781579[33X[0;0YThe string returned by this function can be used to display the Sudoku board1580[3Xgame[103X on the terminal, using [2XPrintFormattedString[102X ([14XGAPDoc:1581PrintFormattedString[114X). The result depends on the value of1582[10XGAPInfo.TermEncoding[110X.[133X15831584[4X[32X Example [32X[104X1585[4X[25Xgap>[125X [27Xgame := Sudoku.Init(" 3 68 | 85 1 69| 97 53| 79 |\[127X[104X1586[4X[25X>[125X [27X 6 47 |45 2 |89 2 1 | 4 8 7 | ");;[127X[104X1587[4X[25Xgap>[125X [27Xstr:= Sudoku.DisplayString( game );;[127X[104X1588[4X[25Xgap>[125X [27XPrintFormattedString( str );[127X[104X1589[4X[28X ┏━━━┯━━━┯━━━┳━━━┯━━━┯━━━┳━━━┯━━━┯━━━┓[128X[104X1590[4X[28X ┃ │ 3 │ ┃ │ │ 6 ┃ 8 │ │ ┃[128X[104X1591[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1592[4X[28X ┃ │ 8 │ 5 ┃ │ │ 1 ┃ │ 6 │ 9 ┃[128X[104X1593[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1594[4X[28X ┃ │ │ 9 ┃ 7 │ │ ┃ │ 5 │ 3 ┃[128X[104X1595[4X[28X ┣━━━┿━━━┿━━━╋━━━┿━━━┿━━━╋━━━┿━━━┿━━━┫[128X[104X1596[4X[28X ┃ │ │ ┃ │ │ ┃ 7 │ 9 │ ┃[128X[104X1597[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1598[4X[28X ┃ │ 6 │ ┃ │ 4 │ 7 ┃ │ │ ┃[128X[104X1599[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1600[4X[28X ┃ 4 │ 5 │ ┃ │ 2 │ ┃ │ │ ┃[128X[104X1601[4X[28X ┣━━━┿━━━┿━━━╋━━━┿━━━┿━━━╋━━━┿━━━┿━━━┫[128X[104X1602[4X[28X ┃ 8 │ 9 │ ┃ │ │ 2 ┃ │ 1 │ ┃[128X[104X1603[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1604[4X[28X ┃ │ 4 │ ┃ │ │ 8 ┃ │ 7 │ ┃[128X[104X1605[4X[28X ┠───┼───┼───╂───┼───┼───╂───┼───┼───┨[128X[104X1606[4X[28X ┃ │ │ ┃ │ │ ┃ │ │ ┃[128X[104X1607[4X[28X ┗━━━┷━━━┷━━━┻━━━┷━━━┷━━━┻━━━┷━━━┷━━━┛[128X[104X1608[4X[32X[104X16091610[1X6.17-6 Sudoku.OneSolution[101X16111612[29X[2XSudoku.OneSolution[102X( [3Xgame[103X ) [32X function1613[6XReturns:[106X [33X[0;10YA completed Sudoku board that solves [3Xgame[103X, or [9Xfail[109X.[133X16141615[33X[0;0YHere [3Xgame[103X must be a Sudoku board as returned by [2XSudoku.Init[102X ([14X6.17-1[114X). It is1616not necessary that [3Xgame[103X describes a proper Sudoku game (has a unique1617solution). It may have several solutions, then one random solution is1618returned. Or it may have no solution, then [9Xfail[109X is returned.[133X16191620[4X[32X Example [32X[104X1621[4X[25Xgap>[125X [27XSudoku.SimpleDisplay(Sudoku.OneSolution(Sudoku.Init(" 3")));[127X[104X1622[4X[28X493|876|251[128X[104X1623[4X[28X861|542|739[128X[104X1624[4X[28X527|193|648[128X[104X1625[4X[28X-----------[128X[104X1626[4X[28X942|618|573[128X[104X1627[4X[28X156|739|482[128X[104X1628[4X[28X738|425|916[128X[104X1629[4X[28X-----------[128X[104X1630[4X[28X289|354|167[128X[104X1631[4X[28X375|961|824[128X[104X1632[4X[28X614|287|395[128X[104X1633[4X[32X[104X16341635[1X6.17-7 Sudoku.UniqueSolution[101X16361637[29X[2XSudoku.UniqueSolution[102X( [3Xgame[103X ) [32X function1638[6XReturns:[106X [33X[0;10YA completed Sudoku board that solves [3Xgame[103X, or [9Xfalse[109X, or [9Xfail[109X.[133X16391640[33X[0;0YHere [3Xgame[103X must be a Sudoku board as returned by [2XSudoku.Init[102X ([14X6.17-1[114X). It is1641not necessary that [3Xgame[103X describes a proper Sudoku game. If it has several1642solutions, then [9Xfalse[109X is returned. If it has no solution, then [9Xfail[109X is1643returned. Otherwise a board with the unique solution is returned.[133X16441645[4X[32X Example [32X[104X1646[4X[25Xgap>[125X [27Xs := " 5 | 154 6 2 |9 5 3 |6 4 | 8 |8 9 53\[127X[104X1647[4X[25X>[125X [27X| 5 | 4 7 2| 91 8 ";;[127X[104X1648[4X[25Xgap>[125X [27Xsol := Sudoku.UniqueSolution(Sudoku.Init(s));;[127X[104X1649[4X[25Xgap>[125X [27XSudoku.SimpleDisplay(sol);[127X[104X1650[4X[28X438|219|576[128X[104X1651[4X[28X715|436|928[128X[104X1652[4X[28X962|758|314[128X[104X1653[4X[28X-----------[128X[104X1654[4X[28X694|573|281[128X[104X1655[4X[28X153|862|749[128X[104X1656[4X[28X827|941|653[128X[104X1657[4X[28X-----------[128X[104X1658[4X[28X281|695|437[128X[104X1659[4X[28X546|387|192[128X[104X1660[4X[28X379|124|865[128X[104X1661[4X[32X[104X16621663[1X6.17-8 PlaySudoku[101X16641665[29X[2XPlaySudoku[102X( [[3Xarg[103X] ) [32X function1666[6XReturns:[106X [33X[0;10YA record describing the latest status of a Sudoku board.[133X16671668[33X[0;0YThis function allows one to solve Sudoku puzzles interactively. There are1669several possibilities for the optional argument [3Xarg[103X. It can either be a1670string, matrix or list of holes and integers as described in [2XSudoku.Init[102X1671([14X6.17-1[114X), or a board as returned by [2XSudoku.Init[102X ([14X6.17-1[114X). Furthermore [3Xarg[103X1672can be an integer or not be given, in that case [2XSudoku.RandomGame[102X ([14X6.17-3[114X)1673is called to produce a random game.[133X16741675[33X[0;0YThe usage of this function is self-explanatory, pressing the [12X?[112X key displays1676a help screen. Here, we mention two keys with a particular action: Pressing1677the [12Xh[112X key you get a hint, either an empty entry is filled or the program1678tells you that there is no solution (so you must delete some entries and try1679others). Pressing the [12Xs[112X key the puzzle is solved by the program or it tells1680you that there is no or no unique solution.[133X16811682[33X[0;0Y[13XImplementation remarks[113X: The game board is implemented via a browse table,1683without row and column labels, with static header, dynamic footer, and1684individual [10Xminyx[110X function. Two modes are supported, with the standard1685actions for quitting the table and asking for help; one cell is selected in1686each mode. The first mode provides actions for moving the selected cell via1687arrow keys, for changing the value in the selected cell, for getting a hint1688or the (unique) solution. (Initial entries of the matrix cannot be changed1689via user input. They are shown in boldface.) The second mode serves for1690error handling: When the user enters an invalid number, i. e., a number that1691occurs already in the current row or column or subsquare, then the1692application switches to this mode, which causes that a message is shown in1693the footer, and the invalid entry is shown in red and blinking; similarly,1694error mode is entered if a hint or solution does not exist.[133X16951696[33X[0;0YThe separating lines are drawn using an individual [10XSpecialGrid[110X function in1697the browse table, since they cannot be specified within the generic browse1698table functions.[133X16991700[33X[0;0YSome standard [2XNCurses.BrowseGeneric[102X ([14X4.3-1[114X) functionality, such as1701scrolling, selecting, and searching, are not available in this application.[133X17021703[33X[0;0YThe code can be found in the file [11Xapp/sudoku.g[111X of the package.[133X17041705[1X6.17-9 Sudoku.HTMLGame[101X17061707[29X[2XSudoku.HTMLGame[102X( [3Xgame[103X ) [32X function1708[29X[2XSudoku.LaTeXGame[102X( [3Xgame[103X ) [32X function1709[6XReturns:[106X [33X[0;10YA string with HTML or LaTeX code, respectively.[133X17101711[33X[0;0YThe argument of these functions is a record describing a Sudoku game. These1712functions return code for including the current status of the board into a1713webpage or a LaTeX document.[133X171417151716[1X6.18 [33X[0;0YUtility for [5XGAP[105X[101X[1X Demos[133X[101X17171718[33X[0;0YThis application can be used with [5XGAP[105X if the user interface has [10Xreadline[110X1719support. The purpose is to simplify the typing during a demonstration of [5XGAP[105X1720commands.[133X17211722[33X[0;0YThe file format to specify [5XGAP[105X code for a demonstration is very simple: it1723contains blocks of lines with [5XGAP[105X input, separated by lines starting with a1724[10X%[110X character. Comments in such a file can be added to one or several lines1725starting with [10X%[110X. Here is the content of an example file [11Xdemo.demo[111X:[133X17261727% Add comments after a % character at the beginning of a line.1728% A comment can have several lines.1729% Here is a multi-line input block:1730g := MathieuGroup(11);;1731cl := ConjugacyClasses(g);1732% Calling a help page1733?MathieuGroup1734% The next line contains a comment in the GAP session:1735a := 12;; b := 13;; # assign two numbers1736%1737a*b;1738%17391740[33X[0;0YA demonstration can be loaded into a [5XGAP[105X session with the command[133X17411742[1X6.18-1 LoadDemoFile[101X17431744[29X[2XLoadDemoFile[102X( [3Xdemoname[103X, [3Xdemofile[103X[, [3Xsingleline[103X] ) [32X function1745[6XReturns:[106X [33X[0;10YNothing.[133X17461747[33X[0;0YThis function loads a demo file in the format described above. The argument1748[3Xdemoname[103X is a string containing a name for the demo, and [3Xdemofile[103X is the1749file name containing the demo.[133X17501751[33X[0;0YIf the optional argument [3Xsingleline[103X is given and its value is [9Xtrue[109X, the demo1752behaves differently with respect to input blocks that span several lines. By1753default full blocks are treated as a single input line for [10Xreadline[110X (maybe1754spanning several physical lines in the terminal). If [3Xsingleline[103X is [9Xtrue[109X then1755all input lines of a block except the last one are sent to [5XGAP[105X and are1756evaluated automatically before the last line of the block is displayed.[133X17571758[4X[32X Example [32X[104X1759[4X[25Xgap>[125X [27Xdirs := DirectoriesPackageLibrary("Browse");;[127X[104X1760[4X[25Xgap>[125X [27Xdemofile := Filename(dirs, "../app/demo.demo");;[127X[104X1761[4X[25Xgap>[125X [27XLoadDemoFile("My first demo", demofile);[127X[104X1762[4X[25Xgap>[125X [27XLoadDemoFile("My first demo (single lines)", demofile, true);[127X[104X1763[4X[32X[104X17641765[33X[0;0YMany demos can be loaded at the same time. They are used with the [12XPageDown[112X1766and [12XPageUp[112X keys.[133X17671768[33X[0;0YThe [12XPageUp[112X key leads to a (Browse) menu which allows one to choose a demo to1769start (if several are loaded), to stop a demo or to move to another position1770in the current demo (e.g., to go back to a previous point or to skip part of1771a demo).[133X17721773[33X[0;0YThe next input block of the current demo is copied into the current input1774line of the [5XGAP[105X session by pressing the [12XPageDown[112X key. This line is not yet1775sent to [5XGAP[105X, use the [12XReturn[112X key if you want to evaluate the input. (You can1776also still edit the input line before evaluation.)[133X17771778[33X[0;0YSo, in the simplest case a demo can be done by just pressing [12XPageDown[112X and1779[12XReturn[112X in turns. But it is always possible to type extra input during a demo1780by hand or to change the input lines from the demo file before evaluation.1781It is no problem if commands are interrupted by [12XCtrl-C[112X. During a demo you1782are in a normal [5XGAP[105X session, this application only saves you some typing.1783The input lines from the demo are put into the history of the session as if1784they were typed by hand.[133X17851786[33X[0;0YTry it yourself with the two demos loaded in the example. This also shows1787the different behaviour between default and single line mode.[133X1788178917901791