rght = Function('rght', fgsort, fgsort) minr = Function('minr', fgsort, intsort) maxr = Function('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), key(x) <= minr(rght(x))))))))) 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) # Problem parameters goal = Implies(bst(x), Implies(And(x != nil, And(IsMember(y, hbst(x)), And(k == minr(x), And(k == minr(y), y != nil)))), k == minr(lft(y)))) # parameters representing the grammar for synth-fun and # terms on which finite model is extracted # TODO: extract this automatically from grammar_string v = Var('v', fgsort) lemma_grammar_args = [v, y, k, nil]
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 np_solver = NPSolver() solution = np_solver.solve(make_pfp_formula(goal)) if not solution.if_sat: print('goal (no lemmas) is valid') else:
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))) AddRecDefinition( keys, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(keys(lft(x)), keys(rght(x))), key(x)))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # vc goal = Implies( bst(x), Implies(And(IsMember(k, keys(x)), k < key(x), x != nil), IsMember(k, keys(lft(x))))) # check validity with natural proof solver and no hardcoded lemmas np_solver = NPSolver()
key = Function('key', fgsort, intsort) keys = Function('keys', fgsort, intsetsort) lft = Function('lft', fgsort, fgsort) rght = Function('rght', fgsort, fgsort) maxheap = RecFunction('maxheap', fgsort, boolsort) htree = RecFunction('htree', fgsort, fgsetsort) AddRecDefinition(maxheap, x, If(x == nil, True, And(notInChildren(x), And(SetIntersect(htree(lft(x)), htree(rght(x))) == fgsetsort.lattice_bottom, And(maxheap(lft(x)), And(maxheap(rght(x)), And(key(lft(x)) <= key(x), key(rght(x)) <= key(x)))))))) AddRecDefinition(htree, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(htree(lft(x)), htree(rght(x))), x))) AddRecDefinition(keys, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(keys(lft(x)), keys(rght(x))), key(x)))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # vc goal = Implies(maxheap(x), Implies(lft(x) != nil, Implies(IsMember(k, keys(x)), k <= key(x)))) # 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: print('goal (no lemmas) is valid') else: print('goal (no lemmas) is invalid')
AddRecDefinition(lseg, (x, y), If(x == y, True, lseg(nxt(x), y))) AddRecDefinition( keys, x, If(x == nil, intsetsort.lattice_bottom, SetAdd(keys(nxt(x)), key(x)))) AddRecDefinition( lsegkeys, (x, y), If(x == y, intsetsort.lattice_bottom, SetAdd(lsegkeys(nxt(x), y), key(x)))) AddAxiom((), nxt(nil) == nil) # Problem parameters pre = And(lst(y), x != c) goal = Implies(lseg(x, y), Implies(pre, keys(x) == SetUnion(lsegkeys(x, y), keys(y)))) # parameters representing the grammar for synth-fun and # terms on which finite model is extracted # TODO: extract this automatically from grammar_string v1, v2 = Vars('v1 v2', fgsort) lemma_grammar_args = [v1, v2, nil] lemma_grammar_terms = { v1, nil, nxt(nil), v2, nxt(v2), nxt(v1), nxt(nxt(v1)), nxt(nxt(nxt(v1))) }
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), key(x) <= minr(rght(x))))))))) AddRecDefinition( keys, x, If(x == nil, fgsetsort.lattice_bottom, SetAdd(SetUnion(keys(lft(x)), keys(rght(x))), key(x)))) AddAxiom((), lft(nil) == nil) AddAxiom((), rght(nil) == nil) # Problem parameters goal = Implies( bst(x), Implies(And(IsMember(k, keys(x)), k < key(x)), IsMember(k, keys(lft(x))))) # parameters representing the grammar for synth-fun and # terms on which finite model is extracted # TODO: extract this automatically from grammar_string v = Var('v', fgsort) lemma_grammar_args = [v, k, nil] lemma_grammar_terms = { lft(v),