/// <summary>
        /// Adds the given substitution to the existing oners and apply the new composition
        /// to the existing problem.
        /// </summary>
        public void ComposeAndApplySubstitutions(Substitution newSubstitution)
        {
            // Add the new substitution to the existing ones
            List <Substitution> removeList = new List <Substitution>();
            bool found = false;

            foreach (var sub in CurrentSubstitutions)
            {
                sub.SubstitutionTerm = sub.SubstitutionTerm.ApplySubstitutions(new[] { newSubstitution });
                if (sub.Variable.Equals(sub.SubstitutionTerm))
                {
                    removeList.Add(sub);
                }
                else
                {
                    found = sub.Variable.Equals(newSubstitution.Variable);
                }
            }
            CurrentSubstitutions.RemoveAll(r => removeList.Contains(r));
            if (!found)
            {
                CurrentSubstitutions.Add(newSubstitution);
            }

            // Apply the modified substitutions to the existing problem
            foreach (var eq in CurrentEquations)
            {
                eq.Lhs = eq.Lhs.ApplySubstitutions(CurrentSubstitutions);
                eq.Rhs = eq.Rhs.ApplySubstitutions(CurrentSubstitutions);
            }
        }
 public UnificationContinuation CreateCopy()
 {
     return(new UnificationContinuation
     {
         CurrentEquations = new List <Equation>(CurrentEquations.Select(eq => eq.CreateCopy())),
         CurrentSubstitutions = new List <Substitution>(CurrentSubstitutions.Select(sub => sub.CreateCopy()))
     });
 }