diff options
author | Braxton Hall | 2022-10-24 07:06:33 +0000 |
---|---|---|
committer | GitHub | 2022-10-24 07:06:33 +0000 |
commit | bb4dd5b33e782d2c385c3393af783a8dd36770c4 (patch) | |
tree | 0fba8615c9c3f8f9de3853f074b7bc83fbf14008 /entries/lizard-business/fib.dats | |
parent | 15c8967ec8074f3c7272ac7107847e3bb4539e99 (diff) | |
parent | dcf99fd7ebf54474ea6d81ced6e00c28fba614fa (diff) |
Merge pull request #18 from lizard-business/maude-ats
add maude & ATS
Diffstat (limited to 'entries/lizard-business/fib.dats')
-rw-r--r-- | entries/lizard-business/fib.dats | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/entries/lizard-business/fib.dats b/entries/lizard-business/fib.dats new file mode 100644 index 0000000..f6bd5a1 --- /dev/null +++ b/entries/lizard-business/fib.dats @@ -0,0 +1,25 @@ +#include "share/atspre_define.hats" +#include "share/atspre_staload.hats" + +dataprop is_fib(int, int) = +| F0(0, 0) | F1(1, 1) +| {i, m, n : nat} Fplus(i + 2, m + n) of (is_fib(i, m), is_fib(i + 1, n)) + +typedef fib(i : int) = [n : nat] (is_fib(i, n) | int(n)) + + +fun fib {t : nat} .<>. (t : int(t)) :<> fib(t) = +let + fun go {m, n, i : nat | i <= t} .<t - i>. + (M : is_fib(i, m), N : is_fib(i + 1, n) | + m : int(m), n : int(n), i : int(i)) :<> + fib(t) = + if i = t then (M | m) + else go(N, Fplus(M, N) | n, m + n, i + 1) +in + go(F0, F1 | 0, 1, 0) +end + +fun fib_(i : Nat) : Nat = let val (_ | res) = fib(i) in res end + +implement main0 () = println!("fib(15) = ", fib_(15)) |