CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Views: 418346
1
2
3 Rational languages
3
4
Rational languages are conveniently represented through rational
5
expressions. These are finite expressions involving letters of the alphabet;
6
concatenation, corresponding to the product; the symbol U, corresponding to
7
the union; and the symbol *, corresponding to the Kleene's star.
8
9
10
3.1 Rational Expressions
11
12
The expressions @ and "empty\_set" are used to represent the empty word and
13
the empty set respectively.
14
15
3.1-1 RationalExpression
16
17
RationalExpression( expr[, alph] )  function
18
19
A rational expression can be created using the function RationalExpression.
20
expr is a string representing the desired expression literally and alph (may
21
or may not be present) is the alphabet of the expression. Of course alph
22
must not contain the symbols '@', '(', ')', '*' nor 'U'. When alph is not
23
present, the alphabet of the rational expression is the set of symbols
24
(other than '"', etc...) occurring in the expression. (The alphabet is then
25
ordered with the alphabetical order.)
26
27
 Example 
28
gap> RationalExpression("abUc");
29
abUc
30
gap> RationalExpression("ab*Uc");
31
ab*Uc
32
gap> RationalExpression("001U1*");
33
001U1*
34
gap> RationalExpression("001U1*","012");
35
001U1*
36

37
38
3.1-2 RatExpOnnLetters
39
40
RatExpOnnLetters( n, operation, list )  function
41
42
This is another way to construct a rational expression over an alphabet. The
43
user may specify the alphabet or just give the number n of letters (in this
44
case the alphabet {a,b,c,...} is considered). operation is the name of an
45
operation, the possibilities being: product, union or star. list is a list
46
of rational expressions, a rational expression in the case of ``star'', or a
47
list consisting of an integer when the rational expression is a single
48
letter. The empty list [ ] and empty\_set are other possibilities for list.
49
An example follows
50
51
 Example 
52
gap> RatExpOnnLetters(2,"star",RatExpOnnLetters(2,"product",
53
> [RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,"union",
54
> [RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,[],[2])])])); 
55
(a(aUb))*
56

57
58
The empty word and the empty set are the rational expressions:
59
60
 Example 
61
gap> RatExpOnnLetters(2,[],[]); 
62
@
63
gap> RatExpOnnLetters(2,[],"empty_set");
64
empty_set
65

66
67
3.1-3 RandomRatExp
68
69
RandomRatExp( arg )  function
70
71
Given the number of symbols of the alphabet and (possibly) a factor m which
72
is intended to increase the randomality of the expression, returns a pseudo
73
random rational expression over that alphabet.
74
75
 Example 
76
gap> RandomRatExp(2);
77
b*(@Ua)
78
gap> RandomRatExp("01");
79
empty_set
80
gap> RandomRatExp("01");
81
(0U1)*
82
gap> RandomRatExp("01",7);
83
0*1(@U0U1)
84

85
86
3.1-4 SizeRatExp
87
88
SizeRatExp( r )  function
89
90
Returns the size, i.e. the number of symbols of the alphabet, of the
91
rational expression r.
92
93
 Example 
94
gap> a:=RationalExpression("0*1(@U0U1)");
95
0*1(@U0U1)
96
gap> SizeRatExp(a);
97
5
98

99
100
3.1-5 IsRationalExpression
101
102
IsRationalExpression( r )  function
103
104
Tests whether an object is a rational expression.
105
106
 Example 
107
gap> r := RandomRatExp("01",7);
108
1(0U1)U@
109
gap> IsRatExpOnnLettersObj(r) and IsRationalExpressionRep(r);
110
true
111
gap> IsRationalExpression(RandomRatExp("01"));
112
true
113

114
115
3.1-6 AlphabetOfRatExp
116
117
AlphabetOfRatExp( R )  function
118
119
Returns the number of symbols in the alphabet of the rational expression R.
120
121
 Example 
122
gap> r:=RandomRatExp(2);
123
a*(ba*U@)
124
gap> AlphabetOfRatExp(r);
125
2
126
gap> r:=RandomRatExp("01");
127
1*(01*U@)
128
gap> AlphabetOfRatExp(r);
129
2
130
gap> a:=RandomTransformation(3);;
131
gap> b:=RandomTransformation(3);;
132
gap> r:=RandomRatExp([a,b]);
133
(Transformation( [ 1, 1, 3 ] )UTransformation( [ 1, 1, 2 ] ))*
134
gap> AlphabetOfRatExp(r);
135
2
136

137
138
3.1-7 AlphabetOfRatExpAsList
139
140
AlphabetOfRatExpAsList( R )  function
141
142
Returns the alphabet of the rational expression R always as a list. If the
143
alphabet of the rational expression is given by means of an integer less
144
than 27 it returns the list "abcd....", otherwise returns [ "a1", "a2",
145
"a3", "a4", ... ].
146
147
 Example 
148
gap> r:=RandomRatExp(2);
149
(aUb)((aUb)(bU@)U@)U@
150
gap> AlphabetOfRatExpAsList(r);
151
"ab"
152
gap> r:=RandomRatExp("01");
153
1*(0U@)
154
gap> AlphabetOfRatExpAsList(r);
155
"01"
156
gap> r:=RandomRatExp(30);;
157
gap> AlphabetOfRatExpAsList(r);
158
[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", 
159
"a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", 
160
"a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ]
161

162
163
3.1-8 CopyRatExp
164
165
CopyRatExp( R )  function
166
167
Returns a new rational expression, which is a copy of R.
168
169
 Example 
170
gap> r:=RandomRatExp(2);
171
a*(bU@)
172
gap> CopyRatExp(r);
173
a*(bU@)
174

175
176
177
3.2 Comparison of rational expressions
178
179
The way two rational expressions r1 and r2 are compared through the operator
180
is the following: the empty set is lesser than everything else; if r1 and r2
181
are letters, then the lesser is taken from the order in the alphabet; if r1
182
is a letter an r2 a product, union or star, then r1 is lesser than r2; a
183
star expression is considered to be lesser than a product or union
184
expression and a product lesser than a union; to compare two star
185
expressions we compare the expressions under the stars; to compare two
186
product or union expressions we compare the subexpressions of each
187
expression from left to right;
188
189
190
3.3 Operations with rational languages
191
192
Only operations with rational languages over the same alphabet are allowed.
193
194
We may compute expressions for the product, union and star (i.e., submonoid
195
generated by) of rational sets. In some cases, simpler expressions
196
representing the same set are returned. Note that that two simplifications
197
are always made, namely, and . Of course, these operations may be used to
198
construct more complex expressions. For rational expressions we have the
199
functions UnionRatExp, ProductRatExp, StarRatExp, that return respectively
200
rational expressions for the union and product of the languages given by the
201
rational expressions r and s and the star of the language given by the
202
rational expression r.
203
204
3.3-1 UnionRatExp
205
206
UnionRatExp( r, s )  function
207
3.3-2 ProductRatExp
208
209
ProductRatExp( r, s )  function
210
3.3-3 StarRatExp
211
212
 StarRatExp( r )  function
213
214
The expression (a(aUb))* may be produced in the following way
215
216
 Example 
217
gap> r1 := RatExpOnnLetters(2,[],[1]); 
218
a
219
gap> r2 := RatExpOnnLetters(2,[],[2]);
220
b
221
gap> r3 := UnionRatExp(r1,r2);
222
aUb
223
gap> r4 := ProductRatExp(r1,r3);
224
a(aUb)
225
gap> r5 := StarRatExp(r4);
226
(a(aUb))*
227

228
229
230