Skip to content

Instantly share code, notes, and snippets.

@gernst
gernst / prop_05.smt2
Created January 12, 2022 09:39
Isaplanner prop_05
(declare-datatypes ((Nat 0)) (((Z) (S (proj1-S Nat)))))
(declare-datatypes ((list 0))
(((nil) (cons (head Nat) (tail list)))))
(define-fun-rec
==
((x Nat) (y Nat)) Bool
(match x
((Z
(match y
((Z true)
@gernst
gernst / Mult.thy
Last active January 29, 2022 18:25
Proof that multiplication is commutative; following Rustan's proof in the Dafny demo at POPL 2022 virtual workshop
begin
fun mult :: "nat ⇒ nat ⇒ nat" where
"mult x 0 = 0" |
"mult x y = x + mult x (y - 1)"
lemma mult_rec[simp]:
"y ≠ 0 ⟹ mult x y = x + mult x (y - 1)"
by (cases y) auto
theory RegularBehavioralHoareLogic
imports Main
begin
(* Mechanization of
Gidon Ernst, Alexander Knapp, and Toby Murray:
A Hoare Logic with Regular Behavioral Specifications
submitted to ISoLa 2022
class Expr:
def eval(self, state):
pass
class Var(Expr):
def __init__(self, name):
self.name = name
def eval(self, state):
return state[name]
(* using tactics *)
lemma "A ∧ B ⟶ B ∧ A"
apply (rule impI) (* A ∧ B ⟹ B ∧ A *)
apply (rule conjI) (* 1: A ∧ B ⟹ B and 2: A ∧ B ⟹ A *)
(* goal 1 *)
apply (erule conjE) (* A ⟹ B ⟹ B *)
apply assumption
(* goal 2 *)
apply (erule conjE) (* A ⟹ B ⟹ A *)
apply assumption
theory Mergesort
imports Main
begin
fun sorted :: "nat list ⇒ bool" where
"sorted [] = True" |
"sorted (x#[]) = True" |
"sorted (x#y#zs) = (x ≤ y ∧ sorted (y#zs))"
fun merge :: "nat list ⇒ nat list ⇒ nat list" where
type Elem = int
/*** Specification ***/
trait SpecSet {
ghost var content: set<Elem>
method insert(x: Elem)
modifies this
ensures content == old(content) + {x}
@gernst
gernst / memcached.dfy
Created May 29, 2024 13:24
Dafny model of the memcached system
// Data types to model the domain
type Key(==) // Keys support equality
type Flags
type Time = nat
type Data
datatype option<T> =
none | some(get: T)
datatype Entry