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

;;; Usage:
;;; 	<dual_variety I c J
;;;
;;; Given the ideal I of a variety X of codimensions c in projective space,
;;; forms the classical dual variety -- that is, the closure
;;; of the set of hyperplanes containing
;;; tangent planes at smooth points of X.  
incr-set prlevel 1
jump END
;;;
;;; Parameters:
;;;		I = and ideal
;;; Output values:
;;;		J = an ideal, in the same set of variables as I
;revised 5/6/89 DE
START:

;Make sure that I is an ideal with row degree 0
copy #1 @I
setdegs @I
        0
        ;

;compute the jacobian matrix with respect to
;all the variables of the base ring of I, and the singular
;locus:
jacob @I @Jac !
wedge @Jac #2 @sing
flatten @sing @sing

;now form a new ring, with two identical blocks of variables
setring @I
<getvars @vars
<idencoldegs @vars @degs
ncols @vars @numvars
ring @r
;
2*@numvars
A[1]-A[@numvars]
X[1]-X[@numvars]
@degs @degs
@numvars @numvars
;
;Bring everything over to the new ring
keep @r @vars1
elim @r @vars2

ev @vars1 @I @I
ev @vars1 @Jac @Jac
ev @vars1 @sing @sing

;Form the graph of the Gauss map

transpose @Jac @Jac'
transpose @vars2 @vars2'
concat @Jac' @vars2'
wedge @Jac' (#2)+1 @graph
flatten @graph @graph
concat @graph @I

;Remove the components of @graph contained in the
;preimage of the singular locus
<sat @graph @sing @graph
setring #1
<project_from_product @graph @numvars #3

kill  @vars @degs @numvars @r'zero @r @vars1
kill @vars2 @I @Jac @sing @Jac' @vars2' @graph

END:
incr-set prlevel -1


$;;;;;;;; EXAMPLE SECTION ;;;;;;;;;;;;;;;;;;;;;;;;;
reset
;Duality in the plane:
ring r

3
a-z
;
;
;Use the above ring for the following examples:

;The nonsingular cubic
poly f1 a3+b3+c3

<dual_variety
<dual_variety f1 1 j
type j
<dual_variety j 1 i
type i

; ;;;;;;;;;;;;;;;;;;;;;;;
;The cuspidal cubic:
poly f a2c-b3
<dual_variety f1 1 j
type j

<dual_variety j 1 i
type i

; ;;;;;;;;;;;;;;;;;;;;;;;
;The nodal cubic:
poly f a2c-b3-b2c

<dual_variety f1 1 j
type j

<dual_variety j 1 i
type i

; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The nonsingular quartic
poly f1 a4+b4+c4
set prlevel -4

<dual_variety f1 1 j
type j

<<dual_variety j 1 i
type i

;Note -- If one tries the sextic, the second computation,
;starting from a curve of degree 30, quickly exceeds the
;monomial degree bound (in a call to sat1,
;in the first set of vars, I think).
; ;;;;;;;;;;;;;;;;;;;;;;;
; ;;;;;;;;;;;;;;;;;;;;;;;
reset
;Duality in 3-space
ring r
;
4
a-z
;
;
; ;;;;;;;;;;;;;;;;;;;;;;;;
;The twisted cubic
cat a i
0 1
0 1 2
wedge i 2 i
flatten i i

set prlevel -4
<dual_variety i 2 j
type j
; b2c2-4ac3-4b3d+18abcd-27a2d2

<dual_variety j 1 i1
type i1
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The elliptic quartic
ideal i
2
ab-cd
a2+b2+c2-d2

;test for nonsingularity
jacob i ii
wedge ii 2 ii
flatten ii ii

concat ii i

std ii ii
codim ii
;4--so its nonsingular


set prlevel -4
<dual_variety i 2 j
type j

<dual_variety j 1 i1
type i1
