  
  [1X5 [33X[0;0YMatrices over semirings[133X[101X
  
  [33X[0;0YIn  this  chapter  we  describe the functionality in [5XSemigroups[105X for creating
  matrices  over  semirings.  [12XOnly square matrices are currently supported.[112X We
  use the term [12Xmatrix[112X to mean [12Xsquare matrix[112X everywhere in this manual.[133X
  
  [33X[0;0YFor   reference,   matrices  over  the  following  semirings  are  currently
  supported:[133X
  
  [8Xthe Boolean semiring[108X
        [33X[0;6Ythe  set [22X{0, 1}[122X where [22X0 + 0 = 0[122X, [22X0 + 1 = 1 + 1 = 1 + 0 = 1[122X, [22X1⋅ 0 = 0 ⋅
        0 = 0 ⋅ 1 = 0[122X, and [22X1⋅ 1 = 1[122X.[133X
  
  [8Xthe max-plus semiring[108X
        [33X[0;6Ythe  set of integers and negative infinity [22XZ∪ {-∞}[122X with operations max
        and plus.[133X
  
  [8Xthe min-plus semiring[108X
        [33X[0;6Ythe set of integers and infinity [22XZ∪ {∞}[122X with operations min and plus;[133X
  
  [8Xtropical max-plus semirings[108X
        [33X[0;6Ythe  set  [22X{-∞,  0, 1, ..., t}[122X for some threshold [22Xt[122X with operations max
        and plus;[133X
  
  [8Xtropical min-plus semirings[108X
        [33X[0;6Ythe set [22X{0, 1, ..., t, ∞}[122X for some threshold [22Xt[122X with operations min and
        plus;[133X
  
  [8Xthe semiring [22XN_t,p[122X[108X
        [33X[0;6Ythe  semiring  [22XN_t,p  = {0, 1, ..., t, t + 1, ..., t + p - 1}[122X for some
        threshold  [22Xt[122X and period [22Xp[122X under addition and multiplication modulo the
        congruence [22Xt = t + p[122X;[133X
  
  [8Xthe integers[108X
        [33X[0;6Ythe usual ring of integers;[133X
  
  [8Xfinite fields[108X
        [33X[0;6Ythe finite fields [10XGF(q^d)[110X for prime [10Xq[110X and some positive integer [10Xd[110X.[133X
  
  [33X[0;0YWith  the  exception of matrices of finite fields, semigroups of matrices in
  [5XSemigroups[105X  are of the second type described in Section [14X6.1[114X. In other words,
  a version of the Froidure-Pin Algorithm [FP97] is used to compute semigroups
  of  these  types,  i.e  it  is  possible  that all of the elements of such a
  semigroup are enumerated and stored in the memory of your computer.[133X
  
  
  [1X5.1 [33X[0;0YCreating matrices over semirings[133X[101X
  
  [33X[0;0YIn  this  section  we describe the two main operations for creating matrices
  over semirings in [5XSemigroups[105X, and the categories, attributes, and operations
  which  apply to every matrix over one of the semirings given at the start of
  this chapter.[133X
  
  [33X[0;0YThere  are  several special methods for boolean matrices, which can be found
  in  Section  [14X5.3[114X.  There are also several special methods for finite fields,
  which can be found in section [14X5.4[114X.[133X
  
  [1X5.1-1 IsMatrixOverSemiring[101X
  
  [33X[1;0Y[29X[2XIsMatrixOverSemiring[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YEvery  matrix  over  a  semiring  in  [5XSemigroups[105X is a member of the category
  [10XIsMatrixOverSemiring[110X,       which       is       a       subcategory      of
  [2XIsMultiplicativeElementWithOne[102X  ([14XReference: IsMultiplicativeElementWithOne[114X),
  [2XIsAssociativeElement[102X       ([14XReference:       IsAssociativeElement[114X),      and
  [10XIsPositionalObjectRep[110X; see [14X'Reference: Representation'[114X.[133X
  
  [33X[0;0YEvery matrix over a semiring in [5XSemigroups[105X is a square matrix.[133X
  
  [33X[0;0YBasic      operations      for      matrices     over     semirings     are:
  [2XDimensionOfMatrixOverSemiring[102X     ([14X5.1-3[114X),     [2XTransposedMat[102X     ([14XReference:
  TransposedMat[114X), and [2XOne[102X ([14XReference: One[114X).[133X
  
  [1X5.1-2 IsMatrixOverSemiringCollection[101X
  
  [33X[1;0Y[29X[2XIsMatrixOverSemiringCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverSemiringCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YEvery  collection of matrices over the same semiring belongs to the category
  [10XIsMatrixOverSemiringCollection[110X.  For  example, semigroups of matrices over a
  semiring belong to [10XIsMatrixOverSemiringCollection[110X.[133X
  
  [33X[0;0YEvery  collection  of collections of matrices over the same semiring belongs
  to  the  category  [10XIsMatrixOverSemiringCollColl[110X.  For  example,  a  list  of
  semigroups      of      matrices      over      semirings     belongs     to
  [10XIsMatrixOverSemiringCollColl[110X.[133X
  
  [1X5.1-3 DimensionOfMatrixOverSemiring[101X
  
  [33X[1;0Y[29X[2XDimensionOfMatrixOverSemiring[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA positive integer.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  a  matrix  over  a  semiring  (i.e.  belongs  to  the  category
  [2XIsMatrixOverSemiring[102X  ([14X5.1-1[114X)),  then  [3Xmat[103X  is  a  square  [10Xn[110X  by  [10Xn[110X  matrix.
  [10XDimensionOfMatrixOverSemiring[110X returns the dimension [10Xn[110X of [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [0, 0, 0, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 1, 1],[128X[104X
    [4X[28X  [0, 0, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XDimensionOfMatrixOverSemiring(x);[127X[104X
    [4X[28X4[128X[104X
  [4X[32X[104X
  
  [1X5.1-4 DimensionOfMatrixOverSemiringCollection[101X
  
  [33X[1;0Y[29X[2XDimensionOfMatrixOverSemiringCollection[102X( [3Xcoll[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA positive integer.[133X
  
  [33X[0;0YIf  [3Xcoll[103X  is  a  collection of matrices over a semiring (i.e. belongs to the
  category  [2XIsMatrixOverSemiringCollection[102X ([14X5.1-2[114X)), then the elements of [3Xcoll[103X
  are  square [10Xn[110X by [10Xn[110X matrices. [10XDimensionOfMatrixOverSemiringCollection[110X returns
  the dimension [10Xn[110X of these matrices.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [0, 0, 0, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [0, 1, 1, 0], [1, 0, 1, 1],[128X[104X
    [4X[28X  [0, 0, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XDimensionOfMatrixOverSemiringCollection(Semigroup(x));[127X[104X
    [4X[28X4[128X[104X
  [4X[32X[104X
  
  [1X5.1-5 Matrix[101X
  
  [33X[1;0Y[29X[2XMatrix[102X( [3Xfilt[103X, [3Xmat[103X[, [3Xthreshold[103X[, [3Xperiod[103X]] ) [32X operation[133X
  [33X[1;0Y[29X[2XMatrix[102X( [3Xsemiring[103X, [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA matrix over semiring.[133X
  
  [33X[0;0YThis  operation  can  be  used  to  construct  a  matrix  over a semiring in
  [5XSemigroups[105X.[133X
  
  [33X[0;0YIn  its  first form, the first argument [3Xfilt[103X specifies the filter to be used
  to  create  the matrix, the second argument [3Xmat[103X is a [5XGAP[105X matrix (i.e. a list
  of lists) compatible with [3Xfilt[103X, the third and fourth arguments [3Xthreshold[103X and
  [3Xperiod[103X (if required) must be positive integers.[133X
  
  [8X[3Xfilt[103X[8X[108X
        [33X[0;6YThis must be one of the filters given in Section [14X5.1-8[114X.[133X
  
  [8X[3Xmat[103X[8X[108X
        [33X[0;6YThis  must  be  a  list  of  [10Xn[110X  lists  each of length [10Xn[110X (i.e. a square
        matrix),  consisting  of elements belonging to the underlying semiring
        described  by  [3Xfilt[103X,  and [3Xthreshold[103X and [3Xperiod[103X if present. An error is
        given if [3Xmat[103X is not compatible with the other arguments.[133X
  
        [33X[0;6YFor  example, if [3Xfilt[103X is [10XIsMaxPlusMatrix[110X, then the entries of [3Xmat[103X must
        belong to the max-plus semiring, i.e. they must be integers or -[22X∞[122X.[133X
  
        [33X[0;6YThe  supported  semirings  are  fully  described  at the start of this
        chapter.[133X
  
  [8X[3Xthreshold[103X[8X[108X
        [33X[0;6YIf     [3Xfilt[103X     is    any    of    [2XIsTropicalMaxPlusMatrix[102X    ([14X5.1-8[114X),
        [2XIsTropicalMinPlusMatrix[102X  ([14X5.1-8[114X),  or  [2XIsNTPMatrix[102X  ([14X5.1-8[114X), then this
        argument  specifies  the  threshold  of the underlying semiring of the
        matrix being created.[133X
  
  [8X[3Xperiod[103X[8X[108X
        [33X[0;6YIf  [3Xfilt[103X  is  [2XIsNTPMatrix[102X  ([14X5.1-8[114X),  then  this argument specifies the
        period of the underlying semiring of the matrix being created.[133X
  
  [33X[0;0YIn  its  second form, the arguments should be a semiring [3Xsemiring[103X and matrix
  [3Xmat[103X  with  entries  in [3Xsemiring[103X. Currently, the only supported semirings are
  finite  fields  of  prime  order,  and  the  integers  [2XIntegers[102X  ([14XReference:
  Integers[114X).[133X
  
  [33X[0;0YThe  function  [2XBooleanMat[102X  ([14X5.3-1[114X)  is  provided  for  specifically creating
  boolean matrices.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XMatrix(IsBooleanMat, [[1, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                         [0, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                         [1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                         [1, 0, 1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 0], [0, 0, 0, 0], [1, 1, 1, 1],[128X[104X
    [4X[28X  [1, 0, 1, 1]])[128X[104X
    [4X[25Xgap>[125X [27XMatrix(IsMaxPlusMatrix, [[4, 0, -2],[127X[104X
    [4X[25X>[125X [27X                            [1, -3, 0],[127X[104X
    [4X[25X>[125X [27X                            [5, -1, -4]]);[127X[104X
    [4X[28XMatrix(IsMaxPlusMatrix, [[4, 0, -2], [1, -3, 0], [5, -1, -4]])[128X[104X
    [4X[25Xgap>[125X [27XMatrix(IsMinPlusMatrix, [[-1, infinity],[127X[104X
    [4X[25X>[125X [27X                            [1, -1]]);[127X[104X
    [4X[28XMatrix(IsMinPlusMatrix, [[-1, infinity], [1, -1]])[128X[104X
    [4X[25Xgap>[125X [27XMatrix(IsTropicalMaxPlusMatrix, [[3, 2, 4],[127X[104X
    [4X[25X>[125X [27X                                    [3, 1, 1],[127X[104X
    [4X[25X>[125X [27X                                    [-infinity, 1, 1]],[127X[104X
    [4X[25X>[125X [27X          9);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[3, 2, 4], [3, 1, 1],[128X[104X
    [4X[28X  [-infinity, 1, 1]], 9)[128X[104X
    [4X[25Xgap>[125X [27XMatrix(IsTropicalMinPlusMatrix, [[1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                                    [0, 3, 0],[127X[104X
    [4X[25X>[125X [27X                                    [1, 1, 3]],[127X[104X
    [4X[25X>[125X [27X          9);[127X[104X
    [4X[28XMatrix(IsTropicalMinPlusMatrix, [[1, 1, 1], [0, 3, 0], [1, 1, 3]], 9)[128X[104X
    [4X[25Xgap>[125X [27XMatrix(IsNTPMatrix, [[0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                        [2, 0, 1],[127X[104X
    [4X[25X>[125X [27X                        [2, 2, 2]],[127X[104X
    [4X[25X>[125X [27X          2, 1);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 0, 0], [2, 0, 1], [2, 2, 2]], 2, 1)[128X[104X
    [4X[25Xgap>[125X [27XMatrix(Integers, [[-1, -2, 0],[127X[104X
    [4X[25X>[125X [27X                     [0, 3, -1],[127X[104X
    [4X[25X>[125X [27X                     [1, 0, -3]]);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27XMatrix(Integers, [[-1, -2, 0],[127X[104X
    [4X[25X>[125X [27X                     [0, 3, -1],[127X[104X
    [4X[25X>[125X [27X                     [1, 0, -3]]);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
  [4X[32X[104X
  
  [1X5.1-6 AsMatrix[101X
  
  [33X[1;0Y[29X[2XAsMatrix[102X( [3Xfilt[103X, [3Xmat[103X ) [32X operation[133X
  [33X[1;0Y[29X[2XAsMatrix[102X( [3Xfilt[103X, [3Xmat[103X, [3Xthreshold[103X ) [32X operation[133X
  [33X[1;0Y[29X[2XAsMatrix[102X( [3Xfilt[103X, [3Xmat[103X, [3Xthreshold[103X, [3Xperiod[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA matrix.[133X
  
  [33X[0;0YThis  operation can be used to change the representation of certain matrices
  over  semirings.  If  [3Xmat[103X  is  a  matrix  over  a  semiring (in the category
  [2XIsMatrixOverSemiring[102X   ([14X5.1-1[114X)),   then   [10XAsMatrix[110X   returns  a  new  matrix
  corresponding  to  [3Xmat[103X  of  the  type  specified  by the filter [3Xfilt[103X, and if
  applicable  the  arguments [3Xthreshold[103X and [3Xperiod[103X. The dimension of the matrix
  [3Xmat[103X is not changed by this operation.[133X
  
  [33X[0;0YThe version of the operation with arguments [3Xfilt[103X and [3Xmat[103X can be applied to:[133X
  
  [30X    [33X[0;6Y[2XIsMinPlusMatrix[102X ([14X5.1-8[114X) and a tropical min-plus matrix (i.e. convert a
        tropical min-plus matrix to a (non-tropical) min-plus matrix);[133X
  
  [30X    [33X[0;6Y[2XIsMaxPlusMatrix[102X ([14X5.1-8[114X) and a tropical max-plus matrix;[133X
  
  [33X[0;0YThe  version of the operation with arguments [3Xfilt[103X, [3Xmat[103X, and [3Xthreshold[103X can be
  applied to:[133X
  
  [30X    [33X[0;6Y[2XIsTropicalMinPlusMatrix[102X  ([14X5.1-8[114X),  a  tropical  min-plus  or  min-plus
        matrix, and a value for the threshold of the resulting matrix.[133X
  
  [30X    [33X[0;6Y[2XIsTropicalMaxPlusMatrix[102X  ([14X5.1-8[114X)  and a tropical max-plus, or max-plus
        matrix, and a value for the threshold of the resulting matrix.[133X
  
  [33X[0;0YThe version of the operation with arguments [3Xfilt[103X, [3Xmat[103X, [3Xthreshold[103X, and [3Xperiod[103X
  can be applied to [2XIsNTPMatrix[102X ([14X5.1-8[114X) and an ntp matrix, or integer matrix.[133X
  
  [33X[0;0YWhen converting matrices with negative entries to an ntp, tropical max-plus,
  or tropical min-plus matrix, the entry is replaced with its absolute value.[133X
  
  [33X[0;0YWhen  converting  non-tropical  matrices to tropical matrices entries higher
  than the specified threshold are reduced to the threshold.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsTropicalMinPlusMatrix, [[0, 1, 3],[127X[104X
    [4X[25X>[125X [27X                                           [1, 1, 6],[127X[104X
    [4X[25X>[125X [27X                                           [0, 4, 2]], 10);;[127X[104X
    [4X[25Xgap>[125X [27XAsMatrix(IsMinPlusMatrix, mat);[127X[104X
    [4X[28XMatrix(IsMinPlusMatrix, [[0, 1, 3], [1, 1, 6], [0, 4, 2]])[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsTropicalMaxPlusMatrix, [[-infinity, -infinity, 3],[127X[104X
    [4X[25X>[125X [27X                                           [0, 1, 3],[127X[104X
    [4X[25X>[125X [27X                                           [4, 1, 0]], 10);;[127X[104X
    [4X[25Xgap>[125X [27XAsMatrix(IsMaxPlusMatrix, mat);[127X[104X
    [4X[28XMatrix(IsMaxPlusMatrix, [[-infinity, -infinity, 3], [0, 1, 3],[128X[104X
    [4X[28X  [4, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsNTPMatrix, [[1, 2, 2],[127X[104X
    [4X[25X>[125X [27X                               [0, 2, 0],[127X[104X
    [4X[25X>[125X [27X                               [1, 3, 0]], 4, 5);;[127X[104X
    [4X[25Xgap>[125X [27XMatrix(Integers, mat);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsMinPlusMatrix, [[0, 1, 3], [1, 1, 6], [0, 4, 2]]);;[127X[104X
    [4X[25Xgap>[125X [27Xmat := AsMatrix(IsTropicalMinPlusMatrix, mat, 2);[127X[104X
    [4X[28XMatrix(IsTropicalMinPlusMatrix, [[0, 1, 2], [1, 1, 2], [0, 2, 2]], 2)[128X[104X
    [4X[25Xgap>[125X [27Xmat := AsMatrix(IsTropicalMinPlusMatrix, mat, 1);[127X[104X
    [4X[28XMatrix(IsTropicalMinPlusMatrix, [[0, 1, 1], [1, 1, 1], [0, 1, 1]], 1)[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsTropicalMaxPlusMatrix, [[-infinity, -infinity, 3],[127X[104X
    [4X[25X>[125X [27X                                           [0, 1, 3],[127X[104X
    [4X[25X>[125X [27X                                           [4, 1, 0]], 10);;[127X[104X
    [4X[25Xgap>[125X [27XAsMatrix(IsTropicalMaxPlusMatrix, mat, 4);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[-infinity, -infinity, 3],[128X[104X
    [4X[28X  [0, 1, 3], [4, 1, 0]], 4)[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsMaxPlusMatrix, [[-infinity, -infinity, 3],[127X[104X
    [4X[25X>[125X [27X                                   [0, 1, 3],[127X[104X
    [4X[25X>[125X [27X                                   [4, 1, 0]]);;[127X[104X
    [4X[25Xgap>[125X [27XAsMatrix(IsTropicalMaxPlusMatrix, mat, 10);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[-infinity, -infinity, 3],[128X[104X
    [4X[28X  [0, 1, 3], [4, 1, 0]], 10)[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsNTPMatrix, [[0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                               [1, 3, 1],[127X[104X
    [4X[25X>[125X [27X                               [1, 0, 1]], 10, 10);;[127X[104X
    [4X[25Xgap>[125X [27Xmat := AsMatrix(IsNTPMatrix, mat, 5, 6);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 1, 0], [1, 3, 1], [1, 0, 1]], 5, 6)[128X[104X
    [4X[25Xgap>[125X [27Xmat := AsMatrix(IsNTPMatrix, mat, 2, 6);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 1, 0], [1, 3, 1], [1, 0, 1]], 2, 6)[128X[104X
    [4X[25Xgap>[125X [27Xmat := AsMatrix(IsNTPMatrix, mat, 2, 1);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]], 2, 1)[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, mat);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27XAsMatrix(IsNTPMatrix, mat, 1, 2);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 1, 0], [1, 2, 1], [1, 0, 1]], 1, 2)[128X[104X
  [4X[32X[104X
  
  [1X5.1-7 RandomMatrix[101X
  
  [33X[1;0Y[29X[2XRandomMatrix[102X( [3Xfilt[103X, [3Xdim[103X[, [3Xthreshold[103X[, [3Xperiod[103X]] ) [32X function[133X
  [33X[1;0Y[29X[2XRandomMatrix[102X( [3Xsemiring[103X, [3Xdim[103X ) [32X function[133X
  [6XReturns:[106X  [33X[0;10YA matrix over semiring.[133X
  
  [33X[0;0YThis  operation  can be used to construct a random matrix over a semiring in
  [5XSemigroups[105X. The usage of [10XRandomMatrix[110X is similar to that of [2XMatrix[102X ([14X5.1-5[114X).[133X
  
  [33X[0;0YIn  its  first form, the first argument [3Xfilt[103X specifies the filter to be used
  to  create  the  matrix, the second argument [3Xdim[103X is dimension of the matrix,
  the  third  and  fourth arguments [3Xthreshold[103X and [3Xperiod[103X (if required) must be
  positive integers.[133X
  
  [8X[3Xfilt[103X[8X[108X
        [33X[0;6YThis must be one of the filters given in Section [14X5.1-8[114X.[133X
  
  [8X[3Xdim[103X[8X[108X
        [33X[0;6YThis must be a positive integer.[133X
  
  [8X[3Xthreshold[103X[8X[108X
        [33X[0;6YIf     [3Xfilt[103X     is    any    of    [2XIsTropicalMaxPlusMatrix[102X    ([14X5.1-8[114X),
        [2XIsTropicalMinPlusMatrix[102X  ([14X5.1-8[114X),  or  [2XIsNTPMatrix[102X  ([14X5.1-8[114X), then this
        argument  specifies  the  threshold  of the underlying semiring of the
        matrix being created.[133X
  
  [8X[3Xperiod[103X[8X[108X
        [33X[0;6YIf  [3Xfilt[103X  is  [2XIsNTPMatrix[102X  ([14X5.1-8[114X),  then  this argument specifies the
        period of the underlying semiring of the matrix being created.[133X
  
  [33X[0;0YIn  its  second  form,  the  arguments  should  be  a  semiring [3Xsemiring[103X and
  dimension  [3Xdim[103X. Currently, the only supported semirings are finite fields of
  prime order and the integers [2XIntegers[102X ([14XReference: Integers[114X).[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsBooleanMat, 3);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0], [1, 0, 1], [1, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsMaxPlusMatrix, 2);[127X[104X
    [4X[28XMatrix(IsMaxPlusMatrix, [[1, -infinity], [1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsMinPlusMatrix, 3);[127X[104X
    [4X[28XMatrix(IsMinPlusMatrix, [[infinity, 2, infinity], [4, 0, -2], [1, -3, 0]])[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsTropicalMaxPlusMatrix, 3, 5);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[5, 1, 4], [1, -infinity, 1], [1, 0, 2]],[128X[104X
    [4X[28X  5)[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsTropicalMinPlusMatrix, 3, 2);[127X[104X
    [4X[28XMatrix(IsTropicalMinPlusMatrix, [[1, -infinity, -infinity], [1, 1, 1],[128X[104X
    [4X[28X  [2, 2, 1]], 2)[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(IsNTPMatrix, 3, 2, 5);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[1, 1, 1], [1, 1, 0], [3, 0, 1]], 2, 5)[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(Integers, 2);[127X[104X
    [4X[28XMatrix(Integers, [[1, 3], [0, 0]])[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(Integers, 2);[127X[104X
    [4X[28XMatrix(Integers, [[-1, 0], [0, -1]])[128X[104X
    [4X[25Xgap>[125X [27XRandomMatrix(GF(5), 1);[127X[104X
    [4X[28XMatrix(GF(5), [[Z(5)^0]])[128X[104X
  [4X[32X[104X
  
  
  [1X5.1-8 [33X[0;0YMatrix filters[133X[101X
  
  [33X[1;0Y[29X[2XIsBooleanMat[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverFiniteField[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMaxPlusMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMinPlusMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMaxPlusMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMinPlusMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsNTPMatrix[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIntegers[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YEvery  matrix  over  a  semiring  in  [5XSemigroups[105X is a member of one of these
  categories, which are subcategory of [2XIsMatrixOverSemiring[102X ([14X5.1-1[114X).[133X
  
  [33X[0;0Y[10XIsTropicalMatrix[110X   is   a   supercategory   of  [10XIsTropicalMaxPlusMatrix[110X  and
  [10XIsTropicalMinPlusMatrix[110X.[133X
  
  [33X[0;0YBasic operations for matrices over semirings include: multiplication via \*,
  [2XDimensionOfMatrixOverSemiring[102X  ([14X5.1-3[114X), [2XOne[102X ([14XReference: One[114X), the underlying
  list  of  lists  used  to  create  the  matrix  can be accessed using [2XAsList[102X
  ([14X5.1-10[114X),  the rows of [10Xmat[110X can be accessed using [10Xmat[i][110X where [10Xi[110X is between [10X1[110X
  and the dimension of the matrix, it also possible to loop over the rows of a
  matrix;  for  tropical  matrices  [2XThresholdTropicalMatrix[102X  ([14X5.1-11[114X); for ntp
  matrices [2XThresholdNTPMatrix[102X ([14X5.1-12[114X) and [2XPeriodNTPMatrix[102X ([14X5.1-12[114X).[133X
  
  [33X[0;0YFor  matrices  over finite fields see Section [14X5.4[114X; for Boolean matrices more
  details can be found in Section [14X5.3[114X.[133X
  
  
  [1X5.1-9 [33X[0;0YMatrix collection filters[133X[101X
  
  [33X[1;0Y[29X[2XIsBooleanMatCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsBooleanMatCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverFiniteFieldCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverFiniteFieldCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMaxPlusMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMaxPlusMatrixCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMinPlusMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMinPlusMatrixCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMaxPlusMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMaxPlusMatrixCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMinPlusMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMinPlusMatrixCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsNTPMatrixCollection[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsNTPMatrixCollColl[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YEvery collection of matrices over the same semiring in [5XSemigroups[105X belongs to
  one  of  the  categories  above. For example, semigroups of boolean matrices
  belong to [10XIsBooleanMatCollection[110X.[133X
  
  [33X[0;0YSimilarly,  every  collection  of  collections  of  matrices  over  the same
  semiring in [5XSemigroups[105X belongs to one of the categories above.[133X
  
  [1X5.1-10 AsList[101X
  
  [33X[1;0Y[29X[2XAsList[102X( [3Xmat[103X ) [32X attribute[133X
  [33X[1;0Y[29X[2XAsMutableList[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA list of lists.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  a  matrix over a semiring (in the category [2XIsMatrixOverSemiring[102X
  ([14X5.1-1[114X)),  then  [10XAsList[110X  returns  the  underlying  list of lists of semiring
  elements  corresponding  to  [3Xmat[103X. In this case, the returned list and all of
  its entries are immutable.[133X
  
  [33X[0;0YThe operation [10XAsMutableList[110X returns a mutable copy of the underlying list of
  lists of the matrix over semiring [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsNTPMatrix,[127X[104X
    [4X[25X>[125X [27X                 [[0, 1, 0], [1, 3, 1], [1, 0, 1]], 5, 6);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[0, 1, 0], [1, 3, 1], [1, 0, 1]], 5, 6)[128X[104X
    [4X[25Xgap>[125X [27Xlist := AsList(mat);[127X[104X
    [4X[28X[ [ 0, 1, 0 ], [ 1, 3, 1 ], [ 1, 0, 1 ] ][128X[104X
    [4X[25Xgap>[125X [27XIsMutable(list);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XIsMutable(list[1]);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xlist := AsMutableList(mat);[127X[104X
    [4X[28X[ [ 0, 1, 0 ], [ 1, 3, 1 ], [ 1, 0, 1 ] ][128X[104X
    [4X[25Xgap>[125X [27XIsMutable(list);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsMutable(list[1]);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xmat = Matrix(IsNTPMatrix, AsList(mat), 5, 6);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.1-11 ThresholdTropicalMatrix[101X
  
  [33X[1;0Y[29X[2XThresholdTropicalMatrix[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA positive integer.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is a tropical matrix (i.e. belongs to the category [2XIsTropicalMatrix[102X
  ([14X5.1-8[114X)),  then  [10XThresholdTropicalMatrix[110X  returns  the  threshold  (i.e. the
  largest integer) of the underlying semiring.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsTropicalMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X[[0, 3, 0, 2],[127X[104X
    [4X[25X>[125X [27X [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X [-infinity, 1, -infinity, 1],[127X[104X
    [4X[25X>[125X [27X [0, -infinity, 2, -infinity]], 10);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[0, 3, 0, 2], [1, 1, 1, 0],[128X[104X
    [4X[28X  [-infinity, 1, -infinity, 1], [0, -infinity, 2, -infinity]], 10)[128X[104X
    [4X[25Xgap>[125X [27XThresholdTropicalMatrix(mat);[127X[104X
    [4X[28X10[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsTropicalMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X[[0, 3, 0, 2],[127X[104X
    [4X[25X>[125X [27X [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X [-infinity, 1, -infinity, 1],[127X[104X
    [4X[25X>[125X [27X [0, -infinity, 2, -infinity]], 3);[127X[104X
    [4X[28XMatrix(IsTropicalMaxPlusMatrix, [[0, 3, 0, 2], [1, 1, 1, 0],[128X[104X
    [4X[28X  [-infinity, 1, -infinity, 1], [0, -infinity, 2, -infinity]], 3)[128X[104X
    [4X[25Xgap>[125X [27XThresholdTropicalMatrix(mat);[127X[104X
    [4X[28X3[128X[104X
  [4X[32X[104X
  
  [1X5.1-12 ThresholdNTPMatrix[101X
  
  [33X[1;0Y[29X[2XThresholdNTPMatrix[102X( [3Xmat[103X ) [32X attribute[133X
  [33X[1;0Y[29X[2XPeriodNTPMatrix[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA positive integer.[133X
  
  [33X[0;0YAn  [12Xntp matrix[112X is a matrix with entries in a semiring [22XN_t,p = {0, 1, ..., t,
  t  + 1, ..., t + p - 1}[122X for some threshold [22Xt[122X and period [22Xp[122X under addition and
  multiplication modulo the congruence [22Xt = t + p[122X.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is a ntp matrix (i.e. belongs to the category [2XIsNTPMatrix[102X ([14X5.1-8[114X)),
  then  [10XThresholdNTPMatrix[110X and [10XPeriodNTPMatrix[110X return the threshold and period
  of the underlying semiring, respectively.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsNTPMatrix, [[1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                               [2, 1, 0],[127X[104X
    [4X[25X>[125X [27X                               [0, 1, 1]],[127X[104X
    [4X[25X>[125X [27X                 1, 2);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[1, 1, 0], [2, 1, 0], [0, 1, 1]], 1, 2)[128X[104X
    [4X[25Xgap>[125X [27XThresholdNTPMatrix(mat);[127X[104X
    [4X[28X1[128X[104X
    [4X[25Xgap>[125X [27XPeriodNTPMatrix(mat);[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(IsNTPMatrix, [[2, 1, 3],[127X[104X
    [4X[25X>[125X [27X                               [0, 5, 1],[127X[104X
    [4X[25X>[125X [27X                               [4, 1, 0]],[127X[104X
    [4X[25X>[125X [27X                 3, 4);[127X[104X
    [4X[28XMatrix(IsNTPMatrix, [[2, 1, 3], [0, 5, 1], [4, 1, 0]], 3, 4)[128X[104X
    [4X[25Xgap>[125X [27XThresholdNTPMatrix(mat);[127X[104X
    [4X[28X3[128X[104X
    [4X[25Xgap>[125X [27XPeriodNTPMatrix(mat);[127X[104X
    [4X[28X4[128X[104X
  [4X[32X[104X
  
  
  [1X5.2 [33X[0;0YOperators for matrices over semirings[133X[101X
  
  [8X[10X[3Xmat1[103X[8X[10X * [3Xmat2[103X[8X[10X[110X[8X[108X
        [33X[0;6Yreturns  the  product of the matrices [3Xmat1[103X and [3Xmat2[103X of equal dimension
        over  the same semiring using the usual matrix multiplication with the
        operations [10X+[110X and [10X*[110X from the underlying semiring.[133X
  
  [8X[10X[3Xmat1[103X[8X[10X < [3Xmat2[103X[8X[10X[110X[8X[108X
        [33X[0;6Yreturns  [9Xtrue[109X if when considered as a list of rows, the matrix [3Xmat1[103X is
        short-lex  less  than  the  matrix  [3Xmat2[103X, and [9Xfalse[109X if this is not the
        case.  This  means  that  a  matrix  of lower dimension is less than a
        matrix of higher dimension.[133X
  
  [8X[10X[3Xmat1[103X[8X[10X = [3Xmat2[103X[8X[10X[110X[8X[108X
        [33X[0;6Yreturns  [9Xtrue[109X  if  the  matrix  [3Xmat1[103X  equals the matrix [3Xmat2[103X (i.e. the
        entries  are equal and the underlying semirings are equal) and returns
        [9Xfalse[109X if it does not.[133X
  
  
  [1X5.3 [33X[0;0YBoolean matrices[133X[101X
  
  [33X[0;0YIn  this  section  we describe the operations, properties, and attributes in
  [5XSemigroups[105X specifically for Boolean matrices. These include:[133X
  
  [30X    [33X[0;6Y[2XNumberBooleanMat[102X ([14X5.3-6[114X)[133X
  
  [30X    [33X[0;6Y[2XSuccessors[102X ([14X5.3-5[114X)[133X
  
  [30X    [33X[0;6Y[2XIsRowTrimBooleanMat[102X    ([14X5.3-9[114X),   [2XIsColTrimBooleanMat[102X   ([14X5.3-9[114X),   and
        [2XIsTrimBooleanMat[102X ([14X5.3-9[114X),[133X
  
  [30X    [33X[0;6Y[2XCanonicalBooleanMat[102X ([14X5.3-8[114X)[133X
  
  [30X    [33X[0;6Y[2XIsSymmetricBooleanMat[102X ([14X5.3-10[114X)[133X
  
  [30X    [33X[0;6Y[2XIsAntiSymmetricBooleanMat[102X ([14X5.3-13[114X)[133X
  
  [30X    [33X[0;6Y[2XIsTransitiveBooleanMat[102X ([14X5.3-12[114X)[133X
  
  [30X    [33X[0;6Y[2XIsReflexiveBooleanMat[102X ([14X5.3-11[114X)[133X
  
  [30X    [33X[0;6Y[2XIsTotalBooleanMat[102X ([14X5.3-14[114X)[133X
  
  [30X    [33X[0;6Y[2XIsOntoBooleanMat[102X ([14X5.3-14[114X)[133X
  
  [30X    [33X[0;6Y[2XIsPartialOrderBooleanMat[102X ([14X5.3-15[114X)[133X
  
  [30X    [33X[0;6Y[2XIsEquivalenceBooleanMat[102X ([14X5.3-16[114X)[133X
  
  [1X5.3-1 BooleanMat[101X
  
  [33X[1;0Y[29X[2XBooleanMat[102X( [3Xarg[103X ) [32X function[133X
  [6XReturns:[106X  [33X[0;10YA boolean matrix.[133X
  
  [33X[0;0Y[10XBooleanMat[110X  returns  the  boolean  matrix  [10Xmat[110X  defined by its argument. The
  argument can be any of the following:[133X
  
  [8Xa matrix with entries [10X0[110X[8X and/or [10X1[110X[8X[108X
        [33X[0;6Ythe  argument  [3Xarg[103X  is  list  of [10Xn[110X lists of length [10Xn[110X consisting of the
        values [10X0[110X and [10X1[110X;[133X
  
  [8Xa matrix with entries [9Xtrue[109X and/or [9Xfalse[109X[108X
        [33X[0;6Ythe  argument  [3Xarg[103X  is  list  of [10Xn[110X lists of length [10Xn[110X consisting of the
        values [9Xtrue[109X and [9Xfalse[109X;[133X
  
  [8Xsuccessors[108X
        [33X[0;6Ythe  argument  [3Xarg[103X  is  list  of  [10Xn[110X sublists of consisting of positive
        integers  not greater than [10Xn[110X. In this case, the entry [10Xj[110X in the sublist
        in  position  [10Xi[110X  of [3Xarg[103X indicates that the entry in position [10X(i, j)[110X of
        the created boolean matrix is [9Xtrue[109X.[133X
  
  [33X[0;0Y[10XBooleanMat[110X returns an error if the argument is not one of the above types.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[true, false], [true, true]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0], [1, 1]])[128X[104X
    [4X[25Xgap>[125X [27Xy := BooleanMat([[1, 0], [1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0], [1, 1]])[128X[104X
    [4X[25Xgap>[125X [27Xz := BooleanMat([[1], [1, 2]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0], [1, 1]])[128X[104X
    [4X[25Xgap>[125X [27Xx = y;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xy = z;[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XDisplay(x);[127X[104X
    [4X[28X1 0[128X[104X
    [4X[28X1 1[128X[104X
  [4X[32X[104X
  
  [1X5.3-2 AsBooleanMat[101X
  
  [33X[1;0Y[29X[2XAsBooleanMat[102X( [3Xx[103X[, [3Xn[103X] ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA boolean matrix.[133X
  
  [33X[0;0Y[10XAsBooleanMat[110X  returns  the pbr, bipartition, permutation, transformation, or
  partial permutation [3Xx[103X, as a boolean matrix of dimension [3Xn[103X.[133X
  
  [33X[0;0YThere are several possible arguments for [10XAsBooleanMat[110X:[133X
  
  [8Xpermutations[108X
        [33X[0;6YIf   [3Xx[103X   is   a   permutation  and  [3Xn[103X  is  a  positive  integer,  then
        [10XAsBooleanMat([3Xx[103X[10X,  [3Xn[103X[10X)[110X returns the boolean matrix [10Xmat[110X of dimension [3Xn[103X such
        that [10Xmat[i][j] = true[110X if and only if [10Xj = i ^ x[110X.[133X
  
        [33X[0;6YIf no positive integer [3Xn[103X is specified, then the largest moved point of
        [3Xx[103X  is  used  as  the  value  for  [3Xn[103X; see [2XLargestMovedPoint[102X ([14XReference:
        LargestMovedPoint for a permutation[114X).[133X
  
  [8Xtransformations[108X
        [33X[0;6YIf  [3Xx[103X is a transformation and [3Xn[103X is a positive integer such that [3Xx[103X is a
        transformation  of [10X[1 .. [3Xn[103X[10X][110X, then [10XAsTransformation[110X returns the boolean
        matrix  [10Xmat[110X of dimension [3Xn[103X such that [10Xmat[i][j] = true[110X if and only if [10Xj
        = i ^ x[110X.[133X
  
        [33X[0;6YIf  the  positive  integer [3Xn[103X is not specified, then the degree of [3Xf[103X is
        used as the value for [3Xn[103X.[133X
  
  [8Xpartial permutations[108X
        [33X[0;6YIf  [3Xx[103X is a partial permutation and [3Xn[103X is a positive integer such that [10Xi
        ^  [3Xx[103X[10X <= n[110X for all [10Xi[110X in [10X[1 .. [3Xn[103X[10X][110X, then [10XAsBooleanMat[110X returns the boolean
        matrix  [10Xmat[110X of dimension [3Xn[103X such that [10Xmat[i][j] = true[110X if and only if [10Xj
        = i ^ x[110X.[133X
  
        [33X[0;6YIf  the  optional argument [3Xn[103X is not present, then the default value of
        the maximum of degree and the codegree of [3Xx[103X is used.[133X
  
  [8Xbipartitions[108X
        [33X[0;6YIf  [3Xx[103X  is  a  bipartition  and  [3Xn[103X  is  any  non-negative integer, then
        [10XAsBooleanMat[110X  returns  the boolean matrix [10Xmat[110X of dimension [3Xn[103X such that
        [10Xmat[i][j] = true[110X if and only if [10Xi[110X and [10Xj[110X belong to the same block of [3Xx[103X.[133X
  
        [33X[0;6YIf  the optional argument [3Xn[103X is not present, then twice the degree of [3Xx[103X
        is used by default.[133X
  
  [8Xpbrs[108X
        [33X[0;6YIf  [3Xx[103X  is  a  pbr and [3Xn[103X is any non-negative integer, then [10XAsBooleanMat[110X
        returns  the  boolean  matrix [10Xmat[110X of dimension [3Xn[103X such that [10Xmat[i][j] =
        true[110X if and only if [10Xi[110X and [10Xj[110X are related in [3Xx[103X.[133X
  
        [33X[0;6YIf  the optional argument [3Xn[103X is not present, then twice the degree of [3Xx[103X
        is used by default.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat((1, 2), 5));[127X[104X
    [4X[28X0 1 0 0 0[128X[104X
    [4X[28X1 0 0 0 0[128X[104X
    [4X[28X0 0 1 0 0[128X[104X
    [4X[28X0 0 0 1 0[128X[104X
    [4X[28X0 0 0 0 1[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat((1, 2)));[127X[104X
    [4X[28X0 1[128X[104X
    [4X[28X1 0[128X[104X
    [4X[25Xgap>[125X [27Xx := Transformation([1, 3, 4, 1, 3]);;[127X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x));[127X[104X
    [4X[28X1 0 0 0 0[128X[104X
    [4X[28X0 0 1 0 0[128X[104X
    [4X[28X0 0 0 1 0[128X[104X
    [4X[28X1 0 0 0 0[128X[104X
    [4X[28X0 0 1 0 0[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x, 4));[127X[104X
    [4X[28X1 0 0 0[128X[104X
    [4X[28X0 0 1 0[128X[104X
    [4X[28X0 0 0 1[128X[104X
    [4X[28X1 0 0 0[128X[104X
    [4X[25Xgap>[125X [27Xx := PartialPerm([1, 2, 3, 6, 8, 10],[127X[104X
    [4X[25X>[125X [27X                    [2, 6, 7, 9, 1, 5]);[127X[104X
    [4X[28X[3,7][8,1,2,6,9][10,5][128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x));[127X[104X
    [4X[28X0 1 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 1 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 0 1 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 1 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X1 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[28X0 0 0 0 1 0 0 0 0 0[128X[104X
    [4X[25Xgap>[125X [27Xx := Bipartition([[1, 4, -2, -3], [2, 3, 5, -5], [-1, -4]]);[127X[104X
    [4X[28X<bipartition: [ 1, 4, -2, -3 ], [ 2, 3, 5, -5 ], [ -1, -4 ]>[128X[104X
    [4X[25Xgap>[125X [27Xy := AsBooleanMat(x);[127X[104X
    [4X[28X<10x10 boolean matrix>[128X[104X
    [4X[25Xgap>[125X [27XDisplay(y);[127X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1[128X[104X
    [4X[28X0 0 0 0 0 1 0 0 1 0[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0[128X[104X
    [4X[28X0 0 0 0 0 1 0 0 1 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1[128X[104X
    [4X[25Xgap>[125X [27XIsEquivalenceBooleanMat(y);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XAsBooleanMat(x, 1);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1]])[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x, 1));[127X[104X
    [4X[28X1[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x, 2));[127X[104X
    [4X[28X1 0[128X[104X
    [4X[28X0 1[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x, 3));[127X[104X
    [4X[28X1 0 0[128X[104X
    [4X[28X0 1 1[128X[104X
    [4X[28X0 1 1[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x, 11));[127X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1 0[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1 0[128X[104X
    [4X[28X0 0 0 0 0 1 0 0 1 0 0[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0 0[128X[104X
    [4X[28X1 0 0 1 0 0 1 1 0 0 0[128X[104X
    [4X[28X0 0 0 0 0 1 0 0 1 0 0[128X[104X
    [4X[28X0 1 1 0 1 0 0 0 0 1 0[128X[104X
    [4X[28X0 0 0 0 0 0 0 0 0 0 0[128X[104X
    [4X[25Xgap>[125X [27Xx := PBR([127X[104X
    [4X[25X>[125X [27X[[-1, 1], [2, 3], [-3, 2, 3]],[127X[104X
    [4X[25X>[125X [27X[[-1, 1, 2], [-3, -1, 1, 3], [-3, -1, 1, 2, 3]]);;[127X[104X
    [4X[25Xgap>[125X [27XAsBooleanMat(x);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1, 0, 0], [0, 1, 1, 0, 0, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0, 0, 1], [1, 1, 0, 1, 0, 0], [1, 0, 1, 1, 0, 1],[128X[104X
    [4X[28X  [1, 1, 1, 1, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XDisplay(AsBooleanMat(x));[127X[104X
    [4X[28X1 0 0 1 0 0[128X[104X
    [4X[28X0 1 1 0 0 0[128X[104X
    [4X[28X0 1 1 0 0 1[128X[104X
    [4X[28X1 1 0 1 0 0[128X[104X
    [4X[28X1 0 1 1 0 1[128X[104X
    [4X[28X1 1 1 1 0 1[128X[104X
  [4X[32X[104X
  
  [1X5.3-3 \in[101X
  
  [33X[1;0Y[29X[2X\in[102X( [3Xmat1[103X, [3Xmat2[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YIf [3Xmat1[103X and [3Xmat2[103X are boolean matrices, then [10X[3Xmat1[103X[10X in [3Xmat2[103X[10X[110X returns [9Xtrue[109X if the
  binary relation defined by [3Xmat1[103X is a subset of that defined by [3Xmat2[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1], [0, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1], [0, 1, 1, 1]]);;[127X[104X
    [4X[25Xgap>[125X [27Xy := BooleanMat([[1, 0, 1, 0], [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0], [1, 1, 1, 1]]);;[127X[104X
    [4X[25Xgap>[125X [27Xx in y;[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xy in y;[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-4 OnBlist[101X
  
  [33X[1;0Y[29X[2XOnBlist[102X( [3Xblist[103X, [3Xmat[103X ) [32X function[133X
  [6XReturns:[106X  [33X[0;10YA boolean list.[133X
  
  [33X[0;0YIf  [3Xblist[103X  is  a  boolean  list  of  length [10Xn[110X and [3Xmat[103X is boolean matrices of
  dimension  [10Xn[110X, then [10XOnBlist[110X returns the product of [3Xblist[103X (thought of as a row
  vector over the boolean semiring) and [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 1, 1]]);;[127X[104X
    [4X[25Xgap>[125X [27Xblist := BlistList([1 .. 4], [1, 2]);[127X[104X
    [4X[28X[ true, true, false, false ][128X[104X
    [4X[25Xgap>[125X [27XOnBlist(blist, mat);[127X[104X
    [4X[28X[ true, false, false, true ][128X[104X
  [4X[32X[104X
  
  [1X5.3-5 Successors[101X
  
  [33X[1;0Y[29X[2XSuccessors[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA list of lists of positive integers.[133X
  
  [33X[0;0YA  row  of  a  boolean  matrix  of  dimension  [10Xn[110X can be thought of of as the
  characteristic  function  of a subset [10XS[110X of [10X[1 .. n][110X, i.e. [10Xi in S[110X if and only
  if  the  [10Xi[110Xth  component of the row equals [22X1[122X. We refer to the subset [10XS[110X as the
  [12Xsuccessors[112X of the row.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is a boolean matrix, then [10XSuccessors[110X returns the list of successors
  of the rows of [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 0]]);;[127X[104X
    [4X[25Xgap>[125X [27XSuccessors(mat);[127X[104X
    [4X[28X[ [ 1, 3, 4 ], [ 1 ], [ 3 ], [ 1, 2 ] ][128X[104X
  [4X[32X[104X
  
  [1X5.3-6 BooleanMatNumber[101X
  
  [33X[1;0Y[29X[2XBooleanMatNumber[102X( [3Xm[103X, [3Xn[103X ) [32X operation[133X
  [33X[1;0Y[29X[2XNumberBooleanMat[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA boolean matrix, or a positive integer.[133X
  
  [33X[0;0YThese  functions  implement a bijection from the set of all boolean matrices
  of dimension [3Xn[103X and the numbers [10X[1 .. 2 ^ ([3Xn[103X[10X ^ 2)][110X.[133X
  
  [33X[0;0YMore  precisely, if [3Xm[103X and [3Xn[103X are positive integers such that [3Xm[103X is at most [10X2 ^
  ([3Xn[103X[10X ^ 2)[110X, then [10XBooleanMatNumber[110X returns the [3Xm[103Xth [3Xn[103X by [3Xn[103X boolean matrix.[133X
  
  [33X[0;0YIf [3Xmat[103X is an [3Xn[103X by [3Xn[103X boolean matrix, then [10XNumberBooleanMat[110X returns the number
  in [10X[1 .. 2 ^ ([3Xn[103X[10X ^ 2)][110X that corresponds to [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 0, 1]]);;[127X[104X
    [4X[25Xgap>[125X [27XNumberBooleanMat(mat);[127X[104X
    [4X[28X27606[128X[104X
    [4X[25Xgap>[125X [27XDisplay(BooleanMatNumber(27606, 4));[127X[104X
    [4X[28X0 1 1 0[128X[104X
    [4X[28X1 0 1 1[128X[104X
    [4X[28X1 1 0 1[128X[104X
    [4X[28X0 1 0 1[128X[104X
  [4X[32X[104X
  
  [1X5.3-7 BlistNumber[101X
  
  [33X[1;0Y[29X[2XBlistNumber[102X( [3Xm[103X, [3Xn[103X ) [32X function[133X
  [33X[1;0Y[29X[2XNumberBlist[102X( [3Xblist[103X ) [32X function[133X
  [6XReturns:[106X  [33X[0;10YA boolean list, or a positive integer.[133X
  
  [33X[0;0YThese  functions  implement a bijection from the set of all boolean lists of
  length [3Xn[103X and the numbers [10X[1 .. 2 ^ [3Xn[103X[10X][110X.[133X
  
  [33X[0;0YMore  precisely, if [3Xm[103X and [3Xn[103X are positive integers such that [3Xm[103X is at most [10X2 ^
  [3Xn[103X[10X[110X, then [10XBlistNumber[110X returns the [3Xm[103Xth boolean list of length [3Xn[103X.[133X
  
  [33X[0;0YIf  [3Xblist[103X is a boolean list of length [3Xn[103X, then [10XNumberBlist[110X returns the number
  in [10X[1 .. 2 ^ [3Xn[103X[10X][110X that corresponds to [3Xblist[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xblist := BlistList([1 .. 10], []);[127X[104X
    [4X[28X[ false, false, false, false, false, false, false, false, false,[128X[104X
    [4X[28X  false ][128X[104X
    [4X[25Xgap>[125X [27XNumberBlist(blist);[127X[104X
    [4X[28X1[128X[104X
    [4X[25Xgap>[125X [27Xblist := BlistList([1 .. 10], [10]);[127X[104X
    [4X[28X[ false, false, false, false, false, false, false, false, false, true[128X[104X
    [4X[28X ][128X[104X
    [4X[25Xgap>[125X [27XNumberBlist(blist);[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27XBlistNumber(1, 10);[127X[104X
    [4X[28X[ false, false, false, false, false, false, false, false, false,[128X[104X
    [4X[28X  false ][128X[104X
    [4X[25Xgap>[125X [27XBlistNumber(2, 10);[127X[104X
    [4X[28X[ false, false, false, false, false, false, false, false, false, true[128X[104X
    [4X[28X ][128X[104X
  [4X[32X[104X
  
  [1X5.3-8 CanonicalBooleanMat[101X
  
  [33X[1;0Y[29X[2XCanonicalBooleanMat[102X( [3XG[103X, [3XH[103X, [3Xmat[103X ) [32X operation[133X
  [33X[1;0Y[29X[2XCanonicalBooleanMat[102X( [3XG[103X, [3Xmat[103X ) [32X operation[133X
  [33X[1;0Y[29X[2XCanonicalBooleanMat[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA boolean matrix.[133X
  
  [33X[0;0YThis  operation  returns  a fixed representative of the orbit of the boolean
  matrix  [3Xmat[103X  under the action of the permutation group [3XG[103X on its rows and the
  permutation group [3XH[103X on its columns.[133X
  
  [33X[0;0YIn  its  second form, when only a single permutation group [3XG[103X is specified, [3XG[103X
  acts on the rows and columns of [3Xmat[103X independently.[133X
  
  [33X[0;0YIn   its   third   form,   when   only   a   boolean  matrix  is  specified,
  [10XCanonicalBooleanMat[110X returns a fixed representative of the orbit of [3Xmat[103X under
  the  action  of  the symmetric group on its rows, and, independently, on its
  columns.  In  other  words,  [10XCanonicalBooleanMat[110X returns a canonical boolean
  matrix equivalent to [3Xmat[103X up to rearranging rows and columns. This version of
  [10XCanonicalBooleanMat[110X  uses  [5XDigraphs[105X and its interface with the [5Xbliss[105X library
  for computing automorphism groups and canonical forms of graphs [JK07]. As a
  consequence,  [10XCanonicalBooleanMat[110X  with  a  single argument is significantly
  faster than the versions with 2 or 3 arguments.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[1, 1, 1, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 0, 0, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 0, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 0, 0, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 1, 0, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 1],[128X[104X
    [4X[28X  [1, 0, 0, 1, 0, 1], [0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 1],[128X[104X
    [4X[28X  [0, 1, 1, 0, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XCanonicalBooleanMat(mat);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0],[128X[104X
    [4X[28X  [0, 0, 1, 1, 1, 0], [1, 1, 0, 0, 1, 0], [0, 0, 1, 1, 0, 1],[128X[104X
    [4X[28X  [1, 1, 1, 1, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XDisplay(CanonicalBooleanMat(mat));[127X[104X
    [4X[28X0 0 0 0 0 0[128X[104X
    [4X[28X1 1 0 0 0 0[128X[104X
    [4X[28X0 0 1 1 1 0[128X[104X
    [4X[28X1 1 0 0 1 0[128X[104X
    [4X[28X0 0 1 1 0 1[128X[104X
    [4X[28X1 1 1 1 0 1[128X[104X
    [4X[25Xgap>[125X [27XDisplay(CanonicalBooleanMat(Group((1, 3)), mat));[127X[104X
    [4X[28X0 1 1 0 0 1[128X[104X
    [4X[28X0 0 1 0 0 1[128X[104X
    [4X[28X1 1 0 1 0 0[128X[104X
    [4X[28X0 0 0 0 0 0[128X[104X
    [4X[28X1 0 1 1 1 1[128X[104X
    [4X[28X1 0 0 1 1 0[128X[104X
    [4X[25Xgap>[125X [27XDisplay(CanonicalBooleanMat(Group((1, 3)), Group(()), mat));[127X[104X
    [4X[28X1 1 1 0 0 0[128X[104X
    [4X[28X0 0 0 1 0 1[128X[104X
    [4X[28X0 1 0 1 0 1[128X[104X
    [4X[28X0 0 0 0 0 0[128X[104X
    [4X[28X1 0 1 1 1 1[128X[104X
    [4X[28X1 0 1 0 1 0[128X[104X
  [4X[32X[104X
  
  [1X5.3-9 IsRowTrimBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsRowTrimBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [33X[1;0Y[29X[2XIsColTrimBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [33X[1;0Y[29X[2XIsTrimBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  row  or column of a boolean matrix of dimension [10Xn[110X can be thought of of as
  the  characteristic  function  of a subset [10XS[110X of [10X[1 .. n][110X, i.e. [10Xi in S[110X if and
  only if the [10Xi[110Xth component of the row or column equals [10X1[110X.[133X
  
  [33X[0;0YA  boolean  matrix  is  [12Xrow  trim[112X  if  no  subset induced by a row of [3Xmat[103X is
  contained  in  the  subset  induced  by any other row of [3Xmat[103X. [12XColumn trim[112X is
  defined  analogously.  A boolean matrix is [12Xtrim[112X if it is both row and column
  trim.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[0, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 0, 1]]);;[127X[104X
    [4X[25Xgap>[125X [27XIsTrimBooleanMat(mat);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 0]]);;[127X[104X
    [4X[25Xgap>[125X [27XIsRowTrimBooleanMat(mat);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XIsColTrimBooleanMat(mat);[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [1X5.3-10 IsSymmetricBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsSymmetricBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is [12Xsymmetric[112X if it is symmetric about the main diagonal,
  i.e. [10X[3Xmat[103X[10X[i][j] = [3Xmat[103X[10X[j][i][110X for all [10Xi, j[110X in the range [10X[1 .. n][110X where [10Xn[110X is the
  dimension of [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 0, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[0, 1, 1, 0], [1, 0, 1, 1], [1, 1, 0, 1],[128X[104X
    [4X[28X  [0, 1, 0, 1]])[128X[104X
    [4X[25Xgap>[125X [27XIsSymmetricBooleanMat(mat);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[0, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[0, 1, 1, 0], [1, 0, 1, 1], [1, 1, 0, 1],[128X[104X
    [4X[28X  [0, 1, 1, 1]])[128X[104X
    [4X[25Xgap>[125X [27XIsSymmetricBooleanMat(mat);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-11 IsReflexiveBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsReflexiveBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix is [12Xreflexive[112X if every entry in the main diagonal is [9Xtrue[109X,
  i.e.  [10X[3Xmat[103X[10X[i][i]  =  true[110X  for  all  [10Xi[110X  in  the range [10X[1 .. n][110X where [10Xn[110X is the
  dimension of [3Xmat[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[1, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 0, 0],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 0, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 0], [1, 1, 0, 0], [0, 1, 0, 1],[128X[104X
    [4X[28X  [1, 1, 1, 1]])[128X[104X
    [4X[25Xgap>[125X [27XIsReflexiveBooleanMat(mat);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xmat := BooleanMat([[1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                      [0, 1, 1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 1],[128X[104X
    [4X[28X  [0, 1, 1, 1]])[128X[104X
    [4X[25Xgap>[125X [27XIsReflexiveBooleanMat(mat);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-12 IsTransitiveBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsTransitiveBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean matrix is [12Xtransitive[112X if whenever [10X[3Xmat[103X[10X[i][j] = true[110X and [10X[3Xmat[103X[10X[j][k] =
  true[110X then [10X[3Xmat[103X[10X[i][k] = true[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XIsTransitiveBooleanMat(x);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 1]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1],[128X[104X
    [4X[28X  [1, 1, 1, 1]])[128X[104X
    [4X[25Xgap>[125X [27XIsTransitiveBooleanMat(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-13 IsAntiSymmetricBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsAntiSymmetricBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is  [12Xanti-symmetric[112X  if  whenever  [10X[3Xmat[103X[10X[i][j]  =  true[110X and
  [10X[3Xmat[103X[10X[j][i] = true[110X then [10Xi = j[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XIsAntiSymmetricBooleanMat(x);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [1, 0, 1, 0], [1, 0, 1, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XIsAntiSymmetricBooleanMat(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-14 IsTotalBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsTotalBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [33X[1;0Y[29X[2XIsOntoBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is  [12Xtotal[112X if there is at least one entry in every row is
  [9Xtrue[109X.  Similarly,  a  boolean  matrix is [12Xonto[112X if at least one entry in every
  column is [9Xtrue[109X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 1, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [1, 0, 1, 1], [1, 1, 1, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XIsTotalBooleanMat(x);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsOntoBooleanMat(x);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xx := BooleanMat([[1, 0, 0, 1],[127X[104X
    [4X[25X>[125X [27X                    [1, 0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 0, 0, 0],[127X[104X
    [4X[25X>[125X [27X                    [0, 1, 1, 0]]);[127X[104X
    [4X[28XMatrix(IsBooleanMat, [[1, 0, 0, 1], [1, 0, 1, 0], [0, 0, 0, 0],[128X[104X
    [4X[28X  [0, 1, 1, 0]])[128X[104X
    [4X[25Xgap>[125X [27XIsTotalBooleanMat(x);[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XIsOntoBooleanMat(x);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.3-15 IsPartialOrderBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsPartialOrderBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is  a  [12Xpartial order[112X if it is reflexive, transitive, and
  anti-symmetric.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XNumber(FullBooleanMatMonoid(3), IsPartialOrderBooleanMat);[127X[104X
    [4X[28X19[128X[104X
  [4X[32X[104X
  
  [1X5.3-16 IsEquivalenceBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsEquivalenceBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is  an  [12Xequivalence[112X  if it is reflexive, transitive, and
  symmetric.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XNumber(FullBooleanMatMonoid(3), IsEquivalenceBooleanMat);[127X[104X
    [4X[28X5[128X[104X
    [4X[25Xgap>[125X [27XBell(3);[127X[104X
    [4X[28X5[128X[104X
  [4X[32X[104X
  
  [1X5.3-17 IsTransformationBooleanMat[101X
  
  [33X[1;0Y[29X[2XIsTransformationBooleanMat[102X( [3Xmat[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YA  boolean  matrix  is  a [12Xtransformation[112X if every row contains precisely one
  [9Xtrue[109X value.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XNumber(FullBooleanMatMonoid(3), IsTransformationBooleanMat);[127X[104X
    [4X[28X27[128X[104X
  [4X[32X[104X
  
  
  [1X5.4 [33X[0;0YMatrices over finite fields[133X[101X
  
  [33X[0;0YIn  this section we describe some operations in [5XSemigroups[105X for matrices over
  finite  fields  that  are  required  for  such  matrices  to form semigroups
  satisfying [2XIsActingSemigroup[102X ([14X6.1-2[114X).[133X
  
  [33X[0;0YFrom v5.0.0, [5XSemigroups[105X uses the [5XGAP[105X library implementation of matrices over
  finite fields belonging to the category [2XIsMatrixObj[102X ([14XReference: IsMatrixObj[114X)
  rather  than  the  previous  implementation  in the [5XSemigroups[105X package. This
  means that from v5.0.0, matrices over a finite field no longer belong to the
  category [2XIsMatrixOverSemiring[102X ([14X5.1-1[114X).[133X
  
  [33X[0;0YThe  following methods are implemented in [5XSemigroups[105X for matrix objects over
  finite fields.[133X
  
  [1X5.4-1 RowSpaceBasis[101X
  
  [33X[1;0Y[29X[2XRowSpaceBasis[102X( [3Xm[103X ) [32X attribute[133X
  [33X[1;0Y[29X[2XRowSpaceTransformation[102X( [3Xm[103X ) [32X attribute[133X
  [33X[1;0Y[29X[2XRowSpaceTransformationInv[102X( [3Xm[103X ) [32X attribute[133X
  
  [33X[0;0YIf  [3Xm[103X  is  a matrix object over a finite field, then to compute the value of
  any  of  the  above  attributes, a canonical basis for the row space of [3Xm[103X is
  computed  along with an invertible matrix [10XRowSpaceTransformation[110X such that [10Xm
  * RowSpaceTransformation(m) = RowSpaceBasis(m)[110X. [10XRowSpaceTransformationInv(m)[110X
  is the inverse of [10XRowSpaceTransformation(m)[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := Matrix(GF(4), Z(4) ^ 0 * [[1, 1, 0], [0, 1, 1], [1, 1, 1]]);[127X[104X
    [4X[28X[ [ Z(2)^0, Z(2)^0, 0*Z(2) ], [ 0*Z(2), Z(2)^0, Z(2)^0 ],[128X[104X
    [4X[28X  [ Z(2)^0, Z(2)^0, Z(2)^0 ] ][128X[104X
    [4X[25Xgap>[125X [27XRowSpaceBasis(x);[127X[104X
    [4X[28X<rowbasis of rank 3 over GF(2^2)>[128X[104X
    [4X[25Xgap>[125X [27XRowSpaceTransformation(x);[127X[104X
    [4X[28X[ [ 0*Z(2), Z(2)^0, Z(2)^0 ], [ Z(2)^0, Z(2)^0, Z(2)^0 ],[128X[104X
    [4X[28X  [ Z(2)^0, 0*Z(2), Z(2)^0 ] ][128X[104X
  [4X[32X[104X
  
  [1X5.4-2 RightInverse[101X
  
  [33X[1;0Y[29X[2XRightInverse[102X( [3Xm[103X ) [32X attribute[133X
  [33X[1;0Y[29X[2XLeftInverse[102X( [3Xm[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YA matrix over a finite field.[133X
  
  [33X[0;0YThese   attributes   contain  a  semigroup  left-inverse,  and  a  semigroup
  right-inverse of the matrix [3Xm[103X respectively.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xx := Matrix(GF(4), Z(4) ^ 0 * [[1, 1, 0], [0, 0, 0], [1, 1, 1]]);[127X[104X
    [4X[28X[ [ Z(2)^0, Z(2)^0, 0*Z(2) ], [ 0*Z(2), 0*Z(2), 0*Z(2) ],[128X[104X
    [4X[28X  [ Z(2)^0, Z(2)^0, Z(2)^0 ] ][128X[104X
    [4X[25Xgap>[125X [27XLeftInverse(x);[127X[104X
    [4X[28X[ [ Z(2)^0, Z(2)^0, 0*Z(2) ], [ 0*Z(2), 0*Z(2), 0*Z(2) ],[128X[104X
    [4X[28X  [ Z(2)^0, 0*Z(2), Z(2)^0 ] ][128X[104X
    [4X[25Xgap>[125X [27XDisplay(LeftInverse(x) * x);[127X[104X
    [4X[28X 1 1 .[128X[104X
    [4X[28X . . .[128X[104X
    [4X[28X . . 1[128X[104X
  [4X[32X[104X
  
  
  [1X5.5 [33X[0;0YMatrices over the integers[133X[101X
  
  [33X[0;0YIn  this  section  we  describe  operations  in  [5XSemigroups[105X specifically for
  integer matrices.[133X
  
  [33X[0;0YFrom v5.0.0, [5XSemigroups[105X uses the [5XGAP[105X library implementation of matrices over
  the  integers belonging to the category [2XIsMatrixObj[102X ([14XReference: IsMatrixObj[114X)
  rather  than  the  previous  implementation  in the [5XSemigroups[105X package. This
  means  that  from v5.0.0, matrices over the integers no longer belong to the
  category [2XIsMatrixOverSemiring[102X ([14X5.1-1[114X).[133X
  
  [33X[0;0YThe  following methods are implemented in [5XSemigroups[105X for matrix objects over
  the integers.[133X
  
  [1X5.5-1 InverseOp[101X
  
  [33X[1;0Y[29X[2XInverseOp[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YAn integer matrix.[133X
  
  [33X[0;0YIf  [3Xmat[103X is an integer matrix (i.e. belongs to the category [2XIntegers[102X ([14X5.1-8[114X))
  whose  inverse  (if  it  exists)  is  also an integer matrix, then [10XInverseOp[110X
  returns the inverse of [3Xmat[103X.[133X
  
  [33X[0;0YAn  integer  matrix  has  an  integer  matrix  inverse if and only if it has
  determinant one.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, [[0, 0, -1],[127X[104X
    [4X[25X>[125X [27X                            [0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                            [1, 0, 0]]);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27XInverseOp(mat);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27Xmat * InverseOp(mat) = One(mat);[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.5-2 IsTorsion[101X
  
  [33X[1;0Y[29X[2XIsTorsion[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X[133X
  
  [33X[0;0YIf [3Xmat[103X is an integer matrix (i.e. belongs to the category [2XIntegers[102X ([14X5.1-8[114X)),
  then [10XIsTorsion[110X returns [9Xtrue[109X if [3Xmat[103X is torsion and [9Xfalse[109X otherwise.[133X
  
  [33X[0;0YAn  integer  matrix  [3Xmat[103X is torsion if and only if there exists an integer [10Xn[110X
  such that [3Xmat[103X to the power of [10Xn[110X is equal to the identity matrix.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, [[0, 0, -1],[127X[104X
    [4X[25X>[125X [27X                            [0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                            [1, 0, 0]]);[127X[104X
    [4X[28X<3x3-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27XIsTorsion(mat);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, [[0, 0, -1, 0],[127X[104X
    [4X[25X>[125X [27X                            [0, -1, 0, 0],[127X[104X
    [4X[25X>[125X [27X                            [4, 4, 2, -1],[127X[104X
    [4X[25X>[125X [27X                            [1, 1, 0, 3]]);[127X[104X
    [4X[28X<4x4-matrix over Integers>[128X[104X
    [4X[25Xgap>[125X [27XIsTorsion(mat);[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [1X5.5-3 Order[101X
  
  [33X[1;0Y[29X[2XOrder[102X( [3Xmat[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10YAn integer or [10Xinfinity[110X.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  an integer matrix, then [10XInverseOp[110X returns the order of [3Xmat[103X. The
  order  of [3Xmat[103X is the smallest integer power of [3Xmat[103X equal to the identity. If
  no such integer exists, the order is equal to [10Xinfinity[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, [[0, 0, -1, 0],[127X[104X
    [4X[25X>[125X [27X                            [0, -1, 0, 0],[127X[104X
    [4X[25X>[125X [27X                            [4, 4, 2, -1],[127X[104X
    [4X[25X>[125X [27X                            [1, 1, 0, 3]]);;[127X[104X
    [4X[25Xgap>[125X [27XOrder(mat);[127X[104X
    [4X[28Xinfinity[128X[104X
    [4X[25Xgap>[125X [27Xmat := Matrix(Integers, [[0, 0, -1],[127X[104X
    [4X[25X>[125X [27X                            [0, 1, 0],[127X[104X
    [4X[25X>[125X [27X                            [1, 0, 0]]);;[127X[104X
    [4X[25Xgap>[125X [27XOrder(mat);[127X[104X
    [4X[28X4[128X[104X
  [4X[32X[104X
  
  
  [1X5.6 [33X[0;0YMax-plus and min-plus matrices[133X[101X
  
  [33X[0;0YIn  this  section  we  describe  operations  in  [5XSemigroups[105X specifically for
  max-plus  and  min-plus  matrices.  These  are  in  addition  to those given
  elsewhere  in  this  chapter  for  arbitrary  matrices over semirings. These
  include:[133X
  
  [30X    [33X[0;6Y[2XInverseOp[102X ([14X5.6-1[114X)[133X
  
  [30X    [33X[0;6Y[2XRadialEigenvector[102X ([14X5.6-2[114X)[133X
  
  [30X    [33X[0;6Y[2XSpectralRadius[102X ([14X5.6-3[114X)[133X
  
  [30X    [33X[0;6Y[2XUnweightedPrecedenceDigraph[102X ([14X5.6-4[114X)[133X
  
  [1X5.6-1 InverseOp[101X
  
  [33X[1;0Y[29X[2XInverseOp[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA max-plus matrix.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  an  invertible  max-plus  matrix  (i.e. belongs to the category
  [2XIsMaxPlusMatrix[102X  ([14X5.1-8[114X)  and is a row permutation applied to the identity),
  then  [10XInverseOp[110X  returns  the  inverse  of  [3Xmat[103X. This method is described in
  [Far09].[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XInverseOp(Matrix(IsMaxPlusMatrix, [[-infinity, -infinity, 0],[127X[104X
    [4X[25X>[125X [27X                                      [0, -infinity, -infinity],[127X[104X
    [4X[25X>[125X [27X                                      [-infinity, 0, -infinity]]));[127X[104X
    [4X[28XMatrix(IsMaxPlusMatrix, [[-infinity, 0, -infinity],[128X[104X
    [4X[28X  [-infinity, -infinity, 0], [0, -infinity, -infinity]])[128X[104X
  [4X[32X[104X
  
  [1X5.6-2 RadialEigenvector[101X
  
  [33X[1;0Y[29X[2XRadialEigenvector[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA vector.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  a  [10Xn[110X  by  [10Xn[110X  max-plus  matrix  (i.e.  belongs  to  the category
  [2XIsMaxPlusMatrix[102X  ([14X5.1-8[114X)),  then  [10XRadialEigenvector[110X  returns  an eigenvector
  corresponding  to  the  eigenvalue equal to the spectral radius of [3Xmat[103X. This
  method is described in [Far09].[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRadialEigenvector(Matrix(IsMaxPlusMatrix, [[0, -3], [-2, -10]]));[127X[104X
    [4X[28X[ 0, -2 ][128X[104X
  [4X[32X[104X
  
  [1X5.6-3 SpectralRadius[101X
  
  [33X[1;0Y[29X[2XSpectralRadius[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA rational number.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  a max-plus matrix (i.e. belongs to the category [2XIsMaxPlusMatrix[102X
  ([14X5.1-8[114X)), then [10XSpectralRadius[110X returns the supremum of the set of eigenvalues
  of [3Xmat[103X. This method is described in [BFCGOGJ92].[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XSpectralRadius(Matrix(IsMaxPlusMatrix, [[-infinity, 1, -4],[127X[104X
    [4X[25X>[125X [27X                                           [2, -infinity, 0],[127X[104X
    [4X[25X>[125X [27X                                           [0, 1, 1]]));[127X[104X
    [4X[28X3/2[128X[104X
  [4X[32X[104X
  
  [1X5.6-4 UnweightedPrecedenceDigraph[101X
  
  [33X[1;0Y[29X[2XUnweightedPrecedenceDigraph[102X( [3Xmat[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA digraph.[133X
  
  [33X[0;0YIf  [3Xmat[103X  is  a max-plus matrix (i.e. belongs to the category [2XIsMaxPlusMatrix[102X
  ([14X5.1-8[114X)), then [10XUnweightedPrecedenceDigraph[110X returns the unweighted precedence
  digraph corresponding to [3Xmat[103X.[133X
  
  [33X[0;0YFor  an  [10Xn[110X  by [10Xn[110X matrix [3Xmat[103X, the unweighted precedence digraph is defined as
  the  digraph  with  [10Xn[110X vertices where vertex [10Xi[110X is adjacent to vertex [10Xj[110X if and
  only if [3Xmat[103X[10X[i][j][110X is not equal to [9X-infinity[109X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XUnweightedPrecedenceDigraph(Matrix(IsMaxPlusMatrix, [[2, -2, 0],[127X[104X
    [4X[25X>[125X [27X[-infinity, 10, -2], [-infinity, 2, 1]]));[127X[104X
    [4X[28X<immutable digraph with 3 vertices, 7 edges>[128X[104X
  [4X[32X[104X
  
  
  [1X5.7 [33X[0;0YMatrix semigroups[133X[101X
  
  [33X[0;0YIn  this  section  we  describe  operations  and  attributes  in  [5XSemigroups[105X
  specifically  for  matrix  semigroups.  These are in addition to those given
  elsewhere  in  this  chapter  for  arbitrary  matrices over semirings. These
  include:[133X
  
  [30X    [33X[0;6Y[2XIsXMatrixSemigroup[102X ([14X5.7-1[114X)[133X
  
  [30X    [33X[0;6Y[2XIsFinite[102X ([14X5.7-3[114X)[133X
  
  [30X    [33X[0;6Y[2XIsTorsion[102X ([14X5.7-4[114X)[133X
  
  [30X    [33X[0;6Y[2XNormalizeSemigroup[102X ([14X5.7-5[114X)[133X
  
  [33X[0;0YRandom   matrix   semigroups   can   be   created   by  using  the  function
  [2XRandomSemigroup[102X ([14X6.6-1[114X). We can also create a matrix semigroup isomorphic to
  a  given  semigroup  by  using  [2XIsomorphismSemigroup[102X ([14X6.5-1[114X) and [2XAsSemigroup[102X
  ([14X6.5-3[114X).  These functions require a filter, and accept any of the filters in
  Section [14X5.7-1[114X.[133X
  
  [33X[0;0YThere  are  corresponding  functions  which  can be used for matrix monoids:
  [2XRandomMonoid[102X ([14X6.6-1[114X), [2XIsomorphismMonoid[102X ([14X6.5-2[114X), and [2XAsMonoid[102X ([14X6.5-4[114X). These
  can be used with the filters in Section [14X5.7-2[114X.[133X
  
  
  [1X5.7-1 [33X[0;0YMatrix semigroup filters[133X[101X
  
  [33X[1;0Y[29X[2XIsMatrixOverSemiringSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsBooleanMatSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverFiniteFieldSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMaxPlusMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMinPlusMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMaxPlusMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMinPlusMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsNTPMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsIntegerMatrixSemigroup[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YThe  above  are  the  currently  supported  types  of matrix semigroups. For
  monoids see Section [14X5.7-2[114X.[133X
  
  
  [1X5.7-2 [33X[0;0YMatrix monoid filters[133X[101X
  
  [33X[1;0Y[29X[2XIsMatrixOverSemiringMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsBooleanMatMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMatrixOverFiniteFieldMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMaxPlusMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsMinPlusMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMaxPlusMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsTropicalMinPlusMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsNTPMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [33X[1;0Y[29X[2XIsIntegerMatrixMonoid[102X( [3Xobj[103X ) [32X Category[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YThe  above  are  the  currently  supported  types  of  matrix  monoids. They
  correspond to the matrix semigroup types in Section [14X5.7-1[114X.[133X
  
  [1X5.7-3 IsFinite[101X
  
  [33X[1;0Y[29X[2XIsFinite[102X( [3XS[103X ) [32X property[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YIf  [3XS[103X  is  a  max-plus  or  min-plus  matrix  semigroup (i.e. belongs to the
  category  [2XIsMaxPlusMatrixSemigroup[102X ([14X5.7-1[114X)), then [10XIsFinite[110X returns [9Xtrue[109X if [3XS[103X
  is  finite  and  [9Xfalse[109X otherwise. This method is based on [Gau96] (max-plus)
  and  [Sim78] (min-plus). For min-plus matrix semigroups, this method is only
  valid  if  each  min-plus matrix in the semigroup contains only non-negative
  integers.  Note, this method is terminating and does not involve enumerating
  semigroups.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XIsFinite(Semigroup(Matrix(IsMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                             [[0, -3],[127X[104X
    [4X[25X>[125X [27X                              [-2, -10]])));[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsFinite(Semigroup(Matrix(IsMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                             [[1, -infinity, 2],[127X[104X
    [4X[25X>[125X [27X                              [-2, 4, -infinity],[127X[104X
    [4X[25X>[125X [27X                              [1, 0, 3]])));[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XIsFinite(Semigroup(Matrix(IsMinPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                             [[infinity, 0],[127X[104X
    [4X[25X>[125X [27X                              [5, 4]])));[127X[104X
    [4X[28Xfalse[128X[104X
    [4X[25Xgap>[125X [27XIsFinite(Semigroup(Matrix(IsMinPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                             [[1, 0],[127X[104X
    [4X[25X>[125X [27X                              [0, infinity]])));[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X5.7-4 IsTorsion[101X
  
  [33X[1;0Y[29X[2XIsTorsion[102X( [3XS[103X ) [32X attribute[133X
  [6XReturns:[106X  [33X[0;10Y[9Xtrue[109X or [9Xfalse[109X.[133X
  
  [33X[0;0YIf  [3XS[103X  is  a  max-plus  matrix  semigroup  (i.e.  belongs  to  the  category
  [2XIsMaxPlusMatrixSemigroup[102X  ([14X5.7-1[114X)),  then  [10XIsTorsion[110X  returns  [9Xtrue[109X  if [3XS[103X is
  torsion  and  [9Xfalse[109X  otherwise. This method is based on [Gau96] and draws on
  [Bur16], [BFCGOGJ92] and [Far09].[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XIsTorsion(Semigroup(Matrix(IsMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                             [[0, -3],[127X[104X
    [4X[25X>[125X [27X                              [-2, -10]])));[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsTorsion(Semigroup(Matrix(IsMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                              [[1, -infinity, 2],[127X[104X
    [4X[25X>[125X [27X                               [-2, 4, -infinity],[127X[104X
    [4X[25X>[125X [27X                               [1, 0, 3]])));[127X[104X
    [4X[28Xfalse[128X[104X
  [4X[32X[104X
  
  [1X5.7-5 NormalizeSemigroup[101X
  
  [33X[1;0Y[29X[2XNormalizeSemigroup[102X( [3XS[103X ) [32X operation[133X
  [6XReturns:[106X  [33X[0;10YA semigroup.[133X
  
  [33X[0;0YThis  method  applies to max-plus matrix semigroups (i.e. those belonging to
  the  category [2XIsMaxPlusMatrixSemigroup[102X ([14X5.7-1[114X)) that are finitely generated,
  such  that  the  spectral  radius  of  the  matrix  equal  to the sum of the
  generators    (with   respect   to   the   max-plus   semiring)   is   zero.
  [10XNormalizeSemigroup[110X  returns  a  semigroup  of  matrices  all  with  strictly
  non-positive  entries.  Note  that  the  output  is isomorphic to a min-plus
  matrix semigroup. This method is based on [Gau96] and [Bur16].[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XNormalizeSemigroup(Semigroup(Matrix(IsMaxPlusMatrix,[127X[104X
    [4X[25X>[125X [27X                                       [[0, -3],[127X[104X
    [4X[25X>[125X [27X                                        [-2, -10]])));[127X[104X
    [4X[28X<commutative semigroup of 2x2 max-plus matrices with 1 generator>[128X[104X
  [4X[32X[104X
  
