We find all functions f0,f1,…,fm:{0,1}n→{0,1} and g0,g1,…,gn:{0,1}m→{0,1} satisfying the following identity for all n×m matrices (zij)∈{0,1}n×m: f0(g1(z11,…,z1m),…,gn(zn1,…,znm))=g0(f1(z11,…,zn1),…,fm(z1m,…,znm)). Our results generalize work of Dokow and Holzman (2010), which considered the case g0=g1=⋯=gn, and of Chase, Filmus, Minzer, Mossel and Saurabh (2022), which considered the case g0=g1=⋯=gn.