Skip to content

Instantly share code, notes, and snippets.

@doublec
Created August 7, 2013 05:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doublec/6171436 to your computer and use it in GitHub Desktop.
Save doublec/6171436 to your computer and use it in GitHub Desktop.
ATS factorial with proof
/* 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