aboutsummaryrefslogtreecommitdiff
path: root/sample/unary_numbers/GCM2023/FibSZ_31-reuse.in
diff options
context:
space:
mode:
Diffstat (limited to 'sample/unary_numbers/GCM2023/FibSZ_31-reuse.in')
-rw-r--r--sample/unary_numbers/GCM2023/FibSZ_31-reuse.in19
1 files changed, 19 insertions, 0 deletions
diff --git a/sample/unary_numbers/GCM2023/FibSZ_31-reuse.in b/sample/unary_numbers/GCM2023/FibSZ_31-reuse.in
new file mode 100644
index 0000000..3163182
--- /dev/null
+++ b/sample/unary_numbers/GCM2023/FibSZ_31-reuse.in
@@ -0,0 +1,19 @@
+// Fibonacci number on unary natural numbers
+fib(r)><Z => r~(*R)Z;
+fib(r)><S(x) => (*L)fibS(r)~x;
+fibS(r)><Z => r~(*L)S((*R)Z);
+fibS(r)><S(x) => (*R)Dup(x1,x2)~x, (*L)add(r,r2)~r1, fib(r2)~x2, fibS(r1)~x1;
+
+
+//------ ADD ------
+add(r,x)><Z => r~x;
+add(r,x)><S(y) => r~(*R)S(w), (*L)add(w,x)~y;
+
+
+// Execution
+// Fib 31
+// 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+fib(r)~S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(S(Z)))))))))))))))))))))))))))))));
+prnat r;
+free r;
+