flpq_data.queries.rpq.converters.rsa#
Convert between regular expressions and regular RSMs.
Functions
|
Create a regular RSM [1] from a regular expression. |
|
Create a regular expression from a regular RSM. |
- regex_to_rsa(regex: Regex, *, box_name: str = 'S') RecursiveAutomaton[source]#
Create a regular RSM [1] from a regular expression.
The RSM has a single box whose DFA is the minimized epsilon-NFA of the regex, so the box language equals the regex language. This is a one-way derivation aid: an RSM remains a first-class, independently specifiable representation — the archive checker couples
.reand.rsmfiles only at terminal-set consistency and regularity, so an RSM that is not an exact copy of the regex-derived one remains valid.- Parameters:
- regexRegex
Regular expression.
- box_namestr, optional
The name of the single box (and the initial label). Default:
"S".
- Returns:
- rsaRSA
Regular State Machine.
References
[1] (1,2)Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18
Examples
>>> from flpq_data import * >>> rsa = regex_to_rsa(regex_from_text("a* b")) >>> len(rsa.boxes) 1 >>> cfg = cfg_from_rsa(rsa) >>> cfg.contains("aab") True >>> cfg.contains("a") False
- rsa_to_regex(rsa: RecursiveAutomaton) Regex[source]#
Create a regular expression from a regular RSM.
The RSM must have exactly one box, its automaton must be a deterministic finite automaton, and it must not be recursive (no transition labelled by the box’s own label). The result is the canonical regular expression of the box language, so
regex_to_rsa(rsa_to_regex(rsa))reproduces the box language.- Parameters:
- rsaRSA
Regular State Machine.
- Returns:
- regexRegex
Regular expression.
- Raises:
- ValueError
If the RSM has more than one box, the box’s automaton is not a deterministic finite automaton, or the box is recursive.
References
[1]Alur R., Etessami K., Yannakakis M. (2001) Analysis of Recursive State Machines. In: Berry G., Comon H., Finkel A. (eds) Computer Aided Verification. CAV 2001. Lecture Notes in Computer Science, vol 2102. Springer, Berlin, Heidelberg. https://doi.org/10.1007/3-540-44585-4_18
Examples
>>> from flpq_data import * >>> rsa = regex_to_rsa(regex_from_text("a* b")) >>> regex_to_text(rsa_to_regex(rsa)) 'a* b'