# declarations x, y = Vars('x y', fgsort) nil, ret = Consts('nil ret', fgsort) lft = Function('lft', fgsort, fgsort) rght = Function('rght', fgsort, fgsort) tree = RecFunction('tree', fgsort, boolsort) htree = RecFunction('htree', fgsort, fgsetsort) reach_lr = RecFunction('reach_lr', fgsort, fgsort, boolsort) AddRecDefinition( tree, x, If( x == nil, True, And( notInChildren(x), And( SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom, And(tree(lft(x)), tree(rght(x))))))) AddRecDefinition( htree, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(htree(lft(x)), htree(rght(x))), x))) AddRecDefinition( reach_lr, (x, y), If(x == y, True, Or(reach_lr(lft(x), y), reach_lr(rght(x), y)))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # vc goal = Implies(tree(x), Implies(reach_lr(x, y), tree(y))) # check validity with natural proof solver and no hardcoded lemmas
# declarations x, y = Vars('x y', fgsort) nil, ret = Consts('nil ret', fgsort) k = Const('k', intsort) key = Function('key', fgsort, intsort) lft = Function('lft', fgsort, fgsort) rght = Function('rght', fgsort, fgsort) dag = RecFunction('dag', fgsort, boolsort) tree = RecFunction('tree', fgsort, boolsort) htree = RecFunction('htree', fgsort, fgsetsort) AddRecDefinition(dag, x, If(x == nil, True, And(notInChildren(x), And(dag(lft(x)), dag(rght(x)))))) AddRecDefinition(tree, x, If(x == nil, True, And(notInChildren(x), And(SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom, And(tree(lft(x)), tree(rght(x))))))) AddRecDefinition(htree, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(htree(lft(x)), htree(rght(x))), x))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # vc pgm = If(x == nil, ret == nil, ret == lft(x)) goal = Implies(tree(x), Implies(pgm, dag(ret))) # check validity with natural proof solver and no hardcoded lemmas np_solver = NPSolver() solution = np_solver.solve(make_pfp_formula(goal)) if not solution.if_sat:
rght = Function('rght', fgsort, fgsort) minr = RecFunction('minr', fgsort, intsort) maxr = RecFunction('maxr', fgsort, intsort) bst = RecFunction('bst', fgsort, boolsort) hbst = RecFunction('hbst', fgsort, fgsetsort) AddRecDefinition(minr, x, If(x == nil, 100, min_intsort(key(x), minr(lft(x)), minr(rght(x))))) AddRecDefinition(maxr, x, If(x == nil, -1, max_intsort(key(x), maxr(lft(x)), maxr(rght(x))))) AddRecDefinition(bst, x, If(x == nil, True, And(0 < key(x), And(key(x) < 100, And(bst(lft(x)), And(bst(rght(x)), And(maxr(lft(x)) <= key(x), And(key(x) <= minr(rght(x)), And(notInChildren(x), SetIntersect(hbst(lft(x)), hbst(rght(x))) == fgsetsort.lattice_bottom))))))))) AddRecDefinition(hbst, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(hbst(lft(x)), hbst(rght(x))), x))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # vc goal = Implies(bst(x), Implies(And(x != nil, And(rght(y) != nil, And(IsMember(y, hbst(x)), And(k == maxr(x), And(k == maxr(y), y != nil))))), k == maxr(rght(y)))) # check validity with natural proof solver and no hardcoded lemmas np_solver = NPSolver()
lambda cyc, index: And(key(x) > z3.IntVal(-50), key(x) < z3.IntVal(50)), 'datacompare': lambda cyc, index: cyc[index](x) == z3.IntVal(3) } mixmethods = { 'normal': lambda index: True, 'skipone': lambda index: index % 2 == 0 } ## Variant dimension tree type treetypes = { 'dag': True, 'tree': SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom, 'maxheap': And( And(key(lft(x)) <= key(x), key(rght(x)) <= key(x)), SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom), 'bst': And( And(And(-100 < key(x), key(x) < 100), And(maxr(lft(x)) <= key(x), key(x) <= minr(rght(x)))), SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom), 'tree_p':