Calculate the trace more efficiently.