incr-set prlevel 1
if #0=4 START
incr-set prlevel -1
;;; Usage:
;;; 	<random_map a b d f
;;;
;;; sets f to be a random linear combination of
;;; the homomorphisms of degree d from a to b.
;;; Sets f to 0 if there are no such maps.
;;;
incr-set prlevel 1
jump END
;;; Parameters:
;;;         a, b modules over the same ring
;;;         d an integer
;;; Output values:
;;;          f a matrix from the row space of
;;;            a to the row space of b
;;; Useful for testing whether b is isomorphic
;;; to a, since if random maps in both directions
;;; are epi, the modules are isomorphic.
;;;
;;; Also useful to produce a 
;;; random map be between 2 free modules,
;;; say the source of a to the target of b, say
;;; of degree 0:
;;;     col-degs a A1
;;;     row-degs b B0
;;;     <random_map A1 B0 0 f
;;;
; created 12/18/89
START:
;Find the homomorphisms:
<hom_and_map #1 #2 @dummy @ff

;Now @ff: H0 --> A0^* \tensor B0 is the map 
;covering the homomorphisms.

;Choose a random element of degree d in the column
;space of @ff.  This is a map from the 
;the ring to A0^* \tensor B0 
<random_element @ff #3 @f

;Change @f:R --> A0^* \tensor B0
;into the corresponding map f: A0 --> B0, 

;Tensor @f with A0 to get
;    @f: @A0 --> @A0 \tensor A0^* \tensor B0
<idenrowdegs #1 @A0
outer @A0 @f @f

;Make the tautological map 
;    @taut:A0 \tensor A0^* --> R
<idenrowdegs #1 @A0
flatten @A0 @taut

;tensor it with B0, the row space of b, to get
;    @taut: @A0 \tensor A0^* \tensor B0 --> B0
<idenrowdegs #2 @B0
outer @taut @B0 @taut

;Compute f:
mult @taut @f #4
;Now reduce #4 modulo the column space of b
std #2 @b
reduce @b #4 #4

kill @dummy @ff @f @A0 @B0 @taut
END:
incr-set prlevel -1

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

<ring 3 a-z r
<powers r 3 i ;a Gorenstein ideal with socle a2b2c2
<random_map r i 5 f
type f ;gives nothing
<random_map r i 6 f
type f ;finds the socle
<random_map r i 7 f
type f ;gives nothing

listvars

; ;;;;;;;;;;;;;
;to produce a map be between 2 free modules,
;say the source of a to the target of b, say
;of degree 0:
<ring 3 x-z r
<ideal a x2 y3 z4
<ideal b x y2 z2
transpose b b
col-degs a A1
row-degs b B0
<random_map A1 B0 0 f
betti a
; total:      1     3 
; --------------------
;     0:      1     - 
;     1:      -     1 
;     2:      -     1 
;     3:      -     1 
betti b
; total:      3     1 
; --------------------
;    -2:      2     - 
;    -1:      1     1 
betti f
; total:      3     3 
; --------------------
;    -2:      2     - 
;    -1:      1     - 
;     0:      -     - 
;     1:      -     1 
;     2:      -     1 
;     3:      -     1 

