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

; An (open) problem suggested by 
;Igor Dolgachev (6/92)--
;The dual of a nonsingular plane cubic
;is a sextic with 9 cusps.  There is a
;unique cubic through those nine cusps.
;If one repeats this procedure for a long
;time, does one come back to the start?
;If one starts with a curve in Hesse
;normal form, 
;   a3+b3+c3+habc,  where h is a scalar,
;then the cubic
;through the cusps of the dual will 
;apparently also be in Hesse form, which
;makes computations rather convenient.
;What is the discrete dynamical system
;on the h-line that we have here??
;    Similarly, if one starts with a
;cubic and takes the Hessian, one gets
;another cubic.  Again, the process 
;produces a cubic in Hesse normal form
;if we start with such a cubic.  What about
;combinations of the two operations?
;
<ring 3 a-c r
poly h 1
poly f a3+b3+c3+{h}*abc

;repeat from here....
<dual_variety f 1 g
jacob g jg
flatten jg jg
std jg jg
betti jg
; total:      1     3 
; --------------------
;     0:      1     - 
;     1:      -     - 
;     2:      -     - 
;     3:      -     - 
;     4:      -     3 

;the cusps of g count as two points
;each in jg -- so take the radical
<radical jg jg 
;betti jg
; total:      1     4 
; --------------------
;     0:      1     - 
;     1:      -     - 
;     2:      -     1 
;     3:      -     3 
submat jg F
;
1
;type F
; a3+b3+53/9abc+c3 
;The dynamical system for
;the dual cusp construction:
;h: 1, 122/11, 53/27


;To compute the Hessian of f
jacob f jf
jacob jf jf
wedge jf 3 Hesse
;Bring it to normal form 
;by getting the coefficient of a3 and 
;dividing
coef Hesse dummy coefs
submat coefs A
1
1
<inverse A A
mult Hesse A Hesse 

type Hesse
; a3+b3-109/3abc+c3 
;dynamical system for the hessian 
;-109/3, -96/101, 899, 11114

type F
;The dynamical system for
;the dual cusp construction:
;h: 1, 122/11, 53/27, 113/11

copy F f
;Now selecting the whole script above
;and executing will iterate...
