Sharedwww / TOM / tomOpen in CoCalc
// [email protected]
SetColumns(50);
//SetRows(20);

Q := Rationals();

P<r,s,t,u,v,w,
  x01,x02,x03,x04,x05,x06,x07,x08,
  x09,x10,x11,x12,x13,x14,x15,x16> := PolynomialRing(Q,22);
eqn := [];
for outer := 0 to 15 do
  ul := outer mod 2;
  ur := (outer div 2) mod 2;
  ll := (outer div 4) mod 2;
  lr := (outer div 8) mod 2;
  outereqn := 0;
  for inner := 0 to 3 do
    innereqn := 1;
    il := inner mod 2;
    ir := (inner div 2) mod 2; 
    if ul eq il then
      innereqn *:= 1-r;
    else
      innereqn *:= r;
    end if;
    if ll eq il then
      innereqn *:= 1-s;
    else
      innereqn *:= s;
    end if;
    if il eq ir then
      innereqn *:= 1-t;
    else 
      innereqn *:= t;
    end if;
    if ur eq ir then
      innereqn *:= 1-u;
    else
      innereqn *:= u;
    end if;
    if lr eq ir then
      innereqn *:= 1-v;
    else
      innereqn *:= v;
    end if;
    outereqn +:= innereqn;
  end for;
  Append(~eqn,outereqn);

end for;

neweqn := [];

temp := x01 - w*eqn[1]; Append(~neweqn, temp);
temp := x02 - w*eqn[2]; Append(~neweqn, temp);
temp := x03 - w*eqn[3]; Append(~neweqn, temp);
temp := x04 - w*eqn[4]; Append(~neweqn, temp);
temp := x05 - w*eqn[5]; Append(~neweqn, temp);
temp := x06 - w*eqn[6]; Append(~neweqn, temp);
temp := x07 - w*eqn[7]; Append(~neweqn, temp);
temp := x08 - w*eqn[8]; Append(~neweqn, temp);
temp := x09 - (1-w)*eqn[9]; Append(~neweqn, temp);
temp := x10 - (1-w)*eqn[10]; Append(~neweqn, temp);
temp := x11 - (1-w)*eqn[11]; Append(~neweqn, temp);
temp := x12 - (1-w)*eqn[12]; Append(~neweqn, temp);
temp := x13 - (1-w)*eqn[13]; Append(~neweqn, temp);
temp := x14 - (1-w)*eqn[14]; Append(~neweqn, temp);
temp := x15 - (1-w)*eqn[15]; Append(~neweqn, temp);
temp := x16 - (1-w)*eqn[16]; Append(~neweqn, temp);

I := ideal<P|neweqn>;
I;
SetVerbose("Groebner",true);
B := GroebnerBasis(I);
B;