aboutsummaryrefslogtreecommitdiff
path: root/entries/funemy/z3
diff options
context:
space:
mode:
authorJames Yoo2022-10-24 23:47:51 +0000
committerJames Yoo2022-10-24 23:47:51 +0000
commit03315f012514bdcc5a4f654056f0103abe11eb83 (patch)
tree2b7c6e9233ecb503e7be0d8354483691f9a1e16c /entries/funemy/z3
parent0921d8222bb883ea86d51c7200a865a5e4dbc469 (diff)
parent7ed13a92711a35a9c263c1f53e33e308653ae727 (diff)
Merging local with remote main
Diffstat (limited to 'entries/funemy/z3')
-rwxr-xr-xentries/funemy/z3/z3fib.sh57
1 files changed, 57 insertions, 0 deletions
diff --git a/entries/funemy/z3/z3fib.sh b/entries/funemy/z3/z3fib.sh
new file mode 100755
index 0000000..07ab418
--- /dev/null
+++ b/entries/funemy/z3/z3fib.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+# Instructions:
+# 1. having z3 installed and put under your $PATH
+# 2. making sure z3fib.sh is executable, by `chmod +x z3fib.sh`
+# 3. running 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
+
+if [ "$1" -lt "0" ]; then
+ echo "Argument must be larger than 0."
+ exit 1
+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
+if [ "$1" -ge "1" ]; then
+ echo " (= x1 1)" >> fib.smt2
+fi
+
+if [ "$1" -ge "2" ]; then
+ for i in $(seq 2 $1);
+ do
+ echo " (= x$i (+ x$(($i - 2)) x$(($i - 1))))" >> fib.smt2
+ done
+fi
+
+echo " )" >> fib.smt2
+echo ")" >> fib.smt2
+
+echo "" >> fib.smt2
+
+echo "(check-sat)" >> fib.smt2
+echo "(get-model)" >> fib.smt2
+
+z3 fib.smt2