Skip to content
Snippets Groups Projects
Commit 260e0291 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add experiment notebook

parent 48a19e14
Branches
Tags
No related merge requests found
%% Cell type:markdown id: tags:
# Experiments in SMTLib Translation #
Let us look at a simple example that poses problems for the Z3/CVC4 backend:
%% Cell type:code id: tags:
``` prob
:solve z3 f = {1|->3, 2|->6} & r = f~[{6}]
```
%% Output
:solve: Computation not completed: no solution found (but one might exist)
%% Cell type:markdown id: tags:
To understand why this simple constraint cannot be solved, we have to know how the translation works:
The relational inverse gets translated into two universal quantifications for SMTLib:
```
x = y~
<=>
!(st11,st12).(st11 |-> st12 : x => st12 |-> st11 : y) &
!(st11,st12).(st12 |-> st11 : y => st11 |-> st12 : x))
```
Similarly, r = f[s] is translated as follows:
```
r = f[s]
<=>
!st27.(st27 : r => #st26.(st26 |-> st27 : f & st26 : s) &
!st27.(#st26.(st26 |-> st27 : f & st26 : s) => st27 : r)
```
The resulting predicate (without the inverse and image operators) is the following, which Z3 cannot solve (but ProB can).
%% Cell type:code id: tags:
``` prob
:prettyprint f = {(1|->3),(2|->6)} &
#st13.(r = st13 & (
!st15.(st15 : st13 => #st14.(#st16.(st14 |-> st15 : st16 &
(!(st17,st18).(st17 |-> st18 : st16 => st18 |-> st17 : f) &
!(st17,st18).(st18 |-> st17 : f => st17 |-> st18 : st16))) & st14 : {6})) &
!st15.(#st14.(#st19.(st14 |-> st15 : st19 & (!(st20,st21).(st20 |-> st21 : st19 => st21 |-> st20 : f) &
!(st20,st21).(st21 |-> st20 : f => st20 |-> st21 : st19))) & st14 : {6}) => st15 : st13)))
```
%% Output
$\mathit{f} = \{(1\mapsto 3),(2\mapsto 6)\} \wedge (\exists /* LET */ (\mathit{st13}).( (\mathit{st13})=\mathit{r} \wedge \forall \mathit{st15}\cdot (\mathit{st15} \in \mathit{st13} \mathbin\Rightarrow \exists \mathit{st16}\cdot (6 \mapsto \mathit{st15} \in \mathit{st16} \wedge (\forall (\mathit{st17},\mathit{st18})\cdot (\mathit{st17} \mapsto \mathit{st18} \in \mathit{st16} \mathbin\Rightarrow \mathit{st18} \mapsto \mathit{st17} \in \mathit{f}) \wedge \forall (\mathit{st17},\mathit{st18})\cdot (\mathit{st18} \mapsto \mathit{st17} \in \mathit{f} \mathbin\Rightarrow \mathit{st17} \mapsto \mathit{st18} \in \mathit{st16})))) \wedge \forall \mathit{st15}\cdot (\exists \mathit{st19}\cdot (6 \mapsto \mathit{st15} \in \mathit{st19} \wedge (\forall (\mathit{st20},\mathit{st21})\cdot (\mathit{st20} \mapsto \mathit{st21} \in \mathit{st19} \mathbin\Rightarrow \mathit{st21} \mapsto \mathit{st20} \in \mathit{f}) \wedge \forall (\mathit{st20},\mathit{st21})\cdot (\mathit{st21} \mapsto \mathit{st20} \in \mathit{f} \mathbin\Rightarrow \mathit{st20} \mapsto \mathit{st21} \in \mathit{st19}))) \mathbin\Rightarrow \mathit{st15} \in \mathit{st13})))$
f = {(1↦3),(2↦6)} ∧ (∃ /* LET */ (st13).( (st13)=r ∧ ∀st15·(st15 ∈ st13 ⇒ ∃st16·(6 ↦ st15 ∈ st16 ∧ (∀(st17,st18)·(st17 ↦ st18 ∈ st16 ⇒ st18 ↦ st17 ∈ f) ∧ ∀(st17,st18)·(st18 ↦ st17 ∈ f ⇒ st17 ↦ st18 ∈ st16)))) ∧ ∀st15·(∃st19·(6 ↦ st15 ∈ st19 ∧ (∀(st20,st21)·(st20 ↦ st21 ∈ st19 ⇒ st21 ↦ st20 ∈ f) ∧ ∀(st20,st21)·(st21 ↦ st20 ∈ f ⇒ st20 ↦ st21 ∈ st19))) ⇒ st15 ∈ st13)))
%% Cell type:code id: tags:
``` prob
:time :solve prob f = {(1|->3),(2|->6)} &
#st13.(r = st13 & (
!st15.(st15 : st13 => #st14.(#st16.(st14 |-> st15 : st16 &
(!(st17,st18).(st17 |-> st18 : st16 => st18 |-> st17 : f) &
!(st17,st18).(st18 |-> st17 : f => st17 |-> st18 : st16))) & st14 : {6})) &
!st15.(#st14.(#st19.(st14 |-> st15 : st19 & (!(st20,st21).(st20 |-> st21 : st19 => st21 |-> st20 : f) &
!(st20,st21).(st21 |-> st20 : f => st20 |-> st21 : st19))) & st14 : {6}) => st15 : st13)))
```
%% Output
Execution time: 0.194111316 seconds
TRUE
Solution:
r = {2}
f = {(1↦3),(2↦6)}
%% Cell type:markdown id: tags:
Experiment in Rodin: adding r={2} as theorem and use SMT Plugin using the technique suggested by Laurent:
pour voir la traduction d’Event-B vers SMT, créer un fichier texte contenant
```
org.eventb.smt.core/debug = true
org.eventb.smt.core/debug/translator = true
org.eventb.smt.core/debug/translator_details = true
```
et lancer Rodin avec les paramètres `-debug <text-file>`.
À chaque fois qu’un solveur SMT est lancé, le contenu du fichier SMT sera affiché dans la console.
```
; translated from Event-B with the PP approach of Rodin SMT Plugin
(set-info :status unsat)
(set-logic AUFLIA)
(declare-fun f (Int Int) Bool)
(declare-fun r (Int) Bool)
(assert (and
(forall ((x Int) (x0 Int))
(=
(f x x0)
(or
(and
(= x 1)
(= x0 3))
(and
(= x 2)
(= x0 6)))))
(forall ((x1 Int))
(=
(r x1)
(exists ((x2 Int))
(and
(= x2 6)
(f x1 x2)))))))
(assert (not
(forall ((x3 Int))
(=
(r x3)
(= x3 2)))))
(check-sat)
```
%% Cell type:code id: tags:
``` prob
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment