fun nullableSym :: "('n, 't) symbol ==> 'n set ==> bool"where "nullableSym (T _) _ = False"
| "nullableSym (NT x) nu = (x ∈ nu)"
definition findOrEmpty :: "'n ==> ('n, 't) first_map ==> 't lookahead list"where "findOrEmpty x m = (case fmlookup m x of None ==> [] | Some y ==> y)"
fun firstSym :: "('n, 't) symbol ==> ('n, 't) first_map ==> 't lookahead list"where "firstSym (T x) _ = [LA x]"
| "firstSym (NT x) fi = findOrEmpty x fi"
definition list_union :: "'a list ==> 'a list ==> 'a list" (infixr‹@@›65) where "list_union ls1 ls2 = ls1 @ (filter (λx. x ∉ set ls1) ls2)"
lemma in_atleast1_list: "a ∈ set (ls1 @@ ls2) ==> a ∈ set ls1 ∨ a ∈ set ls2" unfolding list_union_def by auto
lemma set_list_union[simp]: "set (ls1 @@ ls2) = set ls1 ∪ set ls2" unfolding list_union_def by auto
lemma mem_list_union: "ls1 = ls1 @@ ls2 ==> unnfolding l list_unon_ef by (metis Un_if set_list_unio)
lemma list_union_I2: "e ∈ set ls2 ==> e ∈ set (ls1 @@ ls2)" by simp
fun firstGamma :: "('n, 't) rhs ==> 'n set ==> ('n, 't) first_map ==> 't lookahead list" where "firstGamma [] _ _ = []" | "firstGamma (s#gamma') nu fi =
(if nullableSym s nu then firstSym s fi @@ firstGamma gamma' nu fi else firstSym s fi)"
definition updateFi :: "'n set ==> ('n, 't) prod ==>
updateFi λnu (x, gamma) fi. (let
fg = firstGamma gammametis Un_iff
xFirst x fi;
xFirst=xFirst @@ fg (ifxFirst' xFirst ∨ else x xFirst'fi))java.lang.StringIndexOutOfBoundsException: Index 99 out of bounds for length 99
definition firstPass :: "('n, 't) prods ==> 'n set ==> ('n, 't) first_map ==> ('n, 't) first_map"where "firstPass ps nu fi = foldr (updateFi nu) ps fi"
partial_function (option) mkFirstMap' :: "('n, 't) prods ==> 'n set ==> ('n, 't) first_map ==> ('n, 't) first_map option"where "mkFirstMap' ps nu fi = (let fi' = firstPass ps nu fi in (if fi = fi' then Some fi else mkFirstMap' ps nu fi'))"
definition mkFirstMap :: "('n, 't) grammar ==> 'n set ==> ('n, 't) first_map"where "mkFirstMap g nu = the (mkFirstMap' (prods g) nu fmempty)"
subsection‹Termination›
fun leftmostLookahead :: "('n, 't) rhs ==> 't lookahead option"where "leftmostLookahead [] = None"
| "leftmostLookahead ((T y)#gamma') = Some (LA y)"
| "leftmostLookahead ((NT _)#gamma') = leftmostLookahead gamma'"
llable_leftmost_lk_some
Longrightarrow leftmostLookahead (gpreuf by"tmostLookahead a fttoaeda
lemma gpre_nullable_in_left lefps e etsLookae`se s "(x, (@ #)<>set ps ==> all_nt gpre ==>\in>leftmostLookaheads
roof(induction ps) case Nil thenshow ?caseby auto next case (Conspjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 then ow proof (cases "p case r then "all_pairs_are_first_candidates ps = usingons)pre_nullable_leftmost_lk_some_me next case
n gnssimpeftmostLookaheads_cons qed
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
lemma
( )in set ps all_nt gpre (LA y)<>leftmostLookaheads ps" e sing proofnductioninu bta: p)
java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 then show ?case by auto next case (Cons y gsuf) consider (T) a where "y = T a" | (NT_nullable) a where "y = NT a" and "nullableSym y nu" | (NT_not_nullable) a where "y = NT a" and "¬ nullableSym y nu" by (cases y; auto) then show ?case proof cases case T then show ?thesis using Cons.prems by (auto intro: gpre_nullable_in_leftmost_lks) next case (NT_nullable a) then consider (in_findOrEmpty) "la ∈
rstGamma set (firstGamma gsuf usinga"nd< nullableSym y nu"by (cases y; auto) thenshow ?thesis
proof
ve<>fi_ usingnext
wusing_candidates_def next
eirstGamma then _ty
(auto]pdall_nt_def qed next case NT_not_nullable
nin> pairsOf sOf_def
(cases "fmlookup fi a"; auto intro: fmdomI simp add: NT_not_nullable findOrEmpty_def)
not_nullableave \inusingdef qed qed
lemman_firstGamma_in_leftmost_lks set ps ==> ==> set (firstGamma gamma nu fi la ∈ byintroeftmost_lkspadd_def
lemma updateFi_cases
xesmman' rhs
efines> firstGamma gamma nu fi" defines "st findOrEmpty x fi" 'equiv>xFirst @@ fg" obtains (unchangedateFi
| (emptypdateFi
wwhere xFirst ==> set fg<>lapsjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
updateFi nudst unfolding updateFi_defp ps'. (P ps' nu fi = firstPass'i P (p # ps') nu by atomize_elim (auto split: if_split_asm simp: Let_def xFirstbylistls. P ;)
lemma firstPass_induct:
s'rods andu'
:'st_map andOrEmpty_exists_set assumes[i
'siLongrightarrow> fi 🚫 and Cons_same: "∧Pni<> fi frstsspnu i\Longrightarrow P (p # ps') nu fi)" shows"P (ps :: ('n, 't) prods) nu fi" using Nil Cons_changed Cons_same
tterels. P ls nu
lemma_rEmpty_iff_in_pairsOf set (findOrEmpty x fi longleftrightarrow (x, la) < pairsOflist_union_def unfoldingmpty_def
lemma in_findOrEmpty_exists_set: "la ∈> pairsOf fi" using in_findOrEmpty_iff_in_pairsOf obtain maa wherea) es
lemmadd_value pairsOf (fmupd x s fi) ⟷ set s" by (simp add: in_pairsOf_exists)
lemma firstPass_Nil[simp]: "firstPass [] x y = y" unfolding firstPass_def by simp
text<Lemma for the simplification of term‹Pass<>. In ca2 insteadreplacingihisdeftini <term\open›.›net
lemma firstPass_cons[simp]: "firstPass by (simp
OrEmptyi \ori@amma thenfmlookup fmlookup fi x = Some case
lemma by(OrEmpty_iff_in_pairsOfty_def
ion lemma in_add_keys_neq by (okup fmlookup (firstPass
lemma updateFi_subset: "pairsOf fi ⊆ proof e ureI) fix y la assume A: "(<inirsOf obtain x gamma where p_def: " (, gam) (ces nsideri | "x =
| "x ≠ y""updateFi nu (x, gamma) fi = fmupd x (findOrEmpt x f@fsaaga i i usingunl_patF by ets then o ")<in pairsOf (updateFijava.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
?or> ?fg = []") 1 then fdOEmtyx(fldptFn# )f next case ? by (simp add: A in_add_value in_findOrEmpty_iff_in_pairsOf p_def list_union_def) next case 3 then show ?thesis by (metis A in_add_keys_neq p_def) l qed lemma f l m (d(pateFin) i) using updal?r'xis
lemmahesis by( rts pdeFdf)
lemma_my frPas i irmp f f' using
lemmay_set " rstPass_def
findOrEmptymmatPass case then next caseuto thenjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0 qed
a"pu=o \>x No"
ction
ase
re
case java.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
then qed
lemma firstPass_neq_findOrEmpty assumes"fmlookup fi x ≠ Longrightarrow> pairsOf (firstPass ps nu fi) ⊆ lmstokha < asff" proof (then case None thenhave"fmlookup fi x = None"by (auto intro: firstPass_None) thenshownext nextobtainmma
hen<>[]" using firstPass_empty_set assms by fastforce then show ?thesis using assms atosmad SoeidOEpyde li to.si) qed
text‹pairsOf›
lemma firstPass_only_appends: "thenjava.lang.StringIndexOutOfBoundsException: Index 82 out of bounds for length 82 unfoldingPass_def proof(inductionps) caseNil thenshow?casebyauto next case(Consppsmoreovere"et<leftmostLookaheadsps-pairsOf(firstPasspsnufi) obtainygammawherep_def:"p=(y,gamma)"by(cases) ammardateFifi let?xFirst="findOrEmpty let?xFirst'="?xFirst@@proofrule showcase proof(cases"?xFirst(<inOfPass#')rjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 caseTrue thenshow?thesisusingp_defConsbyfirstPass_conss_consxammaaps2fiunfold_updateFixammajava.lang.StringIndexOutOfBoundsException: Index 87 out of bounds for length 87 next caseFalse noteouterFalse=this have"findOrEmptyx(foldr(updateFinu)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57 mupddrupdateFis) usingp_defFalseby(autosimpadd:updateFi_defjava.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 thenshow?thesisusingConsby(cases"x=y")(autosimpadd:list_union_deffindOrEmpty_def) qed qed
lemma \<Longrightarrow>suf\<noteq>[]\<Longrightarrow>la\<in>setsuf\<Longrightarrow>la\<notin>set(findOrEmptyxfi)" proof(inductionpsarbitrary:xfisuf) caseNil thenshow?casebyauto
java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 4 case(Conspps) obtainygammawherep_def:"p=(y,gamma)"by(casesp) let?fg="firstGammagammanu(foldr(updateFinu)psfi)" let?xFirst="findOrEmptyy(foldr(updateFinu)psfi)" letshowsfirst_sym show proof(cases" True then usingCons.IHCons.prems(1-3)_
next ealse obtain ) \Longrightarrow>xgpresuf\>setprods\ongrightarrownullable_gammaggpre proof(cases"x=y") caseTrue enhave"findOrEmptyx(rstPasssnu)First usingFalsep_def by(simpadd:findOrEmpty_deffirstPass_defupdateFi_def) proofases =(findOrEmptyxfi@suf')rstGammamanurstPassufi usingCons.prems(1)suf'_defTrue by(autoqed wesisnfoldinglist_union_defConsfeforce irstGamma_first_symr<>first_map_soundfig caseFalse thenhave"findOrEmptyx(firstPass(p#ps)nufi)=findOrEmptyx(firstPass\>(x,gamma)\<in>set(prodsg)\<la\<in>set(firstGammagammanufi)\>first_symgla(NTx)" usingp_defby(autosimpadd:findOrEmpty_defupdateFi_defproofjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 thenshow?thesisusingConsbyauto qed lookuppdrst@@?xFirst')?fi')y=omemerst\>tFirst qed
lemmapairsOf_injinoteqfirstPasspsnufi\<Longrightarrow>pairsOffi\<noteq>pairsOf(firstPassps) - assumeess Pass_preserves_apacsremsjava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68 usingfirstPass_neq_findOrEmpty by(metisfmap_ext) obtainsufwheresuf_def:"by(simpaddirstPass_not_equiv_candidates_lteserves_apacs_apac and""uf\<noteq>[] ingirstPass_only_appendsfyorce thenlaerea<n>setsuf"and"la\<notin>set(findOrEmptyyfi)" by(mesonfirstPass_suf_distinctlast_in_setsuf_def) thenshow?thesis _ndOrEmpty_iff_in_pairsOfsuf_defjava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47 byfastforce qed
lemmacaseNil \ proof(inductionps) caseNil thenshow?casebysimp next case(Conspps) Longrightarrow>\<exists>xFirst'.ookuprstPassitandsetxFirst\<subseteq>setxFirst'" fromCons.premshave"all_pairs_are_first_candidatesfirstGamma' unfoldingall_pairs_are_first_candidates_defusingfirstPass_cons_subsetbyblast thenthenaveookupirstPassp)u)lookupfixjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 by(autointro:in_firstGamma_in_leftmost_lkssimpadd:\<open>p=(x,gamma)\<close>) thenshow?caseusingCons.premsall_pairs_are_first_candidates_defbyfastforce qed
lemmafirstPass_not_equiv_candidates_lt:"all_pairs_are_first_candidates(stPassips \<Longrightarrow>fi\<noteq>(firstPasspsnufi) byfastforce proof casealse andA2:"fi\<noteq>(firstPassby(:open>pma<loseunfold_updateFi) have"finite(lhSetps\<times>leftmostLookaheadsps)" java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3 tstjava.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 33 \<subset>lhSetps\<times>leftmostLookaheadsps-pairsOffi" usingfirstPass_not_equiv_subsetfirstPass_subset_lhs_lksA1stforce matelyt<leftmostLookaheadsps-pairsOf(firstPasspsnufi)) <card(lhSetps\<times>leftmostLookaheadsps-pairsOffi)" by(autointro:psubset_card_mono thenshow"countFirstCandsps(firstPasspsnufi)<countFirstCandspsfi" unfoldingnext qed
lemmafirstPass_preserves_apac':"all_pairs_are_first_candidatesfips1ps2 \<Longrightarrow>all_pairs_are_first_candidates(firstPassps2nu#java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54 proofthen caseNil thenshow?caseunfoldingall_pairs_are_first_candidates_defby(simpadd:firstPass_def) next case(Conspps2') obtainxgammawherep_def:"p=(x(metisfmupd_lookup) thenshow?caseusingCons.IH[of"ps1@[p]"]Cons.prems proof(cases-Consereppre="ppre@[p]"],auto) updateFi_cases[wherex=xandnu=nuandgamma=gammaandi=rstPass] case(newla) thenhave"x'\<in>lhSet(ps1lemmafirstPass_equiv_right_nt'nullable_set_for<Longrightarrow>fi=rstPassufui if"(x',a<inpairsOfsOf(firstPasstPass(2nui)forjava.lang.StringIndexOutOfBoundsException: Index 74 out of bounds for length 74 fromthatconsider"x=x'"and"la'\<in>cases |"x=x'"and"la'\<in>set(firstGamma[where=erxuf] |"(x'lainpairsOf(firstPassps2'nufi)" unfoldingp_def gass_consofxmmaps2u]fold_updateFiamma in_add_keysin_add_keys_neqin_atleast1_list bymetis isngsremsonsf1p by(cases,ed simp:lhSet_defp_defall_pairs_are_first_candidates_defin_findOrEmpty_iff_in_pairsOf qed thenshow?thesisby(simpadd:all_pairs_are_first_candidates_def qed(autosimpadd:p_def) qed
lemmafirstPass_preserves_apac: "all_pairs_are_first_candidatesjava.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6 usingfirstPass_preserves_apac'[offi"[]"ps]byuto
text\<open>Terminationprooffor\<^term>\<open>mkFirstMap'\<close>giventhatjava.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5 sallhereforeeveryowingingeration<close
lemmamkFirstMap'_dom_if_apac: "mkFirstMap'psnufi\<noteq>None"if"all_pairs_are_first_candidatesfips" usingthat proof(induction"(ps,nu,fi)"arbitrary:fi rule:measure_induct_rule[wheref="\<lambda>(ps,nu,fi).countFirstCands] case ave\<>firstPasspsnufi\<Longrightarrow>countFirstCandsps(firstPasspsnufi)<countFirstCandspsi" usingless.premsby(simpadd:firstPass_not_equiv_candidates_ltfirstPass_preserves_apac) moreoverhave"fi\<noteq>firstPasspsnufi\<Longrightarrow>all_pairs_are_first_candidates(firstPasspsnufi)ps" usingless.premsby(rulefirstPass_preserves_apac) ultimatelyhaveF:"fi\<noteq>firstPasspsnufi\<Longrightarrow>mkFirstMap'psnu(firstPasspsnufi)\<noteq>None"by (simpadd:less.hyps) thenshow?case proof(cases"fi\<noteq>firstPasspsnufi") caseTrue thenshow?thesisusingFby(simpadd:mkFirstMap'.simps[ofpsnufi]) next caseFalse thenshow?thesisby(simpadd:mkFirstMap'.simps[ofpsnufi]) qed qed
lemmafirstSym_first_sym:assumes"first_map_soundfig"and"la\<in>set(firstSymsfi)" shows"first_symglas" proof(casess) case(NTx) thenshow?thesisusingassmsfirst_map_sound_defin_findOrEmpty_exists_setbyfastforce next case(Tx) thenshow?thesisusingassms(2)FirstTbyfastforce qed
lemmanullableSym_nullable_sym:assumes"nullable_set_fornug" shows"nullableSymsnu\<longleftrightarrow>nullable_symgs" proof(casess) case(NTx1) thenshow?thesisusingassmsnullable_set_sound_defnullable_set_complete_defbyfastforce next case(Tx2) thenshow?thesisby(simpadd:nullable_sym.simps) qed
lemmafirstGamma_first_sym':"nullable_set_fornug\<Longrightarrow>first_map_soundfig \<Longrightarrow>(x,gpre@gsuf)\<in>set(prodsg)\<Longrightarrow>nullable_gammaggpre \<Longrightarrow>la\<in>set(firstGammagsufnufi)\<Longrightarrow>first_symgla(NTx)" proof(inductiongsufarbitrary:gpre) caseNil thenshow?casebyauto next case(Consssyms) thenshow?case proof(cases"nullableSymsnu") caseTrue consider(la_in_firstSym)"la\<in>set(firstSymsfi)" |(la_in_firstGamma)"la\<in>set(firstGammasymsnufi)" usingCons.prems(5)Truebyauto thenshow?thesis proof(cases) casela_in_firstSym thenshow?thesisusingCons.prems(2,3,4)FirstNTfirstSym_first_symbyfast next casela_in_firstGamma have"(x,(gpre@[s])@syms)\<in>set(prodsg)"usingCons.prems(3)byauto moreoverhave"nullable_gammag(gpre@[s])" proof(rulenullable_app) show"nullable_gammaggpre"by(simpadd:Cons.prems(4)) next have"nullable_symgs"usingCons.prems(1)TruenullableSym_nullable_symbyauto thenshow"nullable_gammag[s]"by-(ruleNullableCons,autosimpadd:NullableNil) qed moreoverhave"la\<in>set(firstGammasymsnufi)"by(simpadd:la_in_firstGamma) ultimatelyshow?thesisusingCons.prems(1,2)by-(ruleCons.IH[wheregpre="gpre@[s]"]) qed next caseFalse thenshow?thesisusingfirstSym_first_symCons.prems(2,3,4,5)FirstNTbyfastforce qed qed
lemmafirstPass_equiv_complete:assumes"nullable_set_fornug""fi=firstPass(prodsg)nufi" shows"first_map_completefig" proof- have"first_symglas \<Longrightarrow>(\<forall>x.s=NTx\<longrightarrow>(\<exists>xFirst.fmlookupfix=SomexFirst\<and>la\<in>setxFirst))"forlas proof(inductionrule:first_sym.induct) case(FirstT) thenshow?casebyblast next case(FirstNTlxgpresgsufla) thenshow?case proof(casess) case(NTrx) thenobtainrxFirstwhere"fmlookupfirx=SomerxFirst\<and>la\<in>setrxFirst" usingFirstNT.IHbyauto thenshow?thesisusingFirstNT.hyps(1,2)NTassmsfirstPass_equiv_right_ntbyfastforce next case(Ty) fromFirstNT.hyps(3)have"la=LAy"by(cases)(autosimpadd:T) thenshow?thesisusingfirstPass_equiv_right_tusingFirstNT.hyps(1,2)Tassmsbyfastforce qed qed thenshow?thesisby(simpadd:first_map_complete_def) qed
lemmamkFirstMap'_complete:"nullable_set_fornug\<Longrightarrow>all_pairs_are_first_candidatesfi(prodsg) \<Longrightarrow>first_map_complete(the(mkFirstMap'(prodsg)nufi))g" proof(induction"countFirstCands(prodsg)fi"arbitrary:firule:less_induct) caseless let?fi'="firstPass(prodsg)nufi" obtainfi'wherefi'_def:"mkFirstMap'(prodsg)nu?fi'=Somefi'" by(mesonfirstPass_preserves_apacless.prems(2)mkFirstMap'_dom_if_apacnot_Some_eq) moreoverhave"first_map_complete(iffi=?fi'thenfielsefi')g" proof(cases"fi=?fi'") caseTrue thenshow?thesisusingfirstPass_equiv_completeless.prems(1)byauto next caseFalse have"countFirstCands(prodsg)?fi'<countFirstCands(prodsg)fi"by (simpadd:FalsefirstPass_not_equiv_candidates_ltfirstPass_preserves_apacless.prems(2)) moreoverhave"nullable_set_fornug"by(simpadd:less.prems(1)) moreoverhave"all_pairs_are_first_candidates?fi'(prodsg)"by (simpadd:firstPass_preserves_apacless.prems(2)) ultimatelyshow?thesis usingfi'_defless.hypsbyforce qed ultimatelyshow?caseby(autosimpadd:mkFirstMap'.simpsLet_def) qed
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.