{ "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.5.3" }, "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Formulas & Automata generators\n", "\n", "The `spot.gen` package contains the functions used to generate the patterns produced by [`genltl`](https://spot.lrde.epita.fr/genltl.html) and [`genaut`](https://spot.lrde.epita.fr/genaut.html)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "import spot\n", "import spot.gen as sg\n", "spot.setup()\n", "from IPython.display import display" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 13 }, { "cell_type": "markdown", "metadata": {}, "source": [ "## LTL patterns\n", "\n", "Generation of LTL formulas is done via the `ltl_pattern()` function. This takes two arguments: a pattern id, and a pattern size (or index if the id refers to a list)." ] }, { "cell_type": "code", "collapsed": false, "input": [ "sg.ltl_pattern(sg.AND_GF, 3)" ], "language": "python", "metadata": {}, "outputs": [ { "latex": [ "$\\mathsf{G} \\mathsf{F} p_{1} \\land \\mathsf{G} \\mathsf{F} p_{2} \\land \\mathsf{G} \\mathsf{F} p_{3}$" ], "metadata": {}, "output_type": "pyout", "prompt_number": 14, "text": [ "GFp1 & GFp2 & GFp3" ] } ], "prompt_number": 14 }, { "cell_type": "code", "collapsed": false, "input": [ "sg.ltl_pattern(sg.CCJ_BETA_PRIME, 4)" ], "language": "python", "metadata": {}, "outputs": [ { "latex": [ "$\\mathsf{F} (p \\land \\mathsf{X} p \\land \\mathsf{X} \\mathsf{X} p \\land \\mathsf{X} \\mathsf{X} \\mathsf{X} p) \\land \\mathsf{F} (q \\land \\mathsf{X} q \\land \\mathsf{X} \\mathsf{X} q \\land \\mathsf{X} \\mathsf{X} \\mathsf{X} q)$" ], "metadata": {}, "output_type": "pyout", "prompt_number": 15, "text": [ "F(p & Xp & XXp & XXXp) & F(q & Xq & XXq & XXXq)" ] } ], "prompt_number": 15 }, { "cell_type": "markdown", "metadata": {}, "source": [ "To see the list of supported patterns, the easiest way is to look at the `--help` output of `genltl`. The above pattern for instance is attached to option `--ccj-beta-prime`. The name of the pattern identifier is the same using capital letters and underscores. If a pattern has multiple aliased options in `genltl`, the first one used for the identifier (e.g., `genltl` accept both `--dac-patterns` and `--spec-patterns` as synonyms to denote the patterns of `spot.gen.DAC_PATTERNS`).\n", "\n", "Multiple patterns can be generated using the `ltl_patterns()` function. It's arguments should be either can be:\n", " - pairs of the form `(id, n)`: in this case the pattern `id` with size/index `n` is returned,\n", " - triplets of the form `(id, min, max)`: in this case the patterns are output for all `n` between `min` and `max` included,\n", " - an integer `id`: then this is equivalent to `(id, 1, 10)` if the pattern has now upper bound, or `(id, 1, upper)` if the patter `id` has an upper bound `upper`. This is mostly used when the pattern id correspond to a hard-coded list of formulas.\n", "\n", "Here is an example showing these three types of arguments:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "for f in sg.ltl_patterns((sg.GH_R, 3), (sg.AND_FG, 1, 3), sg.EH_PATTERNS):\n", " display(f)" ], "language": "python", "metadata": { "scrolled": false }, "outputs": [ { "latex": [ "$(\\mathsf{G} \\mathsf{F} p_{1} \\lor \\mathsf{F} \\mathsf{G} p_{2}) \\land (\\mathsf{G} \\mathsf{F} p_{2} \\lor \\mathsf{F} \\mathsf{G} p_{3}) \\land (\\mathsf{G} \\mathsf{F} p_{3} \\lor \\mathsf{F} \\mathsf{G} p_{4})$" ], "metadata": {}, "output_type": "display_data", "text": [ "(GFp1 | FGp2) & (GFp2 | FGp3) & (GFp3 | FGp4)" ] }, { "latex": [ "$\\mathsf{F} \\mathsf{G} p_{1}$" ], "metadata": {}, "output_type": "display_data", "text": [ "FGp1" ] }, { "latex": [ "$\\mathsf{F} \\mathsf{G} p_{1} \\land \\mathsf{F} \\mathsf{G} p_{2}$" ], "metadata": {}, "output_type": "display_data", "text": [ "FGp1 & FGp2" ] }, { "latex": [ "$\\mathsf{F} \\mathsf{G} p_{1} \\land \\mathsf{F} \\mathsf{G} p_{2} \\land \\mathsf{F} \\mathsf{G} p_{3}$" ], "metadata": {}, "output_type": "display_data", "text": [ "FGp1 & FGp2 & FGp3" ] }, { "latex": [ "$p_{0} \\mathbin{\\mathsf{U}} (p_{1} \\land \\mathsf{G} p_{2})$" ], "metadata": {}, "output_type": "display_data", "text": [ "p0 U (p1 & Gp2)" ] }, { "latex": [ "$p_{0} \\mathbin{\\mathsf{U}} (p_{1} \\land \\mathsf{X} (p_{2} \\mathbin{\\mathsf{U}} p_{3}))$" ], "metadata": {}, "output_type": "display_data", "text": [ "p0 U (p1 & X(p2 U p3))" ] }, { "latex": [ "$p_{0} \\mathbin{\\mathsf{U}} (p_{1} \\land \\mathsf{X} (p_{2} \\land \\mathsf{F} (p_{3} \\land \\mathsf{X} \\mathsf{F} (p_{4} \\land \\mathsf{X} \\mathsf{F} (p_{5} \\land \\mathsf{X} \\mathsf{F} p_{6})))))$" ], "metadata": {}, "output_type": "display_data", "text": [ "p0 U (p1 & X(p2 & F(p3 & XF(p4 & XF(p5 & XFp6)))))" ] }, { "latex": [ "$\\mathsf{F} (p_{0} \\land \\mathsf{X} \\mathsf{G} p_{1})$" ], "metadata": {}, "output_type": "display_data", "text": [ "F(p0 & XGp1)" ] }, { "latex": [ "$\\mathsf{F} (p_{0} \\land \\mathsf{X} (p_{1} \\land \\mathsf{X} \\mathsf{F} p_{2}))$" ], "metadata": {}, "output_type": "display_data", "text": [ "F(p0 & X(p1 & XFp2))" ] }, { "latex": [ "$\\mathsf{F} (p_{0} \\land \\mathsf{X} (p_{1} \\mathbin{\\mathsf{U}} p_{2}))$" ], "metadata": {}, "output_type": "display_data", "text": [ "F(p0 & X(p1 U p2))" ] }, { "latex": [ "$\\mathsf{G} \\mathsf{F} p_{0} \\lor \\mathsf{F} \\mathsf{G} p_{1}$" ], "metadata": {}, "output_type": "display_data", "text": [ "GFp0 | FGp1" ] }, { "latex": [ "$\\mathsf{G} (p_{0} \\rightarrow (p_{1} \\mathbin{\\mathsf{U}} p_{2}))$" ], "metadata": {}, "output_type": "display_data", "text": [ "G(p0 -> (p1 U p2))" ] }, { "latex": [ "$\\mathsf{G} (p_{0} \\land \\mathsf{X} \\mathsf{F} (p_{1} \\land \\mathsf{X} \\mathsf{F} (p_{2} \\land \\mathsf{X} \\mathsf{F} p_{3})))$" ], "metadata": {}, "output_type": "display_data", "text": [ "G(p0 & XF(p1 & XF(p2 & XFp3)))" ] }, { "latex": [ "$\\mathsf{G} \\mathsf{F} p_{1} \\land \\mathsf{G} \\mathsf{F} p_{2} \\land \\mathsf{G} \\mathsf{F} p_{3} \\land \\mathsf{G} \\mathsf{F} p_{0} \\land \\mathsf{G} \\mathsf{F} p_{4}$" ], "metadata": {}, "output_type": "display_data", "text": [ "GFp1 & GFp2 & GFp3 & GFp0 & GFp4" ] }, { "latex": [ "$(p_{0} \\mathbin{\\mathsf{U}} (p_{1} \\mathbin{\\mathsf{U}} p_{2})) \\lor (p_{1} \\mathbin{\\mathsf{U}} (p_{2} \\mathbin{\\mathsf{U}} p_{0})) \\lor (p_{2} \\mathbin{\\mathsf{U}} (p_{0} \\mathbin{\\mathsf{U}} p_{1}))$" ], "metadata": {}, "output_type": "display_data", "text": [ "(p0 U (p1 U p2)) | (p1 U (p2 U p0)) | (p2 U (p0 U p1))" ] }, { "latex": [ "$\\mathsf{G} (p_{0} \\rightarrow (p_{1} \\mathbin{\\mathsf{U}} (\\mathsf{G} p_{2} \\lor \\mathsf{G} p_{3})))$" ], "metadata": {}, "output_type": "display_data", "text": [ "G(p0 -> (p1 U (Gp2 | Gp3)))" ] } ], "prompt_number": 20 }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Automata patterns\n", "\n", "We currently have only one generator of automata:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "sg.ks_cobuchi(3).show('.a')" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 23, "svg": [ "\n", "\n", "G\n", "\n", "Fin(\n", "\u24ff\n", ")\n", "\n", "\n", "0\n", "\n", "\n", "0\n", "\n", "\n", "I->0\n", "\n", "\n", "\n", "\n", "1\n", "\n", "1\n", "\n", "\n", "0->1\n", "\n", "\n", "1\n", "\n", "\n", "2\n", "\n", "2\n", "\n", "\n", "0->2\n", "\n", "\n", "1\n", "\n", "\n", "3\n", "\n", "3\n", "\n", "\n", "0->3\n", "\n", "\n", "1\n", "\n", "\n", "4\n", "\n", "4\n", "\n", "\n", "0->4\n", "\n", "\n", "1\n", "\n", "\n", "5\n", "\n", "5\n", "\n", "\n", "0->5\n", "\n", "\n", "1\n", "\n", "\n", "6\n", "\n", "6\n", "\n", "\n", "0->6\n", "\n", "\n", "1\n", "\n", "\n", "1->0\n", "\n", "\n", "!a & !b\n", "\n", "\n", "1->1\n", "\n", "\n", "a & b\n", "\n", "\n", "1->2\n", "\n", "\n", "(!a & b) | (a & !b)\n", "\n", "\n", "2->1\n", "\n", "\n", "!a & b\n", "\n", "\n", "2->2\n", "\n", "\n", "(!a & !b) | (a & b)\n", "\n", "\n", "2->3\n", "\n", "\n", "a & !b\n", "\n", "\n", "3->3\n", "\n", "\n", "!a | b\n", "\n", "\n", "3->4\n", "\n", "\n", "a & !b\n", "\n", "\n", "4->4\n", "\n", "\n", "!a | b\n", "\n", "\n", "4->5\n", "\n", "\n", "a & !b\n", "\n", "\n", "5->5\n", "\n", "\n", "!a | b\n", "\n", "\n", "5->6\n", "\n", "\n", "a & !b\n", "\n", "\n", "6->1\n", "\n", "\n", "a & !b\n", "\n", "\n", "6->6\n", "\n", "\n", "!a | b\n", "\n", "\n", "" ], "text": [ "" ] } ], "prompt_number": 23 }, { "cell_type": "code", "collapsed": true, "input": [], "language": "python", "metadata": {}, "outputs": [], "prompt_number": null } ], "metadata": {} } ] }