!goto $wims_read_parm

:def
title=Parametric to implicit surface
synonyme=implicite equation 3d, 3d implicite equation, parametric to implicit 3D, implicit equation of a space surface
input=list
!exit

:proc
wims_rawmath_variables=u,v
formula=!nonempty item $formula
formula=!rawmath $formula
cnt=!itemcnt $formula
!if $cnt!=3
 error=bad_formula
 !exit
!endif
v1=!varlist nofn $formula
v2=!varlist $formula
n1=!itemcnt $v1
n2=!itemcnt $v2
!if $n2>$n1 or . isin $formula
 result=not_polynomial
 !exit
!endif
!if $n1<1
 result=no_parameter
 !exit
!endif
v1=!sort nocase items $v1
w1=!item 1 of $v1
w2=!item 2 of $v1
fml=$formula

!distribute items $fml into fx,fy,fz
!distribute items $formula into Fx,Fy,Fz
m2_header=implicit3d = (f1,f2,f3) -> (\
     -- f1 and f2 should be polynomials over QQ in a variable\
     -- t.  A string representation of the polynomial\
     -- F(x,y) is returned, where F(f1,f2) = 0.\
     R = QQ[$w1,$w2,x,y,z,h,MonomialSize=>16,MonomialOrder=>Eliminate 2];\
     f = value f1;\
     g = value f2;\
     k = value f3;\
     J = ideal(x-f,y-g,z-k);\
     Jh = homogenize(J,h);\
     M = selectInSubring(1,gens gb Jh);\
     toString substitute(M_(0,0), {h=>1}))

result=!exec m2 implicit3d("$fx","$fy","$fz")
result=!translate # to $\
$ in $result

# Here I just discard the first two words of the result
result=!word 3 to -1 of $result
!exit

:output

!if $result=not_polynomial
 Sorry, we can only compute equations when the parametric functions are
 polynomials of rational coefficients.
 !exit
!endif
!if $result=no_parameter
 Sorry, but are you sure that you have entered two polynomials of parameter
 t as the parametric coordinate functions?
 !exit
!endif

The space surface defined by the parametric equations
<p><center>
!htmlmath x = $Fx , y = $Fy , z = $Fz
<p></center>
satisfies the implicit equation
<p><center>
!insmath $result = 0 .
</center> <p>
<small>Computation done by Macaulay 2</small>

!exit

