From 2f43aade2ed78389b32fd48598a2bf85ca9fdd9c Mon Sep 17 00:00:00 2001 From: funemy Date: Tue, 25 Oct 2022 02:13:02 -0700 Subject: a different z3 constraint encoding --- entries/funemy/z3/z4fib.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100755 entries/funemy/z3/z4fib.sh (limited to 'entries/funemy/z3/z4fib.sh') diff --git a/entries/funemy/z3/z4fib.sh b/entries/funemy/z3/z4fib.sh new file mode 100755 index 0000000..97ae59b --- /dev/null +++ b/entries/funemy/z3/z4fib.sh @@ -0,0 +1,40 @@ +#!/bin/bash +# z3 fib, but better + +# Instructions: +# 1. having z3 installed and put under your $PATH +# 2. making sure z4fib.sh is executable, by `chmod +x z3fib.sh` +# 3. running as `./z4fib.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 + +echo "(declare-const fib (Seq Int))" >> fib.smt2 +echo "" >> fib.smt2 +echo "(assert" >> fib.smt2 +echo " (and" >> fib.smt2 +echo " (= (seq.len fib) $1)" >> fib.smt2 +echo " (= (seq.nth fib 0) 0)" >> fib.smt2 +echo " (= (seq.nth fib 1) 1)" >> fib.smt2 +echo " (forall ((i Int))" >> fib.smt2 +echo " (=> (and (> i 1) (< i (seq.len fib)))" >> fib.smt2 +echo " (= (seq.nth fib i)" >> fib.smt2 +echo " (+ (seq.nth fib (- i 1))" >> fib.smt2 +echo " (seq.nth fib (- i 2))))))))" >> fib.smt2 + + +echo "(check-sat)" >> fib.smt2 +echo "(get-model)" >> fib.smt2 + +z3 fib.smt2 -- cgit v1.2.3-70-g09d2 From cf530ca49024dbdac4234c52a6838fb209ab6cb6 Mon Sep 17 00:00:00 2001 From: funemy Date: Tue, 25 Oct 2022 02:18:23 -0700 Subject: when i still have chance to format --- entries/funemy/z3/z4fib.sh | 1 + 1 file changed, 1 insertion(+) (limited to 'entries/funemy/z3/z4fib.sh') diff --git a/entries/funemy/z3/z4fib.sh b/entries/funemy/z3/z4fib.sh index 97ae59b..b7488e4 100755 --- a/entries/funemy/z3/z4fib.sh +++ b/entries/funemy/z3/z4fib.sh @@ -32,6 +32,7 @@ echo " (=> (and (> i 1) (< i (seq.len fib)))" >> fib.smt2 echo " (= (seq.nth fib i)" >> fib.smt2 echo " (+ (seq.nth fib (- i 1))" >> fib.smt2 echo " (seq.nth fib (- i 2))))))))" >> fib.smt2 +echo "" >> fib.smt2 echo "(check-sat)" >> fib.smt2 -- cgit v1.2.3-70-g09d2 From 1f35f0d22a4cd0bd837b26e8b019345532da89e6 Mon Sep 17 00:00:00 2001 From: funemy Date: Tue, 25 Oct 2022 02:21:15 -0700 Subject: minor --- entries/funemy/z3/z3fib.sh | 2 +- entries/funemy/z3/z4fib.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'entries/funemy/z3/z4fib.sh') diff --git a/entries/funemy/z3/z3fib.sh b/entries/funemy/z3/z3fib.sh index 07ab418..e96226f 100755 --- a/entries/funemy/z3/z3fib.sh +++ b/entries/funemy/z3/z3fib.sh @@ -15,7 +15,7 @@ else fi if [ "$1" -lt "0" ]; then - echo "Argument must be larger than 0." + echo "Argument must be larger or equal to 0." exit 1 fi diff --git a/entries/funemy/z3/z4fib.sh b/entries/funemy/z3/z4fib.sh index b7488e4..983a752 100755 --- a/entries/funemy/z3/z4fib.sh +++ b/entries/funemy/z3/z4fib.sh @@ -16,7 +16,7 @@ else fi if [ "$1" -lt "0" ]; then - echo "Argument must be larger than 0." + echo "Argument must be larger or equal to 0." exit 1 fi -- cgit v1.2.3-70-g09d2 From ae3c469407df59439fb0346344990c0155dcd7a2 Mon Sep 17 00:00:00 2001 From: funemy Date: Tue, 25 Oct 2022 02:23:05 -0700 Subject: redundant line --- entries/funemy/z3/z4fib.sh | 1 - 1 file changed, 1 deletion(-) (limited to 'entries/funemy/z3/z4fib.sh') diff --git a/entries/funemy/z3/z4fib.sh b/entries/funemy/z3/z4fib.sh index 983a752..d5ad2d9 100755 --- a/entries/funemy/z3/z4fib.sh +++ b/entries/funemy/z3/z4fib.sh @@ -34,7 +34,6 @@ echo " (+ (seq.nth fib (- i 1))" >> fib.smt2 echo " (seq.nth fib (- i 2))))))))" >> fib.smt2 echo "" >> fib.smt2 - echo "(check-sat)" >> fib.smt2 echo "(get-model)" >> fib.smt2 -- cgit v1.2.3-70-g09d2 From cdec98dc53617c3ad5c297f8f5d127013c111b6d Mon Sep 17 00:00:00 2001 From: funemy Date: Tue, 25 Oct 2022 12:54:05 -0700 Subject: typo --- entries/funemy/z3/z4fib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'entries/funemy/z3/z4fib.sh') diff --git a/entries/funemy/z3/z4fib.sh b/entries/funemy/z3/z4fib.sh index d5ad2d9..f7a1e48 100755 --- a/entries/funemy/z3/z4fib.sh +++ b/entries/funemy/z3/z4fib.sh @@ -3,7 +3,7 @@ # Instructions: # 1. having z3 installed and put under your $PATH -# 2. making sure z4fib.sh is executable, by `chmod +x z3fib.sh` +# 2. making sure z4fib.sh is executable, by `chmod +x z4fib.sh` # 3. running as `./z4fib.sh [length of the fib sequence]` # 4. having fun :) -- cgit v1.2.3-70-g09d2