def proxify(x): if util.isAtomic(x): return x else: fresh = envr.fresh(x.type(pm.world.symList)) trackFresh.add(fresh) pMatches.append(x.isSuperType(fresh, pm.world.symList)) return fresh
def exec_let(self, envr, pm): result = ProofResult("") result.source = self if len(self.args) != 1: raise ProofError("let takes one argument, found: " + str(len(self.args))) arg = self.args[0] if isinstance(arg, judge.Equality) or isinstance(arg, judge.InTest): if not (not arg.nt and arg.lhs == arg.rhs): vars = envr.getVars() if (arg.lhs in vars or not util.isAtomic(arg.lhs)) and (arg.rhs in vars or not util.isAtomic(arg.rhs)): raise ProofError("let command requires at least one variable to be free, found: " + arg.lhs.shortString() + "; " + arg.rhs.shortString()) else: raise ProofError("let command expects equality or contains assertion, found: " + arg.shortString()) self.results = [arg] result.verbose = pm.getIndent() + "let " + self.results[0].shortString() return result
def invertArg(self, arg, envr, pm): arg = self.resolveOrDont(arg) if not isinstance(arg, judge.Judge) or arg.nt: raise ProofError("Argument to " + self.command + " must be a positive judgement, found: " + arg.shortString()) #if any of the parts of arg are not atomic, we will need to use proxy variables proxy = judge.Judge(None) pMatches = [] proxy.defn = arg.defn proxy.nt = False trackFresh = set() def proxify(x): if util.isAtomic(x): return x else: fresh = envr.fresh(x.type(pm.world.symList)) trackFresh.add(fresh) pMatches.append(x.isSuperType(fresh, pm.world.symList)) return fresh proxy.envs = map(proxify, arg.envs) proxy.args = map(proxify, arg.args) #find the cases that match syntactically cases = [] matches2 = [] #matches formals to fresh variables matches = [] #matches fresh variables to actuals for c in proxy.defn.cases: m2 = symbol.SeqMatch(None) for source in set(c.getConclusions()[0].vars()): for v in source.vars(): if util.interestingRoot(v): m2.addIdMatch(v, envr.fresh(v)) m = proxy.unify(c.getConclusions()[0].substMatch([m2]), pm.world.symList) if m: cases.append(c) m.substMatch(pMatches) matches.append(m) matches2.append(m2) #if no cases, then we have a contradiction and the result is false if not cases: return None #use fresh variables for fv for c,m in zip(cases, matches2): for f in c.free: m.addIdMatch(f, envr.fresh(f)) #find the premises of those cases, subst variables deduced from conc prems = map(lambda (c,m,m2): map(lambda p: p.substMatch([m2]).substMatch([m]), c.premises), zip(cases, matches, matches2)) for (p, m, m2) in zip(prems, matches, matches2): for source in set(m.dom()): #account for equalities between actuals and formals of the conclusion/arg if not util.isAtomic(source): pe = judge.Equality(None) pe.lhs = m.match(source) pe.rhs = source.substMatch([m2]).substMatch([m]) pe.nt = False p.insert(0, pe) #account for where refinements of actuals would otherwise be lost elif not source.substMatch([m]).isSuperType(source, pm.world.symList): #revert the premises to using the more refined variable for i in range(len(p)): p[i] = p[i].substMatch([symbol.IdMatch(m.match(source), source.substMatch([m2]))]) #add an equality which captures the refinement pe = judge.Equality(None) pe.lhs = m.match(source) pe.rhs = source.substMatch([m2]) pe.nt = False p.insert(0, pe) return prems,cases