Computing the Cartier-Foata form and height of traces by threshold circuits