def testEvalSem2(self): com = Seq(incr_one, incr_one) st = mk_const_fun(natT, zero) st2 = fun_upd_of_seq(0, 2) goal = Sem(com, st, st2) prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export() self.assertEqual(thy.check_proof(prf), Thm([], goal))
def testEvalSem(self): com = Seq(Assign(zero, abs(s, one)), Assign(one, abs(s, nat.to_binary(2)))) st = mk_const_fun(natT, zero) st2 = fun_upd_of_seq(0, 1, 1, 2) goal = Sem(com, st, st2) prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export() self.assertEqual(thy.check_proof(prf), Thm([], goal))
def testEvalSem5(self): com = While(abs(s, logic.neg(eq(s(zero), nat.to_binary(3)))), assn_true, incr_one) st = mk_const_fun(natT, zero) st2 = fun_upd_of_seq(0, 3) goal = Sem(com, st, st2) prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export() rpt = ProofReport() self.assertEqual(thy.check_proof(prf, rpt), Thm([], goal))
def process_file(input, output): thy = basic.load_theory('hoare') dn = os.path.dirname(os.path.realpath(__file__)) with open(os.path.join(dn, 'examples/' + input + '.json'), encoding='utf-8') as a: data = json.load(a) output = json_output.JSONTheory(output, ["hoare"], "Generated from " + input) content = data['content'] eval_count = 0 vcg_count = 0 for run in content: if run['ty'] == 'eval': com = parse_hoare(run['com']) st1 = mk_const_fun(nat.natT, nat.zero) for k, v in sorted(run['init'].items()): st1 = mk_fun_upd(st1, nat.to_binary(str_to_nat(k)), nat.to_binary(v)) st2 = mk_const_fun(nat.natT, nat.zero) for k, v in sorted(run['final'].items()): st2 = mk_fun_upd(st2, nat.to_binary(str_to_nat(k)), nat.to_binary(v)) Sem = hoare.Sem(natFunT) goal = Sem(com, st1, st2) prf = ProofTermDeriv("eval_Sem", thy, goal, []).export() rpt = ProofReport() th = thy.check_proof(prf, rpt) output.add_theorem("eval" + str(eval_count), th, prf) eval_count += 1 elif run['ty'] == 'vcg': com = parse_hoare(run['com']) pre = Term.mk_abs(st, parse_cond(run['pre'])) post = Term.mk_abs(st, parse_cond(run['post'])) Valid = hoare.Valid(natFunT) goal = Valid(pre, com, post) prf = hoare.vcg_solve(thy, goal).export() rpt = ProofReport() th = thy.check_proof(prf, rpt) output.add_theorem("vcg" + str(vcg_count), th, prf) vcg_count += 1 else: raise TypeError() output.export_json()
def testEvalSem4(self): com = Cond(abs(s, logic.neg(eq(s(zero), one))), incr_one, Skip) st = mk_const_fun(natT, zero) st2 = fun_upd_of_seq(0, 1) goal = Sem(com, st, st2) prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export() self.assertEqual(thy.check_proof(prf), Thm([], goal)) goal = Sem(com, st2, st2) prf = hoare.eval_Sem_macro().get_proof_term(thy, goal, []).export() self.assertEqual(thy.check_proof(prf), Thm([], goal))
def testProveEvalI(self): s = function.mk_fun_upd(function.mk_const_fun(natT, zero), one, nat.to_binary(7)) test_data = [ (expr.Plus(expr.V(one), expr.N(nat.to_binary(5))), nat.to_binary(12)), (expr.Plus(expr.V(zero), expr.N(nat.to_binary(5))), nat.to_binary(5)), (expr.Times(expr.V(one), expr.N(nat.to_binary(5))), nat.to_binary(35)), ] for t, n in test_data: goal = expr.avalI(s, t, n) prf = expr.prove_avalI_macro().get_proof_term(thy, goal, []).export() self.assertEqual(thy.check_proof(prf), Thm([], goal))
def fun_upd_of_seq(*ns): return mk_fun_upd(mk_const_fun(natT, zero), *[nat.to_binary(n) for n in ns])