Git Product home page Git Product logo

sally's Introduction

Build Status Coverage Status Coverity Scan Build Status

Sally

Sally is a model checker for infinite state systems described as transition systems. It is research software under development so the features and the input language may change rapidly.

Prerequisites

In order to compile Sally you will need a reasonable c++ compiler such as g++ or clang, the cmake build system, the GMP library, some boost libraries, and a working Java runtime (for parser generation). On Ubuntu-like systems, the following should cover it:

sudo apt-get install g++
sudo apt-get install cmake
sudo apt-get install libgmp-dev
sudo apt-get install libboost-program-options-dev libboost-iostreams-dev libboost-test-dev libboost-thread-dev libboost-system-dev
sudo apt-get install default-jre

In addition, Sally needs an SMT solver for reasoning about the systems. It currently supports Yices2, MathSAT5, and OpenSMT2. Optionally, Sally can also use dReal.

For best results, we recommend using Yices2 and at least one of MathSAT5 or OpenSMT2 (or both).

How to Compile

You can configure and build Sally with:

cd build
cmake ..
make
make check

The cmake command will search for the necessary libraries and for the backend SMT solvers installed on your system.

For convenience, you can take a look at the at the following scripts to install some common SMT solvers:

If a solver is installed in a non-standard location, and cmake does not find it, you can give extra options. For example, if MathSAT5 is installed in the $MD directory, meaning that there are $MD/include and $MD/lib directories with MathSAT5 headers and libraries, then configure and build with

cd build
cmake .. -DMATHSAT5_HOME=$MD
make
make check

You can also set YICES2_HOME, OPENSMT2_HOME, or DREAL_HOME.

To compile Sally in debug mode, build with

cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make
make check

In order to use the non-linear capabilities of Yices2 in Sally, you must use a version of Yices2 compiled with MCSAT support, and LibPoly must be installed on your system. As above, you can pass -DLIBPOLY_HOME=$LPD to cmake if LibPoly is installed in a non-standard location.

Input Language

Sally takes as input a simple description of transition systems based on the SMT2 language. A transition system consists of a description of the state type, a formula describing the initial states of the system, and a formula describing the transitions from the current to the next state of the system.

State Types

State type is a list of variables that are part of the state, together with their types.

;; A definition of a state type called "my_state_type" with variables
;; x and y of type Real.
(define-state-type my_state_type
  ((x Real) (y Real))
)

Sometimes it is useful to model systems that take inputs that are not part of the system state. Such inputs can be defined by using the more general form of state type definition.

;; State type with inputs
(define-state-type state_type_with_inputs
  ((x Real) (y Real))
  ((d Real))
)

Above, the variable d is such an input. These input variables can only be referenced in transition formulas, by using the input namespace.

With a defined state type, we can define sets of states and transitions over the state type.

State Formulas

We can describe a set of states with a state formula over the state type. A state formula is a first-order formula over the variables of the state type, written in SMT2 format.

;; Definition of a set of states "x_is_zero" capturing all states
;; over the state type "my_state_type" where x is 0.
(define-states x_is_zero my_state_type
  (= x 0)
)

Once a state formula has been defined it can be reused in other state formulas over the same state type.

;; A definition of a set of states "initial_states" over
;; "my_state_type" by a state formula. These are all states where
;; both x and y are 0.
(define-states initial_states my_state_type
  (and x_is_zero (= y 0))
)

State Transitions

We can describe allowed state transitions by a first-order formula over the current (state) and next variables of the state type. We use the prefix state to denote current variables, and the prefix next to denote the variables in the next state. Previously defined state formulas over the same state type can be used as if they were variables (state or next). Similarly, previously defined transitions over the same type can be used directly.

;; Definition of a transition where the next value of x is the
;; current value + 1.
(define-transition inc_x my_state_type
  (= next.x (+ state.x 1))
)

;; Definition of a transition that increases both x and y
(define-transition inc_x_and_y my_state_type
  (and inc_x (= next.y (+ state.y 1)))
)

;; Definition of a transition that increases x and y if not
;; exceeding 100, or goes back to the state with x = y = 0
(define-transition transition my_state_type
  (or
    (and (< state.x 100) inc_x_and_y)
    next.initial_states
  )
)

Transition Systems

We can define a state transition system by defining the state type, the initial states of the system and the transitions that the system can make.

;; Directly define a simple counter system that increases x and y
(define-transition-system T1 my_state_type
  ;; Initial states
  (and (= x 0) (= y 0))
  ;; Transition
  (and (= next.x (+ state.x 1)) (= next.y (+ state.y 1)))
)

;; Define the counter system that can reset to 0 by reusing defined
;; formulas
(define-transition-system T2 my_state_type
   ;; Initial states
   initial_states
   ;; Transitions
   transition
)

;; Transition system with inputs
(define-transition-system T3 state_type_with_inputs
  (and (= x 0) (= y 0))
  (and (= next.x (+ state.x input.d))
   (= next.y (+ state.y input.d))
  )
)

Adding assumptions

Additional constraints can be added to the transition system after it has been defined.

To add a state formula as an additional assumption of the system (it holds at initial states, it holds before and after every transition), we can use the assume command.

;; Add assumptions on the system
(assume T3
  (and (<= x 100) (<= y 100))
)

To add an assumption on the input values of the system, we can use the assume-input command.

;; Add assumption on the input space
(assume-input T3
  (>= d 0)
)

Queries

A query asks whether a state property is invariant for the given transition system (i.e., whether the state property is true in all reachable states). For example, in the system T1, it is clear that we the variables x and y will always be equal and non-negative. We can check these with the following queries.

;; Check whether x = y in T1
(query T1 (= x y))

;; Check whether x, y >= 0
(query T1 (and (>= x 0) (>= y 0)))

In the system T2, it should hold that both x and y will never exceed 20.

;; Check whether x, y <= 20
(query T2 (and (<= x 20) (<= y 20)))

;; Check whether x, y <= 19
(query T2 (and (<= x 19) (<= y 19)))

In the system T3, the variables x and y should always be equal.

;; Check whether we're always the same
(query T3 (= x y))

The full example above is available in examples/example.mcmt.

Usage

To see the full set of options, run sally -h. Some typical examples are as follows

  • Checking the properties with the bounded model-checking (BMC) engine
> sally --engine bmc examples/example.mcmt
unknown
unknown
unknown
unknown
unknown
  • Checking the property with BMC with a bigger bound and showing any counter-example traces
> sally --engine bmc --bmc-max 20 --show-trace examples/example.mcmt
unknown
unknown
unknown
invalid
(trace
  (state (x 0) (y 0))
  (state (x 1) (y 1))
  ...
  (state (x 20) (y 20))
)
unknown
  • Checking the properties with the k-induction engine
> sally --engine kind examples/example.mcmt
valid
valid
unknown
unknown
valid
> sally --engine kind --kind-max 20 examples/example.mcmt
valid
valid
unknown
invalid
valid
  • Checking the properties with the pdkind engine using the combination of yices2 and MathSAT5 as the reasoning engine
> sally --engine pdkind --solver y2m5 examples/example.mcmt
valid
valid
valid
invalid
valid
  • Checking nonlinear properties with Yices2

By relying on Yices2 with support for MCSAT, you can use Sally to reason about (polynomial) non-linear systems using BMC and k-induction. The following example models two systems computing sums S1 = 1 + 2 + ... + n and S2 = 1^2 + 2^2 + ... + n^2, and asks whether S1 = n*(n+1)/2 and S2 = n*(n+1)*(2n+1)/6.

;; Maintain Sum and n
(define-state-type ST ((Sum Real) (n Real)))
;; Initial states: Sum = 0, n = 0
(define-states Init ST (and (= Sum 0) (= n 0)))

;; Transition: Sum += n; n ++;
(define-transition Trans1 ST (and
  (= next.Sum (+ state.Sum state.n))
  (= next.n (+ state.n 1))
))

;; Transition system: Sum = 1 + 2 + ... + (n-1)
(define-transition-system T1 ST Init Trans1)
;; Sum = n*(n-1)/2
(query T1 (= Sum (/ (* n (- n 1)) 2)))

;; Transition: Sum += n^2; n ++;
(define-transition Trans2 ST (and
    (= next.Sum (+ state.Sum (* state.n state.n)))
    (= next.n (+ state.n 1))
))

;; Transition system: Sum = 1^2 + 2^2 + ... + (n-1)^2
(define-transition-system T2 ST Init Trans2)
;; Sum = n*(n-1)/2
(query T2 (= Sum (/ (* n (- n 1) (- (* 2 n) 1)) 6)))

We can prove these two properties with Sally by using Yices2 with MCSAT as follows

> sally --engine kind ../examples/example-nra.mcmt
valid
valid

Acknowledgments

Sally's development has been funded by the National Science Foundation, the National Aeronautics and Space Administration, and the Defense Advanced Research Projects Agency.

sally's People

Contributors

blishko avatar brunodutertre avatar caballa avatar dddejan avatar ianamason avatar matt-noonan avatar srivatsan-varadarajan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sally's Issues

Parse errors

It seems sally can only parse examples from /test/regess/*.

Whenever running the mcmt cases from the examples folder, I got the following information:

Parse error: ../../examples/honeywell/Ex3.mcmt:28:20:

And the sal cases returned

src/parser/sal/sal_state.cpp:620: sally::expr::term_ref sally::parser::sal_state::mk_term_from_guarded(sally::expr::term_ref, const std::vector<sally::expr::term_ref>&): Assertion false 'failed'. Aborted (core dumped)

Failure in yices model construction.

Yices fails an assert when running on regresssion examples:

dejan@raven:~/workspace/sally/build$ ./src/sally -v 1 --engine ic3 /home/dejan/workspace/sally/test/regress/ic3/example6.a.mcmt
[2015-04-08.19:27:36] Processing /home/dejan/workspace/sally/test/regress/ic3/example6.a.mcmt
[2015-04-08.19:27:36] ic3: Extending trace to 0
[2015-04-08.19:27:36] ic3: starting search
[2015-04-08.19:27:36] ic3: Extending trace to 1
[2015-04-08.19:27:36] ic3: Extending trace to 2
sally: ./terms/terms.h:1015: kind_for_idx: Assertion `good_term_idx(table, i)' failed.
Aborted (core dumped)

Backtrace

#0  0x00007ffff5df2e37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff5df4528 in __GI_abort () at abort.c:89
#2  0x00007ffff5debce6 in __assert_fail_base (fmt=0x7ffff5f3bc08 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", 
    assertion=assertion@entry=0x7ffff7afa0b3 "good_term_idx(table, i)", file=file@entry=0x7ffff7afa0a3 "./terms/terms.h", 
    line=line@entry=1015, function=function@entry=0x7ffff7afa864 <__PRETTY_FUNCTION__.9316> "kind_for_idx") at assert.c:92
#3  0x00007ffff5debd92 in __GI___assert_fail (assertion=0x7ffff7afa0b3 "good_term_idx(table, i)", file=0x7ffff7afa0a3 "./terms/terms.h", 
    line=1015, function=0x7ffff7afa864 <__PRETTY_FUNCTION__.9316> "kind_for_idx") at assert.c:101
#4  0x00007ffff794a221 in kind_for_idx (table=0x7ffff7dd86c0 <terms>, i=4) at ./terms/terms.h:1015
#5  0x00007ffff794a261 in term_kind (table=0x7ffff7dd86c0 <terms>, t=8) at ./terms/terms.h:1095
#6  0x00007ffff794c21a in context_build_model (model=0x17f6540, ctx=0x17b9fd0) at context/context_solver.c:698
#7  0x00007ffff792c9fa in yices_get_model (ctx=0x17b9fd0, keep_subst=1) at api/yices_api.c:7488
Python Exception <class 'ValueError'> Cannot find type const std::set<sally::expr::term_ref, std::less<sally::expr::term_ref>, std::allocator<sally::expr::term_ref> >::_Rep_type: 
#8  0x00000000006fe4f2 in sally::smt::yices2_internal::generalize (this=0x17b9e50, type=sally::smt::solver::GENERALIZE_BACKWARD, 
    to_eliminate=std::set with 3 elements, projection_out=std::vector of length 0, capacity 0)
    at /home/dejan/workspace/sally/src/smt/yices2/yices2_internal.cpp:834
#9  0x00000000006f9908 in sally::smt::yices2::generalize (this=0x17b9dc0, type=sally::smt::solver::GENERALIZE_BACKWARD, 
    projection_out=std::vector of length 0, capacity 0) at /home/dejan/workspace/sally/src/smt/yices2/yices2.cpp:83
#10 0x000000000067489c in sally::ic3::ic3_engine::generalize_sat_at (this=0x174fca0, k=1, solver=0x17b9dc0)
    at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:927
#11 0x0000000000674f49 in sally::ic3::ic3_engine::check_inductive_at (this=0x174fca0, k=1, F=...)
    at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:135
#12 0x00000000006790e9 in sally::ic3::ic3_engine::push_if_inductive (this=0x174fca0, ind=...)
    at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:537
#13 0x000000000067a08a in sally::ic3::ic3_engine::push_current_frame (this=0x174fca0)
    at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:697
#14 0x000000000067a2b0 in sally::ic3::ic3_engine::search (this=0x174fca0) at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:728
#15 0x000000000067ac60 in sally::ic3::ic3_engine::query (this=0x174fca0, ts=0x17610d0, sf=0x175b870)
    at /home/dejan/workspace/sally/src/engine/ic3/ic3_engine.cpp:832
#16 0x000000000068e26a in sally::parser::query_command::run (this=0x1761150, ctx=0x7fffffffd9b0, e=0x174fca0)
    at /home/dejan/workspace/sally/src/parser/command.cpp:118
#17 0x00000000006467a8 in main (argc=6, argv=0x7fffffffdea8) at /home/dejan/workspace/sally/src/sally.cpp:114

Incorrect traces, depending on the order of queries

This is with the version of Sally compiled again revision c9856e7 from GitHub.

Sally seems to be producing incorrect traces in some cases. Here is an example transitions system with two queries:

(define-state-type
   S
   (
     (p Int)
     (p_del Int)
     (p_nil Bool)
     (x Int)
     (x_del Int)
     (x_nil Bool)
     (y Int)
     (y_del Int)
     (y_nil Bool))
   ())
(define-transition-system
   TS
   S
   (and
      (= y x)
      (= y_del x_del)
      (= y_nil true)
      (=
         p
         (+ 1 y))
      (= p_del 0)
      (=
         p_nil
         (or false y_nil))
      (= 0 y_del)
      (= x 1)
      (= x_del 0)
      (= x_nil false))
   (and
      (= next.y state.x)
      (= next.y_del state.x_del)
      (= next.y_nil state.x_nil)
      (=
         next.p
         (+ 1 next.y))
      (= next.p_del 0)
      (=
         next.p_nil
         (or false next.y_nil))
      (= 0 next.y_del)
      (= next.x next.p)
      (= next.x_del next.p_del)
      (= next.x_nil next.p_nil)))
(query
   TS
   (= x 1))
(query
   TS
   (= x 2))

This produces the traces below, using flags: sally --engine=pdkind --show-trace

invalid
(trace 
  (state
    (p 2)
    (|p_del| 0)
    (|p_nil| true)
    (x 1)
    (|x_del| 0)
    (|x_nil| false)
    (y 1)
    (|y_del| 0)
    (|y_nil| true)
  )
  (input
  )
  (state
    (p 2)
    (|p_del| 0)
    (|p_nil| false)
    (x 2)
    (|x_del| 0)
    (|x_nil| false)
    (y 1)
    (|y_del| 0)
    (|y_nil| false)
  )
)

invalid
(trace 
  (state
    (p 2)
    (|p_del| 0)
    (|p_nil| true)
    (x 1)
    (|x_del| 0)
    (|x_nil| false)
    (y 1)
    (|y_del| 0)
    (|y_nil| true)
  )
  (input
  )
  (state
    (p 2)
    (|p_del| 0)
    (|p_nil| false)
    (x 2)
    (|x_del| 0)
    (|x_nil| false)
    (y 1)
    (|y_del| 0)
    (|y_nil| false)
  )
)

The first trace is the correct answer for query 1, however the second one appears to be just a copy of the first. Indeed, query 2 should fail with an empty trace, as it is already false in the initial state.

If I swap the order of the queries, then I get the expected answer.

Segfaults

I just built sally from the git repo (c9856e7) and I am getting segfaults on some queries. For example, the README example seems to crash on the 2nd query:

sally --engine bmc example.mcmt 
unknown
Segmentation fault

Some of the tests also segfault (e.g., 2 and 17).

This is on Linux Mint 18.1, with the binary version of yices downloaded from their website:

  Yices 2.5.4
Copyright SRI International.
Linked with GMP 6.1.2
Copyright Free Software Foundation, Inc.
Build date: 2017-10-16
Platform: x86_64-pc-linux-gnu (release/static)

Unable to use escaped ids

The grammar for sally seems to allowed escaped ids by surrounding them with |...|, but I can't seem to get an example to work using them. In particular, neither |next.x| nor next.|x| seem to work when referencing a variable called |x|.

Improve integer reasoning

For software verification and the SyGuS competition. Need to finish integration of Yices2 generalization for integers.

Z3 mystery

I have version 4.5.1 of Z3 installed in /usr/local/z3

I configure sally with:

cmake .. -DMATHSAT5_HOME=/usr/local/mathsat5 -DYICES2_HOME=/usr/local/yices2 -DZ3_HOME=/usr/local/z3

which results in

<snip>
-- Could NOT find Z3 (missing:  Z3_LIBRARY Z3_INCLUDE_DIR) (Required is at least version "4.4.1")
<snip>

Ideas?

Integrate crab into Sally

I've added some boilerplate to the "ai" branch.

Notes:

  • The code for crab integration should be added to src/ai/crab/crab.{h.cpp}.
  • Any options for the module should be added to src/ai/crab/crab_info.h and they will automatically be available from command line.
  • We try to use regular c++ features, if crab is using new c++ features they should only be used within crab.cpp so that they don't leak out to the rest of the project.

"Variable not part of model" when showing trace

This is using revision 0184506 form GitHub.

It seems that something went wrong with the handling of inputs. Here is a small example:

(define-state-type
   S
   ((x Int))
   ((i Int)))
(define-transition-system
   TS
   S
   (= x 0)
   (= next.x (+ state.x 1)))
(query
   TS
   (< x 10))

Running sally --engine=pdkind --show-trace on it results in:

invalid
(trace 
  (state
    (x 0)
  )
  (input
    (i Variable |i0.i| is not part of the model.

Some weird error with regression test `pdkind/example9.mcmt` in debug mode

I know travis was able to run all the tests successfully in debug mode (https://travis-ci.org/SRI-CSL/sally/jobs/298145318). However, when I run the command sally --engine=pdkind test/regress/pdkind/example9.mcmt and built sally (master branch) in Debug mode I get the following assertion violation:

Assertion failed: (arithvar_has_right_type(ctx, x, tau)), function translate_arithvar_to_eterm, file context/context.c, line 117.

This is the output of cmake ..

-- The C compiler identification is AppleClang 7.3.0.7030031
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - found
-- Found Threads: TRUE  
-- Boost version: 1.65.1
-- Found the following Boost libraries:
--   program_options
--   iostreams
--   thread
--   system
--   regex
--   chrono
--   date_time
--   atomic
-- GMP library: /usr/local/lib/libgmp.dylib
-- Could NOT find Z3 (missing: Z3_LIBRARY Z3_INCLUDE_DIR) (Required is at least version "4.4.1")
-- Boost version: 1.65.1
-- Found the following Boost libraries:
--   unit_test_framework
--   iostreams
--   program_options
--   regex
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/E30338/Repos/SRI-CSL/sally/build

Finish garbage-collection

  • memory consumption is starting to show on deep examples.
  • model usege creates too many value terms, these need to be collected

Assertion failure in Yices

To run it use

./builds/src/sally --engine ic3 --lsal-extensions -v 1 --solver y2m5 examples/tte_synchro/tte_synchro.mcmt examples/tte_synchro/tte_synchro.cm_clock_distance.mcmt -d ic3::generalization -d ic3 -d ic3::deadlock

The assertion fails

sally: solvers/simplex/simplex.c:6949: simplex_process_var_diseq: Assertion `arith_var_has_eterm(&solver->vtbl, x1) && arith_var_has_eterm(&solver->vtbl, x2) && x1 != x2' failed.

Abstraction infinite loop

An hard example that goes into infinite loop with the polyhedra domain.

(define-state-type state_type ((x Real) (y Real)))

(define-states initial_states state_type
  (and (= x 1) (= y 0))
)

(define-transition transition state_type
  (and
    (= next.x (+ (* (/ 3 5) state.x) (* (/ 4 5) state.y)))
    (= next.y (+ (* (- (/ 4 5)) state.x) (* (/ 3 5) state.y)))
  )
)

(define-transition-system T state_type initial_states transition)

(query T (<= x 1))

Multi-property solving

Sally seems to process process queries sequentially. For k-induction, it's often beneficial to attack problems simultaneously so that they can be used to strengthen each other. We can simulate this by just conjoining all of our properties, but if any one of them is false then the whole property becomes false.

Something like the "Multi-property incremental verification" from "Incremental verification with mode variable invariants in state machines" by Kahsai, et al. would be very useful.

C++ API for sally?

Hi, is there any plan for providing C++ api for creating and verifying a transition system?

Suggestions on input format

I am thankful to the contributors for the wonderful work they have done. I have found the format useful (and simple) to extend SMT2 format to state transition systems (finite and infinite). I would like to suggest a few syntax changes/extensions to the .mcmt format.

  1. Is there any specific reason why the keyword "define-state-type" has been used? Since the format allows definition of state variables as well as input variables, I would suggest either splitting state and input declarations separately. Example:
(define-state-type states  (x Real) (y Real))
(define-input-type inputs  (d Real))

Another alternative is to use keyword "define-type" instead of "define-state-type" (to avoid splitting) and possible confusion).

  1. What's the reason for using state.x (for present state variable) when describing the transition relation? It is completely understood that next.x is needed to represent the next state variable versions. Moreover, the syntax state.x is not globally followed in the format (for example when defining a state formula, x is used directly).

  2. The format looks simple (and useful) enough to extend for finite state transition systems, by borrowing syntax from QF_BV theory of SMT2 format. Here is an example of a finite version of example.mcmt. Any comment/suggestion would be appreciated.

;; Define Constants
(define-constant K0 (_ bv0 32))
(define-constant K1 (_ bv1 32))
(define-constant K19 (_ bv19 32))
(define-constant K20 (_ bv20 32))

;; A definition of a state type called "my_state_type" with variables
;; x and y of type (_ BitVec 32). 
(define-state-type my_state_type 
  ((x (_ BitVec 32)) (y (_ BitVec 32)))
)

;; Definition of a set of states "x_is_zero" capturing all states 
;; over the state type "my_state_type" where x is 0.
(define-states x_is_zero my_state_type
  (= x K0)
)

;; A definition of a set of states "initial_states" over 
;; "my_state_type" by a state formula. These are all states where 
;; both x and y are 0.
(define-states initial_states my_state_type
  (and x_is_zero (= y K0))
)

;; Definition of a transition where the next value of x is the 
;; current value + 1.
(define-transition inc_x my_state_type
  (= next.x (bvadd state.x K1))
)   

;; Definition of a transition that increases both x and y
(define-transition inc_x_and_y my_state_type
  (and inc_x (= next.y (bvadd state.y K1)))
)

;; Definition of a transition that increases x and y if not 
;; exceeding 20, or goes back to the state with x = y = 0
(define-transition transition my_state_type
  (or 
(and (bvult state.x K20) inc_x_and_y)
next.initial_states
  ) 
)

;; Directly define a simple counter system that increases x and y
(define-transition-system T1 my_state_type
   ;; Initial states 
   (and (= x K0) (= y K0))
   ;; Transition 
   (and (= next.x (bvadd state.x K1)) (= next.y (bvadd state.y K1)))
)

;; Define a counter system that can reset to 0 by reusing defined
;; formulas 
(define-transition-system T2 my_state_type
   ;; Initial states
   initial_states
   ;; Transitions 
   transition
)

;; Check whether x = y in T1
(query T1 (= x y))

;; Check whether x, y >= 0
(query T1 (and (bvuge x K0) (bvuge y K0)))

;; Check whether x, y <= 20
(query T2 (and (bvule x K20) (bvule y K20)))

;; Check whether x, y <= 19
(query T2 (and (bvule x K19) (bvule y K19)))

;; State type with inputs 
(define-state-type state_type_with_inputs
  ((x (_ BitVec 32)) (y (_ BitVec 32)))
  ((d (_ BitVec 32))) 
)

;; Transition system with inputs 
(define-transition-system T3 state_type_with_inputs
  (and (= x K0) (= y K0))
  (and (= next.x (bvadd state.x input.d))
   (= next.y (bvadd state.y input.d))
  )
) 

;; Check whether we're always the same 
(query T3 (= x y)) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.