spot/tests/python/word.ipynb
2022-01-14 20:26:44 +01:00

611 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.43.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"574pt\" height=\"194pt\"\n",
" viewBox=\"0.00 0.00 574.00 194.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 190)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-190 570,-190 570,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"262.5\" y=\"-171.8\" font-family=\"Lato\" font-size=\"14.00\">Inf(</text>\n",
"<text text-anchor=\"start\" x=\"283.5\" y=\"-171.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"<text text-anchor=\"start\" x=\"299.5\" y=\"-171.8\" font-family=\"Lato\" font-size=\"14.00\">)</text>\n",
"<text text-anchor=\"start\" x=\"261.5\" y=\"-157.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&#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,-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&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>0&#45;&gt;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=\"222\" cy=\"-99\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"222\" y=\"-95.3\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M154.86,-57.35C167.53,-65.33 185.9,-76.9 200.06,-85.82\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"206.24,-89.71 198.64,-88.64 203.28,-87.84 200.31,-85.98 200.31,-85.98 200.31,-85.98 203.28,-87.84 201.99,-83.31 206.24,-89.71 206.24,-89.71\"/>\n",
"<text text-anchor=\"start\" x=\"175\" y=\"-79.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=\"330\" cy=\"-67\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"330\" y=\"-63.3\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M157,-49.41C176.9,-51.1 210.86,-54.05 240,-57 261.93,-59.22 286.86,-62.05 304.75,-64.13\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"311.95,-64.97 304.63,-67.29 308.47,-64.56 305,-64.16 305,-64.16 305,-64.16 308.47,-64.56 305.36,-61.03 311.95,-64.97 311.95,-64.97\"/>\n",
"<text text-anchor=\"start\" x=\"218.5\" y=\"-60.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=\"546\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"546\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M152.24,-35.67C167.12,-22.05 193.67,-2 221,-2 221,-2 221,-2 439,-2 467.47,-2 499.76,-7.71 521.14,-12.31\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"528.23,-13.88 520.71,-15.44 524.81,-13.12 521.39,-12.37 521.39,-12.37 521.39,-12.37 524.81,-13.12 522.07,-9.29 528.23,-13.88 528.23,-13.88\"/>\n",
"<text text-anchor=\"start\" x=\"324.5\" y=\"-5.8\" font-family=\"Lato\" font-size=\"14.00\">!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=\"black\" d=\"M214.97,-115.66C213.41,-125.62 215.75,-135 222,-135 226.69,-135 229.18,-129.73 229.47,-122.89\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"229.03,-115.66 232.6,-122.46 229.24,-119.16 229.46,-122.65 229.46,-122.65 229.46,-122.65 229.24,-119.16 226.31,-122.84 229.03,-115.66 229.03,-115.66\"/>\n",
"<text text-anchor=\"start\" x=\"204\" y=\"-138.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</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=\"black\" d=\"M239.98,-101.62C254.76,-103.19 276.51,-103.75 294,-97 300.58,-94.46 306.78,-90.11 312.08,-85.51\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"317.45,-80.48 314.49,-87.56 314.89,-82.87 312.34,-85.26 312.34,-85.26 312.34,-85.26 314.89,-82.87 310.18,-82.96 317.45,-80.48 317.45,-80.48\"/>\n",
"<text text-anchor=\"start\" x=\"260\" y=\"-120.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"268\" y=\"-105.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;2 -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>3&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M311.9,-67.8C297.23,-68.92 275.71,-71.59 258,-78 252.96,-79.82 247.84,-82.4 243.14,-85.13\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"237.01,-88.89 241.33,-82.54 240,-87.06 242.98,-85.23 242.98,-85.23 242.98,-85.23 240,-87.06 244.63,-87.91 237.01,-88.89 237.01,-88.89\"/>\n",
"<text text-anchor=\"start\" x=\"258\" y=\"-81.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;3 -->\n",
"<g id=\"edge9\" class=\"edge\">\n",
"<title>3&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M320.77,-82.54C318.17,-92.91 321.25,-103 330,-103 336.7,-103 340.08,-97.08 340.12,-89.66\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"339.23,-82.54 343.23,-89.1 339.67,-86.01 340.1,-89.49 340.1,-89.49 340.1,-89.49 339.67,-86.01 336.98,-89.88 339.23,-82.54 339.23,-82.54\"/>\n",
"<text text-anchor=\"start\" x=\"314\" y=\"-121.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"322\" y=\"-106.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">⓿</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node7\" class=\"node\">\n",
"<title>5</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"438\" cy=\"-57\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"438\" y=\"-53.3\" font-family=\"Lato\" font-size=\"14.00\">5</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;5 -->\n",
"<g id=\"edge10\" class=\"edge\">\n",
"<title>3&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M348.03,-65.39C365.57,-63.74 393.06,-61.15 412.84,-59.28\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"420.01,-58.6 413.34,-62.4 416.53,-58.93 413.04,-59.26 413.04,-59.26 413.04,-59.26 416.53,-58.93 412.75,-56.12 420.01,-58.6 420.01,-58.6\"/>\n",
"<text text-anchor=\"start\" x=\"366\" y=\"-66.8\" font-family=\"Lato\" font-size=\"14.00\">!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=\"black\" d=\"M536.77,-33.54C534.17,-43.91 537.25,-54 546,-54 552.7,-54 556.08,-48.08 556.12,-40.66\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"555.23,-33.54 559.23,-40.1 555.67,-37.01 556.1,-40.49 556.1,-40.49 556.1,-40.49 555.67,-37.01 552.98,-40.88 555.23,-33.54 555.23,-33.54\"/>\n",
"<text text-anchor=\"start\" x=\"526\" y=\"-72.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !b</text>\n",
"<text text-anchor=\"start\" x=\"538\" 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=\"black\" d=\"M455.1,-51.08C472.92,-44.52 501.79,-33.9 522,-26.46\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"528.75,-23.98 523.27,-29.35 525.46,-25.19 522.18,-26.4 522.18,-26.4 522.18,-26.4 525.46,-25.19 521.09,-23.44 528.75,-23.98 528.75,-23.98\"/>\n",
"<text text-anchor=\"start\" x=\"474\" y=\"-46.8\" font-family=\"Lato\" font-size=\"14.00\">!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 0x7f14f57d93c0> >"
]
},
"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",
" 3\n",
" | !a & b\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; !a & b}\n"
]
},
{
"data": {
"text/latex": [
"$\\lnot a; \\lnot a; \\mathsf{cycle}\\{a \\land b; \\lnot a \\land b\\}$"
],
"text/plain": [
"<spot.twa_word; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_word > *' at 0x7f14f57d9ed0> >"
]
},
"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=\"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=\"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=\"45\" x2=\"100\" y2=\"45\" 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=\"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=\"150\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><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=\"5\" x2=\"200\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"200\" y1=\"5\" x2=\"250\" y2=\"5\" stroke=\"#ff0000\" stroke-width=\"2\"/><line x1=\"300\" y1=\"0\" x2=\"300\" y2=\"50\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"250\" y1=\"5\" x2=\"250\" y2=\"45\" stroke=\"#ff0000\" stroke-width=\"2\"/><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=\"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\"/><line x1=\"250\" y1=\"50\" x2=\"250\" y2=\"100\" stroke=\"white\" stroke-width=\"1\"/><line x1=\"200\" y1=\"55\" x2=\"250\" y2=\"55\" 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=\"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": 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",
"!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]))\n",
"print(spot.bdd_format_formula(aut.get_dict(), word.cycle[1]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Calling `simplify()` will produce a shorter word that is compatible with the original word. For instance, in the above word the second `a` is compatible with `!a & b`, so the prefix can be shortened by rotating the cycle."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"!a; cycle{!a & b; 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}\\{\\lnot a \\land b; a \\land b\\}$"
],
"text/plain": [
"<spot.twa_word; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_word > *' at 0x7f14f57d9660> >"
]
},
"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 0x7f14f5799ea0> >"
]
},
"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=\"377pt\" height=\"86pt\"\n",
" viewBox=\"0.00 0.00 377.00 86.28\" 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.28)\">\n",
"<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-82.28 373,-82.28 373,4 -4,4\"/>\n",
"<text text-anchor=\"start\" x=\"181.5\" y=\"-63.08\" font-family=\"Lato\" font-size=\"14.00\">t</text>\n",
"<text text-anchor=\"start\" x=\"173.5\" y=\"-48.08\" 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.28\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-18.58\" 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,-22.28C2.79,-22.28 17.15,-22.28 30.63,-22.28\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.94,-22.28 30.94,-25.43 34.44,-22.28 30.94,-22.28 30.94,-22.28 30.94,-22.28 34.44,-22.28 30.94,-19.13 37.94,-22.28 37.94,-22.28\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"135\" cy=\"-22.28\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"135\" y=\"-18.58\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M74.09,-22.28C84.56,-22.28 98.12,-22.28 109.69,-22.28\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"116.96,-22.28 109.96,-25.43 113.46,-22.28 109.96,-22.28 109.96,-22.28 109.96,-22.28 113.46,-22.28 109.96,-19.13 116.96,-22.28 116.96,-22.28\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-26.08\" 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=\"239\" cy=\"-22.28\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"239\" y=\"-18.58\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M153.3,-22.28C169.96,-22.28 195.3,-22.28 213.93,-22.28\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"220.95,-22.28 213.95,-25.43 217.45,-22.28 213.95,-22.28 213.95,-22.28 213.95,-22.28 217.45,-22.28 213.95,-19.13 220.95,-22.28 220.95,-22.28\"/>\n",
"<text text-anchor=\"start\" x=\"171\" y=\"-26.08\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\">\n",
"<title>3</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"351\" cy=\"-22.28\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"351\" y=\"-18.58\" font-family=\"Lato\" font-size=\"14.00\">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=\"black\" d=\"M257.19,-22.28C275.59,-22.28 304.95,-22.28 325.71,-22.28\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"332.93,-22.28 325.93,-25.43 329.43,-22.28 325.93,-22.28 325.93,-22.28 325.93,-22.28 329.43,-22.28 325.93,-19.13 332.93,-22.28 332.93,-22.28\"/>\n",
"<text text-anchor=\"start\" x=\"275\" y=\"-26.08\" font-family=\"Lato\" font-size=\"14.00\">!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=\"black\" d=\"M335.69,-12.42C329.6,-8.79 322.24,-5.12 315,-3.28 297.77,1.09 292.23,1.09 275,-3.28 270.14,-4.52 265.22,-6.58 260.67,-8.9\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"254.31,-12.42 258.91,-6.27 257.37,-10.72 260.44,-9.03 260.44,-9.03 260.44,-9.03 257.37,-10.72 261.96,-11.78 254.31,-12.42 254.31,-12.42\"/>\n",
"<text text-anchor=\"start\" x=\"277\" y=\"-7.08\" font-family=\"Lato\" font-size=\"14.00\">!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 0x7f14f5799ed0> >"
]
},
"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.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}