Replies: 3 comments 3 replies
-
This section of the tutorial provides an introduction to termination proofs: http://fstar-lang.org/tutorial/book/part1/part1_termination.html#proofs-of-termination This part shows one example of non-structural recursion: http://fstar-lang.org/tutorial/book/part1/part1_quicksort.html#proving-sort-correct More advanced topics about termination are here: http://fstar-lang.org/tutorial/book/part2/part2_well_founded.html#well-founded-relations-and-termination For your example: When you write I'll let you think about the answer but if you're stuck, please ask again. |
Beta Was this translation helpful? Give feedback.
-
I think you mean that the length of the list is decreasing. you'll have to prove that filter's output list is no longer than its input. |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Hello. I am new to F* and i have some code in Haskell that i am trying to 'translate' to F* (dont ask why). I read and skimmed and read again parts of the tutorial webside but i saw that some parts are not yet written.
Anyway, this is a function i wrote and tested on the tutorial website verifier. It's purpose is to receive a list of 'literals' (a literal is a type i defined, Var string | NotVar string, where the string is the name of the 'literal', Var means it's positive, NotVar means it's negative) and if i find 2 literals in the list, one positive and one negative, but with the same 'name', remove them.
But it keeps giving me the error 'Could not prove termination of this recursive call'. And i dont know what to change to prove termination.
Sorry i am not sure how to indent the lines for readability.
let rec removeLiteralsWithBothPolarities literals : Tot (res: list literal {subset res literals}) (decreases literals) =
match literals with
| [] -> []
| lit :: otherLiterals -> let negatedLit = negateLit lit in
let doesContain = contains negatedLit otherLiterals in
if doesContain
then
removeLiteralsWithBothPolarities (List.Tot.filter (fun (x: literal) -> not (x = negatedLit || x = lit)) otherLiterals)
else
let newOtherLiterals = removeLiteralsWithBothPolarities otherLiterals in
lit :: newOtherLiterals
Beta Was this translation helpful? Give feedback.
All reactions