In order to save iterations (orderings) over the unsolved eq list, we can just divide them in separate lists for flex-flex and not-flex-flex or similar
Does the partial substitution has to be applied every time or can be postpone it?
General inspection of the code for alternative data structures that seem more appropriate than List
There are multiple things that can be improved: