module Part1.Lemmas open FStar.Mul let rec factorial (n:nat) : nat = if n = 0 then 1 else n * factorial (n - 1) let rec factorial_is_greater_than_arg (x:int) : Lemma (requires x > 2) (ensures factorial x > x) = admit() //////////////////////////////////////////////////////////////////////////////// let rec fibonacci (n:nat) : nat = if n <= 1 then 1 else fibonacci (n - 1) + fibonacci (n - 2) val fibonacci_greater_than_arg (n:nat{n >= 2}) : Lemma (fibonacci n >= n) let fibonacci_greater_than_arg = admit() //////////////////////////////////////////////////////////////////////////////// let rec app #a (l1 l2:list a) : list a = match l1 with | [] -> l2 | hd :: tl -> hd :: app tl l2 let rec length #a (l:list a) : nat = match l with | [] -> 0 | _ :: tl -> 1 + length tl val app_length (#a:Type) (l1 l2:list a) : Lemma (length (app l1 l2) = length l1 + length l2) let app_length = admit() //////////////////////////////////////////////////////////////////////////////// let rec append (#a:Type) (l1 l2:list a) : list a = match l1 with | [] -> l2 | hd::tl -> hd :: append tl l2 let rec reverse #a (l:list a) : list a = match l with | [] -> [] | hd :: tl -> append (reverse tl) [hd] let rec rev_involutive #a (l:list a) : Lemma (reverse (reverse l) == l) = admit() let rec rev_injective (#a:Type) (l1 l2:list a) : Lemma (requires reverse l1 == reverse l2) (ensures l1 == l2) = admit() //////////////////////////////////////////////////////////////////////////////// let rec map #a #b (f: a -> b) (l:list a) : list b = match l with | [] -> [] | hd::tl -> f hd :: map f tl //write a type for find let rec find f l = match l with | [] -> None | hd :: tl -> if f hd then Some hd else find f tl //////////////////////////////////////////////////////////////////////////////// //Write a simpler type for find and prove the lemmas below let rec find_alt f l = match l with | [] -> None | hd :: tl -> if f hd then Some hd else find_alt f tl let rec find_alt_ok #a (f:a -> bool) (l:list a) : Lemma (match find_alt f l with | Some x -> f x | _ -> true) = match l with | [] -> () | _ :: tl -> find_alt_ok f tl //////////////////////////////////////////////////////////////////////////////// let rec fold_left #a #b (f: b -> a -> a) (l: list b) (acc:a) : a = match l with | [] -> acc | hd :: tl -> fold_left f tl (f hd acc) let fold_left_Cons_is_rev (#a:Type) (l:list a) : Lemma (fold_left Cons l [] == reverse l) = admit() //////////////////////////////////////////////////////////////////////////////// let rec rev_aux #a (l1 l2:list a) : Tot (list a) (decreases l2) = match l2 with | [] -> l1 | hd :: tl -> rev_aux (hd :: l1) tl let rev #a (l:list a) : list a = rev_aux [] l let rev_is_ok #a (l:list a) : Lemma (rev l == reverse l) = admit() //////////////////////////////////////////////////////////////////////////////// let rec fib (a b n:nat) : Tot nat (decreases n) = match n with | 0 -> a | _ -> fib b (a+b) (n-1) let fib_tail (n:nat) : nat = fib 1 1 n let fib_tail_is_ok (n:nat) : Lemma (fib_tail n == fibonacci n) = admit()