[GAP Forum] Display of matrices

Thomas Breuer sam at Math.RWTH-Aachen.De
Fri Aug 19 18:23:28 BST 2011


Dear GAP Forum,

Benjamin Sambale wrote:

> I have two related easy questions concerning the Display command for
> matrices.
> 
> The first one: I like the output of Display([[1,0],[0,1]]*Z(2)) much
> more then the output of Display([[1,0],[0,1]]). Especially that dots
> substitute zeros. However, I really want to work with integral
> matrices and not matrices over finite fields. Is it possible to
> change this behavior of "Display"?
> 
> The second one: I also want to consider "large" matrices with say
> 100 rows. Here I don't want that the Display command breaks lines.
> Instead I want to scroll through the output. This is very useful in
> order to recognize patterns. Since this question might also depend
> on the operating system, I have to say that I use Arch Linux and
> bash as shell. Increasing the COLUMNS variable doesn't change
> anything. Any ideas?

As for the second question,
I would recommend the Browse package.
The GAP code appended below can be used for scrolling through
integer matrices, where each zero is shown as a dot.

After loading the Browse package and reading the appended GAP code,
you can enter the following.

    m:= RandomMat( 100, 100 );;  # Create a matrix that exceeds the screen.
    Browse( m );

Then the topleft part of the matrix is shown on the screen,
with row labels shown on the left and column labels shown at the top.
Using the arrow keys (or the udlr keys) one can scroll by one row or column,
using the UDLR keys one can scroll by one page.
Enter ? for an overview of supported key strokes.
One returns to the GAP prompt by entering Q.

All the best,
Thomas

----------------------------------------------------------------------------

InstallMethod( Browse, [ IsTable ], 
    function( table )
      local m, n, conv, r;

      m:= Length( table );
      n:= Maximum( List( table, Length ) );

      conv:= function( entry )
        if entry = 0 then
          return ".";
        else
          return String( entry );
        fi;
      end;

      r:= rec( work:= rec( 
        align:= "c",
        main:= List( table, row -> List( row, conv ) ),
        labelsRow:= List( [ 1 .. m ], i -> [ String( i ) ] ),
        labelsCol:= [ List( [ 1 .. n ], String ) ],
        sepLabelsCol:= [ "", "-" ],
        sepLabelsRow:= [ "", " | " ],
        ) );

      NCurses.BrowseGeneric( r );
    end );





More information about the Forum mailing list