public TermFunction ReplaceVariablesAndConstants(Term function) { var assignment = new Substitution(); var termsToReplace = new HashSet<Term>(); GdlVisitors.VisitTerm(function, new GdlVisitor { VisitConstant = constant => termsToReplace.Add(constant), VisitVariable = variable => termsToReplace.Add(variable) }); foreach (TermVariable var in GetVariables(function)) assignment.AddMapping(var, GetUnusedVariable()); return (TermFunction)function.ApplySubstitution(assignment); }
public Substitution GetReplacementAssignment(Fact sentence, UnusedVariableGenerator varGen) { Debug.Assert(Applies(sentence)); var assignment = new Substitution(); List<Term> tuple = sentence.NestedTerms.ToList(); foreach (int varIndex in _replacementsByOriginalTupleIndex.Keys) { TermFunction function = _replacementsByOriginalTupleIndex[varIndex]; TermFunction replacementFunction = varGen.ReplaceVariablesAndConstants(function); assignment.AddMapping((TermVariable)tuple[varIndex], replacementFunction); } return assignment; }