Can I use lemmas for constraining types for initial functions? #2618
Answered
by
TheoWinterhalter
WhiteBlackGoose
asked this question in
Q&A
-
So, assume I have function let rec mergeSort (l : list int) : list int In a separate lemma I prove that for the returned list it is true that it is sorted: let rec sortReturnsSorted (l : list int) : Lemma (ensures sorted (mergeSort l)) Now, can I use this lemma to change the initial function to let rec mergeSort (l : list int) : (r : list int { sorted r }) ? |
Beta Was this translation helpful? Give feedback.
Answered by
TheoWinterhalter
Jun 11, 2022
Replies: 1 comment 3 replies
-
Yes, you can simply define it to be the other assume val _mergeSort (l : list int) : list int
let cmp (x y : int) = x < y
assume val sortReturnsSorted (l : list int) : Lemma (sorted cmp (_mergeSort l))
let mergeSort (l : list int) : (r : list int { sorted cmp r }) =
sortReturnsSorted l ;
_mergeSort l |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
WhiteBlackGoose
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can simply define it to be the other
mergeSort
and use the lemma to conclude: