public term InstantiateWithoutConstraints(term term) { if (Failed) { throw new Exception("this Vars failed and is in an invalid state"); } switch (term.Kind) { case TermKind.Atom: return(term); case TermKind.Apply: return(term.Apply(InstantiateWithoutConstraints(term.ApplyF), InstantiateWithoutConstraints(term.ApplyX))); case TermKind.Var: term value; if (_bindings.TryGetValue(term.VarName, out value)) { return(InstantiateWithoutConstraints(value)); } return(term); } throw new Exception("unreachable code"); }
private term Unfree(term term) { switch (term.Kind) { case TermKind.Atom: return(term); case TermKind.Apply: return(term.Apply(Unfree(term.ApplyF), Unfree(term.ApplyX))); case TermKind.Var: return(Generate(term.VarName, (a, x, y) => term.Var(new atom(a.Value + "_" + x)))); // TODO: This should be a utility op in atom } throw new Exception("unreachable case"); }
internal term Canonicalize(term term) { switch (term.Kind) { case TermKind.Atom: return(term); case TermKind.Apply: return(term.Apply(Canonicalize(term.ApplyF), Canonicalize(term.ApplyX))); case TermKind.Var: atom existing; if (_canonicalName.TryGetValue(term.VarName, out existing)) { return(term.Var(existing)); } return(term.Var(_canonicalName[term.VarName] = new atom("var_" + (++_counter)))); } throw new Exception("unreachable path"); }