| Copyright | (c) Levent Erkok |
|---|---|
| License | BSD3 |
| Maintainer | erkokl@gmail.com |
| Stability | experimental |
| Safe Haskell | None |
| Language | Haskell2010 |
Documentation.SBV.Examples.KnuckleDragger.ListLen
Description
Example use of the KnuckleDragger, about lenghts of lists
Documentation
Use an uninterpreted type for the elements
Instances
listLengthProof :: IO Proof Source #
Prove that the length of a list is one more than the length of its tail.
We have:
>>>listLengthProofLemma: length_correct Q.E.D. [Proven] length_correct
It is instructive to see what kind of counter-example we get if a lemma fails to prove.
Below, we do a variant of the listLengthProof, but with a bad implementation over integers,
and see the counter-example. Our implementation returns an incorrect answer if the given list is longer
than 5 elements and have 42 in it. We have:
>>>badProof `catch` (\(_ :: SomeException) -> pure ())Lemma: bad *** Failed to prove bad. Falsifiable. Counter-example: xs = [8,25,26,27,28,42] :: [Integer] imp = 42 :: Integer spec = 6 :: Integer
lenAppend :: IO Proof Source #
length (xs ++ ys) == length xs + length ys
We have:
>>>lenAppendLemma: lenAppend Q.E.D. [Proven] lenAppend
lenAppend2 :: IO Proof Source #
length xs == length ys -> length (xs ++ ys) == 2 * length xs
We have:
>>>lenAppend2Lemma: lenAppend2 Q.E.D. [Proven] lenAppend2