-*-M2-*-

Date: Sun, 9 Jul 2006 16:48:16 -0500 (CDT)
From: Dan Grayson <dan@math.uiuc.edu>
To: mike@math.cornell.edu
CC: dan@math.uiuc.edu
Subject: leadComponent versus pivots
Reply-to: dan@math.uiuc.edu


The function leadComponent is totally lame.  It doesn't even check to see
whether the ordering of vectors is Up or Down, it doesn't work for columns
that are zero, and it's not clear what it ought to do for columns that are
zero, except put -1, which will always require further processing.  It's used
exactly once in our packages and code: in Dmodules.

    leadComponent Matrix := m -> apply(entries transpose m, col -> last positions (col, x -> x != 0))

    ii21 : help leadComponent 

    oo21 = leadComponent -- the leading component of a vector or matrix
	   ************************************************************

	   Description
	   ===========

	   leadComponent f -- return the leading component of the vector f, i.e., the integer i so that f_i is the first nonzero component of f.

	   Ways to use leadComponent :
	   ===========================

	     * leadComponent(Matrix)
	     * leadComponent(Vector)

    oo21 : DIV

    ii22 : leadComponent diagonalMatrix {x,x,x,x}

    oo22 = {0, 1, 2, 3}

    oo22 : List

    ii23 : leadComponent diagonalMatrix {x,x,x,0}
    startup.m2:138:19:(0):[3]: array index -1 out of bounds 0 .. -1

My new function "pivots" does what I want, though.

    ii28 : code methods pivots

    oo28 = -- code for method: pivots(Matrix)
	   -- matrix2.m2:5-14
	   pivots Matrix := (p) -> (                           -- I wish this could be in the engine
		R := ring p;
		f := leadTerm matrix {{1_R},{1_R}};
		dir := if f_(0,0) == 1 then Down else Up;
		opt := Reverse => dir === Up;
		cols := entries transpose p;
		for j from 0 to #cols-1 list (
		     i := position(cols#j, e -> e != 0, opt);
		     if i === null then continue;
		     (i,j)))

    ii24 : pivots diagonalMatrix {x,x,x,x}

    oo24 = {(0, 0), (1, 1), (2, 2), (3, 3)}

    oo24 : List

    ii25 : pivots diagonalMatrix {x,x,x,0}

    oo25 = {(0, 0), (1, 1), (2, 2)}

    oo25 : List

What do you think?

