Exemplo n.º 1
0
  def exec_weakf(self, envr, pm):
    result = ProofResult("")
    result.source = self
    
    if len(self.args) != 2:
      raise ProofError("weakf takes two arguments, found: " + str(len(self.args)))
    fun, notDom = map(lambda x: self.resolveOrDont(x), self.args)
    
    if not isinstance(fun, expSemantics.FunOK):
      raise ProofError("weakf expects a fun predicate, found: " + fun.shortString())
    if not isinstance(notDom, judge.InTest) or notDom.nt == False:
      raise ProofError("weakf expects a negative contains assertion, found: " + notDom.shortString())
    if not (isinstance(notDom.rhs, expSemantics.Dom) or (isinstance(notDom.rhs, expSemantics.FunApp) and isinstance(notDom.rhs.fun, judge.DomFun))):
      raise ProofError("weakf expects a domain assertion, found: " + notDom.rhs.shortString())
    if isinstance(notDom.rhs, expSemantics.Dom):
      domFun = notDom.rhs.arg
    else:    
      domFun = notDom.rhs.args[0]

    if domFun != fun.rhs:
      raise ProofError("non-matching arguments to weakf, found: " + fun.rhs.shortString() + "; " + domFun.shortString())
      
    if not isinstance(domFun, expSemantics.Concat) or len(domFun.elements) != 2:
      raise ProofError("weakf operates on a concatenation of length two, found: " + domFun)

    fType = util.isFunType(domFun.type(pm.world.symList), pm.world.symList)
    if not fType:
      raise ProofError("weakf expects a function, found: " + domFun.shortString())
      
    mapping = None
    qVar = envr.fresh(fType.rhs)
    for c in util.atomicType(domFun.elements[0], pm.world.symList).cases:
      if isinstance(c.syntax[0], symbol.List):
        mapPattern = c.syntax[0].arg
        ms = [symbol.IdMatch(fType.lhs[0], notDom.lhs), symbol.IdMatch(fType.rhs, qVar)]
        mapping = mapPattern.substMatch(ms)
    if not mapping:
      raise ProofError("Could not deconstruct function: " + domFun.shortString())

      
    df2 = expSemantics.Concat(None)
    df2.elements.append(domFun.elements[0])
    df2.elements.append(mapping)
    df2.elements.append(domFun.elements[1])
    df2.typeF = domFun.typeF
      
    fun2 = expSemantics.FunOK(None)
    fun2.rhs = df2
    
    forall = expSemantics.Forall(None)
    forall.qVars = [qVar]
    forall.rhs = fun2
      
    self.results = [forall]
    result.verbose = pm.getIndent() + "weakening: " + self.results[0].shortString()
    return result
Exemplo n.º 2
0
  def exec_fun(self, envr, pm):
    result = ProofResult("")
    result.source = self

    if len(self.args) != 2:
      raise ProofError("fun takes two arguments, found: " + str(len(self.args)))
    inMap, funok = map(lambda x: self.resolveOrDont(x), self.args)
    
    if not isinstance(inMap, judge.InTest) or inMap.nt:
      raise ProofError("fun expects a positive contains assertion, found: " + inMap.shortString())
    if not isinstance(funok, expSemantics.FunOK):
      raise ProofError("fun expects a function predicate, found: " + funok.shortString())
    if funok.rhs != inMap.rhs:
      raise ProofError("mismatch of arguments to fun, found: " + inMap.rhs.shortString() + "; " + funok.rhs.shortString())
    
    #extract the parts of the mapping
    sym = util.atomicType(inMap.lhs, pm.world.symList)
    fType = util.isFunType(sym, pm.world.symList)
    l = r = None
    if not fType:
      raise ProofError("Can not construct function: " + sym.shortString())
    for c in sym.cases:
      if len(c.syntax) == 1 and isinstance(c.syntax[0], symbol.List):
        m = inMap.lhs.isSuperType(c.syntax[0].arg, pm.world.symList)
        l = m.match(fType.lhs[0])
        r = m.match(fType.rhs)

    if not l:
      raise ProofError("Can not construct function: " + sym.shortString())
        
    apply = expSemantics.FunApp(None)
    apply.fun = funok.rhs
    apply.args = [l]
    
    eq = judge.Equality(None)
    eq.nt = False
    eq.lhs = apply
    eq.rhs = r
      
    self.results = [eq]
    
    result.verbose = pm.getIndent() + "function introduction: " + eq.shortString()
    return result
Exemplo n.º 3
0
  def exec_mfun(self, envr, pm):
    result = ProofResult("")
    result.source = self

    if len(self.args) != 1:
      raise ProofError("-fun takes one argument, found: " + str(len(self.args)))
    eq = self.resolveOrDont(self.args[0])
    
    if not isinstance(eq, judge.Equality):
      raise ProofError("-fun expects an equality, found: " + str(eq))    
    funapp = eq.lhs
    r = eq.rhs
    if not isinstance(funapp, expSemantics.FunApp):
      raise ProofError("-fun expects a function application on the lhs, found: " + funapp.shortString())
    fun = funapp.fun
    fType = util.isFunType(fun.type(pm.world.symList), pm.world.symList)
    if not fType or not hasattr(funapp, "funInfo") or not funapp.funInfo:
      raise ProofError("-fun can only operate on mappings, found: " + fun.shortString())
    l = funapp.args[0]

    mapping = None
    for c in funapp.funInfo.cases:
      if isinstance(c.syntax[0], symbol.List):
        mapPattern = c.syntax[0].arg
        ms = [symbol.IdMatch(fType.lhs[0], l), symbol.IdMatch(fType.rhs, r)]
        mapping = mapPattern.substMatch(ms)
    if not mapping:
      raise ProofError("Could not deconstruct function: " + fun.shortString())
    
    funok = expSemantics.FunOK(None)
    funok.rhs = fun
    inMap = judge.InTest(None)
    inMap.rhs = fun
    inMap.lhs = mapping
    inMap.nt = False
    
    self.results = [inMap, funok]
    
    result.verbose = pm.getIndent() + "function elimination: " + "; ".join(map(lambda x: x.shortString(), self.results))
    return result
Exemplo n.º 4
0
Arquivo: nchecker.py Projeto: nrc/N
 def isFunType(self, t):
   return util.isFunType(t, self.world.symList)
Exemplo n.º 5
0
Arquivo: nchecker.py Projeto: nrc/N
 def isFunType(self, t):
     return util.isFunType(t, self.world.symList)