Commit 60296317 authored by Alexandre Duret-Lutz's avatar Alexandre Duret-Lutz
Browse files

python: more conventional __repr__ for several types

* NEWS: Mention the change.
* python/spot/__init__.py: Add _repr_latex_ for twa_word, and
remove __repr__ and __str__ for atomic_prop_set.
* python/spot/impl.i: Implement __repr__ and __str__ for
atomic_prop_set.  Fix __repr__ for trival, acc_code, acc_cond,
mark_t.  Remove __repr__ for twa_run and twa_word.
* tests/python/acc_cond.ipynb, tests/python/accparse.ipynb,
tests/python/atva16-fig2a.ipynb, tests/python/automata.ipynb,
tests/python/bdditer.py, tests/python/contains.ipynb,
tests/python/gen.ipynb, tests/python/highlighting.ipynb,
tests/python/ltlsimple.py, tests/python/ltsmin-dve.ipynb,
tests/python/product.ipynb, tests/python/relabel.py,
tests/python/satmin.ipynb tests/python/stutter-inv.ipynb,
tests/python/word.ipynb: Adjust test cases.
* tests/python/formulas.ipynb: Add test for atomic_prop_set.
parent c3b7a691
Pipeline #4512 passed with stages
in 143 minutes and 32 seconds
......@@ -82,6 +82,22 @@ New in spot 2.6.3.dev (not yet released)
vector_rs_pairs) by acc_cond::is_rabin_like() and
acc_cond::is_streett_like() were not usable in Python.
- Many object types had __repr__() methods that would return the
same string as __str__(), contrary to Python usage where repr(x)
should try to show how to rebuild x. The following types have
been changed to follow this convention:
spot.acc_code
spot.acc_cond
spot.atomic_prop_set
spot.formula
spot.mark_t
spot.twa_run (__repr__ shows type and address)
spot.twa_word (likewise, but _repr_latex_ used in notebooks)
Note that this you were relying on the fact that Jupyter calls
repr() to display returned values, you may want to call print()
explicitely if you prefer the old representation.
New in spot 2.6.3 (2018-10-17)
Bugs fixed:
......
......@@ -352,19 +352,6 @@ class formula:
@_extend(atomic_prop_set)
class atomic_prop_set:
def __repr__(self):
res = '{'
comma = ''
for ap in self:
res += comma
comma = ', '
res += '"' + ap.ap_name() + '"'
res += '}'
return res
def __str__(self):
return self.__repr__()
def _repr_latex_(self):
res = '$\{'
comma = ''
......@@ -1147,6 +1134,22 @@ formula.show_mp_hierarchy = show_mp_hierarchy
@_extend(twa_word)
class twa_word:
def _repr_latex_(self):
bd = self.get_dict()
res = '$'
for idx, letter in enumerate(self.prefix):
if idx:
res += '; '
res += bdd_to_formula(letter, bd).to_str('j')
if len(res) > 1:
res += '; ';
res += '\\mathsf{cycle}\\{';
for idx, letter in enumerate(self.cycle):
if idx:
res += '; '
res += bdd_to_formula(letter, bd).to_str('j')
return res + '\\}$'
def as_svg(self):
"""
Build an SVG picture representing the word as a collection of
......
......@@ -669,13 +669,42 @@ def state_is_accepting(self, src) -> "bool":
%include <spot/taalgos/stats.hh>
%include <spot/taalgos/minimize.hh>
%extend std::set<spot::formula> {
std::string __str__()
{
std::ostringstream os;
os << '{';
const char* sep = "";
for (spot::formula s: *self)
{
os << sep << '"' << spot::escape_str(spot::str_psl(s)) << '"';
sep = ", ";
}
os << '}';
return os.str();
}
std::string __repr__()
{
std::ostringstream os;
os << "spot.atomic_prop_set([";
const char* sep = "";
for (spot::formula s: *self)
{
os << sep
<< "spot.formula(\"" << spot::escape_str(spot::str_psl(s)) << "\")";
sep = ", ";
}
os << "])";
return os.str();
}
}
%extend spot::acc_cond::rs_pair {
std::string __repr__()
{
std::ostringstream os;
os << "spot.rs_pair(fin=[";
char* sep = "";
const char* sep = "";
for (unsigned s: self->fin.sets())
{
os << sep << s;
......@@ -696,9 +725,11 @@ def state_is_accepting(self, src) -> "bool":
%extend spot::trival {
std::string __repr__()
{
std::ostringstream os;
os << *self;
return os.str();
if (self->is_true())
return "spot.trival(True)";
if (self->is_false())
return "spot.trival(False)";
return "spot.trival_maybe()";
}
std::string __str__()
......@@ -752,7 +783,9 @@ def state_is_accepting(self, src) -> "bool":
unsigned __len__() { return self->size(); }
formula __getitem__(unsigned pos) { return (*self)[pos]; }
std::string __repr__() { return spot::str_psl(*self); }
std::string __repr__() {
return "spot.formula(\"" + spot::escape_str(spot::str_psl(*self)) + "\")";
}
std::string __str__() { return spot::str_psl(*self); }
}
......@@ -929,7 +962,7 @@ def state_is_accepting(self, src) -> "bool":
std::string __repr__()
{
std::ostringstream os;
os << *self;
os << "spot.acc_code(\"" << *self << "\")";
return os.str();
}
......@@ -951,7 +984,14 @@ def state_is_accepting(self, src) -> "bool":
std::string __repr__()
{
std::ostringstream os;
os << *self;
os << "spot.mark_t([";
const char* sep = "";
for (unsigned s: self->sets())
{
os << sep << s;
sep = ", ";
}
os << "])";
return os.str();
}
......@@ -967,7 +1007,8 @@ def state_is_accepting(self, src) -> "bool":
std::string __repr__()
{
std::ostringstream os;
os << *self;
os << "spot.acc_cond(" << self->num_sets() << ", \""
<< self->get_acceptance() << "\")";
return os.str();
}
......@@ -980,13 +1021,6 @@ def state_is_accepting(self, src) -> "bool":
}
%extend spot::twa_run {
std::string __repr__()
{
std::ostringstream os;
os << *self;
return os.str();
}
std::string __str__()
{
std::ostringstream os;
......@@ -996,13 +1030,6 @@ def state_is_accepting(self, src) -> "bool":
}
%extend spot::twa_word {
std::string __repr__()
{
std::ostringstream os;
os << *self;
return os.str();
}
std::string __str__()
{
std::ostringstream os;
......
This diff is collapsed.
......@@ -6,37 +6,25 @@
"metadata": {},
"outputs": [],
"source": [
"import spot\n",
"spot.setup()"
 
 
},
{
},
{
"cell_type": "code",
"execution_count": 2,
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
"outputs": [
{
"name": "stdout",
"text/plain": [
"(Inf(0) & Fin(1)) | (Inf(2) & Fin(3))"
]
},
"output_type": "stream",
"text": [
"(Inf(0) & Fin(1)) | (Inf(2) & Fin(3))\n"
}
 
}
],
"c = spot.acc_code('Inf(0)&Fin(1)|Inf(2)&Fin(3)'); c"
]
},
{
"source": [
"c = spot.acc_code('Inf(0)&Fin(1)|Inf(2)&Fin(3)'); print(c)"
]
},
{
......@@ -50,11 +38,5 @@
"text": [
"(Fin(1) & Inf(0)) | (Fin(3) & Inf(2))\n"
]
}
],
"source": [
"c.to_dnf()"
]
},
{
"cell_type": "code",
......
......@@ -16,22 +16,22 @@
"import spot\n",
"spot.setup(show_default='.b')"
]
},
{
"cell_type": "code",
 
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\mathsf{G} \\mathsf{F} a \\leftrightarrow \\mathsf{G} \\mathsf{F} b$"
],
"text/plain": [
"spot.formula(\"GFa <-> GFb\")"
 
 
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
......
......@@ -7,22 +7,22 @@
"outputs": [],
"source": [
"from IPython.display import display\n",
"import spot\n",
"from spot.jupyter import display_inline\n",
"spot.setup()"
 
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To build an automaton from an LTL formula, simply call `translate()` with a formula, and a list of options to characterize the automaton you want (those options have the same name as the long options name of the `ltl2tgba` tool, and they can be abbreviated)."
]
},
{
 
 
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
......@@ -63,33 +63,33 @@
"<title>1</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"192\" cy=\"-214\" rx=\"18\" ry=\"18\"/>\n",
"<ellipse fill=\"none\" stroke=\"#000000\" cx=\"192\" cy=\"-214\" rx=\"22\" ry=\"22\"/>\n",
"<text text-anchor=\"middle\" x=\"192\" y=\"-210.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;1 -->\n",
"<!-- 0&#45;&gt;1 -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>0&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M67.8332,-133.9421C74.4899,-141.3052 83.2108,-150.1986 92,-157 115.1023,-174.8774 144.4269,-190.9236 165.335,-201.4008\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"171.8091,-204.602 164.138,-204.3229 168.6717,-203.0506 165.5343,-201.4993 165.5343,-201.4993 165.5343,-201.4993 168.6717,-203.0506 166.9305,-198.6756 171.8091,-204.602 171.8091,-204.602\"/>\n",
"<text text-anchor=\"start\" x=\"92\" y=\"-196.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">b &amp; c &amp; d</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>2</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"332.5\" cy=\"-157\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"332.5\" y=\"-153.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"<text text-anchor=\"middle\" x=\"332.5\" y=\"-153.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">2</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;2 -->\n",
"<g id=\"edge4\" class=\"edge\">\n",
"<title>0&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M74.1419,-122.4277C122.1062,-128.846 252.3489,-146.2745 307.3984,-153.641\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"314.6507,-154.6115 307.2947,-156.8051 311.1816,-154.1472 307.7126,-153.683 307.7126,-153.683 307.7126,-153.683 311.1816,-154.1472 308.1304,-150.5608 314.6507,-154.6115 314.6507,-154.6115\"/>\n",
"<text text-anchor=\"start\" x=\"172.5\" y=\"-143.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">b &amp; !d</text>\n",
"</g>\n",
"<!-- 3 -->\n",
"<g id=\"node5\" class=\"node\">\n",
 
 
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"442\" cy=\"-222\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"442\" y=\"-218.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">3</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;3 -->\n",
"<g id=\"edge5\" class=\"edge\">\n",
......@@ -100,11 +100,11 @@
"</g>\n",
"<!-- 4 -->\n",
"<g id=\"node6\" class=\"node\">\n",
"<title>4</title>\n",
"<ellipse fill=\"#ffffaa\" stroke=\"#000000\" cx=\"192\" cy=\"-18\" rx=\"18\" ry=\"18\"/>\n",
"<text text-anchor=\"middle\" x=\"192\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">4</text>\n",
"<text text-anchor=\"middle\" x=\"192\" y=\"-14.3\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">4</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;4 -->\n",
"<g id=\"edge6\" class=\"edge\">\n",
"<title>0&#45;&gt;4</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M64.323,-103.8495C70.7091,-92.6794 80.387,-78.0719 92,-68 114.626,-48.3765 146.3062,-34.244 167.9061,-26.1124\"/>\n",
......@@ -115,11 +115,11 @@
"<g id=\"edge7\" class=\"edge\">\n",
"<title>1&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M179.6953,-232.5156C176.9609,-243.5833 181.0625,-254 192,-254 200.5449,-254 204.9175,-247.6422 205.1178,-239.5831\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"204.3047,-232.5156 208.2342,-239.1097 204.7048,-235.9927 205.1048,-239.4698 205.1048,-239.4698 205.1048,-239.4698 204.7048,-235.9927 201.9755,-239.8298 204.3047,-232.5156 204.3047,-232.5156\"/>\n",
"<text text-anchor=\"start\" x=\"175\" y=\"-257.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">c &amp; d</text>\n",
"</g>\n",
 
"<!-- 1&#45;&gt;2 -->\n",
"<g id=\"edge8\" class=\"edge\">\n",
"<title>1&#45;&gt;2</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M214.3062,-212.8263C236.2237,-210.8821 270.0602,-205.7177 296,-192 303.3681,-188.1035 310.2911,-182.2836 316.0858,-176.5026\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"321.0707,-171.2608 318.5294,-178.5041 318.6587,-173.7971 316.2468,-176.3333 316.2468,-176.3333 316.2468,-176.3333 318.6587,-173.7971 313.9641,-174.1626 321.0707,-171.2608 321.0707,-171.2608\"/>\n",
......@@ -152,11 +152,11 @@
"<path fill=\"none\" stroke=\"#000000\" d=\"M348.1887,-166.3129C367.0531,-177.511 398.8271,-196.3722 420.1011,-209.0007\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"426.3404,-212.7044 418.7131,-211.8399 423.3307,-210.9178 420.321,-209.1312 420.321,-209.1312 420.321,-209.1312 423.3307,-210.9178 421.929,-206.4225 426.3404,-212.7044 426.3404,-212.7044\"/>\n",
"<text text-anchor=\"start\" x=\"369\" y=\"-202.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!c &amp; d</text>\n",
"</g>\n",
"<!-- 3&#45;&gt;1 -->\n",
 
 
"<title>3&#45;&gt;1</title>\n",
"<path fill=\"none\" stroke=\"#000000\" d=\"M424.1149,-225.1201C387.6378,-230.9319 302.1713,-241.7245 232,-229 227.7924,-228.237 223.4512,-227.0569 219.2499,-225.6861\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"212.3598,-223.2394 220.0103,-222.6135 215.658,-224.4107 218.9562,-225.5819 218.9562,-225.5819 218.9562,-225.5819 215.658,-224.4107 217.9021,-228.5503 212.3598,-223.2394 212.3598,-223.2394\"/>\n",
"<text text-anchor=\"start\" x=\"329\" y=\"-237.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">c</text>\n",
"</g>\n",
......@@ -167,11 +167,11 @@
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"451.2326,-237.5414 455.2286,-244.0955 451.6678,-241.0143 452.103,-244.4871 452.103,-244.4871 452.103,-244.4871 451.6678,-241.0143 448.9775,-244.8788 451.2326,-237.5414 451.2326,-237.5414\"/>\n",
"<text text-anchor=\"start\" x=\"436.5\" y=\"-261.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">!c</text>\n",
"</g>\n",
"<!-- 4&#45;&gt;4 -->\n",
"<g id=\"edge15\" class=\"edge\">\n",
 
 
"<path fill=\"none\" stroke=\"#000000\" d=\"M180.5701,-32.0417C176.2955,-42.9126 180.1055,-54 192,-54 201.2926,-54 205.6508,-47.2328 205.0745,-39.0885\"/>\n",
"<polygon fill=\"#000000\" stroke=\"#000000\" points=\"203.4299,-32.0417 208.0885,-38.1426 204.2254,-35.4502 205.0209,-38.8586 205.0209,-38.8586 205.0209,-38.8586 204.2254,-35.4502 201.9534,-39.5745 203.4299,-32.0417 203.4299,-32.0417\"/>\n",
"<text text-anchor=\"middle\" x=\"192\" y=\"-57.8\" font-family=\"Lato\" font-size=\"14.00\" fill=\"#000000\">1</text>\n",
"</g>\n",
"</g>\n",
......@@ -183,11 +183,11 @@
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
 
 
"source": [
"a = spot.translate('(a U b) & GFc & GFd', 'BA', 'complete'); a"
]
},
{
......@@ -270,22 +270,22 @@
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"253.7254\" y=\"-144.8\">b &amp; !c &amp; d</text>\n",
"</g>\n",
"<!-- 4 -->\n",
"<g class=\"node\" id=\"node6\">\n",
"<title>4</title>\n",
"<ellipse cx=\"289.7254\" cy=\"-196\" fill=\"none\" rx=\"18\" ry=\"18\" stroke=\"#000000\"/>\n",
"<ellipse cx=\"289.7254\" cy=\"-196\" fill=\"none\" rx=\"18\" ry=\"18\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"289.7254\" y=\"-192.3\">4</text>\n",
"</g>\n",
"<!-- 0&#45;&gt;4 -->\n",
"<g class=\"edge\" id=\"edge6\">\n",
"<title>0-&gt;4</title>\n",
"<path d=\"M226.3722,-277.3069C236.1719,-270.7149 248.6225,-261.3359 257.7254,-251 266.1904,-241.3884 273.5514,-229.202 279.0721,-218.7444\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"282.2652,-212.4949 281.8853,-220.1616 280.6727,-215.6117 279.0803,-218.7284 279.0803,-218.7284 279.0803,-218.7284 280.6727,-215.6117 276.2752,-217.2952 282.2652,-212.4949 282.2652,-212.4949\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"288.2254\" y=\"-239.8\">!a &amp; !b</text>\n",
"</g>\n",
"<!-- 1&#45;&gt;1 -->\n",
 
 
"<title>1-&gt;1</title>\n",
"<path d=\"M91.3062,-204.3702C101.5701,-205.5284 110.7254,-202.7383 110.7254,-196 110.7254,-190.9463 105.5756,-188.1134 98.6706,-187.5015\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"91.3062,-187.6298 98.2502,-184.3582 94.8057,-187.5688 98.3052,-187.5077 98.3052,-187.5077 98.3052,-187.5077 94.8057,-187.5688 98.3601,-190.6573 91.3062,-187.6298 91.3062,-187.6298\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"126.7254\" y=\"-192.3\">c &amp; d</text>\n",
"</g>\n",
......@@ -341,11 +341,11 @@
"<!-- 4&#45;&gt;4 -->\n",
"<g class=\"edge\" id=\"edge15\">\n",
"<title>4-&gt;4</title>\n",
"<path d=\"M306.0157,-204.0164C316.1146,-205.9495 325.7254,-203.2773 325.7254,-196 325.7254,-190.542 320.3193,-187.6744 313.3558,-187.3972\" fill=\"none\" stroke=\"#000000\"/>\n",
"<polygon fill=\"#000000\" points=\"306.0157,-187.9836 312.7426,-184.2861 309.5046,-187.7048 312.9935,-187.4261 312.9935,-187.4261 312.9935,-187.4261 309.5046,-187.7048 313.2443,-190.5661 306.0157,-187.9836 306.0157,-187.9836\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"329.2254\" y=\"-192.3\">1</text>\n",
"<text fill=\"#000000\" font-family=\"Times,serif\" font-size=\"14.00\" text-anchor=\"middle\" x=\"329.2254\" y=\"-192.3\">1</text>\n",
"</g>\n",
"</g>\n",
"</svg>"
],
"text/plain": [
......@@ -356,11 +356,11 @@
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
 
 
]
},
{
"cell_type": "markdown",
"metadata": {},
......@@ -386,11 +386,11 @@
"<g class=\"cluster\" id=\"clust1\">\n",
"<title>cluster_0</title>\n",
"<polygon fill=\"none\" points=\"162,-171 162,-373 607,-373 607,-171 162,-171\" stroke=\"#00ff00\"/>\n",
"</g>\n",
"<g class=\"cluster\" id=\"clust2\">\n",
 
 
"<polygon fill=\"none\" points=\"162,-8 162,-93 214,-93 214,-8 162,-8\" stroke=\"#c0c0c0\"/>\n",
"</g>\n",
"<g class=\"cluster\" id=\"clust3\">\n",
"<title>cluster_2</title>\n",
"<polygon fill=\"none\" points=\"30,-106 30,-191 82,-191 82,-106 30,-106\" stroke=\"#ff0000\"/>\n",
......@@ -428,6 +428,6 @@
"<polygon fill=\"#000000\" points=\"174.2193,-236.3036 166.8485,-234.1602 171.5556,-234.0332 168.8918,-231.7628 168.8918,-231.7628 168.8918,-231.7628 171.5556,-234.0332 170.9352,-229.3654 174.2193,-236.3036 174.2193,-236.3036\" stroke=\"#000000\"/>\n",
"<text fill=\"#000000\" font-family=\"Lato\" font-size=\"14.00\" text-anchor=\"start\" x=\"92\" y=\"-219.8\">b &amp; c &amp; d</text>\n",
"</g>\n",
"<!-- 2 -->\n",
"<g class=\"node\" id=\"node4\">\n",
 
 
......
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2017 Laboratoire de Recherche et Développement de l'Epita
# Copyright (C) 2017, 2018 Laboratoire de Recherche et Développement de l'Epita
# (LRDE).
#
# This file is part of Spot, a model checking library.
......@@ -44,8 +44,8 @@ assert res == [0, -1]
res2 = []
for i in run.aut.ap():
res2.append((i, run.aut.register_ap(i)))
assert str(res2) == '[(a, 0), (b, 1)]'
res2.append((str(i), run.aut.register_ap(i)))
assert str(res2) == "[('a', 0), ('b', 1)]"
f = spot.bdd_to_formula(b)
......
......@@ -175,11 +175,12 @@
],
"source": [
"aut_f.contains(\"FGa\"), aut_g.contains(\"GFa\")"
]
},
{
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Equivalence checks\n",
"\n",
"The `spot.are_equivalent()` tests the equivalence of the languages of its two arguments. Note that the corresponding method is called `equivalent_to()`."
......
......@@ -5,10 +5,11 @@
"metadata": {},
"source": [
"Handling LTL and PSL formulas\n",
"============================="
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
......@@ -21,22 +22,22 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For interactive use, formulas can be entered as text strings and passed to the `spot.formula` constructor."
]
},
 
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$p_{1} \\mathbin{\\mathsf{U}} (p_{2} \\mathbin{\\mathsf{R}} (p_{3} \\land \\lnot p_{4}))$"
],
"text/plain": [
 
"spot.formula(\"p1 U (p2 R (p3 & !p4))\")"
]
},
"execution_count": 2,
"metadata": {},
......@@ -47,11 +48,11 @@
"f = spot.formula('p1 U p2 R (p3 & !p4)')\n",
"f"
]
},
{
"cell_type": "code",
 
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
......@@ -62,11 +63,11 @@
"spot.formula(\"{a;b[*];c[+]}<>-> GFb\")"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
"output_type": "execute_result"
}
],
"source": [
"g = spot.formula('{a;b*;c[+]}<>->GFb'); g"
]
......@@ -187,33 +188,33 @@
}
],
"source": [
"for i in ['spot', 'spin', 'lbt', 'wring', 'utf8', 'latex', 'sclatex', 'mathjax']:\n",
" print(\"%-10s%s\" % (i, f.to_str(i)))"
]
 
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Formulas output via `format()` can also use some convenient shorthand to select the syntax:"
]
},
{
"cell_type": "code",
"execution_count": 8,
 
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Spin: p1 U (p2 V (p3 && !p4))\n",
"Spin+parentheses: (p1) U ((p2) V ((p3) && (!(p4))))\n",
"Spot (default): p1 U (p2 R (p3 & !p4))\n",
"Spot+shell quotes: 'p1 U (p2 R (p3 & !p4))'\n",
"LBT, right aligned: ~~~~~~~~~~~~~~~~~~~~~U p1 V p2 & p3 ! p4\n",
"LBT, right aligned: ~~~~~~~~~~~~~~~~~~~~~U p1 V p2 & p3 ! p4\n",
"LBT, no M/W/R: U p1 U & p3 ! p4 | & & p2 p3 ! p4 G & p3 ! p4\n"
]
}
],
"source": [
......@@ -260,11 +261,11 @@
" - '8': use Spot's syntax in UTF-8 mode\n",
" - 's': use Spin's syntax\n",
" - 'l': use LBT's syntax\n",
" - 'w': use Wring's syntax\n",
" - 'x': use LaTeX output\n",
" - 'X': use self-contained LaTeX output\n",
" - 'X': use self-contained LaTeX output\n",
" - 'j': use self-contained LaTeX output, adjusted for MathJax\n",
" \n",
" Add some of those letters for additional options:\n",
" \n",
" - 'p': use full parentheses\n",
......@@ -275,11 +276,11 @@
" - 'd': escape double quotes and backslash,\n",
" for use in C-strings (the outermost double\n",
" quotes are *not* added)\n",
" - 'q': quote and escape for shell output, using single\n",
" quotes or double quotes depending on the contents.\n",
" - '[...]': rewrite away all the operators specified in brackets,\n",
 
" using spot.unabbreviate().\n",
" \n",