This is to workaround differences in minidom's pretty-printing that occurred between Python 3.7 and 3.8. * python/spot/jupyter.py (SVG): New class. * python/spot/__init__.py: Use it. * tests/python/_altscc.ipynb, tests/python/alternation.ipynb, tests/python/automata.ipynb, tests/python/formulas.ipynb, tests/python/gen.ipynb, tests/python/highlighting.ipynb, tests/python/ltsmin-dve.ipynb, tests/python/ltsmin-pml.ipynb, tests/python/product.ipynb, tests/python/randaut.ipynb, tests/python/testingaut.ipynb, tests/python/twagraph-internals.ipynb, tests/python/word.ipynb: Adjust.
607 lines
29 KiB
Text
607 lines
29 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.43.0 (0)\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.0 1.0) rotate(0) translate(4 228)\">\n",
|
|
"<polygon fill=\"white\" 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\">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\">)</text>\n",
|
|
"<text text-anchor=\"start\" x=\"205.25\" y=\"-195.8\" font-family=\"Lato\" font-size=\"14.00\">[Büchi]</text>\n",
|
|
"<!-- I -->\n",
|
|
"<!-- 0 -->\n",
|
|
"<g id=\"node2\" class=\"node\">\n",
|
|
"<title>0</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">0</text>\n",
|
|
"</g>\n",
|
|
"<!-- I->0 -->\n",
|
|
"<g id=\"edge1\" class=\"edge\">\n",
|
|
"<title>I->0</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M1.15,-48C2.79,-48 17.15,-48 30.63,-48\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-48 30.94,-51.15 34.44,-48 30.94,-48 30.94,-48 30.94,-48 34.44,-48 30.94,-44.85 37.94,-48 37.94,-48\"/>\n",
|
|
"</g>\n",
|
|
"<!-- 1 -->\n",
|
|
"<g id=\"node3\" class=\"node\">\n",
|
|
"<title>1</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">1</text>\n",
|
|
"</g>\n",
|
|
"<!-- 0->1 -->\n",
|
|
"<g id=\"edge2\" class=\"edge\">\n",
|
|
"<title>0->1</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M74.18,-48C85.67,-48 100.96,-48 113.69,-48\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"120.85,-48 113.85,-51.15 117.35,-48 113.85,-48 113.85,-48 113.85,-48 117.35,-48 113.85,-44.85 120.85,-48 120.85,-48\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"92\" y=\"-51.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
|
|
"</g>\n",
|
|
"<!-- 2 -->\n",
|
|
"<g id=\"node4\" class=\"node\">\n",
|
|
"<title>2</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">2</text>\n",
|
|
"</g>\n",
|
|
"<!-- 1->2 -->\n",
|
|
"<g id=\"edge3\" class=\"edge\">\n",
|
|
"<title>1->2</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M153.77,-58.91C166.03,-68.62 184.1,-82.94 197.79,-93.78\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"203.35,-98.19 195.91,-96.31 200.61,-96.02 197.87,-93.84 197.87,-93.84 197.87,-93.84 200.61,-96.02 199.82,-91.37 203.35,-98.19 203.35,-98.19\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"175\" y=\"-83.8\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
|
|
"</g>\n",
|
|
"<!-- 3 -->\n",
|
|
"<g id=\"node5\" class=\"node\">\n",
|
|
"<title>3</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">3</text>\n",
|
|
"</g>\n",
|
|
"<!-- 1->3 -->\n",
|
|
"<g id=\"edge4\" class=\"edge\">\n",
|
|
"<title>1->3</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M157.27,-50.51C185.39,-54.68 242.77,-63.5 291,-73 294.65,-73.72 298.51,-74.54 302.27,-75.37\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"309.31,-76.97 301.79,-78.49 305.9,-76.19 302.48,-75.42 302.48,-75.42 302.48,-75.42 305.9,-76.19 303.18,-72.35 309.31,-76.97 309.31,-76.97\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"212.5\" y=\"-65.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
|
|
"</g>\n",
|
|
"<!-- 4 -->\n",
|
|
"<g id=\"node6\" class=\"node\">\n",
|
|
"<title>4</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">4</text>\n",
|
|
"</g>\n",
|
|
"<!-- 1->4 -->\n",
|
|
"<g id=\"edge5\" class=\"edge\">\n",
|
|
"<title>1->4</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M157.14,-46.26C207.03,-41.18 352.37,-26.4 410.53,-20.49\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"417.82,-19.75 411.17,-23.59 414.34,-20.1 410.85,-20.46 410.85,-20.46 410.85,-20.46 414.34,-20.1 410.53,-17.32 417.82,-19.75 417.82,-19.75\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"267\" y=\"-39.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
|
|
"</g>\n",
|
|
"<!-- 2->2 -->\n",
|
|
"<g id=\"edge6\" class=\"edge\">\n",
|
|
"<title>2->2</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M211.27,-126.04C209.89,-135.86 212.14,-145 218,-145 222.4,-145 224.76,-139.86 225.09,-133.14\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"224.73,-126.04 228.23,-132.87 224.91,-129.53 225.08,-133.03 225.08,-133.03 225.08,-133.03 224.91,-129.53 221.93,-133.18 224.73,-126.04 224.73,-126.04\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"201\" y=\"-163.8\" font-family=\"Lato\" font-size=\"14.00\">a & 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->3 -->\n",
|
|
"<g id=\"edge7\" class=\"edge\">\n",
|
|
"<title>2->3</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M231.09,-96.52C237.34,-90.95 245.45,-84.98 254,-82 269.38,-76.64 287.75,-76.47 302.09,-77.61\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"309.18,-78.3 301.91,-80.75 305.7,-77.96 302.22,-77.62 302.22,-77.62 302.22,-77.62 305.7,-77.96 302.52,-74.48 309.18,-78.3 309.18,-78.3\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"254\" y=\"-85.8\" font-family=\"Lato\" font-size=\"14.00\">!a & b</text>\n",
|
|
"</g>\n",
|
|
"<!-- 5 -->\n",
|
|
"<g id=\"node7\" class=\"node\">\n",
|
|
"<title>5</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" 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\">5</text>\n",
|
|
"</g>\n",
|
|
"<!-- 2->5 -->\n",
|
|
"<g id=\"edge8\" class=\"edge\">\n",
|
|
"<title>2->5</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M231.56,-121.4C237.92,-127.24 245.99,-134 254,-139 269.38,-148.59 288.25,-156.6 302.81,-162.07\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"309.58,-164.54 301.92,-165.1 306.29,-163.34 303.01,-162.14 303.01,-162.14 303.01,-162.14 306.29,-163.34 304.09,-159.18 309.58,-164.54 309.58,-164.54\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"254\" y=\"-160.8\" font-family=\"Lato\" font-size=\"14.00\">!a & b</text>\n",
|
|
"</g>\n",
|
|
"<!-- 3->2 -->\n",
|
|
"<g id=\"edge9\" class=\"edge\">\n",
|
|
"<title>3->2</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M310.66,-89.07C304.67,-91.94 297.64,-94.97 291,-97 275.42,-101.77 257.32,-104.77 243.17,-106.58\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"236.17,-107.43 242.74,-103.46 239.64,-107.01 243.12,-106.59 243.12,-106.59 243.12,-106.59 239.64,-107.01 243.49,-109.72 236.17,-107.43 236.17,-107.43\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"255.5\" y=\"-123.8\" font-family=\"Lato\" font-size=\"14.00\">a & b</text>\n",
|
|
"<text text-anchor=\"start\" x=\"264.5\" y=\"-108.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
|
|
"</g>\n",
|
|
"<!-- 3->3 -->\n",
|
|
"<g id=\"edge10\" class=\"edge\">\n",
|
|
"<title>3->3</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M317.77,-96.54C315.17,-106.91 318.25,-117 327,-117 333.7,-117 337.08,-111.08 337.12,-103.66\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"336.23,-96.54 340.23,-103.1 336.67,-100.01 337.1,-103.49 337.1,-103.49 337.1,-103.49 336.67,-100.01 333.98,-103.88 336.23,-96.54 336.23,-96.54\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"308.5\" y=\"-120.8\" font-family=\"Lato\" font-size=\"14.00\">!a & b</text>\n",
|
|
"</g>\n",
|
|
"<!-- 4->4 -->\n",
|
|
"<g id=\"edge11\" class=\"edge\">\n",
|
|
"<title>4->4</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M426.77,-33.54C424.17,-43.91 427.25,-54 436,-54 442.7,-54 446.08,-48.08 446.12,-40.66\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"445.23,-33.54 449.23,-40.1 445.67,-37.01 446.1,-40.49 446.1,-40.49 446.1,-40.49 445.67,-37.01 442.98,-40.88 445.23,-33.54 445.23,-33.54\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"415.5\" y=\"-72.8\" font-family=\"Lato\" font-size=\"14.00\">!a & !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->4 -->\n",
|
|
"<g id=\"edge12\" class=\"edge\">\n",
|
|
"<title>5->4</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M338.07,-155.7C357.19,-128.54 398.8,-69.43 420.76,-38.22\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"424.88,-32.37 423.43,-39.91 422.87,-35.23 420.85,-38.1 420.85,-38.1 420.85,-38.1 422.87,-35.23 418.28,-36.28 424.88,-32.37 424.88,-32.37\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"363\" y=\"-119.8\" font-family=\"Lato\" font-size=\"14.00\">!a & 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 0x7f956c0198d0> >"
|
|
]
|
|
},
|
|
"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 0x7f956c019de0> >"
|
|
]
|
|
},
|
|
"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": [
|
|
"\n",
|
|
"<svg height=\"112\" width=\"200\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
|
|
"<rect x=\"0\" y=\"0\" width=\"200\" height=\"100\" fill=\"#f4f4f4\"/>\n",
|
|
"<line x1=\"100\" y1=\"0\" x2=\"100\" y2=\"100\"\n",
|
|
" stroke=\"white\" stroke-width=\"4\"/>\n",
|
|
"<line x1=\"150\" y1=\"0\" x2=\"150\" y2=\"100\"\n",
|
|
" stroke=\"white\" stroke-width=\"4\"/>\n",
|
|
"<line x1=\"0\" y1=\"0\" x2=\"200\" y2=\"0\" stroke=\"white\" stroke-width=\"4\"/><text x=\"3\" y=\"30\" text-anchor=\"start\" font-size=\"20\">a</text><line x1=\"50\" y1=\"0\" x2=\"50\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"0\" y1=\"45\" x2=\"50\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"100\" y1=\"0\" x2=\"100\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"50\" y1=\"5\" x2=\"50\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"50\" y1=\"5\" x2=\"100\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"150\" y1=\"0\" x2=\"150\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"5\" x2=\"150\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"0\" x2=\"200\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"150\" y1=\"5\" x2=\"200\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"0\" y1=\"50\" x2=\"200\" y2=\"50\" stroke=\"white\" stroke-width=\"4\"/><text x=\"3\" y=\"80\" text-anchor=\"start\" font-size=\"20\">b</text><line x1=\"50\" y1=\"50\" x2=\"50\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"50\" x2=\"100\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"150\" y1=\"50\" x2=\"150\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"55\" x2=\"150\" y2=\"55\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"50\" x2=\"200\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"150\" y1=\"55\" x2=\"200\" y2=\"55\" stroke=\"#ff0000\" stroke-width=\"2\"/><text x=\"0\" y=\"110\" text-anchor=\"start\" font-size=\"10\">prefix</text><text x=\"100\" y=\"110\" text-anchor=\"start\" font-size=\"10\">cycle</text>\n",
|
|
"<text x=\"150\" y=\"110\" text-anchor=\"start\" font-size=\"10\">cycle</text></svg>"
|
|
],
|
|
"text/plain": [
|
|
"<spot.jupyter.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 0x7f956c0388a0> >"
|
|
]
|
|
},
|
|
"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 0x7f956c038b70> >"
|
|
]
|
|
},
|
|
"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": [
|
|
"\n",
|
|
"<svg height=\"112\" width=\"300\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">\n",
|
|
"<rect x=\"0\" y=\"0\" width=\"300\" height=\"100\" fill=\"#f4f4f4\"/>\n",
|
|
"<line x1=\"100\" y1=\"0\" x2=\"100\" y2=\"100\"\n",
|
|
" stroke=\"white\" stroke-width=\"4\"/>\n",
|
|
"<line x1=\"200\" y1=\"0\" x2=\"200\" y2=\"100\"\n",
|
|
" stroke=\"white\" stroke-width=\"4\"/>\n",
|
|
"<line x1=\"0\" y1=\"0\" x2=\"300\" y2=\"0\" stroke=\"white\" stroke-width=\"4\"/><text x=\"3\" y=\"30\" text-anchor=\"start\" font-size=\"20\">a</text><line x1=\"50\" y1=\"0\" x2=\"50\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"0\" y1=\"5\" x2=\"50\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"100\" y1=\"0\" x2=\"100\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"50\" y1=\"5\" x2=\"100\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"150\" y1=\"0\" x2=\"150\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"5\" x2=\"100\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"100\" y1=\"45\" x2=\"150\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"0\" x2=\"200\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"150\" y1=\"45\" x2=\"200\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"250\" y1=\"0\" x2=\"250\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"200\" y1=\"45\" x2=\"250\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"300\" y1=\"0\" x2=\"300\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"250\" y1=\"45\" x2=\"300\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"0\" y1=\"50\" x2=\"300\" y2=\"50\" stroke=\"white\" stroke-width=\"4\"/><text x=\"3\" y=\"80\" text-anchor=\"start\" font-size=\"20\">b</text><line x1=\"50\" y1=\"50\" x2=\"50\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"50\" x2=\"100\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"50\" y1=\"55\" x2=\"100\" y2=\"55\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"150\" y1=\"50\" x2=\"150\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"100\" y1=\"55\" x2=\"100\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"100\" y1=\"95\" x2=\"150\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"50\" x2=\"200\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"150\" y1=\"55\" x2=\"150\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"150\" y1=\"55\" x2=\"200\" y2=\"55\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"250\" y1=\"50\" x2=\"250\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"200\" y1=\"55\" x2=\"200\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"95\" x2=\"250\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"300\" y1=\"50\" x2=\"300\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"250\" y1=\"55\" x2=\"250\" y2=\"95\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"250\" y1=\"55\" x2=\"300\" y2=\"55\" stroke=\"#ff0000\" stroke-width=\"2\"/><text x=\"0\" y=\"110\" text-anchor=\"start\" font-size=\"10\">prefix</text><text x=\"100\" y=\"110\" text-anchor=\"start\" font-size=\"10\">cycle</text>\n",
|
|
"<text x=\"200\" y=\"110\" text-anchor=\"start\" font-size=\"10\">cycle</text></svg>"
|
|
],
|
|
"text/plain": [
|
|
"<spot.jupyter.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.43.0 (0)\n",
|
|
" -->\n",
|
|
"<!-- Pages: 1 -->\n",
|
|
"<svg width=\"380pt\" height=\"86pt\"\n",
|
|
" viewBox=\"0.00 0.00 380.00 86.36\" 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 82.36)\">\n",
|
|
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-82.36 376,-82.36 376,4 -4,4\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"183\" y=\"-63.16\" font-family=\"Lato\" font-size=\"14.00\">t</text>\n",
|
|
"<text text-anchor=\"start\" x=\"175\" y=\"-48.16\" font-family=\"Lato\" font-size=\"14.00\">[all]</text>\n",
|
|
"<!-- I -->\n",
|
|
"<!-- 0 -->\n",
|
|
"<g id=\"node2\" class=\"node\">\n",
|
|
"<title>0</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"56\" cy=\"-22.36\" rx=\"18\" ry=\"18\"/>\n",
|
|
"<text text-anchor=\"middle\" x=\"56\" y=\"-18.66\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
|
|
"</g>\n",
|
|
"<!-- I->0 -->\n",
|
|
"<g id=\"edge1\" class=\"edge\">\n",
|
|
"<title>I->0</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M1.15,-22.36C2.79,-22.36 17.15,-22.36 30.63,-22.36\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-22.36 30.94,-25.51 34.44,-22.36 30.94,-22.36 30.94,-22.36 30.94,-22.36 34.44,-22.36 30.94,-19.21 37.94,-22.36 37.94,-22.36\"/>\n",
|
|
"</g>\n",
|
|
"<!-- 1 -->\n",
|
|
"<g id=\"node3\" class=\"node\">\n",
|
|
"<title>1</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"135\" cy=\"-22.36\" rx=\"18\" ry=\"18\"/>\n",
|
|
"<text text-anchor=\"middle\" x=\"135\" y=\"-18.66\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
|
|
"</g>\n",
|
|
"<!-- 0->1 -->\n",
|
|
"<g id=\"edge2\" class=\"edge\">\n",
|
|
"<title>0->1</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M74.09,-22.36C84.56,-22.36 98.12,-22.36 109.69,-22.36\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"116.96,-22.36 109.96,-25.51 113.46,-22.36 109.96,-22.36 109.96,-22.36 109.96,-22.36 113.46,-22.36 109.96,-19.21 116.96,-22.36 116.96,-22.36\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"92\" y=\"-26.16\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
|
|
"</g>\n",
|
|
"<!-- 2 -->\n",
|
|
"<g id=\"node4\" class=\"node\">\n",
|
|
"<title>2</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"241\" cy=\"-22.36\" rx=\"18\" ry=\"18\"/>\n",
|
|
"<text text-anchor=\"middle\" x=\"241\" y=\"-18.66\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
|
|
"</g>\n",
|
|
"<!-- 1->2 -->\n",
|
|
"<g id=\"edge3\" class=\"edge\">\n",
|
|
"<title>1->2</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M153.17,-22.36C170.18,-22.36 196.4,-22.36 215.57,-22.36\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"222.8,-22.36 215.8,-25.51 219.3,-22.36 215.8,-22.36 215.8,-22.36 215.8,-22.36 219.3,-22.36 215.8,-19.21 222.8,-22.36 222.8,-22.36\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"171\" y=\"-26.16\" font-family=\"Lato\" font-size=\"14.00\">a & b</text>\n",
|
|
"</g>\n",
|
|
"<!-- 3 -->\n",
|
|
"<g id=\"node5\" class=\"node\">\n",
|
|
"<title>3</title>\n",
|
|
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"354\" cy=\"-22.36\" rx=\"18\" ry=\"18\"/>\n",
|
|
"<text text-anchor=\"middle\" x=\"354\" y=\"-18.66\" font-family=\"Lato\" font-size=\"14.00\">3</text>\n",
|
|
"</g>\n",
|
|
"<!-- 2->3 -->\n",
|
|
"<g id=\"edge4\" class=\"edge\">\n",
|
|
"<title>2->3</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M259.34,-22.36C278,-22.36 307.8,-22.36 328.76,-22.36\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"335.78,-22.36 328.78,-25.51 332.28,-22.36 328.78,-22.36 328.78,-22.36 328.78,-22.36 332.28,-22.36 328.78,-19.21 335.78,-22.36 335.78,-22.36\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"277\" y=\"-26.16\" font-family=\"Lato\" font-size=\"14.00\">!a & !b</text>\n",
|
|
"</g>\n",
|
|
"<!-- 3->2 -->\n",
|
|
"<g id=\"edge5\" class=\"edge\">\n",
|
|
"<title>3->2</title>\n",
|
|
"<path fill=\"none\" stroke=\"black\" d=\"M338.69,-12.5C332.6,-8.87 325.24,-5.2 318,-3.36 300.34,1.12 294.66,1.12 277,-3.36 272.14,-4.6 267.22,-6.66 262.67,-8.98\"/>\n",
|
|
"<polygon fill=\"black\" stroke=\"black\" points=\"256.31,-12.5 260.91,-6.35 259.37,-10.8 262.44,-9.11 262.44,-9.11 262.44,-9.11 259.37,-10.8 263.96,-11.86 256.31,-12.5 256.31,-12.5\"/>\n",
|
|
"<text text-anchor=\"start\" x=\"279\" y=\"-7.16\" font-family=\"Lato\" font-size=\"14.00\">!a & 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 0x7f956c0388d0> >"
|
|
]
|
|
},
|
|
"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.7.5"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|