  
  [1X3 [33X[0;0YRational languages[133X[101X
  
  [33X[0;0YRational   languages   are   conveniently   represented   through   rational
  expressions. These are finite expressions involving letters of the alphabet;
  [10Xconcatenation[110X,  corresponding to the [13Xproduct[113X; the symbol [10XU[110X, corresponding to
  the [13Xunion[113X; and the symbol [10X*[110X, corresponding to the Kleene's star.[133X
  
  
  [1X3.1 [33X[0;0YRational Expressions[133X[101X
  
  [33X[0;0YThe  expressions [10X@[110X and [10X"empty\_set"[110X are used to represent the empty word and
  the empty set respectively.[133X
  
  [1X3.1-1 RationalExpression[101X
  
  [33X[1;0Y[29X[2XRationalExpression[102X( [3Xexpr[103X[, [3Xalph[103X] ) [32X function[133X
  
  [33X[0;0YA  rational expression can be created using the function [10XRationalExpression[110X.
  [3Xexpr[103X is a string representing the desired expression literally and [3Xalph[103X (may
  or  may  not  be  present) is the alphabet of the expression. Of course [3Xalph[103X
  must  not  contain  the symbols '@', '(', ')', '*' nor 'U'. When [3Xalph[103X is not
  present,  the  alphabet  of  the  rational  expression is the set of symbols
  (other  than '"', etc...) occurring in the expression. (The alphabet is then
  ordered with the alphabetical order.)[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRationalExpression("abUc");[127X[104X
    [4X[28XabUc[128X[104X
    [4X[25Xgap>[125X [27XRationalExpression("ab*Uc");[127X[104X
    [4X[28Xab*Uc[128X[104X
    [4X[25Xgap>[125X [27XRationalExpression("001U1*");[127X[104X
    [4X[28X001U1*[128X[104X
    [4X[25Xgap>[125X [27XRationalExpression("001U1*","012");[127X[104X
    [4X[28X001U1*[128X[104X
  [4X[32X[104X
  
  [1X3.1-2 RatExpOnnLetters[101X
  
  [33X[1;0Y[29X[2XRatExpOnnLetters[102X( [3Xn[103X, [3Xoperation[103X, [3Xlist[103X ) [32X function[133X
  
  [33X[0;0YThis is another way to construct a rational expression over an alphabet. The
  user  may specify the alphabet or just give the number [22Xn[122X of letters (in this
  case  the  alphabet  [22X{a,b,c,...}[122X is considered). [3Xoperation[103X is the name of an
  operation,  the  possibilities being: [10Xproduct[110X, [10Xunion[110X or [10Xstar[110X. [3Xlist[103X is a list
  of rational expressions, a rational expression in the case of ``star'', or a
  list  consisting  of  an  integer  when  the rational expression is a single
  letter.  The empty list [10X[ ][110X and [10Xempty\_set[110X are other possibilities for [10Xlist[110X.
  An example follows[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRatExpOnnLetters(2,"star",RatExpOnnLetters(2,"product",[127X[104X
    [4X[25X>[125X [27X[RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,"union",[127X[104X
    [4X[25X>[125X [27X[RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,[],[2])])]));      [127X[104X
    [4X[28X(a(aUb))*[128X[104X
  [4X[32X[104X
  
  [33X[0;0YThe empty word and the empty set are the rational expressions:[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRatExpOnnLetters(2,[],[]);         [127X[104X
    [4X[28X@[128X[104X
    [4X[25Xgap>[125X [27XRatExpOnnLetters(2,[],"empty_set");[127X[104X
    [4X[28Xempty_set[128X[104X
  [4X[32X[104X
  
  [1X3.1-3 RandomRatExp[101X
  
  [33X[1;0Y[29X[2XRandomRatExp[102X( [3Xarg[103X ) [32X function[133X
  
  [33X[0;0YGiven  the number of symbols of the alphabet and (possibly) a factor [22Xm[122X which
  is  intended to increase the randomality of the expression, returns a pseudo
  random rational expression over that alphabet.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27XRandomRatExp(2);[127X[104X
    [4X[28Xb*(@Ua)[128X[104X
    [4X[25Xgap>[125X [27XRandomRatExp("01");[127X[104X
    [4X[28Xempty_set[128X[104X
    [4X[25Xgap>[125X [27XRandomRatExp("01");[127X[104X
    [4X[28X(0U1)*[128X[104X
    [4X[25Xgap>[125X [27XRandomRatExp("01",7);[127X[104X
    [4X[28X0*1(@U0U1)[128X[104X
  [4X[32X[104X
  
  [1X3.1-4 SizeRatExp[101X
  
  [33X[1;0Y[29X[2XSizeRatExp[102X( [3Xr[103X ) [32X function[133X
  
  [33X[0;0YReturns  the  size,  i.e.  the  number  of  symbols  of the alphabet, of the
  rational expression [3Xr[103X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xa:=RationalExpression("0*1(@U0U1)");[127X[104X
    [4X[28X0*1(@U0U1)[128X[104X
    [4X[25Xgap>[125X [27XSizeRatExp(a);[127X[104X
    [4X[28X5[128X[104X
  [4X[32X[104X
  
  [1X3.1-5 IsRationalExpression[101X
  
  [33X[1;0Y[29X[2XIsRationalExpression[102X( [3Xr[103X ) [32X function[133X
  
  [33X[0;0YTests whether an object is a rational expression.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xr := RationalExpression("1(0U1)U@");[127X[104X
    [4X[28X1(0U1)U@[128X[104X
    [4X[25Xgap>[125X [27XIsRatExpOnnLettersObj(r) and IsRationalExpressionRep(r);[127X[104X
    [4X[28Xtrue[128X[104X
    [4X[25Xgap>[125X [27XIsRationalExpression(RandomRatExp("01"));[127X[104X
    [4X[28Xtrue[128X[104X
  [4X[32X[104X
  
  [1X3.1-6 AlphabetOfRatExp[101X
  
  [33X[1;0Y[29X[2XAlphabetOfRatExp[102X( [3XR[103X ) [32X function[133X
  
  [33X[0;0YReturns the number of symbols in the alphabet of the rational expression [10XR[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X
    [4X[28Xa*(ba*U@)[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp("01");[127X[104X
    [4X[28X1*(01*U@)[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X
    [4X[28X2[128X[104X
    [4X[25Xgap>[125X [27Xa:=RandomTransformation(3);;[127X[104X
    [4X[25Xgap>[125X [27Xb:=RandomTransformation(3);;[127X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp([a,b]);[127X[104X
    [4X[28X(Transformation( [ 1, 1, 3 ] )UTransformation( [ 1, 1, 2 ] ))*[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X
    [4X[28X2[128X[104X
  [4X[32X[104X
  
  [1X3.1-7 AlphabetOfRatExpAsList[101X
  
  [33X[1;0Y[29X[2XAlphabetOfRatExpAsList[102X( [3XR[103X ) [32X function[133X
  
  [33X[0;0YReturns  the  alphabet of the rational expression [10XR[110X always as a list. If the
  alphabet  of  the  rational  expression is given by means of an integer less
  than  27  it  returns  the  list [10X"abcd...."[110X, otherwise returns [10X[ "a1", "a2",
  "a3", "a4", ... ][110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X
    [4X[28X(aUb)((aUb)(bU@)U@)U@[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X
    [4X[28X"ab"[128X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp("01");[127X[104X
    [4X[28X1*(0U@)[128X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X
    [4X[28X"01"[128X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp(30);;[127X[104X
    [4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X
    [4X[28X[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", [128X[104X
    [4X[28X"a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", [128X[104X
    [4X[28X"a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ][128X[104X
  [4X[32X[104X
  
  [1X3.1-8 CopyRatExp[101X
  
  [33X[1;0Y[29X[2XCopyRatExp[102X( [3XR[103X ) [32X function[133X
  
  [33X[0;0YReturns a new rational expression, which is a copy of [10XR[110X.[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X
    [4X[28Xa*(bU@)[128X[104X
    [4X[25Xgap>[125X [27XCopyRatExp(r);[127X[104X
    [4X[28Xa*(bU@)[128X[104X
  [4X[32X[104X
  
  
  [1X3.2 [33X[0;0YComparison of rational expressions[133X[101X
  
  [33X[0;0YThe way two rational expressions [10Xr1[110X and [10Xr2[110X are compared through the operator
  is the following: the empty set is lesser than everything else; if r1 and r2
  are  letters, then the lesser is taken from the order in the alphabet; if r1
  is  a  letter  an  r2 a product, union or star, then r1 is lesser than r2; a
  star  expression  is  considered  to  be  lesser  than  a  product  or union
  expression  and  a  product  lesser  than  a  union;  to  compare  two  star
  expressions  we  compare  the  expressions  under  the stars; to compare two
  product   or  union  expressions  we  compare  the  subexpressions  of  each
  expression from left to right;[133X
  
  
  [1X3.3 [33X[0;0YOperations with rational languages[133X[101X
  
  [33X[0;0YOnly operations with rational languages over the same alphabet are allowed.[133X
  
  [33X[0;0YWe  may compute expressions for the [10Xproduct[110X, [10Xunion[110X and [10Xstar[110X (i.e., submonoid
  generated   by)  of  rational  sets.  In  some  cases,  simpler  expressions
  representing  the  same set are returned. Note that that two simplifications
  are  always  made,  namely, and . Of course, these operations may be used to
  construct  more  complex  expressions.  For rational expressions we have the
  functions  [10XUnionRatExp[110X,  [10XProductRatExp[110X, [10XStarRatExp[110X, that return respectively
  rational expressions for the [13Xunion[113X and [13Xproduct[113X of the languages given by the
  rational  expressions  [10Xr[110X  and  [10Xs[110X  and  the [10Xstar[110X of the language given by the
  rational expression [10Xr[110X.[133X
  
  [1X3.3-1 UnionRatExp[101X
  
  [33X[1;0Y[29X[2XUnionRatExp[102X( [3Xr[103X, [3Xs[103X ) [32X function[133X
  [1X3.3-2 ProductRatExp[101X
  
  [33X[1;0Y[29X[2XProductRatExp[102X( [3Xr[103X, [3Xs[103X ) [32X function[133X
  [1X3.3-3  StarRatExp[101X
  
  [33X[1;0Y[29X[2X StarRatExp[102X( [3Xr[103X ) [32X function[133X
  
  [33X[0;0YThe expression [10X(a(aUb))*[110X may be produced in the following way[133X
  
  [4X[32X  Example  [32X[104X
    [4X[25Xgap>[125X [27Xr1 := RatExpOnnLetters(2,[],[1]); [127X[104X
    [4X[28Xa[128X[104X
    [4X[25Xgap>[125X [27Xr2 := RatExpOnnLetters(2,[],[2]);[127X[104X
    [4X[28Xb[128X[104X
    [4X[25Xgap>[125X [27Xr3 := UnionRatExp(r1,r2);[127X[104X
    [4X[28XaUb[128X[104X
    [4X[25Xgap>[125X [27Xr4 := ProductRatExp(r1,r3);[127X[104X
    [4X[28Xa(aUb)[128X[104X
    [4X[25Xgap>[125X [27Xr5 := StarRatExp(r4);[127X[104X
    [4X[28X(a(aUb))*[128X[104X
  [4X[32X[104X
  
