K := GF(PreviousPrime(2^16));

range := [2, 3, 4];
range := [3];

for r in range do
    "\n**** r:", r;
    IndentPush();

    n := r + 3;
    k := (n - r)^2;
    n, k, r;
    time B := MinRankSystem(K, n, k, r);
    Universe(B);
    "#B:", #B;

    for NT in [1, 16] do
	"\n* NT:", NT;
	IndentPush();
	SetNthreads(NT);
	I := Ideal(B);

	"Get GB";
	time Groebner(I: PairsLimit := 500, Dense, DynamicStrategy);
	QuotientDimension(I);
	"Get Variety";
	time V := Variety(I: Al := "Wiedemann");
	V;
	time assert { Evaluate(f, V[1]): f in B } eq { 0 };
	IndentPop();
    end for;

    IndentPop();
end for;

/*

"Source: Text/System/Par.text";
"Line: 817";
"Date: Mon May 17 10:50:06 2021";
"Main: Wed Mar 31 17:08:09 2021";
// original file: Text/System/Par.text, line: 817
// Example: H5E7 ()
print "Example: H5E7";
ei := GetEchoInput();
SetEchoInput(true);
function RandomDenseSystem(K, n, m, d)
    P<[x]> := PolynomialRing(K, n, "grevlex");
    B := [
        &+[Random(K)*s: s in MonomialsOfDegree(P, k), k in [0 .. d]]:
            i in [1 .. m]
    ];
    sol := [Random(K): j in [1 .. n]];
    return [f - Evaluate(f, sol): f in B];
end function;
n := 27; B := RandomDenseSystem(GF(31), n, 2*n, 2);
// Single thread only
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 5000);
G;
Variety(Ideal(G));
// 24 threads
SetNthreads(24);
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 5000);
// GPU
SetNthreads(1); SetGPU(true);
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 5000);
n := 32; B := RandomDenseSystem(GF(31), n, 2*n, 2);
// Single thread only
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 10000);
Basis(I);
Variety(Ideal(G));
// 24 threads
SetNthreads(24);
I := Ideal(B); // Recreate ideal
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 10000);
// GPU
SetNthreads(1); SetGPU(true);
I := Ideal(B); // Recreate ideal
time G := GroebnerBasis(B, 6: Dense, PairsLimit := 10000);
SetEchoInput(ei);
*/
