code: public static boolean isIndempotent(Map<Variable, Variable> substitutionMap) {
          if (substitutionMap.isEmpty())
              return true;
  
          Set<Variable> valueSet = new HashSet<>(substitutionMap.values());
          valueSet.retainAll(substitutionMap.entrySet());
  
          return valueSet.isEmpty();
      }
docs: Returns true if there is common variables in the domain and the range of the substitution map.