Gauge invariant extremization on the lattice