incr-set prlevel 1
if #0=4 START
incr-set prlevel -1
;;; Usage:
;;;   <comp_to_array w M v1 v2
;;;
;;; Given a computation w, this command returns the triple
;;; (M,v1,v2) which holds the array of matrices.
;;;
incr-set prlevel 1
jump END
;;; Parameters:  w  -  a Macaulay produced computation
;;;
;;; Output values: (M,v1,v2) - an array of matrices
;;;
;;; The Array of Matrices Data Type:
;;;
;;; An array of matrices is a triple (M,v1,v2) of matrices.
;;; The first coordinate is a direct sum of matrices such
;;; that the upper left hand corner is thought of as the
;;; first matrix, and so on.
;;;
;;; The second coordinate is an n by 0 matrix whose row
;;; degrees give the ranks of the free modules which are
;;; the sources of the maps.
;;;
;;; The third coordinate is an n by 0 matrix whose row de-
;;; grees give the ranks of the free modules which are the
;;; targets of the maps.
;;;
;;; Caveats:  The script does something different depending
;;; on whether the computation w is the entire resolution
;;; of a module or not.  If it is, it will tack a zero map
;;; onto the end.  However, if it is not, such a matrix will
;;; not be appended, since it would reflect some homology
;;; the the resolution really would not have, if extended.

; created ... 3/25/92
START:

; Clear out the v1_tr,v2_tr, and #2 matrices

<zeromat 0 1 @dummy_matrix
<zeromat 1 0 @v1_tr
<zeromat 1 0 @v2_tr
<zeromat 0 0 #2

int @i 1
LOOP:
	nrows #1.@i @image_rank
	ncols #1.@i @source_rank
	if @source_rank=0 ENDLOOP
	setcoldegs @dummy_matrix
	-@source_rank
	concat @v1_tr @dummy_matrix
	setcoldegs @dummy_matrix
	-@image_rank
	concat @v2_tr @dummy_matrix
	dsum #2 #1.@i @sum_matrix
	copy @sum_matrix #2
	int @i @i+1
jump LOOP

ENDLOOP:
	syz #1.(@i-1) -1 @ker
	ncols @ker @ker_cols
	if @ker_cols>0 CLEAN
		if @i=1 BRANCHA
			ncols #1.(@i-1) @image_rank
			col-degs #1.(@i-1) @cdegs
			jump BRANCHB
		BRANCHA:
			nrows #1.(@i) @image_rank
			row-degs #1.(@i) @cdegs
		BRANCHB:

		setcoldegs @dummy_matrix
			0
		concat @v1_tr @dummy_matrix
		setcoldegs @dummy_matrix
			-@image_rank
		concat @v2_tr @dummy_matrix
		mat @last_mat
			@image_rank
			0
		setdegs @last_mat
			@cdegs
			0		
		dsum #2 @last_mat @sum_matrix
		copy @sum_matrix #2
CLEAN:

transpose @v1_tr #3
transpose @v2_tr #4

kill @i @sum_matrix @dummy_matrix @image_rank @source_rank
kill @v1_tr @v2_tr @ker @ker_cols

END:
incr-set prlevel -1

$;;;;;;;; EXAMPLE SECTION ;;;;;;;;;;;;;;;;;;;;;;;;;

% <2byn 1 4 0 0 M I

% nres I Ires

% <comp_to_array Ires M v1 v2

% type M
; b2-ac bc-ad bd-ae c2-ae cd-be d2-ce 0  0  0  0  0  0  0  0  0  0  0  
; 0     0     0     0     0     0     0  0  e  0  0  d  0  c  0  0  0  
; 0     0     0     0     0     0     e  0  0  e  c  -c d  -b 0  0  0  
; 0     0     0     0     0     0     -d -e -c 0  0  -b -c -a 0  0  0  
; 0     0     0     0     0     0     0  e  0  -d -b b  0  a  0  0  0  
; 0     0     0     0     0     0     0  -d b  c  a  0  0  0  0  0  0  
; 0     0     0     0     0     0     b  c  0  0  0  0  a  0  0  0  0  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  -a 0  c  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  0  -a -b 
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  0  -c -d 
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  a  b  0  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  -c -d 0  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  -c 0  e  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  b  c  0  
; 0     0     0     0     0     0     0  0  0  0  0  0  0  0  d  e  0  

% row-degs v1
6 8 3

% row-degs v2
1 6 8

