Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 4183461[1X3 [33X[0;0YRational languages[133X[101X23[33X[0;0YRational languages are conveniently represented through rational4expressions. These are finite expressions involving letters of the alphabet;5[10Xconcatenation[110X, corresponding to the [13Xproduct[113X; the symbol [10XU[110X, corresponding to6the [13Xunion[113X; and the symbol [10X*[110X, corresponding to the Kleene's star.[133X789[1X3.1 [33X[0;0YRational Expressions[133X[101X1011[33X[0;0YThe expressions [10X@[110X and [10X"empty\_set"[110X are used to represent the empty word and12the empty set respectively.[133X1314[1X3.1-1 RationalExpression[101X1516[29X[2XRationalExpression[102X( [3Xexpr[103X[, [3Xalph[103X] ) [32X function1718[33X[0;0YA rational expression can be created using the function [10XRationalExpression[110X.19[3Xexpr[103X is a string representing the desired expression literally and [3Xalph[103X (may20or may not be present) is the alphabet of the expression. Of course [3Xalph[103X21must not contain the symbols '@', '(', ')', '*' nor 'U'. When [3Xalph[103X is not22present, the alphabet of the rational expression is the set of symbols23(other than '"', etc...) occurring in the expression. (The alphabet is then24ordered with the alphabetical order.)[133X2526[4X[32X Example [32X[104X27[4X[25Xgap>[125X [27XRationalExpression("abUc");[127X[104X28[4X[28XabUc[128X[104X29[4X[25Xgap>[125X [27XRationalExpression("ab*Uc");[127X[104X30[4X[28Xab*Uc[128X[104X31[4X[25Xgap>[125X [27XRationalExpression("001U1*");[127X[104X32[4X[28X001U1*[128X[104X33[4X[25Xgap>[125X [27XRationalExpression("001U1*","012");[127X[104X34[4X[28X001U1*[128X[104X35[4X[32X[104X3637[1X3.1-2 RatExpOnnLetters[101X3839[29X[2XRatExpOnnLetters[102X( [3Xn[103X, [3Xoperation[103X, [3Xlist[103X ) [32X function4041[33X[0;0YThis is another way to construct a rational expression over an alphabet. The42user may specify the alphabet or just give the number [22Xn[122X of letters (in this43case the alphabet [22X{a,b,c,...}[122X is considered). [3Xoperation[103X is the name of an44operation, the possibilities being: [10Xproduct[110X, [10Xunion[110X or [10Xstar[110X. [3Xlist[103X is a list45of rational expressions, a rational expression in the case of ``star'', or a46list consisting of an integer when the rational expression is a single47letter. The empty list [10X[ ][110X and [10Xempty\_set[110X are other possibilities for [10Xlist[110X.48An example follows[133X4950[4X[32X Example [32X[104X51[4X[25Xgap>[125X [27XRatExpOnnLetters(2,"star",RatExpOnnLetters(2,"product",[127X[104X52[4X[25X>[125X [27X[RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,"union",[127X[104X53[4X[25X>[125X [27X[RatExpOnnLetters(2,[],[1]),RatExpOnnLetters(2,[],[2])])])); [127X[104X54[4X[28X(a(aUb))*[128X[104X55[4X[32X[104X5657[33X[0;0YThe empty word and the empty set are the rational expressions:[133X5859[4X[32X Example [32X[104X60[4X[25Xgap>[125X [27XRatExpOnnLetters(2,[],[]); [127X[104X61[4X[28X@[128X[104X62[4X[25Xgap>[125X [27XRatExpOnnLetters(2,[],"empty_set");[127X[104X63[4X[28Xempty_set[128X[104X64[4X[32X[104X6566[1X3.1-3 RandomRatExp[101X6768[29X[2XRandomRatExp[102X( [3Xarg[103X ) [32X function6970[33X[0;0YGiven the number of symbols of the alphabet and (possibly) a factor [22Xm[122X which71is intended to increase the randomality of the expression, returns a pseudo72random rational expression over that alphabet.[133X7374[4X[32X Example [32X[104X75[4X[25Xgap>[125X [27XRandomRatExp(2);[127X[104X76[4X[28Xb*(@Ua)[128X[104X77[4X[25Xgap>[125X [27XRandomRatExp("01");[127X[104X78[4X[28Xempty_set[128X[104X79[4X[25Xgap>[125X [27XRandomRatExp("01");[127X[104X80[4X[28X(0U1)*[128X[104X81[4X[25Xgap>[125X [27XRandomRatExp("01",7);[127X[104X82[4X[28X0*1(@U0U1)[128X[104X83[4X[32X[104X8485[1X3.1-4 SizeRatExp[101X8687[29X[2XSizeRatExp[102X( [3Xr[103X ) [32X function8889[33X[0;0YReturns the size, i.e. the number of symbols of the alphabet, of the90rational expression [3Xr[103X.[133X9192[4X[32X Example [32X[104X93[4X[25Xgap>[125X [27Xa:=RationalExpression("0*1(@U0U1)");[127X[104X94[4X[28X0*1(@U0U1)[128X[104X95[4X[25Xgap>[125X [27XSizeRatExp(a);[127X[104X96[4X[28X5[128X[104X97[4X[32X[104X9899[1X3.1-5 IsRationalExpression[101X100101[29X[2XIsRationalExpression[102X( [3Xr[103X ) [32X function102103[33X[0;0YTests whether an object is a rational expression.[133X104105[4X[32X Example [32X[104X106[4X[25Xgap>[125X [27Xr := RandomRatExp("01",7);[127X[104X107[4X[28X1(0U1)U@[128X[104X108[4X[25Xgap>[125X [27XIsRatExpOnnLettersObj(r) and IsRationalExpressionRep(r);[127X[104X109[4X[28Xtrue[128X[104X110[4X[25Xgap>[125X [27XIsRationalExpression(RandomRatExp("01"));[127X[104X111[4X[28Xtrue[128X[104X112[4X[32X[104X113114[1X3.1-6 AlphabetOfRatExp[101X115116[29X[2XAlphabetOfRatExp[102X( [3XR[103X ) [32X function117118[33X[0;0YReturns the number of symbols in the alphabet of the rational expression [10XR[110X.[133X119120[4X[32X Example [32X[104X121[4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X122[4X[28Xa*(ba*U@)[128X[104X123[4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X124[4X[28X2[128X[104X125[4X[25Xgap>[125X [27Xr:=RandomRatExp("01");[127X[104X126[4X[28X1*(01*U@)[128X[104X127[4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X128[4X[28X2[128X[104X129[4X[25Xgap>[125X [27Xa:=RandomTransformation(3);;[127X[104X130[4X[25Xgap>[125X [27Xb:=RandomTransformation(3);;[127X[104X131[4X[25Xgap>[125X [27Xr:=RandomRatExp([a,b]);[127X[104X132[4X[28X(Transformation( [ 1, 1, 3 ] )UTransformation( [ 1, 1, 2 ] ))*[128X[104X133[4X[25Xgap>[125X [27XAlphabetOfRatExp(r);[127X[104X134[4X[28X2[128X[104X135[4X[32X[104X136137[1X3.1-7 AlphabetOfRatExpAsList[101X138139[29X[2XAlphabetOfRatExpAsList[102X( [3XR[103X ) [32X function140141[33X[0;0YReturns the alphabet of the rational expression [10XR[110X always as a list. If the142alphabet of the rational expression is given by means of an integer less143than 27 it returns the list [10X"abcd...."[110X, otherwise returns [10X[ "a1", "a2",144"a3", "a4", ... ][110X.[133X145146[4X[32X Example [32X[104X147[4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X148[4X[28X(aUb)((aUb)(bU@)U@)U@[128X[104X149[4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X150[4X[28X"ab"[128X[104X151[4X[25Xgap>[125X [27Xr:=RandomRatExp("01");[127X[104X152[4X[28X1*(0U@)[128X[104X153[4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X154[4X[28X"01"[128X[104X155[4X[25Xgap>[125X [27Xr:=RandomRatExp(30);;[127X[104X156[4X[25Xgap>[125X [27XAlphabetOfRatExpAsList(r);[127X[104X157[4X[28X[ "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10", "a11", [128X[104X158[4X[28X"a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20", "a21", [128X[104X159[4X[28X"a22", "a23", "a24", "a25", "a26", "a27", "a28", "a29", "a30" ][128X[104X160[4X[32X[104X161162[1X3.1-8 CopyRatExp[101X163164[29X[2XCopyRatExp[102X( [3XR[103X ) [32X function165166[33X[0;0YReturns a new rational expression, which is a copy of [10XR[110X.[133X167168[4X[32X Example [32X[104X169[4X[25Xgap>[125X [27Xr:=RandomRatExp(2);[127X[104X170[4X[28Xa*(bU@)[128X[104X171[4X[25Xgap>[125X [27XCopyRatExp(r);[127X[104X172[4X[28Xa*(bU@)[128X[104X173[4X[32X[104X174175176[1X3.2 [33X[0;0YComparison of rational expressions[133X[101X177178[33X[0;0YThe way two rational expressions [10Xr1[110X and [10Xr2[110X are compared through the operator179is the following: the empty set is lesser than everything else; if r1 and r2180are letters, then the lesser is taken from the order in the alphabet; if r1181is a letter an r2 a product, union or star, then r1 is lesser than r2; a182star expression is considered to be lesser than a product or union183expression and a product lesser than a union; to compare two star184expressions we compare the expressions under the stars; to compare two185product or union expressions we compare the subexpressions of each186expression from left to right;[133X187188189[1X3.3 [33X[0;0YOperations with rational languages[133X[101X190191[33X[0;0YOnly operations with rational languages over the same alphabet are allowed.[133X192193[33X[0;0YWe may compute expressions for the [10Xproduct[110X, [10Xunion[110X and [10Xstar[110X (i.e., submonoid194generated by) of rational sets. In some cases, simpler expressions195representing the same set are returned. Note that that two simplifications196are always made, namely, and . Of course, these operations may be used to197construct more complex expressions. For rational expressions we have the198functions [10XUnionRatExp[110X, [10XProductRatExp[110X, [10XStarRatExp[110X, that return respectively199rational expressions for the [13Xunion[113X and [13Xproduct[113X of the languages given by the200rational expressions [10Xr[110X and [10Xs[110X and the [10Xstar[110X of the language given by the201rational expression [10Xr[110X.[133X202203[1X3.3-1 UnionRatExp[101X204205[29X[2XUnionRatExp[102X( [3Xr[103X, [3Xs[103X ) [32X function206[1X3.3-2 ProductRatExp[101X207208[29X[2XProductRatExp[102X( [3Xr[103X, [3Xs[103X ) [32X function209[1X3.3-3 StarRatExp[101X210211[29X[2X StarRatExp[102X( [3Xr[103X ) [32X function212213[33X[0;0YThe expression [10X(a(aUb))*[110X may be produced in the following way[133X214215[4X[32X Example [32X[104X216[4X[25Xgap>[125X [27Xr1 := RatExpOnnLetters(2,[],[1]); [127X[104X217[4X[28Xa[128X[104X218[4X[25Xgap>[125X [27Xr2 := RatExpOnnLetters(2,[],[2]);[127X[104X219[4X[28Xb[128X[104X220[4X[25Xgap>[125X [27Xr3 := UnionRatExp(r1,r2);[127X[104X221[4X[28XaUb[128X[104X222[4X[25Xgap>[125X [27Xr4 := ProductRatExp(r1,r3);[127X[104X223[4X[28Xa(aUb)[128X[104X224[4X[25Xgap>[125X [27Xr5 := StarRatExp(r4);[127X[104X225[4X[28X(a(aUb))*[128X[104X226[4X[32X[104X227228229230