incr-set prlevel 1
if #0=4 START 
incr-set prlevel -1

;;; Usage:
;;;     <diagonal_submodule f M h M1
;;;
;;; Given any map f: R --> S of rings, (WHERE R IS THE CURRENT RING)
;;; any S-module M presented as 
;;; 	F -->G --> M -->0,
;;; and any inclusion h: G --> H, 
;;; the script computes the S-submodule M1 of M generated by
;;; G \intersect H_R, 
;;; where H_R is the R-free R-submodule of H  generated by 
;;; the given S-generators.
;;;
;;; For example, if f:k[zij] --> k[xi yj] is a Segre map, then
;;; given a bigraded S-module M and a monomorphism h from the free module
;;; of generators of M to a free module generated in degrees n,n (n \in Z)
;;; this script computes the "diagonal" S-module 
;;; generated by all elements of M of 
;;; bidegree n,n  (n \in Z).
incr-set prlevel 1
jump END
;;;
;;; Parameters:
;;;     f = 1xn matrix over a ring S. THE VARIABLES OF THE CURRENT
;;;     RING MUST HAVE DEGREES PROPORTIONAL TO THOSE OF THE ENTRIES OF f.
;;;     M = module over S
;;;     h = matrix over S which can be composed with M as hM.
;;;
;;; Output values:
;;;     M1 = module over S.  
;;;
;;; The method is as follows: we use 
;;; pushforward1 to compute the intersection 
;;; hm1:F1_R --> H_R of 
;;; h m F with H_R, since this is the set of 
;;; relations on the R-submodule of the cokernel
;;; of hm generated by the given S-generators of H.  
;;; Then we use f to tensor up to S,
;;; obtaining hm1: F1 --> H; this will be the S-submodule 
;;; generated by the intersection.
;;; We lift this map back to G (we can since its image 
;;; is by definition a submodule of 
;;; the image of G under h) to get the result M1.
;;;
;;; Caveats:
;;;		This really ought to be done by having 
;;; Macaulay keep track of bigradings 
;;; with a facility like "trunc" for the multigraded case.
;;;
; created 4/27/89 DE
START:

;Note that we assume R is the current ring! Get a handle:
poly @curring 0
mult #3 #2 @hm

setring @curring
<push_forward1 #1 @hm @hm1
ev #1 @hm1 @hm1
lift-std #3 @h
lift @h @hm1 #4

kill @curring @h @hm1 @hm
END:
incr-set prlevel -1

$;;;;;;;; EXAMPLE SECTION ;;;;;;;;;;;;;;;;;;;;;;;;;
;The bihomogeneous coordinate ring of P1xP1:
ring r
;
4
x[0]-x[1]
y[0]-y[1];
;
;

;Form the segre map
cat x[0] xvars
0
0..1
cat y[0] yvars
0
0..1

transpose yvars yvars'
mult yvars' xvars zvars
flatten zvars f
type f

;The bihomogeneous ideal of a point:
ideal i
2
x[0]
y[0]

;An inclusion map from the ring to a 
;diagonally generated free module:
<ideal h 1

<ring 4 z[0,0]-z[1,1] s
;The diagonal submodule
<diagonal_submodule
<diagonal_submodule f i h M1
type M1
