- term_variables(+Term, +Vars0, -Vars) is det
- Vars is the union of Vars0 and all variables that occur in Term.
This is not the same as SWI-Prolog's built-in term_variables/3 -
the argument order is different and this predicate is guaranteed
to return a list without duplicates.