

// WARNING: This function makes use of the computationally expensive routine Coordinates. 
function MakeSimultaneousCombo(G,H,e)
	R := Parent(G);
	k := BaseRing(R);
	n := Rank(R);	
	
	// Dummy variables not corresponding to edges.
	S := PolynomialRing(k,n+2);
	s := S.(n+1);
	t := S.(n+2);

	phi := hom<R->S | [S.i : i in [1 .. n]]>;
	
	F := s*phi(G) + t*phi(H);
	Fe := Derivative(F,e);
	He := Derivative(phi(H),e);

	eqns := [Derivative(Fe,i) : i in [1 .. n]] cat [t*He];
	I := IdealWithFixedBasis(eqns);
	
	A := Coordinates(I,F);	
	return A;
end function;

k := Rationals();

R<x,y,z,w,e> := PolynomialRing(k,5);
vars := [R.i : i in [1 .. Rank(R)]];

// Polynomials for H. Note that e=eta.
H := e*(x+y) + (x*y + (x+y)*(z+w));
Hbar := e*(x*y + (x+y)*(z+w));

// The edge for which we desire a simultaneous combination.
i := 5;

A := [ Evaluate(aj, vars cat [0,0]) : aj in MakeSimultaneousCombo(H,Hbar,i)];
c := A[#A];

assert &+[A[j]*Derivative(Derivative(H,j),i) : j in [1 .. 5]] eq H;

assert &+[A[j]*Derivative(Derivative(Hbar,j),i) : j in [1 .. 5]] 
		+ c*Derivative(Hbar,i) eq Hbar;


