From 1da50bc82da34870f8449c48e1df4567b777a79c Mon Sep 17 00:00:00 2001 From: Mauro Toscano <12560266+MauroToscano@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:23:27 -0300 Subject: [PATCH] Looped fibonacci (#567) * Rust cache on check * Fibo looped * Delete CI upgrade that belongs to another pr --- .../cairo0/fibonacci_5_loop.cairo | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 provers/cairo/cairo_programs/cairo0/fibonacci_5_loop.cairo diff --git a/provers/cairo/cairo_programs/cairo0/fibonacci_5_loop.cairo b/provers/cairo/cairo_programs/cairo0/fibonacci_5_loop.cairo new file mode 100644 index 000000000..328b2085c --- /dev/null +++ b/provers/cairo/cairo_programs/cairo0/fibonacci_5_loop.cairo @@ -0,0 +1,21 @@ + +// Looped fibonacci is more efficient +// than calling the fibo function with recursion +// For n = 5, it's 31 steps vs 49 steps +// This is useful to compare with other vms that are not validating the call stack for fibonacci + +func main{}() { + tempvar x0 = 0; + tempvar x1 = 1; + tempvar fib_acc = x0 + x1; + tempvar n = 5; + loop: + tempvar x0 = x1; + tempvar x1 = fib_acc; + tempvar fib_acc = x0 + x1; + tempvar n = n - 1; + jmp loop if n != 0; + + assert fib_acc = 13; + return (); +}