spot/tests/python/word.ipynb
Alexandre Duret-Lutz 60296317c7 python: more conventional __repr__ for several types
* NEWS: Mention the change.
* python/spot/__init__.py: Add _repr_latex_ for twa_word, and
remove __repr__ and __str__ for atomic_prop_set.
* python/spot/impl.i: Implement __repr__ and __str__ for
atomic_prop_set.  Fix __repr__ for trival, acc_code, acc_cond,
mark_t.  Remove __repr__ for twa_run and twa_word.
* tests/python/acc_cond.ipynb, tests/python/accparse.ipynb,
tests/python/atva16-fig2a.ipynb, tests/python/automata.ipynb,
tests/python/bdditer.py, tests/python/contains.ipynb,
tests/python/gen.ipynb, tests/python/highlighting.ipynb,
tests/python/ltlsimple.py, tests/python/ltsmin-dve.ipynb,
tests/python/product.ipynb, tests/python/relabel.py,
tests/python/satmin.ipynb tests/python/stutter-inv.ipynb,
tests/python/word.ipynb: Adjust test cases.
* tests/python/formulas.ipynb: Add test for atomic_prop_set.
2018-11-03 07:53:26 +01:00

601 lines
30 KiB
Text

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import spot\n",
"spot.setup()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's build a small automaton to use as example."
]
},
{
"cell_type": "code",
"execution_count": 2,
"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.40.1 (20161225.0304)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"465pt\" height=\"232pt\"\n",
" viewBox=\"0.00 0.00 464.50 232.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 1) rotate(0) translate(4 228)\">\n",
"<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-228 460.5,-228 460.5,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"207.25\" y=\"-209.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">Inf(</text>\n",
"<text text-anchor=\"start\" x=\"229.25\" y=\"-209.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"245.25\" y=\"-209.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">)</text>\n",
"<text text-anchor=\"start\" x=\"205.25\" y=\"-195.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">[Büchi]</text>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"56\" cy=\"-48\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-44.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">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=\"#000000\" d=\"M1.1233,-48C4.178,-48 17.9448,-48 30.9241,-48\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"37.9807,-48 30.9808,-51.1501 34.4807,-48 30.9807,-48.0001 30.9807,-48.0001 30.9807,-48.0001 34.4807,-48 30.9807,-44.8501 37.9807,-48 37.9807,-48\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"139\" cy=\"-48\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"139\" y=\"-44.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M74.0098,-48C85.5679,-48 100.7507,-48 113.5345,-48\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"120.7388,-48 113.7388,-51.1501 117.2388,-48 113.7388,-48.0001 113.7388,-48.0001 113.7388,-48.0001 117.2388,-48 113.7387,-44.8501 120.7388,-48 120.7388,-48\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-51.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"218\" cy=\"-109\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"218\" y=\"-105.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M153.4898,-59.1883C165.9622,-68.8189 184.0861,-82.8133 197.9501,-93.5184\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"203.602,-97.8826 196.1363,-96.0977 200.8318,-95.7435 198.0615,-93.6044 198.0615,-93.6044 198.0615,-93.6044 200.8318,-95.7435 199.9867,-91.1112 203.602,-97.8826 203.602,-97.8826\"/>\n",
"<text text-anchor=\"start\" x=\"175\" y=\"-83.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">a</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"327\" cy=\"-81\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"327\" y=\"-77.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">3</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>1&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M156.8419,-50.6052C185.2996,-54.8346 242.6854,-63.666 291,-73 294.6774,-73.7105 298.5541,-74.514 302.3468,-75.3309\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"309.4626,-76.8975 301.949,-78.4687 306.0445,-76.1449 302.6263,-75.3924 302.6263,-75.3924 302.6263,-75.3924 306.0445,-76.1449 303.3037,-72.316 309.4626,-76.8975 309.4626,-76.8975\"/>\n",
"<text text-anchor=\"start\" x=\"212.5\" y=\"-66.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>4</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"436\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"436\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">4</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;4 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>1&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M157.1316,-46.1685C207.9791,-41.0324 352.035,-26.4813 410.6856,-20.557\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"417.7283,-19.8456 411.0804,-23.6833 414.246,-20.1974 410.7638,-20.5492 410.7638,-20.5492 410.7638,-20.5492 414.246,-20.1974 410.4472,-17.4152 417.7283,-19.8456 417.7283,-19.8456\"/>\n",
"<text text-anchor=\"start\" x=\"267\" y=\"-39.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;2 -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>2&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M211.2664,-126.0373C209.8922,-135.8579 212.1367,-145 218,-145 222.3975,-145 224.7594,-139.8576 225.0858,-133.1433\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"224.7336,-126.0373 228.2263,-132.8728 224.9069,-129.533 225.0802,-133.0287 225.0802,-133.0287 225.0802,-133.0287 224.9069,-129.533 221.934,-133.1847 224.7336,-126.0373 224.7336,-126.0373\"/>\n",
"<text text-anchor=\"start\" x=\"201\" y=\"-163.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"210\" y=\"-148.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge7\" class=\"edge\">\n",
"<title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M230.8279,-96.2312C237.2266,-90.7425 245.4224,-84.9246 254,-82 269.3238,-76.7752 287.53,-76.5154 301.927,-77.5667\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"309.0731,-78.2166 301.8165,-80.7195 305.5875,-77.8995 302.1019,-77.5825 302.1019,-77.5825 302.1019,-77.5825 305.5875,-77.8995 302.3872,-74.4454 309.0731,-78.2166 309.0731,-78.2166\"/>\n",
"<text text-anchor=\"start\" x=\"254\" y=\"-85.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>5</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"327\" cy=\"-170\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"327\" y=\"-166.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">5</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;5 -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>2&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M231.3838,-121.1984C237.9043,-126.7614 246.042,-133.1687 254,-138 269.5528,-147.4421 288.3865,-155.6265 303.0282,-161.3544\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"309.8464,-163.9637 302.1829,-164.4037 306.5776,-162.7127 303.3088,-161.4618 303.3088,-161.4618 303.3088,-161.4618 306.5776,-162.7127 304.4347,-158.5198 309.8464,-163.9637 309.8464,-163.9637\"/>\n",
"<text text-anchor=\"start\" x=\"254\" y=\"-159.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;2 -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>3&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M310.8472,-89.2341C304.7566,-92.0552 297.6838,-95.0013 291,-97 275.3867,-101.669 257.3176,-104.6576 243.0626,-106.4846\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"235.989,-107.3368 242.5619,-103.372 239.4638,-106.9181 242.9387,-106.4994 242.9387,-106.4994 242.9387,-106.4994 239.4638,-106.9181 243.3156,-109.6268 235.989,-107.3368 235.989,-107.3368\"/>\n",
"<text text-anchor=\"start\" x=\"255.5\" y=\"-122.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"264.5\" y=\"-107.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;3 -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>3&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M317.7674,-96.5414C315.1685,-106.9087 318.2461,-117 327,-117 333.7022,-117 337.077,-111.0847 337.1245,-103.6591\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"336.2326,-96.5414 340.2286,-103.0955 336.6678,-100.0143 337.103,-103.4871 337.103,-103.4871 337.103,-103.4871 336.6678,-100.0143 333.9775,-103.8788 336.2326,-96.5414 336.2326,-96.5414\"/>\n",
"<text text-anchor=\"start\" x=\"308.5\" y=\"-120.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;4 -->\n",
"<g id=\"edge11\" class=\"edge\">\n",
"<title>4&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M426.7674,-33.5414C424.1685,-43.9087 427.2461,-54 436,-54 442.7022,-54 446.077,-48.0847 446.1245,-40.6591\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"445.2326,-33.5414 449.2286,-40.0955 445.6678,-37.0143 446.103,-40.4871 446.103,-40.4871 446.103,-40.4871 445.6678,-37.0143 442.9775,-40.8788 445.2326,-33.5414 445.2326,-33.5414\"/>\n",
"<text text-anchor=\"start\" x=\"415.5\" y=\"-72.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; !b</text>\n",
"<text text-anchor=\"start\" x=\"428\" y=\"-57.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;4 -->\n",
"<g id=\"edge12\" class=\"edge\">\n",
"<title>5&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M337.6498,-155.1488C357.2359,-127.8361 399.0029,-69.5923 421.2835,-38.5222\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"425.4674,-32.6877 423.9479,-40.2119 423.4277,-35.5319 421.3881,-38.3762 421.3881,-38.3762 421.3881,-38.3762 423.4277,-35.5319 418.8282,-36.5405 425.4674,-32.6877 425.4674,-32.6877\"/>\n",
"<text text-anchor=\"start\" x=\"363\" y=\"-119.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; b</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 0x7f4e4c5e8de0> >"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut = spot.translate('!a & G(Fa <-> XXb)'); aut"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build an accepting run:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Prefix:\n",
" 0\n",
" | !a\n",
" 1\n",
" | a\n",
"Cycle:\n",
" 2\n",
" | a & b\t{0}\n",
"\n"
]
}
],
"source": [
"run = aut.accepting_run()\n",
"print(run)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Accessing the contents of the run can be done via the `prefix` and `cycle` lists."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!a\n",
"{0}\n"
]
}
],
"source": [
"print(spot.bdd_format_formula(aut.get_dict(), run.prefix[0].label))\n",
"print(run.cycle[0].acc)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To convert the run into a word, using `spot.twa_word()`. Note that our runs are labeled by Boolean formulas that are not necessarily a conjunction of all involved litterals. The word is just the projection of the run on its labels."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!a; a; cycle{a & b}\n"
]
},
{
"data": {
"text/latex": [
"$\\lnot a; a; \\mathsf{cycle}\\{a \\land b\\}$"
],
"text/plain": [
"<spot.twa_word; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_word > *' at 0x7f4e4c5e8b70> >"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"word = spot.twa_word(run)\n",
"print(word) # print as a string\n",
"word # LaTeX-style representation in notebooks"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A word can be represented as a collection of signals (one for each atomic proposition). The cycle part is shown twice."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"112\" version=\"1.1\" width=\"200\" xmlns=\"http://www.w3.org/2000/svg\">\n",
"<rect fill=\"#f4f4f4\" height=\"100\" width=\"200\" x=\"0\" y=\"0\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"100\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"150\" x2=\"150\" y1=\"0\" y2=\"100\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"0\" x2=\"200\" y1=\"0\" y2=\"0\"/><text font-size=\"20\" text-anchor=\"start\" x=\"3\" y=\"30\">a</text><line stroke=\"white\" stroke-width=\"1\" x1=\"50\" x2=\"50\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"0\" x2=\"50\" y1=\"45\" y2=\"45\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"50\" x2=\"50\" y1=\"5\" y2=\"45\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"50\" x2=\"100\" y1=\"5\" y2=\"5\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"150\" x2=\"150\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"150\" y1=\"5\" y2=\"5\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"200\" x2=\"200\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"150\" x2=\"200\" y1=\"5\" y2=\"5\"/><line stroke=\"white\" stroke-width=\"4\" x1=\"0\" x2=\"200\" y1=\"50\" y2=\"50\"/><text font-size=\"20\" text-anchor=\"start\" x=\"3\" y=\"80\">b</text><line stroke=\"white\" stroke-width=\"1\" x1=\"50\" x2=\"50\" y1=\"50\" y2=\"100\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"100\" x2=\"100\" y1=\"50\" y2=\"100\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"150\" x2=\"150\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"150\" y1=\"55\" y2=\"55\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"200\" x2=\"200\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"150\" x2=\"200\" y1=\"55\" y2=\"55\"/><text font-size=\"10\" text-anchor=\"start\" x=\"0\" y=\"110\">prefix</text><text font-size=\"10\" text-anchor=\"start\" x=\"100\" y=\"110\">cycle</text>\n",
"<text font-size=\"10\" text-anchor=\"start\" x=\"150\" y=\"110\">cycle</text></svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"word.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Accessing the different formulas (stored as BDDs) can be done again via the `prefix` and `cycle` lists."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!a\n",
"a\n",
"a & b\n"
]
}
],
"source": [
"print(spot.bdd_format_formula(aut.get_dict(), word.prefix[0]))\n",
"print(spot.bdd_format_formula(aut.get_dict(), word.prefix[1]))\n",
"print(spot.bdd_format_formula(aut.get_dict(), word.cycle[0]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calling `simplifify()` will produce a shorter word that is compatible with the original word. For instance in the above word, the initial `a` is compatible with both `a & b` and `a & !b`. The word obtained by restricting `a` to `a & b` is therefore still accepted, allowing us to remove the prefix."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!a; cycle{a & b}\n"
]
}
],
"source": [
"word.simplify()\n",
"print(word)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Such a simplified word can be created directly from the automaton:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\lnot a; \\mathsf{cycle}\\{a \\land b\\}$"
],
"text/plain": [
"<spot.twa_word; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_word > *' at 0x7f4e4c652810> >"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"aut.accepting_word()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Words can be created using the `parse_word` function:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"a; b; cycle{a & b}\n",
"cycle{(a & bb) | (aaa & bac) | (bac & bbb)}\n",
"a; b; b; qiwuei; \"a;b&c;a\"; cycle{a}\n"
]
}
],
"source": [
"print(spot.parse_word('a; b; cycle{a&b}'))\n",
"print(spot.parse_word('cycle{a&bb|bac&(aaa|bbb)}'))\n",
"print(spot.parse_word('a; b;b; qiwuei;\"a;b&c;a\" ;cycle{a}'))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$a; a \\land b; \\mathsf{cycle}\\{\\lnot a \\land \\lnot b; \\lnot a \\land b\\}$"
],
"text/plain": [
"<spot.twa_word; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_word > *' at 0x7f4e4c574600> >"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# make sure that we can parse a word back after it has been printed\n",
"w = spot.parse_word(str(spot.parse_word('a;b&a;cycle{!a&!b;!a&b}'))); w"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<svg height=\"112\" version=\"1.1\" width=\"300\" xmlns=\"http://www.w3.org/2000/svg\">\n",
"<rect fill=\"#f4f4f4\" height=\"100\" width=\"300\" x=\"0\" y=\"0\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"100\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"200\" x2=\"200\" y1=\"0\" y2=\"100\"/>\n",
"<line stroke=\"white\" stroke-width=\"4\" x1=\"0\" x2=\"300\" y1=\"0\" y2=\"0\"/><text font-size=\"20\" text-anchor=\"start\" x=\"3\" y=\"30\">a</text><line stroke=\"white\" stroke-width=\"1\" x1=\"50\" x2=\"50\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"0\" x2=\"50\" y1=\"5\" y2=\"5\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"100\" x2=\"100\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"50\" x2=\"100\" y1=\"5\" y2=\"5\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"150\" x2=\"150\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"100\" y1=\"5\" y2=\"45\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"150\" y1=\"45\" y2=\"45\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"200\" x2=\"200\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"150\" x2=\"200\" y1=\"45\" y2=\"45\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"250\" x2=\"250\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"200\" x2=\"250\" y1=\"45\" y2=\"45\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"300\" x2=\"300\" y1=\"0\" y2=\"50\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"250\" x2=\"300\" y1=\"45\" y2=\"45\"/><line stroke=\"white\" stroke-width=\"4\" x1=\"0\" x2=\"300\" y1=\"50\" y2=\"50\"/><text font-size=\"20\" text-anchor=\"start\" x=\"3\" y=\"80\">b</text><line stroke=\"white\" stroke-width=\"1\" x1=\"50\" x2=\"50\" y1=\"50\" y2=\"100\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"100\" x2=\"100\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"50\" x2=\"100\" y1=\"55\" y2=\"55\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"150\" x2=\"150\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"100\" y1=\"55\" y2=\"95\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"100\" x2=\"150\" y1=\"95\" y2=\"95\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"200\" x2=\"200\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"150\" x2=\"150\" y1=\"55\" y2=\"95\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"150\" x2=\"200\" y1=\"55\" y2=\"55\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"250\" x2=\"250\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"200\" x2=\"200\" y1=\"55\" y2=\"95\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"200\" x2=\"250\" y1=\"95\" y2=\"95\"/><line stroke=\"white\" stroke-width=\"1\" x1=\"300\" x2=\"300\" y1=\"50\" y2=\"100\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"250\" x2=\"250\" y1=\"55\" y2=\"95\"/><line stroke=\"#ff0000\" stroke-width=\"2\" x1=\"250\" x2=\"300\" y1=\"55\" y2=\"55\"/><text font-size=\"10\" text-anchor=\"start\" x=\"0\" y=\"110\">prefix</text><text font-size=\"10\" text-anchor=\"start\" x=\"100\" y=\"110\">cycle</text>\n",
"<text font-size=\"10\" text-anchor=\"start\" x=\"200\" y=\"110\">cycle</text></svg>"
],
"text/plain": [
"<IPython.core.display.SVG object>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Words can be easily converted to automata"
]
},
{
"cell_type": "code",
"execution_count": 13,
"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.40.1 (20161225.0304)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"380pt\" height=\"86pt\"\n",
" viewBox=\"0.00 0.00 380.00 86.29\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 82.2859)\">\n",
"<polygon fill=\"#ffffff\" stroke=\"transparent\" points=\"-4,4 -4,-82.2859 376,-82.2859 376,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"183\" y=\"-63.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">t</text>\n",
"<text text-anchor=\"start\" x=\"175\" y=\"-48.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">[all]</text>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"56\" cy=\"-22.2859\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-18.5859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">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=\"#000000\" d=\"M1.1233,-22.2859C4.178,-22.2859 17.9448,-22.2859 30.9241,-22.2859\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"37.9807,-22.2859 30.9808,-25.436 34.4807,-22.286 30.9807,-22.286 30.9807,-22.286 30.9807,-22.286 34.4807,-22.286 30.9807,-19.136 37.9807,-22.2859 37.9807,-22.2859\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"135\" cy=\"-22.2859\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"135\" y=\"-18.5859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M74.3228,-22.2859C84.7921,-22.2859 98.0794,-22.2859 109.5495,-22.2859\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"116.7766,-22.2859 109.7767,-25.436 113.2766,-22.286 109.7766,-22.286 109.7766,-22.286 109.7766,-22.286 113.2766,-22.286 109.7766,-19.136 116.7766,-22.2859 116.7766,-22.2859\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-26.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"241\" cy=\"-22.2859\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"241\" y=\"-18.5859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M153.4638,-22.2859C170.6394,-22.2859 196.386,-22.2859 215.5153,-22.2859\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"222.7478,-22.2859 215.7478,-25.436 219.2478,-22.286 215.7478,-22.286 215.7478,-22.286 215.7478,-22.286 219.2478,-22.286 215.7478,-19.136 222.7478,-22.2859 222.7478,-22.2859\"/>\n",
"<text text-anchor=\"start\" x=\"171\" y=\"-26.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">a &amp; b</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"354\" cy=\"-22.2859\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"354\" y=\"-18.5859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">3</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M259.1554,-22.2859C278.0184,-22.2859 307.6779,-22.2859 328.8045,-22.2859\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"335.8897,-22.2859 328.8897,-25.436 332.3897,-22.286 328.8897,-22.286 328.8897,-22.286 328.8897,-22.286 332.3897,-22.286 328.8896,-19.136 335.8897,-22.2859 335.8897,-22.2859\"/>\n",
"<text text-anchor=\"start\" x=\"277\" y=\"-26.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; !b</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;2 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
"<title>3&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M338.8943,-12.2159C332.6932,-8.6541 325.2713,-5.087 318,-3.2859 300.3123,1.0953 294.6877,1.0953 277,-3.2859 272.1146,-4.496 267.1612,-6.5033 262.5558,-8.7706\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"256.1057,-12.2159 260.7959,-6.1393 259.1929,-10.5668 262.2801,-8.9178 262.2801,-8.9178 262.2801,-8.9178 259.1929,-10.5668 263.7642,-11.6963 256.1057,-12.2159 256.1057,-12.2159\"/>\n",
"<text text-anchor=\"start\" x=\"279\" y=\"-7.0859\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!a &amp; b</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 0x7f4e4c6528a0> >"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w.as_automaton()"
]
}
],
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}