spot/tests/python/atva16-fig2a.ipynb
Alexandre Duret-Lutz 2072151499 twa_graph: swap the two passes of merge_edges()
This improves the determinism in a few cases.

* spot/twa/twagraph.cc (merge_edges): Encapsulate the two
passes into lambdas so that they are very easy to swap.
* spot/twa/twagraph.hh (merge_edges): Adjust documentation.
* tests/python/mergedge.py: Add test case.
* tests/core/alternating.test, tests/python/alternation.ipynb:
Determinism was improved.
* tests/core/parity2.test, tests/core/readsave.test,
tests/core/sbacc.test, tests/python/_product_susp.ipynb,
tests/python/atva16-fig2a.ipynb, tests/python/decompose.ipynb,
tests/python/highlighting.ipynb, tests/python/satmin.ipynb,
tests/python/simstate.py: Adjust expected order of edges.
* NEWS: Mention the change.
2021-01-20 00:16:12 +01:00

246 lines
11 KiB
Text

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example is the left part of Fig.2 in our ATVA'16 paper titled [\"*Spot 2.0 — a framework for LTL and ω-automata manipulation*\"](https://www.lrde.epita.fr/~adl/dl/adl/duret.16.atva2.pdf), slightly updated to the current version of Spot."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import spot\n",
"spot.setup(show_default='.b')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\mathsf{G} \\mathsf{F} a \\leftrightarrow \\mathsf{G} \\mathsf{F} b$"
],
"text/plain": [
"spot.formula(\"GFa <-> GFb\")"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f = spot.formula('GFa <-> GFb'); f"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
"<!-- Generated by graphviz version 2.43.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"196pt\" height=\"355pt\"\n",
" viewBox=\"0.00 0.00 196.00 355.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1.0 1.0) rotate(0) translate(4 351)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-351 192,-351 192,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"48.5\" y=\"-332.8\" font-family=\"Lato\" font-size=\"14.00\">Inf(</text>\n",
"<text text-anchor=\"start\" x=\"69.5\" y=\"-332.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"85.5\" y=\"-332.8\" font-family=\"Lato\" font-size=\"14.00\">)&amp;Inf(</text>\n",
"<text text-anchor=\"start\" x=\"119.5\" y=\"-332.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"<text text-anchor=\"start\" x=\"135.5\" y=\"-332.8\" font-family=\"Lato\" font-size=\"14.00\">)</text>\n",
"<text text-anchor=\"start\" x=\"51.5\" y=\"-318.8\" font-family=\"Lato\" font-size=\"14.00\">[gen. Büchi 2]</text>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"56\" cy=\"-68\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-64.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15,-68C2.79,-68 17.15,-68 30.63,-68\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-68 30.94,-71.15 34.44,-68 30.94,-68 30.94,-68 30.94,-68 34.44,-68 30.94,-64.85 37.94,-68 37.94,-68\"/>\n",
"</g>\n",
"<!-- 0&#45;&gt;0 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M49.62,-85.04C48.32,-94.86 50.45,-104 56,-104 60.17,-104 62.4,-98.86 62.71,-92.14\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"62.38,-85.04 65.85,-91.88 62.54,-88.53 62.71,-92.03 62.71,-92.03 62.71,-92.03 62.54,-88.53 59.56,-92.18 62.38,-85.04 62.38,-85.04\"/>\n",
"<text text-anchor=\"start\" x=\"51.5\" y=\"-107.8\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"168\" cy=\"-118\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"start\" x=\"163.5\" y=\"-114.3\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M72.76,-75.16C91.63,-83.74 123.36,-98.16 144.72,-107.87\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"151.27,-110.85 143.59,-110.82 148.08,-109.4 144.9,-107.95 144.9,-107.95 144.9,-107.95 148.08,-109.4 146.2,-105.09 151.27,-110.85 151.27,-110.85\"/>\n",
"<text text-anchor=\"start\" x=\"99\" y=\"-104.8\" font-family=\"Lato\" font-size=\"14.00\">a | b</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"168\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"168\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M72.76,-60.84C91.63,-52.26 123.36,-37.84 144.72,-28.13\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"151.27,-25.15 146.2,-30.91 148.08,-26.6 144.9,-28.05 144.9,-28.05 144.9,-28.05 148.08,-26.6 143.59,-25.18 151.27,-25.15 151.27,-25.15\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-54.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !b</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M165.47,-136.15C165.08,-145.54 165.92,-154 168,-154 169.53,-154 170.39,-149.44 170.58,-143.3\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"170.53,-136.15 173.73,-143.13 170.56,-139.65 170.58,-143.15 170.58,-143.15 170.58,-143.15 170.56,-139.65 167.43,-143.17 170.53,-136.15 170.53,-136.15\"/>\n",
"<text text-anchor=\"start\" x=\"148\" y=\"-157.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !b</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M163.83,-135.7C161.52,-153 162.91,-172 168,-172 172.37,-172 174.01,-157.96 172.93,-143.04\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"172.17,-135.7 176.02,-142.34 172.53,-139.18 172.89,-142.66 172.89,-142.66 172.89,-142.66 172.53,-139.18 169.75,-142.98 172.17,-135.7 172.17,-135.7\"/>\n",
"<text text-anchor=\"start\" x=\"150\" y=\"-190.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; !b</text>\n",
"<text text-anchor=\"start\" x=\"160\" y=\"-175.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M163.05,-135.47C157.9,-163.15 159.55,-202 168,-202 175.76,-202 177.78,-169.26 174.08,-142.48\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"172.95,-135.47 177.17,-141.88 173.51,-138.92 174.06,-142.38 174.06,-142.38 174.06,-142.38 173.51,-138.92 170.95,-142.88 172.95,-135.47 172.95,-135.47\"/>\n",
"<text text-anchor=\"start\" x=\"150\" y=\"-220.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"160\" y=\"-205.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M162.52,-135.24C154.33,-171.92 156.16,-232 168,-232 179.1,-232 181.4,-179.2 174.9,-142.37\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"173.48,-135.24 177.93,-141.49 174.16,-138.67 174.85,-142.1 174.85,-142.1 174.85,-142.1 174.16,-138.67 171.76,-142.72 173.48,-135.24 173.48,-135.24\"/>\n",
"<text text-anchor=\"start\" x=\"152\" y=\"-249.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"152\" y=\"-235.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"168\" y=\"-235.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;2 -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>2&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M158.43,-33.54C155.73,-43.91 158.92,-54 168,-54 174.95,-54 178.45,-48.08 178.5,-40.66\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"177.57,-33.54 181.6,-40.08 178.03,-37.01 178.48,-40.48 178.48,-40.48 178.48,-40.48 178.03,-37.01 175.35,-40.89 177.57,-33.54 177.57,-33.54\"/>\n",
"<text text-anchor=\"start\" x=\"148\" y=\"-71.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !b</text>\n",
"<text text-anchor=\"start\" x=\"152\" y=\"-57.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"168\" y=\"-57.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#ff4da0\">❶</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<spot.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7f12cf944300> >"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.translate()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def implies(f, g):\n",
" f = spot.formula(f)\n",
" g = spot.formula.Not(g)\n",
" return spot.product(f.translate(), g.translate()).is_empty()\n",
"def equiv(f, g):\n",
" return implies(f, g) and implies(g, f)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"equiv('a U (b U a)', 'b U a')"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"equiv('!(a U b)', '!a U !b')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.1+"
}
},
"nbformat": 4,
"nbformat_minor": 2
}