Distributed Function Computation over Fields and Rings via Linear Compression of Sources