From 679ee8faf561b6e53f582edef2d93b65615bcea7 Mon Sep 17 00:00:00 2001 From: funemy Date: Sun, 23 Oct 2022 16:14:40 -0700 Subject: z3 fib impl --- entries/funemy/z3/z3fib.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 entries/funemy/z3/z3fib.sh (limited to 'entries/funemy/z3') diff --git a/entries/funemy/z3/z3fib.sh b/entries/funemy/z3/z3fib.sh new file mode 100755 index 0000000..fdc8937 --- /dev/null +++ b/entries/funemy/z3/z3fib.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# Instruction: +# 1. having z3 installed and under you $PATH +# 2. making sure z3fib.sh is executable, by `chmod +x z3fib.sh` +# 3. run as `./z3fib.sh [length of the fib sequence]` +# 4. having fun :) + +if [ -e fib.smt2 ] +then + rm -f fib.smt2 + touch fib.smt2 +else + touch fib.smt2 +fi + +for i in $(seq 0 $1); +do + echo "(declare-const x$i Int)" >> fib.smt2 +done + +echo "" >> fib.smt2 + +echo "(assert" >> fib.smt2 +echo " (and" >> fib.smt2 + +for i in $(seq 0 $1); +do + echo " (>= x$i 0)" >> fib.smt2 +done + +echo " (= x0 0)" >> fib.smt2 +echo " (= x1 1)" >> fib.smt2 + +for i in $(seq 2 $1); +do + echo " (= x$i (+ x$(($i - 2)) x$(($i - 1))))" >> fib.smt2 +done + +echo " )" >> fib.smt2 +echo ")" >> fib.smt2 + +echo "" >> fib.smt2 + +echo "(check-sat)" >> fib.smt2 +echo "(get-model)" >> fib.smt2 + +z3 fib.smt2 -- cgit v1.2.3-70-g09d2 From a89c7847195a7b20e307b042fbc821e741ccdaa4 Mon Sep 17 00:00:00 2001 From: funemy Date: Sun, 23 Oct 2022 16:16:41 -0700 Subject: minor --- entries/funemy/z3/z3fib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entries/funemy/z3') diff --git a/entries/funemy/z3/z3fib.sh b/entries/funemy/z3/z3fib.sh index fdc8937..9faa228 100755 --- a/entries/funemy/z3/z3fib.sh +++ b/entries/funemy/z3/z3fib.sh @@ -3,7 +3,7 @@ # Instruction: # 1. having z3 installed and under you $PATH # 2. making sure z3fib.sh is executable, by `chmod +x z3fib.sh` -# 3. run as `./z3fib.sh [length of the fib sequence]` +# 3. running as `./z3fib.sh [length of the fib sequence]` # 4. having fun :) if [ -e fib.smt2 ] -- cgit v1.2.3-70-g09d2