spot/tests/python/word.ipynb
Alexandre Duret-Lutz 17b295e10f python: SVG display of word as signals
Fixes #309.

* python/spot/__init__.py (twa_word.as_svg, twa_word.show): New
  methods.
* tests/python/word.ipynb: Use them.
* NEWS: Mention them.
2018-01-04 18:43:12 +01:00

716 lines
35 KiB
Text

{
"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.4"
},
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"import spot\n",
"spot.setup()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's build a small automaton to use as example."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"aut = spot.translate('!a & G(Fa <-> XXb)'); aut"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 2,
"svg": [
"<?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.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"465pt\" height=\"166pt\"\n",
" viewBox=\"0.00 0.00 464.50 166.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 162)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-162 460.5,-162 460.5,4 -4,4\"/>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"56\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15491,-18C2.79388,-18 17.1543,-18 30.6317,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.9419,-18 30.9419,-21.1501 34.4419,-18 30.9419,-18.0001 30.9419,-18.0001 30.9419,-18.0001 34.4419,-18 30.9418,-14.8501 37.9419,-18 37.9419,-18\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\"><title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"139\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"139\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M74.178,-18C85.6688,-18 100.959,-18 113.693,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"120.847,-18 113.847,-21.1501 117.347,-18 113.847,-18.0001 113.847,-18.0001 113.847,-18.0001 117.347,-18 113.847,-14.8501 120.847,-18 120.847,-18\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-21.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"218\" cy=\"-79\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"218\" y=\"-75.3\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M153.766,-28.9056C166.03,-38.6209 184.099,-52.936 197.786,-63.7783\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"203.353,-68.1888 195.91,-66.3112 200.61,-66.0154 197.866,-63.8421 197.866,-63.8421 197.866,-63.8421 200.61,-66.0154 199.822,-61.373 203.353,-68.1888 203.353,-68.1888\"/>\n",
"<text text-anchor=\"start\" x=\"175\" y=\"-53.8\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"327\" cy=\"-51\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"327\" y=\"-47.3\" font-family=\"Lato\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>1&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M157.272,-20.511C185.389,-24.6769 242.767,-33.504 291,-43 294.652,-43.719 298.505,-44.538 302.266,-45.371\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"309.309,-46.9679 301.786,-48.492 305.896,-46.194 302.483,-45.42 302.483,-45.42 302.483,-45.42 305.896,-46.194 303.179,-42.348 309.309,-46.9679 309.309,-46.9679\"/>\n",
"<text text-anchor=\"start\" x=\"212.5\" y=\"-35.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node6\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"436\" cy=\"-22\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"436\" y=\"-18.3\" font-family=\"Lato\" font-size=\"14.00\">4</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;4 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>1&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M157.382,-17.8002C179.736,-17.5541 219.759,-17.1502 254,-17 270.444,-16.9279 274.558,-16.7146 291,-17 333.016,-17.7292 381.897,-19.6544 410.541,-20.892\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"417.716,-21.2059 410.585,-24.0468 414.219,-21.0529 410.722,-20.8998 410.722,-20.8998 410.722,-20.8998 414.219,-21.0529 410.86,-17.7529 417.716,-21.2059 417.716,-21.2059\"/>\n",
"<text text-anchor=\"start\" x=\"267\" y=\"-20.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;2 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>2&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M211.266,-96.0373C209.892,-105.858 212.137,-115 218,-115 222.397,-115 224.759,-109.858 225.086,-103.143\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"224.734,-96.0373 228.226,-102.873 224.907,-99.533 225.08,-103.029 225.08,-103.029 225.08,-103.029 224.907,-99.533 221.934,-103.185 224.734,-96.0373 224.734,-96.0373\"/>\n",
"<text text-anchor=\"start\" x=\"201\" y=\"-133.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"210\" y=\"-118.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">\u24ff</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge7\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M231.092,-66.5202C237.345,-60.9508 245.449,-54.9814 254,-52 269.38,-46.6377 287.754,-46.4746 302.091,-47.6074\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"309.184,-48.2973 301.912,-50.7547 305.7,-47.9584 302.217,-47.6195 302.217,-47.6195 302.217,-47.6195 305.7,-47.9584 302.522,-44.4843 309.184,-48.2973 309.184,-48.2973\"/>\n",
"<text text-anchor=\"start\" x=\"254\" y=\"-55.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 5 -->\n",
"<g id=\"node7\" class=\"node\"><title>5</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"327\" cy=\"-140\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"327\" y=\"-136.3\" font-family=\"Lato\" font-size=\"14.00\">5</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;5 -->\n",
"<g id=\"edge8\" class=\"edge\"><title>2&#45;&gt;5</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M231.561,-91.398C237.925,-97.2386 245.987,-104.003 254,-109 269.382,-118.592 288.25,-126.595 302.812,-132.066\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"309.58,-134.544 301.924,-135.095 306.293,-133.341 303.007,-132.137 303.007,-132.137 303.007,-132.137 306.293,-133.341 304.09,-129.179 309.58,-134.544 309.58,-134.544\"/>\n",
"<text text-anchor=\"start\" x=\"254\" y=\"-130.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;2 -->\n",
"<g id=\"edge9\" class=\"edge\"><title>3&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M310.663,-59.0732C304.666,-61.9449 297.644,-64.9668 291,-67 275.418,-71.7682 257.324,-74.7739 243.173,-76.5847\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"236.167,-77.4257 242.741,-73.4638 239.642,-77.0085 243.117,-76.5914 243.117,-76.5914 243.117,-76.5914 239.642,-77.0085 243.492,-79.7189 236.167,-77.4257 236.167,-77.4257\"/>\n",
"<text text-anchor=\"start\" x=\"255.5\" y=\"-93.8\" font-family=\"Lato\" font-size=\"14.00\">a &amp; b</text>\n",
"<text text-anchor=\"start\" x=\"264.5\" y=\"-78.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">\u24ff</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;3 -->\n",
"<g id=\"edge10\" class=\"edge\"><title>3&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M317.767,-66.5414C315.169,-76.9087 318.246,-87 327,-87 333.702,-87 337.077,-81.0847 337.124,-73.6591\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"336.233,-66.5414 340.229,-73.0955 336.668,-70.0143 337.103,-73.4871 337.103,-73.4871 337.103,-73.4871 336.668,-70.0143 333.977,-73.8788 336.233,-66.5414 336.233,-66.5414\"/>\n",
"<text text-anchor=\"start\" x=\"308.5\" y=\"-90.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\"><title>4&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M426.767,-37.5414C424.169,-47.9087 427.246,-58 436,-58 442.702,-58 446.077,-52.0847 446.124,-44.6591\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"445.233,-37.5414 449.229,-44.0955 445.668,-41.0143 446.103,-44.4871 446.103,-44.4871 446.103,-44.4871 445.668,-41.0143 442.977,-44.8788 445.233,-37.5414 445.233,-37.5414\"/>\n",
"<text text-anchor=\"start\" x=\"415.5\" y=\"-76.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; !b</text>\n",
"<text text-anchor=\"start\" x=\"428\" y=\"-61.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#1f78b4\">\u24ff</text>\n",
"</g>\n",
"<!-- 5&#45;&gt;4 -->\n",
"<g id=\"edge12\" class=\"edge\"><title>5&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M339.86,-126.921C358.901,-105.922 396.358,-64.6141 418.163,-40.5684\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"423.087,-35.1375 420.719,-42.439 420.736,-37.7303 418.385,-40.3231 418.385,-40.3231 418.385,-40.3231 420.736,-37.7303 416.052,-38.2071 423.087,-35.1375 423.087,-35.1375\"/>\n",
"<text text-anchor=\"start\" x=\"363\" y=\"-101.8\" font-family=\"Lato\" font-size=\"14.00\">!a &amp; b</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fb74c39da80> >"
]
}
],
"prompt_number": 2
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Build an accepting run:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"run = aut.accepting_run(); run"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"text": [
"Prefix:\n",
" 0\n",
" | !a\n",
" 1\n",
" | a\n",
"Cycle:\n",
" 2\n",
" | a & b\t{0}"
]
}
],
"prompt_number": 3
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Accessing the contents of the run can be done via the `prefix` and `cycle` lists."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(spot.bdd_format_formula(aut.get_dict(), run.prefix[0].label))\n",
"print(run.cycle[0].acc)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"!a\n",
"{0}\n"
]
}
],
"prompt_number": 4
},
{
"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",
"collapsed": false,
"input": [
"word = spot.twa_word(run); word"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"text": [
"!a; a; cycle{a & b}"
]
}
],
"prompt_number": 5
},
{
"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",
"collapsed": false,
"input": [
"word.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"svg": [
"<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": [
"<IPython.core.display.SVG object>"
]
}
],
"prompt_number": 6
},
{
"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",
"collapsed": false,
"input": [
"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]))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"!a\n",
"a\n",
"a & b\n"
]
}
],
"prompt_number": 7
},
{
"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",
"collapsed": false,
"input": [
"word.simplify()\n",
"word"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"text": [
"!a; cycle{a & b}"
]
}
],
"prompt_number": 8
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Such a simplified word can be created directly from the automaton:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"aut.accepting_word()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 9,
"text": [
"!a; cycle{a & b}"
]
}
],
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Words can be created using the `parse_word` function:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"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}'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"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"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# 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"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 11,
"text": [
"a; a & b; cycle{!a & !b; !a & b}"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"w.show()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 12,
"svg": [
"<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": [
"<IPython.core.display.SVG object>"
]
}
],
"prompt_number": 12
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Words can be easily converted as automata"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"w1 = spot.parse_word('a; !a; cycle{a; !a; a}')"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"w1.as_automaton()"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 14,
"svg": [
"<?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.38.0 (20140413.2041)\n",
" -->\n",
"<!-- Title: G Pages: 1 -->\n",
"<svg width=\"406pt\" height=\"74pt\"\n",
" viewBox=\"0.00 0.00 406.00 74.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 70)\">\n",
"<title>G</title>\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-70 402,-70 402,4 -4,4\"/>\n",
"<!-- I -->\n",
"<!-- 0 -->\n",
"<g id=\"node2\" class=\"node\"><title>0</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"56\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"56\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">0</text>\n",
"</g>\n",
"<!-- I&#45;&gt;0 -->\n",
"<g id=\"edge1\" class=\"edge\"><title>I&#45;&gt;0</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M1.15491,-18C2.79388,-18 17.1543,-18 30.6317,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"37.9419,-18 30.9419,-21.1501 34.4419,-18 30.9419,-18.0001 30.9419,-18.0001 30.9419,-18.0001 34.4419,-18 30.9418,-14.8501 37.9419,-18 37.9419,-18\"/>\n",
"</g>\n",
"<!-- 1 -->\n",
"<g id=\"node3\" class=\"node\"><title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"135\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"135\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge2\" class=\"edge\"><title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M74.0888,-18C84.5562,-18 98.1196,-18 109.693,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"116.959,-18 109.959,-21.1501 113.459,-18 109.959,-18.0001 109.959,-18.0001 109.959,-18.0001 113.459,-18 109.959,-14.8501 116.959,-18 116.959,-18\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-21.8\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\"><title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"218\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"218\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">2</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge3\" class=\"edge\"><title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M153.178,-18C164.669,-18 179.959,-18 192.693,-18\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"199.847,-18 192.847,-21.1501 196.347,-18 192.847,-18.0001 192.847,-18.0001 192.847,-18.0001 196.347,-18 192.847,-14.8501 199.847,-18 199.847,-18\"/>\n",
"<text text-anchor=\"start\" x=\"171\" y=\"-21.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\"><title>3</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"297\" cy=\"-48\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"297\" y=\"-44.3\" font-family=\"Lato\" font-size=\"14.00\">3</text>\n",
"</g>\n",
"<!-- 2&#45;&gt;3 -->\n",
"<g id=\"edge4\" class=\"edge\"><title>2&#45;&gt;3</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M234.954,-24.216C246.105,-28.5603 261.15,-34.4223 273.515,-39.2395\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"280.066,-41.7919 272.4,-42.1858 276.805,-40.5213 273.544,-39.2507 273.544,-39.2507 273.544,-39.2507 276.805,-40.5213 274.687,-36.3156 280.066,-41.7919 280.066,-41.7919\"/>\n",
"<text text-anchor=\"start\" x=\"254\" y=\"-36.8\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node6\" class=\"node\"><title>4</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"black\" cx=\"380\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"380\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\">4</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;4 -->\n",
"<g id=\"edge5\" class=\"edge\"><title>3&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M314.003,-42.073C326.017,-37.6233 342.638,-31.4675 356.064,-26.4947\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"362.753,-24.0174 357.283,-29.4026 359.471,-25.233 356.189,-26.4487 356.189,-26.4487 356.189,-26.4487 359.471,-25.233 355.095,-23.4948 362.753,-24.0174 362.753,-24.0174\"/>\n",
"<text text-anchor=\"start\" x=\"333\" y=\"-37.8\" font-family=\"Lato\" font-size=\"14.00\">!a</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;2 -->\n",
"<g id=\"edge6\" class=\"edge\"><title>4&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M362.276,-13.9842C349.433,-11.115 331.209,-7.50646 315,-6 299.069,-4.51934 294.922,-4.4234 279,-6 266.86,-7.20214 253.537,-9.74069 242.536,-12.1747\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"235.677,-13.744 241.798,-9.11188 239.089,-12.9632 242.501,-12.1825 242.501,-12.1825 242.501,-12.1825 239.089,-12.9632 243.204,-15.2532 235.677,-13.744 235.677,-13.744\"/>\n",
"<text text-anchor=\"start\" x=\"293.5\" y=\"-9.8\" font-family=\"Lato\" font-size=\"14.00\">a</text>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fb74c39d990> >"
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The rest of this page tests some syntax errors, you (humans) may skip it, but the test suite will not."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(spot.parse_word('a; b&!a; b'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "\n>>> a; b&!a; b\n ^\nA twa_word must contain a cycle\n (<string>)",
"output_type": "pyerr",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32munknown\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m \n>>> a; b&!a; b\n ^\nA twa_word must contain a cycle\n\n"
]
}
],
"prompt_number": 15
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(spot.parse_word('a; b; c}'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "\n>>> a; b; c}\n ^\nExpected ';' delimiter: '}' stands for ending a cycle\n (<string>)",
"output_type": "pyerr",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32munknown\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m \n>>> a; b; c}\n ^\nExpected ';' delimiter: '}' stands for ending a cycle\n\n"
]
}
],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(spot.parse_word('a; cycle{}'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "\n>>> a; cycle{}\n ^\nempty input\n\n (<string>)",
"output_type": "pyerr",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32munknown\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m \n>>> a; cycle{}\n ^\nempty input\n\n\n"
]
}
],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(spot.parse_word('a; cycle{!a}; a'))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "\n>>> a; cycle{!a}; a\n ^\nInput should be finished after cycle\n (<string>)",
"output_type": "pyerr",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<string>\"\u001b[0;36m, line \u001b[0;32munknown\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m \n>>> a; cycle{!a}; a\n ^\nInput should be finished after cycle\n\n"
]
}
],
"prompt_number": 18
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# Creating an empty word is OK...\n",
"w = spot.twa_word(spot._bdd_dict)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 19
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# ... as long as this word is not printed.\n",
"print(w)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"ename": "RuntimeError",
"evalue": "a twa_word may not have an empty cycle",
"output_type": "pyerr",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-20-9968db49e707>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# ... as long as this word is not printed.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mw\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m/home/adl/git/spot/python/spot/impl.py\u001b[0m in \u001b[0;36m__str__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 4922\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4923\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__str__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;34m\"std::string\"\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 4924\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0m_impl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtwa_word___str__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4925\u001b[0m \u001b[0mtwa_word_swigregister\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_impl\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtwa_word_swigregister\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4926\u001b[0m \u001b[0mtwa_word_swigregister\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtwa_word\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mRuntimeError\u001b[0m: a twa_word may not have an empty cycle"
]
}
],
"prompt_number": 20
}
],
"metadata": {}
}
]
}