rename is_deterministic to is_universal
For #212. * spot/twa/twa.hh: Rename prop_deterministic() as prop_universal(), and keep the old name as deprecated. * spot/twaalgos/isdet.cc, spot/twaalgos/isdet.hh: Rename is_deterministic() as is_universal(), and add a new function for is_deterministic(). * doc/org/concepts.org, doc/org/hoa.org, doc/org/tut21.org, spot/tl/hierarchy.cc, spot/twa/twagraph.cc, spot/twaalgos/are_isomorphic.cc, spot/twaalgos/determinize.cc, spot/twaalgos/dtbasat.cc, spot/twaalgos/dtwasat.cc, spot/twaalgos/hoa.cc, spot/twaalgos/minimize.cc, spot/twaalgos/postproc.cc, spot/twaalgos/product.cc, spot/twaalgos/randomgraph.cc, spot/twaalgos/remfin.cc, spot/twaalgos/simulation.cc, spot/twaalgos/totgba.cc, spot/twaalgos/word.cc, tests/python/product.ipynb, tests/python/remfin.py: Adjust. * NEWS: Mention the change.
This commit is contained in:
parent
4518724a5b
commit
4a5d7a3978
24 changed files with 181 additions and 180 deletions
|
|
@ -1524,23 +1524,23 @@
|
|||
"\n",
|
||||
"We could stop with the previous function: the result is a correct product from a theoretical point of view. However our function is still inferior to `spot.product()` in a couple of points:\n",
|
||||
"- states are not presented as pairs\n",
|
||||
"- the properties of the resulting automaton are not sets\n",
|
||||
"- the properties of the resulting automaton are not set\n",
|
||||
"\n",
|
||||
"The former point can be addressed by calling `set_state_names()` and passing an array of strings: if a state number is smaller than the size of that array, then the string at that position will be displayed instead of the state number in the dot output. \n",
|
||||
"\n",
|
||||
"(Note: the original `spot.product()` is in fact *not* naming states. The `spot.product()` function actually attaches a vector of pairs of integers to the automaton because some algorithms need to project a state of the product onto the original automaton. The `dot` printer knows how to display those pairs for states that are not named. Here we shall name states because (1) that is more flexible, and (2) there is a Python interface for this.)\n",
|
||||
"\n",
|
||||
"Regarding the latter point, consider for instance the deterministic nature of these automata:"
|
||||
"Regarding the latter point, consider for instance the deterministic nature of these automata. In Spot an automaton is deterministic if it is both existential (no universal branching) and universal (no non-deterministic branching). In our case we will restrict the algorithm to existantial input (by asserting `is_existential()` on both operands), so we can consider that the `prop_universal()` property is an indication of determinism:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"collapsed": false,
|
||||
"input": [
|
||||
"print(a1.prop_deterministic())\n",
|
||||
"print(a2.prop_deterministic())\n",
|
||||
"print(prod.prop_deterministic())\n",
|
||||
"print(p1.prop_deterministic())"
|
||||
"print(a1.prop_universal())\n",
|
||||
"print(a2.prop_universal())\n",
|
||||
"print(prod.prop_universal())\n",
|
||||
"print(p1.prop_universal())"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
|
@ -1564,18 +1564,18 @@
|
|||
"source": [
|
||||
"Because `a1` and `a2` are deterministic, their product is necessarily deterministic. This is a property that the `spot.product()` algorithm will preserve, but that our version does not *yet* preserve. We can fix that by adding\n",
|
||||
"\n",
|
||||
" if left.prop_deterministic() and right.prop_deterministic():\n",
|
||||
" result.prop_deterministic(True)\n",
|
||||
" if left.prop_universal() and right.prop_universal():\n",
|
||||
" result.prop_universal(True)\n",
|
||||
" \n",
|
||||
"at the end of our function. Note that this is **not** the same as\n",
|
||||
"\n",
|
||||
" result.prop_deterministic(left.prop_deterministic() and right.prop_deterministic())\n",
|
||||
" result.prop_universal(left.prop_universal() and right.prop_universal())\n",
|
||||
"\n",
|
||||
"because the results the `prop_*()` family of functions take and return instances of `spot.trival` values. These `spot.trival`, can, as their name implies, take one amongst three values representing `yes`, `no`, and `maybe`. `yes` and `no` should be used when we actually know that the automaton is deterministic or not (not deterministic meaning that there actually exists some non determinitic state in the automaton), and `maybe` when we do not know. \n",
|
||||
"\n",
|
||||
"The one-liner above is wrong for two reasons:\n",
|
||||
"\n",
|
||||
" - if `left` and `right` are non-deterministic, their product could be deterministic, so calling prop_deterministic(False) would be wrong. \n",
|
||||
" - if `left` and `right` are non-deterministic, their product could be deterministic, so calling prop_universal(False) would be wrong. \n",
|
||||
"\n",
|
||||
" - the use of the `and` operator on `trival` is misleading in non-Boolean context. The `&` operator would be the correct operator to use if you want to work in threed-valued logic. Compare: "
|
||||
]
|
||||
|
|
@ -1621,8 +1621,8 @@
|
|||
"\n",
|
||||
"So our\n",
|
||||
"\n",
|
||||
" if left.prop_deterministic() and right.prop_deterministic():\n",
|
||||
" result.prop_deterministic(True)\n",
|
||||
" if left.prop_universal() and right.prop_universal():\n",
|
||||
" result.prop_universal(True)\n",
|
||||
"\n",
|
||||
"is OK because the `if` body will only be entered of both input automata are known to be deterministic."
|
||||
]
|
||||
|
|
@ -1639,6 +1639,9 @@
|
|||
"collapsed": false,
|
||||
"input": [
|
||||
"def product3(left, right):\n",
|
||||
" # the twa_graph.is_existential() method returns a Boolean, not a spot.trival\n",
|
||||
" if not (left.is_existential() and right.is_existential()):\n",
|
||||
" raise RuntimeError(\"alternating automata are not supported\")\n",
|
||||
" bdict = left.get_dict()\n",
|
||||
" if right.get_dict() != bdict:\n",
|
||||
" raise RuntimeError(\"automata should share their dictionary\")\n",
|
||||
|
|
@ -1680,7 +1683,7 @@
|
|||
" result.set_state_names(names)\n",
|
||||
" \n",
|
||||
" # Loop over all the properties we want to preserve if they hold in both automata\n",
|
||||
" for p in ('prop_deterministic', 'prop_complete', 'prop_weak', 'prop_inherently_weak', \n",
|
||||
" for p in ('prop_universal', 'prop_complete', 'prop_weak', 'prop_inherently_weak', \n",
|
||||
" 'prop_terminal', 'prop_stutter_invariant', 'prop_state_acc'):\n",
|
||||
" if getattr(left, p)() and getattr(right, p)():\n",
|
||||
" getattr(result, p)(True)\n",
|
||||
|
|
@ -1688,7 +1691,7 @@
|
|||
"\n",
|
||||
"p3 = product3(a1, a2)\n",
|
||||
"show_prod(a1, a2, p3)\n",
|
||||
"print(p3.prop_deterministic())"
|
||||
"print(p3.prop_universal())"
|
||||
],
|
||||
"language": "python",
|
||||
"metadata": {},
|
||||
|
|
@ -2018,7 +2021,7 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"prompt_number": 9
|
||||
"prompt_number": 14
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
|
|
@ -2042,7 +2045,7 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"1000 loops, best of 3: 206 \u00b5s per loop\n"
|
||||
"1000 loops, best of 3: 202 \u00b5s per loop\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
@ -2061,8 +2064,8 @@
|
|||
"output_type": "stream",
|
||||
"stream": "stdout",
|
||||
"text": [
|
||||
"The slowest run took 6.27 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
|
||||
"100000 loops, best of 3: 4.2 \u00b5s per loop\n"
|
||||
"The slowest run took 5.71 times longer than the fastest. This could mean that an intermediate result is being cached.\n",
|
||||
"100000 loops, best of 3: 4.39 \u00b5s per loop\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue