B provides the booleans, strings and integers as built-in datatypes. (Strings are not available in Event-B.)
B provides the booleans, strings and integers as built-in datatypes. (Strings are not available in Event-B.)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
BOOL
BOOL
```
```
%% Output
%% Output
$\{\mathit{FALSE},\mathit{TRUE}\}$
$\{\mathit{FALSE},\mathit{TRUE}\}$
{FALSE,TRUE}
{FALSE,TRUE}
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
"this is a string"
"this is a string"
```
```
%% Output
%% Output
$\text{"this is a string"}$
$\text{"this is a string"}$
"this is a string"
"this is a string"
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
1024
1024
```
```
%% Output
%% Output
$1024$
$1024$
1024
1024
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Users can define their own datatype in a B machine.
Users can define their own datatype in a B machine.
One distinguishes between explicitly specified enumerated sets and deferred sets.
One distinguishes between explicitly specified enumerated sets and deferred sets.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
::load
::load
MACHINE MyBasicSets
MACHINE MyBasicSets
SETS Trains = {thomas, gordon}; Points
SETS Trains = {thomas, gordon}; Points
END
END
```
```
%% Output
%% Output
Loaded machine: MyBasicSets
Loaded machine: MyBasicSets
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
For animation and constraint solving purposes, ProB will instantiate deferred sets to some finite set (the size of which can be controlled and is partially inferred).
For animation and constraint solving purposes, ProB will instantiate deferred sets to some finite set (the size of which can be controlled and is partially inferred).
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
Points
Points
```
```
%% Output
%% Output
$\{\mathit{Points1},\mathit{Points2}\}$
$\{\mathit{Points1},\mathit{Points2}\}$
{Points1,Points2}
{Points1,Points2}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Pairs ###
### Pairs ###
B also has pairs of values, which can be written in two ways:
B also has pairs of values, which can be written in two ways:
B provides many operators which return values, such as the usual arithmetic operators but also many operators for sets, relations and functions.
B provides many operators which return values, such as the usual arithmetic operators but also many operators for sets, relations and functions.
For example set union and set difference:
For example set union and set difference:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
(1..3 \/ 5..10) \ (2..6)
(1..3 \/ 5..10) \ (2..6)
```
```
%% Output
%% Output
$\{1,7,8,9,10\}$
$\{1,7,8,9,10\}$
{1,7,8,9,10}
{1,7,8,9,10}
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
(1..3 ∪ 5..10) \ (2..6)
(1..3 ∪ 5..10) \ (2..6)
```
```
%% Output
%% Output
$\{1,7,8,9,10\}$
$\{1,7,8,9,10\}$
{1,7,8,9,10}
{1,7,8,9,10}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
The range of a relation or function:
The range of a relation or function:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
dom({(thomas↦1),(gordon↦2)})
dom({(thomas↦1),(gordon↦2)})
```
```
%% Output
%% Output
$\{thomas,gordon\}$
$\{thomas,gordon\}$
{thomas,gordon}
{thomas,gordon}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Function application:
Function application:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
{(thomas↦1),(gordon↦2)} (thomas)
{(thomas↦1),(gordon↦2)} (thomas)
```
```
%% Output
%% Output
$1$
$1$
1
1
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Relational inverse (.~) and relational image .[.] :
Relational inverse (.~) and relational image .[.] :
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
{(thomas↦1),(gordon↦2)}~[2..3]
{(thomas↦1),(gordon↦2)}~[2..3]
```
```
%% Output
%% Output
$\{\mathit{gordon}\}$
$\{\mathit{gordon}\}$
{gordon}
{gordon}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Predicates
## Predicates
ProB can also be used to evaluate predicates (B distinguishes between expressions which have a value and predicates which are either true or false).
ProB can also be used to evaluate predicates (B distinguishes between expressions which have a value and predicates which are either true or false).
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
2>3
2>3
```
```
%% Output
%% Output
$FALSE$
$FALSE$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
3>2
3>2
```
```
%% Output
%% Output
$TRUE$
$TRUE$
TRUE
TRUE
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Within predicates you can use **open** variables, which are implicitly existentially quantified.
Within predicates you can use **open** variables, which are implicitly existentially quantified.
ProB will display the solution for the open variables, if possible.
ProB will display the solution for the open variables, if possible.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
x*x=100
x*x=100
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
**Solution:**
**Solution:**
* $\mathit{x} = -10$
* $\mathit{x} = -10$
TRUE
TRUE
Solution:
Solution:
x = −10
x = −10
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
We can find all solutions to a predicate by using the set comprehension notation.
We can find all solutions to a predicate by using the set comprehension notation.
Note that by this we turn a predicate into an expression.
Note that by this we turn a predicate into an expression.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
{x|x*x=100}
{x|x*x=100}
```
```
%% Output
%% Output
$\{-10,10\}$
$\{-10,10\}$
{−10,10}
{−10,10}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Substitutions (Statements) ###
### Substitutions (Statements) ###
B also has a rich syntax for **substitutions**, aka statements.
B also has a rich syntax for **substitutions**, aka statements.
For example ```x := x+1``` increments the value of x by 1.
For example ```x := x+1``` increments the value of x by 1.
Other constructs are WHILE loops and CASE statements.
Other constructs are WHILE loops and CASE statements.
We will not talk about substitutions in the rest of this presentation.
We will not talk about substitutions in the rest of this presentation.
But B can provide a nice mixture of **functional programming**, **constraint programming** and **imperative programming**, with precise proof rules rooted in logic.
But B can provide a nice mixture of **functional programming**, **constraint programming** and **imperative programming**, with precise proof rules rooted in logic.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Definition of Constraint Solving ##
## Definition of Constraint Solving ##
Constraint solving is determine whether a predicate with open/existentially quantified variables is satisfiable and providing values for the open variables in case it is.
Constraint solving is determine whether a predicate with open/existentially quantified variables is satisfiable and providing values for the open variables in case it is.
We have already solved the predicate ```x*x=100``` above, yielding the solution ```x=-10```.
We have already solved the predicate ```x*x=100``` above, yielding the solution ```x=-10```.
The difference to **proof** is that in constraint solving one has to produce a solution (aka a model). The difference to **execution** is that not all variables are known.
The difference to **proof** is that in constraint solving one has to produce a solution (aka a model). The difference to **execution** is that not all variables are known.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Constraint Solving Applications ##
## Constraint Solving Applications ##
Constraint solving has many applications in formal methods in general and B in particular:
Constraint solving has many applications in formal methods in general and B in particular:
* Animation, in particular dealing with implict specifications to determine parameters
* Animation, in particular dealing with implict specifications to determine parameters
* Test-case generation
* Test-case generation
* Bounded Model Checking
* Bounded Model Checking
* Disprover and prover
* Disprover and prover
* Enabling analysis (determining implicit control flow)
* Enabling analysis (determining implicit control flow)
and many more
and many more
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
As no counter example has been found, we can in this case establish the goal to be proven.
As no counter example has been found, we can in this case establish the goal to be proven.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Modelling and Solving Problems in B ###
### Modelling and Solving Problems in B ###
Obviously, we can also use constraint solving in B to solve puzzles or real-life problems.
Obviously, we can also use constraint solving in B to solve puzzles or real-life problems.
In other words, we use B as way to express constraint problems in almost pure mathematics.
In other words, we use B as way to express constraint problems in almost pure mathematics.
#### Send More Money Puzzle ####
#### Send More Money Puzzle ####
We now try and solve the SEND+MORE=MONEY arithmetic puzzle in B, involving 8 distinct digits:
We now try and solve the SEND+MORE=MONEY arithmetic puzzle in B, involving 8 distinct digits:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:prettyprint {S,E,N,D, M,O,R, Y} <: 0..9 & S >0 & M >0 & card({S,E,N,D, M,O,R, Y}) = 8 &
:prettyprint {S,E,N,D, M,O,R, Y} <: 0..9 & S >0 & M >0 & card({S,E,N,D, M,O,R, Y}) = 8 &
S*1000 + E*100 + N*10 + D + M*1000 + O*100 + R*10 + E = M*10000 + O*1000 + N*100 + E*10 + Y
S*1000 + E*100 + N*10 + D + M*1000 + O*100 + R*10 + E = M*10000 + O*1000 + N*100 + E*10 + Y
{S,E,N,D,M,O,R,Y} ⊆ 0 ‥ 9 ∧ S > 0 ∧ M > 0 ∧ card({S,E,N,D,M,O,R,Y}) = 8 ∧ S * 1000 + E * 100 + N * 10 + D + M * 1000 + O * 100 + R * 10 + E = M * 10000 + O * 1000 + N * 100 + E * 10 + Y
{S,E,N,D,M,O,R,Y} ⊆ 0 ‥ 9 ∧ S > 0 ∧ M > 0 ∧ card({S,E,N,D,M,O,R,Y}) = 8 ∧ S * 1000 + E * 100 + N * 10 + D + M * 1000 + O * 100 + R * 10 + E = M * 10000 + O * 1000 + N * 100 + E * 10 + Y
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
{S,E,N,D, M,O,R, Y} ⊆ 0..9 & S >0 & M >0 &
{S,E,N,D, M,O,R, Y} ⊆ 0..9 & S >0 & M >0 &
card({S,E,N,D, M,O,R, Y}) = 8 &
card({S,E,N,D, M,O,R, Y}) = 8 &
S*1000 + E*100 + N*10 + D +
S*1000 + E*100 + N*10 + D +
M*1000 + O*100 + R*10 + E =
M*1000 + O*100 + R*10 + E =
M*10000 + O*1000 + N*100 + E*10 + Y
M*10000 + O*1000 + N*100 + E*10 + Y
```
```
%% Output
%% Output
$\mathit{TRUE}$
$\mathit{TRUE}$
**Solution:**
**Solution:**
* $\mathit{R} = 8$
* $\mathit{R} = 8$
* $\mathit{S} = 9$
* $\mathit{S} = 9$
* $\mathit{D} = 7$
* $\mathit{D} = 7$
* $\mathit{E} = 5$
* $\mathit{E} = 5$
* $\mathit{Y} = 2$
* $\mathit{Y} = 2$
* $\mathit{M} = 1$
* $\mathit{M} = 1$
* $\mathit{N} = 6$
* $\mathit{N} = 6$
* $\mathit{O} = 0$
* $\mathit{O} = 0$
TRUE
TRUE
Solution:
Solution:
R = 8
R = 8
S = 9
S = 9
D = 7
D = 7
E = 5
E = 5
Y = 2
Y = 2
M = 1
M = 1
N = 6
N = 6
O = 0
O = 0
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
We can find all solutions (to the unmodified puzzle) using a set comprehension and make sure that there is just a single solution:
We can find all solutions (to the unmodified puzzle) using a set comprehension and make sure that there is just a single solution:
:time: :solve: Computation not completed: no solution found (but one might exist)
:time: :solve: Computation not completed: no solution found (but one might exist)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Result for KISS*KISS=PASSION puzzle:
Result for KISS*KISS=PASSION puzzle:
Solver | Runtime
Solver | Runtime
-------|-------
-------|-------
ProB Default | 0.01 sec
ProB Default | 0.01 sec
Kodkod Backend | 1 sec
Kodkod Backend | 1 sec
Z3 Backend | ? > 100 sec
Z3 Backend | ? > 100 sec
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Unbounded integers ###
### Unbounded integers ###
The SAT translation via Kodkod/Alloy requires to determine the bid width.
The SAT translation via Kodkod/Alloy requires to determine the bid width.
It cannot be applied to unbounded integers.
It cannot be applied to unbounded integers.
Even for bounded integers it is quite tricky to get the bid widths correct: one needs also to take care of intermediate results. Alloy can detect incorrect models where an overflow occured, but to our understanding not where an overflow prevented a model (e.g., use inside negation or equivalence, see ```#(V.SS->V.SS)=0 iff no V.SS``` in paper at ABZ conference).
Even for bounded integers it is quite tricky to get the bid widths correct: one needs also to take care of intermediate results. Alloy can detect incorrect models where an overflow occured, but to our understanding not where an overflow prevented a model (e.g., use inside negation or equivalence, see ```#(V.SS->V.SS)=0 iff no V.SS``` in paper at ABZ conference).
SMTLib is more tailored towards proof than towards model finding; as such it has typically no/less issues with unbounded values.
SMTLib is more tailored towards proof than towards model finding; as such it has typically no/less issues with unbounded values.
The ProB default solver can also deal with unbounded integers: it tries to narrow down domains to finite ones. If this fails, an unbounded variable is enumerated (partially) and an **enumeration warning** is generated. In case a solution is found, this warning is ignored, otherwise the result of ProB's analysis is **UNKNOWN**.
The ProB default solver can also deal with unbounded integers: it tries to narrow down domains to finite ones. If this fails, an unbounded variable is enumerated (partially) and an **enumeration warning** is generated. In case a solution is found, this warning is ignored, otherwise the result of ProB's analysis is **UNKNOWN**.
Some inconsistencies cannot be detected by interval/domain propagation; here it helps to activate ProB's CHR module which performs some additional inferences.
Some inconsistencies cannot be detected by interval/domain propagation; here it helps to activate ProB's CHR module which performs some additional inferences.
Let us perform some experiments. Both ProB and Z3 can solve the following:
Let us perform some experiments. Both ProB and Z3 can solve the following:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve z3 x*x=100
:solve z3 x*x=100
```
```
%% Output
%% Output
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = -10$
* $x = -10$
TRUE
TRUE
Solution:
Solution:
x = −10
x = −10
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Here is an example where ProB generates an enumeration warning, but finds a solution:
Here is an example where ProB generates an enumeration warning, but finds a solution:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
x>100 & x mod 2000 = 1 & x mod 3000 = 1
x>100 & x mod 2000 = 1 & x mod 3000 = 1
```
```
%% Output
%% Output
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = 6001$
* $x = 6001$
TRUE
TRUE
Solution:
Solution:
x = 6001
x = 6001
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve z3 x>100 & x mod 2000 = 1 & x mod 3000 = 1
:solve z3 x>100 & x mod 2000 = 1 & x mod 3000 = 1
```
```
%% Output
%% Output
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = 6001$
* $x = 6001$
TRUE
TRUE
Solution:
Solution:
x = 6001
x = 6001
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Here ProB generates an enumeration warning and does not find a solution, hence the result is **UNKNOWN**. Here Z3 finds a solution.
Here ProB generates an enumeration warning and does not find a solution, hence the result is **UNKNOWN**. Here Z3 finds a solution.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve prob x>100 & x mod 2000 = 1 & x mod 3000 = 1 & (x+x) mod 4501 = 0
:solve prob x>100 & x mod 2000 = 1 & x mod 3000 = 1 & (x+x) mod 4501 = 0
```
```
%% Output
%% Output
:solve: Computation not completed: no solution found (but one might exist)
:solve: Computation not completed: no solution found (but one might exist)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve z3 x>100 & x mod 2000 = 1 & x mod 3000 = 1 & (x+x) mod 4501 = 0
:solve z3 x>100 & x mod 2000 = 1 & x mod 3000 = 1 & (x+x) mod 4501 = 0
```
```
%% Output
%% Output
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = 6756001$
* $x = 6756001$
TRUE
TRUE
Solution:
Solution:
x = 6756001
x = 6756001
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Here is an inconsistency which cannot be detected by CLP(FD)'s interval propagation.
Here is an inconsistency which cannot be detected by CLP(FD)'s interval propagation.
ProB can detect it with CHR (Constraint Handling Rules) enabled, but without the module the result is **UNKNOWN**.
ProB can detect it with CHR (Constraint Handling Rules) enabled, but without the module the result is **UNKNOWN**.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve z3 x>y & y>x
:solve z3 x>y & y>x
```
```
%% Output
%% Output
$FALSE$
$FALSE$
FALSE
FALSE
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve prob x>y &y>x
:solve prob x>y &y>x
```
```
%% Output
%% Output
:solve: Computation not completed: no solution found (but one might exist)
:solve: Computation not completed: no solution found (but one might exist)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Summary for Integer Arithmetic ###
### Summary for Integer Arithmetic ###
Solver | Unbounded | Model Finding | Inconsistency Detection (Unbounded)
Solver | Unbounded | Model Finding | Inconsistency Detection (Unbounded)
------|------------|---------------|---
------|------------|---------------|---
ProB CLP(FD) | yes | very good | limited with CHR
ProB CLP(FD) | yes | very good | limited with CHR
ProB Z3 | yes | reasonable | very good
ProB Z3 | yes | reasonable | very good
ProB Kodkod | no | good | -
ProB Kodkod | no | good | -
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Set Constraints ##
## Set Constraints ##
After booleans, integers and enumerated set elements, let us now move to constraint solving involving set variables.
After booleans, integers and enumerated set elements, let us now move to constraint solving involving set variables.
### Translation to SAT ###
### Translation to SAT ###
The Kodkod/Alloy backend translates sets bit vectors. The size of the vector is the number of possible elements.
The Kodkod/Alloy backend translates sets bit vectors. The size of the vector is the number of possible elements.
Take for example the following constraint, the sets x and y are translated to bit vectors of size 2 and set union is simple bitwise or:
Take for example the following constraint, the sets x and y are translated to bit vectors of size 2 and set union is simple bitwise or:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve kodkod x <: 1..2 & y<: 1..2 & x \/ y = 1..2 & 1:x & x <<: y
:solve kodkod x ⊆ 1..2 & y ⊆ 1..2 & x ∪ y = 1..2 & 1∈x & x ⊂ y
```
```
%% Output
%% Output
$TRUE$
$\mathit{TRUE}$
**Solution:**
**Solution:**
* $x = \{1\}$
* $\mathit{x} = \{1\}$
* $y = \{1,2\}$
* $\mathit{y} = \{1,2\}$
TRUE
TRUE
Solution:
Solution:
x = {1}
x = {1}
y = {1,2}
y = {1,2}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Limitations of translating set constraints to SAT:
Limitations of translating set constraints to SAT:
- this cannot deal with **unbounded** sets: we need to know a finite type for each set, so that we can generate a finite bit vector
- this cannot deal with **unbounded** sets: we need to know a finite type for each set, so that we can generate a finite bit vector
- this approach cannot usually deal with **higher order** sets (sets of sets), as the size of the bit vector would be prohibitively large
- this approach cannot usually deal with **higher order** sets (sets of sets), as the size of the bit vector would be prohibitively large
Given that:
Given that:
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
card(POW(1..100))
card(POW(1..100))
```
```
%% Output
%% Output
$1267650600228229401496703205376$
$1267650600228229401496703205376$
1267650600228229401496703205376
1267650600228229401496703205376
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
translating the following constraint to SAT would require a bit vector of length 1267650600228229401496703205376.
translating the following constraint to SAT would require a bit vector of length 1267650600228229401496703205376.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
x <: POW(1..100) & {100}:x & !y.(y:x => {card(y)}:x)
x ⊆ POW(1..100) & {100}∈x & ∀y.(y∈x ⇒ {card(y)}:x)
```
```
%% Output
%% Output
$TRUE$
$\mathit{TRUE}$
**Solution:**
**Solution:**
* $x = \{\{100\},\{1\}\}$
* $\mathit{x} = \{\{100\},\{1\}\}$
TRUE
TRUE
Solution:
Solution:
x = {{100},{1}}
x = {{100},{1}}
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
Also, in the following constraint, the set x is unbounded and no translation to SAT is feasible (without a very clever analysis of the universal implications).
Also, in the following constraint, the set x is unbounded and no translation to SAT is feasible (without a very clever analysis of the universal implications).
Internally, a symbolic representation is a **closure** in functional programming terms: all dependent variables are *compiled* into the closure: the closure can be passed as a value and evaluated without needing access to an environment. In Prolog this is represented as a tuple:
Internally, a symbolic representation is a **closure** in functional programming terms: all dependent variables are *compiled* into the closure: the closure can be passed as a value and evaluated without needing access to an environment. In Prolog this is represented as a tuple:
- closure(Parameters,Types,CompiledPredicate)
- closure(Parameters,Types,CompiledPredicate)
For example, a set {x|x>v} where v has the value 17 is compiled to:
For example, a set {x|x>v} where v has the value 17 is compiled to:
- closure([x],[integer],```x>17```)
- closure([x],[integer],```x>17```)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### List representation ####
#### List representation ####
The list representation is used when a finite set is partially known and constraint solving has to determine the set.
The list representation is used when a finite set is partially known and constraint solving has to determine the set.
In the appendix there are more examples which analyse the performance for such examples.
In the appendix there are more examples which analyse the performance for such examples.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
ProB employs the *Andorra* principle: deterministic computations are done first.
ProB employs the *Andorra* principle: deterministic computations are done first.
As there are multiple set representations, there are actually two kinds of deterministic computations:
As there are multiple set representations, there are actually two kinds of deterministic computations:
- deterministic computations that generate an efficient representation, e.g., an AVL set representation
- deterministic computations that generate an efficient representation, e.g., an AVL set representation
- and other deterministic computations
- and other deterministic computations
The ProB solver has a **WAITFLAG store** where choice points and enumerations are registered with a given priority.
The ProB solver has a **WAITFLAG store** where choice points and enumerations are registered with a given priority.
- Priority 0 means that an efficient representation can be generated
- Priority 0 means that an efficient representation can be generated
- Priority 1 is a deterministic computation not guaranteed to produce an efficient representation
- Priority 1 is a deterministic computation not guaranteed to produce an efficient representation
- Priority k is a choice point/enumeration which may generate k possible values
- Priority k is a choice point/enumeration which may generate k possible values
At each solving step one waitflag is activated, the one with the lowest priority.
At each solving step one waitflag is activated, the one with the lowest priority.
CLP(FD) variables are also registered in the WAITFLAG store and are enumerated before a waitflag of the same priority is activated. For tie breaking one typically uses the **most attached constraints first** (ffc) heuristic.
CLP(FD) variables are also registered in the WAITFLAG store and are enumerated before a waitflag of the same priority is activated. For tie breaking one typically uses the **most attached constraints first** (ffc) heuristic.
#### Example ####
#### Example ####
Let us examine how ```x = 1..n & y = 2*n..3*n & n = 100 & xy = x \/ y``` is solved.
Let us examine how ```x = 1..n & y = 2*n..3*n & n = 100 & xy = x \/ y``` is solved.
- all constraints are registered
- all constraints are registered
- in phase 0 ```n=100``` is run
- in phase 0 ```n=100``` is run
- this means that ```1..n``` can be efficiently computed
- this means that ```1..n``` can be efficiently computed
- this means that ```x = 1..n``` triggers in phase 0
- this means that ```x = 1..n``` triggers in phase 0
- then ```2*n``` and ```3*n``` can be computed, followed by ```2*n..3*n```
- then ```2*n``` and ```3*n``` can be computed, followed by ```2*n..3*n```
- this means that ```y = 2*n..3*n``` triggers in phase 0
- this means that ```y = 2*n..3*n``` triggers in phase 0
- again, this means that ```x \/ y``` can be efficiently computed
- again, this means that ```x \/ y``` can be efficiently computed
- finally ```xy = x \/ y``` can be executed in phase 0
- finally ```xy = x \/ y``` can be executed in phase 0
No enumeration was required. In this case ProB's constraint solver works similar to a topological sorting algorithm.
No enumeration was required. In this case ProB's constraint solver works similar to a topological sorting algorithm.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
#### Dealing with unbounded enumeration ####
#### Dealing with unbounded enumeration ####
Note: if an unbounded enumeration is encountered, the solver registers an **enumeration warning** in the current scope (every quantification / comprehension set results in a new inner scope). Depending on the kind of scope (existential/universal) and on whether a solution is found, the warning gets translated into an **UNKNOWN** result.
Note: if an unbounded enumeration is encountered, the solver registers an **enumeration warning** in the current scope (every quantification / comprehension set results in a new inner scope). Depending on the kind of scope (existential/universal) and on whether a solution is found, the warning gets translated into an **UNKNOWN** result.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Summary of Set Constraint Solving Approaches ##
## Summary of Set Constraint Solving Approaches ##
- SAT Translation (Kodkod backend):
- SAT Translation (Kodkod backend):
- needs finite and small base type, no unbounded or higher-order sets
- needs finite and small base type, no unbounded or higher-order sets
- can be very effective for complex constraints involving image, transitive closure,...
- can be very effective for complex constraints involving image, transitive closure,...
- limited performance for large sets
- limited performance for large sets
- SMTLib Translation (Z3/CVC4 backend):
- SMTLib Translation (Z3/CVC4 backend):
- can deal with unbounded and large sets
- can deal with unbounded and large sets
- due to heavy use of quantifiers, some finite constraints get translated into infinite ones: limited model finding capabilities
- due to heavy use of quantifiers, some finite constraints get translated into infinite ones: limited model finding capabilities
- works well for large sets and semi-deterministic computation
- works well for large sets and semi-deterministic computation
- works well for animation, data validation, disproving
- works well for animation, data validation, disproving
- limitations appear for symbolic model checking (IC3,...)
- limitations appear for symbolic model checking (IC3,...)
- Future work: improve combination with Z3/Kodkod, improve list representation (maybe use a bit-vector like representation, and CLP(FD) cardinality variable)
- Future work: improve combination with Z3/Kodkod, improve list representation (maybe use a bit-vector like representation, and CLP(FD) cardinality variable)
- CHR: can complement ProB's default backend
- CHR: can complement ProB's default backend
- currently only very limited propagations (>, >=, x=y+c, ...)
- currently only very limited propagations (>, >=, x=y+c, ...)
- very difficult to control and avoid propagation loops
- very difficult to control and avoid propagation loops
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Integrations of Approaches ###
### Integrations of Approaches ###
ProB provides the joint application of the CLP(FD) and SMT backend (preference ```SMT_SUPPORTED_INTERPRETER```.
ProB provides the joint application of the CLP(FD) and SMT backend (preference ```SMT_SUPPORTED_INTERPRETER```.
Constraints are posted both to ProB and Z3/CVC4, with the hope that Z3/CVC4 prune infeasible branches.
Constraints are posted both to ProB and Z3/CVC4, with the hope that Z3/CVC4 prune infeasible branches.
The main motivation was new symbolic validation techniques such as IC3.
The main motivation was new symbolic validation techniques such as IC3.
The Kodkod integration also passes higher-order/unbounded constraints to ProB, after solving the first order finite constraints with Kodkod/Alloy.
The Kodkod integration also passes higher-order/unbounded constraints to ProB, after solving the first order finite constraints with Kodkod/Alloy.
However, this kind of integration is rarely useful (most of the generated solutions get rejected by ProB).
However, this kind of integration is rarely useful (most of the generated solutions get rejected by ProB).
A more promising, fine-grained integration has been presented at PADL'18.
A more promising, fine-grained integration has been presented at PADL'18.
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Appendix ##
## Appendix ##
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
### Explicit Computations ####
### Explicit Computations ####
What about explicit computations? How well does the SMTLib translation fare here?
What about explicit computations? How well does the SMTLib translation fare here?
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:solve z3 x = 1..1000 /\ (200..300)
:solve z3 x = 1..1000 /\ (200..300)
```
```
%% Output
%% Output
:solve: Computation not completed: no solution found (but one might exist)
:solve: Computation not completed: no solution found (but one might exist)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:time :solve z3 x = 1..40 /\ (6..15)
:time :solve z3 x = 1..40 /\ (6..15)
```
```
%% Output
%% Output
Execution time: 0.224425596 seconds
Execution time: 0.224425596 seconds
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = \{6,7,8,9,10,11,12,13,14,15\}$
* $x = \{6,7,8,9,10,11,12,13,14,15\}$
TRUE
TRUE
Solution:
Solution:
x = {6,7,8,9,10,11,12,13,14,15}
x = {6,7,8,9,10,11,12,13,14,15}
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:time :solve z3 x = 1..60 /\ (6..15)
:time :solve z3 x = 1..60 /\ (6..15)
```
```
%% Output
%% Output
Execution time: 1.149180308 seconds
Execution time: 1.149180308 seconds
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = \{6,7,8,9,10,11,12,13,14,15\}$
* $x = \{6,7,8,9,10,11,12,13,14,15\}$
TRUE
TRUE
Solution:
Solution:
x = {6,7,8,9,10,11,12,13,14,15}
x = {6,7,8,9,10,11,12,13,14,15}
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:time :solve z3 x = 1..80 /\ (6..15)
:time :solve z3 x = 1..80 /\ (6..15)
```
```
%% Output
%% Output
:time: :solve: Computation not completed: no solution found (but one might exist)
:time: :solve: Computation not completed: no solution found (but one might exist)
%% Cell type:code id: tags:
%% Cell type:code id: tags:
``` prob
``` prob
:time :solve prob x = 1..80 /\ (6..15)
:time :solve prob x = 1..80 /\ (6..15)
```
```
%% Output
%% Output
Execution time: 0.005873811 seconds
Execution time: 0.005873811 seconds
$TRUE$
$TRUE$
**Solution:**
**Solution:**
* $x = (6 \ldots 15)$
* $x = (6 \ldots 15)$
TRUE
TRUE
Solution:
Solution:
x = (6 ‥ 15)
x = (6 ‥ 15)
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
In the following the inverse operator seems to pose problems to Z3:
In the following the inverse operator seems to pose problems to Z3: