python: implicit str->formula conversion

* python/spot/impl.i, python/spot/__init__.py: Implement it.
* NEWS: Mention it.
* tests/python/atva16-fig2a.ipynb, tests/python/atva16-fig2b.ipynb,
tests/python/formulas.ipynb, tests/python/ltsmin-dve.ipynb,
tests/python/ltsmin-pml.ipynb, tests/python/stutter-inv.ipynb,
doc/org/tut02.org: Modernize.
This commit is contained in:
Alexandre Duret-Lutz 2018-05-15 16:07:14 +02:00
parent 5c1d9c492c
commit 6a808492c1
10 changed files with 168 additions and 210 deletions

View file

@ -7,7 +7,7 @@
"outputs": [],
"source": [
"import spot\n",
"spot.setup(show_default='.ban')\n",
"spot.setup(show_default='.bn')\n",
"from IPython.display import display"
]
},
@ -302,7 +302,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa2444ce810> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642b47b0> >"
]
},
"metadata": {},
@ -355,7 +355,7 @@
"def explain_stut(f):\n",
" f = spot.formula(f)\n",
" pos = spot.translate(f)\n",
" neg = spot.translate(spot.formula_Not(f))\n",
" neg = spot.translate(spot.formula.Not(f))\n",
" word = spot.product(spot.closure(pos), spot.closure(neg)).accepting_word()\n",
" if word is None:\n",
" print(f, \"is stutter invariant\")\n",
@ -428,7 +428,7 @@
"source": [
"f1 = spot.formula('F(a & X!a & XF(b & X!b & Ga))')\n",
"f2 = spot.formula('F(a & Xa & XXa & G!b)')\n",
"f = spot.formula_Or([f1, f2])\n",
"f = spot.formula.Or([f1, f2])\n",
"\n",
"print(spot.is_stutter_invariant(f1))\n",
"print(spot.is_stutter_invariant(f2))\n",
@ -595,7 +595,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa24445d270> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642c22d0> >"
]
},
"metadata": {},
@ -804,7 +804,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa24445d270> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642c22d0> >"
]
},
"metadata": {},
@ -845,7 +845,7 @@
"source": [
"g1 = spot.formula('GF(a & Xa) & GF!a')\n",
"g2 = spot.formula('!GF(a & Xa) & GF!a')\n",
"g = spot.formula_Or([g1, g2])"
"g = spot.formula.Or([g1, g2])"
]
},
{
@ -963,7 +963,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa2444ce8a0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642b4750> >"
]
},
"metadata": {},
@ -1062,7 +1062,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa24446e5d0> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642d26c0> >"
]
},
"metadata": {},
@ -1279,7 +1279,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa24446e660> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642d2720> >"
]
},
"metadata": {},
@ -1408,7 +1408,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa244d50270> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1643175a0> >"
]
},
"metadata": {},
@ -1539,7 +1539,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa24446eb70> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642d2ea0> >"
]
},
"metadata": {},
@ -1799,7 +1799,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa244480540> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642e62a0> >"
]
},
"metadata": {},
@ -1819,7 +1819,7 @@
"State: 6 [!0] 0\n",
"State: 7 [!0] 6 [0] 5\n",
"--END--\"\"\")\n",
"spot.highlight_stutter_invariant_states(ex1,None, 5)\n",
"spot.highlight_stutter_invariant_states(ex1, None, 5)\n",
"display(ex1)"
]
},
@ -2113,7 +2113,7 @@
"</svg>\n"
],
"text/plain": [
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fa244480540> >"
"<spot.impl.twa_graph; proxy of <Swig Object of type 'std::shared_ptr< spot::twa_graph > *' at 0x7fc1642e62a0> >"
]
},
"metadata": {},
@ -2189,69 +2189,69 @@
"output_type": "stream",
"text": [
"formula states SIstates fwd_closed\n",
"(p1 & X(!p0 U p2)) R !p0 3 2 1\n",
"(!p1 U (p0 | (!p1 & p2 & X(!p1 U p3)))) 4 3 1\n",
"!p0 | ((p2 & X(!p1 U p3)) R !p1) 4 2 1\n",
"G(!p0 | (!p2 U (p1 | (!p2 & p3 & X(!p2 U 4 1 1\n",
"G(!p0 | (!p1 W (p2 | (!p1 & p3 & X(!p1 U 3 0 1\n",
"(!p0 U p2) | G(!p0 | XG!p1) 3 2 1\n",
"G!p0 | ((p0 | !p1 | X(!p2 W p0)) U (p0 | 4 3 1\n",
"!p0 W (p0 & ((!p1 U p3) | G(!p1 | XG!p2) 4 2 1\n",
"G(!p0 | G!p1 | ((p1 | !p2 | X(!p3 W p1)) 4 1 1\n",
"G(!p0 | ((p1 | !p2 | X(!p3 W p1)) U (p1 3 0 1\n",
"G(!p0 | X(F(p1 & Fp2) | G!p1)) 6 1 1\n",
"G!p0 | ((!p1 | X((!p0 U (p2 & Fp3)) | (p 6 2 1\n",
"G(!p0 | G(!p1 | X(!p2 W (p2 & Fp3)))) 5 0 1\n",
"G(!p0 | G!p1 | ((!p2 | X((!p1 U (p3 & Fp 10 2 1\n",
"G(!p0 | ((!p1 | X((!p2 U (p3 & Fp4)) | ( 10 0 1\n",
"G(!p0 | F(p1 & XFp2)) 4 0 1\n",
"G!p0 | ((!p1 | ((p2 & X(!p0 U p3)) M !p0 4 1 1\n",
"G(!p0 | G(!p1 | (p2 & XFp3))) 3 3 1\n",
"G(!p0 | G!p1 | ((!p2 | ((p3 & X(!p1 U p4 4 0 1\n",
"G(!p0 | ((!p1 | ((p3 & X(!p2 U p4)) M !p 6 2 1\n",
"G(!p0 | F(p1 & !p2 & X(!p2 U p3))) 4 0 1\n",
"G!p0 | ((!p1 | ((p2 & !p3 & X((!p0 & !p3 4 1 1\n",
"G(!p0 | G(!p1 | (p2 & !p3 & X(!p3 U p4)) 3 3 1\n",
"G(!p0 | G!p1 | ((!p2 | ((p3 & !p4 & X((! 4 0 1\n",
"G(!p0 | ((!p1 | ((p3 & !p4 & X((!p2 & !p 6 2 1\n",
"Fp0 -> (!p0 U (!p0 & p1 & X(!p0 U p2))) 3 2 1\n",
"Fp0 -> (!p1 U (p0 | (!p1 & p2 & X(!p1 U 4 3 1\n",
"G!p0 | (!p0 U ((p0 & Fp1) -> (!p1 U (!p1 4 2 1\n",
"G((p0 & Fp1) -> (!p2 U (p1 | (!p2 & p3 & 4 1 1\n",
"G(p0 -> (Fp1 -> (!p1 U (p2 | (!p1 & p3 & 3 0 1\n",
"F(p0 & XFp1) -> (!p0 U p2) 3 2 1\n",
"Fp0 -> (!(!p0 & p1 & X(!p0 U (!p0 & p2)) 4 3 1\n",
"G!p0 | (!p0 U (p0 & (F(p1 & XFp2) -> (!p 4 2 1\n",
"G((p0 & Fp1) -> (!(!p1 & p2 & X(!p1 U (! 4 1 1\n",
"G(p0 -> ((!(!p1 & p2 & X(!p1 U (!p1 & p3 3 0 1\n",
"G((p0 & XFp1) -> XF(p1 & Fp2)) 6 1 1\n",
"Fp0 -> (((p1 & X(!p0 U p2)) -> X(!p0 U ( 6 2 1\n",
"G(p0 -> G((p1 & XFp2) -> X(!p2 U (p2 & F 5 0 1\n",
"G((p0 & Fp1) -> (((p2 & X(!p1 U p3)) -> 10 2 1\n",
"G(p0 -> (((p1 & X(!p2 U p3)) -> X(!p2 U 10 0 1\n",
"G(p0 -> F(p1 & XFp2)) 4 0 1\n",
"Fp0 -> ((p1 -> (!p0 U (!p0 & p2 & X(!p0 4 1 1\n",
"G(p0 -> G(p1 -> (p2 & XFp3))) 3 3 1\n",
"G((p0 & Fp1) -> ((p2 -> (!p1 U (!p1 & p3 4 0 1\n",
"G(p0 -> ((p1 -> (!p2 U (!p2 & p3 & X(!p2 6 2 1\n",
"G(p0 -> F(p1 & !p2 & X(!p2 U p3))) 4 0 1\n",
"Fp0 -> ((p1 -> (!p0 U (!p0 & p2 & !p3 & 4 1 1\n",
"G(p0 -> G(p1 -> (p2 & !p3 & X(!p3 U p4)) 3 3 1\n",
"G((p0 & Fp1) -> ((p2 -> (!p1 U (!p1 & p3 4 0 1\n",
"G(p0 -> ((p1 -> (!p2 U (!p2 & p3 & !p4 & 6 2 1\n",
"p0 U (p1 & X(p2 U p3)) 3 2 1\n",
"p0 U (p1 & X(p2 & F(p3 & XF(p4 & XF(p5 & 7 2 1\n",
"F(p0 & XGp1) 2 2 1\n",
"F(p0 & X(p1 & XFp2)) 4 2 1\n",
"F(p0 & X(p1 U p2)) 3 1 1\n",
"G(p0 & Fp1 & Fp2 & Fp3) 1 1 1\n",
"GF((!p0 & Xp0) | (p0 & X!p0) | (!p1 & Xp 4 4 1\n",
"GF((!p0 & Xp0) | (p0 & X!p0) | (!p1 & Xp 9 9 1\n",
"G(!p0 | !p1 | p2 | X(!p2 | p3 | X(!p1 | 3 0 1\n",
"G(!p0 | !p1 | p2 | X(!p2 | (p2 U (!p2 U 5 5 1\n",
"1 1 1 1\n",
"G(p0 | !p1 | Xp2) 2 0 1\n",
"G(!p0 | X(p0 | p1)) 2 2 1\n",
"G((((p1 & Xp1) | (!p1 & X!p1)) & ((p0 & 34 34 1\n",
"G(!p0 | p1 | !p2 | X(!p0 | !p1 | p3)) 2 2 1\n",
"G(!p0 | X(!p0 U p1)) 2 0 1\n",
"G(p0 | X(!p0 | (p0 W p1))) 3 3 1\n",
"G(p0 | X(!p0 | ((!p1 & X(p0 & p1)) M p0) 4 4 1\n",
"G(p0 | X(!p0 | ((!p1 & X(p1 & ((!p1 & X( 6 6 1\n",
"G(!p0 | X(p0 | ((!p1 & X(p1 & ((!p1 & X( 6 6 1\n",
"G(!p0 | X(p0 | ((!p1 & X(p1 & ((!p1 & X( 8 8 1\n",
"G(p0 | X(!p0 | ((p0 | X!p0) U (!p1 & Xp1 6 6 1\n",
"G(p0 & XF(p1 & XF(p2 & XFp3))) 1 1 1\n",
"GF(!(p1 <-> Xp1) | !(p0 <-> Xp0)) 4 4 1\n",
"GF(!(p1 <-> Xp1) | !(p0 <-> Xp0) | !(p2 9 9 1\n",
"G((p0 & p1 & !p2 & Xp2) -> X(p3 | X(!p1 3 0 1\n",
"G((p0 & p1 & !p2 & Xp2) -> X(X!p1 | (p2 5 5 1\n",
"G(p0 & p1 & !p2 & Xp2) -> X(X!p1 | (p2 U 1 1 1\n",
"G((!p0 & p1) -> Xp2) 2 0 1\n",
"G(p0 -> X(p0 | p1)) 2 2 1\n",
"G((!(p1 <-> Xp1) | !(p0 <-> Xp0) | !(p2 34 34 1\n",
"G((p0 & !p1 & Xp1 & Xp0) -> (p2 -> Xp3)) 2 2 1\n",
"G(p0 -> X(!p0 U p1)) 2 0 1\n",
"G((!p0 & Xp0) -> X((p0 U p1) | Gp0)) 3 3 1\n",
"G((!p0 & Xp0) -> X(p0 U (p0 & !p1 & X(p0 4 4 1\n",
"G((!p0 & Xp0) -> X(p0 U (p0 & !p1 & X(p0 6 6 1\n",
"G((p0 & X!p0) -> X(!p0 U (!p0 & !p1 & X( 6 6 1\n",
"G((p0 & X!p0) -> X(!p0 U (!p0 & !p1 & X( 8 8 1\n",
"G((!p0 & Xp0) -> X(!(!p0 & Xp0) U (!p1 & 6 6 1\n",
"G(!p0 | X(!p0 | X(!p0 | X(!p0 | X(!p0 | 12 0 1\n",
"G((!p0 & Xp0) | (p1 & Xp1) | (!p1 & X!p1 4 4 1\n",
"G((!p0 & Xp0) | ((!p1 | Xp1) & (p1 | X!p 4 4 1\n",
"G((Xp0 -> p0) -> (p1 <-> Xp1)) 4 4 1\n",
"G((Xp0 -> p0) -> ((p1 -> Xp1) & (!p1 -> 4 4 1\n",
"p0 & XG!p0 2 1 1\n",
"XG(!p0 | p2 | G!p1 | X(p2 M !p1)) 4 1 1\n",
"XG(!p0 | p1 | (!p1 W p2)) 3 2 1\n",
"XG(!p0 | !p1 | (p1 W p2)) 3 2 1\n",
"Xp0 & G(p0 | X(!p0 | Xp0)) 5 0 1\n",
"1 1 1 1\n",
"1 1 1 1\n",
"G(!p0 | Fp1) 2 2 1\n",
"G(!p0 | Fp1) 2 2 1\n",
"F(p0 & X(!p1 U !p2)) 3 1 1\n",
"(p0 & Xp1) R X(p2 R p0) 5 3 1\n",
"G((p0 | XGp1) & (p2 | XG!p1)) 3 2 1\n",
"Gp0 1 1 1\n"
"XG(p0 -> (G!p1 | (!Xp1 U p2))) 4 1 1\n",
"XG((p0 & !p1) -> (G!p1 | (!p1 U p2))) 3 2 1\n",
"XG((p0 & p1) -> (Gp1 | (p1 U p2))) 3 2 1\n",
"Xp0 & G((!p0 & Xp0) -> XXp0) 5 0 1\n",
"(Xp0 U Xp1) | !X(p0 U p1) 1 1 1\n",
"(Xp0 U p1) | !X(p0 U (p0 & p1)) 1 1 1\n",
"((Xp0 U p1) | !X(p0 U (p0 & p1))) & G(p0 2 2 1\n",
"((Xp0 U Xp1) | !X(p0 U p1)) & G(p0 -> Fp 2 2 1\n",
"!G(p0 -> X(p1 R p2)) 3 1 1\n",
"(p0 & Xp1) R X(((p2 U p3) R p0) U (p2 R 5 3 1\n",
"G(p0 | XGp1) & G(p2 | XG!p1) 3 2 1\n",
"G(p0 | (Xp1 & X!p1)) 1 1 1\n"
]
}
],
@ -2272,6 +2272,7 @@
"fmt = \"{:40.40} {:>6} {:>8} {:>10}\"\n",
"print(fmt.format(\"formula\", \"states\", \"SIstates\", \"fwd_closed\"))\n",
"for f in formulas:\n",
" s = f.to_str()\n",
" aut = spot.translate(f)\n",
" aut_size.append(aut.num_states())\n",
" sistates = spot.stutter_invariant_states(aut, f)\n",
@ -2279,7 +2280,7 @@
" sistates_size.append(sisz)\n",
" fc = spot.is_stutter_invariant_forward_closed(aut, sistates) == -1\n",
" fwd_closed.append(fc)\n",
" print(fmt.format(f.to_str(), aut.num_states(), sisz, fc))"
" print(fmt.format(s, aut.num_states(), sisz, fc))"
]
},
{
@ -2335,6 +2336,13 @@
"source": [
"100*sum(sistates_size)/sum(aut_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {