cfl_regular.h
Go to the documentation of this file.
1 
2 /** @file cfl_regular.h
3 
4 Operations on regular languages.
5 See [Cassandras and Lafortune. Introduction to Discrete Event Systems] for an
6 introduction to regular language operations.
7 Operations are always performed on language(s) marked by the passed generator(s),
8 resulting in the language(s) marked by the resulting generator(s).
9 Only if mentioned extra, the same is done for the involved generated (prefix-closed)
10 languages.
11 
12 */
13 
14 /* FAU Discrete Event Systems Library (libfaudes)
15 
16  Copyright (C) 2006 Bernd Opitz
17  Exclusive copyright is granted to Klaus Schmidt
18 
19  This library is free software; you can redistribute it and/or
20  modify it under the terms of the GNU Lesser General Public
21  License as published by the Free Software Foundation; either
22  version 2.1 of the License, or (at your option) any later version.
23 
24  This library is distributed in the hope that it will be useful,
25  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27  Lesser General Public License for more details.
28 
29  You should have received a copy of the GNU Lesser General Public
30  License along with this library; if not, write to the Free Software
31  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
32 
33 
34 #ifndef FAUDES_REGULAR_H
35 #define FAUDES_REGULAR_H
36 
37 #include "cfl_definitions.h"
38 #include "cfl_parallel.h"
39 #include "cfl_project.h"
40 
41 namespace faudes {
42 
43 /**
44  * Language union, nondeterministic version.
45  *
46  * This function performs the union of two languages marked by two generators;
47  * the resulting generator marks the resulting language.
48  * Moreover, the same is done for the involved generated (prefix-closed) languages.
49  * Method:
50  * This function implements the textbook version in taking unions of all generator
51  * entities (alphabets, initial states, ...) of rGen1 and rGen2. State sets are taken
52  * as disjoint by definition and thus reindexed and renamed to achieve disjoint union.
53  * The resulting language is defined over the union of the alphabets of the original
54  * languages; original languages defined over different alphabets are treated as if
55  * they were defined over the union of both alphabets.
56  *
57  * Determinism:
58  * Input parameters may be nondeterministic.
59  * This function is more economical than the deterministic version, but likely to
60  * produce a non-deterministic result; see also LanguageUnion().
61  *
62  * No restrictions on parameters.
63  *
64  * @param rGen1
65  * generator generating/marking L1/Lm1
66  * @param rGen2
67  * generator generating/marking L2/Lm2
68  * @param rResGen
69  * resulting generator generating/marking the language union of L1 and L2/of Lm1 and Lm2
70  *
71  *
72  * @ingroup GeneratorFunctions
73  */
74 extern FAUDES_API void LanguageUnionNonDet(const Generator& rGen1, const Generator& rGen2,
75  Generator& rResGen);
76 
77 /**
78  * Language union, deterministic version.
79  *
80  * This function performs the union of two languages marked by two generators;
81  * the resulting generator marks the resulting language.
82  * Moreover, the same is done for the involved generated (prefix-closed) |languages.
83  * Method:
84  * This function implements the textbook version (which textbook??) in taking unions
85  * of all generator entities (alphabets, initial states, ...). State sets are taken
86  * as disjoint by definition and thus reindexed and renamed to achieve disjoint union.
87  * The resulting language is defined over the union of the alphabets of the original
88  * languages.
89  *
90  * Determinism:
91  * Input parameters may be nondeterministic.
92  * This function calls LanguageUnionNonDet() and then Deterministic() to convert the
93  * result into a deterministic generator. Note that this conversion is usually
94  * straightforward, but there exist theoretical worst-case examples of exponential complexity.
95  *
96  * No restrictions on parameters.
97  *
98  * ToDo: a version similar to parallel composition that produces a deterministic result by construction. (?)
99  *
100  * @param rGen1
101  * generator generating/marking L1/Lm1
102  * @param rGen2
103  * generator generating/marking L2/Lm2
104  * @param rResGen
105  * resulting generator generating/marking the language union of L1 and L2/of Lm1 and Lm2
106  *
107  * <h4>Example:</h4>
108  * <table border=0> <tr> <td> <table>
109  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
110  * <tr>
111  * <td> @image html tmp_boolean_g1.png </td>
112  * <td> @image html tmp_boolean_g2.png </td>
113  * </tr>
114  * </table> </td> </tr> <tr> <td> <table width=100%>
115  * <tr> <td> LanguageUnion(G1,G2,Result) </td> </tr>
116  * <tr> <td> @image html tmp_union_g1g2.png </td> </tr>
117  * </table> </td> </tr> </table>
118  *
119  * @ingroup GeneratorFunctions
120  */
121 extern FAUDES_API void LanguageUnion(const Generator& rGen1, const Generator& rGen2,
122  Generator& rResGen);
123 
124 /**
125  * Language union.
126  *
127  * See also LanguageUnion(const Generator&, const Generator&, Generator&);
128  * This version takes a vector of generators as argument to perform
129  * the union for multiple languages. The implementation
130  * calls the std union multiple times, future implementations may
131  * do better.
132  *
133  * @param rGenVec
134  * Vector of input generators
135  * @param rResGen
136  * Reference to resulting generator
137  *
138  */
139 extern FAUDES_API void LanguageUnion(const GeneratorVector& rGenVec, Generator& rResGen);
140 
141 
142 /**
143  * Language intersection.
144  *
145  * This function performs the intersection of two languages marked by two generators;
146  * the resulting generator marks the resulting language.
147  * Moreover, the same is done for the involved generated (prefix-closed) languages.
148  * The resulting languages are defined over the intersection of the involved alphabets.
149  * Method:
150  * This function calls Product(). In the product of two automata, an event occurs if
151  * and only if it occurs in both automata rGen1 and rGen2. The result generates/marks
152  * the intersection of the involved languages, see e.g.
153  * [Cassandras, Lafortune. Introduction to Discrete Event Systems, p.84]
154  *
155  * Determinism:
156  * Input parameters may be nondeterministic.
157  * Result can be nondeterministic only if input parameters are nondeterministic.
158  *
159  * No restrictions on parameters.
160  *
161  * @param rGen1
162  * generator generating/marking L1/Lm1
163  * @param rGen2
164  * generator generating/marking L2/Lm2
165  * @param rResGen
166  * resulting generator generating/marking the language intersection of L1 and L2/of Lm1 and Lm2
167  *
168  * <h4>Example:</h4>
169  *
170  * <table border=0> <tr> <td> <table>
171  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
172  * <tr>
173  * <td> @image html tmp_boolean_g1.png </td>
174  * <td> @image html tmp_boolean_g2.png </td>
175  * </tr>
176  * </table> </td> </tr> <tr> <td> <table width=100%>
177  * <tr> <td> LanguageIntersection(G1,G2,Result) </td> </tr>
178  * <tr> <td> @image html tmp_intersection_g1g2.png </td> </tr>
179  * </table> </td> </tr> </table>
180  *
181  * @ingroup GeneratorFunctions
182  */
183 extern FAUDES_API void LanguageIntersection(const Generator& rGen1, const Generator& rGen2,
184  Generator& rResGen);
185 
186 /**
187  * Language intersection.
188  *
189  * See also LanguageUnion(const Generator&, const Generator&, Generator&);
190  * This version takes a vector of generators as argument to perform
191  * the intersection for multiple languages. The implementation
192  * calls the std intersection multiple times, future implementations may
193  * do better.
194  *
195  * @param rGenVec
196  * Vector of input generators
197  * @param rResGen
198  * Reference to resulting generator
199  *
200  */
201 extern FAUDES_API void LanguageIntersection(const GeneratorVector& rGenVec, Generator& rResGen);
202 
203 
204 /**
205  * Test for empty language intersection (same as Disjoind()).
206  *
207  * This function checks if the intersection of two languages marked by two generators
208  * is empty that is the two languages are disjoint.
209  * The involved generated (prefix-closed) languages are not considered. This function
210  * is identical to Disjoint().
211  *
212  * No restrictions on parameters.
213  *
214  * @param rGen1
215  * generator marking Lm1
216  * @param rGen2
217  * generator marking Lm2
218  *
219  * @return
220  * true if language intersection is empty, false if not.
221  *
222  * @ingroup GeneratorFunctions
223  */
224 extern FAUDES_API bool EmptyLanguageIntersection(const Generator& rGen1, const Generator& rGen2);
225 
226 /**
227  * Test whether two languages are disjoint.
228  *
229  * This function tests whether the intersection of two languages marked by two generators
230  * is empty, ie the two languages are disjoint.
231  * The involved generated (prefix-closed) languages are not considered. This function
232  * is identical to EmptyLanguageIntersection().
233  *
234  * No restrictions on parameters.
235  *
236  * @param rGen1
237  * generator marking Lm1
238  * @param rGen2
239  * generator marking Lm2
240  *
241  * @return
242  * true if language intersection is empty, false if not.
243  *
244  * @ingroup GeneratorFunctions
245  */
246 extern FAUDES_API bool LanguageDisjoint(const Generator& rGen1, const Generator& rGen2);
247 
248 /**
249  * Convert generator to automaton.
250  *
251  * Convert a generator marking the language Lm into a formal automaton recognizing Lm
252  * with a dump state representing Sigma*-PrefixClosure(Lm). In this function, Sigma is
253  * given by the alphabet of rGen; see also Automaton(rGen,rAlphabet).
254  * For information about automata, see [Wonham. Supervisory Control of Discrete Event
255  * Systems].
256  * The original generated language is ignored.
257  * Note: An automaton is a deterministic transition structure according to the formal
258  * definition; see also "Determinism" below.
259  * Method:
260  * Uncoaccessible states are erased, as the language generated by rGen is not examined
261  * in this function. A dump state representing "Sigma*-PrefixClosure(Lm)" is created.
262  * Then, the transition relation is completed such that it is fully defined for each
263  * state and each event. Formerly undefined transitions lead to the dump state.
264  *
265  * Determinism:
266  * Input parameter has to be deterministic for correct result. If not, then the
267  * (also nondeterministic) result recognizes the correct language, but the dump state
268  * does not represent "Sigma*-PrefixClosure(Lm)" as it should;
269  * see also example ExAutomaton_basic().
270  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
271  *
272  * No further restrictions on parameter.
273  *
274  * @param rGen
275  * generator that is converted to automaton
276  *
277  * <h4>Example:</h4>
278  * <table>
279  * <tr> <td> Generator G </td> <td> Automaton(G) </td> </tr>
280  * <tr>
281  * <td> @image html tmp_automaton_g.png </td>
282  * <td> @image html tmp_automaton_gRes.png </td>
283  * </tr>
284  * </table>
285  *
286  * @ingroup GeneratorFunctions
287  */
288 extern FAUDES_API void Automaton(Generator& rGen);
289 
290 /**
291  * Convert generator to automaton.
292  *
293  * Convert a generator marking the language Lm into a formal automaton recognizing Lm
294  * with a dump state representing Sigma*-PrefixClosure(Lm); see also Automaton(rGen,rGen).
295  * For information about automata, see [Wonham. Supervisory Control of Discrete Event
296  * Systems].
297  * The original generated language is ignored.
298  * Note: An automaton is a deterministic transition structure according to the formal
299  * definition; see also "Determinism" below.
300  * Method:
301  * Uncoaccessible states are erased, as the language generated by rGen is not examined
302  * in this function. A dump state representing "Sigma*-PrefixClosure(Lm)" is created.
303  * Then, the transition relation is completed such that it is fully defined for each
304  * state and each event. Formerly undefined transitions lead to the dump state.
305  */
306 extern FAUDES_API void Automaton(const Generator& rGen, Generator& rRes);
307 
308 /**
309  * Convert generator to automaton wrt specified alphabet.
310  *
311  * Convert a generator marking the language Lm into a formal automaton recognizing Lm
312  * with a dump state representing Sigma*-PrefixClosure(Lm(rGen)). In this function,
313  * Sigma is given by the parameter rAlphabet.
314  * For information about automata, see [Wonham. Supervisory Control of Discrete Event
315  * Systems].
316  * The original generated language is ignored.
317  * Note: An automaton is a deterministic transition structure according to the formal
318  * definition; see also "Determinism" below.
319  * Method:
320  * Uncoaccessible states are erased, as the language generated by rGen is not examined
321  * in this function. A dump state representing "Sigma*-PrefixClosure(Lm)" is created.
322  * Then, the transition relation is completed such that it is fully defined for each
323  * state of rGen and each event of rAlphabet. Formerly undefined transitions lead to
324  * the dump state.
325  *
326  * Determinism:
327  * Input parameter has to be deterministic for correct result. If not, then the
328  * (also nondeterministic) result recognizes the correct language, but the dump state
329  * does not represent "Sigma*-PrefixClosure(Lm)" as it should;
330  * see also example ExAutomaton_basic().
331  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
332  *
333  * No further restrictions on parameters.
334  *
335  * @param rGen
336  * generator that is converted to automaton
337  *
338  * @param rAlphabet
339  * the dump state of the resulting automaton represents the
340  * language L_dump=rAlphabet*-PrefixClosure(Lm(rGen))
341  *
342  * @ingroup GeneratorFunctions
343  */
344 extern FAUDES_API void Automaton(Generator& rGen, const EventSet& rAlphabet);
345 
346 /**
347  * Language complement.
348  *
349  * Convert generator marking the language Lm into generator marking the language
350  * complement of Lm which is defined as Sigma*-Lm. In this function, Sigma is
351  * given by the alphabet of rGen; see also LanguageComplement(rGen,rAlphabet).
352  * The original generated language is ignored.
353  * Method:
354  * This function calls Automaton() first and then inverts the marking of the states
355  * of the result.
356  *
357  * Determinism:
358  * Input parameter has to be deterministic for correct result, see Automaton() for
359  * explanations.
360  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
361  * (by function Automaton()).
362  *
363  * No further restrictions on parameter.
364  *
365  * @param rGen
366  * generator on which the language complement is performed
367  *
368  * <h4>Example:</h4>
369  * <table>
370  * <tr> <td> Generator G </td> <td> LanguageComplement(G) </td> </tr>
371  * <tr>
372  * <td> @image html tmp_boolean_g1.png </td>
373  * <td> @image html tmp_complement_g1.png </td>
374  * </tr>
375  * </table>
376  *
377  *
378  * @ingroup GeneratorFunctions
379  */
380 extern FAUDES_API void LanguageComplement(Generator& rGen);
381 
382 /**
383  * Language complement wrt specified alphabet.
384  *
385  * Convert generator marking the language Lm into generator marking the language
386  * complement of Lm which is defined as Sigma*-Lm. In this function, Sigma is
387  * given by the parameter rAlphabet.
388  * The original generated language is ignored.
389  * Method:
390  * This function calls Automaton() first and then inverts the marking of the states
391  * of the result.
392  *
393  * Determinism:
394  * Input parameter has to be deterministic for correct result, see Automaton() for
395  * explanations.
396  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
397  * (by function Automaton()).
398  *
399  * No further restrictions on parameter.
400  *
401  * @param rGen
402  * generator on which the language complement is performed
403  *
404  * @param rAlphabet
405  * reference alphabet to build the complement
406  *
407  * @ingroup GeneratorFunctions
408  */
409 extern FAUDES_API void LanguageComplement(Generator& rGen, const EventSet& rAlphabet);
410 
411 
412 /**
413  * Language Complement (uniform API wrapper).
414  *
415  * @param rGen
416  * generator on which the language complement is performed
417  *
418  * @param rRes
419  * resulting generator
420  *
421  * @ingroup GeneratorFunctions
422  */
423 extern FAUDES_API void LanguageComplement(const Generator& rGen, Generator& rRes);
424 
425 /**
426  * Language Complement (uniform API wrapper).
427  *
428  * @param rGen
429  * generator on which the language complement is performed
430  *
431  * @param rSigma
432  * reference alphabet to build the complement
433  *
434  * @param rRes
435  * resulting generator
436  *
437  * @ingroup GeneratorFunctions
438  */
439 extern FAUDES_API void LanguageComplement(const Generator& rGen, const EventSet& rSigma, Generator& rRes);
440 
441 
442 
443 /**
444  * Language difference (set-theoretic difference).
445  *
446  * This function calculates Lm1-Lm2 (sometimes also denoted by Lm1\\Lm2), that is the
447  * set of all strings included in Lm1 but not in Lm2.
448  * Method:
449  * The language difference is computed by taking the intersection of Lm1 with the
450  * complement of Lm2.
451  *
452  * Determinism:
453  * Due to the use of LanguageComplement(), rGen2 has to be deterministic.
454  * Result can be nondeterministic only if rGen1 is nondeterministic.
455  *
456  * Restrictions on prameters:
457  * rGen2 has to be deterministic.
458  *
459  * @param rGen1
460  * generator marking the language Lm1
461  * @param rGen2
462  * generator marking the language Lm2
463  * @param rResGen
464  * generator marking the language difference Lm1-Lm2
465  *
466  * @exception Exception
467  * - nondeterministic parameter rGen2 (id 101).
468  *
469  * <h4>Example:</h4>
470  * <table border=0> <tr> <td> <table>
471  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
472  * <tr>
473  * <td> @image html tmp_difference_g1.png </td>
474  * <td> @image html tmp_difference_g2.png </td>
475  * </tr>
476  * </table> </td> </tr> <tr> <td> <table width=100%>
477  * <tr> <td> LanguageDifference(G1,G2,Result) </td> </tr>
478  * <tr> <td> @image html tmp_difference_g1minusg2.png </td> </tr>
479  * </table> </td> </tr> </table>
480  *
481  * @ingroup GeneratorFunctions
482  */
483 extern FAUDES_API void LanguageDifference(const Generator& rGen1, const Generator& rGen2,
484  Generator& rResGen);
485 
486 /**
487  * Language concatenation, nondeterministic version.
488  *
489  * With the languages Lm1 and Lm2 marked by rGen1 and rGen2, respectively, the result
490  * rResGen marks the concatenation LmRes=Lm1Lm2.
491  * The languages generated by rGen1 and rGen2 are ignored. It would be possible to let
492  * the result also generate the concatenation of the generated languages; however, this can
493  * produce disproportionate computational overhead, if only the marked languages shall be
494  * concatenated.
495  * Method:
496  * rGen2 is appended to rGen1: first, the initial states of rGen2 are erased. Then,
497  * transitions, that formerly started from the initial state(s) of rGen2, are redirected
498  * and multiplied such that they start from each marked state of rGen1. The marked states
499  * corresponding to rGen2 remain marked. The marked states of rGen1 remain marked only if
500  * rGen2 has at least one marked initial state (i.e. if epsilon is concatenated to Lm1.)
501  *
502  * Determinism:
503  * Input parameters may be nondeterministic. Result can be nondeterministic even if input
504  * parameters are deterministic; see also LanguageConcatenate().
505  *
506  * No restrictions on parameters.
507  *
508  * @param rGen1
509  * generator marking Lm1
510  * @param rGen2
511  * generator marking Lm2
512  * @param rResGen
513  * resulting generator marking the language concatenation Lm1Lm2
514  *
515  * @ingroup GeneratorFunctions
516  */
517 extern FAUDES_API void LanguageConcatenateNonDet(const Generator& rGen1, const Generator& rGen2,
518  Generator& rResGen);
519 
520 /**
521  * Language concatenation, deterministic version.
522  *
523  * With the languages Lm1 and Lm2 marked by rGen1 and rGen2, respectively, the result
524  * rResGen marks the concatenation LmRes=Lm1Lm2.
525  * The languages generated by rGen1 and rGen2 are ignored. It would be possible to let
526  * the result also generate the concatenation of the generated languages; however, this can
527  * produce disproportionate computational overhead, if only the marked languages shall be
528  * concatenated.
529  * Method:
530  * rGen2 is appended to rGen1: first, the initial states of rGen2 are erased. Then,
531  * transitions, that formerly started from the initial state(s) of rGen2, are redirected
532  * and multiplied such that they start from each marked state of rGen1. The marked states
533  * corresponding to rGen2 remain marked. The marked states of rGen1 remain marked only if
534  * rGen2 has at least one marked initial state (i.e. if epsilon is concatenated to Lm1.)
535  *
536  * Determinism:
537  * Input parameters may be nondeterministic.
538  * This function calls LanguageUnionNonDet() and then Deterministic() to convert the
539  * result into a deterministic generator. Note that this conversion is usually
540  * straightforward, but there exist theoretical worst-case examples of exponential complexity.
541  *
542  * No restrictions on parameters.
543  *
544  * @param rGen1
545  * generator marking Lm1
546  * @param rGen2
547  * generator marking Lm2
548  * @param rResGen
549  * Resulting generator marking the language concatenation Lm1Lm2
550  *
551  * <h4>Example:</h4>
552  * <table border=0> <tr> <td> <table>
553  * <tr> <td> Generator G1 </td> <td> </td> <td> LanguageConcatenate(G1,G3,Result) </td> </tr>
554  * <tr>
555  * <td> @image html tmp_concat_g1.png </td>
556  * <td> </td>
557  * <td> @image html tmp_concat_g1g3.png </td>
558  * </tr>
559  * <tr> <td> Generator G2 </td> <td> </td> <td> LanguageConcatenate(G1,G4,Result) </td> </tr>
560  * <tr>
561  * <td> @image html tmp_concat_g2.png </td>
562  * <td> </td>
563  * <td> @image html tmp_concat_g1g4.png </td>
564  * </tr>
565  * </tr>
566  * <tr> <td> Generator G3 </td> <td> </td> <td> LanguageConcatenate(G2,G3,Result) </td> </tr>
567  * <tr>
568  * <td> @image html tmp_concat_g3.png </td>
569  * <td> </td>
570  * <td> @image html tmp_concat_g2g3.png </td>
571  * </tr>
572  * </tr>
573  * <tr> <td> Generator G4 </td> <td> </td> <td> LanguageConcatenate(G2,G4,Result) </td> </tr>
574  * <tr>
575  * <td> @image html tmp_concat_g4.png </td>
576  * <td> </td>
577  * <td> @image html tmp_concat_g2g4.png </td>
578  * </tr>
579  * </table> </td> </tr> </table>
580  *
581  * @ingroup GeneratorFunctions
582  */
583 extern FAUDES_API void LanguageConcatenate(const Generator& rGen1, const Generator& rGen2,
584  Generator& rResGen);
585 
586 /**
587  * Full Language, L(G)=Lm(G)=Sigma*.
588  *
589  * Construct generator generating and marking full language Sigma* from alphabet Sigma.
590  * Method: this function creates a generator with one state that is marked and init state. This
591  * state is selflooped with all events from rAlphabet.
592  *
593  * @param rAlphabet
594  * Alphabet Sigma from which full language Sigma* is built
595  * @param rResGen
596  * Generator generating and marking full language Sigma*
597  *
598  * <h4>Example:</h4>
599  * <table>
600  * <tr> <td> FullLanguage(Sigma={a,b},Result) </td> </tr>
601  * <tr>
602  * <td> @image html tmp_languagesFull_result.png </td>
603  * </tr>
604  * </table>
605  *
606  * @ingroup GeneratorFunctions
607  */
608 extern FAUDES_API void FullLanguage(const EventSet& rAlphabet, Generator& rResGen);
609 
610 /**
611  * Alphabet Language, L(G)=Lm(G)=Sigma
612  *
613  * Construct generator generating and marking an alphabet as languages, that is L(G)=Lm(G)=Sigma.
614  * Method: this function creates a generator with one init state and one marked state. For each
615  * event from rAlphabet, a transition is inserted leading from the init state to the marked state.
616  *
617  * No restrictions on parameters.
618  *
619  * @param rAlphabet
620  * alphabet from which alphabet language is built
621  * @param rResGen
622  * generator with languages Lm(G)=Sigma
623  *
624  * <h4>Example:</h4>
625  * <table>
626  * <tr> <td> AlphabetLanguage(Sigma={a,b},Result) </td> </tr>
627  * <tr>
628  * <td> @image html tmp_languagesAlphabet_result.png </td>
629  * </tr>
630  * </table>
631  *
632  * @ingroup GeneratorFunctions
633  */
634 extern FAUDES_API void AlphabetLanguage(const EventSet& rAlphabet, Generator& rResGen);
635 
636 /**
637  * Empty string language, L(G)=Lm(G)={epsilon}.
638  *
639  * Construct generator generating and marking the empty string, that is L(G)=Lm(G)={epsilon}.
640  * Method: this function creates a generator with one marked init state and the alphabet rAlphabet.
641  *
642  * No restrictions on parameters.
643  *
644  * @param rAlphabet
645  * alphabet of the resulting generator
646  * @param rResGen
647  * generator with languages L(G)=Lm(G)={epsilon} and alphabet rAlphabet
648  *
649  * <h4>Example:</h4>
650  * <table>
651  * <tr> <td> EmptyStringLanguage(Sigma={a,b},Result) </td> </tr>
652  * <tr>
653  * <td> @image html tmp_languagesEmptyString_result.png </td>
654  * </tr>
655  * </table>
656  *
657  * @ingroup GeneratorFunctions
658  */
659 extern FAUDES_API void EmptyStringLanguage(const EventSet& rAlphabet, Generator& rResGen);
660 
661 /**
662  * Empty language Lm(G)={}.
663  *
664  * Construct generator and marking the empty language, that is Lm(G)={}.
665  * Method: this function creates a deterministic generator with one initial state that is not marked.
666  * The alphabet is set as specified.
667  *
668  * No restrictions on parameters.
669  *
670  * @param rAlphabet
671  * Alphabet of the resulting generator
672  * @param rResGen
673  * Generator with language Lm(G)={}
674  *
675  * @ingroup GeneratorFunctions
676  */
677 extern FAUDES_API void EmptyLanguage(const EventSet& rAlphabet, Generator& rResGen);
678 
679 /**
680  * Test for Empty language Lm(G)=={}.
681  *
682  * Tests if the language marked by rGen is empty, that is if Lm(G)=={}. The generated
683  * language L(G) is not considered.
684  * Method:
685  * This function tests if
686  * a) the set of marked states is empty or else
687  * b) the intersection of the set of accessible states and the set of marked states
688  * is empty, i.e. if there is no marked state or if no marked state is accessible (reachable).
689  *
690  * No restrictions on parameter.
691  *
692  * @param rGen
693  * generator to be tested for empty marked language
694  *
695  * @return
696  * true on empty marked language, false on nonempty marked language
697  *
698  * @ingroup GeneratorFunctions
699  */
700 extern FAUDES_API bool IsEmptyLanguage(const Generator& rGen);
701 
702 /**
703  * Test language inclusion, Lm1<=Lm2.
704  *
705  * Test if language Lm1 marked by rGen1 is included in language Lm2 marked by rGen2. The
706  * generated languages are not considered.
707  * Method:
708  * This function checks if there is no string in Lm1 that is not in Lm2 by testing if
709  * the intersection of Lm1 and the language complement of Lm2 is empty.
710  *
711  * Restrictions on parameters: rGen2 has to be deterministic!
712  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
713  * (by function Automaton()).
714  *
715  * Determinism: correctness in case of nondeterministic parameter rGen1 has been tested with an
716  * example (see ExInclusion_simple), but not proven.
717  *
718  * ToDo: implement faster version using a variant of Product():
719  * compute product without storing result, return false as soon as some event is
720  * possible in Lm2 but not in Lm1.
721  *
722  * @param rGen1
723  * generator marking Lm1
724  * @param rGen2
725  * generator marking Lm2
726  *
727  * @return
728  * true if language marked by rGen1 is included in language marked by rGen2
729  *
730  * @ingroup GeneratorFunctions
731  */
732 extern FAUDES_API bool LanguageInclusion(const Generator& rGen1, const Generator& rGen2);
733 
734 /**
735  * Language equality, Lm1==Lm2.
736  *
737  * Test if the language Lm1 marked by rGen1 equals the language Lm2 marked by rGen2. The
738  * generated languages are not considered.
739  * Method:
740  * This function checks mutual inclusion of Lm1 in Lm2 and of Lm2 in Lm1 using the
741  * function LanguageInclusion().
742  *
743  * Restrictions on parameters: rGen1 and rGen2 have to be deterministic!
744  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
745  * (by function Automaton()).
746  *
747  * ToDo: implement faster, version using a variant of Product():
748  * compute product without storing result, return false as soon as rGen1 and rGen2
749  * "disagree" on the occurrence of some event.
750  *
751  * @param rGen1
752  * generator marking Lm1
753  * @param rGen2
754  * generator marking Lm2
755  *
756  * @return
757  * true if the language marked by rGen1 equals the language marked by rGen2
758  *
759  * @ingroup GeneratorFunctions
760  */
761 extern FAUDES_API bool LanguageEquality(const Generator& rGen1, const Generator& rGen2);
762 
763 /**
764  * Kleene Closure.
765  *
766  * This function computes the Kleene Closure ( ()* - operator) of the
767  * language marked by rGen. The generated language is not considered.
768  * Method: KleeneClosureNonDet() is called, which, for all transitions
769  * leading from a state x to a marked state, inserts a transition with the
770  * same event starting from x and leading to (one of) the initial state(s).
771  * As this step causes nondeterminism, the function Deterministic() is called.
772  * See also KleeneClosureNonDet().
773  *
774  * No restrictions on parameter.
775  *
776  * @param rGen
777  * generator marking the language Lm to which the Kleene Closure is applied
778  *
779  * <h4>Example:</h4>
780  * <table>
781  * <tr> <td> Generator G </td> <td> KleeneClosure(G) </td> </tr>
782  * <tr>
783  * <td> @image html tmp_kleene_g.png </td>
784  * <td> @image html tmp_kleene_gRes.png </td>
785  * </tr>
786  * </table>
787  *
788  * @ingroup GeneratorFunctions
789  */
790 extern FAUDES_API void KleeneClosure(Generator& rGen);
791 
792 /**
793  * Kleene Closure.
794  *
795  * This function is a convenience wrapper for KleeneClosure(Generator&).
796  *
797  *
798  * @ingroup GeneratorFunctions
799  */
800 extern FAUDES_API void KleeneClosure(const Generator& rGen, Generator& rResGen);
801 
802 /**
803  * Kleene Closure, nondeterministic version.
804  *
805  * This function computes the Kleene Closure ( ()* - operator) of the
806  * language marked by rGen. The generated language is not considered.
807  * Method: KleeneClosureNonDet() is called, which, for all transitions
808  * leading from a state x to a marked state, inserts a transition with the
809  * same event starting from x and leading to (one of) the initial state(s).
810  *
811  * @param rGen
812  * generator marking the language Lm to which Kleene Closure is applied
813  *
814  * @ingroup GeneratorFunctions
815  */
816 extern FAUDES_API void KleeneClosureNonDet(Generator& rGen);
817 
818 /**
819  * Prefix Closure.
820  *
821  * This function computes the prefix closure the language Lm marked by rGen. A
822  * language Lm is prefix closed if each string of Lm implies that all its
823  * prefixes are also element of Lm. The prefix closure of a language marked by
824  * a generator is always a subset of the generated language and is represented
825  * by the set of coaccessible states of the generator.
826  * Method:
827  * First, Coaccessible() is called to erase all states of rGen that do not
828  * represent prefixes of marked strings. Then, all remaining states are marked.
829  *
830  * No restrictions on parameter.
831  *
832  * ToDo: (slightly) more efficient version: implement generator function
833  * CoAccessibleSet() similar to AccessibleSet() and call
834  * InjectMarkedStates(AccessibleSet()).
835  *
836  * @param rGen
837  * generator marking the language Lm to which prefix closure is applied
838  *
839  * <h4>Example:</h4>
840  * <table>
841  * <tr> <td> Generator G </td> <td> PrefixClosure(G) </td> </tr>
842  * <tr>
843  * <td> @image html tmp_prefixclosure_g.png </td>
844  * <td> @image html tmp_prefixclosure_gRes.png </td>
845  * </tr>
846  * </table>
847  *
848  * @ingroup GeneratorFunctions
849  */
850 extern FAUDES_API void PrefixClosure(Generator& rGen);
851 
852 
853 /**
854  * Test for prefix closed marked language.
855  *
856  * This function tests whether the language Lm(G) marked by the specified generator G
857  * is prefix closed. It does so by testing whether all accessible and coaccessible
858  * states are marked.
859  *
860  * The specified generator must be deterministic.
861  *
862  * @param rGen
863  * generator G marking the Lm(G) to test
864  * @return
865  * True <> Lm(G) is prefix closed
866  *
867  * @ingroup GeneratorFunctions
868  */
869 extern FAUDES_API bool IsClosed(const Generator& rGen);
870 
871 
872 /**
873  * Test for nonblocking generator
874  *
875  * A generator G is nonblocking if closure(Lm(G)) = L(G), i.e.
876  * if every accessible state is coacessile.
877  *
878  * The specified generator must be deterministic.
879  *
880  * @param rGen
881  * generator G marking to test
882  * @return
883  * True <> G is nonblocking
884  *
885  * @ingroup GeneratorFunctions
886  */
887 extern FAUDES_API bool IsNonblocking(const Generator& rGen);
888 
889 /**
890  * Test for nonblocking marked languages.
891  *
892  * Two languages L1 and L2 are nonblocking, if
893  * closure(L1 || L2) == closure(L1) || closure(L2).
894  *
895  * This function performs the parallel composition of the two
896  * specified generators and tests it for nonblockingness. Provided
897  * that both generators are trim, this is equivalent to the
898  * respective marked languages being nonblocking.
899  *
900  * The specified generators must be trim.
901  *
902  * @param rGen1
903  * Generator G1
904  * @param rGen2
905  * Generator G2
906  * @return
907  * True <> Lm(G1) and Lm(G2) are nonblocking
908  *
909  * @ingroup GeneratorFunctions
910  */
911 extern FAUDES_API bool IsNonblocking(const Generator& rGen1, const Generator& rGen2);
912 
913 
914 /**
915  * Self-loop all states.
916  *
917  * This function selfoops all states of rGen with the events from rAlphabet.
918  * Method:
919  * The alphabet of rGen is extended by rAlphabet. For each state x of rGen
920  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
921  * irrespective of whether this event was already active in x before.
922  * See also SelfLoop(rGen,rAlphabet,rStates) and SelfLoopMarkedStates(rGen,rAlphabet).
923  *
924  * No restrictions on parameter.
925  *
926  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
927  * before, or if rGen already contains one or more (non selfloop) transitions with
928  * events from rAlphabet.
929  *
930  * @param rGen
931  * generator to be selflooped with events from rAlphabet
932  * @param rAlphabet
933  * alphabet with selfloop events
934  *
935  * <h4>Example:</h4>
936  * <table>
937  * <tr> <td> Generator G </td> <td> SelfLoop(G,Sigma={e,f}) </td> </tr>
938  * <tr>
939  * <td> @image html tmp_selfloop_g.png </td>
940  * <td> @image html tmp_selfloop_gRes.png </td>
941  * </tr>
942  * </table>
943  *
944  * @ingroup GeneratorFunctions
945  */
946 extern FAUDES_API void SelfLoop(Generator& rGen,const EventSet& rAlphabet);
947 
948 /**
949  * Self-loop all marked states.
950  *
951  * This function selfoops all marked states of rGen with the events from rAlphabet.
952  * Method:
953  * The alphabet of rGen is extended by rAlphabet. For each marked state x of rGen
954  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
955  * irrespective of whether this event was already active in x before.
956  * See also SelfLoop(rGen,rAlphabet) and SelfLoop(rGen,rAlphabet,rStates).
957  *
958  * No restrictions on parameter.
959  *
960  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
961  * before, or if rGen already contains one or more (non selfloop) transitions
962  * starting from a marked state with events from rAlphabet.
963  *
964  * @param rGen
965  * generator with marked states to be selflooped with events from rAlphabet
966  * @param rAlphabet
967  * alphabet with selfloop events
968  *
969  * <h4>Example:</h4>
970  * <table>
971  * <tr> <td> Generator G </td> <td> SelfLoopMarkedStates(G,Sigma={e,f}) </td> </tr>
972  * <tr>
973  * <td> @image html tmp_selfloop_g.png </td>
974  * <td> @image html tmp_selfloopMarked_gRes.png </td>
975  * </tr>
976  * </table>
977  *
978  * @ingroup GeneratorFunctions
979  */
980 extern FAUDES_API void SelfLoopMarkedStates(Generator& rGen,const EventSet& rAlphabet);
981 
982 /**
983  * Self-loop specified states.
984  *
985  * This function selfoops the states rStates of rGen with the events from rAlphabet.
986  * Method:
987  * The alphabet of rGen is extended by rAlphabet. For each state x of rStates
988  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
989  * irrespective of whether this event was already active in x before.
990  * See also SelfLoop(rGen,rAlphabet) and SelfLoopMarkedStates(rGen,rAlphabet).
991  *
992  * No restrictions on parameter.
993  *
994  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
995  * before, or if rGen already contains one or more (non selfloop) transitions
996  * starting from a state of rState with events from rAlphabet.
997  *
998  * @param rGen
999  * generator with marked states to be selflooped with events from rAlphabet
1000  * @param rAlphabet
1001  * alphabet with selfloop events
1002  * @param rStates
1003  * states to apply selfloop
1004  *
1005  * @exception Exception
1006  * - rStates is not a subset of rGen.States() (id 100).
1007  *
1008  * <h4>Example:</h4>
1009  * <table>
1010  * <tr> <td> Generator G </td> <td> SelfLoop(G,Sigma={e,f},G.InitStates()) </td> </tr>
1011  * <tr>
1012  * <td> @image html tmp_selfloop_g.png </td>
1013  * <td> @image html tmp_selfloopInit_gRes.png </td>
1014  * </tr>
1015  * </table>
1016  *
1017  * @ingroup GeneratorFunctions
1018  */
1019 extern FAUDES_API void SelfLoop(Generator& rGen,const EventSet& rAlphabet,const StateSet& rStates);
1020 
1021 
1022 /** lagacy wrappet (pre 2.33) */
1023 extern FAUDES_API bool IsPrefixClosed(const Generator& rGen);
1024 
1025 
1026 } // namespace faudes
1027 
1028 #define FAUDES_REGULAR_H
1029 #endif
1030 
#define FAUDES_API
Definition: cfl_platform.h:80
IndexSet StateSet
Definition: cfl_indexset.h:273
NameSet EventSet
Definition: cfl_nameset.h:534
vGenerator Generator
TBaseVector< Generator > GeneratorVector
bool IsClosed(const Generator &rGen)
bool EmptyLanguageIntersection(const Generator &rGen1, const Generator &rGen2)
void FullLanguage(const EventSet &rAlphabet, Generator &rResGen)
void LanguageUnion(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void LanguageConcatenateNonDet(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void SelfLoop(Generator &rGen, const EventSet &rAlphabet)
bool LanguageDisjoint(const Generator &rGen1, const Generator &rGen2)
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
void KleeneClosure(Generator &rGen)
void PrefixClosure(Generator &rGen)
void LanguageUnionNonDet(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Definition: cfl_regular.cpp:45
void Automaton(Generator &rGen, const EventSet &rAlphabet)
void AlphabetLanguage(const EventSet &rAlphabet, Generator &rResGen)
void LanguageConcatenate(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
bool IsEmptyLanguage(const Generator &rGen)
bool LanguageEquality(const Generator &rGen1, const Generator &rGen2)
void LanguageDifference(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void LanguageIntersection(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
void EmptyLanguage(const EventSet &rAlphabet, Generator &rResGen)
void LanguageComplement(Generator &rGen, const EventSet &rAlphabet)
void EmptyStringLanguage(const EventSet &rAlphabet, Generator &rResGen)
void KleeneClosureNonDet(Generator &rGen)
void SelfLoopMarkedStates(Generator &rGen, const EventSet &rAlphabet)
bool IsNonblocking(const GeneratorVector &rGvec)
bool IsPrefixClosed(const Generator &rGen)

libFAUDES 2.33h --- 2025.06.18 --- c++ api documentaion by doxygen