diff options
author | Braxton Hall | 2022-10-25 20:02:35 +0000 |
---|---|---|
committer | GitHub | 2022-10-25 20:02:35 +0000 |
commit | d57abc9cefad29bd3977fc513ef6948f021dd558 (patch) | |
tree | b37c9548a59a6167fe9ba7c46230734f812fec5d /entries | |
parent | 5ff019bc3205def15e1ee73cd9c60e4c69509750 (diff) | |
parent | cdec98dc53617c3ad5c297f8f5d127013c111b6d (diff) |
Merge pull request #42 from funemy/main
z3 but cooler
Diffstat (limited to 'entries')
-rwxr-xr-x | entries/funemy/z3/z3fib.sh | 2 | ||||
-rwxr-xr-x | entries/funemy/z3/z4fib.sh | 40 |
2 files changed, 41 insertions, 1 deletions
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 new file mode 100755 index 0000000..f7a1e48 --- /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 z4fib.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 or equal to 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 "" >> fib.smt2 + +echo "(check-sat)" >> fib.smt2 +echo "(get-model)" >> fib.smt2 + +z3 fib.smt2 |