arxiv: v2 [cs.lo] 24 Feb 2017

Size: px
Start display at page:

Download "arxiv: v2 [cs.lo] 24 Feb 2017"

Transcription

1 Lol Lexing teven Ou University of dinurgh Phil ott University of dinurgh Jques Fleuriot University of dinurgh rxiv: v2 [s.lo] 24 Fe 2017 strt We introdue novel prsing onept lled lol lexing. It integrtes the lssilly seprted stges of lexing nd prsing y llowing lexing to e dependent upon the prsing progress nd y proving simple mehnism for onstrining lexil miguity. This mes it possile for lnguge design to e omposle not only t the level of ontext-free grmmrs, ut lso t the lexil level. It lso mes it possile to inlude lightweight error-hndling diretly s prt of the lnguge speifition insted of leving it up to the implementtion. We present high-level lgorithm for lol lexing, whih is n extension of rley s lgorithm. We hve formlly verified the orretness of our lgorithm with respet to its lol lexing semntis in Iselle/HOL. 1. Introdution The trditionl pproh to speifying the syntx of omputer lnguge is to define two omponents, lexer (lso lled snner nd prser. The lexer prtitions the input doument onsisting of sequene of hrters into sequene of toens. h toen is uniquely ssoited with terminl, suh tht the sequene of toens n e viewed s sequene of terminls. The prser is typilly defined y ontext-free grmmr (CFG, nd hes if the sequene of terminls is in the lnguge generted y the CFG. CFGs re powerful lnguge design tool. most importnt property of CFGs is omposility. Given two or more CFGs, it is esy to omine them into single CFG in vrious wys in order to speify lnguge s mshup of severl other lnguges, whih is ommon senrio in modern progrmming environments. The lexer omponent of this trditionl setup is prolemti though in suh mshup senrio. eyword in one lnguge might e n entifier in nother lnguge, rendering the lexers of these two lnguges inomptile with eh other. The prolem is tht lexers re not supposed to e omposed in the trditionl setup. Prtil solutions to this prolem usully involve some form of d-ho ommunition etween prser nd lexer stges, thus shifting n issue This wor hs een funded y PRC grnt P/L011794/1. whih should e delt with t the lnguge design level to the implementtion level. The min resons for the trditionl split of syntx reognition into lexing nd prsing re speed, expressivity nd onveniene: peed Typilly terminls re speified vi regulr expressions tht n e reognized with deterministi finite stte mhines. This is usully muh fster thn prsing with respet to CFG. xpressivity Despite CFGs eing more expressive thn regulr expressions, two ommon lexing rules nnot e expressed with CFGs: longest-mth, nd priority. The longest-mth rule sttes tht if multiple terminls re ssoited with regulr expressions tht ould ll mth prefixes of the rest of the sequene of hrters to e snned, then the terminls whih mth the longest prefix re to e preferred. The priority rule omes into ply if fter pplition of the longest-mth rule there re still t lest two different terminls s possile ndtes: then liner priority order mong terminls is ssumed, nd the terminl with the highest priority mong ll ndtes is pied. Conveniene In this setup, whitespe nd omments re usully speil terminls whih do not pper in ny grmmr rule, ut whih re filtered out of the sequene of terminls during the lexing stge. nnerless prsing [3] proposes to solve our lexing prolem y relinquishing seprte lexing, effetively entifying hrters, toens nd terminls. This negtively ffets ll three mentioned dvntges of seprte lexing stge, the most severely ffeted eing expressivity: in order to pproximte the missing longest-mth nd priority rules, snnerless prsing introdues follow restritions nd rejet produtions, whih re wrd dditions to the elegnt formlism of ontext-free grmmrs euse they destroy the nie omposility properties of ontext-free grmmrs. snnerless prsing tehnique lled prt prsing goes even further nd does wy with ontext-free grmmrs entirely, employing prsing expression grmmrs insted [2], gin to the detriment of omposility. Insted, we propose new prsing semntis whih we ll lol lexing. Lol lexing eeps the distintion etween

2 lexing nd prsing, nd etween hrters, toens nd terminls. But insted of deterministilly onverting sequene of hrters into sequene of toens, lol lexing onverts sequene of hrters into set of toen sequenes, pplying lexing nd prsing in n intertwined mnner. The ontriutions of this pper re s follows: We first define the novel onept of lol lexing in etion 2. We then present exmples of pplitions of lol lexing in etion 3. These exmples show tht lol lexing is generlistion of the trditionl setup, nd tht lol lexing redily llows integrted ess t the lnguge design level to issues suh s lexil omposility nd error-hndling. In etion 4 we desrie high-level lgorithm whih implements lol lexing s n extension of rley s lgorithm. We hve formlly verified the orretness of this lgorithm in Iselle/HOL [6], nd prove n outline of this orretness proof in etion 5. The full proof ( totl of lines or out 230 pges is ville in [12]. We lso prove prtil lirry for lol lexing [13], written in l/l.js [7, 8]. The lirry ontins exmples of its pplition to the exmples in etion 3. Before onluding, we disuss further relted wor in etion Definition of Lol Lexing Before defining lol lexing, we remind the reder of few si notions. For set U we let U denote the set of sequenes with elements in U, ε U denotes the empty sequene, nd for two sequenes α U nd β U we let αβ U denote their ontention. Given sequene α U, we denote its length y α nd let α i U denote the i-th element of α for i {0,..., α 1}. ontextfree grmmr is qudruple (N, T, R,, where N is the set of nonterminls, T the set of terminls (suh tht N nd T re disjoint, R N (N T the rules of the grmmr nd N the strt. Insted of (N, α R we often write N α. For α, β (N T we sy α β iff there re α 0, N, α 1 nd γ suh tht α = α 0 Nα 1, β = α 0 γα 1 nd N γ. Furthermore, we write for the reflexive nd trnsitive losure of. We define the lnguge L of grmmr G s the set of ll sequenes of terminls derivle from the strt, L = {w T w}. Furthermore we define the set of prefixes L prefix of G vi { } L prefix = w T α (N T. wα. Definition 2.1 (Toen. Given set of terminls T, nd set of hrters Σ, toen x is pir x = (t, T Σ. In exmples we will often use the nottion t for the toen x. We ll the toen empty iff = 0. We define [x] = t nd x =. We lift these nottions in the ovious mnner to sequenes of toens: given toen sequene q = x 0... x r (T Σ we define [q] = [x 0 ]... [x r ] T nd q = x 0... x r Σ. Definition 2.2 (Lol Lexing. Given set of terminls T, nd set of hrters Σ, we ll pir (Lex, el lol lexing (with respet to T nd Σ iff: The lexer Lex ssigns to eh terminl t T lexing funtion Lex(t whih, given sequene of hrters D Σ nd position {0,..., D }, returns set onsisting of toens (t, suh tht D nd i = D i for ll i suh tht 0 i 1. The seletor el tes two toen sets nd B suh tht B nd returns toen set el(, B suh tht el(, B B. We usully define el indiretly y defining strit prtil order < el on toens nd setting el(, B = {x B y B. x < el y}. emntis of Lol Lexing Given lol lexing ll, wht is its semntis, i.e. how does it onvert sequene D of hrters into set ll(d of toen sequenes? Note tht while for defining prtiulr lol lexing ll we do not need ontext-free grmmr, just its sets of terminls nd hrters, the semntis of ll is dependent upon grmmr. In the following we will often ll toen sequenes pths. The onversion proess wors s follows: We go through D from to right, produing sets of pths P u (T Σ long the wy. The index {0,..., D } denotes the position in D we re looing t, nd we use the index u {0, 1,...} to tr itertively generted P 0, P1,... t this position. Let s ssume now tht we hve rehed position in D, hving so fr produed the set of pths P 0; in se we re t the very eginning of D suh tht = 0 we ssume P0 0 = {ε}. We will hve een reful to only produe p P 0 suh tht [p] L prefix. Now, whih toen should we produe next? For sure, the toen to produe next must e memer of the set X = {x T Σ x Lex([x](D, } euse ording to Lex these re the only toens whih strt t position in D. Furthermore, we re only interested in the suset W 0 of those memers of X whih n ontinue sequene in P 0 to sequene of terminls in L prefix: W 0 = { x X p P 0. p = [px] L prefix }. The seletor dees whether nd how to onstrin ny remining miguity in the toen seletion: The set Z 1 = el(, W 0 ontins those toens we use to rete the next set of pths P 1 İf Z 1 does not ontin ny empty toens, then P1 is just P 1 = ppend Z 1 P 0,

3 where ppend T P = P {pt p P p = t T [pt] L prefix }, nd euse we only dded pths q with q > we n simply proeed to position 1 vi P1 0 = P1. But if Z 1 does indeed ontin empty toens, then there might e newly dded pths q with q =, nd we might e le to extend these pths even further. Therefore we define P 1 more generlly s where P 1 = limit (ppend Z 1 P 0, limit f X = f n (X. n=0 The ft tht now P 1 \ P0 my ontin pths q with q = mens tht potentilly more toens in X eome eligile to extends pths whih stop t position. We therefore eep repeting the ove proedure (potentilly infinitely often until we re sure to hve produed ll eligile toens t position y forming monotone hins W 0 W 1 W 2... Z 0 Z 1 Z 2... P 0 P 1 P 2... where for u {0, 1, 2,...} we reursively define W u = {x X p P u. p = [px] L prefix} Z u1 = el(z u, Wu1 P u1 = limit (ppend Z u1 P u. We finlize the genertion of toen sequenes t position y defining P = u=0 nd move on to position 1 vi P1 0 = P. To omplete the given set of reursive equtions, we define Z 0 = for ll positions. One we hve rrived t the end of the hrter sequene D, we finish the onversion of D into the set ll(d of toen sequenes vi defining P = P D nd P u ll(d = {p P p = D [p] L}. Note tht the lol lexing semntis does not depend on the prtiulr form of the grmmr, ut only on L nd L prefix. If the grmmr ontins no unprodutive nonterminls, i.e. if for ll X N there is w Σ suh tht X w, then L prefix is uniquely determined y L nd thus in this se the lol lexing semntis only depends on L lone. Let us lso omment on why the seletor tes two rguments. It is tempting (nd indeed this ws the first thing we tried to let the seletor t only on single rgument, s in Z u1 = el W u1, ut this destroys the property tht the Z u form monotone hin, whih turned out to e importnt for the orretness of our lgorithm for lol lexing (see etion pplitions of Lol Lexing In this setion we explore lol lexing nd its pplitions through rnge of exmples. xmple 3.1 (Trditionl Lexil peifitions. Turning trditionl lexil speifition into the definition of lol lexing is strightforwrd. Let the trditionl speifition e defined over n input lphet Σ nd given y n pirs (r 1, t 1... (r n, t n. The r i re regulr expressions over Σ, none of whih mth ε Σ, nd the set of terminls T onsists of n different terminls t 1,..., t n. For eh t i T we then define Lex(t i (D, = {(t i, }, where is the longest prefix of D... D D 1 suh tht r i mthes. If r i mthes no prefix of D... D D 1 then we define Lex(t i (D, =. We define strit prtil order < el on the set of toens whih enodes the longest-mth nd priority rules: (t i, < el (t j, d iff < d ( = d i < j. This implies tht el(, X will e either empty or singleton euse < el is totl on ll possile X. To endow the lol lexing ll = (Lex, el with the equivlent semntis to trditionl lexing, we define the ontextfree grmmr G = ({, T}, T, R, where R = T, ε, T t 1,. T t n. Beuse of L prefix = L = T this grmmr poses no dditionl onstrints on the lol lexing proess, nd therefore ll(d = iff trditionl lexing of D would led to n error, nd ll(d = {p} iff trditionl lexing of D would yield the toen sequene p. xmple 3.2 (Infinite et of Toen equenes. We hnge the previous exmple slightly nd llow the r i to lso mth the empty hrter sequene ε. s onrete exmple onser Σ = {}, n = 1 nd let r 1 e regulr expression whih mthes ny (possily empty sequene of s. Then

4 using the sme grmmr G s in the previous exmple, we otin for exmple { ll( =, ε, ε ε, } ε ε ε,..., t 1 t 1 t 1 t 1 whih is n infinite set. t 1 t 1 t 1 t 1 t 1 t 1 Beuse lol lexing intertwines lexing nd prsing, determining for hrter sequene D Σ ll possile toen sequenes ll(d involves finding vl prses of [p] for ll p ll(d. The following exmples demonstrte this interply etween lexing nd prsing nd the role of the seletor el in it. xmple 3.3. Conser the grmmr H = (N, T, R, where N = {,, }, T = {, minus,, }, R = {, minus,,,,, }, =. The input hrters re Σ = {, -,,, }. s previously, we speify Lex simply y ssoiting the terminls with regulr expressions: The terminl reognizes the hrter, minus reognizes the hrter -, reognizes ny nonempty sequene of letters nd reognizes ny nonempty sequene of letters nd hyphens -. Let D denote the hrter sequene -. We hoose the simplest option for < el nd define < el =, i.e. no toen hs higher priority thn nother toen. This implies el(, B = B for ll toen sets B. The result of determining ll(d is shown in Figure 1. Beuse overlps with oth entifier nd minus, D n e interpreted in eight different wys s toen sequene. Beuse of the longest-mth rule for regulr expressions, - minus / ll(d, exluded together with severl other toen sequenes whih would otherwise qulify. For ll p ll(d the terminl sequene [p] yields vl prse tree, i.e. there re 8 different wys to prse D lthough H y itself is n unmiguous grmmr; ll of them re jointly depited in the prse grph in Figure 2. miguities re depited s dshed lines in the grph: whenever there re multiple wys to proeed with the derivtion of nonterminl, eh lterntive is onneted with the nonterminl y dshed line. xmple 3.4. We use the sme grmmer H nd the sme lexer Lex s in xmple 3.3, ut hoose seletor el suh tht hs lower priority thn nd minus: x < el y iff [x] = [y] {, minus}. This results in unique lexing of -, { } - ll(- =, minus ll(- = - minus, - minus, - minus, - minus, -, -, -, - Figure 1. Lexing - in xmple minus - - Figure 2. Prsing - in xmple 3.3

5 - minus Figure 3. Prsing - in xmple 3.4 nd thus lso in unique prsing s shown in Figure 3. xmple 3.5. We gin leve H nd Lex fixed. This time we define < el suh tht longer toens hve higher priority: x < el y iff x < y. This yields two possile lexings for -, -, ll(- = -, nd leds to the miguous prsing shown on the hnd se of Figure 4. xmple 3.6. We hoose to modify the previous exmple suh tht its remining miguity is resolved in fvour of y defining x < el y iff x < y ( x = y [x] = [y] =. This leds to unique lexing for -, { } - ll(- =, nd yields the unique prsing depited on the right hnd se of Figure 4. xmple 3.7 (The Lexer H. Conser the expression (* given in the progrmming lnguge C. The mening of this expression depends on whether is type entifier or vrile entifier. If it is type entifier, then the expression is to e interpreted s type st, otherwise s - - Figure 4. Prsing - in x. 3.5 ( nd x. 3.6 (right multiplition. Beuse type entifiers nnot e distinguished from vrile entifiers y their loo, in trditionl prsing prolem rises, euse the lexer phse is supposed to hppen efore the prsing phse nd ny semnti nlysis, ut the terminl type of relly depends on informtion from the semnti nlysis. The trditionl solution, to mnully diret feed from the semnti nlysis into the lexer, is nown s the lexer h [4]. With lol lexing, the lexer / prser n offer oth lterntives, nd let lter stges of the nlysis pi the right one, thus deoupling prsing nd semnti nlysis. The grmmr C demonstrtes this, where T = {type,, steris,, right} nd R = xpr, xpr Cst, xpr Deref, xpr, xpr xpr right, xpr steris xpr, Cst Type right xpr, Deref steris xpr, Type type. The lexer Lex is hosen in the ovious wy, together with n empty < el. The resulting miguous prse grph for (* is shown in Figure 5, nd ll((* = ( ( right type * steris right, * steris. hrödinger s Toen xmple 3.7 is speil se of senrio where the onversion from hrter sequenes to toen sequenes is miguous, ut where the toen oundries re lwys the sme in ll lterntive toen sequenes. The toens ppering in suh senrio hve een hristened hrödinger s toens [5]. Lol lexing is more power-

6 xpr {, mul,, num,, right}, nd the rules y ( xpr xpr Cst Type type * steris right xpr Figure 5. Prsing (* in C xpr Deref xpr um, um um, um, mul tom, tom, tom um right, tom, tom num. The input hrters re Σ = {, *, (,, ,... z}, nd Lex is speified suh tht reognizes the hrter, mul reognizes the hrter *, reognizes the opening ret (, right reognizes the losing ret, reognizes ny nonempty sequene of letters nd digits strting with letter, nd num reognizes ny nonempty sequene of digits. Conser now the following string w whih is invl with respet to the lnguge we just speified: 2(*(1 ful thn the hrödinger s toen pproh nd (t lest oneptully susumes it. Ruy lippers The Mrp prser [10] is n rley-sed prsing lirry whih dvotes the use of tehnique lled Ruy lippers [11]. This tehnique tes dvntge of the ft tht the rley prser nows whih toens it expets t ny given stge of the prse progress. Mrp hs n interfe through whih the prser n ommunite with the snner to negotite whih toen to sn next, thus llowing for sophistited error hndling. Ruy lippers nd lol lexing re oth hildren of the sme insight, nmely tht the snning nd prsing stges should ommunite euse the prser hs informtion out whih toens it expets next. Lol lexing though tes this insight to new level whih in priniple is independent from prtiulr prsing lgorithm lie rley. In this sense, lol lexing n e seen s proving rigorous semntis for ertin uses of the Ruy lippers tehnique. The next exmple demonstrtes how lol lexing n e used to speify lightweight error reovery s prt of the lnguge design. xmple 3.8 (rror Reovery. Conser grmmr for simple rithmeti expressions, where the nonterminls re given y {xpr, um,, tom}, the terminls y Insted of simply dignosing tht there is some prse error t position = 1, we would lie to reover some of the struture of w, for exmple for proving etter error messges or for rih intertive editing experiene. To simplify this ts, we first me our grmmr more permissive y dding the rule tom. This hs the effet tht string lie 2x eomes legl, representing the multiplition of 2 nd x. uh nottion is ommon mthemtil prtie nd thus seems lie justifile design hoie. We then introdue three new terminls: e-tom nd e-right oth reognize the empty string ε only, nd e-superfluous reognizes the losing ret. We inorporte these new terminls into the grmmr y dding the following rules: e-superfluous, tom um e-right, tom e-tom Finlly, we hoose the seletor el suh tht the three dded error terminls hve lower priority thn ll other terminls. Pths in ll(d tht ontin error terminls will only e onsered y us if ll(d ontins no pths without error terminls. Figure 6 shows the result of pplying the updted grmmr to w. The orresponding pth is 2 num ( * mul ε e-tom e-tom right ( e-superfluous ε 1 num ε e-right. Testing onvines us tht the updted grmmr n indeed suessfully prse ll D Σ, nd does so unmiguously. Whitespe In our exmples we hve voed to me use of whitespe. In trditionl prsing there re essentilly two different wys of deling with whitespe:

7 tom 2 num tom ( um * mul tom um e-superfluous um tom " e-tom xpr um right tom ( " e-tom tom um tom 1 num Figure 6. Prsing 2(*(1 in xmple 3.8 " e-right 1. One pproh is to expliitly inorporte whitespe terminls into the grmmr rules. This n eome umersome nd error-prone if done mnully, euse usully whitespe n leglly pper lmost everywhere. 2. The other pproh is to hndle whitespe t the lexil stge exlusively. The first pproh pplies to lol lexing s well. The seond pproh does not diretly pply, s there is no single lexil stge nymore with lol lexing. Nevertheless, it seems tht lol lexing llows to omine the onveniene of the seond pproh with the fine-grined ontrol of the first one y using extended ttriute grmmrs to speify lyout onstrints, ming it possile to tle lyout-sensitive lnguges. The omintion of lol lexing with lyoutsensitivity is wor in progress nd eyond the sope of this pper. 4. Implementing Lol Lexing Given grmmr G nd lol lexing ll, let us define the hrter lnguge L Σ of G nd ll y L Σ = {D Σ ll(d }. How do we uild reognizer for L Σ? Lexing Driving Prsing Our first ttempt might e to diretly pply the semntis of lol lexing fter hving pied prsing lgorithm whih is ple of reognizing oth the prefixes L prefix nd the lnguge L of G. Most of the populr prsing lgorithms would e suitle for this, suh s LL, LR or rley prsing. While this pproh will wor in mny ses, it is ineffiient to tret the prsing lgorithm s l ox whih is repetedly sed whether given sequene of terminls is in L prefix or not. More importntly, s xmple 3.2 shows there re finite grmmrs whih nevertheless produe infinite sets of toen sequenes nd for whih this pproh would therefore fil y getting stu in non-terminting pth generting loop. Prsing Driving Lexing etter pproh seems to e to inverse ove pproh nd to let the prsing progress drive the lexing proess. Often it will e possile to predit from the internl prser stte whih terminl is expeted next. For this to wor, we need to modify the prsing lgorithm so tht it not only nows out terminls T, ut lso out hrters Σ. The rley lgorithm seems to e est suited to e dpted to suh purpose, s it wors on ll ontext-free grmmrs, opes grefully with miguity, nd is esily extended with top-down, -right, nd ottom-up prmetriity. This is why rley-sed prsing is our min fous here. Nevertheless, studying how to modify other prsing lgorithms for lol lexing is interesting nd of potentilly gret prtil interest s well; experiments indite tht in prtiulr the LR(1 prsing lgorithm n e modified to filitte lol lexing in nturl nd simple wy. rley s lgorithm We first desrie ( high-level version of rley s originl lgorithm, ssuming Σ = T. To reognize n input D Σ s elonging to L, it omputes items; n item is qudruple (r, d, i, j where r = (N αβ R is rule of the grmmr, d = α is position within tht rule demring the urrent prsing progress, i {0,..., D } is the origin of the item, nd j {i,..., D } is the in of the item. n lterntive wy to write the item is s (N α β, i, j. rley s lgorithm uilds monotone hin of item sets I 0 I 1 I 2... I D = I.

8 Init = {( α, 0, 0 α R} Predit I = I {(M γ,, N α β i. Complete I = I (N α Mβ, i, I (M γ R} {(N αm β, i, j γ. (N α Mβ, i, j I (M γ, j, I} n I = I {(N αx β, i, 1 < D X = D (N α Xβ, i, I} Figure 7. Building Blos of rley s lgorithm To this end, we define n initil item set Init nd monotone opertors Predit, Complete nd n whih ll te position {0,..., D } nd n item set I nd return n ugmented item set (Figure 7. We then define for {0,..., D } the opertor π y π I = limit (n Complete Predit I, reusing the limit opertor introdued in etion 2, nd use π to reursively define the sets I y I 0 = π 0 Init, I = π I 1 for > 0. Theorem 4.1 (Corretness of rley s lgorithm. rley s lgorithm is oth sound nd omplete, i.e. D iff α. ( α, 0, D I. Proof. This is overed y Theorem 4.2 for the speil se Σ = T, { {(t, t} Lex(t(D, = < el =. for < D D = t, otherwise rley s lgorithm with Lol Lexing We now ssume tht we hve lol lexing ll nd thus Σ nd T do not neessrily oine nymore. We leve Init, Predit nd Complete unhnged, ut we need n updted n opertor tht wors on toens insted of hrters, nd new opertor Toens (Figure 8. The opertion Toens T I first determines ll the ndte terminls tht ould possily pper next t position Toens T I = el T {x X N α β i. X T (N α Xβ, i, I x Lex(X(D, } n T I = I {(N αx β, i, (X, T (N α Xβ, i, I} Figure 8. New nner in D ording to I. It then determines whih of those ndte terminls n tully e lexed s toens t tht position. It pplies the seletor el to it nd returns the resulting set of toens. Finlly, the n opertor is esily dpted to wor on toens insted of single hrters. We itertively ompute the sets T 0, T 1,... of toens t position, nd these t s rguments T to oth Toens nd n. ordingly, we need to updte the definition of π to te the dditionl rgument T into ount: π T I = limit (n T Complete Predit I. Furthermore, it is now possile tht snning t position might dd new items to in due to the existene of empty toens, therefore enlrging the set of eligile terminls t position. To ope with this we eep pplying the opertor π with updted toen sets until it onverges: J 0 0 = π 0 Init J u1 = π T u1 I = u=0 J u J 0 1 = π 1 I T 0 T u1 = J u = Toens T u J u. Note tht in se of J u1 = J u we hve I = J u, thus the omputtion of I n stop t tht point. In prtiulr, if T 1 does not ontin ny empty toens, then the omputtion of I simplifies to I = J 1. ove equtions for omputing I = I D show n ovious orrespondene to the equtions we used for defining P in etion 2. nd indeed, rley s lgorithm with lol lexing is orret with respet to the lol lexing semntis: Theorem 4.2 (Corretness of rley s lgorithm with Lol Lexing. rley s lgorithm with lol lexing is oth sound nd omplete, i.e. D L Σ iff α. ( α, 0, D I. Proof. ee etion 5.

9 The ove orretness result omes with vet: It my e the se tht the omputtion requires n infinite mount of time nd spe. If the grmmr is finite though, then for n input D Σ the size of I is ounded y (( D 1 D 1 1 α, 2 N α R nd thus the omputtion will require only finite mount of time nd spe (ssuming el nd Lex require only finite mount in the first ple. Prtil Implementtion We hve developed prtil lirry for lol lexing written in l/l.js whih n e used to try out the exmples in etion 3 [13]. It is firly nive proof-of-onept implementtion nd not optimized for dt strutures t ll. For future versions of the lirry we pln to exmine whih of the mny estlished es for ming rley prsing fster lso pply (t lest prtilly to our se. 5. Proof of Theorem 4.2 In this setion we give short outline of the proof of Theorem 4.2. The full forml proof is ville s Iselle/HOL 2016 theory files nd hs een fully mhine-heed for orretness [12]. To onvine yourself tht the forml proof relly proves Theorem 4.2 we reommend first studying theories CFG, LolLexing nd LLrleyPrsing. These ontin the si definitions in (lmost the sme nottion s presented in this pper. You should then proeed to loo t theory MinTheorems. It ontins the theorem Corretness whih is the mhine-heed ounterprt of Theorem 4.2. Proof Outline There is n intuitive orrespondene etween the sets P u nd the sets J u. Clrifying this orrespondene is the most importnt step towrds proving the orretness of the lgorithm. Definition 5.1 (Vl nd Generted Items. We ll n item (N α β, i, j I p-vl for some toen sequene p P iff there is u {0,..., p } suh tht p = j, p 0... p u 1 = i, [p 0... p u 1 ]Nγ for some γ, α [p u... p p 1 ]. For P P we sy tht P genertes P, where P = {x I p P. x is p-vl}. This notion of vlity hs een inspired y the one introdued in [9] where it hs een defined s n solute property of n item. To me it wor in our ontext, we hd to define it not solutely, ut reltively with respet to pth. The ul of the proof onsists then in proving I = P. We will not delve into the rther tehnil proof of this here, ut we wnt to point out the following supporting theorem out pths: Theorem 5.1. For ll inputs D, for ll {0,..., D } nd for ll u {0, 1, 2,...} the following holds: Given p, q P u suh tht p = q 0... q n 1 for some n {0,..., q } nd [p q n... q q 1 ] L prefix, it follows tht p q n... q q 1 P u. Intuitively this mens tht when there re two pths p P nd q P whih meet t some position, i.e. p = nd q = d with = =, then they n rossover, i.e. oth d nd will e in P s long s this mes sense with respet to the grmmr. But p nd q re not gurnteed to rrive t the sme time u t position, nd so it might e tht toens tht were round when p rrived re not there nymore when q rrives, nd vie vers. The ft tht the toen sets Z u form monotone hin t position mens tht this nnot hppen. The semntis of lol lexing is defined y mutully reursive equtions whih intertwine lexing nd prsing, ut one ll toen sets Z = u=0 Zu hve een estlished it is possile to disentngle lexil nd grmmtil mtters gin s nother supporting theorem out pths shows: Theorem 5.2. Let p e sequene of toens. Then p P iff p i Z p 0...p i 1 nd [p] L prefix. 0 i< p From I = P nd with the help of Theorem 5.2 it is then strightforwrd to prove Theorem 4.2: Proof. Let us first ssume D L Σ. This implies ll(d, whih implies tht there is p P with p = D nd [p]. This mens there is n α suh tht α nd α [p]. Therefore, ( α, 0, D is p-vl nd thus ( α, 0, D P = I. On the other hnd, let us ssume tht there is n α with ove property. This mens tht ( α, 0, D is p-vl for some p P, i.e. there is u {0,..., p } with p = D, p 0... p u 1 = 0, [p 0... p u 1 ]γ for some γ, α [p u... p p 1 ]. ove fts together with Theorem 5.2 show tht y dropping the first u empty toens from p we otin pth p u... p p 1 ll(d.

10 6. Further Relted Wor strong influene on our wor hs een the e of lox rley prsing presented in [1]. lox is (possily third-prty prser omponent plugged into the rley prsing frmewor y ssoiting the lox with nonterminl. Our Lex omponent n silly e viewed s olletion of loxes, ut insted of ssoiting them with nonterminls, we ssoite them with terminls. This mes it possile to tret loxes s onept tht is in priniple independent from rley prsing. Unlie the originl wor on loxes we lso prove method for dismigution, vi the seletor el. 7. Conlusion With hindsight lol lexing is simple onept, ut it hs ten us over two yers to rrive t the onept s it is presented in this pper. Our lgorithm for lol lexing nd the semntis of lol lexing developed se-y-se during this time. There hve een enough missteps long the wy to finlly me us formlly verify our lgorithm. Despite its simpliity, the exmples from etion 3 show tht lol lexing is verstile nd unifying onept for designing syntx. We hope tht you my find it useful, too. Referenes [1] Trevor Jim, Yitzh Mndelum, Dv Wler. emntis nd lgorithms for Dt-dependent Grmmrs, POPL [2] Brin Ford. Prsing xpression Grmmrs: Reognition Bsed yntti Foundtion, POPL [3] elo Visser. nnerless Generlized-LR Prsing, Report P9707, University of msterdm [4] The lexer h, [5] John yo, R. Nigel Horspool. hrödinger s toen, oftwre Prtie nd xperiene, [6] Iselle, [7] l, [8] éstien Doerene. l.js, [9] Cliff B. Jones. Forml Development Of Corret lgorithms: n xmple Bsed On rley s Reogniser, Proving ssertions out Progrms, [10] Jeffrey Kegler. The Mrp prser, jeffreyegler.githu.io/mrp-we-site/. [11] Jeffrey Kegler. Mrp nd the Ruy lippers, logs.perl.org/users/jeffrey_egler/2011/ 11/mrp-nd-the-ruy-slippers.html. [12] teven Ou. Iselle Theories for Lol Lexing (v1.1.0, doi: /zenodo [13] teven Ou. Lol Lexing Prototype Implementtion (v1.0.1, doi: /zenodo

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS

The University of Nottingham SCHOOL OF COMPUTER SCIENCE A LEVEL 2 MODULE, SPRING SEMESTER MACHINES AND THEIR LANGUAGES ANSWERS The University of ottinghm SCHOOL OF COMPUTR SCIC A LVL 2 MODUL, SPRIG SMSTR 2015 2016 MACHIS AD THIR LAGUAGS ASWRS Time llowed TWO hours Cndidtes my omplete the front over of their nswer ook nd sign their

More information

Project 6: Minigoals Towards Simplifying and Rewriting Expressions

Project 6: Minigoals Towards Simplifying and Rewriting Expressions MAT 51 Wldis Projet 6: Minigols Towrds Simplifying nd Rewriting Expressions The distriutive property nd like terms You hve proly lerned in previous lsses out dding like terms ut one prolem with the wy

More information

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6

CS311 Computational Structures Regular Languages and Regular Grammars. Lecture 6 CS311 Computtionl Strutures Regulr Lnguges nd Regulr Grmmrs Leture 6 1 Wht we know so fr: RLs re losed under produt, union nd * Every RL n e written s RE, nd every RE represents RL Every RL n e reognized

More information

CS 573 Automata Theory and Formal Languages

CS 573 Automata Theory and Formal Languages Non-determinism Automt Theory nd Forml Lnguges Professor Leslie Lnder Leture # 3 Septemer 6, 2 To hieve our gol, we need the onept of Non-deterministi Finite Automton with -moves (NFA) An NFA is tuple

More information

Finite State Automata and Determinisation

Finite State Automata and Determinisation Finite Stte Automt nd Deterministion Tim Dworn Jnury, 2016 Lnguges fs nf re df Deterministion 2 Outline 1 Lnguges 2 Finite Stte Automt (fs) 3 Non-deterministi Finite Stte Automt (nf) 4 Regulr Expressions

More information

6.5 Improper integrals

6.5 Improper integrals Eerpt from "Clulus" 3 AoPS In. www.rtofprolemsolving.om 6.5. IMPROPER INTEGRALS 6.5 Improper integrls As we ve seen, we use the definite integrl R f to ompute the re of the region under the grph of y =

More information

NON-DETERMINISTIC FSA

NON-DETERMINISTIC FSA Tw o types of non-determinism: NON-DETERMINISTIC FS () Multiple strt-sttes; strt-sttes S Q. The lnguge L(M) ={x:x tkes M from some strt-stte to some finl-stte nd ll of x is proessed}. The string x = is

More information

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides.

1 PYTHAGORAS THEOREM 1. Given a right angled triangle, the square of the hypotenuse is equal to the sum of the squares of the other two sides. 1 PYTHAGORAS THEOREM 1 1 Pythgors Theorem In this setion we will present geometri proof of the fmous theorem of Pythgors. Given right ngled tringle, the squre of the hypotenuse is equl to the sum of the

More information

Parse trees, ambiguity, and Chomsky normal form

Parse trees, ambiguity, and Chomsky normal form Prse trees, miguity, nd Chomsky norml form In this lecture we will discuss few importnt notions connected with contextfree grmmrs, including prse trees, miguity, nd specil form for context-free grmmrs

More information

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4

Semantic Analysis. CSCI 3136 Principles of Programming Languages. Faculty of Computer Science Dalhousie University. Winter Reading: Chapter 4 Semnti nlysis SI 16 Priniples of Progrmming Lnguges Fulty of omputer Siene Dlhousie University Winter 2012 Reding: hpter 4 Motivtion Soure progrm (hrter strem) Snner (lexil nlysis) Front end Prse tree

More information

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II

Bottom-Up Parsing. Canonical Collection of LR(0) items. Part II 2 ottom-up Prsing Prt II 1 Cnonil Colletion of LR(0) items CC_LR(0)_I items(g :ugmented_grmmr){ C = {CLOURE({ })} ; repet{ foreh(i C) foreh(grmmr symol X) if(goto(i,x) && GOTO(I,X) C) C = C {GOTO(I,X)};

More information

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic

Chapter 3. Vector Spaces. 3.1 Images and Image Arithmetic Chpter 3 Vetor Spes In Chpter 2, we sw tht the set of imges possessed numer of onvenient properties. It turns out tht ny set tht possesses similr onvenient properties n e nlyzed in similr wy. In liner

More information

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch.

Overview HC9. Parsing: Top-Down & LL(1) Context-Free Grammars (1) Introduction. CFGs (3) Context-Free Grammars (2) Vertalerbouw HC 9: Ch. Overview H9 Vertlerouw H 9: Prsing: op-down & LL(1) do 3 mei 2001 56 heo Ruys h. 8 - Prsing 8.1 ontext-free Grmmrs 8.2 op-down Prsing 8.3 LL(1) Grmmrs See lso [ho, Sethi & Ullmn 1986] for more thorough

More information

Nondeterministic Automata vs Deterministic Automata

Nondeterministic Automata vs Deterministic Automata Nondeterministi Automt vs Deterministi Automt We lerned tht NFA is onvenient model for showing the reltionships mong regulr grmmrs, FA, nd regulr expressions, nd designing them. However, we know tht n

More information

A Lower Bound for the Length of a Partial Transversal in a Latin Square, Revised Version

A Lower Bound for the Length of a Partial Transversal in a Latin Square, Revised Version A Lower Bound for the Length of Prtil Trnsversl in Ltin Squre, Revised Version Pooy Htmi nd Peter W. Shor Deprtment of Mthemtil Sienes, Shrif University of Tehnology, P.O.Bo 11365-9415, Tehrn, Irn Deprtment

More information

Chapter 4 State-Space Planning

Chapter 4 State-Space Planning Leture slides for Automted Plnning: Theory nd Prtie Chpter 4 Stte-Spe Plnning Dn S. Nu CMSC 722, AI Plnning University of Mrylnd, Spring 2008 1 Motivtion Nerly ll plnning proedures re serh proedures Different

More information

Matrices SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics (c) 1. Definition of a Matrix

Matrices SCHOOL OF ENGINEERING & BUILT ENVIRONMENT. Mathematics (c) 1. Definition of a Matrix tries Definition of tri mtri is regulr rry of numers enlosed inside rkets SCHOOL OF ENGINEERING & UIL ENVIRONEN Emple he following re ll mtries: ), ) 9, themtis ), d) tries Definition of tri Size of tri

More information

2.4 Theoretical Foundations

2.4 Theoretical Foundations 2 Progrmming Lnguge Syntx 2.4 Theoretil Fountions As note in the min text, snners n prsers re se on the finite utomt n pushown utomt tht form the ottom two levels of the Chomsky lnguge hierrhy. At eh level

More information

Nondeterministic Finite Automata

Nondeterministic Finite Automata Nondeterministi Finite utomt The Power of Guessing Tuesdy, Otoer 4, 2 Reding: Sipser.2 (first prt); Stoughton 3.3 3.5 S235 Lnguges nd utomt eprtment of omputer Siene Wellesley ollege Finite utomton (F)

More information

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18

Global alignment. Genome Rearrangements Finding preserved genes. Lecture 18 Computt onl Biology Leture 18 Genome Rerrngements Finding preserved genes We hve seen before how to rerrnge genome to obtin nother one bsed on: Reversls Knowledge of preserved bloks (or genes) Now we re

More information

Introduction to Olympiad Inequalities

Introduction to Olympiad Inequalities Introdution to Olympid Inequlities Edutionl Studies Progrm HSSP Msshusetts Institute of Tehnology Snj Simonovikj Spring 207 Contents Wrm up nd Am-Gm inequlity 2. Elementry inequlities......................

More information

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution

Technische Universität München Winter term 2009/10 I7 Prof. J. Esparza / J. Křetínský / M. Luttenberger 11. Februar Solution Tehnishe Universität Münhen Winter term 29/ I7 Prof. J. Esprz / J. Křetínský / M. Luttenerger. Ferur 2 Solution Automt nd Forml Lnguges Homework 2 Due 5..29. Exerise 2. Let A e the following finite utomton:

More information

Chapter 2 Finite Automata

Chapter 2 Finite Automata Chpter 2 Finite Automt 28 2.1 Introduction Finite utomt: first model of the notion of effective procedure. (They lso hve mny other pplictions). The concept of finite utomton cn e derived y exmining wht

More information

CS 275 Automata and Formal Language Theory

CS 275 Automata and Formal Language Theory CS 275 utomt nd Forml Lnguge Theory Course Notes Prt II: The Recognition Prolem (II) Chpter II.5.: Properties of Context Free Grmmrs (14) nton Setzer (Bsed on ook drft y J. V. Tucker nd K. Stephenson)

More information

Lecture 6: Coding theory

Lecture 6: Coding theory Leture 6: Coing theory Biology 429 Crl Bergstrom Ferury 4, 2008 Soures: This leture loosely follows Cover n Thoms Chpter 5 n Yeung Chpter 3. As usul, some of the text n equtions re tken iretly from those

More information

Behavior Composition in the Presence of Failure

Behavior Composition in the Presence of Failure Behvior Composition in the Presene of Filure Sestin Srdin RMIT University, Melourne, Austrli Fio Ptrizi & Giuseppe De Giomo Spienz Univ. Rom, Itly KR 08, Sept. 2008, Sydney Austrli Introdution There re

More information

Symmetrical Components 1

Symmetrical Components 1 Symmetril Components. Introdution These notes should e red together with Setion. of your text. When performing stedy-stte nlysis of high voltge trnsmission systems, we mke use of the per-phse equivlent

More information

Closure Properties of Regular Languages

Closure Properties of Regular Languages Closure Properties of Regulr Lnguges Regulr lnguges re closed under mny set opertions. Let L 1 nd L 2 e regulr lnguges. (1) L 1 L 2 (the union) is regulr. (2) L 1 L 2 (the conctention) is regulr. (3) L

More information

CS241 Week 6 Tutorial Solutions

CS241 Week 6 Tutorial Solutions 241 Week 6 Tutoril olutions Lnguges: nning & ontext-free Grmmrs Winter 2018 1 nning Exerises 1. 0x0x0xd HEXINT 0x0 I x0xd 2. 0xend--- HEXINT 0xe I nd ER -- MINU - 3. 1234-120x INT 1234 INT -120 I x 4.

More information

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28

SEMANTIC ANALYSIS PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/28 SEMNTI NLYSIS PRINIPLES OF PROGRMMING LNGUGES Norbert Zeh Winter 2018 Dlhousie University 1/28 PROGRM TRNSLTION FLOW HRT Soure progrm (hrter strem) Snner (lexil nlysis) Front end Prse tree Prser (syntti

More information

CS 491G Combinatorial Optimization Lecture Notes

CS 491G Combinatorial Optimization Lecture Notes CS 491G Comintoril Optimiztion Leture Notes Dvi Owen July 30, August 1 1 Mthings Figure 1: two possile mthings in simple grph. Definition 1 Given grph G = V, E, mthing is olletion of eges M suh tht e i,

More information

Arrow s Impossibility Theorem

Arrow s Impossibility Theorem Rep Voting Prdoxes Properties Arrow s Theorem Arrow s Impossiility Theorem Leture 12 Arrow s Impossiility Theorem Leture 12, Slide 1 Rep Voting Prdoxes Properties Arrow s Theorem Leture Overview 1 Rep

More information

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4

Intermediate Math Circles Wednesday, November 14, 2018 Finite Automata II. Nickolas Rollick a b b. a b 4 Intermedite Mth Circles Wednesdy, Novemer 14, 2018 Finite Automt II Nickols Rollick nrollick@uwterloo.c Regulr Lnguges Lst time, we were introduced to the ide of DFA (deterministic finite utomton), one

More information

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3

I1 = I2 I1 = I2 + I3 I1 + I2 = I3 + I4 I 3 2 The Prllel Circuit Electric Circuits: Figure 2- elow show ttery nd multiple resistors rrnged in prllel. Ech resistor receives portion of the current from the ttery sed on its resistnce. The split is

More information

Probability. b a b. a b 32.

Probability. b a b. a b 32. Proility If n event n hppen in '' wys nd fil in '' wys, nd eh of these wys is eqully likely, then proility or the hne, or its hppening is, nd tht of its filing is eg, If in lottery there re prizes nd lnks,

More information

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh

Computational Biology Lecture 18: Genome rearrangements, finding maximal matches Saad Mneimneh Computtionl Biology Leture 8: Genome rerrngements, finding miml mthes Sd Mneimneh We hve seen how to rerrnge genome to otin nother one sed on reversls nd the knowledge of the preserved loks or genes. Now

More information

Convert the NFA into DFA

Convert the NFA into DFA Convert the NF into F For ech NF we cn find F ccepting the sme lnguge. The numer of sttes of the F could e exponentil in the numer of sttes of the NF, ut in prctice this worst cse occurs rrely. lgorithm:

More information

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4.

Tutorial Worksheet. 1. Find all solutions to the linear system by following the given steps. x + 2y + 3z = 2 2x + 3y + z = 4. Mth 5 Tutoril Week 1 - Jnury 1 1 Nme Setion Tutoril Worksheet 1. Find ll solutions to the liner system by following the given steps x + y + z = x + y + z = 4. y + z = Step 1. Write down the rgumented mtrix

More information

Part 4. Integration (with Proofs)

Part 4. Integration (with Proofs) Prt 4. Integrtion (with Proofs) 4.1 Definition Definition A prtition P of [, b] is finite set of points {x 0, x 1,..., x n } with = x 0 < x 1

More information

Lecture Notes No. 10

Lecture Notes No. 10 2.6 System Identifition, Estimtion, nd Lerning Leture otes o. Mrh 3, 26 6 Model Struture of Liner ime Invrint Systems 6. Model Struture In representing dynmil system, the first step is to find n pproprite

More information

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals

AP Calculus BC Chapter 8: Integration Techniques, L Hopital s Rule and Improper Integrals AP Clulus BC Chpter 8: Integrtion Tehniques, L Hopitl s Rule nd Improper Integrls 8. Bsi Integrtion Rules In this setion we will review vrious integrtion strtegies. Strtegies: I. Seprte the integrnd into

More information

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of:

22: Union Find. CS 473u - Algorithms - Spring April 14, We want to maintain a collection of sets, under the operations of: 22: Union Fin CS 473u - Algorithms - Spring 2005 April 14, 2005 1 Union-Fin We wnt to mintin olletion of sets, uner the opertions of: 1. MkeSet(x) - rete set tht ontins the single element x. 2. Fin(x)

More information

CSE 401 Compilers. Today s Agenda

CSE 401 Compilers. Today s Agenda CSE 401 Compilers Leture 3: Regulr Expressions & Snning, on?nued Mihel Ringenurg Tody s Agend Lst?me we reviewed lnguges nd grmmrs, nd riefly strted disussing regulr expressions. Tody I ll restrt the regulr

More information

System Validation (IN4387) November 2, 2012, 14:00-17:00

System Validation (IN4387) November 2, 2012, 14:00-17:00 System Vlidtion (IN4387) Novemer 2, 2012, 14:00-17:00 Importnt Notes. The exmintion omprises 5 question in 4 pges. Give omplete explntion nd do not onfine yourself to giving the finl nswer. Good luk! Exerise

More information

Ch. 2.3 Counting Sample Points. Cardinality of a Set

Ch. 2.3 Counting Sample Points. Cardinality of a Set Ch..3 Counting Smple Points CH 8 Crdinlity of Set Let S e set. If there re extly n distint elements in S, where n is nonnegtive integer, we sy S is finite set nd n is the rdinlity of S. The rdinlity of

More information

TIME AND STATE IN DISTRIBUTED SYSTEMS

TIME AND STATE IN DISTRIBUTED SYSTEMS Distriuted Systems Fö 5-1 Distriuted Systems Fö 5-2 TIME ND STTE IN DISTRIUTED SYSTEMS 1. Time in Distriuted Systems Time in Distriuted Systems euse eh mhine in distriuted system hs its own lok there is

More information

2.4 Linear Inequalities and Interval Notation

2.4 Linear Inequalities and Interval Notation .4 Liner Inequlities nd Intervl Nottion We wnt to solve equtions tht hve n inequlity symol insted of n equl sign. There re four inequlity symols tht we will look t: Less thn , Less thn or

More information

University of Sioux Falls. MAT204/205 Calculus I/II

University of Sioux Falls. MAT204/205 Calculus I/II University of Sioux Flls MAT204/205 Clulus I/II Conepts ddressed: Clulus Textook: Thoms Clulus, 11 th ed., Weir, Hss, Giordno 1. Use stndrd differentition nd integrtion tehniques. Differentition tehniques

More information

Spacetime and the Quantum World Questions Fall 2010

Spacetime and the Quantum World Questions Fall 2010 Spetime nd the Quntum World Questions Fll 2010 1. Cliker Questions from Clss: (1) In toss of two die, wht is the proility tht the sum of the outomes is 6? () P (x 1 + x 2 = 6) = 1 36 - out 3% () P (x 1

More information

Learning Partially Observable Markov Models from First Passage Times

Learning Partially Observable Markov Models from First Passage Times Lerning Prtilly Oservle Mrkov s from First Pssge s Jérôme Cllut nd Pierre Dupont Europen Conferene on Mhine Lerning (ECML) 8 Septemer 7 Outline. FPT in models nd sequenes. Prtilly Oservle Mrkov s (POMMs).

More information

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Lexical Analysis and. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Lexicl Anlysis nd These slides re sed on slides copyrighted y Keith Cooper, Ken Kennedy & Lind Torczon t Rice University First Progrmming Project Instruction Scheduling Project hs een posted

More information

Discrete Structures Lecture 11

Discrete Structures Lecture 11 Introdution Good morning. In this setion we study funtions. A funtion is mpping from one set to nother set or, perhps, from one set to itself. We study the properties of funtions. A mpping my not e funtion.

More information

Alpha Algorithm: Limitations

Alpha Algorithm: Limitations Proess Mining: Dt Siene in Ation Alph Algorithm: Limittions prof.dr.ir. Wil vn der Alst www.proessmining.org Let L e n event log over T. α(l) is defined s follows. 1. T L = { t T σ L t σ}, 2. T I = { t

More information

TOPIC: LINEAR ALGEBRA MATRICES

TOPIC: LINEAR ALGEBRA MATRICES Interntionl Blurete LECTUE NOTES for FUTHE MATHEMATICS Dr TOPIC: LINEA ALGEBA MATICES. DEFINITION OF A MATIX MATIX OPEATIONS.. THE DETEMINANT deta THE INVESE A -... SYSTEMS OF LINEA EQUATIONS. 8. THE AUGMENTED

More information

Test Generation from Timed Input Output Automata

Test Generation from Timed Input Output Automata Chpter 8 Test Genertion from Timed Input Output Automt The purpose of this hpter is to introdue tehniques for the genertion of test dt from models of softwre sed on vrints of timed utomt. The tests generted

More information

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata

CS103B Handout 18 Winter 2007 February 28, 2007 Finite Automata CS103B ndout 18 Winter 2007 Ferury 28, 2007 Finite Automt Initil text y Mggie Johnson. Introduction Severl childrens gmes fit the following description: Pieces re set up on plying ord; dice re thrown or

More information

(a) A partition P of [a, b] is a finite subset of [a, b] containing a and b. If Q is another partition and P Q, then Q is a refinement of P.

(a) A partition P of [a, b] is a finite subset of [a, b] containing a and b. If Q is another partition and P Q, then Q is a refinement of P. Chpter 7: The Riemnn Integrl When the derivtive is introdued, it is not hrd to see tht the it of the differene quotient should be equl to the slope of the tngent line, or when the horizontl xis is time

More information

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs

Counting Paths Between Vertices. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs. Isomorphism of Graphs Isomorphism of Grphs Definition The simple grphs G 1 = (V 1, E 1 ) n G = (V, E ) re isomorphi if there is ijetion (n oneto-one n onto funtion) f from V 1 to V with the property tht n re jent in G 1 if

More information

CSCI565 - Compiler Design

CSCI565 - Compiler Design CSCI565 - Compiler Deign Spring 6 Due Dte: Fe. 5, 6 t : PM in Cl Prolem [ point]: Regulr Expreion nd Finite Automt Develop regulr expreion (RE) tht detet the longet tring over the lphet {-} with the following

More information

1 Nondeterministic Finite Automata

1 Nondeterministic Finite Automata 1 Nondeterministic Finite Automt Suppose in life, whenever you hd choice, you could try oth possiilities nd live your life. At the end, you would go ck nd choose the one tht worked out the est. Then you

More information

Metodologie di progetto HW Technology Mapping. Last update: 19/03/09

Metodologie di progetto HW Technology Mapping. Last update: 19/03/09 Metodologie di progetto HW Tehnology Mpping Lst updte: 19/03/09 Tehnology Mpping 2 Tehnology Mpping Exmple: t 1 = + b; t 2 = d + e; t 3 = b + d; t 4 = t 1 t 2 + fg; t 5 = t 4 h + t 2 t 3 ; F = t 5 ; t

More information

5: The Definite Integral

5: The Definite Integral 5: The Definite Integrl 5.: Estimting with Finite Sums Consider moving oject its velocity (meters per second) t ny time (seconds) is given y v t = t+. Cn we use this informtion to determine the distnce

More information

Generalization of 2-Corner Frequency Source Models Used in SMSIM

Generalization of 2-Corner Frequency Source Models Used in SMSIM Generliztion o 2-Corner Frequeny Soure Models Used in SMSIM Dvid M. Boore 26 Mrh 213, orreted Figure 1 nd 2 legends on 5 April 213, dditionl smll orretions on 29 My 213 Mny o the soure spetr models ville

More information

Bisimulation, Games & Hennessy Milner logic

Bisimulation, Games & Hennessy Milner logic Bisimultion, Gmes & Hennessy Milner logi Leture 1 of Modelli Mtemtii dei Proessi Conorrenti Pweł Soboiński Univeristy of Southmpton, UK Bisimultion, Gmes & Hennessy Milner logi p.1/32 Clssil lnguge theory

More information

Electromagnetism Notes, NYU Spring 2018

Electromagnetism Notes, NYU Spring 2018 Eletromgnetism Notes, NYU Spring 208 April 2, 208 Ation formultion of EM. Free field desription Let us first onsider the free EM field, i.e. in the bsene of ny hrges or urrents. To tret this s mehnil system

More information

Lecture 3: Equivalence Relations

Lecture 3: Equivalence Relations Mthcmp Crsh Course Instructor: Pdric Brtlett Lecture 3: Equivlence Reltions Week 1 Mthcmp 2014 In our lst three tlks of this clss, we shift the focus of our tlks from proof techniques to proof concepts

More information

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b

where the box contains a finite number of gates from the given collection. Examples of gates that are commonly used are the following: a b CS 294-2 9/11/04 Quntum Ciruit Model, Solovy-Kitev Theorem, BQP Fll 2004 Leture 4 1 Quntum Ciruit Model 1.1 Clssil Ciruits - Universl Gte Sets A lssil iruit implements multi-output oolen funtion f : {0,1}

More information

The Word Problem in Quandles

The Word Problem in Quandles The Word Prolem in Qundles Benjmin Fish Advisor: Ren Levitt April 5, 2013 1 1 Introdution A word over n lger A is finite sequene of elements of A, prentheses, nd opertions of A defined reursively: Given

More information

SWEN 224 Formal Foundations of Programming WITH ANSWERS

SWEN 224 Formal Foundations of Programming WITH ANSWERS T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Time Allowed: 3 Hours EXAMINATIONS 2011 END-OF-YEAR SWEN 224 Forml Foundtions of Progrmming

More information

Prefix-Free Regular-Expression Matching

Prefix-Free Regular-Expression Matching Prefix-Free Regulr-Expression Mthing Yo-Su Hn, Yjun Wng nd Derik Wood Deprtment of Computer Siene HKUST Prefix-Free Regulr-Expression Mthing p.1/15 Pttern Mthing Given pttern P nd text T, find ll sustrings

More information

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014

CS 2204 DIGITAL LOGIC & STATE MACHINE DESIGN SPRING 2014 S 224 DIGITAL LOGI & STATE MAHINE DESIGN SPRING 214 DUE : Mrh 27, 214 HOMEWORK III READ : Relte portions of hpters VII n VIII ASSIGNMENT : There re three questions. Solve ll homework n exm prolems s shown

More information

#A42 INTEGERS 11 (2011) ON THE CONDITIONED BINOMIAL COEFFICIENTS

#A42 INTEGERS 11 (2011) ON THE CONDITIONED BINOMIAL COEFFICIENTS #A42 INTEGERS 11 (2011 ON THE CONDITIONED BINOMIAL COEFFICIENTS Liqun To Shool of Mthemtil Sienes, Luoyng Norml University, Luoyng, Chin lqto@lynuedun Reeived: 12/24/10, Revised: 5/11/11, Aepted: 5/16/11,

More information

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz

Compiler Design. Spring Lexical Analysis. Sample Exercises and Solutions. Prof. Pedro C. Diniz University of Southern Cliforni Computer Siene Deprtment Compiler Design Spring 7 Lexil Anlysis Smple Exerises nd Solutions Prof. Pedro C. Diniz USC / Informtion Sienes Institute 47 Admirlty Wy, Suite

More information

Formal languages, automata, and theory of computation

Formal languages, automata, and theory of computation Mälrdlen University TEN1 DVA337 2015 School of Innovtion, Design nd Engineering Forml lnguges, utomt, nd theory of computtion Thursdy, Novemer 5, 14:10-18:30 Techer: Dniel Hedin, phone 021-107052 The exm

More information

Green s Theorem. (2x e y ) da. (2x e y ) dx dy. x 2 xe y. (1 e y ) dy. y=1. = y e y. y=0. = 2 e

Green s Theorem. (2x e y ) da. (2x e y ) dx dy. x 2 xe y. (1 e y ) dy. y=1. = y e y. y=0. = 2 e Green s Theorem. Let be the boundry of the unit squre, y, oriented ounterlokwise, nd let F be the vetor field F, y e y +, 2 y. Find F d r. Solution. Let s write P, y e y + nd Q, y 2 y, so tht F P, Q. Let

More information

Arrow s Impossibility Theorem

Arrow s Impossibility Theorem Rep Fun Gme Properties Arrow s Theorem Arrow s Impossiility Theorem Leture 12 Arrow s Impossiility Theorem Leture 12, Slide 1 Rep Fun Gme Properties Arrow s Theorem Leture Overview 1 Rep 2 Fun Gme 3 Properties

More information

, g. Exercise 1. Generator polynomials of a convolutional code, given in binary form, are g. Solution 1.

, g. Exercise 1. Generator polynomials of a convolutional code, given in binary form, are g. Solution 1. Exerise Genertor polynomils of onvolutionl ode, given in binry form, re g, g j g. ) Sketh the enoding iruit. b) Sketh the stte digrm. ) Find the trnsfer funtion T. d) Wht is the minimum free distne of

More information

Parsing and Pattern Recognition

Parsing and Pattern Recognition Topics in IT Prsing nd Pttern Recognition Week Context-Free Prsing College of Informtion Science nd Engineering Ritsumeikn University this week miguity in nturl lnguge in mchine lnguges top-down, redth-first

More information

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9.

5. (±±) Λ = fw j w is string of even lengthg [ 00 = f11,00g 7. (11 [ 00)± Λ = fw j w egins with either 11 or 00g 8. (0 [ ffl)1 Λ = 01 Λ [ 1 Λ 9. Regulr Expressions, Pumping Lemm, Right Liner Grmmrs Ling 106 Mrch 25, 2002 1 Regulr Expressions A regulr expression descries or genertes lnguge: it is kind of shorthnd for listing the memers of lnguge.

More information

Regular expressions, Finite Automata, transition graphs are all the same!!

Regular expressions, Finite Automata, transition graphs are all the same!! CSI 3104 /Winter 2011: Introduction to Forml Lnguges Chpter 7: Kleene s Theorem Chpter 7: Kleene s Theorem Regulr expressions, Finite Automt, trnsition grphs re ll the sme!! Dr. Neji Zgui CSI3104-W11 1

More information

Automatic Synthesis of New Behaviors from a Library of Available Behaviors

Automatic Synthesis of New Behaviors from a Library of Available Behaviors Automti Synthesis of New Behviors from Lirry of Aville Behviors Giuseppe De Giomo Università di Rom L Spienz, Rom, Itly degiomo@dis.unirom1.it Sestin Srdin RMIT University, Melourne, Austrli ssrdin@s.rmit.edu.u

More information

For a, b, c, d positive if a b and. ac bd. Reciprocal relations for a and b positive. If a > b then a ab > b. then

For a, b, c, d positive if a b and. ac bd. Reciprocal relations for a and b positive. If a > b then a ab > b. then Slrs-7.2-ADV-.7 Improper Definite Integrls 27.. D.dox Pge of Improper Definite Integrls Before we strt the min topi we present relevnt lger nd it review. See Appendix J for more lger review. Inequlities:

More information

Bases for Vector Spaces

Bases for Vector Spaces Bses for Vector Spces 2-26-25 A set is independent if, roughly speking, there is no redundncy in the set: You cn t uild ny vector in the set s liner comintion of the others A set spns if you cn uild everything

More information

Minimal DFA. minimal DFA for L starting from any other

Minimal DFA. minimal DFA for L starting from any other Miniml DFA Among the mny DFAs ccepting the sme regulr lnguge L, there is exctly one (up to renming of sttes) which hs the smllest possile numer of sttes. Moreover, it is possile to otin tht miniml DFA

More information

Formal Languages and Automata

Formal Languages and Automata Moile Computing nd Softwre Engineering p. 1/5 Forml Lnguges nd Automt Chpter 2 Finite Automt Chun-Ming Liu cmliu@csie.ntut.edu.tw Deprtment of Computer Science nd Informtion Engineering Ntionl Tipei University

More information

Behavior Composition in the Presence of Failure

Behavior Composition in the Presence of Failure Behior Composition in the Presene of Filure Sestin Srdin RMIT Uniersity, Melourne, Austrli Fio Ptrizi & Giuseppe De Giomo Spienz Uni. Rom, Itly KR 08, Sept. 2008, Sydney Austrli Introdution There re t

More information

p-adic Egyptian Fractions

p-adic Egyptian Fractions p-adic Egyptin Frctions Contents 1 Introduction 1 2 Trditionl Egyptin Frctions nd Greedy Algorithm 2 3 Set-up 3 4 p-greedy Algorithm 5 5 p-egyptin Trditionl 10 6 Conclusion 1 Introduction An Egyptin frction

More information

Polynomials. Polynomials. Curriculum Ready ACMNA:

Polynomials. Polynomials. Curriculum Ready ACMNA: Polynomils Polynomils Curriulum Redy ACMNA: 66 www.mthletis.om Polynomils POLYNOMIALS A polynomil is mthemtil expression with one vrile whose powers re neither negtive nor frtions. The power in eh expression

More information

Chapter 8 Roots and Radicals

Chapter 8 Roots and Radicals Chpter 8 Roots nd Rdils 7 ROOTS AND RADICALS 8 Figure 8. Grphene is n inredily strong nd flexile mteril mde from ron. It n lso ondut eletriity. Notie the hexgonl grid pttern. (redit: AlexnderAIUS / Wikimedi

More information

Linear Algebra Introduction

Linear Algebra Introduction Introdution Wht is Liner Alger out? Liner Alger is rnh of mthemtis whih emerged yers k nd ws one of the pioneer rnhes of mthemtis Though, initilly it strted with solving of the simple liner eqution x +

More information

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA

Common intervals of genomes. Mathieu Raffinot CNRS LIAFA Common intervls of genomes Mthieu Rffinot CNRS LIF Context: omprtive genomis. set of genomes prtilly/totlly nnotte Informtive group of genes or omins? Ex: COG tse Mny iffiulties! iology Wht re two similr

More information

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points:

Algorithms & Data Structures Homework 8 HS 18 Exercise Class (Room & TA): Submitted by: Peer Feedback by: Points: Eidgenössishe Tehnishe Hohshule Zürih Eole polytehnique fédérle de Zurih Politenio federle di Zurigo Federl Institute of Tehnology t Zurih Deprtement of Computer Siene. Novemer 0 Mrkus Püshel, Dvid Steurer

More information

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true.

1. For each of the following theorems, give a two or three sentence sketch of how the proof goes or why it is not true. York University CSE 2 Unit 3. DFA Clsses Converting etween DFA, NFA, Regulr Expressions, nd Extended Regulr Expressions Instructor: Jeff Edmonds Don t chet y looking t these nswers premturely.. For ech

More information

Logic Synthesis and Verification

Logic Synthesis and Verification Logi Synthesis nd Verifition SOPs nd Inompletely Speified Funtions Jie-Hong Rolnd Jing 江介宏 Deprtment of Eletril Engineering Ntionl Tiwn University Fll 2010 Reding: Logi Synthesis in Nutshell Setion 2 most

More information

Designing finite automata II

Designing finite automata II Designing finite utomt II Prolem: Design DFA A such tht L(A) consists of ll strings of nd which re of length 3n, for n = 0, 1, 2, (1) Determine wht to rememer out the input string Assign stte to ech of

More information

Data Structures LECTURE 10. Huffman coding. Example. Coding: problem definition

Data Structures LECTURE 10. Huffman coding. Example. Coding: problem definition Dt Strutures, Spring 24 L. Joskowiz Dt Strutures LEURE Humn oing Motivtion Uniquel eipherle oes Prei oes Humn oe onstrution Etensions n pplitions hpter 6.3 pp 385 392 in tetook Motivtion Suppose we wnt

More information

= state, a = reading and q j

= state, a = reading and q j 4 Finite Automt CHAPTER 2 Finite Automt (FA) (i) Derterministi Finite Automt (DFA) A DFA, M Q, q,, F, Where, Q = set of sttes (finite) q Q = the strt/initil stte = input lphet (finite) (use only those

More information

8 THREE PHASE A.C. CIRCUITS

8 THREE PHASE A.C. CIRCUITS 8 THREE PHSE.. IRUITS The signls in hpter 7 were sinusoidl lternting voltges nd urrents of the so-lled single se type. n emf of suh type n e esily generted y rotting single loop of ondutor (or single winding),

More information

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018 Finite Automt Theory nd Forml Lnguges TMV027/DIT321 LP4 2018 Lecture 10 An Bove April 23rd 2018 Recp: Regulr Lnguges We cn convert between FA nd RE; Hence both FA nd RE ccept/generte regulr lnguges; More

More information

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations.

Lecture 3. In this lecture, we will discuss algorithms for solving systems of linear equations. Lecture 3 3 Solving liner equtions In this lecture we will discuss lgorithms for solving systems of liner equtions Multiplictive identity Let us restrict ourselves to considering squre mtrices since one

More information