Skip to content

Instantly share code, notes, and snippets.

@jeb2239
Created July 17, 2016 01:17
Show Gist options
  • Save jeb2239/4e5c3ba90d2648f2f1a49b67e3d78247 to your computer and use it in GitHub Desktop.
Save jeb2239/4e5c3ba90d2648f2f1a49b67e3d78247 to your computer and use it in GitHub Desktop.
module Hello
val factorial: x:int{x>=0} -> Tot int (*factorial is a totalfunction over non negative ints*)
val length: list 'a -> Tot nat
let rec length l = match l with
| [] -> 0
| _ :: tl -> 1 + length tl
val mem: x:'a -> l:list 'a -> Tot bool
let rec mem x l = match l with
| [] -> false
| head::tl -> head=x || (mem x tl)
val append: x:list 'a -> y:list 'a -> Tot (z:list 'a {length z = length x + length y})
let rec append l1 l2 = match l1 with
| [] -> l2
| hd :: tl -> hd :: append tl l2
val append_mem: l1:list 'a -> l2:list 'a -> a:'a
-> Lemma (ensures (mem a (append l1 l2) <==> mem a l1 || mem a l2))
let rec append_mem l1 l2 a = match l1 with
| [] -> ()
| hd::tl ->append_mem tl l2 a
let rec factorial n = if n = 0 then 1 else n * factorial (n - 1)
let max x y = if x > y then x else y
let a = assert (
forall x y. max x y >= x && max x y >= y &&
(max x y = x || max x y = y)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment