Add support for computing operator nesting depth

* spot/tl/hierarchy.hh, spot/tl/hierarchy.cc (nesting_depth): New
function.
* python/spot/__init__.py: Also make it a method of formula in Python
* bin/common_output.cc, bin/common_output.hh: Implement
--stats=%[OP]n.
* NEWS: Mention it.
* tests/core/format.test, tests/python/formulas.ipynb: Test it.
This commit is contained in:
Alexandre Duret-Lutz 2017-12-10 20:22:40 +01:00
parent 49b76bcf66
commit 62d1e0219d
8 changed files with 218 additions and 25 deletions

View file

@ -15,7 +15,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.3rc1"
"version": "3.6.4rc1"
},
"name": ""
},
@ -636,7 +636,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 22,
"prompt_number": 18,
"svg": [
"<svg height=\"210\" version=\"1.1\" width=\"220\" xmlns=\"http://www.w3.org/2000/svg\">\n",
"<polygon fill=\"cyan\" opacity=\".2\" points=\"20,0 200,120 200,210 20,210\"/>\n",
@ -668,7 +668,7 @@
]
}
],
"prompt_number": 22
"prompt_number": 18
},
{
"cell_type": "code",
@ -682,13 +682,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 24,
"prompt_number": 19,
"text": [
"'recurrence'"
]
}
],
"prompt_number": 24
"prompt_number": 19
},
{
"cell_type": "code",
@ -705,13 +705,13 @@
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 18,
"prompt_number": 20,
"text": [
"F(a & X(!a & b))"
]
}
],
"prompt_number": 18
"prompt_number": 20
},
{
"cell_type": "markdown",
@ -735,13 +735,13 @@
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 19,
"prompt_number": 21,
"text": [
"F(a & ((a & (a U (!a & b)) & ((!b U !a) | (b U !a))) | (!a & (!a U (a & !a & b)) & ((!b U a) | (b U a))) | (b & (b U (!a & b & !b)) & ((!a U !b) | (a U !b))) | (!b & (!b U (!a & b)) & ((!a U b) | (a U b))) | (!a & b & (G!a | Ga) & (G!b | Gb))))"
]
}
],
"prompt_number": 19
"prompt_number": 21
},
{
"cell_type": "markdown",
@ -766,13 +766,13 @@
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 20,
"prompt_number": 22,
"text": [
"(0 R !(a <-> b)) -> (1 U (a <-> b))"
]
}
],
"prompt_number": 20
"prompt_number": 22
},
{
"cell_type": "code",
@ -789,13 +789,51 @@
],
"metadata": {},
"output_type": "pyout",
"prompt_number": 21,
"prompt_number": 23,
"text": [
"(1 U ((a & b) | (!a & !b))) | !(0 R ((!a & b) | (a & !b)))"
]
}
],
"prompt_number": 21
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Nesting level of operators"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"f = spot.formula('F(b & X(a U b U ((a W Fb) | (c U d))))')\n",
"print(\"U\", spot.nesting_depth(f, spot.op_U))\n",
"print(\"F\", spot.nesting_depth(f, spot.op_F))\n",
"# These following two are syntactic sugar for the above two\n",
"print(\"U\", spot.nesting_depth(f, \"U\"))\n",
"print(\"F\", spot.nesting_depth(f, \"F\"))\n",
"# If you want to consider \"U\" and \"F\" are a similar type of\n",
"# operator, you can count both with\n",
"print(\"FU\", spot.nesting_depth(f, \"FU\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"U 3\n",
"F 2\n",
"U 3\n",
"F 2\n",
"FU 4\n"
]
}
],
"prompt_number": 24
}
],
"metadata": {}