Created
August 7, 2013 05:24
-
-
Save doublec/6171436 to your computer and use it in GitHub Desktop.
ATS factorial with proof
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
/* From an example in the ATS distribution */ | |
dataprop FACT (int, int) = | |
| FACTzero (0, 1) | |
| {n,r,r1:int | n > 0} FACTsucc (n, r) of (FACT (n-1, r1), MUL (n, r1, r)) | |
fun fact {n:nat} .<n>. (n: int n): [r:int] (FACT (n, r) | int r) = | |
if n > 0 then let | |
val (pf1 | r1) = fact (n - 1) | |
val (pf_mul | r) = n imul2 r1 | |
in | |
(FACTsucc (pf1, pf_mul) | r) | |
end else begin | |
(FACTzero () | 1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment