I did a map instead of a fold when checking for the absence of cycle. On programs with 10 000 of equations, I go from 150s to 5s.