示例#1
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If
from z3 import IsMember, IsSubset, SetUnion, SetIntersect, SetComplement, EmptySet, SetAdd

from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort, min_intsort, max_intsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom

from lemsynth.lemsynth_engine import solveProblem

# Declarations
x = Var('x', fgsort)
y, nil = Consts('y nil', fgsort)
k = Const('k', intsort)
key = Function('key', fgsort, intsort)
lft = Function('lft', fgsort, fgsort)
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)))))))))
示例#2
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If, Exists
from z3 import IsSubset, IsMember, SetUnion, SetIntersect, SetComplement, EmptySet, SetAdd

from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.prover import NPSolver
import naturalproofs.proveroptions as proveroptions

from lemsynth.lemsynth_engine import solveProblem

x, y, tx = Vars('x y tx', fgsort)
hx = Var('hx', intsort)

# ADT definition of lists
nil = Const('nil', fgsort)
cons = Function('cons', intsort, fgsort, fgsort)

# projections for cons
head = Function('head', fgsort, intsort)
tail = Function('tail', fgsort, fgsort)

# rec defs
append = RecFunction('append', fgsort, fgsort, fgsort)
length = RecFunction('length', fgsort, intsort)
AddRecDefinition(append, (x, y),
                 If(x == nil, y, cons(head(x), append(tail(x), y))))
AddRecDefinition(length, x, If(x == nil, 0, length(tail(x)) + 1))
示例#3
0
import z3
from z3 import And, Or, Not, Implies, If
from z3 import IsMember, IsSubset, SetUnion, SetIntersect, SetComplement, EmptySet, SetAdd

from naturalproofs.prover import NPSolver
from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort, min_intsort, max_intsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.pfp import make_pfp_formula

from lemsynth.lemsynth_engine import solveProblem

def notInChildren(x):
    return And(Not(IsMember(x, hbst(lft(x)))), Not(IsMember(x, hbst(rght(x)))))

# declarations
x = Var('x', fgsort)
y, nil = Consts('y nil', fgsort)
k = Const('k', intsort)
key = Function('key', fgsort, intsort)
lft = Function('lft', fgsort, fgsort)
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)),
示例#4
0
            # print(solution.model)
            # exit(0)
    except ValueError as err:
        continue
    factory_counter = factory_counter + 1
    if args.dry:
        with open('autobench.cache', 'a') as f:
            f.write(bench_name + '\n')
        print(bench_name)
        continue

    # Not a dry run
    print(f'Running automatically generated benchmark: {bench_name}')

    # lemma synthesis
    v1 = Var('v1', fgsort)
    lemma_grammar_args = [v1, nil]
    lemma_grammar_terms = {v1}

    theorem_name = 'autobench__' + hashlib.md5(bench_name.encode('utf-8')).hexdigest()
    grammar_string = f"""
(synth-fun lemma ((x Int) (nil Int)) Bool

            ((Start Bool) (Val Int))

            ((Start Bool (
                    (=> Start Start)
                    (and Start Start)
                    (= x nil)
                    (not (= x nil))
                    {synth_str} ;benchmark-specific predicates
示例#5
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If
from z3 import IsSubset, Union, SetIntersect, SetComplement, EmptySet

from naturalproofs.prover import NPSolver
from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.pfp import make_pfp_formula

from lemsynth.lemsynth_engine import solveProblem

# declarations
x = Var('x', fgsort)
c, s, nil = Consts('c s nil', fgsort)
v1 = Function('v1', fgsort, fgsort)
v2 = Function('v2', fgsort, fgsort)
p = Function('p', fgsort, fgsort)
n = Function('n', fgsort, fgsort)

reach_pgm = RecFunction('reach_pgm', fgsort, boolsort)

# precondition
AddAxiom((), v1(s) == n(v2(s)))

cond = v1(p(x)) != nil
assign1 = v1(x) == n(v1(p(x)))
assign2 = v2(x) == n(v2(p(x)))
assign = And(assign1, assign2)
AddRecDefinition(reach_pgm, x,
示例#6
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If
from z3 import IsSubset, Union, SetIntersect, SetComplement, EmptySet

from naturalproofs.prover import NPSolver
from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.pfp import make_pfp_formula

from lemsynth.lemsynth_engine import solveProblem

# declarations
x = Var('x', fgsort)
l = Var('l', intsort)
nil, ret = Consts('nil ret', fgsort)
nxt = Function('nxt', fgsort, fgsort)
lst = RecFunction('lst', fgsort, boolsort)
lstlen_bool = RecFunction('lstlen_bool', fgsort, boolsort)
lstlen_int = RecFunction('lstlen_int', fgsort, intsort)
AddRecDefinition(lst, x, If(x == nil, True, lst(nxt(x))))
AddRecDefinition(lstlen_bool, x, If(x == nil, True, lstlen_bool(nxt(x))))
AddRecDefinition(lstlen_int, x, If(x == nil, 0, lstlen_int(nxt(x)) + 1))
AddAxiom((), nxt(nil) == nil)

# vc
pgm = If(lstlen_int(x) == 1, ret == x, ret == nxt(x))
goal = Implies(lstlen_bool(x), Implies(pgm, lst(ret)))

# check validity with natural proof solver and no hardcoded lemmas
示例#7
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If
from z3 import IsSubset, Union, SetIntersect, SetComplement, EmptySet

from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.prover import NPSolver
import naturalproofs.proveroptions as proveroptions
from naturalproofs.pfp import make_pfp_formula

from lemsynth.lemsynth_engine import solveProblem

# declarations
x = Var('x', fgsort)
nil, yc, zc = Consts('nil yc zc', fgsort)
k = Const('k', intsort)
nxt = Function('nxt', fgsort, fgsort)
lsegy = RecFunction('lsegy', fgsort, boolsort)
lsegz = RecFunction('lsegz', fgsort, boolsort)
lsegy_p = RecFunction('lsegy_p', fgsort, boolsort)
lsegz_p = RecFunction('lsegz_p', fgsort, boolsort)
key = Function('key', fgsort, intsort)
AddRecDefinition(lsegy, x, If(x == yc, True, lsegy(nxt(x))))
AddRecDefinition(lsegz, x, If(x == zc, True, lsegz(nxt(x))))
# lsegy_p, lsegz_p defs reflect change of nxt(y) == z
AddRecDefinition(lsegy_p, x, If(x == yc, True, lsegy_p(If(x == yc, zc,
                                                          nxt(x)))))
AddRecDefinition(lsegz_p, x, If(x == zc, True, lsegz_p(If(x == yc, zc,
                                                          nxt(x)))))
示例#8
0
import importlib_resources

import z3
from z3 import And, Or, Not, Implies, If, Exists
from z3 import IsSubset, IsMember, SetUnion, SetIntersect, SetComplement, EmptySet, SetAdd

from naturalproofs.uct import fgsort, fgsetsort, intsort, intsetsort, boolsort
from naturalproofs.decl_api import Const, Consts, Var, Vars, Function, RecFunction, AddRecDefinition, AddAxiom
from naturalproofs.prover import NPSolver
import naturalproofs.proveroptions as proveroptions

from lemsynth.lemsynth_engine import solveProblem

l, tl = Vars('l tl', fgsort)
k, h = Consts('k h', intsort)
x = Var('x', intsort)

# ADT definition of lists
nil = Const('nil', fgsort)
cons = Function('cons', intsort, fgsort, fgsort)

# projections for cons
head = Function('head', fgsort, intsort)
tail = Function('tail', fgsort, fgsort)

# rec defs
slst = RecFunction('slst', fgsort, boolsort)
elems = RecFunction('elems', fgsort, fgsetsort)
member = RecFunction('member', fgsort, boolsort)
AddRecDefinition(
    slst, l,
示例#9
0
# hardcoded lemmas
lemma_params = (x, )
lemma_body = Implies(maxheap(x), dag(x))
lemmas = {(lemma_params, lemma_body)}

# check validity of lemmas
solution = np_solver.solve(make_pfp_formula(lemma_body))
if not solution.if_sat:
    print('lemma is valid')
else:
    print('lemma is invalid')

# check validity with natural proof solver and hardcoded lemmas
solution = np_solver.solve(goal, lemmas)
if not solution.if_sat:
    print('goal (with lemmas) is valid')
else:
    print('goal (with lemmas) is invalid')

# lemma synthesis
v = Var('v', fgsort)
lemma_grammar_args = [v, nil]
lemma_grammar_terms = {v, nil, rght(v), lft(v)}

name = 'maxheap-dag'
grammar_string = importlib_resources.read_text('grammars',
                                               'grammar_{}.sy'.format(name))

solveProblem(lemma_grammar_args, lemma_grammar_terms, goal, name,
             grammar_string)