Example #1
0
def saveDistinctElements(C6, arraymap, indexpe) :
    """retains within  arraymay  only those elements provably
       distinct from  indexpe
    """
    akeys = arraymap.keys()
    for key in akeys :
        elempe = PE.tupleToPe(key)  # get pe-value of element-index
        # is the following good enough?  Or will we need theorem proving?
        distinct = PE.prove(C6["rels"], ["!=", elempe, indexpe])
        if not distinct :
            del arraymap[key]
Example #2
0
def verifyRelation(C6, bfactlist, bgoal) :
    """attempts to verify  bgoal,  which is a primitive (relop or forall)
       
       params: C6 table
               bfactlist: a list of facts of form
                  [relop, e1, e2]  or  [forall/exists, lo, i, hi, e]
               bgoal: a single fact of form [relop, e1, e2]
                                         or [forall/exists, lo, i, hi, e]

       returns : True, if  bfactlist |- bgoal  is proved
                 False, if not
    """
    #print "verifyRelation: C6"#, C6
    #print "bfactlist:",  bfactlist
    #print "bgoal:", bgoal
    #raw_input("press Enter")

    if (bgoal[0] in RELOPS) :   # [relop, e1, e2]
        # eval goal:
        pe1 = PE.evall(C6, bgoal[1])
        pe2 = PE.evall(C6, bgoal[2])
        goal = [bgoal[0], pe1, pe2]

        # eval all facts in the bfactlist:
        factlist = []
        for f in list(bfactlist) :
            if f[0] in RELOPS :
                pe1 = PE.evall(C6, f[1])
                pe2 = PE.evall(C6, f[2])
                factlist.append([f[0], pe1, pe2])
            elif f[0] in ("forall", "exists") :
                 pass # can't handle quantified phrases (yet) in PE!
                 # If I am brave, I might try to evaluate lower and upper
                 # bounds of quantification and enumerate the facts therein.
                 # But this is high overhead....
        # send off the PE-valued facts and goal to the prover:
        #print "In verifyrelation; ready to call PE.prove:"
        #print "all facts=", factlist + C6["rels"]
        #print "goal=", goal
        return PE.prove(factlist + C6["rels"], goal)
    elif bgoal[0] == "forall" :
        return proveUniversal(C6, bfactlist, bgoal)
    else :  # ["exists", lo, i, hi, e] ???
        return False