incr-set prlevel 1
if #0=12 START
incr-set prlevel -1
;;; Usage:
;;; 	<mc F F1 F2 G G1 G2 D D1 D2 M M1 M2
;;;
;;; Given a map of complexes F ----> G, construct the
;;; mapping cylinder, which will be a complex of which
;;; G is a subcomplex and F[-1] is a quotient.
;;;
incr-set prlevel 1
jump END
;;; Parameters: (F,F1,F2) (G,G1,G2) are complexes of free
;;;			modules as arrays of matrices.
;;;		(D,D1,D2) is the array of matrices giving
;;;			the maps from F to G.
;;;
;;; Output values: (M,M1,M2) is the mapping cylinder, given
;;;			as 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.
;;;
; created ... 6/28/92 by M. Johnson
START:

;;;
;;; initialize the mapping cylinder array
;;;

	<zeromat 0 0 #(10)
	<zeromat 0 0 #(11)
	<zeromat 0 0 #(12)

	nrows #2 @lengthF
	nrows #5 @lengthG
	int @length @lengthF+1
	if @lengthG<@length BRANCH
		int @length @lengthG
	BRANCH:
		
	int @i 1
	poly @minus_one -1
	<extract_matrix #7 #8 #9 @i @Dmap
	<extract_matrix #4 #5 #6 @i @Gmap
	
	nrows @Dmap @rk
	row-degs @Dmap @row_degs
	mat @MC
		@rk
		0
	setdegs @MC
		@row_degs
		;
	concat @MC @Dmap @Gmap
	col-degs @Gmap @col_degs1
	col-degs @Dmap @col_degs2
	setcoldegs @MC
		@col_degs2 @col_degs1

	<add_matrix_to_array #(10) #(11) #(12) @MC
	
	LOOP:
		int @i @i+1
		if @i>@length ENDLOOP
		<extract_matrix #1 #2 #3 @i-1 @Fmap
		<extract_matrix #7 #8 #9 @i @Dmap
		<extract_matrix #4 #5 #6 @i @Gmap
		smult @Dmap {@minus_one}^(@i+1) @Dmap

		nrows @Fmap @Frows
		col-degs @Fmap @Fcoldegs
		row-degs @Fmap @Frowdegs
		row-degs @Dmap @Drowdegs
		ncols @Gmap @Gcols
		col-degs @Gmap @Gcoldegs

		<zeromat @Frows @Gcols @zero_block
		concat @Fmap @zero_block
		concat @Dmap @Gmap
		transpose @Fmap @Fmap
		transpose @Dmap @Dmap
		concat @Fmap @Dmap
		transpose @Fmap @MC
		setdegs @MC
			@Frowdegs @Drowdegs
			@Fcoldegs @Gcoldegs

		<add_matrix_to_array #(10) #(11) #(12) @MC
		jump LOOP
	ENDLOOP:

kill @MC @Dmap @Gmap @Fmap @zero_block
kill @i @minus_one @length @rk @lengthF @lengthG
kill @Frowdegs @Drowdegs @Fcoldegs @Gcoldegs 
kill @Frows @Gcols

END:
incr-set prlevel -1

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

<ring 6 a-f r
<ideal I a b c d
<koszul_complex I k k1 k2
poly p e
<smult_complex k k1 k2 p D D1 D2
<mc k k1 k2 k k1 k2 D D1 D2 MC MC1 MC2
<pres MC MC1 MC2
