Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ProB 2 Jupyter Kernel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
ProB 2 Jupyter Kernel
Commits
260e0291
Commit
260e0291
authored
Jun 6, 2018
by
Michael Leuschel
Browse files
Options
Downloads
Patches
Plain Diff
add experiment notebook
parent
48a19e14
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
notebooks/experiments/SMT_Translation_Experiments.ipynb
+197
-0
197 additions, 0 deletions
notebooks/experiments/SMT_Translation_Experiments.ipynb
with
197 additions
and
0 deletions
notebooks/experiments/SMT_Translation_Experiments.ipynb
0 → 100644
+
197
−
0
View file @
260e0291
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Experiments in SMTLib Translation #\n",
"\n",
"Let us look at a simple example that poses problems for the Z3/CVC4 backend:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "CommandExecutionException",
"evalue": ":solve: Computation not completed: no solution found (but one might exist)",
"output_type": "error",
"traceback": [
"\u001b[1m\u001b[31m:solve: Computation not completed: no solution found (but one might exist)\u001b[0m"
]
}
],
"source": [
":solve z3 f = {1|->3, 2|->6} & r = f~[{6}]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To understand why this simple constraint cannot be solved, we have to know how the translation works:\n",
"The relational inverse gets translated into two universal quantifications for SMTLib:\n",
"```\n",
" x = y~\n",
"<=>\n",
" !(st11,st12).(st11 |-> st12 : x => st12 |-> st11 : y) & \n",
" !(st11,st12).(st12 |-> st11 : y => st11 |-> st12 : x))\n",
"```\n",
"Similarly, r = f[s] is translated as follows:\n",
"```\n",
" r = f[s]\n",
"<=>\n",
" !st27.(st27 : r => #st26.(st26 |-> st27 : f & st26 : s) & \n",
" !st27.(#st26.(st26 |-> st27 : f & st26 : s) => st27 : r)\n",
"```\n",
"The resulting predicate (without the inverse and image operators) is the following, which Z3 cannot solve (but ProB can)."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\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})))$"
],
"text/plain": [
"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)))"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":prettyprint f = {(1|->3),(2|->6)} &\n",
"#st13.(r = st13 & (\n",
" !st15.(st15 : st13 => #st14.(#st16.(st14 |-> st15 : st16 & \n",
" (!(st17,st18).(st17 |-> st18 : st16 => st18 |-> st17 : f) & \n",
" !(st17,st18).(st18 |-> st17 : f => st17 |-> st18 : st16))) & st14 : {6})) & \n",
" !st15.(#st14.(#st19.(st14 |-> st15 : st19 & (!(st20,st21).(st20 |-> st21 : st19 => st21 |-> st20 : f) &\n",
" !(st20,st21).(st21 |-> st20 : f => st20 |-> st21 : st19))) & st14 : {6}) => st15 : st13)))"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/markdown": [
"Execution time: 0.194111316 seconds"
],
"text/plain": [
"Execution time: 0.194111316 seconds"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"TRUE\n",
"\n",
"Solution:\n",
"\tr = {2}\n",
"\tf = {(1↦3),(2↦6)}"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
":time :solve prob f = {(1|->3),(2|->6)} &\n",
"#st13.(r = st13 & (\n",
" !st15.(st15 : st13 => #st14.(#st16.(st14 |-> st15 : st16 & \n",
" (!(st17,st18).(st17 |-> st18 : st16 => st18 |-> st17 : f) & \n",
" !(st17,st18).(st18 |-> st17 : f => st17 |-> st18 : st16))) & st14 : {6})) & \n",
" !st15.(#st14.(#st19.(st14 |-> st15 : st19 & (!(st20,st21).(st20 |-> st21 : st19 => st21 |-> st20 : f) &\n",
" !(st20,st21).(st21 |-> st20 : f => st20 |-> st21 : st19))) & st14 : {6}) => st15 : st13)))\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Experiment in Rodin: adding r={2} as theorem and use SMT Plugin using the technique suggested by Laurent:\n",
"\n",
"pour voir la traduction d’Event-B vers SMT, créer un fichier texte contenant\n",
"```\n",
" org.eventb.smt.core/debug = true\n",
" org.eventb.smt.core/debug/translator = true\n",
" org.eventb.smt.core/debug/translator_details = true\n",
"```\n",
"et lancer Rodin avec les paramètres `-debug <text-file>`.\n",
"\n",
"À chaque fois qu’un solveur SMT est lancé, le contenu du fichier SMT sera affiché dans la console.\n",
"\n",
"```\n",
"; translated from Event-B with the PP approach of Rodin SMT Plugin\n",
"\n",
"(set-info :status unsat)\n",
"(set-logic AUFLIA)\n",
"(declare-fun f (Int Int) Bool)\n",
"(declare-fun r (Int) Bool)\n",
"\n",
"(assert (and \n",
" (forall ((x Int) (x0 Int)) \n",
" (= \n",
" (f x x0) \n",
" (or \n",
" (and \n",
" (= x 1) \n",
" (= x0 3)) \n",
" (and \n",
" (= x 2) \n",
" (= x0 6))))) \n",
" (forall ((x1 Int)) \n",
" (= \n",
" (r x1) \n",
" (exists ((x2 Int)) \n",
" (and \n",
" (= x2 6) \n",
" (f x1 x2)))))))\n",
"(assert (not \n",
" (forall ((x3 Int)) \n",
" (= \n",
" (r x3) \n",
" (= x3 2)))))\n",
"(check-sat)\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "ProB 2",
"language": "prob",
"name": "prob2"
},
"language_info": {
"file_extension": ".prob",
"mimetype": "text/x-prob",
"name": "prob"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
%% 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
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment