├── .gitignore ├── .header ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── Makefile ├── README.md ├── dune-project ├── examples ├── acyclic.lisp ├── acyclic.smt2 ├── append.lisp ├── append.smt2 ├── asserting1.smt2 ├── benchpress.sexp ├── bugs │ └── mu_terms3.nunchaku.smbc.smt2 ├── data1.smt2 ├── data2.smt2 ├── de_morgan1.lisp ├── de_morgan1.smt2 ├── de_morgan2.lisp ├── de_morgan2.smt2 ├── fact.lisp ├── fact.smt2 ├── fact2.lisp ├── fact2.smt2 ├── fold0.smt2 ├── fold1.smt2 ├── ho_bool1.smt2 ├── incompatible_len.lisp ├── incompatible_len.smt2 ├── ind_pred.nunchaku.smbc.smt2 ├── list.lisp ├── list_head_nat.smt2 ├── list_sum.lisp ├── list_sum.smt2 ├── logic.lisp ├── long_rev.lisp ├── long_rev_sum.lisp ├── long_rev_sum2.lisp ├── long_rev_sum2.smt2 ├── long_rev_sum3.lisp ├── long_rev_sum3.smt2 ├── long_rev_sum4.lisp ├── long_rev_sum4.smt2 ├── long_rev_sum5.lisp ├── long_rev_sum5.smt2 ├── long_rev_sum6.lisp ├── long_rev_sum6.smt2 ├── map_fun.lisp ├── map_fun.smt2 ├── map_fun2.lisp ├── map_fun2.smt2 ├── map_fun3.lisp ├── map_fun3.smt2 ├── nat.lisp ├── pigeon4.smt2 ├── quant_fact_leq_100.smt2 ├── quant_fact_leq_10000.smt2 ├── quant_list1.smt2 ├── quant_nat_zero_or_lt.smt2 ├── regex │ ├── regex_0.smt2 │ ├── regex_1.smt2 │ ├── regex_10.smt2 │ ├── regex_11.smt2 │ ├── regex_2.smt2 │ ├── regex_3.smt2 │ ├── regex_4.smt2 │ ├── regex_5.smt2 │ ├── regex_6.smt2 │ ├── regex_7.smt2 │ ├── regex_8.smt2 │ └── regex_9.smt2 ├── regression │ ├── bad_model.smt2 │ ├── bad_model2.smt2 │ ├── bad_model3.smt2 │ ├── bug1.smt2 │ ├── bug2.smt2 │ ├── bug3.smt2 │ ├── bug4.smt2 │ ├── bug5.smt2 │ ├── bug5_simple.smt2 │ ├── card_constraints.smt2 │ ├── card_constraints2.smt2 │ ├── first_order.nunchaku.smbc.smt2 │ ├── ho_sko.smt2 │ └── list_head.nunchaku.smbc.smt2 ├── rev.lisp ├── rev.smt2 ├── sat_solver1.smt2 ├── slow_hotel.nunchaku.smbc.smt2 ├── sorted.lisp ├── sorted.smt2 ├── sorted2.lisp ├── sorted2.smt2 ├── sorted3.lisp ├── sorted3.smt2 ├── sorted4.lisp ├── sorted4.smt2 ├── sudoku.smt2 ├── sum_len.lisp ├── ty_infer.lisp ├── ty_infer.smt2 ├── ty_infer2.lisp ├── ty_infer2.smt2 ├── ty_infer2_unin.lisp ├── ty_infer2_unin.smt2 ├── ty_infer_nat.lisp ├── ty_infer_nat.smt2 ├── ty_infer_nat2.lisp ├── ty_infer_nat2.smt2 ├── ty_infer_unin.lisp ├── ty_infer_unin.smt2 ├── uf5.smt2 ├── unin1.lisp └── unin1.smt2 ├── smbc ├── smbc.opam ├── src ├── Ast.ml ├── Ast.mli ├── Common_.ml ├── Hash.ml ├── Hash.mli ├── Hashcons.ml ├── ID.ml ├── ID.mli ├── Intf.ml ├── Log.ml ├── Log.mli ├── Model.ml ├── Model.mli ├── Parse_ast.ml ├── Poly_set.ml ├── Poly_set.mli ├── Solver.ml ├── Solver.mli ├── Util.ml ├── Util.mli ├── dune └── smbc.ml └── utils ├── conv_lisp.ml ├── lsc.sh └── profile.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | .*.swo 3 | _build 4 | *.native 5 | *.byte 6 | .session 7 | TAGS 8 | *.docdir 9 | setup.* 10 | qtest* 11 | *.html 12 | .merlin 13 | *.install 14 | jbuild 15 | -------------------------------------------------------------------------------- /.header: -------------------------------------------------------------------------------- 1 | (* This file is free software. See file "license" for more details. *) 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | install: wget https://raw.githubusercontent.com/ocaml/ocaml-ci-scripts/master/.travis-docker.sh 3 | script: bash -ex .travis-docker.sh 4 | services: 5 | - docker 6 | env: 7 | global: 8 | - PINS="smbc:." 9 | - DISTRO="ubuntu-16.04" 10 | matrix: 11 | #- PACKAGE="logitest" OCAML_VERSION="4.02" 12 | - PACKAGE="smbc" OCAML_VERSION="4.03" 13 | - PACKAGE="smbc" OCAML_VERSION="4.08" 14 | - PACKAGE="smbc" OCAML_VERSION="4.10" 15 | 16 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## 0.6.1 4 | 5 | - fixes: format error, compat with containers 2.7 6 | 7 | ## 0.6 8 | 9 | - upgrade to msat 0.8 10 | - upgrade to tip-parser 0.6 11 | - remove some dead code 12 | - make tests faster (timeout=10) 13 | - use release mode 14 | 15 | ## 0.5 16 | 17 | - fix(model): add a constant to unin types with empty domains 18 | - adapt to tip-parser 0.5 19 | - handle new `Stmt_prove` from TIP 20 | - cleaner display of result in presence of progress bar 21 | - add `default` case in match (makes smaller terms) 22 | - display `theorem/countersat` if the goal is a `prove` goal 23 | 24 | - refactor a bit AST 25 | - add travis support 26 | - modernize metatada: opam2 and dune 27 | 28 | ## 0.4.2 29 | 30 | - support containers 2.0 31 | - move to jbuilder 32 | - small optims 33 | - add option `--eval-under-quant` 34 | - more stats 35 | 36 | ## 0.4.1 37 | 38 | - bugfix related to De Bruijn indices and function extensionality 39 | 40 | ## 0.4 41 | 42 | - quantification on datatypes/bool 43 | 44 | - remove limited checking of models 45 | - some bugfixes and regression tests 46 | 47 | ## 0.3.1 48 | 49 | - compatibility with containers 1.0 50 | 51 | ## 0.3 52 | 53 | - add flag `--check-proof` for checking SAT solver proofs 54 | - remove parser for custom format; only keep TIP; remove .lisp from tests 55 | - less accurate detection of incomplete expansions (without unsat-cores) 56 | - bugfixes in uninterpreted types 57 | - detect some evaluation loops with a `term_being_evaled` field 58 | - internal notion of `undefined` for `asserting`, loops, and selectors 59 | - simple prefix skolemization for `assert` axioms 60 | - add `asserting` construct 61 | - delay a bit combinatorial explosion for HO functions 62 | - support for HO unknowns 63 | - allow quantification over booleans, translated as conjunction/disjunction 64 | - better error message for HO metas 65 | - add support for selectors 66 | 67 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Simon Cruanes 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. Redistributions in binary 9 | form must reproduce the above copyright notice, this list of conditions and 10 | the following disclaimer in the documentation and/or other materials 11 | provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | J?=3 3 | OPTS ?= --profile=release 4 | all: build 5 | 6 | build: 7 | @dune build @install -j $J $(OPTS) 8 | 9 | install: 10 | @dune install 11 | 12 | clean: 13 | @dune clean 14 | 15 | TESTOPTS ?= -j 3 16 | TESTTOOL=benchpress 17 | 18 | test: build 19 | $(TESTTOOL) run -c examples/benchpress.sexp $(TESTOPTS) \ 20 | -t 30 --meta `git rev-parse HEAD` --progress -p smbc examples/ 21 | 22 | WATCH ?= @all 23 | watch: 24 | @dune build $(WATCH) $(OPTS) -w 25 | 26 | .PHONY: watch benchs clean build test 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SMBC 2 | 3 | 4 | [![build status](https://travis-ci.org/c-cube/smbc.svg?branch=master "build status")](https://travis-ci.org/c-cube/smbc) 5 | 6 | Experimental model finder/SMT solver for functional programming. 7 | 8 | The underlying algorithm is described in [a 2016 paper](https://hal.inria.fr/hal-01572531). 9 | 10 | The code is under the BSD license. 11 | 12 | ## Use 13 | 14 | - run on a problem (timeout 30s) 15 | 16 | ``` 17 | smbc examples/regex_2.smt2 -t 30 18 | ``` 19 | 20 | - get a list of options: 21 | 22 | ``` 23 | smbc --help 24 | ``` 25 | 26 | - verbose mode: 27 | 28 | ``` 29 | smbc examples/regex_0.smt2 --debug 2 30 | ``` 31 | 32 | - specify depth/depth-step: 33 | 34 | ``` 35 | smbc examples/regex_0.smt2 --depth-step 3 --max-depth 200 36 | ``` 37 | 38 | ## Build 39 | 40 | The recommended way is to use [opam](http://opam.ocaml.org/) 41 | 42 | ```sh 43 | opam pin 'https://github.com/c-cube/smbc.git#master' 44 | opam install smbc 45 | ``` 46 | 47 | Or manually, using 48 | 49 | ```sh 50 | opam install msat containers iter tip-parser 51 | make 52 | ``` 53 | 54 | ## A Few Examples 55 | 56 | We show a few example input files for smbc, along with the result. 57 | 58 | ### examples/append.smt2 59 | 60 | A wrong conjecture stating that `append l1 l2 = append l2 l1` 61 | holds for every lists `l1` and `l2`. 62 | 63 | ```smt2 64 | (declare-datatypes () 65 | ((nat (s (select_s_0 nat)) (z)))) 66 | (declare-datatypes 67 | () 68 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 69 | (nil)))) 70 | (define-funs-rec 71 | ((append ((x list) (y list)) list)) 72 | ((match x (case (cons n tail) (cons n (append tail y))) 73 | (case nil y)))) 74 | (assert-not 75 | (forall ((l1 list) (l2 list)) (= (append l1 l2) (append l2 l1)))) 76 | 77 | (check-sat) 78 | ``` 79 | 80 | Running smbc gives us a counter-example, the lists `l1 = [s _]` and `l2 = [0]`. 81 | Note that `l1` is not fully defined, the `?nat_8` object is an unknown 82 | that can take any value of type `nat`. Whatever its value is, 83 | the counter-example holds because `append l1 l2 != append l2 l1`. 84 | 85 | ``` 86 | $ smbc examples/append.smt2 87 | (result SAT :model ((val l2 (cons z nil)) 88 | (val l1 (cons (s ?nat_8) nil)))) 89 | ``` 90 | 91 | ### examples/pigeon4.smt2 92 | 93 | An instance of the classic 94 | [pigeon-hole problem](https://en.wikipedia.org/wiki/Pigeonhole_principle) 95 | with 4 holes and 5 pigeons 96 | 97 | ```smt2 98 | (declare-sort hole 0) 99 | (declare-fun h1 () hole) 100 | (declare-fun h2 () hole) 101 | (declare-fun h3 () hole) 102 | (declare-fun h4 () hole) 103 | (declare-fun p1 () hole) 104 | (declare-fun p2 () hole) 105 | (declare-fun p3 () hole) 106 | (declare-fun p4 () hole) 107 | (declare-fun p5 () hole) 108 | (assert 109 | (and 110 | (not (= h1 h2)) (not (= h1 h3)) (not (= h1 h4)) 111 | (not (= h2 h3)) (not (= h2 h4)) (not (= h3 h4)))) 112 | (assert 113 | (and 114 | (not (= p1 p2)) (not (= p1 p3)) (not (= p1 p4)) 115 | (not (= p1 p5)) 116 | (not (= p2 p3)) 117 | (not (= p2 p4)) 118 | (not (= p2 p5)) 119 | (not (= p3 p4)) 120 | (not (= p3 p5)) 121 | (not (= p4 p5)))) 122 | (assert 123 | (forall ((p hole)) (or (= p h1) (= p h2) (= p h3) (= p h4)))) 124 | (check-sat) 125 | ``` 126 | 127 | We obtain `(result UNSAT)` since there is no way of satisfying 128 | the constraints. 129 | 130 | ## Why the name? 131 | 132 | "Sat Modulo Bounded Checking" 133 | 134 | (and a reference to [the awesome webcomics](http://smbc-comics.com)) 135 | 136 | 137 | ## Note: Memory Profiling 138 | 139 | ```sh 140 | opam sw 4.04.0+spacetime 141 | make 142 | OCAML_SPACETIME_INTERVAL=100 ./smbc.native --debug 1 --check examples/ty_infer.lisp 143 | prof_spacetime serve spacetime- -e smbc.native 144 | ``` 145 | -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 1.0) 2 | -------------------------------------------------------------------------------- /examples/acyclic.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; `n = n+2` 3 | ; expect: UNSAT 4 | 5 | (include "nat.lisp") 6 | 7 | (goal 8 | ((n nat)) 9 | (= n (s (s n)))) 10 | -------------------------------------------------------------------------------- /examples/acyclic.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; `n = n+2` 3 | ; expect: UNSAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (assert-not (forall ((n nat)) (not (= n (s (s n)))))) 22 | (check-sat) 23 | -------------------------------------------------------------------------------- /examples/append.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | (data (nat z (s nat))) 5 | 6 | (data (list nil (cons nat list))) 7 | 8 | (define 9 | (append 10 | (-> list list list) 11 | (fun (x list) 12 | (fun (y list) 13 | (match 14 | x 15 | (nil y) 16 | ((cons n tail) (cons n (append tail y)))))))) 17 | 18 | (goal ((l1 list) (l2 list)) (not (= (append l1 l2) (append l2 l1)))) 19 | -------------------------------------------------------------------------------- /examples/append.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | (declare-datatypes () ((nat (s (select_s_0 nat)) 5 | (z)))) 6 | (declare-datatypes 7 | () 8 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 9 | (nil)))) 10 | (define-funs-rec 11 | ((append ((x list) (y list)) list)) 12 | ((match x (case (cons n tail) (cons n (append tail y))) 13 | (case nil y)))) 14 | (assert-not 15 | (forall ((l1 list) (l2 list)) (= (append l1 l2) (append l2 l1)))) 16 | (check-sat) 17 | -------------------------------------------------------------------------------- /examples/asserting1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: sat 3 | 4 | ; a simple problem to test "asserting". 5 | ; we look for a list where "head (tail (tail (tail l))) = A" 6 | ; with safe versions of those 7 | 8 | (declare-datatypes () ((ab (A)(B)))) 9 | (declare-datatypes () ((List (Cons (_hd ab)(_tail List)) (Nil)))) 10 | 11 | ; safe head and tail 12 | 13 | (define-fun head ((l List)) ab 14 | (asserting (_hd l) (not (= l Nil)))) 15 | (define-fun tail ((l List)) List 16 | (asserting (_tail l) (not (= l Nil)))) 17 | 18 | (assert-not 19 | (forall ((l List)) 20 | (not (= (head (tail (tail (tail l)))) A)))) 21 | -------------------------------------------------------------------------------- /examples/benchpress.sexp: -------------------------------------------------------------------------------- 1 | 2 | (prover 3 | (name smbc) 4 | (cmd "ulimit -t $timeout; $cur_dir/../smbc --timeout $timeout $file") 5 | (unsat "^UNSAT") 6 | (sat "^SAT") 7 | (unknown "UNKNOWN") 8 | (timeout "TIMEOUT")) 9 | 10 | (dir 11 | (path $cur_dir/) 12 | (pattern ".*.smt2") 13 | (expect (const unknown))) 14 | -------------------------------------------------------------------------------- /examples/bugs/mu_terms3.nunchaku.smbc.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; actual status is SAT, but here we have a non-terminating computation 3 | ; expect: ERROR 4 | 5 | ; generated by nunchaku 6 | (declare-datatypes () ((a (Zero) 7 | (One)))) 8 | (declare-sort tree 0) 9 | (declare-fun Node (a tree tree) tree) 10 | (declare-fun is_Node (tree) Bool) 11 | (declare-fun select_Node_0 (tree) a) 12 | (declare-fun select_Node_1 (tree) tree) 13 | (declare-fun select_Node_2 (tree) tree) 14 | (declare-datatypes () ((_nat (_zero) 15 | (_succ (select-_succ-0 _nat))))) 16 | (declare-fun decr_eq_corec_tree () _nat) 17 | (define-fun-rec 18 | eq_corec_tree ((v_0 _nat) (v_1 tree) (v_2 tree)) Bool 19 | (or 20 | (match v_0 (case _zero true) 21 | (case default false)) 22 | (match v_0 23 | (case (_succ x_0) 24 | (and 25 | (is_Node v_1) 26 | (is_Node v_2) 27 | (= (select_Node_0 v_1) (select_Node_0 v_2)) 28 | (eq_corec_tree x_0 (select_Node_1 v_1) (select_Node_1 v_2)) 29 | (eq_corec_tree x_0 (select_Node_2 v_1) (select_Node_2 v_2)))) 30 | (case default false)))) 31 | (assert 32 | (forall 33 | ((x tree)) 34 | (forall ((y tree)) (=> (eq_corec_tree decr_eq_corec_tree x y) (= x y))))) 35 | (assert (forall ((v_tree tree)) (is_Node v_tree))) 36 | (assert true) 37 | (assert 38 | (forall 39 | ((x_1 tree)) 40 | (forall 41 | ((y_0 tree)) 42 | (=> 43 | (and 44 | (is_Node x_1) 45 | (is_Node y_0) 46 | (= (select_Node_0 x_1) (select_Node_0 y_0)) 47 | (= (select_Node_1 x_1) (select_Node_1 y_0)) 48 | (= (select_Node_2 x_1) (select_Node_2 y_0))) 49 | (= x_1 y_0))))) 50 | (declare-fun all0 () tree) 51 | (define-fun-rec 52 | cnst ((x_2 a)) tree 53 | (let ((#tree_0 (Node x_2 (cnst x_2) (cnst x_2)))) 54 | (asserting #tree_0 55 | (and 56 | (= (cnst x_2) (select_Node_1 #tree_0)) 57 | (= x_2 (select_Node_0 #tree_0)) 58 | (is_Node #tree_0) 59 | (= (cnst x_2) (select_Node_2 #tree_0)))))) 60 | (assert (= all0 (cnst Zero))) 61 | (declare-fun all1 () tree) 62 | (assert (= all1 (cnst One))) 63 | (declare-fun swap (a) a) 64 | (assert (= (swap Zero) One)) 65 | (assert (= (swap One) Zero)) 66 | (declare-fun alt01 () tree) 67 | (define-fun-rec 68 | alt ((x_3 a)) tree 69 | (let ((#tree_0_0 (Node x_3 (alt (swap x_3)) (alt (swap x_3))))) 70 | (asserting #tree_0_0 71 | (and 72 | (= (alt (swap x_3)) (select_Node_1 #tree_0_0)) 73 | (= x_3 (select_Node_0 #tree_0_0)) 74 | (is_Node #tree_0_0) 75 | (= (alt (swap x_3)) (select_Node_2 #tree_0_0)))))) 76 | (assert (= alt01 (alt Zero))) 77 | (declare-fun alt10 () tree) 78 | (assert (= alt10 (alt One))) 79 | (declare-fun odd2 () tree) 80 | (declare-fun odd3 () tree) 81 | (declare-fun odd1 () tree) 82 | (assert 83 | (let ((#tree_0_1 (Node Zero odd2 odd3))) 84 | (asserting (= odd1 #tree_0_1) 85 | (and 86 | (= odd3 (select_Node_2 #tree_0_1)) 87 | (= Zero (select_Node_0 #tree_0_1)) 88 | (is_Node #tree_0_1) 89 | (= odd2 (select_Node_1 #tree_0_1)))))) 90 | (assert 91 | (let ((#tree_0_2 (Node One odd1 odd1))) 92 | (let ((#tree_1 (Node One odd2 odd3))) 93 | (let ((#tree_2 (Node One #tree_0_2 #tree_1))) 94 | (asserting (= odd2 #tree_2) 95 | (and 96 | (= odd3 (select_Node_2 #tree_1)) 97 | (= odd1 (select_Node_2 #tree_0_2)) 98 | (= One (select_Node_0 #tree_2)) 99 | (= One (select_Node_0 #tree_1)) 100 | (= One (select_Node_0 #tree_0_2)) 101 | (is_Node #tree_2) 102 | (is_Node #tree_1) 103 | (is_Node #tree_0_2) 104 | (= odd2 (select_Node_1 #tree_1)) 105 | (= #tree_1 (select_Node_2 #tree_2)) 106 | (= #tree_0_2 (select_Node_1 #tree_2)) 107 | (= odd1 (select_Node_1 #tree_0_2)))))))) 108 | (assert 109 | (let ((#tree_0_3 (Node Zero odd1 odd3))) 110 | (let ((#tree_1_0 (Node Zero odd2 #tree_0_3))) 111 | (asserting (= odd3 #tree_1_0) 112 | (and 113 | (= odd3 (select_Node_2 #tree_0_3)) 114 | (= Zero (select_Node_0 #tree_1_0)) 115 | (= Zero (select_Node_0 #tree_0_3)) 116 | (is_Node #tree_1_0) 117 | (is_Node #tree_0_3) 118 | (= odd2 (select_Node_1 #tree_1_0)) 119 | (= #tree_0_3 (select_Node_2 #tree_1_0)) 120 | (= odd1 (select_Node_1 #tree_0_3))))))) 121 | (assert-not false) 122 | (check-sat) 123 | 124 | -------------------------------------------------------------------------------- /examples/data1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | (declare-datatypes () ((Direction (North)(South)(East)(West)))) 5 | (declare-datatypes () ((Nat (Zero) (Succ (Prec Nat))))) 6 | (declare-datatypes () ((List (Nil) (Cons (Head Nat)(Tail List))))) 7 | 8 | (declare-fun some_dir () Direction) 9 | 10 | ;(define-fun-rec (Plus ((a Nat) (b Nat)) Nat 11 | ; (match a 12 | ; (case Zero b) 13 | ; (case (Succ a2) (Succ (Plus a2 b)))))) 14 | 15 | (assert-not 16 | (forall ((d Direction)(a Nat)(b Nat)) 17 | (or 18 | (not (= d North)) 19 | (= (Cons a (Cons b Nil)) (Cons b (Cons a Nil)))))) 20 | -------------------------------------------------------------------------------- /examples/data2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | (declare-datatypes () ((Nat (Zero) (Succ (Prec Nat))))) 5 | (declare-datatypes () ((List (Nil) (Cons (Head Nat)(Tail List))))) 6 | 7 | (define-fun-rec eq-nat ((a Nat) (b Nat)) Bool 8 | (match a 9 | (case Zero 10 | (match b 11 | (case Zero true) 12 | (case (Succ b2) false))) 13 | (case (Succ a2) 14 | (match b 15 | (case Zero false) 16 | (case (Succ b2) (eq-nat a2 b2)))))) 17 | 18 | (define-fun-rec eq-list ((a List) (b List)) Bool 19 | (match a 20 | (case Nil 21 | (match b 22 | (case Nil true) 23 | (case (Cons b2 b3) false))) 24 | (case (Cons a2 a3) 25 | (match b 26 | (case Nil false) 27 | (case (Cons b2 b3) (and (eq-nat a2 b2) (eq-list a3 b3))))))) 28 | 29 | (assert-not 30 | (forall ((a Nat)(b Nat)) 31 | (eq-list (Cons a (Cons b Nil)) (Cons b (Cons a Nil))))) 32 | -------------------------------------------------------------------------------- /examples/de_morgan1.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; expect: UNSAT 3 | 4 | ; try some formulas 5 | 6 | (include "logic.lisp") 7 | 8 | ; (not (a & (b | c))) | (not c & not d) 9 | (define 10 | (f1 form 11 | (| 12 | (~(& (at a) (| (at b) (at c)))) 13 | (& (~ (at c)) (~ (at d)))))) 14 | 15 | ; ((not a | not b) & (not a | not c)) | (not (c | d)) 16 | (define 17 | (f2 form 18 | (| 19 | (& 20 | (| (~ (at a)) (~ (at b))) 21 | (| (~ (at a)) (~ (at c)))) 22 | (~ (| (at c) (at d)))))) 23 | 24 | (define 25 | (v1 26 | (-> atom prop) 27 | (fun (x atom) 28 | (match x 29 | (a true) 30 | (b false) 31 | (c true) 32 | (d false))))) 33 | 34 | (goal () 35 | (not 36 | (= (eval v1 f1) (eval v1 f2)))) 37 | 38 | -------------------------------------------------------------------------------- /examples/de_morgan1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: UNSAT 3 | 4 | ; try some formulas 5 | 6 | (declare-datatypes () 7 | ((atom (d) 8 | (c) 9 | (b) 10 | (a)))) 11 | (declare-datatypes 12 | () 13 | ((form 14 | (~ (select_~_0 form)) 15 | (or_ (select_or_0 form) (select_or_1 form)) 16 | (& (select_&_0 form) (select_&_1 form)) 17 | (at (select_at_0 atom))))) 18 | (define-funs-rec 19 | ((eval ((v (=> atom Bool)) (e form)) Bool)) 20 | ((match e 21 | (case (~ a_1) (not (eval v a_1))) 22 | (case (or_ a_2 b_1) (or (eval v a_2) (eval v b_1))) 23 | (case (& a_3 b_2) (and (eval v a_3) (eval v b_2))) 24 | (case (at a_4) (v a_4))))) 25 | ; (not (a & (b | c))) | (not c & not d) 26 | (define-funs-rec 27 | ((f1 () form)) 28 | ((or_ (~ (& (at a) (or_ (at b) (at c)))) (& (~ (at c)) (~ (at d)))))) 29 | ; ((not a | not b) & (not a | not c)) | (not (c | d)) 30 | (define-funs-rec 31 | ((f2 () form)) 32 | ((or_ (& (or_ (~ (at a)) (~ (at b))) (or_ (~ (at a)) (~ (at c)))) 33 | (~ (or_ (at c) (at d)))))) 34 | ; valuation 35 | (define-funs-rec 36 | ((v1 ((x atom)) Bool)) 37 | ((match x (case d false) 38 | (case c true) 39 | (case b false) 40 | (case a true)))) 41 | (assert-not (= (eval v1 f1) (eval v1 f2))) 42 | (check-sat) 43 | -------------------------------------------------------------------------------- /examples/de_morgan2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; find a formula equivalent to f1 with 3 valuations 5 | 6 | (include "logic.lisp") 7 | 8 | ; (not (a & (b | c))) | (not c & not d) 9 | (define 10 | (f1 form 11 | (| 12 | (~(& (at a) (| (at b) (at c)))) 13 | (& (~ (at c)) (~ (at d)))))) 14 | 15 | (define 16 | (v1 17 | (-> atom prop) 18 | (fun (x atom) 19 | (match x 20 | (a true) 21 | (b false) 22 | (c true) 23 | (d false))))) 24 | 25 | (define 26 | (v2 27 | (-> atom prop) 28 | (fun (x atom) 29 | (match x 30 | (a false) 31 | (b false) 32 | (c false) 33 | (d true))))) 34 | 35 | (define 36 | (v3 37 | (-> atom prop) 38 | (fun (x atom) 39 | (match x 40 | (a false) 41 | (b true) 42 | (c true) 43 | (d false))))) 44 | 45 | (goal 46 | ((f2 form)) 47 | (and 48 | (= (eval v1 f1) (eval v1 f2)) 49 | (= (eval v2 f1) (eval v2 f2)) 50 | (= (eval v3 f1) (eval v3 f2)))) 51 | 52 | 53 | -------------------------------------------------------------------------------- /examples/de_morgan2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; find a formula equivalent to f1 with 3 valuations 5 | (declare-datatypes () ((atom_1 (d_1) 6 | (c_1) 7 | (b_3) 8 | (a_5)))) 9 | (declare-datatypes 10 | () 11 | ((form_1 12 | (~_1 (select_~_1_0 form_1)) 13 | (or__1 (select_or_1_0 form_1) (select_or_1_1 form_1)) 14 | (&_1 (select_&_1_0 form_1) (select_&_1_1 form_1)) 15 | (at_1 (select_at_1_0 atom_1))))) 16 | (define-funs-rec 17 | ((eval_1 ((v_1 (=> atom_1 Bool)) (e_1 form_1)) Bool)) 18 | ((match e_1 19 | (case (~_1 a_6) (not (eval_1 v_1 a_6))) 20 | (case (or__1 a_7 b_4) (or (eval_1 v_1 a_7) (eval_1 v_1 b_4))) 21 | (case (&_1 a_8 b_5) (and (eval_1 v_1 a_8) (eval_1 v_1 b_5))) 22 | (case (at_1 a_9) (v_1 a_9))))) 23 | ; (not (a & (b | c))) | (not c & not d) 24 | (define-funs-rec 25 | ((f1_1 () form_1)) 26 | ((or__1 (~_1 (&_1 (at_1 a_5) (or__1 (at_1 b_3) (at_1 c_1)))) 27 | (&_1 (~_1 (at_1 c_1)) (~_1 (at_1 d_1)))))) 28 | (define-funs-rec 29 | ((v1_1 ((x_1 atom_1)) Bool)) 30 | ((match x_1 31 | (case d_1 false) 32 | (case c_1 true) 33 | (case b_3 false) 34 | (case a_5 true)))) 35 | (define-funs-rec 36 | ((v2 ((x_2 atom_1)) Bool)) 37 | ((match x_2 38 | (case d_1 true) 39 | (case c_1 false) 40 | (case b_3 false) 41 | (case a_5 false)))) 42 | (define-funs-rec 43 | ((v3 ((x_3 atom_1)) Bool)) 44 | ((match x_3 45 | (case d_1 false) 46 | (case c_1 true) 47 | (case b_3 true) 48 | (case a_5 false)))) 49 | (assert-not 50 | (forall 51 | ((f2_1 form_1)) 52 | (not (and 53 | (and 54 | (= (eval_1 v1_1 f1_1) (eval_1 v1_1 f2_1)) 55 | (= (eval_1 v2 f1_1) (eval_1 v2 f2_1))) 56 | (= (eval_1 v3 f1_1) (eval_1 v3 f2_1)))))) 57 | (check-sat) 58 | -------------------------------------------------------------------------------- /examples/fact.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find `n` where `n! >= 100` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (define 8 | (fact 9 | (-> nat nat) 10 | (fun (n nat) 11 | (match n 12 | (z (s z)) 13 | ((s n2) 14 | (mult n 15 | (fact n2))))))) 16 | 17 | (define (5 nat (s (s (s (s (s z))))))) 18 | (define (10 nat (mult (s (s z)) 5))) 19 | (define (100 nat (mult 10 10))) 20 | 21 | (goal 22 | ((n nat)) 23 | (leq 100 (fact n))) 24 | 25 | -------------------------------------------------------------------------------- /examples/fact.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find `n` where `n! >= 100 * 100` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat_1 (s_1 (select_s_1_0 nat_1)) 6 | (z_1)))) 7 | (define-funs-rec 8 | ((plus_1 ((x_3 nat_1) (y_3 nat_1)) nat_1)) 9 | ((match x_3 (case (s_1 x2_3) (s_1 (plus_1 x2_3 y_3))) 10 | (case z_1 y_3)))) 11 | (define-funs-rec 12 | ((mult_1 ((x_4 nat_1) (y_4 nat_1)) nat_1)) 13 | ((match x_4 14 | (case (s_1 x2_4) (plus_1 y_4 (mult_1 x2_4 y_4))) 15 | (case z_1 z_1)))) 16 | (define-funs-rec 17 | ((leq_1 ((x_5 nat_1) (y_5 nat_1)) Bool)) 18 | ((match x_5 19 | (case (s_1 x2_5) 20 | (match y_5 (case (s_1 y2_1) (leq_1 x2_5 y2_1)) 21 | (case z_1 false))) 22 | (case z_1 true)))) 23 | (define-funs-rec 24 | ((fact_1 ((n_2 nat_1)) nat_1)) 25 | ((match n_2 26 | (case (s_1 n2_1) (mult_1 n_2 (fact_1 n2_1))) 27 | (case z_1 (s_1 z_1))))) 28 | (define-funs-rec ((num_5_1 () nat_1)) ((s_1 (s_1 (s_1 (s_1 (s_1 z_1))))))) 29 | (define-funs-rec ((num_10_1 () nat_1)) ((mult_1 (s_1 (s_1 z_1)) num_5_1))) 30 | (define-funs-rec ((num_100_1 () nat_1)) ((mult_1 num_10_1 num_10_1))) 31 | (assert-not (forall ((n_3 nat_1)) (not (leq_1 num_100_1 (fact_1 n_3)))))(check-sat) 32 | -------------------------------------------------------------------------------- /examples/fact2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find `n` where `n! >= 100 * 100` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (define 8 | (fact 9 | (-> nat nat) 10 | (fun (n nat) 11 | (match n 12 | (z (s z)) 13 | ((s n2) 14 | (mult n 15 | (fact n2))))))) 16 | 17 | (define (5 nat (s (s (s (s (s z))))))) 18 | (define (10 nat (mult (s (s z)) 5))) 19 | (define (100 nat (mult 10 10))) 20 | 21 | (goal 22 | ((n nat)) 23 | (leq (mult 100 100) (fact n))) 24 | 25 | -------------------------------------------------------------------------------- /examples/fact2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find `n` where `n! >= 100` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (define-funs-rec 22 | ((fact ((n nat)) nat)) 23 | ((match n (case (s n2) (mult n (fact n2))) 24 | (case z (s z))))) 25 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 26 | (define-funs-rec ((num_10 () nat)) ((mult (s (s z)) num_5))) 27 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 28 | (assert-not 29 | (forall ((n_1 nat)) (not (leq (mult num_100 num_100) (fact n_1)))))(check-sat) 30 | -------------------------------------------------------------------------------- /examples/fold0.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; distinguish between lists of booleans using only `fold` 5 | ; the solver must synthesize a function and an initial accumulator 6 | 7 | (declare-datatypes () ((nat (s (select_s_0 nat)) 8 | (z)))) 9 | 10 | (declare-datatypes 11 | () 12 | ((list (cons (select_cons_0 Bool) (select_cons_1 list)) (nil)))) 13 | 14 | (declare-sort acc 0) 15 | (declare-fun acc_init () acc) 16 | (declare-fun f (acc Bool) acc) 17 | 18 | ; force card(acc) to be 2 19 | (declare-fun a0 () acc) 20 | (declare-fun a1 () acc) 21 | 22 | (assert (not (= a0 a1))) 23 | (assert (forall ((x acc)) (or (= x a0) (= x a1)))) 24 | 25 | (define-fun-rec 26 | fold 27 | ((a acc) (l list)) acc 28 | (match l 29 | (case nil a) 30 | (case (cons x tail) 31 | (let ((a2 (f a x))) 32 | (fold a2 tail))))) 33 | 34 | 35 | (define-fun l0 () list (cons false (cons false (cons true (cons false nil))))) 36 | (define-fun l1 () list (cons false (cons true (cons false (cons false nil))))) 37 | (define-fun l2 () list (cons false (cons false (cons false (cons false (cons true (cons false nil))))))) 38 | (define-fun l3 () list (cons false (cons false (cons false (cons true (cons false (cons false nil))))))) 39 | 40 | (assert-not 41 | (not 42 | (and 43 | (not (= (fold acc_init l0) (fold acc_init l1))) 44 | (not (= (fold acc_init l2) (fold acc_init l3))) 45 | ))) 46 | 47 | (check-sat) 48 | -------------------------------------------------------------------------------- /examples/fold1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; distinguish between lists of natural numbers using only `fold` 5 | ; the solver must synthesize a function and an initial accumulator 6 | 7 | ; this time it's about distinguishing lists by the modulo 3 of their sum 8 | 9 | (declare-datatypes () ((nat (s (select_s_0 nat)) 10 | (z)))) 11 | 12 | (declare-datatypes 13 | () 14 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) (nil)))) 15 | 16 | (define-funs-rec 17 | ((plus ((x nat) (y nat)) nat)) 18 | ((match x (case (s x2) (s (plus x2 y))) 19 | (case z y)))) 20 | 21 | (define-funs-rec 22 | ((sum ((l_2 list)) nat)) 23 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 24 | (case nil z)))) 25 | 26 | (define-fun-rec 27 | modulo3 ((x nat)) nat 28 | (match x 29 | (case z z) 30 | (case (s x1) 31 | (match x1 (case z (s z)) 32 | (case (s x2) 33 | (match x2 (case z (s (s z))) 34 | (case (s x3) (modulo3 x3)))))))) 35 | 36 | (declare-sort acc 0) 37 | (declare-fun acc_init () acc) 38 | (declare-fun f (acc nat) acc) 39 | 40 | ; force card(acc) to be 3 41 | (declare-fun a0 () acc) 42 | (declare-fun a1 () acc) 43 | (declare-fun a2 () acc) 44 | 45 | (assert (not (= a0 a1))) 46 | (assert (not (= a0 a2))) 47 | (assert (not (= a1 a2))) 48 | (assert (forall ((x acc)) (or (= x a0) (= x a1) (= x a2)))) 49 | 50 | ; injective function acc->nat 51 | (declare-fun acc_to_nat (acc) nat) 52 | (assert (not (= (acc_to_nat a0) (acc_to_nat a1)))) 53 | (assert (not (= (acc_to_nat a0) (acc_to_nat a2)))) 54 | (assert (not (= (acc_to_nat a1) (acc_to_nat a2)))) 55 | 56 | (define-fun-rec 57 | fold 58 | ((a acc) (l list)) acc 59 | (match l 60 | (case nil a) 61 | (case (cons x tail) 62 | (let ((a2 (f a x))) 63 | (fold a2 tail))))) 64 | 65 | (define-fun n0 () nat z) 66 | (define-fun n1 () nat (s n0)) 67 | (define-fun n2 () nat (s n1)) 68 | (define-fun n3 () nat (s n2)) 69 | (define-fun n4 () nat (s n3)) 70 | (define-fun n5 () nat (s n4)) 71 | (define-fun n6 () nat (s n5)) 72 | (define-fun n7 () nat (s n6)) 73 | 74 | (define-fun l0 () list (cons n0 (cons n1 (cons n2 (cons n3 nil))))) 75 | (define-fun l1 () list (cons n1 (cons n2 (cons n3 (cons n4 nil))))) 76 | (define-fun l2 () list (cons n0 (cons n1 (cons n2 (cons n3 (cons n4 (cons n5 nil))))))) 77 | (define-fun l3 () list (cons n1 (cons n3 (cons n4 (cons n5 (cons n6 (cons n7 nil))))))) 78 | 79 | (assert-not 80 | (not 81 | (and 82 | (= (acc_to_nat (fold acc_init l0)) (modulo3 (sum l0))) 83 | (= (acc_to_nat (fold acc_init l1)) (modulo3 (sum l1))) 84 | (= (acc_to_nat (fold acc_init l2)) (modulo3 (sum l2))) 85 | (= (acc_to_nat (fold acc_init l3)) (modulo3 (sum l3))) 86 | (not (= (fold acc_init l0) (fold acc_init l1))) 87 | (not (= (fold acc_init l2) (fold acc_init l3))) 88 | (not (= (modulo3 (sum l0)) (modulo3 (sum l1)))) ; safety check 89 | (not (= (modulo3 (sum l2)) (modulo3 (sum l3)))) ; safety check 90 | ))) 91 | 92 | (check-sat) 93 | -------------------------------------------------------------------------------- /examples/ho_bool1.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; goal is to find `f:(bool->bool)->bool->bool` such that `f not x=x`, `f id x=not x` 4 | 5 | (declare-fun f ((=> Bool Bool) Bool) Bool) 6 | 7 | (define-fun fid ((x Bool)) Bool x) 8 | (define-fun fnot ((x Bool)) Bool (not x)) 9 | 10 | (assert (forall ((x Bool)) (= (f fnot x) x))) 11 | (assert (forall ((x Bool)) (= (f fid x) (not x)))) 12 | 13 | (check-sat) 14 | -------------------------------------------------------------------------------- /examples/incompatible_len.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; len l1 = 3, len l2 = 2, len (rev (l1 ++ l2)) = 6 3 | ; expect: UNSAT 4 | 5 | (include "list.lisp") 6 | (include "nat.lisp") 7 | 8 | (define (2 nat (s (s z)))) 9 | (define (3 nat (s (s (s z))))) 10 | (define (6 nat (mult 2 3))) 11 | 12 | (goal 13 | ((l1 list) 14 | (l2 list)) 15 | (and 16 | (= (length l1) 3) 17 | (= (length l2) 2) 18 | (= (length (rev (append l1 l2))) 6) 19 | )) 20 | 21 | -------------------------------------------------------------------------------- /examples/incompatible_len.smt2: -------------------------------------------------------------------------------- 1 | 2 | 3 | ; len l1 = 3, len l2 = 2, len (rev (l1 ++ l2)) = 6 4 | ; expect: UNSAT 5 | 6 | (declare-datatypes () ((nat (s (select_s_0 nat)) 7 | (z)))) 8 | (define-funs-rec 9 | ((plus ((x nat) (y nat)) nat)) 10 | ((match x (case (s x2) (s (plus x2 y))) 11 | (case z y)))) 12 | (define-funs-rec 13 | ((mult ((x_1 nat) (y_1 nat)) nat)) 14 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 15 | (case z z)))) 16 | (define-funs-rec 17 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 18 | ((match x_2 19 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 20 | (case z false))) 21 | (case z true)))) 22 | (declare-datatypes 23 | () 24 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 25 | (nil)))) 26 | (define-funs-rec 27 | ((append ((x_3 list) (y_3 list)) list)) 28 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 29 | (case nil y_3)))) 30 | (define-funs-rec 31 | ((rev ((l list)) list)) 32 | ((match l 33 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 34 | (case nil nil)))) 35 | (define-funs-rec 36 | ((length ((l_1 list)) nat)) 37 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 38 | (case nil z)))) 39 | (define-funs-rec 40 | ((sum ((l_2 list)) nat)) 41 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 42 | (case nil z)))) 43 | (define-funs-rec 44 | ((sorted ((l_3 list)) Bool)) 45 | ((match l_3 46 | (case (cons x_7 l2) 47 | (match l2 48 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 49 | (case nil true))) 50 | (case nil true)))) 51 | (define-funs-rec 52 | ((map ((f (=> nat nat)) (l_4 list)) list)) 53 | ((match l_4 54 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 55 | (case nil nil)))) 56 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 57 | (define-funs-rec ((num_3 () nat)) ((s (s (s z))))) 58 | (define-funs-rec ((num_6 () nat)) ((mult num_2 num_3))) 59 | (assert-not 60 | (forall 61 | ((l1 list) (l2_1 list)) 62 | (not (and 63 | (and (= (length l1) num_3) (= (length l2_1) num_2)) 64 | (= (length (rev (append l1 l2_1))) num_6)))))(check-sat) 65 | -------------------------------------------------------------------------------- /examples/ind_pred.nunchaku.smbc.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; generated by nunchaku 4 | (declare-datatypes () ((nat (z) 5 | (s (select-s-0 nat))))) 6 | (declare-sort iota 0) 7 | (declare-datatypes 8 | () 9 | ((list_iota 10 | (nil_iota) 11 | (cons_iota (select-cons_iota-0 iota) (select-cons_iota-1 list_iota))))) 12 | (declare-fun t () iota) 13 | (define-fun-rec 14 | even ((v_0 nat)) Bool 15 | (or 16 | (match v_0 (case z true) 17 | (case default false)) 18 | (match v_0 19 | (case (s x_0) 20 | (match x_0 (case (s x_0_0) (even x_0_0)) 21 | (case default false))) 22 | (case default false)))) 23 | (declare-datatypes () ((_nat (_zero) 24 | (_succ (select-_succ-0 _nat))))) 25 | (declare-fun decr_odd () _nat) 26 | (define-fun-rec 27 | odd ((v_0_0 _nat) (v_1 nat)) Bool 28 | (or 29 | (match v_0_0 30 | (case (_succ x_0_2) 31 | (match v_1 32 | (case (s x_0_1) (match x_0_1 (case z true) 33 | (case default false))) 34 | (case default false))) 35 | (case default false)) 36 | (match v_0_0 (case (_succ x_0_3) (odd x_0_3 v_1)) 37 | (case default false)) 38 | (match v_0_0 39 | (case (_succ x_0_5) 40 | (match v_1 41 | (case (s x_0_4) 42 | (match x_0_4 43 | (case (s x_0_6) (odd x_0_5 x_0_6)) 44 | (case default false))) 45 | (case default false))) 46 | (case default false)))) 47 | (declare-fun decr_has_len_iota () _nat) 48 | (define-fun-rec 49 | has_len_iota ((v_0_1 _nat) (v_1_0 list_iota) (v_2 nat)) Bool 50 | (or 51 | (match v_0_1 52 | (case (_succ x_0_7) 53 | (match v_1_0 54 | (case nil_iota (match v_2 (case z true) 55 | (case default false))) 56 | (case default false))) 57 | (case default false)) 58 | (match v_0_1 59 | (case (_succ x_0_8) 60 | (match v_1_0 61 | (case (cons_iota x_0_10 x_1) 62 | (match v_2 63 | (case (s x_0_9) (has_len_iota x_0_8 x_1 x_0_9)) 64 | (case default false))) 65 | (case default false))) 66 | (case default false)))) 67 | (assert-not 68 | (or 69 | (not (has_len_iota decr_has_len_iota (cons_iota t (cons_iota t nil_iota)) 70 | (s (s z)))) 71 | (not (even (s (s (s (s z)))))) 72 | (not (odd decr_odd (s (s (s (s (s z))))))))) 73 | (check-sat) 74 | 75 | -------------------------------------------------------------------------------- /examples/list.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; theory of lists 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (data (list nil (cons nat list))) 8 | 9 | (define 10 | (append 11 | (-> list list list) 12 | (fun (x list) 13 | (fun (y list) 14 | (match 15 | x 16 | (nil y) 17 | ((cons n tail) (cons n (append tail y)))))))) 18 | 19 | (define 20 | (rev 21 | (-> list list) 22 | (fun 23 | (l list) 24 | (match 25 | l 26 | (nil nil) 27 | ((cons x xs) (append (rev xs) (cons x nil))))))) 28 | 29 | (define 30 | (length (-> list nat) 31 | (fun (l list) 32 | (match l 33 | (nil z) 34 | ((cons x tail) (s (length tail))))))) 35 | 36 | (define 37 | (sum 38 | (-> list nat) 39 | (fun (l list) 40 | (match l 41 | (nil z) 42 | ((cons x tail) (plus x (sum tail))))))) 43 | 44 | (define 45 | (sorted (-> list prop) 46 | (fun (l list) 47 | (match l 48 | (nil true) 49 | ((cons x l2) 50 | (match l2 51 | (nil true) 52 | ((cons y l3) 53 | (and (leq x y) (sorted (cons y l3)))))))))) 54 | 55 | (define 56 | (map (-> (-> nat nat) list list) 57 | (fun (f (-> nat nat)) 58 | (fun (l list) 59 | (match l 60 | (nil nil) 61 | ((cons x tail) (cons (f x) (map f tail)))))))) 62 | 63 | -------------------------------------------------------------------------------- /examples/list_head_nat.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: unsat 3 | ; variation on list_head, using natural numbers instead of uninterpreted type 4 | 5 | (declare-datatypes () ((nat (Zero) (Succ (Pred nat))))) 6 | (declare-datatypes 7 | () 8 | ((list 9 | (Nil) 10 | (Cons (select-Cons-0 nat) (select-Cons-1 list))))) 11 | (define-fun-rec 12 | is_empty ((v_0 list)) Bool 13 | (match v_0 (case Nil true) 14 | (case default false))) 15 | (declare-const the_head nat) ; the "head" unknown 16 | (define-fun-rec 17 | head ((list_0 list)) nat 18 | (match list_0 19 | (case (Cons nat_0 list_1) nat_0) 20 | (case Nil the_head))) 21 | (declare-fun l10 () list) 22 | (declare-fun l21 () list) 23 | (assert-not 24 | (or 25 | (not (is_empty l10)) 26 | (not (is_empty l21)) 27 | (= (head l10) (head l21)))) 28 | (check-sat) 29 | 30 | -------------------------------------------------------------------------------- /examples/list_sum.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list whose sum = 4, where `rev l = l` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (goal 9 | ((l list)) 10 | (and 11 | (= (sum l) (s (s (s (s z))))) 12 | (= (rev l) l) 13 | )) 14 | 15 | -------------------------------------------------------------------------------- /examples/list_sum.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list whose sum = 4, where `rev l = l` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat_1 (s_1 (select_s_1_0 nat_1)) 6 | (z_1)))) 7 | (define-funs-rec 8 | ((plus_1 ((x_9 nat_1) (y_5 nat_1)) nat_1)) 9 | ((match x_9 (case (s_1 x2_3) (s_1 (plus_1 x2_3 y_5))) 10 | (case z_1 y_5)))) 11 | (define-funs-rec 12 | ((mult_1 ((x_10 nat_1) (y_6 nat_1)) nat_1)) 13 | ((match x_10 14 | (case (s_1 x2_4) (plus_1 y_6 (mult_1 x2_4 y_6))) 15 | (case z_1 z_1)))) 16 | (define-funs-rec 17 | ((leq_1 ((x_11 nat_1) (y_7 nat_1)) Bool)) 18 | ((match x_11 19 | (case (s_1 x2_5) 20 | (match y_7 (case (s_1 y2_1) (leq_1 x2_5 y2_1)) 21 | (case z_1 false))) 22 | (case z_1 true)))) 23 | (declare-datatypes 24 | () 25 | ((list_1 (cons_1 (select_cons_1_0 nat_1) (select_cons_1_1 list_1)) 26 | (nil_1)))) 27 | (define-funs-rec 28 | ((append_1 ((x_12 list_1) (y_8 list_1)) list_1)) 29 | ((match x_12 30 | (case (cons_1 n_1 tail_4) (cons_1 n_1 (append_1 tail_4 y_8))) 31 | (case nil_1 y_8)))) 32 | (define-funs-rec 33 | ((rev_1 ((l_5 list_1)) list_1)) 34 | ((match l_5 35 | (case (cons_1 x_13 xs_1) (append_1 (rev_1 xs_1) (cons_1 x_13 nil_1))) 36 | (case nil_1 nil_1)))) 37 | (define-funs-rec 38 | ((length_1 ((l_6 list_1)) nat_1)) 39 | ((match l_6 40 | (case (cons_1 x_14 tail_5) (s_1 (length_1 tail_5))) 41 | (case nil_1 z_1)))) 42 | (define-funs-rec 43 | ((sum_1 ((l_7 list_1)) nat_1)) 44 | ((match l_7 45 | (case (cons_1 x_15 tail_6) (plus_1 x_15 (sum_1 tail_6))) 46 | (case nil_1 z_1)))) 47 | (define-funs-rec 48 | ((sorted_1 ((l_8 list_1)) Bool)) 49 | ((match l_8 50 | (case (cons_1 x_16 l2_2) 51 | (match l2_2 52 | (case (cons_1 y_9 l3_1) 53 | (and (leq_1 x_16 y_9) (sorted_1 (cons_1 y_9 l3_1)))) 54 | (case nil_1 true))) 55 | (case nil_1 true)))) 56 | (define-funs-rec 57 | ((map_1 ((f_1 (=> nat_1 nat_1)) (l_9 list_1)) list_1)) 58 | ((match l_9 59 | (case (cons_1 x_17 tail_7) (cons_1 (f_1 x_17) (map_1 f_1 tail_7))) 60 | (case nil_1 nil_1)))) 61 | (assert-not 62 | (forall 63 | ((l_10 list_1)) 64 | (not (and 65 | (= (sum_1 l_10) (s_1 (s_1 (s_1 (s_1 z_1))))) 66 | (= (rev_1 l_10) l_10)))))(check-sat) 67 | -------------------------------------------------------------------------------- /examples/logic.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; basic propositional formulas 3 | ; expect: sat 4 | 5 | (data (atom a b c d)) 6 | 7 | (data (form (at atom) (& form form) (| form form) (~ form))) 8 | 9 | ; evaluate a formula (v: valuation) 10 | (define 11 | (eval 12 | (-> (-> atom prop) form prop) 13 | (fun (v (-> atom prop)) 14 | (fun (e form) 15 | (match e 16 | ((at a) (v a)) 17 | ((& a b) (and (eval v a) (eval v b))) 18 | ((| a b) (or (eval v a) (eval v b))) 19 | ((~ a) (not (eval v a)))))))) 20 | 21 | -------------------------------------------------------------------------------- /examples/long_rev.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list of length 6, where `rev l = l` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (goal 9 | ((l list)) 10 | (and 11 | (= (length l) (s (s (s (s (s (s z))))))) 12 | (= (rev l) l))) 13 | 14 | -------------------------------------------------------------------------------- /examples/long_rev_sum.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 6 & sum l = 10 & rev l = l` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (goal 9 | ((l list)) 10 | (and 11 | (= (length l) (s (s (s (s (s (s z))))))) 12 | (= (sum l) (s (s (s (s (s (s (s (s (s (s z))))))))))) 13 | (= (rev l) l) 14 | )) 15 | 16 | -------------------------------------------------------------------------------- /examples/long_rev_sum2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 6 & sum l = 11 & rev l = l` 3 | ; unsat since the list must be symmetric, but 11 is odd 4 | 5 | ; expect: UNSAT 6 | 7 | (include "nat.lisp") 8 | (include "list.lisp") 9 | 10 | (goal 11 | ((l list)) 12 | (and 13 | (= (length l) (s (s (s (s (s (s z))))))) 14 | (= (sum l) (s (s (s (s (s (s (s (s (s (s (s z)))))))))))) 15 | (= (rev l) l) 16 | )) 17 | 18 | -------------------------------------------------------------------------------- /examples/long_rev_sum2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 6 & sum l = 11 & rev l = l` 3 | ; unsat since the list must be symmetric, but 11 is odd 4 | 5 | ; expect: UNSAT 6 | 7 | (declare-datatypes () ((nat (s (select_s_0 nat)) 8 | (z)))) 9 | (define-funs-rec 10 | ((plus ((x nat) (y nat)) nat)) 11 | ((match x (case (s x2) (s (plus x2 y))) 12 | (case z y)))) 13 | (define-funs-rec 14 | ((mult ((x_1 nat) (y_1 nat)) nat)) 15 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 16 | (case z z)))) 17 | (define-funs-rec 18 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 19 | ((match x_2 20 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 21 | (case z false))) 22 | (case z true)))) 23 | (declare-datatypes 24 | () 25 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 26 | (nil)))) 27 | (define-funs-rec 28 | ((append ((x_3 list) (y_3 list)) list)) 29 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 30 | (case nil y_3)))) 31 | (define-funs-rec 32 | ((rev ((l list)) list)) 33 | ((match l 34 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 35 | (case nil nil)))) 36 | (define-funs-rec 37 | ((length ((l_1 list)) nat)) 38 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 39 | (case nil z)))) 40 | (define-funs-rec 41 | ((sum ((l_2 list)) nat)) 42 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 43 | (case nil z)))) 44 | (define-funs-rec 45 | ((sorted ((l_3 list)) Bool)) 46 | ((match l_3 47 | (case (cons x_7 l2) 48 | (match l2 49 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 50 | (case nil true))) 51 | (case nil true)))) 52 | (define-funs-rec 53 | ((map ((f (=> nat nat)) (l_4 list)) list)) 54 | ((match l_4 55 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 56 | (case nil nil)))) 57 | (assert-not 58 | (forall 59 | ((l_5 list)) 60 | (not (and 61 | (and 62 | (= (length l_5) (s (s (s (s (s (s z))))))) 63 | (= (sum l_5) (s (s (s (s (s (s (s (s (s (s (s z))))))))))))) 64 | (= (rev l_5) l_5)))))(check-sat) 65 | -------------------------------------------------------------------------------- /examples/long_rev_sum3.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 10 & sum l = 20 & rev l = l` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (two nat (s (s z)))) 9 | (define (five nat (s (s (s (s (s z))))))) 10 | (define (ten nat (mult two five))) 11 | (define (twenty nat (mult two ten))) 12 | 13 | (goal 14 | ((l list)) 15 | (and 16 | (= (length l) ten) 17 | (= (sum l) twenty) 18 | (= (rev l) l) 19 | )) 20 | 21 | 22 | -------------------------------------------------------------------------------- /examples/long_rev_sum3.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 10 & sum l = 20 & rev l = l` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (declare-datatypes 22 | () 23 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 24 | (nil)))) 25 | (define-funs-rec 26 | ((append ((x_3 list) (y_3 list)) list)) 27 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 28 | (case nil y_3)))) 29 | (define-funs-rec 30 | ((rev ((l list)) list)) 31 | ((match l 32 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 33 | (case nil nil)))) 34 | (define-funs-rec 35 | ((length ((l_1 list)) nat)) 36 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 37 | (case nil z)))) 38 | (define-funs-rec 39 | ((sum ((l_2 list)) nat)) 40 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 41 | (case nil z)))) 42 | (define-funs-rec 43 | ((sorted ((l_3 list)) Bool)) 44 | ((match l_3 45 | (case (cons x_7 l2) 46 | (match l2 47 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 48 | (case nil true))) 49 | (case nil true)))) 50 | (define-funs-rec 51 | ((map ((f (=> nat nat)) (l_4 list)) list)) 52 | ((match l_4 53 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 54 | (case nil nil)))) 55 | (define-funs-rec ((two () nat)) ((s (s z)))) 56 | (define-funs-rec ((five () nat)) ((s (s (s (s (s z))))))) 57 | (define-funs-rec ((ten () nat)) ((mult two five))) 58 | (define-funs-rec ((twenty () nat)) ((mult two ten))) 59 | (assert-not 60 | (forall 61 | ((l_5 list)) 62 | (not (and 63 | (and (= (length l_5) ten) (= (sum l_5) twenty)) 64 | (= (rev l_5) l_5)))))(check-sat) 65 | -------------------------------------------------------------------------------- /examples/long_rev_sum4.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 1,000 & sum l = 1 & rev l = l` 3 | ; expect: UNSAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (1 nat (s z))) 9 | (define (2 nat (s (s z)))) 10 | (define (5 nat (s (s (s (s (s z))))))) 11 | (define (10 nat (mult 2 5))) 12 | (define (100 nat (mult 10 10))) 13 | (define (1000 nat (mult 10 100))) 14 | 15 | (goal 16 | ((l list)) 17 | (and 18 | (= (length l) 1000) 19 | (= (sum l) 1) 20 | (= (rev l) l) 21 | )) 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/long_rev_sum4.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 1,000 & sum l = 1 & rev l = l` 3 | ; expect: UNSAT 4 | (declare-datatypes () ((nat (s (select_s_0 nat)) 5 | (z)))) 6 | (define-funs-rec 7 | ((plus ((x nat) (y nat)) nat)) 8 | ((match x (case (s x2) (s (plus x2 y))) 9 | (case z y)))) 10 | (define-funs-rec 11 | ((mult ((x_1 nat) (y_1 nat)) nat)) 12 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 13 | (case z z)))) 14 | (define-funs-rec 15 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 16 | ((match x_2 17 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 18 | (case z false))) 19 | (case z true)))) 20 | (declare-datatypes 21 | () 22 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 23 | (nil)))) 24 | (define-funs-rec 25 | ((append ((x_3 list) (y_3 list)) list)) 26 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 27 | (case nil y_3)))) 28 | (define-funs-rec 29 | ((rev ((l list)) list)) 30 | ((match l 31 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 32 | (case nil nil)))) 33 | (define-funs-rec 34 | ((length ((l_1 list)) nat)) 35 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 36 | (case nil z)))) 37 | (define-funs-rec 38 | ((sum ((l_2 list)) nat)) 39 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 40 | (case nil z)))) 41 | (define-funs-rec 42 | ((sorted ((l_3 list)) Bool)) 43 | ((match l_3 44 | (case (cons x_7 l2) 45 | (match l2 46 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 47 | (case nil true))) 48 | (case nil true)))) 49 | (define-funs-rec 50 | ((map ((f (=> nat nat)) (l_4 list)) list)) 51 | ((match l_4 52 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 53 | (case nil nil)))) 54 | (define-funs-rec ((num_1 () nat)) ((s z))) 55 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 56 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 57 | (define-funs-rec ((num_10 () nat)) ((mult num_2 num_5))) 58 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 59 | (define-funs-rec ((num_1000 () nat)) ((mult num_10 num_100))) 60 | (assert-not 61 | (forall 62 | ((l_5 list)) 63 | (not (and 64 | (and (= (length l_5) num_1000) (= (sum l_5) num_1)) 65 | (= (rev l_5) l_5)))))(check-sat) 66 | -------------------------------------------------------------------------------- /examples/long_rev_sum5.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 200 & sum l = 2 & rev l = l` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (1 nat (s z))) 9 | (define (2 nat (s (s z)))) 10 | (define (5 nat (s (s (s (s (s z))))))) 11 | (define (10 nat (mult 2 5))) 12 | (define (100 nat (mult 10 10))) 13 | (define (200 nat (mult 2 100))) 14 | 15 | (goal 16 | ((l list)) 17 | (and 18 | (= (length l) 200) 19 | (= (sum l) 2) 20 | (= (rev l) l) 21 | )) 22 | 23 | 24 | -------------------------------------------------------------------------------- /examples/long_rev_sum5.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 200 & sum l = 2 & rev l = l` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (declare-datatypes 22 | () 23 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 24 | (nil)))) 25 | (define-funs-rec 26 | ((append ((x_3 list) (y_3 list)) list)) 27 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 28 | (case nil y_3)))) 29 | (define-funs-rec 30 | ((rev ((l list)) list)) 31 | ((match l 32 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 33 | (case nil nil)))) 34 | (define-funs-rec 35 | ((length ((l_1 list)) nat)) 36 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 37 | (case nil z)))) 38 | (define-funs-rec 39 | ((sum ((l_2 list)) nat)) 40 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 41 | (case nil z)))) 42 | (define-funs-rec 43 | ((sorted ((l_3 list)) Bool)) 44 | ((match l_3 45 | (case (cons x_7 l2) 46 | (match l2 47 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 48 | (case nil true))) 49 | (case nil true)))) 50 | (define-funs-rec 51 | ((map ((f (=> nat nat)) (l_4 list)) list)) 52 | ((match l_4 53 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 54 | (case nil nil)))) 55 | (define-funs-rec ((num_1 () nat)) ((s z))) 56 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 57 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 58 | (define-funs-rec ((num_10 () nat)) ((mult num_2 num_5))) 59 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 60 | (define-funs-rec ((num_200 () nat)) ((mult num_2 num_100))) 61 | (assert-not 62 | (forall 63 | ((l_5 list)) 64 | (not (and 65 | (and (= (length l_5) num_200) (= (sum l_5) num_2)) 66 | (= (rev l_5) l_5)))))(check-sat) 67 | -------------------------------------------------------------------------------- /examples/long_rev_sum6.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 2, rev l = l, sum l = 500` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (1 nat (s z))) 9 | (define (2 nat (s (s z)))) 10 | (define (5 nat (s (s (s (s (s z))))))) 11 | (define (10 nat (mult 2 5))) 12 | (define (100 nat (mult 10 10))) 13 | (define (500 nat (mult 5 100))) 14 | 15 | (goal 16 | ((l list)) 17 | (and 18 | (= (length l) 2) 19 | (= (sum l) 500) 20 | (= (rev l) l) 21 | )) 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/long_rev_sum6.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find a list `l` where: `length l = 2, rev l = l, sum l = 500` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (declare-datatypes 22 | () 23 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 24 | (nil)))) 25 | (define-funs-rec 26 | ((append ((x_3 list) (y_3 list)) list)) 27 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 28 | (case nil y_3)))) 29 | (define-funs-rec 30 | ((rev ((l list)) list)) 31 | ((match l 32 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 33 | (case nil nil)))) 34 | (define-funs-rec 35 | ((length ((l_1 list)) nat)) 36 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 37 | (case nil z)))) 38 | (define-funs-rec 39 | ((sum ((l_2 list)) nat)) 40 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 41 | (case nil z)))) 42 | (define-funs-rec 43 | ((sorted ((l_3 list)) Bool)) 44 | ((match l_3 45 | (case (cons x_7 l2) 46 | (match l2 47 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 48 | (case nil true))) 49 | (case nil true)))) 50 | (define-funs-rec ((num_1 () nat)) ((s z))) 51 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 52 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 53 | (define-funs-rec ((num_10 () nat)) ((mult num_2 num_5))) 54 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 55 | (define-funs-rec ((num_500 () nat)) ((mult num_5 num_100))) 56 | (assert-not 57 | (forall 58 | ((l_5 list)) 59 | (not (and 60 | (and (= (length l_5) num_2) (= (sum l_5) num_500)) 61 | (= (rev l_5) l_5)))))(check-sat) 62 | -------------------------------------------------------------------------------- /examples/map_fun.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map f [1,2,3] = [3,4,5], f 10=12` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (1 nat (s z))) 9 | (define (2 nat (s 1))) 10 | (define (3 nat (s 2))) 11 | (define (4 nat (s 3))) 12 | (define (5 nat (s 4))) 13 | (define (10 nat (mult 2 5))) 14 | 15 | (goal 16 | ((f (-> nat nat))) 17 | (and 18 | (= 19 | (map f (cons 1 (cons 2 (cons 3 nil)))) 20 | (cons 3 (cons 4 (cons 5 nil)))) 21 | (= (f 10) (plus 2 10)) 22 | )) 23 | 24 | 25 | -------------------------------------------------------------------------------- /examples/map_fun.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map f [1,2,3] = [3,4,5], f 10=12` 3 | ; expect: SAT 4 | (declare-datatypes () ((nat_4 (s_4 (select_s_4_0 nat_4)) 5 | (z_4)))) 6 | (define-funs-rec 7 | ((plus_4 ((x_36 nat_4) (y_20 nat_4)) nat_4)) 8 | ((match x_36 (case (s_4 x2_12) (s_4 (plus_4 x2_12 y_20))) 9 | (case z_4 y_20)))) 10 | (define-funs-rec 11 | ((mult_4 ((x_37 nat_4) (y_21 nat_4)) nat_4)) 12 | ((match x_37 13 | (case (s_4 x2_13) (plus_4 y_21 (mult_4 x2_13 y_21))) 14 | (case z_4 z_4)))) 15 | (define-funs-rec 16 | ((leq_4 ((x_38 nat_4) (y_22 nat_4)) Bool)) 17 | ((match x_38 18 | (case (s_4 x2_14) 19 | (match y_22 (case (s_4 y2_4) (leq_4 x2_14 y2_4)) 20 | (case z_4 false))) 21 | (case z_4 true)))) 22 | (declare-datatypes 23 | () 24 | ((list_4 (cons_4 (select_cons_4_0 nat_4) (select_cons_4_1 list_4)) 25 | (nil_4)))) 26 | (define-funs-rec 27 | ((append_4 ((x_39 list_4) (y_23 list_4)) list_4)) 28 | ((match x_39 29 | (case (cons_4 n_4 tail_16) (cons_4 n_4 (append_4 tail_16 y_23))) 30 | (case nil_4 y_23)))) 31 | (define-funs-rec 32 | ((rev_4 ((l_21 list_4)) list_4)) 33 | ((match l_21 34 | (case (cons_4 x_40 xs_4) (append_4 (rev_4 xs_4) (cons_4 x_40 nil_4))) 35 | (case nil_4 nil_4)))) 36 | (define-funs-rec 37 | ((length_4 ((l_22 list_4)) nat_4)) 38 | ((match l_22 39 | (case (cons_4 x_41 tail_17) (s_4 (length_4 tail_17))) 40 | (case nil_4 z_4)))) 41 | (define-funs-rec 42 | ((sum_4 ((l_23 list_4)) nat_4)) 43 | ((match l_23 44 | (case (cons_4 x_42 tail_18) (plus_4 x_42 (sum_4 tail_18))) 45 | (case nil_4 z_4)))) 46 | (define-funs-rec 47 | ((sorted_4 ((l_24 list_4)) Bool)) 48 | ((match l_24 49 | (case (cons_4 x_43 l2_5) 50 | (match l2_5 51 | (case (cons_4 y_24 l3_4) 52 | (and (leq_4 x_43 y_24) (sorted_4 (cons_4 y_24 l3_4)))) 53 | (case nil_4 true))) 54 | (case nil_4 true)))) 55 | (define-funs-rec 56 | ((map_4 ((f_6 (=> nat_4 nat_4)) (l_25 list_4)) list_4)) 57 | ((match l_25 58 | (case (cons_4 x_44 tail_19) (cons_4 (f_6 x_44) (map_4 f_6 tail_19))) 59 | (case nil_4 nil_4)))) 60 | (define-funs-rec ((num_1_2 () nat_4)) ((s_4 z_4))) 61 | (define-funs-rec ((num_2_3 () nat_4)) ((s_4 num_1_2))) 62 | (define-funs-rec ((num_3_3 () nat_4)) ((s_4 num_2_3))) 63 | (define-funs-rec ((num_4_2 () nat_4)) ((s_4 num_3_3))) 64 | (define-funs-rec ((num_5_2 () nat_4)) ((s_4 num_4_2))) 65 | (define-funs-rec ((num_10_2 () nat_4)) ((mult_4 num_2_3 num_5_2))) 66 | (assert-not 67 | (forall 68 | ((f_7 (=> nat_4 nat_4))) 69 | (not (and 70 | (= 71 | (map_4 f_7 72 | (cons_4 num_1_2 (cons_4 num_2_3 (cons_4 num_3_3 nil_4)))) 73 | (cons_4 num_3_3 (cons_4 num_4_2 (cons_4 num_5_2 nil_4)))) 74 | (= (f_7 num_10_2) (plus_4 num_2_3 num_10_2))))))(check-sat) 75 | -------------------------------------------------------------------------------- /examples/map_fun2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map f [1,2,3] = [2,4,6], f 10=20` 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | (include "list.lisp") 7 | 8 | (define (1 nat (s z))) 9 | (define (2 nat (s 1))) 10 | (define (3 nat (s 2))) 11 | (define (4 nat (s 3))) 12 | (define (5 nat (s 4))) 13 | (define (6 nat (s 5))) 14 | (define (10 nat (mult 2 5))) 15 | 16 | (goal 17 | ((f (-> nat nat))) 18 | (and 19 | (= 20 | (map f (cons 1 (cons 2 (cons 3 nil)))) 21 | (cons 2 (cons 4 (cons 6 nil)))) 22 | (= (f 10) (mult 2 10)) 23 | )) 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/map_fun2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map f [1,2,3] = [2,4,6], f 10=20` 3 | ; expect: SAT 4 | (declare-datatypes () ((nat_2 (s_2 (select_s_2_0 nat_2)) 5 | (z_2)))) 6 | (define-funs-rec 7 | ((plus_2 ((x_18 nat_2) (y_10 nat_2)) nat_2)) 8 | ((match x_18 (case (s_2 x2_6) (s_2 (plus_2 x2_6 y_10))) 9 | (case z_2 y_10)))) 10 | (define-funs-rec 11 | ((mult_2 ((x_19 nat_2) (y_11 nat_2)) nat_2)) 12 | ((match x_19 13 | (case (s_2 x2_7) (plus_2 y_11 (mult_2 x2_7 y_11))) 14 | (case z_2 z_2)))) 15 | (define-funs-rec 16 | ((leq_2 ((x_20 nat_2) (y_12 nat_2)) Bool)) 17 | ((match x_20 18 | (case (s_2 x2_8) 19 | (match y_12 (case (s_2 y2_2) (leq_2 x2_8 y2_2)) 20 | (case z_2 false))) 21 | (case z_2 true)))) 22 | (declare-datatypes 23 | () 24 | ((list_2 (cons_2 (select_cons_2_0 nat_2) (select_cons_2_1 list_2)) 25 | (nil_2)))) 26 | (define-funs-rec 27 | ((append_2 ((x_21 list_2) (y_13 list_2)) list_2)) 28 | ((match x_21 29 | (case (cons_2 n_2 tail_8) (cons_2 n_2 (append_2 tail_8 y_13))) 30 | (case nil_2 y_13)))) 31 | (define-funs-rec 32 | ((rev_2 ((l_11 list_2)) list_2)) 33 | ((match l_11 34 | (case (cons_2 x_22 xs_2) (append_2 (rev_2 xs_2) (cons_2 x_22 nil_2))) 35 | (case nil_2 nil_2)))) 36 | (define-funs-rec 37 | ((length_2 ((l_12 list_2)) nat_2)) 38 | ((match l_12 39 | (case (cons_2 x_23 tail_9) (s_2 (length_2 tail_9))) 40 | (case nil_2 z_2)))) 41 | (define-funs-rec 42 | ((sum_2 ((l_13 list_2)) nat_2)) 43 | ((match l_13 44 | (case (cons_2 x_24 tail_10) (plus_2 x_24 (sum_2 tail_10))) 45 | (case nil_2 z_2)))) 46 | (define-funs-rec 47 | ((sorted_2 ((l_14 list_2)) Bool)) 48 | ((match l_14 49 | (case (cons_2 x_25 l2_3) 50 | (match l2_3 51 | (case (cons_2 y_14 l3_2) 52 | (and (leq_2 x_25 y_14) (sorted_2 (cons_2 y_14 l3_2)))) 53 | (case nil_2 true))) 54 | (case nil_2 true)))) 55 | (define-funs-rec 56 | ((map_2 ((f_2 (=> nat_2 nat_2)) (l_15 list_2)) list_2)) 57 | ((match l_15 58 | (case (cons_2 x_26 tail_11) (cons_2 (f_2 x_26) (map_2 f_2 tail_11))) 59 | (case nil_2 nil_2)))) 60 | (define-funs-rec ((num_1 () nat_2)) ((s_2 z_2))) 61 | (define-funs-rec ((num_2_1 () nat_2)) ((s_2 num_1))) 62 | (define-funs-rec ((num_3_1 () nat_2)) ((s_2 num_2_1))) 63 | (define-funs-rec ((num_4 () nat_2)) ((s_2 num_3_1))) 64 | (define-funs-rec ((num_5 () nat_2)) ((s_2 num_4))) 65 | (define-funs-rec ((num_6_1 () nat_2)) ((s_2 num_5))) 66 | (define-funs-rec ((num_10 () nat_2)) ((mult_2 num_2_1 num_5))) 67 | (assert-not 68 | (forall 69 | ((f_3 (=> nat_2 nat_2))) 70 | (not (and 71 | (= 72 | (map_2 f_3 (cons_2 num_1 (cons_2 num_2_1 (cons_2 num_3_1 nil_2)))) 73 | (cons_2 num_2_1 (cons_2 num_4 (cons_2 num_6_1 nil_2)))) 74 | (= (f_3 num_10) (mult_2 num_2_1 num_10))))))(check-sat) 75 | -------------------------------------------------------------------------------- /examples/map_fun3.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map (f plus) [1,2,3] = [2,4,6], f 10=20`, 3 | 4 | ; actual status is SAT, but here it's out of fragment 5 | ; expect: ERROR 6 | 7 | (include "nat.lisp") 8 | (include "list.lisp") 9 | 10 | (define (1 nat (s z))) 11 | (define (2 nat (s 1))) 12 | (define (3 nat (s 2))) 13 | (define (4 nat (s 3))) 14 | (define (5 nat (s 4))) 15 | (define (6 nat (s 5))) 16 | (define (10 nat (mult 2 5))) 17 | 18 | (goal 19 | ((f (-> (-> nat nat nat) nat nat))) 20 | (and 21 | (= 22 | (map (f plus) (cons 1 (cons 2 (cons 3 nil)))) 23 | (cons 2 (cons 4 (cons 6 nil)))) 24 | (= (f plus 10) (mult 2 10)) 25 | )) 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/map_fun3.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; find `f` where: `map (f plus) [1,2,3] = [2,4,6], f 10=20`, 3 | 4 | ; expect: SAT 5 | (declare-datatypes () ((nat_3 (s_3 (select_s_3_0 nat_3)) 6 | (z_3)))) 7 | (define-funs-rec 8 | ((plus_3 ((x_27 nat_3) (y_15 nat_3)) nat_3)) 9 | ((match x_27 (case (s_3 x2_9) (s_3 (plus_3 x2_9 y_15))) 10 | (case z_3 y_15)))) 11 | (define-funs-rec 12 | ((mult_3 ((x_28 nat_3) (y_16 nat_3)) nat_3)) 13 | ((match x_28 14 | (case (s_3 x2_10) (plus_3 y_16 (mult_3 x2_10 y_16))) 15 | (case z_3 z_3)))) 16 | (define-funs-rec 17 | ((leq_3 ((x_29 nat_3) (y_17 nat_3)) Bool)) 18 | ((match x_29 19 | (case (s_3 x2_11) 20 | (match y_17 (case (s_3 y2_3) (leq_3 x2_11 y2_3)) 21 | (case z_3 false))) 22 | (case z_3 true)))) 23 | (declare-datatypes 24 | () 25 | ((list_3 (cons_3 (select_cons_3_0 nat_3) (select_cons_3_1 list_3)) 26 | (nil_3)))) 27 | (define-funs-rec 28 | ((append_3 ((x_30 list_3) (y_18 list_3)) list_3)) 29 | ((match x_30 30 | (case (cons_3 n_3 tail_12) (cons_3 n_3 (append_3 tail_12 y_18))) 31 | (case nil_3 y_18)))) 32 | (define-funs-rec 33 | ((rev_3 ((l_16 list_3)) list_3)) 34 | ((match l_16 35 | (case (cons_3 x_31 xs_3) (append_3 (rev_3 xs_3) (cons_3 x_31 nil_3))) 36 | (case nil_3 nil_3)))) 37 | (define-funs-rec 38 | ((length_3 ((l_17 list_3)) nat_3)) 39 | ((match l_17 40 | (case (cons_3 x_32 tail_13) (s_3 (length_3 tail_13))) 41 | (case nil_3 z_3)))) 42 | (define-funs-rec 43 | ((sum_3 ((l_18 list_3)) nat_3)) 44 | ((match l_18 45 | (case (cons_3 x_33 tail_14) (plus_3 x_33 (sum_3 tail_14))) 46 | (case nil_3 z_3)))) 47 | (define-funs-rec 48 | ((sorted_3 ((l_19 list_3)) Bool)) 49 | ((match l_19 50 | (case (cons_3 x_34 l2_4) 51 | (match l2_4 52 | (case (cons_3 y_19 l3_3) 53 | (and (leq_3 x_34 y_19) (sorted_3 (cons_3 y_19 l3_3)))) 54 | (case nil_3 true))) 55 | (case nil_3 true)))) 56 | (define-funs-rec 57 | ((map_3 ((f_4 (=> nat_3 nat_3)) (l_20 list_3)) list_3)) 58 | ((match l_20 59 | (case (cons_3 x_35 tail_15) (cons_3 (f_4 x_35) (map_3 f_4 tail_15))) 60 | (case nil_3 nil_3)))) 61 | (define-funs-rec ((num_1_1 () nat_3)) ((s_3 z_3))) 62 | (define-funs-rec ((num_2_2 () nat_3)) ((s_3 num_1_1))) 63 | (define-funs-rec ((num_3_2 () nat_3)) ((s_3 num_2_2))) 64 | (define-funs-rec ((num_4_1 () nat_3)) ((s_3 num_3_2))) 65 | (define-funs-rec ((num_5_1 () nat_3)) ((s_3 num_4_1))) 66 | (define-funs-rec ((num_6_2 () nat_3)) ((s_3 num_5_1))) 67 | (define-funs-rec ((num_10_1 () nat_3)) ((mult_3 num_2_2 num_5_1))) 68 | (assert-not 69 | (forall 70 | ((f_5 (=> (=> nat_3 (=> nat_3 nat_3)) (=> nat_3 nat_3)))) 71 | (not (and 72 | (= 73 | (map_3 (f_5 plus_3) 74 | (cons_3 num_1_1 (cons_3 num_2_2 (cons_3 num_3_2 nil_3)))) 75 | (cons_3 num_2_2 (cons_3 num_4_1 (cons_3 num_6_2 nil_3)))) 76 | (= (f_5 plus_3 num_10_1) (mult_3 num_2_2 num_10_1))))))(check-sat) 77 | -------------------------------------------------------------------------------- /examples/nat.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; theory of nat 3 | ; expect: SAT 4 | 5 | (data (nat z (s nat))) 6 | 7 | (define 8 | (plus 9 | (-> nat nat nat) 10 | (fun (x nat) 11 | (fun (y nat) 12 | (match x 13 | (z y) 14 | ((s x2) (s (plus x2 y)))))))) 15 | 16 | (define 17 | (mult 18 | (-> nat nat nat) 19 | (fun (x nat) 20 | (fun (y nat) 21 | (match x 22 | (z z) 23 | ((s x2) (plus y (mult x2 y)))))))) 24 | 25 | (define 26 | (leq 27 | (-> nat nat prop) 28 | (fun (x nat) 29 | (fun (y nat) 30 | (match x 31 | (z true) 32 | ((s x2) 33 | (match y (z false) ((s y2) (leq x2 y2))))))))) 34 | -------------------------------------------------------------------------------- /examples/pigeon4.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; pigeonhole 3 | ; expect: UNSAT 4 | 5 | (declare-sort hole 0) 6 | (declare-fun h1 () hole) 7 | (declare-fun h2 () hole) 8 | (declare-fun h3 () hole) 9 | (declare-fun h4 () hole) 10 | (declare-fun p1 () hole) 11 | (declare-fun p2 () hole) 12 | (declare-fun p3 () hole) 13 | (declare-fun p4 () hole) 14 | (declare-fun p5 () hole) 15 | (assert 16 | (and 17 | (not (= h1 h2)) (not (= h1 h3)) (not (= h1 h4)) 18 | (not (= h2 h3)) (not (= h2 h4)) (not (= h3 h4)))) 19 | (assert 20 | (and 21 | (not (= p1 p2)) (not (= p1 p3)) (not (= p1 p4)) 22 | (not (= p1 p5)) 23 | (not (= p2 p3)) 24 | (not (= p2 p4)) 25 | (not (= p2 p5)) 26 | (not (= p3 p4)) 27 | (not (= p3 p5)) 28 | (not (= p4 p5)))) 29 | (assert 30 | (forall ((p hole)) (or (= p h1) (= p h2) (= p h3) (= p h4)))) 31 | (check-sat) 32 | -------------------------------------------------------------------------------- /examples/quant_fact_leq_100.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; all factorials are smaller than 100 3 | ; expect: unsat 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (define-funs-rec 22 | ((fact ((n nat)) nat)) 23 | ((match n (case (s n2) (mult n (fact n2))) 24 | (case z (s z))))) 25 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 26 | (define-funs-rec ((num_10 () nat)) ((mult (s (s z)) num_5))) 27 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 28 | (assert-not 29 | (not (forall ((n_1 nat)) (leq (fact n_1) num_100)))) 30 | (check-sat) 31 | -------------------------------------------------------------------------------- /examples/quant_fact_leq_10000.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; all factorials are smaller than 100×100 3 | ; expect: unsat 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (define-funs-rec 22 | ((fact ((n nat)) nat)) 23 | ((match n (case (s n2) (mult n (fact n2))) 24 | (case z (s z))))) 25 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 26 | (define-funs-rec ((num_10 () nat)) ((mult (s (s z)) num_5))) 27 | (define-funs-rec ((num_100 () nat)) ((mult num_10 num_10))) 28 | (assert-not 29 | (not (forall ((n_1 nat)) (leq (fact n_1) (mult num_100 num_100))))) 30 | (check-sat) 31 | -------------------------------------------------------------------------------- /examples/quant_list1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: sat 3 | 4 | ; find list with len=3, sum=5 5 | ; here we use quantifiers instead of meta variables 6 | 7 | (declare-datatypes () ((nat (s (select_s_0 nat)) 8 | (z)))) 9 | (define-funs-rec 10 | ((plus ((x nat) (y nat)) nat)) 11 | ((match x (case (s x2) (s (plus x2 y))) 12 | (case z y)))) 13 | (define-funs-rec 14 | ((mult ((x_1 nat) (y_1 nat)) nat)) 15 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 16 | (case z z)))) 17 | (declare-datatypes 18 | () 19 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 20 | (nil)))) 21 | (define-funs-rec 22 | ((length ((l_1 list)) nat)) 23 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 24 | (case nil z)))) 25 | (define-funs-rec 26 | ((sum ((l_2 list)) nat)) 27 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 28 | (case nil z)))) 29 | (define-funs-rec ((num_1 () nat)) ((s z))) 30 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 31 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 32 | (define-funs-rec ((num_10 () nat)) ((mult num_2 num_5))) 33 | (assert-not 34 | (not (exists 35 | ((l_5 list)) 36 | (and 37 | (and (= (length l_5) (s num_2)) (= (sum l_5) num_5)))))) 38 | (check-sat) 39 | -------------------------------------------------------------------------------- /examples/quant_nat_zero_or_lt.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; quantification that should evaluate to true 5 | ; forall x:nat. x=0 ∨ 02 (>_0 R) (>_1 R)) 11 | (Star (Star_0 R))))) 12 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 13 | (declare-datatypes () 14 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 15 | (define-fun-rec 16 | splits2 17 | ((x T) (y list2)) list2 18 | (match y 19 | (case Nil2 Nil2) 20 | (case (Cons2 z x2) 21 | (match z 22 | (case (Pair2 bs cs) 23 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 24 | (define-fun-rec 25 | splits 26 | ((x list)) list2 27 | (match x 28 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 29 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 30 | (define-fun-rec 31 | ors 32 | ((x list3)) Bool 33 | (match x 34 | (case Nil3 false) 35 | (case (Cons3 y xs) (or y (ors xs))))) 36 | (define-fun 37 | eqT 38 | ((x T) (y T)) Bool 39 | (match x 40 | (case A 41 | (match y 42 | (case default false) 43 | (case A true))) 44 | (case B 45 | (match y 46 | (case default false) 47 | (case B true))) 48 | (case C 49 | (match y 50 | (case default false) 51 | (case C true))))) 52 | (define-fun-rec 53 | eps 54 | ((x R)) Bool 55 | (match x 56 | (case default false) 57 | (case Eps true) 58 | (case (+2 p q) (or (eps p) (eps q))) 59 | (case (>2 r q2) (and (eps r) (eps q2))) 60 | (case (Star y) true))) 61 | (define-fun-rec 62 | okay 63 | ((x R)) Bool 64 | (match x 65 | (case default true) 66 | (case (+2 p q) (and (okay p) (okay q))) 67 | (case (>2 r q2) (and (okay r) (okay q2))) 68 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 69 | (define-fun-rec 70 | step 71 | ((x R) (y T)) R 72 | (match x 73 | (case default Nil22) 74 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 75 | (case (+2 p q) (+2 (step p y) (step q y))) 76 | (case (>2 r q2) 77 | (ite 78 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 79 | (+2 (>2 (step r y) q2) Nil22))) 80 | (case (Star p2) (>2 (step p2 y) x)))) 81 | (define-fun-rec 82 | rec 83 | ((x R) (y list)) Bool 84 | (match y 85 | (case Nil (eps x)) 86 | (case (Cons z xs) (rec (step x z) xs)))) 87 | (define-funs-rec 88 | ((reck2 ((p R) (q R) (x list2)) list3) 89 | (reck ((x R) (y list)) Bool)) 90 | ((match x 91 | (case Nil2 Nil3) 92 | (case (Cons2 y z) 93 | (match y 94 | (case (Pair2 l r) 95 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 96 | (match x 97 | (case Nil22 false) 98 | (case Eps 99 | (match y 100 | (case Nil true) 101 | (case (Cons z x2) false))) 102 | (case (Atom c) 103 | (match y 104 | (case Nil false) 105 | (case (Cons b2 x3) 106 | (match x3 107 | (case Nil (eqT c b2)) 108 | (case (Cons x4 x5) false))))) 109 | (case (+2 p q) (or (reck p y) (reck q y))) 110 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 111 | (case (Star p2) 112 | (match y 113 | (case Nil true) 114 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 115 | (assert-not 116 | (forall ((p R)) (not (rec p (Cons A (Cons B (Cons B Nil))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_1.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not (rec p (Cons A (Cons B (Cons A (Cons B Nil)))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_10.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R) (q R) (s list)) 116 | (=> (rec (Star (+2 p q)) s) (rec (+2 (Star p) (Star q)) s)))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_11.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R) (q R) (s list)) 116 | (=> (rec (+2 (Star p) (Star q)) s) (rec (Star (+2 p q)) s)))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not (rec p (Cons A (Cons A (Cons B (Cons B Nil)))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_3.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not (rec p (Cons A (Cons B (Cons B (Cons A Nil)))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_4.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not (rec p (Cons A (Cons B (Cons A (Cons B (Cons A Nil))))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_5.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not (rec p (Cons A (Cons B (Cons A (Cons B (Cons B Nil))))))))) 117 | (check-sat) 118 | -------------------------------------------------------------------------------- /examples/regex/regex_6.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R)) 116 | (not 117 | (rec p 118 | (Cons A (Cons B (Cons A (Cons B (Cons A (Cons B Nil)))))))))) 119 | (check-sat) 120 | -------------------------------------------------------------------------------- /examples/regex/regex_7.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | (declare-datatypes () 3 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 4 | (declare-datatypes () ((T (A) (B) (C)))) 5 | (declare-datatypes () 6 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 7 | (declare-datatypes () 8 | ((R (Nil22) 9 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 10 | (Star (Star_0 R))))) 11 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 12 | (declare-datatypes () 13 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 14 | (define-fun-rec 15 | splits2 16 | ((x T) (y list2)) list2 17 | (match y 18 | (case Nil2 Nil2) 19 | (case (Cons2 z x2) 20 | (match z 21 | (case (Pair2 bs cs) 22 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 23 | (define-fun-rec 24 | splits 25 | ((x list)) list2 26 | (match x 27 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 28 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 29 | (define-fun-rec 30 | ors 31 | ((x list3)) Bool 32 | (match x 33 | (case Nil3 false) 34 | (case (Cons3 y xs) (or y (ors xs))))) 35 | (define-fun 36 | eqT 37 | ((x T) (y T)) Bool 38 | (match x 39 | (case A 40 | (match y 41 | (case default false) 42 | (case A true))) 43 | (case B 44 | (match y 45 | (case default false) 46 | (case B true))) 47 | (case C 48 | (match y 49 | (case default false) 50 | (case C true))))) 51 | (define-fun-rec 52 | eps 53 | ((x R)) Bool 54 | (match x 55 | (case default false) 56 | (case Eps true) 57 | (case (+2 p q) (or (eps p) (eps q))) 58 | (case (>2 r q2) (and (eps r) (eps q2))) 59 | (case (Star y) true))) 60 | (define-fun-rec 61 | okay 62 | ((x R)) Bool 63 | (match x 64 | (case default true) 65 | (case (+2 p q) (and (okay p) (okay q))) 66 | (case (>2 r q2) (and (okay r) (okay q2))) 67 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 68 | (define-fun-rec 69 | step 70 | ((x R) (y T)) R 71 | (match x 72 | (case default Nil22) 73 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 74 | (case (+2 p q) (+2 (step p y) (step q y))) 75 | (case (>2 r q2) 76 | (ite 77 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 78 | (+2 (>2 (step r y) q2) Nil22))) 79 | (case (Star p2) (>2 (step p2 y) x)))) 80 | (define-fun-rec 81 | rec 82 | ((x R) (y list)) Bool 83 | (match y 84 | (case Nil (eps x)) 85 | (case (Cons z xs) (rec (step x z) xs)))) 86 | (define-funs-rec 87 | ((reck2 ((p R) (q R) (x list2)) list3) 88 | (reck ((x R) (y list)) Bool)) 89 | ((match x 90 | (case Nil2 Nil3) 91 | (case (Cons2 y z) 92 | (match y 93 | (case (Pair2 l r) 94 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 95 | (match x 96 | (case Nil22 false) 97 | (case Eps 98 | (match y 99 | (case Nil true) 100 | (case (Cons z x2) false))) 101 | (case (Atom c) 102 | (match y 103 | (case Nil false) 104 | (case (Cons b2 x3) 105 | (match x3 106 | (case Nil (eqT c b2)) 107 | (case (Cons x4 x5) false))))) 108 | (case (+2 p q) (or (reck p y) (reck q y))) 109 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 110 | (case (Star p2) 111 | (match y 112 | (case Nil true) 113 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 114 | (assert-not 115 | (forall ((p R) (q R) (a T) (b T)) 116 | (= (rec (>2 p q) (Cons a (Cons b Nil))) 117 | (rec (>2 q p) (Cons a (Cons b Nil)))))) 118 | (check-sat) 119 | -------------------------------------------------------------------------------- /examples/regex/regex_8.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | (declare-datatypes () 4 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 5 | (declare-datatypes () ((T (A) (B) (C)))) 6 | (declare-datatypes () 7 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 8 | (declare-datatypes () 9 | ((R (Nil22) 10 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 11 | (Star (Star_0 R))))) 12 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 13 | (declare-datatypes () 14 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 15 | (define-fun-rec 16 | splits2 17 | ((x T) (y list2)) list2 18 | (match y 19 | (case Nil2 Nil2) 20 | (case (Cons2 z x2) 21 | (match z 22 | (case (Pair2 bs cs) 23 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 24 | (define-fun-rec 25 | splits 26 | ((x list)) list2 27 | (match x 28 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 29 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 30 | (define-fun-rec 31 | ors 32 | ((x list3)) Bool 33 | (match x 34 | (case Nil3 false) 35 | (case (Cons3 y xs) (or y (ors xs))))) 36 | (define-fun 37 | eqT 38 | ((x T) (y T)) Bool 39 | (match x 40 | (case A 41 | (match y 42 | (case default false) 43 | (case A true))) 44 | (case B 45 | (match y 46 | (case default false) 47 | (case B true))) 48 | (case C 49 | (match y 50 | (case default false) 51 | (case C true))))) 52 | (define-fun-rec 53 | eps 54 | ((x R)) Bool 55 | (match x 56 | (case default false) 57 | (case Eps true) 58 | (case (+2 p q) (or (eps p) (eps q))) 59 | (case (>2 r q2) (and (eps r) (eps q2))) 60 | (case (Star y) true))) 61 | (define-fun-rec 62 | okay 63 | ((x R)) Bool 64 | (match x 65 | (case default true) 66 | (case (+2 p q) (and (okay p) (okay q))) 67 | (case (>2 r q2) (and (okay r) (okay q2))) 68 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 69 | (define-fun-rec 70 | step 71 | ((x R) (y T)) R 72 | (match x 73 | (case default Nil22) 74 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 75 | (case (+2 p q) (+2 (step p y) (step q y))) 76 | (case (>2 r q2) 77 | (ite 78 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 79 | (+2 (>2 (step r y) q2) Nil22))) 80 | (case (Star p2) (>2 (step p2 y) x)))) 81 | (define-fun-rec 82 | rec 83 | ((x R) (y list)) Bool 84 | (match y 85 | (case Nil (eps x)) 86 | (case (Cons z xs) (rec (step x z) xs)))) 87 | (define-funs-rec 88 | ((reck2 ((p R) (q R) (x list2)) list3) 89 | (reck ((x R) (y list)) Bool)) 90 | ((match x 91 | (case Nil2 Nil3) 92 | (case (Cons2 y z) 93 | (match y 94 | (case (Pair2 l r) 95 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 96 | (match x 97 | (case Nil22 false) 98 | (case Eps 99 | (match y 100 | (case Nil true) 101 | (case (Cons z x2) false))) 102 | (case (Atom c) 103 | (match y 104 | (case Nil false) 105 | (case (Cons b2 x3) 106 | (match x3 107 | (case Nil (eqT c b2)) 108 | (case (Cons x4 x5) false))))) 109 | (case (+2 p q) (or (reck p y) (reck q y))) 110 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 111 | (case (Star p2) 112 | (match y 113 | (case Nil true) 114 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 115 | (assert-not 116 | (forall ((p R) (q R) (s list)) 117 | (= (rec (>2 p q) s) (rec (>2 q p) s)))) 118 | (check-sat) 119 | -------------------------------------------------------------------------------- /examples/regex/regex_9.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | (declare-datatypes () 4 | ((list3 (Nil3) (Cons3 (Cons_03 Bool) (Cons_13 list3))))) 5 | (declare-datatypes () ((T (A) (B) (C)))) 6 | (declare-datatypes () 7 | ((list (Nil) (Cons (Cons_0 T) (Cons_1 list))))) 8 | (declare-datatypes () 9 | ((R (Nil22) 10 | (Eps) (Atom (Atom_0 T)) (+2 (+_0 R) (+_1 R)) (>2 (>_0 R) (>_1 R)) 11 | (Star (Star_0 R))))) 12 | (declare-datatypes () ((Pair (Pair2 (first list) (second list))))) 13 | (declare-datatypes () 14 | ((list2 (Nil2) (Cons2 (Cons_02 Pair) (Cons_12 list2))))) 15 | (define-fun-rec 16 | splits2 17 | ((x T) (y list2)) list2 18 | (match y 19 | (case Nil2 Nil2) 20 | (case (Cons2 z x2) 21 | (match z 22 | (case (Pair2 bs cs) 23 | (Cons2 (Pair2 (Cons x bs) cs) (splits2 x x2))))))) 24 | (define-fun-rec 25 | splits 26 | ((x list)) list2 27 | (match x 28 | (case Nil (Cons2 (Pair2 Nil Nil) Nil2)) 29 | (case (Cons y xs) (Cons2 (Pair2 Nil x) (splits2 y (splits xs)))))) 30 | (define-fun-rec 31 | ors 32 | ((x list3)) Bool 33 | (match x 34 | (case Nil3 false) 35 | (case (Cons3 y xs) (or y (ors xs))))) 36 | (define-fun 37 | eqT 38 | ((x T) (y T)) Bool 39 | (match x 40 | (case A 41 | (match y 42 | (case default false) 43 | (case A true))) 44 | (case B 45 | (match y 46 | (case default false) 47 | (case B true))) 48 | (case C 49 | (match y 50 | (case default false) 51 | (case C true))))) 52 | (define-fun-rec 53 | eps 54 | ((x R)) Bool 55 | (match x 56 | (case default false) 57 | (case Eps true) 58 | (case (+2 p q) (or (eps p) (eps q))) 59 | (case (>2 r q2) (and (eps r) (eps q2))) 60 | (case (Star y) true))) 61 | (define-fun-rec 62 | okay 63 | ((x R)) Bool 64 | (match x 65 | (case default true) 66 | (case (+2 p q) (and (okay p) (okay q))) 67 | (case (>2 r q2) (and (okay r) (okay q2))) 68 | (case (Star p2) (and (okay p2) (not (eps p2)))))) 69 | (define-fun-rec 70 | step 71 | ((x R) (y T)) R 72 | (match x 73 | (case default Nil22) 74 | (case (Atom b) (ite (eqT b y) Eps Nil22)) 75 | (case (+2 p q) (+2 (step p y) (step q y))) 76 | (case (>2 r q2) 77 | (ite 78 | (eps r) (+2 (>2 (step r y) q2) (step q2 y)) 79 | (+2 (>2 (step r y) q2) Nil22))) 80 | (case (Star p2) (>2 (step p2 y) x)))) 81 | (define-fun-rec 82 | rec 83 | ((x R) (y list)) Bool 84 | (match y 85 | (case Nil (eps x)) 86 | (case (Cons z xs) (rec (step x z) xs)))) 87 | (define-funs-rec 88 | ((reck2 ((p R) (q R) (x list2)) list3) 89 | (reck ((x R) (y list)) Bool)) 90 | ((match x 91 | (case Nil2 Nil3) 92 | (case (Cons2 y z) 93 | (match y 94 | (case (Pair2 l r) 95 | (Cons3 (and (reck p l) (rec q r)) (reck2 p q z)))))) 96 | (match x 97 | (case Nil22 false) 98 | (case Eps 99 | (match y 100 | (case Nil true) 101 | (case (Cons z x2) false))) 102 | (case (Atom c) 103 | (match y 104 | (case Nil false) 105 | (case (Cons b2 x3) 106 | (match x3 107 | (case Nil (eqT c b2)) 108 | (case (Cons x4 x5) false))))) 109 | (case (+2 p q) (or (reck p y) (reck q y))) 110 | (case (>2 r q2) (ors (reck2 r q2 (splits y)))) 111 | (case (Star p2) 112 | (match y 113 | (case Nil true) 114 | (case (Cons x6 x7) (and (not (eps p2)) (rec (>2 p2 x) y)))))))) 115 | (assert-not 116 | (forall ((p R) (q R) (s list)) 117 | (= (rec (Star (+2 p q)) s) (rec (+2 (Star p) (Star q)) s)))) 118 | (check-sat) 119 | -------------------------------------------------------------------------------- /examples/regression/bad_model.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | 3 | (declare-sort a_ 0) 4 | (declare-datatypes 5 | () 6 | ((list_ (Nil_) 7 | (Cons_ (select-Cons_-0 a_) (select-Cons_-1 list_))))) 8 | (declare-fun xs_ () list_) 9 | (define-fun-rec 10 | append_ ((list__0 list_) (list__1_0 list_)) list_ 11 | (match list__0 12 | (case (Cons_ a__0 list__1) (Cons_ a__0 (append_ list__1 list__1_0))) 13 | (case Nil_ list__1_0))) 14 | (define-fun-rec 15 | rev_ ((list__0_0 list_)) list_ 16 | (match list__0_0 17 | (case (Cons_ a__0_0 list__1_1) 18 | (append_ (rev_ list__1_1) (Cons_ a__0_0 Nil_))) 19 | (case Nil_ Nil_))) 20 | (assert-not (or (not (= (rev_ (rev_ xs_)) xs_)) (= xs_ Nil_))) 21 | (check-sat) 22 | 23 | -------------------------------------------------------------------------------- /examples/regression/bad_model2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | 3 | (declare-datatypes () ((nat (zero) 4 | (Suc (select-Suc-0 nat))))) 5 | (declare-datatypes () ((prod (Pair (select-Pair-0 nat) (select-Pair-1 nat))))) 6 | (declare-sort int 0) 7 | (declare-fun AbsInteg (prod) int) 8 | (declare-fun RepInteg (int) prod) 9 | (assert (forall ((a int)) (= a (AbsInteg (RepInteg a))))) 10 | (define-fun-rec 11 | plus ((nat_0 nat) (nat_1 nat)) nat 12 | (match nat_0 13 | (case (Suc nat_0_0) (Suc (plus nat_0_0 nat_1))) 14 | (case zero nat_1))) 15 | (define-fun-rec 16 | intrel ((prod_0 prod) (prod_1 prod)) Bool 17 | (@ 18 | (match prod_0 19 | (case (Pair x __0) 20 | (lambda ((uu2 prod)) 21 | (match uu2 22 | (case (Pair __1 __2) (= (plus __1 __2) (plus x __0))))))) 23 | prod_1)) 24 | (assert (forall ((a_0 int)) (intrel (RepInteg a_0) (RepInteg a_0)))) 25 | (define-fun-rec 26 | intrel_0 ((prod_0_0 prod) (prod_1_0 prod)) Bool 27 | (@ 28 | (match prod_0_0 29 | (case (Pair __3 __4) 30 | (lambda ((uu2_0 prod)) 31 | (match uu2_0 32 | (case (Pair __5 __6) (= (plus __5 __6) (plus __3 __4))))))) 33 | prod_1_0)) 34 | (assert 35 | (forall 36 | ((a_1 int)) 37 | (forall ((b int)) (=> (intrel_0 (RepInteg a_1) (RepInteg b)) (= a_1 b))))) 38 | (declare-datatypes () ((unit (Unity)))) 39 | (declare-datatypes 40 | () 41 | ((point2dext 42 | (point2dext1 (select-point2dext1-0 int) (select-point2dext1-1 int) 43 | (select-point2dext1-2 unit))))) 44 | (declare-fun x () int) 45 | (declare-fun p () point2dext) 46 | (declare-fun y () int) 47 | (define-fun-rec 48 | xcupdate_spec_0 ((point2dext_1 point2dext)) point2dext 49 | (match point2dext_1 50 | (case (point2dext1 int_0 int_1 unit_2) 51 | (point2dext1 (@ (lambda ((uu int)) x) int_0) int_1 unit_2)))) 52 | (assert-not (= (point2dext1 x y Unity) (xcupdate_spec_0 p))) 53 | (check-sat) 54 | 55 | -------------------------------------------------------------------------------- /examples/regression/bad_model3.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | 3 | (declare-sort i 0) 4 | (assert (exists ((x_0 i)) (exists ((x_1 i)) (not (= x_0 x_1))))) 5 | (assert 6 | (exists 7 | ((x_0_0 i)) 8 | (exists 9 | ((x_1_0 i)) 10 | (exists 11 | ((x_2 i)) 12 | (forall ((y i)) (or (= x_0_0 y) (= x_1_0 y) (= x_2 y))))))) 13 | (declare-fun i2 () i) 14 | (declare-fun i1 () i) 15 | (declare-fun i3 () i) 16 | (assert (and (not (= i1 i2)) (not (= i2 i3)) (not (= i1 i3)))) 17 | (check-sat) 18 | -------------------------------------------------------------------------------- /examples/regression/bug1.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | (declare-sort iota 0) 4 | (declare-datatypes 5 | () 6 | ((list_iota 7 | (cons_iota (cons_iota_0 iota) (cons_iota_1 list_iota)) 8 | (nil_iota)))) 9 | (declare-datatypes () ((nat (z) 10 | (s (s_0 nat))))) 11 | (define-fun-rec 12 | take_iota ((v_0 nat) (l list_iota)) list_iota 13 | (match v_0 14 | (case (s n) 15 | (match l 16 | (case nil_iota nil_iota) 17 | (case (cons_iota x l_0) (cons_iota x (take_iota n l_0))))) 18 | (case z nil_iota))) 19 | (declare-fun nun_sk_0 () list_iota) 20 | (declare-fun nun_sk_1 () iota) 21 | (declare-fun nun_sk_2 () iota) 22 | (declare-fun nun_sk_3 () iota) 23 | (declare-fun nun_sk_4 () list_iota) 24 | (assert-not 25 | (not (= (take_iota (s (s (s z))) nun_sk_0) 26 | (cons_iota nun_sk_1 (cons_iota nun_sk_2 (cons_iota nun_sk_3 nun_sk_4)))))) 27 | 28 | -------------------------------------------------------------------------------- /examples/regression/bug2.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: SAT 3 | 4 | ; model is not specified enough 5 | 6 | (declare-datatypes () ((a (ZeroA) 7 | (SuccA (PredA a))))) 8 | (declare-fun y () a) 9 | (declare-fun x () a) 10 | (assert (not (= x y))) 11 | (declare-datatypes () ((list (Nil) 12 | (Cons (Cons_0 a) (Cons_1 list))))) 13 | (declare-datatypes () ((prod (Pair (Pair_0 a) (Pair_1 a))))) 14 | (declare-datatypes () ((plist (PNil) 15 | (PCons (PCons_0 prod) (PCons_1 plist))))) 16 | (declare-fun xs () list) 17 | (declare-fun ys () list) 18 | (define-fun-rec 19 | zip ((xs_0 list) (ys_0 list)) plist 20 | (match xs_0 21 | (case (Cons x __1) 22 | (match ys_0 23 | (case (Cons __0 __2) (PCons (Pair x __0) (zip __1 __2))) 24 | (case Nil PNil))) 25 | (case Nil PNil))) 26 | (define-fun-rec 27 | append ((xs_1 list) (ys_1 list)) list 28 | (match xs_1 29 | (case (Cons __3 __4) (Cons __3 (append __4 ys_1))) 30 | (case Nil ys_1))) 31 | (define-fun-rec 32 | rev ((xs_2 list)) list 33 | (match xs_2 34 | (case (Cons __6 __5) (append (rev __5) (Cons __6 Nil))) 35 | (case Nil Nil))) 36 | (assert-not (= (zip (Cons x xs) ys) (zip (rev (Cons x xs)) (rev ys)))) 37 | 38 | -------------------------------------------------------------------------------- /examples/regression/bug3.smt2: -------------------------------------------------------------------------------- 1 | (declare-datatypes () ((nat (s (select_s_0 nat)) 2 | (z)))) 3 | (define-funs-rec 4 | ((plus ((x nat) (y nat)) nat)) 5 | ((match x (case (s x2) (s (plus x2 y))) 6 | (case z y)))) 7 | (define-funs-rec 8 | ((mult ((x_1 nat) (y_1 nat)) nat)) 9 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 10 | (case z z)))) 11 | (define-funs-rec 12 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 13 | ((match x_2 14 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 15 | (case z false))) 16 | (case z true)))) 17 | (declare-datatypes 18 | () 19 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 20 | (nil)))) 21 | (define-funs-rec 22 | ((append ((x_3 list) (y_3 list)) list)) 23 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 24 | (case nil y_3)))) 25 | (define-funs-rec 26 | ((rev ((l list)) list)) 27 | ((match l 28 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 29 | (case nil nil)))) 30 | (define-funs-rec 31 | ((length ((l_1 list)) nat)) 32 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 33 | (case nil z)))) 34 | (define-funs-rec 35 | ((sum ((l_2 list)) nat)) 36 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 37 | (case nil z)))) 38 | (define-funs-rec 39 | ((sorted ((l_3 list)) Bool)) 40 | ((match l_3 41 | (case (cons x_7 l2) 42 | (match l2 43 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 44 | (case nil true))) 45 | (case nil true)))) 46 | (define-funs-rec 47 | ((map ((f (=> nat nat)) (l_4 list)) list)) 48 | ((match l_4 49 | (case (cons x_8 tail_3) (cons (f x_8) (map f tail_3))) 50 | (case nil nil)))) 51 | (define-funs-rec ((num_1 () nat)) ((s z))) 52 | (define-funs-rec ((num_2 () nat)) ((s (s z)))) 53 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 54 | (define-funs-rec ((num_10 () nat)) ((mult num_2 num_5))) 55 | (assert-not 56 | (forall 57 | ((l_5 list)) 58 | (not (and 59 | (and (= (length l_5) num_2) (= (sum l_5) (plus num_10 num_5))) 60 | (= (rev l_5) l_5)))))(check-sat) 61 | 62 | ;expect: unsat 63 | -------------------------------------------------------------------------------- /examples/regression/bug4.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; generated by nunchaku 4 | (declare-datatypes 5 | () 6 | ((pos_num (B_one) 7 | (Bit1 (Bit1_0 pos_num)) 8 | (Bit0 (Bit0_0 pos_num))))) 9 | (declare-datatypes 10 | () 11 | ((b_int (B_0) 12 | (B_pos (B_pos_0 pos_num)) 13 | (B_neg (B_neg_0 pos_num))))) 14 | (declare-fun nun_sk_0 () b_int) 15 | (define-fun-rec 16 | pos_plus ((v_0 pos_num) (v_1 pos_num)) pos_num 17 | (match v_0 18 | (case (Bit0 x) 19 | (match v_1 20 | (case (Bit0 y) (Bit0 (pos_plus x y))) 21 | (case (Bit1 y_0) (Bit1 (pos_plus x y_0))) 22 | (case B_one (Bit1 x)))) 23 | (case (Bit1 x_0) 24 | (match v_1 25 | (case (Bit0 y_1) (Bit1 (pos_plus x_0 y_1))) 26 | (case (Bit1 y_2) (Bit0 (pos_plus B_one (pos_plus x_0 y_2)))) 27 | (case B_one (Bit0 (pos_plus B_one x_0))))) 28 | (case B_one 29 | (match v_1 30 | (case (Bit0 x_1) (Bit1 x_1)) 31 | (case (Bit1 x_2) (Bit0 (pos_plus B_one x_2))) 32 | (case B_one (Bit0 B_one)))))) 33 | (define-fun-rec 34 | pos_mult ((x_3 pos_num) (x_4 pos_num)) pos_num 35 | (match x_3 36 | (case (Bit0 x_5) 37 | (match x_4 38 | (case (Bit0 y_3) (Bit0 (Bit0 (pos_mult x_5 y_3)))) 39 | (case (Bit1 y_4) (Bit0 (pos_mult x_5 (Bit1 y_4)))) 40 | (case B_one x_3))) 41 | (case (Bit1 x_6) 42 | (match x_4 43 | (case (Bit0 y_5) (Bit0 (pos_mult (Bit1 x_6) y_5))) 44 | (case (Bit1 y_6) 45 | (Bit1 (pos_plus x_6 (pos_plus y_6 (Bit0 (pos_mult x_6 y_6)))))) 46 | (case B_one x_3))) 47 | (case B_one 48 | (match x_4 49 | (case (Bit0 v_0_0) x_4) 50 | (case (Bit1 v_0_1) x_4) 51 | (case B_one x_4))))) 52 | (define-fun-rec 53 | b_mult ((x_7 b_int) (x_8 b_int)) b_int 54 | (match x_7 55 | (case (B_neg x_9) 56 | (match x_8 57 | (case (B_neg y_7) (B_pos (pos_mult x_9 y_7))) 58 | (case (B_pos y_8) (B_neg (pos_mult x_9 y_8))) 59 | (case B_0 B_0))) 60 | (case (B_pos x_10) 61 | (match x_8 62 | (case (B_neg y_9) (B_neg (pos_mult x_10 y_9))) 63 | (case (B_pos y_10) (B_pos (pos_mult x_10 y_10))) 64 | (case B_0 B_0))) 65 | (case B_0 66 | (match x_8 67 | (case (B_neg v_0_2) B_0) 68 | (case (B_pos v_0_3) B_0) 69 | (case B_0 B_0))))) 70 | (define-fun-rec b_5 () b_int (B_pos (Bit1 (Bit0 B_one)))) 71 | (define-fun-rec 72 | b_positive ((v_0_4 b_int)) Bool 73 | (match v_0_4 74 | (case (B_neg x_11) false) 75 | (case (B_pos x_12) true) 76 | (case B_0 true))) 77 | (assert-not 78 | (or 79 | (not (= (b_mult nun_sk_0 nun_sk_0) (b_mult b_5 b_5))) 80 | (not (b_positive nun_sk_0)))) 81 | 82 | -------------------------------------------------------------------------------- /examples/regression/bug5.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | 3 | (declare-sort i 0) 4 | (declare-fun i2 () i) 5 | (declare-fun i1 () i) 6 | (declare-fun i3 () i) 7 | (assert (and (not (= i1 i2)) (not (= i2 i3)) (not (= i1 i3)))) 8 | (check-sat) 9 | 10 | 11 | -------------------------------------------------------------------------------- /examples/regression/bug5_simple.smt2: -------------------------------------------------------------------------------- 1 | ; expect: sat 2 | 3 | (declare-sort i 0) 4 | (declare-fun a () i) 5 | (declare-fun b () i) 6 | (assert (not (= a b))) 7 | (check-sat) 8 | 9 | 10 | -------------------------------------------------------------------------------- /examples/regression/card_constraints.smt2: -------------------------------------------------------------------------------- 1 | ; expect: UNSAT 2 | 3 | ; two cardinality constraints that express that `i` has at most 2 4 | ; elements, and at least 3 elements 5 | 6 | (declare-sort i 0) 7 | 8 | ; max card: 2 9 | (declare-fun a () i) 10 | (declare-fun b () i) 11 | (assert (forall ((x i)) (or (= x a) (= x b)))) 12 | 13 | (declare-fun i2 () i) 14 | (declare-fun i1 () i) 15 | (declare-fun i3 () i) 16 | 17 | ; min card: 3 18 | (assert (and (not (= i1 i2)) (not (= i2 i3)) (not (= i1 i3)))) 19 | 20 | (check-sat) 21 | 22 | -------------------------------------------------------------------------------- /examples/regression/card_constraints2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: UNSAT 2 | 3 | ; two cardinality constraints that express that `i` has at most 2 4 | ; elements, and at least 3 elements 5 | 6 | ; the difference with card_constraints.smt2 is the encoding, which here 7 | ; relies on existentials 8 | 9 | (declare-sort i 0) 10 | 11 | ; max card: 2 12 | (assert 13 | (exists 14 | ((x_0 i)) 15 | (exists ((x_1 i)) (forall ((y i)) (or (= x_0 y) (= x_1 y)))))) 16 | 17 | ; min card: 3 18 | (assert 19 | (exists ((i1 i)) 20 | (exists ((i2 i)) 21 | (exists ((i3 i)) 22 | (and (not (= i1 i2)) (not (= i2 i3)) (not (= i1 i3))))))) 23 | 24 | (check-sat) 25 | 26 | -------------------------------------------------------------------------------- /examples/regression/first_order.nunchaku.smbc.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; generated by nunchaku 4 | (declare-sort list 0) 5 | (declare-sort term 0) 6 | (declare-fun cons (term list) list) 7 | (declare-fun b () term) 8 | (declare-fun a () term) 9 | (declare-fun nil () list) 10 | (assert-not (= (cons a (cons b nil)) (cons b (cons a nil)))) 11 | (check-sat) 12 | 13 | -------------------------------------------------------------------------------- /examples/regression/ho_sko.smt2: -------------------------------------------------------------------------------- 1 | 2 | (declare-datatypes () ((nat (Z) 3 | (S (s_0 nat))))) 4 | 5 | (declare-fun f (nat) Bool) 6 | 7 | (define-fun check () Bool 8 | (and (f Z) (not (f (S Z))) (f (S (S Z))))) 9 | (define-fun the-goal () Bool check) 10 | (assert (the-goal)) 11 | (check-sat) 12 | -------------------------------------------------------------------------------- /examples/regression/list_head.nunchaku.smbc.smt2: -------------------------------------------------------------------------------- 1 | ; expect: unsat 2 | 3 | ; generated by nunchaku 4 | (declare-sort tau 0) 5 | (declare-datatypes 6 | () 7 | ((list_tau 8 | (Nil_tau) 9 | (Cons_tau (select-Cons_tau-0 tau) (select-Cons_tau-1 list_tau))))) 10 | (define-fun-rec 11 | is_empty_tau ((v_0 list_tau)) Bool 12 | (match v_0 (case Nil_tau true) 13 | (case default false))) 14 | (declare-fun list_tau_to_tau (list_tau) tau) 15 | (define-fun-rec 16 | head_tau ((list_tau_0 list_tau)) tau 17 | (match list_tau_0 18 | (case (Cons_tau tau_0 list_tau_1) tau_0) 19 | (case default (list_tau_to_tau list_tau_0)))) 20 | (declare-fun l10 () list_tau) 21 | (declare-fun l21 () list_tau) 22 | (assert-not 23 | (or 24 | (not (is_empty_tau l10)) 25 | (not (is_empty_tau l21)) 26 | (= (head_tau l10) (head_tau l21)))) 27 | (check-sat) 28 | 29 | -------------------------------------------------------------------------------- /examples/rev.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; `l1 ++ l2 != l2 ++ l1` 3 | ; expect: SAT 4 | 5 | (data (nat z (s nat))) 6 | 7 | (data (list nil (cons nat list))) 8 | 9 | (define 10 | (append 11 | (-> list list list) 12 | (fun (x list) 13 | (fun (y list) 14 | (match 15 | x 16 | (nil y) 17 | ((cons n tail) (cons n (append tail y)))))))) 18 | 19 | (define 20 | (rev 21 | (-> list list) 22 | (fun 23 | (l list) 24 | (match 25 | l 26 | (nil nil) 27 | ((cons x xs) (append (rev xs) (cons x nil))))))) 28 | 29 | (goal ((l list)) (not (= l (rev l)))) 30 | -------------------------------------------------------------------------------- /examples/rev.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; `l1 ++ l2 != l2 ++ l1` 3 | ; expect: SAT 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (declare-datatypes 8 | () 9 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 10 | (nil)))) 11 | (define-funs-rec 12 | ((append ((x list) (y list)) list)) 13 | ((match x (case (cons n tail) (cons n (append tail y))) 14 | (case nil y)))) 15 | (define-funs-rec 16 | ((rev ((l list)) list)) 17 | ((match l 18 | (case (cons x_1 xs) (append (rev xs) (cons x_1 nil))) 19 | (case nil nil)))) 20 | (assert-not (forall ((l_1 list)) (not (not (= l_1 (rev l_1))))))(check-sat) 21 | -------------------------------------------------------------------------------- /examples/sat_solver1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; mini-sat solver 3 | ; expect: unsat 4 | 5 | (declare-datatypes () ((atom (True) (False)))) 6 | 7 | (declare-datatypes () 8 | ((form (A (bvar atom)) (And (and1 form) (and2 form)) (Not (not1 form))))) 9 | 10 | (define-fun bimply ((f1 form) (f2 form)) form 11 | (Not (And f1 (Not f2)))) 12 | 13 | (define-fun-rec eval ((f form)) Bool 14 | (match f 15 | (case (A atom) 16 | (match atom (case True true) (case False false))) 17 | (case False false) 18 | (case (Not f) (not (eval f))) 19 | (case (And f1 f2) (and (eval f1) (eval f2))))) 20 | 21 | (assert-not 22 | (forall ((a atom) (b atom)) 23 | (eval (bimply (bimply (A a) (A b)) (bimply (Not (A b)) (Not (A a))))))) 24 | 25 | 26 | -------------------------------------------------------------------------------- /examples/slow_hotel.nunchaku.smbc.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; expect: sat 3 | ; generated by nunchaku 4 | (declare-datatypes () ((state (S1) 5 | (S2) 6 | (S3) 7 | (S4) 8 | (S5) 9 | (S6)))) 10 | (declare-datatypes () ((guest (G1) 11 | (G2)))) 12 | (declare-datatypes () ((option (None) 13 | (Some (select-Some-0 guest))))) 14 | (declare-datatypes () ((room (R1)))) 15 | (declare-fun owns (state room) option) 16 | (declare-datatypes () ((key (K1) 17 | (K2) 18 | (K3) 19 | (K4)))) 20 | (declare-fun currk (state room) key) 21 | (declare-fun issued (state key) Bool) 22 | (declare-datatypes () ((card (C1) 23 | (C2) 24 | (C3) 25 | (C4) 26 | (C5)))) 27 | (declare-fun cards (state guest card) Bool) 28 | (declare-fun roomk (state room) key) 29 | (declare-fun isin (state room guest) Bool) 30 | (declare-fun safe (state room) Bool) 31 | (declare-fun next (state state) Bool) 32 | (assert 33 | (forall 34 | ((s1 state)) 35 | (forall 36 | ((sH state)) 37 | (= (next s1 sH) 38 | (or 39 | (and (= s1 S1) (= sH S2)) 40 | (and (= s1 S2) (= sH S3)) 41 | (and (= s1 S3) (= sH S4)) 42 | (and (= s1 S4) (= sH S5)) 43 | (and (= s1 S5) (= sH S6))))))) 44 | (declare-fun reachH (state) Bool) 45 | (declare-fun fst (card) key) 46 | (declare-fun snd (card) key) 47 | (declare-fun buggy () Bool) 48 | (declare-fun s10 (state) state) 49 | (declare-fun r11 (key state) room) 50 | (declare-fun s12 (state) state) 51 | (declare-fun sH3 (state) state) 52 | (declare-fun K4_0 (state) key) 53 | (declare-fun C5_0 (state) card) 54 | (declare-fun R6 (state) room) 55 | (declare-fun G7 (state) guest) 56 | (declare-fun s18 (state) state) 57 | (declare-fun sH9 (state) state) 58 | (declare-fun G10 (state) guest) 59 | (declare-fun C11 (state) card) 60 | (declare-fun K12 (state) key) 61 | (declare-fun KH13 (state) key) 62 | (declare-fun r114 (state) room) 63 | (declare-fun R15 (state) room) 64 | (declare-fun rb16 (room state) room) 65 | (declare-fun g117 (room state) guest) 66 | (declare-fun s118 (state) state) 67 | (declare-fun sH19 (state) state) 68 | (declare-fun R20 (state) room) 69 | (declare-fun G21 (state) guest) 70 | (assert 71 | (forall 72 | ((a state)) 73 | (=> (reachH a) 74 | (or 75 | (and 76 | (= a (s10 a)) 77 | (= (s10 a) S1) 78 | (forall ((r1 room)) (= (owns (s10 a) r1) None)) 79 | (forall 80 | ((r1_0 room)) 81 | (forall 82 | ((rH room)) 83 | (=> (= (currk (s10 a) r1_0) (currk (s10 a) rH)) (= r1_0 rH)))) 84 | (forall 85 | ((k key)) 86 | (and 87 | (=> (issued (s10 a) k) (= (currk (s10 a) (r11 k a)) k)) 88 | (=> (exists ((r1_1 room)) (= (currk (s10 a) r1_1) k)) 89 | (issued (s10 a) k)))) 90 | (forall ((g1 guest)) (forall ((c card)) (not (cards (s10 a) g1 c)))) 91 | (forall ((r1_2 room)) (= (roomk (s10 a) r1_2) (currk (s10 a) r1_2))) 92 | (forall 93 | ((r1_3 room)) 94 | (forall ((g1_0 guest)) (not (isin (s10 a) r1_3 g1_0)))) 95 | (forall ((r1_4 room)) (safe (s10 a) r1_4))) 96 | (and 97 | (= a (sH3 a)) 98 | (next (s12 a) (sH3 a)) 99 | (reachH (s12 a)) 100 | (not (issued (s12 a) (K4_0 a))) 101 | (= (fst (C5_0 a)) (currk (s12 a) (R6 a))) 102 | (= (snd (C5_0 a)) (K4_0 a)) 103 | (forall 104 | ((r1_5 room)) 105 | (= (owns (sH3 a) r1_5) 106 | (ite (= r1_5 (R6 a)) (Some (G7 a)) (owns (s12 a) r1_5)))) 107 | (forall 108 | ((r1_6 room)) 109 | (= (currk (sH3 a) r1_6) 110 | (ite (= r1_6 (R6 a)) (K4_0 a) (currk (s12 a) r1_6)))) 111 | (forall 112 | ((k_0 key)) 113 | (and 114 | (=> (issued (sH3 a) k_0) 115 | (or (= k_0 (K4_0 a)) (issued (s12 a) k_0))) 116 | (=> (or (= k_0 (K4_0 a)) (issued (s12 a) k_0)) 117 | (issued (sH3 a) k_0)))) 118 | (forall 119 | ((g1_1 guest)) 120 | (forall 121 | ((c_0 card)) 122 | (and 123 | (=> (cards (sH3 a) g1_1 c_0) 124 | (or 125 | (and (= g1_1 (G7 a)) (= c_0 (C5_0 a))) 126 | (cards (s12 a) g1_1 c_0))) 127 | (=> 128 | (or 129 | (and (= g1_1 (G7 a)) (= c_0 (C5_0 a))) 130 | (cards (s12 a) g1_1 c_0)) 131 | (cards (sH3 a) g1_1 c_0))))) 132 | (forall ((r1_7 room)) (= (roomk (sH3 a) r1_7) (roomk (s12 a) r1_7))) 133 | (forall 134 | ((r1_8 room)) 135 | (forall 136 | ((g1_2 guest)) 137 | (and 138 | (=> (isin (sH3 a) r1_8 g1_2) (isin (s12 a) r1_8 g1_2)) 139 | (=> (isin (s12 a) r1_8 g1_2) (isin (sH3 a) r1_8 g1_2))))) 140 | (forall 141 | ((r1_9 room)) 142 | (and 143 | (=> (safe (sH3 a) r1_9) 144 | (and (not (= r1_9 (R6 a))) (safe (s12 a) r1_9))) 145 | (=> (and (not (= r1_9 (R6 a))) (safe (s12 a) r1_9)) 146 | (safe (sH3 a) r1_9))))) 147 | (and 148 | (= a (sH9 a)) 149 | (next (s18 a) (sH9 a)) 150 | (reachH (s18 a)) 151 | (cards (s18 a) (G10 a) (C11 a)) 152 | (= (fst (C11 a)) (K12 a)) 153 | (= (snd (C11 a)) (KH13 a)) 154 | (or 155 | (= (roomk (s18 a) (r114 a)) (K12 a)) 156 | (= (roomk (s18 a) (r114 a)) (KH13 a))) 157 | (forall ((ra room)) (= (owns (sH9 a) ra) (owns (s18 a) ra))) 158 | (forall ((ra_0 room)) (= (currk (sH9 a) ra_0) (currk (s18 a) ra_0))) 159 | (forall 160 | ((k_1 key)) 161 | (and 162 | (=> (issued (sH9 a) k_1) (issued (s18 a) k_1)) 163 | (=> (issued (s18 a) k_1) (issued (sH9 a) k_1)))) 164 | (forall 165 | ((g1_3 guest)) 166 | (forall 167 | ((c_1 card)) 168 | (and 169 | (=> (cards (sH9 a) g1_3 c_1) (cards (s18 a) g1_3 c_1)) 170 | (=> (cards (s18 a) g1_3 c_1) (cards (sH9 a) g1_3 c_1))))) 171 | (forall 172 | ((ra_1 room)) 173 | (= (roomk (sH9 a) ra_1) 174 | (ite (= ra_1 (R15 a)) (KH13 a) (roomk (s18 a) ra_1)))) 175 | (forall 176 | ((ra_2 room)) 177 | (forall 178 | ((g1_4 guest)) 179 | (and 180 | (=> (isin (sH9 a) ra_2 g1_4) 181 | (or 182 | (and (= ra_2 (R15 a)) (= g1_4 (G10 a))) 183 | (isin (s18 a) ra_2 g1_4))) 184 | (=> 185 | (or 186 | (and (= ra_2 (R15 a)) (= g1_4 (G10 a))) 187 | (isin (s18 a) ra_2 g1_4)) 188 | (isin (sH9 a) ra_2 g1_4))))) 189 | (forall 190 | ((ra_3 room)) 191 | (and 192 | (=> (safe (sH9 a) ra_3) 193 | (ite (= ra_3 (R15 a)) 194 | (or 195 | (and 196 | (= (owns (s18 a) (R15 a)) (Some (G10 a))) 197 | (forall 198 | ((rb room)) 199 | (forall ((g1_5 guest)) (not (isin (s18 a) rb g1_5)))) 200 | (or buggy (= (KH13 a) (currk (s18 a) (R15 a))))) 201 | (safe (s18 a) (R15 a))) 202 | (safe (s18 a) ra_3))) 203 | (=> 204 | (ite (= ra_3 (R15 a)) 205 | (or 206 | (and 207 | (= (owns (s18 a) (R15 a)) (Some (G10 a))) 208 | (not (isin (s18 a) (rb16 ra_3 a) (g117 ra_3 a))) 209 | (or buggy (= (KH13 a) (currk (s18 a) (R15 a))))) 210 | (safe (s18 a) (R15 a))) 211 | (safe (s18 a) ra_3)) 212 | (safe (sH9 a) ra_3))))) 213 | (and 214 | (= a (sH19 a)) 215 | (next (s118 a) (sH19 a)) 216 | (reachH (s118 a)) 217 | (isin (s118 a) (R20 a) (G21 a)) 218 | (forall ((r1_10 room)) (= (owns (sH19 a) r1_10) (owns (s118 a) r1_10))) 219 | (forall 220 | ((r1_11 room)) 221 | (= (currk (sH19 a) r1_11) (currk (s118 a) r1_11))) 222 | (forall 223 | ((k_2 key)) 224 | (and 225 | (=> (issued (sH19 a) k_2) (issued (s118 a) k_2)) 226 | (=> (issued (s118 a) k_2) (issued (sH19 a) k_2)))) 227 | (forall 228 | ((g1_6 guest)) 229 | (forall 230 | ((c_2 card)) 231 | (and 232 | (=> (cards (sH19 a) g1_6 c_2) (cards (s118 a) g1_6 c_2)) 233 | (=> (cards (s118 a) g1_6 c_2) (cards (sH19 a) g1_6 c_2))))) 234 | (forall 235 | ((r1_12 room)) 236 | (= (roomk (sH19 a) r1_12) (roomk (s118 a) r1_12))) 237 | (forall 238 | ((r1_13 room)) 239 | (forall 240 | ((g1_7 guest)) 241 | (and 242 | (=> (isin (sH19 a) r1_13 g1_7) 243 | (and 244 | (or (not (= r1_13 (R20 a))) (not (= g1_7 (G21 a)))) 245 | (isin (s118 a) r1_13 g1_7))) 246 | (=> 247 | (and 248 | (or (not (= r1_13 (R20 a))) (not (= g1_7 (G21 a)))) 249 | (isin (s118 a) r1_13 g1_7)) 250 | (isin (sH19 a) r1_13 g1_7))))) 251 | (forall 252 | ((r1_14 room)) 253 | (and 254 | (=> (safe (sH19 a) r1_14) (safe (s118 a) r1_14)) 255 | (=> (safe (s118 a) r1_14) (safe (sH19 a) r1_14))))))))) 256 | (declare-fun g () guest) 257 | (declare-fun s () state) 258 | (declare-fun r () room) 259 | (assert-not 260 | (=> (and buggy (reachH s) (safe s r) (isin s r g)) (= (owns s r) (Some g)))) 261 | (check-sat) 262 | 263 | -------------------------------------------------------------------------------- /examples/sorted.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list that is sorted, and where `sum l = 15, 3 | ; and where `6 >= len l >= 4` 4 | 5 | ; expect: SAT 6 | 7 | (include "nat.lisp") 8 | (include "list.lisp") 9 | 10 | (define (3 nat (s (s (s z))))) 11 | (define (5 nat (s (s (s (s (s z))))))) 12 | 13 | (goal 14 | ((l list)) 15 | (and 16 | (sorted l) 17 | (= (sum l) (mult 3 5)) 18 | (leq (s 3) (length l)) 19 | (leq (length l) (s 5)) 20 | )) 21 | 22 | -------------------------------------------------------------------------------- /examples/sorted.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; find a sorted list of length in [3,5] with sum 15 4 | 5 | (declare-datatypes () ((nat (s (select_s_0 nat)) 6 | (z)))) 7 | (define-funs-rec 8 | ((plus ((x nat) (y nat)) nat)) 9 | ((match x (case (s x2) (s (plus x2 y))) 10 | (case z y)))) 11 | (define-funs-rec 12 | ((mult ((x_1 nat) (y_1 nat)) nat)) 13 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 14 | (case z z)))) 15 | (define-funs-rec 16 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 17 | ((match x_2 18 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 19 | (case z false))) 20 | (case z true)))) 21 | (declare-datatypes 22 | () 23 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 24 | (nil)))) 25 | (define-funs-rec 26 | ((append ((x_3 list) (y_3 list)) list)) 27 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 28 | (case nil y_3)))) 29 | (define-funs-rec 30 | ((rev ((l list)) list)) 31 | ((match l 32 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 33 | (case nil nil)))) 34 | (define-funs-rec 35 | ((length ((l_1 list)) nat)) 36 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 37 | (case nil z)))) 38 | (define-funs-rec 39 | ((sum ((l_2 list)) nat)) 40 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 41 | (case nil z)))) 42 | (define-funs-rec 43 | ((sorted ((l_3 list)) Bool)) 44 | ((match l_3 45 | (case (cons x_7 l2) 46 | (match l2 47 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 48 | (case nil true))) 49 | (case nil true)))) 50 | (define-funs-rec ((num_3 () nat)) ((s (s (s z))))) 51 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 52 | (assert-not 53 | (forall 54 | ((l_5 list)) 55 | (not (and 56 | (and 57 | (and (sorted l_5) (= (sum l_5) (mult num_3 num_5))) 58 | (leq (s num_3) (length l_5))) 59 | (leq (length l_5) (s num_5))))))(check-sat) 60 | -------------------------------------------------------------------------------- /examples/sorted2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list that is sorted, length=3, sum=1, rev l=l 3 | 4 | ; expect: UNSAT 5 | 6 | (include "nat.lisp") 7 | (include "list.lisp") 8 | 9 | (define (3 nat (s (s (s z))))) 10 | 11 | (goal 12 | ((l list)) 13 | (and 14 | (sorted l) 15 | (= l (rev l)) 16 | (= (sum l) (s z)) 17 | (= (length l) 3) 18 | )) 19 | 20 | -------------------------------------------------------------------------------- /examples/sorted2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: UNSAT 2 | 3 | ; find a sorted list of length 3, that is a palindrome, and has sum 1 4 | ; this is impossible because the 1 should be in the middle (palindrome), 5 | ; but then the list is not sorted anymore 6 | 7 | (declare-datatypes () ((nat (s (select_s_0 nat)) 8 | (z)))) 9 | (define-funs-rec 10 | ((plus ((x nat) (y nat)) nat)) 11 | ((match x (case (s x2) (s (plus x2 y))) 12 | (case z y)))) 13 | (define-funs-rec 14 | ((mult ((x_1 nat) (y_1 nat)) nat)) 15 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 16 | (case z z)))) 17 | (define-funs-rec 18 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 19 | ((match x_2 20 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 21 | (case z false))) 22 | (case z true)))) 23 | (declare-datatypes 24 | () 25 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 26 | (nil)))) 27 | (define-funs-rec 28 | ((append ((x_3 list) (y_3 list)) list)) 29 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 30 | (case nil y_3)))) 31 | (define-funs-rec 32 | ((rev ((l list)) list)) 33 | ((match l 34 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 35 | (case nil nil)))) 36 | (define-funs-rec 37 | ((length ((l_1 list)) nat)) 38 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 39 | (case nil z)))) 40 | (define-funs-rec 41 | ((sum ((l_2 list)) nat)) 42 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 43 | (case nil z)))) 44 | (define-funs-rec 45 | ((sorted ((l_3 list)) Bool)) 46 | ((match l_3 47 | (case (cons x_7 l2) 48 | (match l2 49 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 50 | (case nil true))) 51 | (case nil true)))) 52 | (define-funs-rec ((num_3 () nat)) ((s (s (s z))))) 53 | (assert-not 54 | (forall 55 | ((l_5 list)) 56 | (not (and 57 | (and (and (sorted l_5) (= l_5 (rev l_5))) (= (sum l_5) (s z))) 58 | (= (length l_5) num_3)))))(check-sat) 59 | -------------------------------------------------------------------------------- /examples/sorted3.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list that is sorted, length=51, sum=11, rev l=l 3 | 4 | ; expect: UNSAT 5 | 6 | (include "nat.lisp") 7 | (include "list.lisp") 8 | 9 | (define (5 nat (s (s (s (s (s z))))))) 10 | (define (10 nat (plus 5 5))) 11 | (define (50 nat (mult 5 10))) 12 | 13 | (goal 14 | ((l list)) 15 | (and 16 | (sorted l) 17 | (= l (rev l)) 18 | (= (sum l) (s 10)) 19 | (= (length l) (s 50)) 20 | )) 21 | 22 | -------------------------------------------------------------------------------- /examples/sorted3.smt2: -------------------------------------------------------------------------------- 1 | ; expect: UNSAT 2 | 3 | ; a more difficult variant of sorted2 4 | 5 | ; find a sorted list of length 51, that is a palindrome, and has sum 11 6 | 7 | (declare-datatypes () ((nat (s (select_s_0 nat)) 8 | (z)))) 9 | (define-funs-rec 10 | ((plus ((x nat) (y nat)) nat)) 11 | ((match x (case (s x2) (s (plus x2 y))) 12 | (case z y)))) 13 | (define-funs-rec 14 | ((mult ((x_1 nat) (y_1 nat)) nat)) 15 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 16 | (case z z)))) 17 | (define-funs-rec 18 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 19 | ((match x_2 20 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 21 | (case z false))) 22 | (case z true)))) 23 | (declare-datatypes 24 | () 25 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 26 | (nil)))) 27 | (define-funs-rec 28 | ((append ((x_3 list) (y_3 list)) list)) 29 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 30 | (case nil y_3)))) 31 | (define-funs-rec 32 | ((rev ((l list)) list)) 33 | ((match l 34 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 35 | (case nil nil)))) 36 | (define-funs-rec 37 | ((length ((l_1 list)) nat)) 38 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 39 | (case nil z)))) 40 | (define-funs-rec 41 | ((sum ((l_2 list)) nat)) 42 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 43 | (case nil z)))) 44 | (define-funs-rec 45 | ((sorted ((l_3 list)) Bool)) 46 | ((match l_3 47 | (case (cons x_7 l2) 48 | (match l2 49 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 50 | (case nil true))) 51 | (case nil true)))) 52 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 53 | (define-funs-rec ((num_10 () nat)) ((plus num_5 num_5))) 54 | (define-funs-rec ((num_50 () nat)) ((mult num_5 num_10))) 55 | (assert-not 56 | (forall 57 | ((l_5 list)) 58 | (not (and 59 | (and (and (sorted l_5) (= l_5 (rev l_5))) (= (sum l_5) (s num_10))) 60 | (= (length l_5) (s num_50))))))(check-sat) 61 | -------------------------------------------------------------------------------- /examples/sorted4.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; find a list that is sorted, length=10, sum=20 3 | 4 | ; expect: SAT 5 | 6 | (include "nat.lisp") 7 | (include "list.lisp") 8 | 9 | (define (5 nat (s (s (s (s (s z))))))) 10 | (define (10 nat (plus 5 5))) 11 | (define (20 nat (plus 10 10))) 12 | 13 | (goal 14 | ((l list)) 15 | (and 16 | (sorted l) 17 | (= (sum l) 20) 18 | (= (length l) 10) 19 | )) 20 | 21 | -------------------------------------------------------------------------------- /examples/sorted4.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; find a sorted list that is has length 10 and sum 2. 4 | ; by iterative deepening, smbc should find [2,2,…,2] 5 | 6 | (declare-datatypes () ((nat (s (select_s_0 nat)) 7 | (z)))) 8 | (define-funs-rec 9 | ((plus ((x nat) (y nat)) nat)) 10 | ((match x (case (s x2) (s (plus x2 y))) 11 | (case z y)))) 12 | (define-funs-rec 13 | ((mult ((x_1 nat) (y_1 nat)) nat)) 14 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 15 | (case z z)))) 16 | (define-funs-rec 17 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 18 | ((match x_2 19 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 20 | (case z false))) 21 | (case z true)))) 22 | (declare-datatypes 23 | () 24 | ((list (cons (select_cons_0 nat) (select_cons_1 list)) 25 | (nil)))) 26 | (define-funs-rec 27 | ((append ((x_3 list) (y_3 list)) list)) 28 | ((match x_3 (case (cons n tail) (cons n (append tail y_3))) 29 | (case nil y_3)))) 30 | (define-funs-rec 31 | ((rev ((l list)) list)) 32 | ((match l 33 | (case (cons x_4 xs) (append (rev xs) (cons x_4 nil))) 34 | (case nil nil)))) 35 | (define-funs-rec 36 | ((length ((l_1 list)) nat)) 37 | ((match l_1 (case (cons x_5 tail_1) (s (length tail_1))) 38 | (case nil z)))) 39 | (define-funs-rec 40 | ((sum ((l_2 list)) nat)) 41 | ((match l_2 (case (cons x_6 tail_2) (plus x_6 (sum tail_2))) 42 | (case nil z)))) 43 | (define-funs-rec 44 | ((sorted ((l_3 list)) Bool)) 45 | ((match l_3 46 | (case (cons x_7 l2) 47 | (match l2 48 | (case (cons y_4 l3) (and (leq x_7 y_4) (sorted (cons y_4 l3)))) 49 | (case nil true))) 50 | (case nil true)))) 51 | (define-funs-rec ((num_5 () nat)) ((s (s (s (s (s z))))))) 52 | (define-funs-rec ((num_10 () nat)) ((plus num_5 num_5))) 53 | (define-funs-rec ((num_20 () nat)) ((plus num_10 num_10))) 54 | (assert-not 55 | (forall 56 | ((l_5 list)) 57 | (not (and (and (sorted l_5) (= (sum l_5) num_20)) (= (length l_5) num_10)))))(check-sat) 58 | -------------------------------------------------------------------------------- /examples/sum_len.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; len l1 = 5 & len l2 = 5 & sum (l1 ++ l2) = 16 & rev (l1 ++ l2) = l1 ++ l2 3 | ; expect: SAT 4 | 5 | (include "list.lisp") 6 | (include "nat.lisp") 7 | 8 | (define (5 nat (s (s (s (s (s z))))))) 9 | (define (3 nat (s (s (s z))))) 10 | (define (15 nat (mult 3 5))) 11 | 12 | (goal 13 | ((l1 list) 14 | (l2 list)) 15 | (and 16 | (= (length l1) 5) 17 | (= (length l2) 5) 18 | (= (sum (append l1 l2)) (s 15)) 19 | (= (rev (append l1 l2)) (append l1 l2)) 20 | )) 21 | 22 | -------------------------------------------------------------------------------- /examples/ty_infer.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (data (ty a b c (arrow ty ty))) 8 | 9 | (data (ty_opt ty_none (ty_some ty))) 10 | 11 | (data (env e_nil (e_cons ty env))) 12 | 13 | ; lambda-expressions (where `app` has the type argument explicit) 14 | (data (expr (var nat) (lam expr) (app expr expr ty))) 15 | 16 | ; lookup in env 17 | (define 18 | (at_index 19 | (-> nat env ty_opt) 20 | (fun (n nat) 21 | (fun (e env) 22 | (match n 23 | (z 24 | (match e 25 | (e_nil ty_none) 26 | ((e_cons ty e') (ty_some ty)))) 27 | ((s n') 28 | (match e 29 | (e_nil ty_none) 30 | ((e_cons ty e') (at_index n' e'))))))))) 31 | 32 | ; type-check 33 | (define 34 | (ty_check 35 | (-> env expr ty prop) 36 | (fun (env env) 37 | (fun (e expr) 38 | (fun (ty ty) 39 | (match e 40 | ((app f arg ty_arg) 41 | (and 42 | (ty_check env f (arrow ty_arg ty)) 43 | (ty_check env arg ty_arg))) 44 | ((lam e') 45 | (match ty 46 | ((arrow ty_arg ty_ret) 47 | (ty_check (e_cons ty_arg env) e' ty_ret)) 48 | (a false) 49 | (b false) 50 | (c false))) 51 | ((var n) 52 | (match (at_index n env) 53 | (ty_none false) 54 | ((ty_some ty_var) (= ty_var ty)))))))))) 55 | 56 | (goal 57 | ((e expr)) 58 | (ty_check e_nil e 59 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c))))) 60 | 61 | -------------------------------------------------------------------------------- /examples/ty_infer.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; synthesize a lambda term of type 4 | ; "(a -> b) -> (b -> c) -> a -> c" 5 | ; from the definition of the type-checking function 6 | 7 | ; here, a,b,c are type constructors 8 | 9 | (declare-datatypes () ((nat (s (select_s_0 nat)) 10 | (z)))) 11 | (define-funs-rec 12 | ((plus ((x nat) (y nat)) nat)) 13 | ((match x (case (s x2) (s (plus x2 y))) 14 | (case z y)))) 15 | (define-funs-rec 16 | ((mult ((x_1 nat) (y_1 nat)) nat)) 17 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 18 | (case z z)))) 19 | (define-funs-rec 20 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 21 | ((match x_2 22 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 23 | (case z false))) 24 | (case z true)))) 25 | (declare-datatypes 26 | () 27 | ((ty (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 28 | (c) 29 | (b) 30 | (a)))) 31 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 32 | (ty_none)))) 33 | (declare-datatypes 34 | () 35 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 36 | (e_nil)))) 37 | (declare-datatypes 38 | () 39 | ((expr 40 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 41 | (lam (select_lam_0 expr)) 42 | (var (select_var_0 nat))))) 43 | (define-funs-rec 44 | ((at_index ((n nat) (e env)) ty_opt)) 45 | ((match n 46 | (case (s n_) 47 | (match e 48 | (case (e_cons ty_1 e_) (at_index n_ e_)) 49 | (case e_nil ty_none))) 50 | (case z 51 | (match e 52 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 53 | (case e_nil ty_none)))))) 54 | (define-funs-rec 55 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 56 | ((match e_1 57 | (case (app f arg ty_arg) 58 | (and 59 | (ty_check env_1 f (arrow ty_arg ty_3)) 60 | (ty_check env_1 arg ty_arg))) 61 | (case (lam e__2) 62 | (match ty_3 63 | (case (arrow ty_arg_1 ty_ret) 64 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 65 | (case c false) 66 | (case b false) 67 | (case a false))) 68 | (case (var n_1) 69 | (match (at_index n_1 env_1) 70 | (case (ty_some ty_var) (= ty_var ty_3)) 71 | (case ty_none false)))))) 72 | (assert-not 73 | (forall 74 | ((e_2 expr)) 75 | (not (ty_check e_nil e_2 76 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c)))))))(check-sat) 77 | -------------------------------------------------------------------------------- /examples/ty_infer2.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (data (ty a b c d (arrow ty ty))) 8 | 9 | (data (ty_opt ty_none (ty_some ty))) 10 | 11 | (data (env e_nil (e_cons ty env))) 12 | 13 | ; lambda-expressions (where `app` has the type argument explicit) 14 | (data (expr (var nat) (lam expr) (app expr expr ty))) 15 | 16 | ; lookup in env 17 | (define 18 | (at_index 19 | (-> nat env ty_opt) 20 | (fun (n nat) 21 | (fun (e env) 22 | (match n 23 | (z 24 | (match e 25 | (e_nil ty_none) 26 | ((e_cons ty e') (ty_some ty)))) 27 | ((s n') 28 | (match e 29 | (e_nil ty_none) 30 | ((e_cons ty e') (at_index n' e'))))))))) 31 | 32 | ; type-check 33 | (define 34 | (ty_check 35 | (-> env expr ty prop) 36 | (fun (env env) 37 | (fun (e expr) 38 | (fun (ty ty) 39 | (match e 40 | ((app f arg ty_arg) 41 | (and 42 | (ty_check env f (arrow ty_arg ty)) 43 | (ty_check env arg ty_arg))) 44 | ((lam e') 45 | (match ty 46 | ((arrow ty_arg ty_ret) 47 | (ty_check (e_cons ty_arg env) e' ty_ret)) 48 | (a false) 49 | (b false) 50 | (c false) 51 | (d false))) 52 | ((var n) 53 | (match (at_index n env) 54 | (ty_none false) 55 | ((ty_some ty_var) (= ty_var ty)))))))))) 56 | 57 | (goal 58 | ((e expr)) 59 | (ty_check e_nil e 60 | (arrow (arrow c d) 61 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d)))))) 62 | 63 | -------------------------------------------------------------------------------- /examples/ty_infer2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; synthesize a lambda term of type 4 | ; "(a -> b) -> (b -> c) -> (c -> d) -> a -> d" 5 | ; from the definition of the type-checking function 6 | 7 | ; here, a,b,c,d are type constructors 8 | 9 | (declare-datatypes () ((nat (s (select_s_0 nat)) 10 | (z)))) 11 | (define-funs-rec 12 | ((plus ((x nat) (y nat)) nat)) 13 | ((match x (case (s x2) (s (plus x2 y))) 14 | (case z y)))) 15 | (define-funs-rec 16 | ((mult ((x_1 nat) (y_1 nat)) nat)) 17 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 18 | (case z z)))) 19 | (define-funs-rec 20 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 21 | ((match x_2 22 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 23 | (case z false))) 24 | (case z true)))) 25 | (declare-datatypes 26 | () 27 | ((ty (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 28 | (d) 29 | (c) 30 | (b) 31 | (a)))) 32 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 33 | (ty_none)))) 34 | (declare-datatypes 35 | () 36 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 37 | (e_nil)))) 38 | (declare-datatypes 39 | () 40 | ((expr 41 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 42 | (lam (select_lam_0 expr)) 43 | (var (select_var_0 nat))))) 44 | (define-funs-rec 45 | ((at_index ((n nat) (e env)) ty_opt)) 46 | ((match n 47 | (case (s n_) 48 | (match e 49 | (case (e_cons ty_1 e_) (at_index n_ e_)) 50 | (case e_nil ty_none))) 51 | (case z 52 | (match e 53 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 54 | (case e_nil ty_none)))))) 55 | (define-funs-rec 56 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 57 | ((match e_1 58 | (case (app f arg ty_arg) 59 | (and 60 | (ty_check env_1 f (arrow ty_arg ty_3)) 61 | (ty_check env_1 arg ty_arg))) 62 | (case (lam e__2) 63 | (match ty_3 64 | (case (arrow ty_arg_1 ty_ret) 65 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 66 | (case d false) 67 | (case c false) 68 | (case b false) 69 | (case a false))) 70 | (case (var n_1) 71 | (match (at_index n_1 env_1) 72 | (case (ty_some ty_var) (= ty_var ty_3)) 73 | (case ty_none false)))))) 74 | (assert-not 75 | (forall 76 | ((e_2 expr)) 77 | (not (ty_check e_nil e_2 78 | (arrow (arrow c d) 79 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d))))))))(check-sat) 80 | -------------------------------------------------------------------------------- /examples/ty_infer2_unin.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (decl-ty ty-const) 8 | (decl k_a ty-const) 9 | (decl k_b ty-const) 10 | (decl k_c ty-const) 11 | (decl k_d ty-const) 12 | 13 | (assert (not (= k_a k_b))) 14 | (assert (not (= k_a k_c))) 15 | (assert (not (= k_a k_d))) 16 | (assert (not (= k_b k_c))) 17 | (assert (not (= k_b k_d))) 18 | (assert (not (= k_c k_d))) 19 | 20 | (data (ty (const ty-const) (arrow ty ty))) 21 | 22 | (define (a ty (const k_a))) 23 | (define (b ty (const k_b))) 24 | (define (c ty (const k_c))) 25 | (define (d ty (const k_d))) 26 | 27 | (data (ty_opt ty_none (ty_some ty))) 28 | 29 | (data (env e_nil (e_cons ty env))) 30 | 31 | ; lambda-expressions (where `app` has the type argument explicit) 32 | (data (expr (var nat) (lam expr) (app expr expr ty))) 33 | 34 | ; lookup in env 35 | (define 36 | (at_index 37 | (-> nat env ty_opt) 38 | (fun (n nat) 39 | (fun (e env) 40 | (match n 41 | (z 42 | (match e 43 | (e_nil ty_none) 44 | ((e_cons ty e') (ty_some ty)))) 45 | ((s n') 46 | (match e 47 | (e_nil ty_none) 48 | ((e_cons ty e') (at_index n' e'))))))))) 49 | 50 | ; type-check 51 | (define 52 | (ty_check 53 | (-> env expr ty prop) 54 | (fun (env env) 55 | (fun (e expr) 56 | (fun (ty ty) 57 | (match e 58 | ((app f arg ty_arg) 59 | (and 60 | (ty_check env f (arrow ty_arg ty)) 61 | (ty_check env arg ty_arg))) 62 | ((lam e') 63 | (match ty 64 | ((arrow ty_arg ty_ret) 65 | (ty_check (e_cons ty_arg env) e' ty_ret)) 66 | ((const x) false))) 67 | ((var n) 68 | (match (at_index n env) 69 | (ty_none false) 70 | ((ty_some ty_var) (= ty_var ty)))))))))) 71 | 72 | (goal 73 | ((e expr)) 74 | (ty_check e_nil e 75 | (arrow (arrow c d) 76 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d)))))) 77 | 78 | -------------------------------------------------------------------------------- /examples/ty_infer2_unin.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | (declare-datatypes () ((nat (s (select_s_0 nat)) 5 | (z)))) 6 | (define-funs-rec 7 | ((plus ((x nat) (y nat)) nat)) 8 | ((match x (case (s x2) (s (plus x2 y))) 9 | (case z y)))) 10 | (define-funs-rec 11 | ((mult ((x_1 nat) (y_1 nat)) nat)) 12 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 13 | (case z z)))) 14 | (define-funs-rec 15 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 16 | ((match x_2 17 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 18 | (case z false))) 19 | (case z true)))) 20 | (declare-sort ty-const 0) 21 | (declare-fun k_a () ty-const) 22 | (declare-fun k_b () ty-const) 23 | (declare-fun k_c () ty-const) 24 | (declare-fun k_d () ty-const) 25 | (assert (not (= k_a k_b))) 26 | (assert (not (= k_a k_c))) 27 | (assert (not (= k_a k_d))) 28 | (assert (not (= k_b k_c))) 29 | (assert (not (= k_b k_d))) 30 | (assert (not (= k_c k_d))) 31 | (declare-datatypes 32 | () 33 | ((ty 34 | (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 35 | (const (select_const_0 ty-const))))) 36 | (define-funs-rec ((a () ty)) ((const k_a))) 37 | (define-funs-rec ((b () ty)) ((const k_b))) 38 | (define-funs-rec ((c () ty)) ((const k_c))) 39 | (define-funs-rec ((d () ty)) ((const k_d))) 40 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 41 | (ty_none)))) 42 | (declare-datatypes 43 | () 44 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 45 | (e_nil)))) 46 | (declare-datatypes 47 | () 48 | ((expr 49 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 50 | (lam (select_lam_0 expr)) 51 | (var (select_var_0 nat))))) 52 | (define-funs-rec 53 | ((at_index ((n nat) (e env)) ty_opt)) 54 | ((match n 55 | (case (s n_) 56 | (match e 57 | (case (e_cons ty_1 e_) (at_index n_ e_)) 58 | (case e_nil ty_none))) 59 | (case z 60 | (match e 61 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 62 | (case e_nil ty_none)))))) 63 | (define-funs-rec 64 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 65 | ((match e_1 66 | (case (app f arg ty_arg) 67 | (and 68 | (ty_check env_1 f (arrow ty_arg ty_3)) 69 | (ty_check env_1 arg ty_arg))) 70 | (case (lam e__2) 71 | (match ty_3 72 | (case (arrow ty_arg_1 ty_ret) 73 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 74 | (case (const x_3) false))) 75 | (case (var n_1) 76 | (match (at_index n_1 env_1) 77 | (case (ty_some ty_var) (= ty_var ty_3)) 78 | (case ty_none false)))))) 79 | (assert-not 80 | (forall 81 | ((e_2 expr)) 82 | (not (ty_check e_nil e_2 83 | (arrow (arrow c d) 84 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d))))))))(check-sat) 85 | -------------------------------------------------------------------------------- /examples/ty_infer_nat.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (data (ty (const nat) (arrow ty ty))) 8 | 9 | (define (a ty (const z))) 10 | (define (b ty (const (s z)))) 11 | (define (c ty (const (s (s z))))) 12 | 13 | (data (ty_opt ty_none (ty_some ty))) 14 | 15 | (data (env e_nil (e_cons ty env))) 16 | 17 | ; lambda-expressions (where `app` has the type argument explicit) 18 | (data (expr (var nat) (lam expr) (app expr expr ty))) 19 | 20 | ; lookup in env 21 | (define 22 | (at_index 23 | (-> nat env ty_opt) 24 | (fun (n nat) 25 | (fun (e env) 26 | (match n 27 | (z 28 | (match e 29 | (e_nil ty_none) 30 | ((e_cons ty e') (ty_some ty)))) 31 | ((s n') 32 | (match e 33 | (e_nil ty_none) 34 | ((e_cons ty e') (at_index n' e'))))))))) 35 | 36 | ; type-check 37 | (define 38 | (ty_check 39 | (-> env expr ty prop) 40 | (fun (env env) 41 | (fun (e expr) 42 | (fun (ty ty) 43 | (match e 44 | ((app f arg ty_arg) 45 | (and 46 | (ty_check env f (arrow ty_arg ty)) 47 | (ty_check env arg ty_arg))) 48 | ((lam e') 49 | (match ty 50 | ((arrow ty_arg ty_ret) 51 | (ty_check (e_cons ty_arg env) e' ty_ret)) 52 | ((const x) false))) 53 | ((var n) 54 | (match (at_index n env) 55 | (ty_none false) 56 | ((ty_some ty_var) (= ty_var ty)))))))))) 57 | 58 | (goal 59 | ((e expr)) 60 | (ty_check e_nil e 61 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c))))) 62 | 63 | -------------------------------------------------------------------------------- /examples/ty_infer_nat.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; synthesize a lambda term of type 4 | ; "(a -> b) -> (b -> c) -> a -> c" 5 | ; from the definition of the type-checking function 6 | 7 | ; here, a,b,c are natural numbers 8 | 9 | (declare-datatypes () ((nat (s (select_s_0 nat)) 10 | (z)))) 11 | (define-funs-rec 12 | ((plus ((x nat) (y nat)) nat)) 13 | ((match x (case (s x2) (s (plus x2 y))) 14 | (case z y)))) 15 | (define-funs-rec 16 | ((mult ((x_1 nat) (y_1 nat)) nat)) 17 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 18 | (case z z)))) 19 | (define-funs-rec 20 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 21 | ((match x_2 22 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 23 | (case z false))) 24 | (case z true)))) 25 | (declare-datatypes 26 | () 27 | ((ty 28 | (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 29 | (const (select_const_0 nat))))) 30 | (define-funs-rec ((a () ty)) ((const z))) 31 | (define-funs-rec ((b () ty)) ((const (s z)))) 32 | (define-funs-rec ((c () ty)) ((const (s (s z))))) 33 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 34 | (ty_none)))) 35 | (declare-datatypes 36 | () 37 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 38 | (e_nil)))) 39 | (declare-datatypes 40 | () 41 | ((expr 42 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 43 | (lam (select_lam_0 expr)) 44 | (var (select_var_0 nat))))) 45 | (define-funs-rec 46 | ((at_index ((n nat) (e env)) ty_opt)) 47 | ((match n 48 | (case (s n_) 49 | (match e 50 | (case (e_cons ty_1 e_) (at_index n_ e_)) 51 | (case e_nil ty_none))) 52 | (case z 53 | (match e 54 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 55 | (case e_nil ty_none)))))) 56 | (define-funs-rec 57 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 58 | ((match e_1 59 | (case (app f arg ty_arg) 60 | (and 61 | (ty_check env_1 f (arrow ty_arg ty_3)) 62 | (ty_check env_1 arg ty_arg))) 63 | (case (lam e__2) 64 | (match ty_3 65 | (case (arrow ty_arg_1 ty_ret) 66 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 67 | (case (const x_3) false))) 68 | (case (var n_1) 69 | (match (at_index n_1 env_1) 70 | (case (ty_some ty_var) (= ty_var ty_3)) 71 | (case ty_none false)))))) 72 | (assert-not 73 | (forall 74 | ((e_2 expr)) 75 | (not (ty_check e_nil e_2 76 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c)))))))(check-sat) 77 | -------------------------------------------------------------------------------- /examples/ty_infer_nat2.lisp: -------------------------------------------------------------------------------- 1 | 2 | 3 | ; type checking of simply-typed λ calculus 4 | ; expect: SAT 5 | 6 | (include "nat.lisp") 7 | 8 | (data (ty (const nat) (arrow ty ty))) 9 | 10 | (define (a ty (const z))) 11 | (define (b ty (const (s z)))) 12 | (define (c ty (const (s (s z))))) 13 | (define (d ty (const (s (s (s z)))))) 14 | 15 | (data (ty_opt ty_none (ty_some ty))) 16 | 17 | (data (env e_nil (e_cons ty env))) 18 | 19 | ; lambda-expressions (where `app` has the type argument explicit) 20 | (data (expr (var nat) (lam expr) (app expr expr ty))) 21 | 22 | ; lookup in env 23 | (define 24 | (at_index 25 | (-> nat env ty_opt) 26 | (fun (n nat) 27 | (fun (e env) 28 | (match n 29 | (z 30 | (match e 31 | (e_nil ty_none) 32 | ((e_cons ty e') (ty_some ty)))) 33 | ((s n') 34 | (match e 35 | (e_nil ty_none) 36 | ((e_cons ty e') (at_index n' e'))))))))) 37 | 38 | ; type-check 39 | (define 40 | (ty_check 41 | (-> env expr ty prop) 42 | (fun (env env) 43 | (fun (e expr) 44 | (fun (ty ty) 45 | (match e 46 | ((app f arg ty_arg) 47 | (and 48 | (ty_check env f (arrow ty_arg ty)) 49 | (ty_check env arg ty_arg))) 50 | ((lam e') 51 | (match ty 52 | ((arrow ty_arg ty_ret) 53 | (ty_check (e_cons ty_arg env) e' ty_ret)) 54 | ((const x) false))) 55 | ((var n) 56 | (match (at_index n env) 57 | (ty_none false) 58 | ((ty_some ty_var) (= ty_var ty)))))))))) 59 | 60 | (goal 61 | ((e expr)) 62 | (ty_check e_nil e 63 | (arrow (arrow c d) 64 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d)))))) 65 | -------------------------------------------------------------------------------- /examples/ty_infer_nat2.smt2: -------------------------------------------------------------------------------- 1 | ; expect: SAT 2 | 3 | ; synthesize a lambda term of type 4 | ; "(a -> b) -> (b -> c) -> (c -> d) -> a -> d" 5 | ; from the definition of the type-checking function 6 | 7 | ; here, a,b,c,d are type constructors 8 | 9 | (declare-datatypes () ((nat (s (select_s_0 nat)) 10 | (z)))) 11 | (define-funs-rec 12 | ((plus ((x nat) (y nat)) nat)) 13 | ((match x (case (s x2) (s (plus x2 y))) 14 | (case z y)))) 15 | (define-funs-rec 16 | ((mult ((x_1 nat) (y_1 nat)) nat)) 17 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 18 | (case z z)))) 19 | (define-funs-rec 20 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 21 | ((match x_2 22 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 23 | (case z false))) 24 | (case z true)))) 25 | (declare-datatypes 26 | () 27 | ((ty 28 | (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 29 | (const (select_const_0 nat))))) 30 | (define-funs-rec ((a () ty)) ((const z))) 31 | (define-funs-rec ((b () ty)) ((const (s z)))) 32 | (define-funs-rec ((c () ty)) ((const (s (s z))))) 33 | (define-funs-rec ((d () ty)) ((const (s (s (s z)))))) 34 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 35 | (ty_none)))) 36 | (declare-datatypes 37 | () 38 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 39 | (e_nil)))) 40 | (declare-datatypes 41 | () 42 | ((expr 43 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 44 | (lam (select_lam_0 expr)) 45 | (var (select_var_0 nat))))) 46 | (define-funs-rec 47 | ((at_index ((n nat) (e env)) ty_opt)) 48 | ((match n 49 | (case (s n_) 50 | (match e 51 | (case (e_cons ty_1 e_) (at_index n_ e_)) 52 | (case e_nil ty_none))) 53 | (case z 54 | (match e 55 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 56 | (case e_nil ty_none)))))) 57 | (define-funs-rec 58 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 59 | ((match e_1 60 | (case (app f arg ty_arg) 61 | (and 62 | (ty_check env_1 f (arrow ty_arg ty_3)) 63 | (ty_check env_1 arg ty_arg))) 64 | (case (lam e__2) 65 | (match ty_3 66 | (case (arrow ty_arg_1 ty_ret) 67 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 68 | (case (const x_3) false))) 69 | (case (var n_1) 70 | (match (at_index n_1 env_1) 71 | (case (ty_some ty_var) (= ty_var ty_3)) 72 | (case ty_none false)))))) 73 | (assert-not 74 | (forall 75 | ((e_2 expr)) 76 | (not (ty_check e_nil e_2 77 | (arrow (arrow c d) 78 | (arrow (arrow b c) (arrow (arrow a b) (arrow a d))))))))(check-sat) 79 | -------------------------------------------------------------------------------- /examples/ty_infer_unin.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | 5 | (include "nat.lisp") 6 | 7 | (decl-ty ty-const) 8 | (decl k_a ty-const) 9 | (decl k_b ty-const) 10 | (decl k_c ty-const) 11 | (assert (not (= k_a k_b))) 12 | (assert (not (= k_a k_c))) 13 | (assert (not (= k_b k_c))) 14 | 15 | (data (ty (const ty-const) (arrow ty ty))) 16 | 17 | (define (a ty (const k_a))) 18 | (define (b ty (const k_b))) 19 | (define (c ty (const k_c))) 20 | 21 | (data (ty_opt ty_none (ty_some ty))) 22 | 23 | (data (env e_nil (e_cons ty env))) 24 | 25 | ; lambda-expressions (where `app` has the type argument explicit) 26 | (data (expr (var nat) (lam expr) (app expr expr ty))) 27 | 28 | ; lookup in env 29 | (define 30 | (at_index 31 | (-> nat env ty_opt) 32 | (fun (n nat) 33 | (fun (e env) 34 | (match n 35 | (z 36 | (match e 37 | (e_nil ty_none) 38 | ((e_cons ty e') (ty_some ty)))) 39 | ((s n') 40 | (match e 41 | (e_nil ty_none) 42 | ((e_cons ty e') (at_index n' e'))))))))) 43 | 44 | ; type-check 45 | (define 46 | (ty_check 47 | (-> env expr ty prop) 48 | (fun (env env) 49 | (fun (e expr) 50 | (fun (ty ty) 51 | (match e 52 | ((app f arg ty_arg) 53 | (and 54 | (ty_check env f (arrow ty_arg ty)) 55 | (ty_check env arg ty_arg))) 56 | ((lam e') 57 | (match ty 58 | ((arrow ty_arg ty_ret) 59 | (ty_check (e_cons ty_arg env) e' ty_ret)) 60 | ((const x) false))) 61 | ((var n) 62 | (match (at_index n env) 63 | (ty_none false) 64 | ((ty_some ty_var) (= ty_var ty)))))))))) 65 | 66 | (goal 67 | ((e expr)) 68 | (ty_check e_nil e 69 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c))))) 70 | 71 | -------------------------------------------------------------------------------- /examples/ty_infer_unin.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; type checking of simply-typed λ calculus 3 | ; expect: SAT 4 | (declare-datatypes () ((nat (s (select_s_0 nat)) 5 | (z)))) 6 | (define-funs-rec 7 | ((plus ((x nat) (y nat)) nat)) 8 | ((match x (case (s x2) (s (plus x2 y))) 9 | (case z y)))) 10 | (define-funs-rec 11 | ((mult ((x_1 nat) (y_1 nat)) nat)) 12 | ((match x_1 (case (s x2_1) (plus y_1 (mult x2_1 y_1))) 13 | (case z z)))) 14 | (define-funs-rec 15 | ((leq ((x_2 nat) (y_2 nat)) Bool)) 16 | ((match x_2 17 | (case (s x2_2) (match y_2 (case (s y2) (leq x2_2 y2)) 18 | (case z false))) 19 | (case z true)))) 20 | (declare-sort ty-const 0) 21 | (declare-fun k_a () ty-const) 22 | (declare-fun k_b () ty-const) 23 | (declare-fun k_c () ty-const) 24 | (assert (not (= k_a k_b))) 25 | (assert (not (= k_a k_c))) 26 | (assert (not (= k_b k_c))) 27 | (declare-datatypes 28 | () 29 | ((ty 30 | (arrow (select_arrow_0 ty) (select_arrow_1 ty)) 31 | (const (select_const_0 ty-const))))) 32 | (define-funs-rec ((a () ty)) ((const k_a))) 33 | (define-funs-rec ((b () ty)) ((const k_b))) 34 | (define-funs-rec ((c () ty)) ((const k_c))) 35 | (declare-datatypes () ((ty_opt (ty_some (select_ty_some_0 ty)) 36 | (ty_none)))) 37 | (declare-datatypes 38 | () 39 | ((env (e_cons (select_e_cons_0 ty) (select_e_cons_1 env)) 40 | (e_nil)))) 41 | (declare-datatypes 42 | () 43 | ((expr 44 | (app (select_app_0 expr) (select_app_1 expr) (select_app_2 ty)) 45 | (lam (select_lam_0 expr)) 46 | (var (select_var_0 nat))))) 47 | (define-funs-rec 48 | ((at_index ((n nat) (e env)) ty_opt)) 49 | ((match n 50 | (case (s n_) 51 | (match e 52 | (case (e_cons ty_1 e_) (at_index n_ e_)) 53 | (case e_nil ty_none))) 54 | (case z 55 | (match e 56 | (case (e_cons ty_2 e__1) (ty_some ty_2)) 57 | (case e_nil ty_none)))))) 58 | (define-funs-rec 59 | ((ty_check ((env_1 env) (e_1 expr) (ty_3 ty)) Bool)) 60 | ((match e_1 61 | (case (app f arg ty_arg) 62 | (and 63 | (ty_check env_1 f (arrow ty_arg ty_3)) 64 | (ty_check env_1 arg ty_arg))) 65 | (case (lam e__2) 66 | (match ty_3 67 | (case (arrow ty_arg_1 ty_ret) 68 | (ty_check (e_cons ty_arg_1 env_1) e__2 ty_ret)) 69 | (case (const x_3) false))) 70 | (case (var n_1) 71 | (match (at_index n_1 env_1) 72 | (case (ty_some ty_var) (= ty_var ty_3)) 73 | (case ty_none false)))))) 74 | (assert-not 75 | (forall 76 | ((e_2 expr)) 77 | (not (ty_check e_nil e_2 78 | (arrow (arrow b c) (arrow (arrow a b) (arrow a c)))))))(check-sat) 79 | -------------------------------------------------------------------------------- /examples/uf5.smt2: -------------------------------------------------------------------------------- 1 | 2 | 3 | ; simple QF_UF test 4 | ; (set-logic QF_UF) 5 | 6 | ; expect: sat 7 | 8 | (declare-sort i 0) 9 | (declare-fun a () i) 10 | (declare-fun b () i) 11 | (declare-fun c () i) 12 | (declare-fun f (i) i) 13 | (declare-fun p (i) Bool) 14 | (declare-fun test () Bool) 15 | 16 | (assert (= (f a) b)) 17 | (assert (= (f b) c)) 18 | (assert (= (f c) a)) 19 | (assert (not (p (f c)))) 20 | (assert (p (ite test a (f (f (f b)))))) 21 | 22 | (check-sat) 23 | -------------------------------------------------------------------------------- /examples/unin1.lisp: -------------------------------------------------------------------------------- 1 | 2 | ; uninterpreted functions 3 | ; expect: SAT 4 | 5 | (decl-ty u) 6 | (decl a u) 7 | (decl b u) 8 | (decl f (-> u prop)) 9 | 10 | (assert (not (= (f a) (f b)))) 11 | 12 | ; u = {a,b} 13 | (assert 14 | (forall (x u) 15 | (or (= x a) (= x b)))) 16 | 17 | (goal 18 | ((x u)) 19 | (not (= (f x) (f b)))) 20 | 21 | -------------------------------------------------------------------------------- /examples/unin1.smt2: -------------------------------------------------------------------------------- 1 | 2 | ; uninterpreted functions 3 | ; expect: SAT 4 | (declare-sort u 0) 5 | (declare-fun a () u) 6 | (declare-fun b () u) 7 | (declare-fun f_8 (u) Bool) 8 | (assert (not (= (f_8 a) (f_8 b)))) 9 | ; u = {a,b} 10 | (assert (forall ((x_45 u)) (or (= x_45 a) (= x_45 b)))) 11 | (assert-not (forall ((x_46 u)) (not (not (= (f_8 x_46) (f_8 b))))))(check-sat) 12 | -------------------------------------------------------------------------------- /smbc: -------------------------------------------------------------------------------- 1 | _build/default/src/smbc.exe -------------------------------------------------------------------------------- /smbc.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | version: "0.6.1" 3 | maintainer: "simon.cruanes.2007@m4x.org" 4 | author: "Simon Cruanes" 5 | homepage: "https://github.com/c-cube/smbc" 6 | synopsis: "Experimental model finder/SMT solver for functional programming" 7 | build: [ 8 | ["dune" "build" "@install" "-p" name "-j" jobs] 9 | ] 10 | depends: [ 11 | "dune" { >= "1.0" } 12 | "base-bytes" 13 | "containers" { >= "3.4" & < "4.0" } 14 | "iter" { >= "1.0" } 15 | "msat" { >= "0.8" & < "0.9" } 16 | "tip-parser" { >= "0.6" & < "0.7" } 17 | "ocaml" { >= "4.03" } 18 | ] 19 | tags: [ "logic" "narrowing" "model" "smt" ] 20 | bug-reports: "https://github.com/c-cube/smbc/issues" 21 | dev-repo: "git+https://github.com/c-cube/smbc.git" 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/Ast.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Preprocessing AST} *) 5 | 6 | type 'a or_error = ('a, string) CCResult.t 7 | type sexp = CCSexp.t 8 | type 'a to_sexp = 'a -> sexp 9 | 10 | (** {2 Types} *) 11 | 12 | exception Error of string 13 | exception Ill_typed of string 14 | 15 | module Var : sig 16 | type 'ty t = private { 17 | id: ID.t; 18 | ty: 'ty; 19 | } 20 | 21 | val make : ID.t -> 'ty -> 'ty t 22 | val copy : 'a t -> 'a t 23 | val id : _ t -> ID.t 24 | val ty : 'a t -> 'a 25 | 26 | val equal : 'a t -> 'a t -> bool 27 | val compare : 'a t -> 'a t -> int 28 | val pp : _ t CCFormat.printer 29 | val to_sexp : _ t to_sexp 30 | val to_sexp_typed : 'ty to_sexp -> 'ty t to_sexp 31 | end 32 | 33 | module Ty : sig 34 | type t = 35 | | Prop 36 | | Const of ID.t 37 | | Arrow of t * t 38 | 39 | val prop : t 40 | val const : ID.t -> t 41 | val arrow : t -> t -> t 42 | val arrow_l : t list -> t -> t 43 | 44 | include Intf.EQ with type t := t 45 | include Intf.ORD with type t := t 46 | include Intf.HASH with type t := t 47 | include Intf.PRINT with type t := t 48 | 49 | val unfold : t -> t list * t 50 | (** [unfold ty] will get the list of arguments, and the return type 51 | of any function. An atomic type is just a function with no arguments *) 52 | 53 | val to_sexp : t to_sexp 54 | 55 | (** {2 Datatypes} *) 56 | 57 | (** Mutually recursive datatypes *) 58 | type data = { 59 | data_id: ID.t; 60 | data_cstors: t ID.Map.t; 61 | } 62 | 63 | val data_to_sexp : data -> sexp 64 | 65 | module Map : CCMap.S with type key = t 66 | 67 | (** {2 Error Handling} *) 68 | 69 | val ill_typed : ('a, Format.formatter, unit, 'b) format4 -> 'a 70 | end 71 | 72 | type var = Ty.t Var.t 73 | 74 | type binop = 75 | | And 76 | | Or 77 | | Imply 78 | | Eq 79 | 80 | type binder = 81 | | Fun 82 | | Forall 83 | | Exists 84 | | Mu 85 | 86 | type term = private { 87 | term: term_cell; 88 | ty: Ty.t; 89 | } 90 | and term_cell = 91 | | Var of var 92 | | Const of ID.t 93 | | Unknown of var 94 | | App of term * term list 95 | | If of term * term * term 96 | | Select of select * term 97 | | Match of term * (var list * term) ID.Map.t * (ID.Set.t * term) option 98 | | Switch of term * term ID.Map.t (* switch on constants *) 99 | | Bind of binder * var * term 100 | | Let of var * term * term 101 | | Not of term 102 | | Binop of binop * term * term 103 | | Asserting of term * term 104 | | Undefined_value 105 | | Bool of bool 106 | 107 | and select = { 108 | select_name: ID.t lazy_t; 109 | select_cstor: ID.t; 110 | select_i: int; 111 | } 112 | 113 | (* TODO: records? *) 114 | 115 | type definition = ID.t * Ty.t * term 116 | 117 | type statement = 118 | | Data of Ty.data list 119 | | TyDecl of ID.t (* new atomic cstor *) 120 | | Decl of ID.t * Ty.t 121 | | Define of definition list 122 | | Assert of term 123 | | Goal of { 124 | prove: bool; 125 | vars: var list; 126 | body: term; 127 | } 128 | 129 | (** {2 Constructors} *) 130 | 131 | val term_view : term -> term_cell 132 | val ty : term -> Ty.t 133 | 134 | val var : var -> term 135 | val const : ID.t -> Ty.t -> term 136 | val unknown : var -> term 137 | val app : term -> term list -> term 138 | val app_a : term -> term array -> term 139 | val select : select -> term -> Ty.t -> term 140 | val if_ : term -> term -> term -> term 141 | val match_ : term -> (var list * term) ID.Map.t -> default:(ID.Set.t * term) option -> term 142 | val switch : term -> term ID.Map.t -> term 143 | val let_ : var -> term -> term -> term 144 | val bind : ty:Ty.t -> binder -> var -> term -> term 145 | val fun_ : var -> term -> term 146 | val fun_l : var list -> term -> term 147 | val fun_a : var array -> term -> term 148 | val forall : var -> term -> term 149 | val forall_l : var list -> term -> term 150 | val exists : var -> term -> term 151 | val exists_l : var list -> term -> term 152 | val mu : var -> term -> term 153 | val eq : term -> term -> term 154 | val not_ : term -> term 155 | val binop : binop -> term -> term -> term 156 | val and_ : term -> term -> term 157 | val and_l : term list -> term 158 | val or_ : term -> term -> term 159 | val or_l : term list -> term 160 | val imply : term -> term -> term 161 | val true_ : term 162 | val false_ : term 163 | val undefined_value : Ty.t -> term 164 | val asserting : term -> term -> term 165 | 166 | val unfold_fun : term -> var list * term 167 | 168 | (** {2 Printing} *) 169 | 170 | val pp_term : term CCFormat.printer 171 | val pp_statement : statement CCFormat.printer 172 | 173 | val pp_term_tip : term CCFormat.printer 174 | val pp_ty_tip : Ty.t CCFormat.printer 175 | val pp_statement_tip : statement CCFormat.printer 176 | 177 | (** {2 Parsing and Typing} *) 178 | 179 | module Ctx : sig 180 | type t 181 | val create: include_dir:string -> unit -> t 182 | include Intf.PRINT with type t := t 183 | end 184 | 185 | type syntax = 186 | | Auto 187 | (** Guess based on file extension *) 188 | | Tip 189 | (** Syntax for Tip (https://github.com/tip-org/) 190 | 191 | This is a small subset of Smtlib2, so we can reuse the same S-expr 192 | parser as {!Smbc} *) 193 | 194 | val string_of_syntax : syntax -> string 195 | 196 | val parse : include_dir:string -> file:string -> syntax -> statement list or_error 197 | (** Parse the given file, type-check, etc. 198 | @raise Error in case the input is ill formed 199 | @raise Ill_typed if the input is ill typed *) 200 | 201 | val parse_stdin : syntax -> statement list or_error 202 | (** Parse stdin, type-check, etc. 203 | @raise Error in case the input is ill formed 204 | @raise Ill_typed if the input is ill typed *) 205 | 206 | (** {2 Environment} *) 207 | 208 | type env_entry = 209 | | E_uninterpreted_ty 210 | | E_uninterpreted_cst (* domain element *) 211 | | E_const of Ty.t 212 | | E_data of Ty.t ID.Map.t (* list of cstors *) 213 | | E_cstor of Ty.t 214 | | E_defined of Ty.t * term (* if defined *) 215 | 216 | type env = { 217 | defs: env_entry ID.Map.t; 218 | } 219 | (** Environment with definitions and goals *) 220 | 221 | val env_empty : env 222 | 223 | val env_add_statement : env -> statement -> env 224 | 225 | val env_of_statements: statement Iter.t -> env 226 | 227 | val env_find_def : env -> ID.t -> env_entry option 228 | 229 | val env_add_def : env -> ID.t -> env_entry -> env 230 | 231 | -------------------------------------------------------------------------------- /src/Common_.ml: -------------------------------------------------------------------------------- 1 | 2 | module Fmt = CCFormat 3 | module Option = CCOpt 4 | -------------------------------------------------------------------------------- /src/Hash.ml: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | type 'a t = 'a -> int 5 | 6 | let bool b = if b then 1 else 2 7 | 8 | let int i = i land max_int 9 | 10 | let string (s:string) = Hashtbl.hash s 11 | 12 | let combine f a b = Hashtbl.seeded_hash a (f b) 13 | 14 | let combine2 a b = Hashtbl.seeded_hash a b 15 | 16 | let combine3 a b c = 17 | combine2 a b 18 | |> combine2 c 19 | 20 | let combine4 a b c d = 21 | combine2 a b 22 | |> combine2 c 23 | |> combine2 d 24 | 25 | let pair f g (x,y) = combine2 (f x) (g y) 26 | 27 | let opt f = function 28 | | None -> 42 29 | | Some x -> combine2 43 (f x) 30 | 31 | let list f l = List.fold_left (combine f) 0x42 l 32 | let array f l = Array.fold_left (combine f) 0x42 l 33 | let seq f seq = 34 | let h = ref 0x43 in 35 | seq (fun x -> h := combine f !h x); 36 | !h 37 | 38 | let poly x = Hashtbl.hash x 39 | -------------------------------------------------------------------------------- /src/Hash.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | type 'a t = 'a -> int 5 | 6 | val bool : bool t 7 | val int : int t 8 | val string : string t 9 | val combine : 'a t -> int -> 'a -> int 10 | 11 | val pair : 'a t -> 'b t -> ('a * 'b) t 12 | 13 | val opt : 'a t -> 'a option t 14 | val list : 'a t -> 'a list t 15 | val array : 'a t -> 'a array t 16 | val seq : 'a t -> 'a Iter.t t 17 | 18 | val combine2 : int -> int -> int 19 | val combine3 : int -> int -> int -> int 20 | val combine4 : int -> int -> int -> int -> int 21 | 22 | val poly : 'a t 23 | (** the regular polymorphic hash function *) 24 | -------------------------------------------------------------------------------- /src/Hashcons.ml: -------------------------------------------------------------------------------- 1 | 2 | module type ARG = sig 3 | type t 4 | val equal : t -> t -> bool 5 | val hash : t -> int 6 | val set_id : t -> int -> unit 7 | end 8 | 9 | module Make(A : ARG): sig 10 | val hashcons : A.t -> A.t 11 | val to_iter : A.t Iter.t 12 | end = struct 13 | module W = Weak.Make(A) 14 | 15 | let tbl_ = W.create 1024 16 | let n_ = ref 0 17 | 18 | (* hashcons terms *) 19 | let hashcons t = 20 | let t' = W.merge tbl_ t in 21 | if t == t' then ( 22 | incr n_; 23 | A.set_id t' !n_; 24 | ); 25 | t' 26 | 27 | let to_iter yield = 28 | W.iter yield tbl_ 29 | end 30 | -------------------------------------------------------------------------------- /src/ID.ml: -------------------------------------------------------------------------------- 1 | (* This file is free software. See file "license" for more details. *) 2 | 3 | type t = { 4 | id: int; 5 | name: string; 6 | } 7 | 8 | let make = 9 | let n = ref 0 in 10 | fun name -> 11 | let x = { id= !n; name; } in 12 | incr n; 13 | x 14 | 15 | let makef fmt = CCFormat.ksprintf ~f:make fmt 16 | 17 | let copy {name;_} = make name 18 | 19 | let id {id;_} = id 20 | let to_string id = id.name 21 | let to_sexp id = `Atom id.name 22 | 23 | let equal a b = a.id=b.id 24 | let compare a b = CCInt.compare a.id b.id 25 | let hash a = Hash.int a.id 26 | let pp out a = Format.fprintf out "%s/%d" a.name a.id 27 | let pp_name out a = CCFormat.string out a.name 28 | let to_string_full a = Printf.sprintf "%s/%d" a.name a.id 29 | 30 | module AsKey = struct 31 | type t_ = t 32 | type t = t_ 33 | let equal = equal 34 | let compare = compare 35 | let hash = hash 36 | end 37 | 38 | module Map = CCMap.Make(AsKey) 39 | module Set = CCSet.Make(AsKey) 40 | module Tbl = CCHashtbl.Make(AsKey) 41 | -------------------------------------------------------------------------------- /src/ID.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Unique Identifiers} *) 5 | 6 | type t 7 | 8 | val make : string -> t 9 | val makef : ('a, Format.formatter, unit, t) format4 -> 'a 10 | val copy : t -> t 11 | 12 | val id : t -> int 13 | 14 | val to_string : t -> string 15 | val to_sexp : t -> CCSexp.t 16 | val to_string_full : t -> string 17 | 18 | include Intf.EQ with type t := t 19 | include Intf.ORD with type t := t 20 | include Intf.HASH with type t := t 21 | include Intf.PRINT with type t := t 22 | 23 | val pp_name : t CCFormat.printer 24 | 25 | module Map : CCMap.S with type key = t 26 | module Set : CCSet.S with type elt = t 27 | module Tbl : CCHashtbl.S with type key = t 28 | -------------------------------------------------------------------------------- /src/Intf.ml: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | module type EQ = sig 5 | type t 6 | val equal : t -> t -> bool 7 | end 8 | 9 | module type ORD = sig 10 | type t 11 | val compare : t -> t -> int 12 | end 13 | 14 | module type HASH = sig 15 | type t 16 | val hash : t -> int 17 | end 18 | 19 | module type PRINT = sig 20 | type t 21 | val pp : t CCFormat.printer 22 | end 23 | -------------------------------------------------------------------------------- /src/Log.ml: -------------------------------------------------------------------------------- 1 | (* 2 | MSAT is free software, using the Apache license, see file LICENSE 3 | Copyright 2014 Guillaume Bury 4 | Copyright 2014 Simon Cruanes 5 | *) 6 | 7 | (** {1 Logging functions} *) 8 | 9 | let debug_level_ = ref 0 10 | let set_debug l = debug_level_ := l 11 | let get_debug () = !debug_level_ 12 | 13 | let debug_fmt_ = ref Format.std_formatter 14 | 15 | let set_debug_out f = debug_fmt_ := f 16 | 17 | let debug_real_ l k = 18 | k (fun fmt -> 19 | CCFormat.fprintf !debug_fmt_ "@[<2>@{[debug %d]@}@ " l; 20 | Format.kfprintf 21 | (fun fmt -> Format.fprintf fmt "@]@.") 22 | !debug_fmt_ fmt) 23 | 24 | let debugf l k = 25 | if l <= !debug_level_ 26 | then debug_real_ l k 27 | 28 | let debug l msg = debugf l (fun k->k "%s" msg) 29 | -------------------------------------------------------------------------------- /src/Log.mli: -------------------------------------------------------------------------------- 1 | (* 2 | MSAT is free software, using the Apache license, see file LICENSE 3 | Copyright 2014 Guillaume Bury 4 | Copyright 2014 Simon Cruanes 5 | *) 6 | 7 | (** {1 Logging function, for debugging} *) 8 | 9 | val set_debug : int -> unit (** Set debug level *) 10 | 11 | val get_debug : unit -> int (** Current debug level *) 12 | 13 | val debugf : 14 | int -> 15 | ((('a, Format.formatter, unit, unit) format4 -> 'a) -> unit) -> 16 | unit 17 | (** Emit a debug message at the given level. If the level is lower 18 | than [get_debug ()], the message will indeed be emitted *) 19 | 20 | val debug : int -> string -> unit 21 | (** Simpler version of {!debug}, without formatting *) 22 | 23 | val set_debug_out : Format.formatter -> unit 24 | (** Change the output formatter. *) 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/Model.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Model} *) 5 | 6 | type term = Ast.term 7 | type ty = Ast.Ty.t 8 | type domain = ID.t list 9 | 10 | type t = private { 11 | env: Ast.env; 12 | (* environment, defining symbols *) 13 | domains: domain Ast.Ty.Map.t; 14 | (* uninterpreted type -> its domain *) 15 | consts: term ID.Map.t; 16 | (* constant -> its value *) 17 | } 18 | 19 | val make : 20 | env:Ast.env -> 21 | consts:term ID.Map.t -> 22 | domains:domain Ast.Ty.Map.t -> 23 | t 24 | 25 | val pp : t CCFormat.printer 26 | val pp_syn : Ast.syntax -> t CCFormat.printer 27 | 28 | val eval : t -> term -> term 29 | 30 | exception Bad_model of t * term * term 31 | -------------------------------------------------------------------------------- /src/Poly_set.ml: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Imperative Set} *) 5 | 6 | type 'a t = { 7 | eq: 'a -> 'a -> bool; 8 | vec: 'a CCVector.vector 9 | } 10 | 11 | let create (type a) ~eq _size : a t = 12 | {vec= CCVector.create (); eq; } 13 | 14 | let mem (type a) (set:a t) x = 15 | try 16 | (* search from the most recent elements, so that if we add 17 | the same element several times it gets faster *) 18 | let a = CCVector.unsafe_get_array set.vec in 19 | let n = CCVector.size set.vec in 20 | for i = n-1 downto 0 do 21 | if set.eq x (Array.unsafe_get a i) then raise Exit 22 | done; 23 | false 24 | with Exit -> true 25 | 26 | let add (type a) (set:a t) x = 27 | if not (mem set x) then CCVector.push set.vec x 28 | 29 | let to_iter (type a) (set:a t) = 30 | CCVector.to_iter set.vec 31 | 32 | let iter f s = to_iter s f 33 | -------------------------------------------------------------------------------- /src/Poly_set.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Imperative Set} *) 5 | 6 | type 'a t 7 | 8 | val create : 9 | eq:('a -> 'a -> bool) -> 10 | int -> 11 | 'a t 12 | (** [create ~eq ~hash size] makes a new set of initial size [size] *) 13 | 14 | val mem : 'a t -> 'a -> bool 15 | (** Check if an element is within *) 16 | 17 | val add : 'a t -> 'a -> unit 18 | (** Add an element *) 19 | 20 | val to_seq : 'a t -> 'a Iter.t 21 | (** Iterate on elements that are alive *) 22 | 23 | val iter : ('a -> unit) -> 'a t -> unit 24 | -------------------------------------------------------------------------------- /src/Solver.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Solver} 5 | 6 | The solving algorithm, based on MCSat *) 7 | 8 | module type CONFIG = sig 9 | val max_depth: int 10 | 11 | val deepening_step : int option 12 | (** Increment between two successive max depths in iterative deepening *) 13 | 14 | val uniform_depth : bool 15 | (** Depth increases uniformly *) 16 | 17 | val quant_unfold_depth : int 18 | (** Depth for quantifier unfolding *) 19 | 20 | val eval_under_quant : bool 21 | (** Evaluate under quantifiers to see if the body is a value *) 22 | 23 | val progress: bool 24 | (** progress display progress bar *) 25 | 26 | val pp_hashcons: bool 27 | 28 | val dimacs_file : string option 29 | (** File for dumping the SAT problem *) 30 | 31 | val check_proof : bool 32 | (** Check proofs given by MSat? *) 33 | end 34 | 35 | module Make(C:CONFIG)(Dummy : sig end) : sig 36 | type term 37 | type cst 38 | type ty_h (** types *) 39 | 40 | type cst_info 41 | 42 | type ty_def 43 | 44 | type ty_cell = 45 | | Prop 46 | | Atomic of ID.t * ty_def 47 | | Arrow of ty_h * ty_h 48 | 49 | type 'a db_env 50 | 51 | (** {2 Main} *) 52 | 53 | type model = Model.t 54 | 55 | type unknown = 56 | | U_timeout 57 | | U_max_depth 58 | | U_incomplete 59 | | U_undefined_values (* non-terminating functions, ill-applied selector, etc. *) 60 | 61 | val pp_unknown : unknown CCFormat.printer 62 | 63 | type res = 64 | | Sat of Model.t 65 | | Unsat (* TODO: proof *) 66 | | Unknown of unknown 67 | 68 | val pp_stats : unit CCFormat.printer 69 | 70 | val add_statement_l : Ast.statement list -> unit 71 | 72 | val is_prove : unit -> bool 73 | 74 | val solve : 75 | ?on_exit:(unit -> unit) list -> 76 | ?check:bool -> 77 | unit -> 78 | res 79 | (** [solve ()] checks the satisfiability of the statement added so far 80 | @param check if true, the model is checked before returning 81 | @param on_exit functions to be run before this returns *) 82 | end 83 | -------------------------------------------------------------------------------- /src/Util.ml: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Util} *) 5 | 6 | module Fmt = CCFormat 7 | 8 | type 'a printer = 'a CCFormat.printer 9 | 10 | let pp_list ?(sep=Fmt.return "@ ") pp out l = 11 | Fmt.list ~sep pp out l 12 | 13 | let pp_iter ?(sep=Fmt.return "@ ") pp out l = 14 | Fmt.iter ~sep pp out l 15 | 16 | let pp_array ?(sep=Fmt.return "@ ") pp out l = 17 | Fmt.array ~sep pp out l 18 | -------------------------------------------------------------------------------- /src/Util.mli: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | (** {1 Utils} *) 5 | 6 | type 'a printer = 'a CCFormat.printer 7 | 8 | val pp_list : ?sep:unit printer -> 'a printer -> 'a list printer 9 | val pp_iter : ?sep:unit printer -> 'a printer -> 'a Iter.t printer 10 | val pp_array : ?sep:unit printer -> 'a printer -> 'a array printer 11 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | 2 | (rule 3 | (targets const.ml) 4 | (action 5 | (with-stdout-to %{targets} 6 | (echo "let version = \"%{version:smbc}\"\n"))) 7 | ) 8 | 9 | ; main binary 10 | (executable 11 | (name smbc) 12 | (public_name smbc) 13 | (libraries containers iter msat tip-parser unix) 14 | (flags :standard -w +a-4-44-58-60-70@8 15 | -strict-sequence -color always -safe-string -warn-error -a+8) 16 | (ocamlopt_flags :standard -O3 -color always 17 | -unbox-closures -unbox-closures-factor 20) 18 | ) 19 | -------------------------------------------------------------------------------- /src/smbc.ml: -------------------------------------------------------------------------------- 1 | 2 | (* This file is free software. See file "license" for more details. *) 3 | 4 | type config = { 5 | syntax: Ast.syntax; 6 | max_depth: int; 7 | print_stat: bool; 8 | dot_term_graph: string option; 9 | pp_hashcons: bool; 10 | progress : bool; 11 | dimacs: string option; 12 | deepening_step: int option; 13 | uniform_depth: bool; 14 | quant_depth : int; 15 | eval_under_quant: bool; 16 | check: bool; 17 | check_proof: bool; 18 | } 19 | 20 | let parse_file (syn:Ast.syntax) (file:string) : Ast.statement list Ast.or_error = 21 | Log.debugf 2 (fun k->k "(@[parse_file@ %S@])" file); 22 | let dir = Filename.dirname file in 23 | Ast.parse ~include_dir:dir ~file syn 24 | 25 | let parse syn input: Ast.statement list = 26 | let res = match input with 27 | | `None -> failwith "provide one file or use --stdin" 28 | | `Stdin -> Ast.parse_stdin syn 29 | | `File f -> parse_file syn f 30 | in 31 | match res with 32 | | Result.Error msg -> print_endline msg; exit 1 33 | | Result.Ok l -> l 34 | 35 | let solve ~config (ast:Ast.statement list) : unit = 36 | let module Conf = struct 37 | let max_depth = config.max_depth 38 | let pp_hashcons = config.pp_hashcons 39 | let progress = config.progress 40 | let deepening_step = config.deepening_step 41 | let uniform_depth = config.uniform_depth 42 | let dimacs_file = config.dimacs 43 | let quant_unfold_depth = config.quant_depth 44 | let check_proof = config.check_proof 45 | let eval_under_quant = config.eval_under_quant 46 | end in 47 | let module S = Solver.Make(Conf)(struct end) in 48 | let on_exit = [] in 49 | (* solve *) 50 | S.add_statement_l ast; 51 | let res = S.solve ~on_exit ~check:config.check () in 52 | let is_prove = S.is_prove() in 53 | if config.print_stat then Format.printf "%a@." S.pp_stats (); 54 | match res with 55 | | S.Sat m -> 56 | if is_prove then ( 57 | Format.printf "\r(@[<1>result @{COUNTERSAT@}@ :model @[%a@]@])@." 58 | (Model.pp_syn config.syntax) m; 59 | ) else ( 60 | Format.printf "\r(@[<1>result @{SAT@}@ :model @[%a@]@])@." 61 | (Model.pp_syn config.syntax) m; 62 | ) 63 | | S.Unsat -> 64 | if is_prove then ( 65 | Format.printf "\r(result @{THEOREM@})@." 66 | ) else ( 67 | Format.printf "\r(result @{UNSAT@})@." 68 | ) 69 | | S.Unknown u -> 70 | Format.printf "\r(result @{UNKNOWN@} :reason %a)@." S.pp_unknown u 71 | 72 | (** {2 Main} *) 73 | 74 | let print_input_ = ref false 75 | let color_ = ref true 76 | let dot_term_graph_ = ref "" 77 | let stats_ = ref false 78 | let progress_ = ref false 79 | let pp_hashcons_ = ref false 80 | let max_depth_ = ref 1000 81 | let depth_step_ = ref 1 82 | let check_ = ref false 83 | let timeout_ = ref ~-1 84 | let syntax_ = ref Ast.Auto 85 | let uniform_depth_ = ref false 86 | let quant_depth_ = ref 3 87 | let eval_under_quant_ = ref true 88 | let version_ = ref false 89 | let dimacs_ = ref "" (* file to put sat problem in *) 90 | let check_proof_ = ref false 91 | 92 | let file = ref `None 93 | 94 | let set_file s = match !file with 95 | | `None -> file := `File s 96 | | `Stdin -> raise (Arg.Bad "cannot combine --stdin and file") 97 | | `File _ -> raise (Arg.Bad "provide at most one file") 98 | 99 | let set_stdin () = match !file with 100 | | `Stdin -> () 101 | | `None -> file := `Stdin; syntax_ := Ast.Tip 102 | | `File _ -> raise (Arg.Bad "cannot combine --stdin and file") 103 | 104 | let set_syntax_ s = 105 | syntax_ := 106 | begin match CCString.uncapitalize_ascii s with 107 | | "tip" -> Ast.Tip 108 | | _ -> failwith ("unknown syntax " ^ s) (* TODO list *) 109 | end 110 | 111 | let set_debug_ d = 112 | Log.set_debug d; 113 | Msat.Log.set_debug d; 114 | () 115 | 116 | let options = 117 | Arg.align [ 118 | "--print-input", Arg.Set print_input_, " print input"; 119 | "--max-depth", Arg.Set_int max_depth_, " set max depth"; 120 | "--dot-term-graph", Arg.Set_string dot_term_graph_, " print term graph in file"; 121 | "--check", Arg.Set check_, " check model"; 122 | "--no-check", Arg.Clear check_, " do not check model"; 123 | "-nc", Arg.Clear color_, " do not use colors"; 124 | "-p", Arg.Set progress_, " progress bar"; 125 | "--input", Arg.String set_syntax_, " input format"; 126 | "--stdin", Arg.Unit set_stdin, " parse on stdin (forces --input tip)"; 127 | "-i", Arg.String set_syntax_, " alias to --input"; 128 | "--pp-hashcons", Arg.Set pp_hashcons_, " print hashconsing IDs"; 129 | "--debug", Arg.Int set_debug_, " set debug level"; 130 | "-d", Arg.Int set_debug_, " set debug level"; 131 | "--stats", Arg.Set stats_, " print stats"; 132 | "--backtrace", Arg.Unit (fun () -> Printexc.record_backtrace true), " enable backtrace"; 133 | "--depth-step", Arg.Set_int depth_step_, " increment for iterative deepening"; 134 | "--uniform-depth", Arg.Set uniform_depth_, " uniform depth"; 135 | "--no-uniform-depth", Arg.Clear uniform_depth_, " non-uniform depth"; 136 | "--quant-depth", Arg.Set_int quant_depth_, " unfolding depth for quantifiers"; 137 | "--timeout", Arg.Set_int timeout_, " timeout (in s)"; 138 | "--dimacs", Arg.Set_string dimacs_, " file to output dimacs problem into"; 139 | "--check-proof", Arg.Set check_proof_, " check propositional proofs"; 140 | "--no-check-proof", Arg.Clear check_proof_, " do not check propositional proofs"; 141 | "--eval-under-quant", Arg.Set eval_under_quant_, " evaluate under quantifiers"; 142 | "--no-eval-under-quant", Arg.Clear eval_under_quant_, " evaluate under quantifiers"; 143 | "-t", Arg.Set_int timeout_, " alias to --timeout"; 144 | "--version", Arg.Set version_, " display version info"; 145 | ] 146 | 147 | let setup_timeout_ t = 148 | assert (t >= 1); 149 | Sys.set_signal Sys.sigalrm 150 | (Sys.Signal_handle (fun _ -> print_endline "(TIMEOUT)"; exit 0)); 151 | ignore (Unix.alarm !timeout_); 152 | () 153 | 154 | let setup_gc () = 155 | let g = Gc.get () in 156 | Gc.set { 157 | g with Gc. 158 | space_overhead = 3_000; (* major gc *) 159 | max_overhead = 10_000; (* compaction *) 160 | minor_heap_size = 500_000; (* ×8 to obtain bytes on 64 bits --> *) 161 | }; 162 | Gc.set g 163 | 164 | let () = 165 | Arg.parse options set_file 166 | "experimental SMT solver for datatypes and recursive functions.\n\ 167 | \n\ 168 | Usage: smbc [options] (file | --stdin).\n"; 169 | CCFormat.set_color_default !color_; 170 | if !version_ then ( 171 | Format.printf "version: %s@." Const.version; 172 | exit 0; 173 | ); 174 | if !timeout_ >= 1 then setup_timeout_ !timeout_; 175 | setup_gc (); 176 | (* parse *) 177 | let ast = parse !syntax_ !file in 178 | if !print_input_ 179 | then 180 | Format.printf "@[parsed:@ @[%a@]@]@." 181 | CCFormat.(list ~sep:(return "@,") Ast.pp_statement) ast; 182 | (* solve *) 183 | let config = { 184 | max_depth = !max_depth_; 185 | syntax= !syntax_; 186 | print_stat = !stats_; 187 | progress = !progress_; 188 | pp_hashcons = !pp_hashcons_; 189 | quant_depth= !quant_depth_; 190 | eval_under_quant= !eval_under_quant_; 191 | uniform_depth = !uniform_depth_; 192 | dimacs = (if !dimacs_ = "" then None else Some !dimacs_); 193 | deepening_step = 194 | (if !depth_step_ = 0 then None else Some !depth_step_); 195 | dot_term_graph = 196 | (if !dot_term_graph_ = "" then None else Some !dot_term_graph_); 197 | check= !check_; 198 | check_proof= !check_proof_; 199 | } in 200 | solve ~config ast 201 | -------------------------------------------------------------------------------- /utils/conv_lisp.ml: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ocaml 2 | 3 | #use "topfind";; 4 | #directory "_build/src/";; 5 | #require "containers";; 6 | #require "containers.sexp";; 7 | #require "sequence";; 8 | #require "result";; 9 | #require "tip_parser";; 10 | #load "Hash.cmo";; 11 | #load "Utils.cmo";; 12 | #load "ID.cmo";; 13 | #load "Log.cmo";; 14 | #load "Parse_ast.cmo";; 15 | #load "Parser_smbc.cmo";; 16 | #load "Lexer_smbc.cmo";; 17 | #load "Ast.cmo";; 18 | 19 | let process file = 20 | Format.printf "processing `%s`@." file; 21 | let stmts = Ast.parse ~include_dir:(Filename.dirname file) ~file Ast.Smbc in 22 | begin match stmts with 23 | | Result.Ok l -> 24 | (* Format.printf "@[<2>parsed@ %a@]@." (CCFormat.list Ast.pp_statement) l; *) 25 | let out_file = Filename.chop_suffix file ".lisp" ^ ".smt2" in 26 | CCIO.with_out out_file 27 | (fun oc -> 28 | let out = Format.formatter_of_out_channel oc in 29 | Format.fprintf out "@[%a@]@." 30 | (CCFormat.list ~start:"" ~stop:"" ~sep:"" Ast.pp_statement_tip) l) 31 | | Result.Error e -> 32 | print_endline e; 33 | exit 1 34 | end 35 | 36 | let () = 37 | for i=1 to Array.length Sys.argv-1 do 38 | process Sys.argv.(i) 39 | done 40 | -------------------------------------------------------------------------------- /utils/lsc.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # script for Lazy Small Check 4 | # use: `lsc.sh file.smt2 timeout` 5 | 6 | TIP_FILE=$1 7 | TIMEOUT=$2 8 | 9 | BASENAME=`basename $1 .smt2` 10 | ROOT=/tmp/lsc/`dirname $1`/ 11 | mkdir -p $ROOT 12 | HS_FILE=$ROOT/$BASENAME.hs 13 | BINARY=$ROOT/$BASENAME 14 | 15 | tip --haskell-lazysc $TIP_FILE > $HS_FILE 16 | ghc --make $HS_FILE -o $BINARY 17 | ulimit -t $2 ; exec $BINARY 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /utils/profile.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | perf record --call-graph=dwarf $@ 4 | 5 | perf script \ 6 | | stackcollapse-perf --kernel \ 7 | | sed 's/caml//g' \ 8 | | flamegraph > perf.svg 9 | 10 | --------------------------------------------------------------------------------