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 wrt specified alphabet.
292  *
293  * Convert a generator marking the language Lm into a formal automaton recognizing Lm
294  * with a dump state representing Sigma*-PrefixClosure(Lm(rGen)). In this function,
295  * Sigma is given by the parameter rAlphabet.
296  * For information about automata, see [Wonham. Supervisory Control of Discrete Event
297  * Systems].
298  * The original generated language is ignored.
299  * Note: An automaton is a deterministic transition structure according to the formal
300  * definition; see also "Determinism" below.
301  * Method:
302  * Uncoaccessible states are erased, as the language generated by rGen is not examined
303  * in this function. A dump state representing "Sigma*-PrefixClosure(Lm)" is created.
304  * Then, the transition relation is completed such that it is fully defined for each
305  * state of rGen and each event of rAlphabet. Formerly undefined transitions lead to
306  * the dump state.
307  *
308  * Determinism:
309  * Input parameter has to be deterministic for correct result. If not, then the
310  * (also nondeterministic) result recognizes the correct language, but the dump state
311  * does not represent "Sigma*-PrefixClosure(Lm)" as it should;
312  * see also example ExAutomaton_basic().
313  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
314  *
315  * No further restrictions on parameters.
316  *
317  * @param rGen
318  * generator that is converted to automaton
319  *
320  * @param rAlphabet
321  * the dump state of the resulting automaton represents the
322  * language L_dump=rAlphabet*-PrefixClosure(Lm(rGen))
323  *
324  * @ingroup GeneratorFunctions
325  */
326 extern FAUDES_API void Automaton(Generator& rGen, const EventSet& rAlphabet);
327 
328 /**
329  * Language complement.
330  *
331  * Convert generator marking the language Lm into generator marking the language
332  * complement of Lm which is defined as Sigma*-Lm. In this function, Sigma is
333  * given by the alphabet of rGen; see also LanguageComplement(rGen,rAlphabet).
334  * The original generated language is ignored.
335  * Method:
336  * This function calls Automaton() first and then inverts the marking of the states
337  * of the result.
338  *
339  * Determinism:
340  * Input parameter has to be deterministic for correct result, see Automaton() for
341  * explanations.
342  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
343  * (by function Automaton()).
344  *
345  * No further restrictions on parameter.
346  *
347  * @param rGen
348  * generator on which the language complement is performed
349  *
350  * <h4>Example:</h4>
351  * <table>
352  * <tr> <td> Generator G </td> <td> LanguageComplement(G) </td> </tr>
353  * <tr>
354  * <td> @image html tmp_boolean_g1.png </td>
355  * <td> @image html tmp_complement_g1.png </td>
356  * </tr>
357  * </table>
358  *
359  *
360  * @ingroup GeneratorFunctions
361  */
362 extern FAUDES_API void LanguageComplement(Generator& rGen);
363 
364 /**
365  * Language complement wrt specified alphabet.
366  *
367  * Convert generator marking the language Lm into generator marking the language
368  * complement of Lm which is defined as Sigma*-Lm. In this function, Sigma is
369  * given by the parameter rAlphabet.
370  * The original generated language is ignored.
371  * Method:
372  * This function calls Automaton() first and then inverts the marking of the states
373  * of the result.
374  *
375  * Determinism:
376  * Input parameter has to be deterministic for correct result, see Automaton() for
377  * explanations.
378  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
379  * (by function Automaton()).
380  *
381  * No further restrictions on parameter.
382  *
383  * @param rGen
384  * generator on which the language complement is performed
385  *
386  * @param rAlphabet
387  * reference alphabet to build the complement
388  *
389  * @ingroup GeneratorFunctions
390  */
391 extern FAUDES_API void LanguageComplement(Generator& rGen, const EventSet& rAlphabet);
392 
393 
394 /**
395  * Language Complement (uniform API wrapper).
396  *
397  * @param rGen
398  * generator on which the language complement is performed
399  *
400  * @param rRes
401  * resulting generator
402  *
403  * @ingroup GeneratorFunctions
404  */
405 extern FAUDES_API void LanguageComplement(const Generator& rGen, Generator& rRes);
406 
407 /**
408  * Language Complement (uniform API wrapper).
409  *
410  * @param rGen
411  * generator on which the language complement is performed
412  *
413  * @param rSigma
414  * reference alphabet to build the complement
415  *
416  * @param rRes
417  * resulting generator
418  *
419  * @ingroup GeneratorFunctions
420  */
421 extern FAUDES_API void LanguageComplement(const Generator& rGen, const EventSet& rSigma, Generator& rRes);
422 
423 
424 
425 /**
426  * Language difference (set-theoretic difference).
427  *
428  * This function calculates Lm1-Lm2 (sometimes also denoted by Lm1\\Lm2), that is the
429  * set of all strings included in Lm1 but not in Lm2.
430  * Method:
431  * The language difference is computed by taking the intersection of Lm1 with the
432  * complement of Lm2.
433  *
434  * Determinism:
435  * Due to the use of LanguageComplement(), rGen2 has to be deterministic.
436  * Result can be nondeterministic only if rGen1 is nondeterministic.
437  *
438  * Restrictions on prameters:
439  * rGen2 has to be deterministic.
440  *
441  * @param rGen1
442  * generator marking the language Lm1
443  * @param rGen2
444  * generator marking the language Lm2
445  * @param rResGen
446  * generator marking the language difference Lm1-Lm2
447  *
448  * @exception Exception
449  * - nondeterministic parameter rGen2 (id 101).
450  *
451  * <h4>Example:</h4>
452  * <table border=0> <tr> <td> <table>
453  * <tr> <td> Generator G1 </td> <td> Generator G2 </td> </tr>
454  * <tr>
455  * <td> @image html tmp_difference_g1.png </td>
456  * <td> @image html tmp_difference_g2.png </td>
457  * </tr>
458  * </table> </td> </tr> <tr> <td> <table width=100%>
459  * <tr> <td> LanguageDifference(G1,G2,Result) </td> </tr>
460  * <tr> <td> @image html tmp_difference_g1minusg2.png </td> </tr>
461  * </table> </td> </tr> </table>
462  *
463  * @ingroup GeneratorFunctions
464  */
465 extern FAUDES_API void LanguageDifference(const Generator& rGen1, const Generator& rGen2,
466  Generator& rResGen);
467 
468 /**
469  * Language concatenation, nondeterministic version.
470  *
471  * With the languages Lm1 and Lm2 marked by rGen1 and rGen2, respectively, the result
472  * rResGen marks the concatenation LmRes=Lm1Lm2.
473  * The languages generated by rGen1 and rGen2 are ignored. It would be possible to let
474  * the result also generate the concatenation of the generated languages; however, this can
475  * produce disproportionate computational overhead, if only the marked languages shall be
476  * concatenated.
477  * Method:
478  * rGen2 is appended to rGen1: first, the initial states of rGen2 are erased. Then,
479  * transitions, that formerly started from the initial state(s) of rGen2, are redirected
480  * and multiplied such that they start from each marked state of rGen1. The marked states
481  * corresponding to rGen2 remain marked. The marked states of rGen1 remain marked only if
482  * rGen2 has at least one marked initial state (i.e. if epsilon is concatenated to Lm1.)
483  *
484  * Determinism:
485  * Input parameters may be nondeterministic. Result can be nondeterministic even if input
486  * parameters are deterministic; see also LanguageConcatenate().
487  *
488  * No restrictions on parameters.
489  *
490  * @param rGen1
491  * generator marking Lm1
492  * @param rGen2
493  * generator marking Lm2
494  * @param rResGen
495  * resulting generator marking the language concatenation Lm1Lm2
496  *
497  * @ingroup GeneratorFunctions
498  */
499 extern FAUDES_API void LanguageConcatenateNonDet(const Generator& rGen1, const Generator& rGen2,
500  Generator& rResGen);
501 
502 /**
503  * Language concatenation, deterministic version.
504  *
505  * With the languages Lm1 and Lm2 marked by rGen1 and rGen2, respectively, the result
506  * rResGen marks the concatenation LmRes=Lm1Lm2.
507  * The languages generated by rGen1 and rGen2 are ignored. It would be possible to let
508  * the result also generate the concatenation of the generated languages; however, this can
509  * produce disproportionate computational overhead, if only the marked languages shall be
510  * concatenated.
511  * Method:
512  * rGen2 is appended to rGen1: first, the initial states of rGen2 are erased. Then,
513  * transitions, that formerly started from the initial state(s) of rGen2, are redirected
514  * and multiplied such that they start from each marked state of rGen1. The marked states
515  * corresponding to rGen2 remain marked. The marked states of rGen1 remain marked only if
516  * rGen2 has at least one marked initial state (i.e. if epsilon is concatenated to Lm1.)
517  *
518  * Determinism:
519  * Input parameters may be nondeterministic.
520  * This function calls LanguageUnionNonDet() and then Deterministic() to convert the
521  * result into a deterministic generator. Note that this conversion is usually
522  * straightforward, but there exist theoretical worst-case examples of exponential complexity.
523  *
524  * No restrictions on parameters.
525  *
526  * @param rGen1
527  * generator marking Lm1
528  * @param rGen2
529  * generator marking Lm2
530  * @param rResGen
531  * Resulting generator marking the language concatenation Lm1Lm2
532  *
533  * <h4>Example:</h4>
534  * <table border=0> <tr> <td> <table>
535  * <tr> <td> Generator G1 </td> <td> </td> <td> LanguageConcatenate(G1,G3,Result) </td> </tr>
536  * <tr>
537  * <td> @image html tmp_concat_g1.png </td>
538  * <td> </td>
539  * <td> @image html tmp_concat_g1g3.png </td>
540  * </tr>
541  * <tr> <td> Generator G2 </td> <td> </td> <td> LanguageConcatenate(G1,G4,Result) </td> </tr>
542  * <tr>
543  * <td> @image html tmp_concat_g2.png </td>
544  * <td> </td>
545  * <td> @image html tmp_concat_g1g4.png </td>
546  * </tr>
547  * </tr>
548  * <tr> <td> Generator G3 </td> <td> </td> <td> LanguageConcatenate(G2,G3,Result) </td> </tr>
549  * <tr>
550  * <td> @image html tmp_concat_g3.png </td>
551  * <td> </td>
552  * <td> @image html tmp_concat_g2g3.png </td>
553  * </tr>
554  * </tr>
555  * <tr> <td> Generator G4 </td> <td> </td> <td> LanguageConcatenate(G2,G4,Result) </td> </tr>
556  * <tr>
557  * <td> @image html tmp_concat_g4.png </td>
558  * <td> </td>
559  * <td> @image html tmp_concat_g2g4.png </td>
560  * </tr>
561  * </table> </td> </tr> </table>
562  *
563  * @ingroup GeneratorFunctions
564  */
565 extern FAUDES_API void LanguageConcatenate(const Generator& rGen1, const Generator& rGen2,
566  Generator& rResGen);
567 
568 /**
569  * Full Language, L(G)=Lm(G)=Sigma*.
570  *
571  * Construct generator generating and marking full language Sigma* from alphabet Sigma.
572  * Method: this function creates a generator with one state that is marked and init state. This
573  * state is selflooped with all events from rAlphabet.
574  *
575  * @param rAlphabet
576  * Alphabet Sigma from which full language Sigma* is built
577  * @param rResGen
578  * Generator generating and marking full language Sigma*
579  *
580  * <h4>Example:</h4>
581  * <table>
582  * <tr> <td> FullLanguage(Sigma={a,b},Result) </td> </tr>
583  * <tr>
584  * <td> @image html tmp_languagesFull_result.png </td>
585  * </tr>
586  * </table>
587  *
588  * @ingroup GeneratorFunctions
589  */
590 extern FAUDES_API void FullLanguage(const EventSet& rAlphabet, Generator& rResGen);
591 
592 /**
593  * Alphabet Language, L(G)=Lm(G)=Sigma
594  *
595  * Construct generator generating and marking an alphabet as languages, that is L(G)=Lm(G)=Sigma.
596  * Method: this function creates a generator with one init state and one marked state. For each
597  * event from rAlphabet, a transition is inserted leading from the init state to the marked state.
598  *
599  * No restrictions on parameters.
600  *
601  * @param rAlphabet
602  * alphabet from which alphabet language is built
603  * @param rResGen
604  * generator with languages Lm(G)=Sigma
605  *
606  * <h4>Example:</h4>
607  * <table>
608  * <tr> <td> AlphabetLanguage(Sigma={a,b},Result) </td> </tr>
609  * <tr>
610  * <td> @image html tmp_languagesAlphabet_result.png </td>
611  * </tr>
612  * </table>
613  *
614  * @ingroup GeneratorFunctions
615  */
616 extern FAUDES_API void AlphabetLanguage(const EventSet& rAlphabet, Generator& rResGen);
617 
618 /**
619  * Empty string language, L(G)=Lm(G)={epsilon}.
620  *
621  * Construct generator generating and marking the empty string, that is L(G)=Lm(G)={epsilon}.
622  * Method: this function creates a generator with one marked init state and the alphabet rAlphabet.
623  *
624  * No restrictions on parameters.
625  *
626  * @param rAlphabet
627  * alphabet of the resulting generator
628  * @param rResGen
629  * generator with languages L(G)=Lm(G)={epsilon} and alphabet rAlphabet
630  *
631  * <h4>Example:</h4>
632  * <table>
633  * <tr> <td> EmptyStringLanguage(Sigma={a,b},Result) </td> </tr>
634  * <tr>
635  * <td> @image html tmp_languagesEmptyString_result.png </td>
636  * </tr>
637  * </table>
638  *
639  * @ingroup GeneratorFunctions
640  */
641 extern FAUDES_API void EmptyStringLanguage(const EventSet& rAlphabet, Generator& rResGen);
642 
643 /**
644  * Empty language Lm(G)={}.
645  *
646  * Construct generator and marking the empty language, that is Lm(G)={}.
647  * Method: this function creates a deterministic generator with one initial state that is not marked.
648  * The alphabet is set as specified.
649  *
650  * No restrictions on parameters.
651  *
652  * @param rAlphabet
653  * Alphabet of the resulting generator
654  * @param rResGen
655  * Generator with language Lm(G)={}
656  *
657  * @ingroup GeneratorFunctions
658  */
659 extern FAUDES_API void EmptyLanguage(const EventSet& rAlphabet, Generator& rResGen);
660 
661 /**
662  * Test for Empty language Lm(G)=={}.
663  *
664  * Tests if the language marked by rGen is empty, that is if Lm(G)=={}. The generated
665  * language L(G) is not considered.
666  * Method:
667  * This function tests if
668  * a) the set of marked states is empty or else
669  * b) the intersection of the set of accessible states and the set of marked states
670  * is empty, i.e. if there is no marked state or if no marked state is accessible (reachable).
671  *
672  * No restrictions on parameter.
673  *
674  * @param rGen
675  * generator to be tested for empty marked language
676  *
677  * @return
678  * true on empty marked language, false on nonempty marked language
679  *
680  * @ingroup GeneratorFunctions
681  */
682 extern FAUDES_API bool IsEmptyLanguage(const Generator& rGen);
683 
684 /**
685  * Test language inclusion, Lm1<=Lm2.
686  *
687  * Test if language Lm1 marked by rGen1 is included in language Lm2 marked by rGen2. The
688  * generated languages are not considered.
689  * Method:
690  * This function checks if there is no string in Lm1 that is not in Lm2 by testing if
691  * the intersection of Lm1 and the language complement of Lm2 is empty.
692  *
693  * Restrictions on parameters: rGen2 has to be deterministic!
694  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
695  * (by function Automaton()).
696  *
697  * Determinism: correctness in case of nondeterministic parameter rGen1 has been tested with an
698  * example (see ExInclusion_simple), but not proven.
699  *
700  * ToDo: implement faster version using a variant of Product():
701  * compute product without storing result, return false as soon as some event is
702  * possible in Lm2 but not in Lm1.
703  *
704  * @param rGen1
705  * generator marking Lm1
706  * @param rGen2
707  * generator marking Lm2
708  *
709  * @return
710  * true if language marked by rGen1 is included in language marked by rGen2
711  *
712  * @ingroup GeneratorFunctions
713  */
714 extern FAUDES_API bool LanguageInclusion(const Generator& rGen1, const Generator& rGen2);
715 
716 /**
717  * Language equality, Lm1==Lm2.
718  *
719  * Test if the language Lm1 marked by rGen1 equals the language Lm2 marked by rGen2. The
720  * generated languages are not considered.
721  * Method:
722  * This function checks mutual inclusion of Lm1 in Lm2 and of Lm2 in Lm1 using the
723  * function LanguageInclusion().
724  *
725  * Restrictions on parameters: rGen1 and rGen2 have to be deterministic!
726  * If FAUDES_CHECKED is defined a warning on non-deterministic input is issued.
727  * (by function Automaton()).
728  *
729  * ToDo: implement faster, version using a variant of Product():
730  * compute product without storing result, return false as soon as rGen1 and rGen2
731  * "disagree" on the occurrence of some event.
732  *
733  * @param rGen1
734  * generator marking Lm1
735  * @param rGen2
736  * generator marking Lm2
737  *
738  * @return
739  * true if the language marked by rGen1 equals the language marked by rGen2
740  *
741  * @ingroup GeneratorFunctions
742  */
743 extern FAUDES_API bool LanguageEquality(const Generator& rGen1, const Generator& rGen2);
744 
745 /**
746  * Kleene Closure.
747  *
748  * This function computes the Kleene Closure ( ()* - operator) of the
749  * language marked by rGen. The generated language is not considered.
750  * Method: KleeneClosureNonDet() is called, which, for all transitions
751  * leading from a state x to a marked state, inserts a transition with the
752  * same event starting from x and leading to (one of) the initial state(s).
753  * As this step causes nondeterminism, the function Deterministic() is called.
754  * See also KleeneClosureNonDet().
755  *
756  * No restrictions on parameter.
757  *
758  * @param rGen
759  * generator marking the language Lm to which the Kleene Closure is applied
760  *
761  * <h4>Example:</h4>
762  * <table>
763  * <tr> <td> Generator G </td> <td> KleeneClosure(G) </td> </tr>
764  * <tr>
765  * <td> @image html tmp_kleene_g.png </td>
766  * <td> @image html tmp_kleene_gRes.png </td>
767  * </tr>
768  * </table>
769  *
770  * @ingroup GeneratorFunctions
771  */
772 extern FAUDES_API void KleeneClosure(Generator& rGen);
773 
774 /**
775  * Kleene Closure.
776  *
777  * This function is a convenience wrapper for KleeneClosure(Generator&).
778  *
779  *
780  * @ingroup GeneratorFunctions
781  */
782 extern FAUDES_API void KleeneClosure(const Generator& rGen, Generator& rResGen);
783 
784 /**
785  * Kleene Closure, nondeterministic version.
786  *
787  * This function computes the Kleene Closure ( ()* - operator) of the
788  * language marked by rGen. The generated language is not considered.
789  * Method: KleeneClosureNonDet() is called, which, for all transitions
790  * leading from a state x to a marked state, inserts a transition with the
791  * same event starting from x and leading to (one of) the initial state(s).
792  *
793  * @param rGen
794  * generator marking the language Lm to which Kleene Closure is applied
795  *
796  * @ingroup GeneratorFunctions
797  */
798 extern FAUDES_API void KleeneClosureNonDet(Generator& rGen);
799 
800 /**
801  * Prefix Closure.
802  *
803  * This function computes the prefix closure the language Lm marked by rGen. A
804  * language Lm is prefix closed if each string of Lm implies that all its
805  * prefixes are also element of Lm. The prefix closure of a language marked by
806  * a generator is always a subset of the generated language and is represented
807  * by the set of coaccessible states of the generator.
808  * Method:
809  * First, Coaccessible() is called to erase all states of rGen that do not
810  * represent prefixes of marked strings. Then, all remaining states are marked.
811  *
812  * No restrictions on parameter.
813  *
814  * ToDo: (slightly) more efficient version: implement generator function
815  * CoAccessibleSet() similar to AccessibleSet() and call
816  * InjectMarkedStates(AccessibleSet()).
817  *
818  * @param rGen
819  * generator marking the language Lm to which prefix closure is applied
820  *
821  * <h4>Example:</h4>
822  * <table>
823  * <tr> <td> Generator G </td> <td> PrefixClosure(G) </td> </tr>
824  * <tr>
825  * <td> @image html tmp_prefixclosure_g.png </td>
826  * <td> @image html tmp_prefixclosure_gRes.png </td>
827  * </tr>
828  * </table>
829  *
830  * @ingroup GeneratorFunctions
831  */
832 extern FAUDES_API void PrefixClosure(Generator& rGen);
833 
834 
835 /**
836  * Test for prefix closed marked language.
837  *
838  * This function tests whether the language Lm(G) marked by the specified generator G
839  * is prefix closed. It does so by testing whether all accessible and coaccessible
840  * states are marked.
841  *
842  * The specified generator must be deterministic.
843  *
844  * @param rGen
845  * generator G marking the Lm(G) to test
846  * @return
847  * True <> Lm(G) is prefix closed
848  *
849  * @ingroup GeneratorFunctions
850  */
851 extern FAUDES_API bool IsPrefixClosed(const Generator& rGen);
852 
853 
854 /**
855  * Test for nonblocking generator
856  *
857  * A generator G is nonblocking if closure(Lm(G)) = L(G), i.e.
858  * if every accessible state is coacessile.
859  *
860  * The specified generator must be deterministic.
861  *
862  * @param rGen
863  * generator G marking to test
864  * @return
865  * True <> G is nonblocking
866  *
867  * @ingroup GeneratorFunctions
868  */
869 extern FAUDES_API bool IsNonblocking(const Generator& rGen);
870 
871 /**
872  * Test for nonblocking marked languages.
873  *
874  * Two languages L1 and L2 are nonblocking, if
875  * closure(L1 || L2) == closure(L1) || closure(L2).
876  *
877  * This function performs the parallel composition of the two
878  * specified generators and tests it for nonblockingness. Provided
879  * that both generators are trim, this is equivalent to the
880  * respective marked languages being nonblocking.
881  *
882  * The specified generators must be trim.
883  *
884  * @param rGen1
885  * Generator G1
886  * @param rGen2
887  * Generator G2
888  * @return
889  * True <> Lm(G1) and Lm(G2) are nonblocking
890  *
891  * @ingroup GeneratorFunctions
892  */
893 extern FAUDES_API bool IsNonblocking(const Generator& rGen1, const Generator& rGen2);
894 
895 
896 /**
897  * Self-loop all states.
898  *
899  * This function selfoops all states of rGen with the events from rAlphabet.
900  * Method:
901  * The alphabet of rGen is extended by rAlphabet. For each state x of rGen
902  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
903  * irrespective of whether this event was already active in x before.
904  * See also SelfLoop(rGen,rAlphabet,rStates) and SelfLoopMarkedStates(rGen,rAlphabet).
905  *
906  * No restrictions on parameter.
907  *
908  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
909  * before, or if rGen already contains one or more (non selfloop) transitions with
910  * events from rAlphabet.
911  *
912  * @param rGen
913  * generator to be selflooped with events from rAlphabet
914  * @param rAlphabet
915  * alphabet with selfloop events
916  *
917  * <h4>Example:</h4>
918  * <table>
919  * <tr> <td> Generator G </td> <td> SelfLoop(G,Sigma={e,f}) </td> </tr>
920  * <tr>
921  * <td> @image html tmp_selfloop_g.png </td>
922  * <td> @image html tmp_selfloop_gRes.png </td>
923  * </tr>
924  * </table>
925  *
926  * @ingroup GeneratorFunctions
927  */
928 extern FAUDES_API void SelfLoop(Generator& rGen,const EventSet& rAlphabet);
929 
930 /**
931  * Self-loop all marked states.
932  *
933  * This function selfoops all marked states of rGen with the events from rAlphabet.
934  * Method:
935  * The alphabet of rGen is extended by rAlphabet. For each marked state x of rGen
936  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
937  * irrespective of whether this event was already active in x before.
938  * See also SelfLoop(rGen,rAlphabet) and SelfLoop(rGen,rAlphabet,rStates).
939  *
940  * No restrictions on parameter.
941  *
942  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
943  * before, or if rGen already contains one or more (non selfloop) transitions
944  * starting from a marked state with events from rAlphabet.
945  *
946  * @param rGen
947  * generator with marked states to be selflooped with events from rAlphabet
948  * @param rAlphabet
949  * alphabet with selfloop events
950  *
951  * <h4>Example:</h4>
952  * <table>
953  * <tr> <td> Generator G </td> <td> SelfLoopMarkedStates(G,Sigma={e,f}) </td> </tr>
954  * <tr>
955  * <td> @image html tmp_selfloop_g.png </td>
956  * <td> @image html tmp_selfloopMarked_gRes.png </td>
957  * </tr>
958  * </table>
959  *
960  * @ingroup GeneratorFunctions
961  */
962 extern FAUDES_API void SelfLoopMarkedStates(Generator& rGen,const EventSet& rAlphabet);
963 
964 /**
965  * Self-loop specified states.
966  *
967  * This function selfoops the states rStates of rGen with the events from rAlphabet.
968  * Method:
969  * The alphabet of rGen is extended by rAlphabet. For each state x of rStates
970  * and each event alpha of rAlphabet, a transition (x,alpha,x) is inserted,
971  * irrespective of whether this event was already active in x before.
972  * See also SelfLoop(rGen,rAlphabet) and SelfLoopMarkedStates(rGen,rAlphabet).
973  *
974  * No restrictions on parameter.
975  *
976  * Determinism: resulting generator is nondeterministic, if it was nondeterministic
977  * before, or if rGen already contains one or more (non selfloop) transitions
978  * starting from a state of rState with events from rAlphabet.
979  *
980  * @param rGen
981  * generator with marked states to be selflooped with events from rAlphabet
982  * @param rAlphabet
983  * alphabet with selfloop events
984  * @param rStates
985  * states to apply selfloop
986  *
987  * @exception Exception
988  * - rStates is not a subset of rGen.States() (id 100).
989  *
990  * <h4>Example:</h4>
991  * <table>
992  * <tr> <td> Generator G </td> <td> SelfLoop(G,Sigma={e,f},G.InitStates()) </td> </tr>
993  * <tr>
994  * <td> @image html tmp_selfloop_g.png </td>
995  * <td> @image html tmp_selfloopInit_gRes.png </td>
996  * </tr>
997  * </table>
998  *
999  * @ingroup GeneratorFunctions
1000  */
1001 extern FAUDES_API void SelfLoop(Generator& rGen,const EventSet& rAlphabet,const StateSet& rStates);
1002 
1003 
1004 
1005 
1006 } // namespace faudes
1007 
1008 #define FAUDES_REGULAR_H
1009 #endif
1010 
Compiletime options.
parallel composition
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
language projection
IndexSet StateSet
Definition: cfl_indexset.h:273
NameSet EventSet
Convenience typedef for plain event sets.
Definition: cfl_nameset.h:533
vGenerator Generator
Plain generator, api typedef for generator with no attributes.
TBaseVector< Generator > GeneratorVector
Convenience typedef for vectors og generators.
bool EmptyLanguageIntersection(const Generator &rGen1, const Generator &rGen2)
Test for empty language intersection (same as Disjoind()).
void FullLanguage(const EventSet &rAlphabet, Generator &rResGen)
Full Language, L(G)=Lm(G)=Sigma*.
void LanguageUnion(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language union, deterministic version.
void LanguageConcatenateNonDet(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language concatenation, nondeterministic version.
void SelfLoop(Generator &rGen, const EventSet &rAlphabet)
Self-loop all states.
bool LanguageDisjoint(const Generator &rGen1, const Generator &rGen2)
Test whether two languages are disjoint.
bool LanguageInclusion(const Generator &rGen1, const Generator &rGen2)
Test language inclusion, Lm1<=Lm2.
void KleeneClosure(Generator &rGen)
Kleene Closure.
void PrefixClosure(Generator &rGen)
Prefix Closure.
void LanguageUnionNonDet(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language union, nondeterministic version.
Definition: cfl_regular.cpp:45
void Automaton(Generator &rGen, const EventSet &rAlphabet)
Convert generator to automaton wrt specified alphabet.
void AlphabetLanguage(const EventSet &rAlphabet, Generator &rResGen)
Alphabet Language, L(G)=Lm(G)=Sigma.
void LanguageConcatenate(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language concatenation, deterministic version.
bool IsEmptyLanguage(const Generator &rGen)
Test for Empty language Lm(G)=={}.
bool LanguageEquality(const Generator &rGen1, const Generator &rGen2)
Language equality, Lm1==Lm2.
void LanguageDifference(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language difference (set-theoretic difference).
void LanguageIntersection(const Generator &rGen1, const Generator &rGen2, Generator &rResGen)
Language intersection.
bool IsPrefixClosed(const Generator &rGen)
Test for prefix closed marked language.
void EmptyLanguage(const EventSet &rAlphabet, Generator &rResGen)
Empty language Lm(G)={}.
void LanguageComplement(Generator &rGen, const EventSet &rAlphabet)
Language complement wrt specified alphabet.
void EmptyStringLanguage(const EventSet &rAlphabet, Generator &rResGen)
Empty string language, L(G)=Lm(G)={epsilon}.
void KleeneClosureNonDet(Generator &rGen)
Kleene Closure, nondeterministic version.
void SelfLoopMarkedStates(Generator &rGen, const EventSet &rAlphabet)
Self-loop all marked states.
libFAUDES resides within the namespace faudes.
bool IsNonblocking(const GeneratorVector &rGvec)

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen