finished implementing lattice partition function