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
;;;

	mat #(10)
		0
		0
	mat #(11)
		0
		0
	mat #(12)
		0
		0

	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
	mat @MC
		@rk
		0
	concat @MC @Gmap @Dmap

	<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
		power @minus_one @i+1 @sign
		smult @Dmap @sign @Dmap
		ncols @Gmap @rk1
		nrows @Fmap @rk2
		<zeromat @rk2 @rk1 @zero_block

		concat @Gmap @Dmap
		concat @zero_block @Fmap
		<stack @MC @Gmap @zero_block

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

	ncols @MC @last_rk
	mat @MC
		@last_rk
		0
	<add_matrix_to_array #(10) #(11) #(12) @MC

kill @MC @Dmap @Gmap @Fmap @zero_block @rk1 @rk2 @sign
kill @i @minus_one @length @rk @lengthF @lengthG @last_rk

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

--------------------------------------------------- 
; a b c d e 
--------------------------------------------------- 
; b  c  d  0  0  0  -e 0  0  0  
; -a 0  0  c  d  0  0  -e 0  0  
; 0  -a 0  -b 0  d  0  0  -e 0  
; 0  0  -a 0  -b -c 0  0  0  -e 
; 0  0  0  0  0  0  a  b  c  d  
--------------------------------------------------- 
; c  d  0  0  e  0  0  0  0  0  
; -b 0  d  0  0  e  0  0  0  0  
; 0  -b -c 0  0  0  e  0  0  0  
; a  0  0  d  0  0  0  e  0  0  
; 0  a  0  -c 0  0  0  0  e  0  
; 0  0  a  b  0  0  0  0  0  e  
; 0  0  0  0  b  c  d  0  0  0  
; 0  0  0  0  -a 0  0  c  d  0  
; 0  0  0  0  0  -a 0  -b 0  d  
; 0  0  0  0  0  0  -a 0  -b -c 
--------------------------------------------------- 
; d  -e 0  0  0  
; -c 0  -e 0  0  
; b  0  0  -e 0  
; -a 0  0  0  -e 
; 0  c  d  0  0  
; 0  -b 0  d  0  
; 0  0  -b -c 0  
; 0  a  0  0  d  
; 0  0  a  0  -c 
; 0  0  0  a  b  
--------------------------------------------------- 
; e  
; d  
; -c 
; b  
; -a 
--------------------------------------------------- 

% end of file ($) received, exiting Macaulay
