本文整理匯總了Python中PE.evallToInt方法的典型用法代碼示例。如果您正苦於以下問題:Python PE.evallToInt方法的具體用法?Python PE.evallToInt怎麽用?Python PE.evallToInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PE
的用法示例。
在下文中一共展示了PE.evallToInt方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: proveUniversal
# 需要導入模塊: import PE [as 別名]
# 或者: from PE import evallToInt [as 別名]
def proveUniversal(C6, bfactlist, bgoal) :
""" Tries to prove a bgoal of form, ["forall", lo, i, hi, bprop_i_]
from bfactlist. First, attempts to show hi <= lo, meaning
quantification ranges over empty set. If this fails, tries
to establish numerical lower and upper bounds for the quantification
and enumerate proofs for all elements within these bounds.
If this fails, then searches
for a bfact in bfactlist that is a forall of the same form,
but where its upper bound is hi-1. If success, then tries
to prove bprop_hi-1_.
If I have the energy, I'll try to make this smarter later....
"""
#print "proveUNIVERSAL: bfactlist=", bfactlist
#print "goal=", bgoal
lo = bgoal[1]
hi = bgoal[3]
i = bgoal[2]
bprop = bgoal[4]
# first, see if bgoal in premises:
success = bgoal in bfactlist
if not success :
# next, try to prove that domain is empty, ie, hi <= lo :
success = verifyRelation(C6, bfactlist, ["<=", hi, lo])
if not success:
# next, try to establish numerical lower and upper bounds and
# prove bprop for all elements in the numerical range:
lonum = PE.evallToInt(C6, lo)
hinum = PE.evallToInt(C6, hi)
if isinstance(lonum, int) and isinstance(hinum, int):
success = True # so far, so good...
for j in range(lonum, hinum):
stree = Parse.substituteTree(["int", str(j)], i, bprop)
success = success and proveSequent(C6, bfactlist, stree)
if not success:
# then search bfactlist for a forall goal whose body
# matches bprop and whose bounds cover bgoal's all but one:
possibles = [ f for f in bfactlist
if f[0] == "forall" \
and Parse.substituteTree(i, f[2], f[4]) == bprop \
#and verifyRelation(C6, bfactlist, ["==", f[1], lo]) \
and verifyRelation(C6, bfactlist, ["<=", f[1], lo]) \
and verifyRelation(C6, bfactlist, \
["==", ["+", f[3], ["int", "1"]], hi]) \
]
if len(possibles) > 0 :
success = proveSequent(C6, bfactlist,
Parse.substituteTree \
(["-", hi, ["int", "1"]], i, bprop) )
if not success:
#search bfactlist for a forall goal whose body
# matches bprop and whose bounds cover bgoal's:
possibles = [ f for f in bfactlist
if f[0] == "forall" \
and Parse.substituteTree(i, f[2], f[4]) == bprop \
and verifyRelation(C6, bfactlist, ["<=", f[1], lo]) \
and verifyRelation(C6, bfactlist, [">=", f[3], hi]) \
]
success = (len(possibles) > 0)
return success