Distributivity in logic and algebra