Created
January 23, 2009 22:38
-
-
Save GabrielL/51240 to your computer and use it in GitHub Desktop.
Preuve de code simple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
length :: [a] -> Int | |
length [] = 0 | |
length (h:t) = 1 + length t | |
Prouver que la propriété P : | |
length [ l1 ++ l2 ] = length l1 + length l2 | |
---------------- | |
Montrons P([], []) | |
length [] = 0 | |
[ [] ++ [] ] = [] | |
donc on a bien P([], []) | |
Montrons que P(l1, l2) => P(e:l1, l2) | |
length e:l1 + length l2 = 1 + length l1 + length l2 | |
de plus [ e:l1 ++ l2 ] = e:[ l1 ++ l2 ] | |
donc, length [ e:l1 ++ l2 ] = length e:[ l1 ++ l2 ] | |
= 1 + length [ l1 ++ l2 ] | |
Or P(l1, l2) est vrai, donc P(e:l1, l2) est vraie | |
P(l1, []) => P(e:l1, []) est deja montrée dans le point precedent | |
Il nous reste a montrer P(l1, l2) <=> P(l2, l1) | |
length l1 + length l2 = length l2 + length l1 (par associativité de l'addition) | |
length [ l1 ++ l2 ] = length l1 + length l2 | |
length [ l2 ++ l1 ] = length l2 + length l1 | |
on a donc associativité de la propriété. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment