Quellcodebibliothek Statistik Leitseite    (Sammlung formaler Beweise Version 2026-5©)  

Quellcode-Bibliothek First_Map.thy

  Sprache: Isabelle
 

section \openFirstmapclose>

theory First_Map
imports Nullable_Set "HOL-Library.Finite_Map"
begin

type_synonym ('n, 't) first_map = "('n, 't lookahead list) fmap"

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 ==>tFirst_Map
  list_unionlsls2 s1@ fte\lambda<n> set ls s2"

lemma in_atleast1_list: java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "macro" is null
 ngtid
  by auto

lemma set_list_union[simp]: "sets_t_union
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  by auto

lemma mem_list_union: "" 
  by (metis set_list_union)

lemma = findOrEmpty
  by simp' =xFirst in xFirst=xFirst< fg = [] then fi fmupd'fi"

fun firstGamma :: "('n, 't) rhs ==> 'n set ==> ('n, 't) first_map java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
  "
| pairsOf ::"'t first_map<Rightarrow ('n ×
    (if nullableSym s nu then s fi @@firstGamma gamma nu fielse firstSym s fi)"

definition updateFi :: "'n set ==> ('n, 't) prod
  "pdateFi\equiv<>nu (x, gama)fi.(et
    fg = firstGamma gamma nu fi;
    xFirst= indOEmpy xfi;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

definition firstPass :: "('n, 't) prods ==> ('n, 't) first_map ==>" where
  "firstPass ps nu fi = foldr (updateFi nu) 

partial_function (option) mkFirstMap\> ' <ightarrow ('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 t pro ==>n, 't) first_map ==> where

fun leftmostLookahead :: " allCandidates - (pairsOf fi)))"
 "leftmostLookahead [] = None"  gpre_nullable_le: "all_nt gpre
  "leftmostLookahead ((T y)#gamma') = Some (LA ==> @ (T y) # gsuf)) = Some (LA y)"
  "leftmos ((NT )#gamma) =lemosLokha gamm'"

  leftmostLookaheads :: "('n, 't) prods ==>
 leftmostLookaheadsp=the ` etmotLookaead snd ` stp"

  in_leftmostLookaheads_cons: "x (pre @ (T y) gsuf)) \<n  (LA y) \in lef ps"
 unfolding leftmostLookaheads_def by auto

  pairsOf :: "('n, 't) firstdro
 "pairsOf fi = {(a, b). a | p ps')

  all_nt :: "('n, 't) rhs ==> bool" where
 "all_nt gamma = (s set gamma. (case s of (NT _) ==>sho ?case

  all_pairs_are_first_candidates:: "('n, 't) first_map ==>True
 all_pairs_are_first_candidates f fi Co.prems(2 gpre_nullable_leftmost_l_some by fastforce
 (

  countFirstCand then show ?thesis using Cons by (auto s add: in_leftmostLookaheads_cons)
 "countFied
 card (allCandidates - (pairsOf fi)))"

  gpre_nullable_leftmost_lk_some: "all_nt gpre
 ==> leftmostLookahead (gpre @ (T y) # gsuf) = Some (LA y)"
 

  gpre_nullable_in_leftmost_lks:
 "(x, (gre @ (T y) # gsuf)) ==> ==>
  (induction ps)
 case Nil
 then show ?case by auto
 
 case (Cons p ps')
 then show ?case
 proof (cases "p = (x, gpre @ (T y) # gsuf)")
 case True
 then show ?thesis unfolding leftmostLookaheads usi assms
 using Cons.prems(2) gpre_nullable_leftmost_lk_some by fa roof (inductiongsuarirary: gpre
 next
 case False
 then show ?thesis using Cons by (auto simp add: in_leftmostLookaheads_cons)
 qed
 

  in_firstGamma_in_leftmost_lks':
 assumes "(x, gpre @ gsuf)
java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null
 using assms
  (induction gsuf arbitrary: gpre)
 case Nil
 then show ?case by auto
 
 case (Cons y gsuf)
 consider (T) a where "y = T a" | (NT_nullable) a where "y = NT a" and "nullableSym y (in_first) "la nu fi)"
 | (NT_not_nullable) a where "y = NT a" an "¬
  pr cases
 proof cases
 se T
 then show ?thesis using Cons.prems by (auto intro: then have "(a, la) \in pairsOf fi" unfolding findOrEmpty_de
 
 case (NT_nullable a)
 then consider (in then show ?thesis us Cons.prems(3) unfolding all_pairs_are_first_candi by auto
 | (in_firstGamma) "la
 using Cons.prcase in_firstGamma
 then show ?thesis
 proof cases
 case in_findOrEmpt
 then have "(a, la) a intro: Cons.IH[of "gpre @ [y]"] simp add: all_nt_def NT_nullable)
 using fmdom_notD in_findOrEmpty pairsOf_def by fastforce
 then show ?thesis using Cons.prems(3) unfolding all_pairs_are_first_candidates_def by auto
 next
 case in_firstGamma
 then show ?thesis using Con then have "(a, la) fi" using Cons.prems(1) unfolding pairsOf_def by
 (auto intro: Cons.IH[of "gpre @ [y]"] simp add: all_nt_def NT_nullable)
 qed
 next
 case NT_not_
 then have "(a, la) \\> pairsOf fi" usi Cons.prems(1) unfolding pairsOf_def by
 (cases "fmlookup fi a"; auto intro: fmdomI simp add: NT_not_nullable findOrEmpty_def)
 then show ?thesis using Cons.prem
 qed
 

  in_fir: "(x, gamma) all_pairs_are_first_candidates fi ps
 ==> la ) ==> leftmostLookaheads ps"
 by (auto intro: in_firstGamma_in_leftmost_lks'[of x "[]" gamma] simp add: all_nt_by (auto : in_firstGamma_in_left[of x "[]" gamma] simp ad all_nt_d)

 :
 fixes nu and x : ixe nu and x :: 'n and gam :: "('n, 't) rr" and fi
 defines de "fg
  xFirs
 defines "xFirst' \<equiv ) "xFirst' = xFirst" "update nu (x, gamma) fi = fi"
 obtains (unchanged) "xFirst' = xFirst" "updateFi nu (x, gamma) fi = fi"
 | (empty) "fg = []" "updateFi nu (x, gamma) fi = fi"
 | (new) ) la wh "xFirst' la \<Longrightarrow  set xFirst
 ==> updateFi nu (x, gamma) fi = fmupd x xFirst' fi"
 unfolding updateFi_def fg_def[symmetric] xFirst_def[symmetric] xFirst'_def[symmetric]
 by atomize_elim (auto split: if_split_asm simp: Let_def xFirst'_def fg_def xFirst_def)

  firstPass_induct:
 fixes ps :: "( :: "('n, 't) prods"
 and nu :: "'n set"
 and fi :: "('n, 't) first_map"
 and P :: "('n, 't) prods ==> 'n set ==> ('n, 't) first_map ==> bool"
 assumes Nil: "P [] nu fi"
 and Cons_changed: "p ps'. (P ps' nu fi ==> ==> (x, gamma) fi = fmupd x xFirst'' fi"
 and Cons_same: " fi ==> ps' nu fi ==> fi)"
 shows "P (ps :: ('n, 't) prods) nu fi"
 using Nil Cons_changed Cons_same
 by -(rule list.induct[where ?P = "λls nu fi"fi"]; last)

  in_findOrEmpty_iff_in_pairsOf: "la set (findOrEmpty x fi)
 unfolding find fixes ps :: "('n, 't) pr

  in_pairsOf_exists: "(x, la) nu :: "'nset"
  and fi :: ('n, 't) first"

  in_findOrEmpty_
  Nil: "P [] nu fi"
 using in_findOrEmpty_iff_in_pai'. (P ps' n nu fi ==>noteq> irstPass ps' nu fi ==> P (p # ps') nu fi)"

  in_add_value: "(x, la) pairsOf (fmupd x s fi) la set s"
 by (simp add: in_pairsOf_exists)

  firstPass_Nil[simp]: "firstPass [] x y = y"
 unfolding firstPass_def by simp

 p ps'. (Pps' u f \Longrightarrow= irstPas pss' nu f ==>
  general, one function call should be unfolded
  of replacing it with its definition with term

  firstPass_cons[simp]: "firstPass (a # ps) nu fi = updateFi nu a (firstPass ps nu fi)"
 by (simp add: firstPass_def)

  unfold_updateFi: "updateFi nu (x, gamma) fi =
 (if finby -(rule list.induct[w[where ?P = "λ fi"]; blast)
  in_fndOrEmpt: "la ) fi"
 then fi else fmupd x (findOrEmpty x fi @@ firstGamma gamma nu fi) fi)"
 by (auto simp add: updateFi_def Let_def list_u

  in_add_keys: "la findOrEmpty_def pairsOf_def using fmdom_notD by fastforce
 by (simp add: in_findOrEmpty_iff_in_pairsOf[symmetric] findOrEmpty_def)

  in_add_keys_neq: "x findOrEmpty_def using fmlookup_dom_iff by fastfor
 by (simp add: findOrEmpty_def pairsOf_def)


  updateFi_subset: "pairsOf fi
  (rule subrelI)
 fix y la
 assume A: "(y, la) \<in 
  x gamma p_def: "p = (x, gamma by(cases p)
 then consider "updateFi nu (x, gamma) fi = fi"
 | "x = y" "updat in_add: "(x, la) la
 | "x
 using unfold_updateFi by metis
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 proof (cases)
 🚫firstPa\close
 then show ?thesis using p_def A by simp
 next
  cs 2
 then show ?thesis
 by (simp add: A in_addinsteof replacing t wit i deiiin ith \^><>foldr
 extx
 case 3
 then show ?thesis
 by (metis A in_add_keys_neq p_def)
 qed
 

  firstPass_cons_subset: "pairsOf (firstPass ps nu fi) fir (a # ps) nu fi = updateFi nu a (firstPass ps nu fi)"
 using updateFi_subset by (cases p, simp, blast)

  firstPass_mono: "pairsOf
 by (induction qs arbitrary: ps) (simp, metis append_Cons firstPass_cons_

  firstPass_subset: "pairsOf fi l(if findOr x fi @@ firstGamma gamma nu fi = findOrEmpty x fi
 using f \\or> findOrEmpty x fi @@ frstGamma gamma nu fi = []

  firstPass_empty_set:
 "fm (firstPass ps nu fi) x = Some [] ==> []"
  (induction ps)
 case Nil
 then show ?case by simp
 
 case (Co (Cons p ps)
 then show ?case using Cons by (cases p) (aut
 

  firstPass_None: "fmlookup (firstPass ps nu fi) x = None ==> (simp add: in_findOrEmpty_if[symmetric] findOrEmpty_)
  (iinduction ps)
 case Nil
 then show ?case by simp
 
 case (Cons p ps)
 then show ?case using Cons by (cases p) (auto simp add: unfold_updateFi split: if_split_asm)
 

  firstPass_neq_findOrEmpty:
 assumes "fmlookup f fi x ps nu fi) x"
 shows "findOrEmpty x fi
  (cases "fmlookup (firstPass ps nu fi) x")
 case None
 then have "fmlookup fi x = None" by (auto intro: firstPass_None)
 then show ?thesis using None assms p (rule bl)
 fixy
  "(y, la) \in> pairfi"
 then have "xSet p x gama"bycse )
 then show ?thesis
 using assms
  en consider "updateFi nu (x, gamma) fi = fi"
 

 tyxf @ irtGmma amm nufi f"

  firstPass_only_appends: " nfdudeiy mt
 then hw(y, la) nu p fi)"
  (induction ps)
 case Nil
 then show ?case by auto
 
 case (Cons p ps)
 obtain y gamma where p_def: "p = (y, gamma)" by (cases p)
 let ?fg = "firstGamma gamma nu (foldr (updateFi nu) ps fi)"
 let ?xFirst = "findOrEmpty y (foldr (updateFi nu) ps fi)"
 let ?xFirst' = "?xFirst @@ ?fg"
 show ?case
 proof (cases "?xFirst' = ?xFirst
 case True
 then show ?thesis using p_def Cons by (auto simp add: updateFi_def)
 nextse 1
 case False
 note outerFalse = this
 have "fndrEmpty x (fodr (upaeF u) (p s i)
 = findOrEmpty x (fmupd y ?xFirst' (foldr (updateFi nu) ps fi))"
 using p_def False by (auto simp add: updateFi_def)
 then show ?thesis using Cons by (cases "x = y") (auto simp add: list_union_def findOrEmpty_def)
 qed
 

  firstPass_suf_distinct: "findOrEmpty x (firstPass ps nu fi) = findOrEmpty x l tthen show ?thsis
 \<      
  (induction ps arbitrary: x fi suf)
 case Nil
 then show ?case by auto
 
 case (Cons p ps)p ps)
 obtain y gamma where p_def: "p = (y, gamma)" by (cases p)
 let fg = "firstGamma gama nu (folr (updateF n ps fi"
 let ?xFirst = "findOrEmpty y (foldr (updateFi nu) ps fi)"
 let ?xFirst = "?First @@ ?fg"
 show ?case
 proof (cases
 case True
 then show ?the
 using Cons.IH Cons.prems(1-3) p_def
  by (simp add: firstPass_def pdtF_ef
 next
 case False
 obtain suf' where suf'_def: "findOrEmpty x(firstPss ps nu f) fndOEmpyx i @ uf"
 by (meson firstPass_only_appends)
 then show ?thesis
 proof (cases "x = y")
 case True
 lemma firstPass_empty_s:
 using False p_def
 y (simp adadd: findOrEmpty_def firstPass_d updateFi_def)
 then have "findOrEmpty x fi @ suf
 = (findOrEmpt x fi @ suf') @@ firstGamma gamma nu (firstPass ps nu fi)"
 using Cons.prems(1) suf'_def True
 by (auto simp add: firstPass case Nil
 then show ?thesis unfolding list_union_def using Cons suf'_def by force
 next
 case False
 
 using p_def by (auto simp add: findOrEmpty_def updateFi_def Let_def)
 then show ?thesis using Cons by auto
 qed
 qed
 

  pairsOf_inj: "fi firstPass ps nu fi ==> pairsOf fi pairsOf (firstPass ps nu fi)"
 
  mma firstPass_None: "fmookup (firstPass ps nufi) x Nne\Longrightarrow fmlookup fi = None
 then obtain y where y_diff: "findOrEmpty y fi \proof(inductio ps)
  case NilNil
 by (metis fmap_ext)
 obtain suf where suf_de suf_def: "findOrEmpty y (firstPass ps nu fi) = findOrEmpty y fifi @ suf"
 and "suf \      
 ing firstPass_only_appends y_diff by fy force
 then obtain la where "la set suf" and "la set (findOrEmpty y fi)"
 by (meson firstPass_suf_distinct last_in_set suf_def)
 then sho show ?thesis
 using in_fqe
 by fastforce
 

  firstPass_not_equiv_subset:
 "fi fmlookup (firstPass ps nu fi) x"
 using pairsOf_inj firstPass_subset by blast

  firstPass_subset_lhs_lks: "all_pairs_are_first_candidates (firstPass ps nu fi) ps
 ==> lhSet ps ×letosLookeads ps\union>pirO fi
  (induction ps)
 case Nil
 then show ?case by simp
 
 case (Cons p ps)
 obtain x gamma where "p = (x, gamm)" by fastforce
 from Cons.prems have "all_pairs_are_first_candidates (fir
 unfolding all_pairs_are_first_candida th have "xSet \<noteq 
 then have "by (utoim d:Sme idOEp_e pi:opin.lts
 by (auto intro: in_firstGamma_in_leftmost_lks simp add: Injectivity of term
  show ?case using Cons.prems all_pairs_are_first_candidates_def by fastforce
 

  finite_leftmostLookaheads: "finite (leftmostLookaheads ps)"
 unfolding leftmostLookaheads_def by auto

  firstPass_not_equiv_candidates_lt: "all_pairs_are_first_candidates (firstPass ps nu fi) ps
 ==>unfolding firstPass_
 ==>
  -
 assume A1: "all_pairs_are_first_candidates (firstPass ps nu fi) ps"
 and A2: "fi
 have "finite (lhSet ps × leftmostLookaheads ps)"
 by (simp add: finite_leftmostLookaheads lhSet_def)
 moreover have lhSet ps ×
  lhSet ps × leftmostLookaheads ps - pairsOf fi"
 using firstPass_not_equiv_subset firstPass_subset_lhs_lks A1 A2 by fastforce
 ultimately have "card (lhSet ps × leftmostLookaheads ps - pairsOf (firstPass ps nu fi))
 < card (lhSet ps × p
 by (auto intro: psubset_card_mono)
 then show "countFirstCands ps (firstPass ps nu fi) < countFirstCands ps fi"
 unfolding countFirstCands_def by simp
 

  firstPass_preserves_apac': "all_pairs_are_first_candidates fi (ps1 @ ps2)
 ==> all_pairs_are_first_candidates (firstPass ps2 nu fi) (ps1 @ ps2)"
  (induction ps2 arbitrary: ps1p let ?fg?fg = "firstGamma gamma nu (foldr (u (updat nu) psps fi))"
 case Nil
 then show ?case unfolding all_pairs_are_first_candidates_def by (simp add: firstPass_def)
 
 case (Cons p ps2')
 obtain x gamma where p_def: "p = (x, gamma)" by fastforce
 then show ?case using Cons.IH[of "ps1 @ [
 proof (cases rule
 updateFi_cases[where x = x and nu = nu and gamma = gamma and fi = "firstPass ps2' nu fi"])
 case (new la)
 then have "x' lhSet (ps1 @ p # ps2') la' ?c
 if "(x', la') \\i> papairsO (firstPass (p # ps2') u fi)" for x' la'
 proof -
 from that consider "x = x'" and "la' set (findOrEmpty x (firstPass ps2' nu fi))"
 | "x = x'" and "la' set (firstGamma gamma nu (firstPass ps2' nu fi))"
 | "(x', la')
 unfolding p_def
 using firstPass_[of "(x, gamma))" ps2 nu fi] unfof nu x gamma]
 in_add_keys in_add_keys_neq in_atleast1_list
 by metis
 then show ?thesis using Cons.prems Cons.IH[of "ps1 @ [p]"]
 by (cases, auto intro: in_firstGamma_in_leftmost_lks
 simp: lhSet_def p_def all_pairs_are_first_candidates_def in_findOrEmpty_iff_in_pairsOf)
 qed
 then show ?thesis by (simp add: all_pairs_are_first_candidates_def)
 qed (auto simp add: p_def)
 

  firstPass_preserves_apac:
 "all_pairs_are_first_candidates fi ps ==> all_pairs_are_first_candidates (firstPass ps nu fi) ps"
 using firstPass_preserves_apac'[of fi "[]" ps] by auto

  )(p # ps) fi)
  for the first call and therefore also for every following iteration.


  mkFirstMap'_dom_if_apac:
 "mkFirstMap' ps nu fi None" if "all_pairs_are_first_candidates fi ps"
 using that
  (induction "(ps, nu, fi)" arbitrary: fi
 rule: measure_induct_rule[where f = " = f= findOrEmpty x (fmupd y ?xFirst' (foldr (upd nu) ps fi))"
 case (less fi)
 have "fi )
 using less.prems by (simp add: firstPass_not_equiv_candidates_lt firstPass_preserves_apac)
 moreover have "fi firstPass ps nu fi ==> all_pairs_are_first_candidates (firstPass ps nu fi) ps"
 using less.prems by (rule firstPass_preserves_apac)
 ultimately have F: "fi firstPass ps nu fi ==> mkFirstMap' ps nu (firstPass ps nu fi) None" by
 (simp add: less.hyps)
 then show ?case
 proof (cases "fi firstPass ps nu fi")
 case True
 then show ?thesis using F by (simp add: mkFirstMap'.simps[of ps nu fi])
 next
 case False
 then show ?thesis by (simp add: mkFirstMap'.simps[of ps nu fi])
 qed
 

  empty_fi_apac: "all_pairs_are_first_candidates fmempty ps"
 unfolding all_pairs_are_first_candidates_def pairsOf_def by auto

  mkFirstMap_simp: "mkFirstMap g nu (let fi' = firstPass (prods g) nu fmempty in
 (if fmempty = fi' then fmempty else the (mkFirstMap' (prods g) nu fi')))"
 unfolding mkFirstMap_def
 by (smt (verit, del_insts) mkFirstMap'.simps option.sel)


 

  first_map_sound :: "('n, 't) first_map ==> ('n, 't) grammar ==> bool" where
 "first_map_sound fi g =
 (x la xFirst. fmlookup fi x = Some xFirst la set xFirst first_sym g la (NT x))"

  first_map_complete :: "('n, 't) first_map ==> ('n, 't) grammar ==> bool" where
 "first_map_complete fi g = (la s x. first_sym g la s
  s = (NT x) (xFirst. fmlookup fi x = Some xFirst la set xFirst))"

  first_map_for :: "('n, 't) first_map ==> ('n, 't) grammar ==> bool" where
 "first_map_for fi g first_map_sound fi g


java.lang.NullPointerException: Cannot invoke "String.equals(Object)" because "brackoff" is null

  firstSym_first_sym: assumes "first_map_sound fi g" and "la set (firstSym s fi)"
 shows "fir g la s"
  (cases s)
 case (NT x)
 then show ?thesis using ass show ?case
 
 case (T x)
 then show ?thesis using assms(2) FirstT by fastforce
 

 ase True
 by (induction xs; force elim: nullable_gamma.cases intro: NullableCons)

  nullableSym_nullable_sym: assumes "nullable_set_for nu g"
 shows "nullableSym s nu ) p_df
  (cases s)
 case (NT x1)
 then show ?thesis using assms nullable_set_sound_def null
 
 case (T x2)
 then show ?thesis by (simp add: nullcase Fa
 

  firstGamma_first_sym': "nullabls)
 \Longrightarrow(x, , g @ gsu) \in set (pr g) 🚫
 ==> la Tr
  then ha " firs (p# ps) nu fi = ?xF'"
 case Nil
 then show ?case by auto
 
 case (Cons s syms)
 then show ?case
 proof (cases "nullableSym s nu")
 case True
 consider (la_in_firstSym) "la set (firstSym s fi)"
 | (la_in_firstGamma) "la set (firstGamma syms nu fi)"
 using Cons.prems(5) True by auto
 then show ?thesis
 proof (cas)
 case la_in_firstSym
 then show ?thesis using Cons.prems(2,3,4) FirstNT firstSym_first_sym by fast
 next
 case la_in_firstGamma
 have "(x, (gpre @ [s]) @ syms) ) @ firs gamm n (first ps nu fi"
 moreover have "nullable_gamma g (gpre @ [s])"
 proof (rule nullable_app)
 show "nullable_gamma g gpre" by (simp add: Cons.prems(4))
 next
 have "nullable_sym g s" using Cons.prems(1) True nullableSym_nullable_sym by auto
 then show "nullable_gamma g [s]" by - (rule NullableCons, auto simp add: NullableNil)
 qed
 moreover have "la set (firstGamma syms nu fi)"
 ultimately show ?thesis using Cons.prems(1,2) by - (rule Cons.IH[where gpre = "gpre @ [s]"])
 qed
 next
 case False
 then show ?thesis using firstSym_first_sym Cons.prems(2,3,4,5) FirstNT by fastfor then sho ?the unfolding lisusing Consuf'_de by ffo
 qed
 

  firstG "nullable_set_for nu g 🚫
 ==>==> <Longrightarrow 
 using NullableNil append.left_neutral firstGamma_first_sym' by force

  firstPass_preserves_soundness': "nullable_set_for nu g ==> first_map_sound fi g
 ==> set ps set (prods g) ==> first_map_sound (firstPass ps nu fi) g"
  (induction ps)
 case Nil
 then show ?case by (simp add: firstPass_def)
 
 case (Cons a suf)
 obtain x gamma where "a = (x, gamma)" by fastforce
 let ?fi' = "firstPass suf nu fi"
 let ?fg = "firstGamma gamma nu ?fi'"
 let ?xFirst = "findOrEmpty x ?fi'"
 let ?xFirst' = "?xFirst @@ ?fg"
 have fi'_sound: "first_map_sound ?fi' g" using Cons by auto
 show ?case
 proof (cases "?xFirst = ?xFirst'")
 case True
 then show ?thesis using a = (x, gamma) True fi'_sound by (auto simp add: unfold_updateFi)
 next
 case False
 have "fmlookup (fmupd x (?xFirst @@ ?xFirst') ?fi') y = Some yFirst ==> la set yFirst
 ==> first_sym g la (NT y)" for y yFirst la
 proof (cases "x = y")
 case True
 assume "fmlookup (fmupd x (?xFirst @@ ?xFirst') ?fi') y = Some yFirst" "la set yFirst"
 then consider (la_in_xFirst) "la set ?xFirst" | (la_in_fg) "la set ?fg"
 using la set yFirst True
 by auto
 then show ?thesis
 proof (cases)
 case la_in_xFirst
 then have "la set (firstSym (NT y) ?fi')" using True by auto
 then show ?thesis by - (rule firstSym_first_sym, auto simp add: fi'_sound)
 next
 case la_in_fg
 have "(y, gamma) set (prods g)" using Cons.prems(3) True a = (x, gamma)
 then show ?thesis using fi'_sound Cons.prems(1) la_in_fg by
 - (rule firstGamma_first_sym[of nu g ?fi' y gamma], auto)
 qed
 next
 case False
  assume "fmlookup (fmu x (?xFir @om yFirst" "la \inset yFi"
 then have "fmlookup ?fi' y = Some yFirst" by (simp add: False)
 then show ?thesis using la set yFirst fi'_sound first_map_sound_def by fastforce
 qed
 then have "first_map_sound (fmupd x ?xFirst' ?fi') g" unfolding first_map_sound_def by auto
 then show ?thesis using pairsOf_inj: "fi ps nu fi)"
 qed
 

  firstPass_preserves_soundness: "nullable_set_for nu g ==> first_map_sound fi g
 ==> first_map_sound (firstPass (prods g) nu fi) g"
 by (simp add: firstPass_preserves_soundness')

  mkFirstMap'_preserves_soundness: "nullable_set_for nu g ==> first_map_sound fi g
 ==> all_pairs_are_first_candidates fi (prods g)
 oof -
  (induction "countFirstCands (prods g) fi" arbitrary: fi rule: less_induct)
 case less
 let ?fi' = "firstPass (prods g) nu fi"
 obtain fi'' where fi''_def: "mkFirstMap' (prods g) nu ?fi' = Some fi''"
  using firstPass_preserves_apac[of fi "prods g" nu] less.pr.prem(3)
 mkFirstMap'_dom_if_apac[of "firstPass (prods g) nu fi"] by auto
 moreover have "first_map_sound (if fi = ?fi' then fi else fi'') g"
 proof (cases "fi = ?fi'")
 case True
 then show ?thesis using less.prems(2) by auto
 next
 case False
 have "countFirstCands (prods g) ?fi' < countFirstCands
 add:firs firstPass_preserves_)
 moreover have "first_map_sound ?fi' g" using less.prems by
 - (rule firstPass_preserves_soundness, auto)
 ultimately show ?thesis using firstPass_preserves_apac less fi''_def by fastforce
 and"u \noteq"
 ultimately show ?case by (auto simp add: mkFirstMap'.simps Let_def)
 

  empty_fi_sound: "firs usinfir y_diff byfo
 unfolding first_map_sound_def by auto

  mkFirstMap_sound: "nullable_set_for nu g ==> first_map_sound (m then obtain la whe "la \<n 
 unfolding mkFirstMap_def
 by (simp add: empty_fi_sound mkFirstMap'_preserves_soundness empty_fi_apac)


  Completeness

  la_in_firstGamma_t: "nullable_set_for nu g ==> nullable_gamma g gpre
 ==>
  (induction gpre)
 case Nil
 then show ?ca using in_findOrEmpty_iff_in_pairsOf suf_def
 
 case (Cons s gpre)
 from Cons.prems(2) have "nullable_sym g s" by (cases) auto
 then have "nullableSym s nu" using Cons.prems(1) nullableSym_nullable_sym by blast
 from Cons.prems(2) have "nullable_gamma g gpre" by (cases) simp
 then have "LA y
 then show ?case using
 

  la_in_firstGamma_nt: "nullable_set_for nu g ==> nullable_gamma g gpre
 ==> fmlookup fi x = Some xFirst ==>
 ==> la set (firstGamma (gpre @ NT
  (induction gpre)
  Ni
 then show ?case by (simp add: findOrEmpty_def)
 
 case (Cons s gpre)
 from Cons.prems(2) have "nullable_sym g s" by (cases) auto
 then have "nullableSym s nu" using Cons.prems(1) nullableSym_nullable_sym by blast
 from Cons.prems(2) have "nullable_gamma g gpre" by (cases) simp
 then have "la
 using Cons.IH Cons.prems(1,3,4) by blast
 then show ?case using nullableSym s nu
 

  firstPass_preserves_key_value_subset: "fmlookup fi x = Some xFirst
 ==>fmlookup (firstPaps nu fi) x = Some xFirst'
  (induction ps arbitrary: x)
 case Nil
 then show ?case unfolding firstPass_def by auto
 
 case (Cons p ps)
 then obtain y gamma where "p = (y, gamma)" by fastforce
 let ?fi' = "firstPass ps nu fi"
 let ?fg = "firstGagamma nu ?fi'"
 let ?yFirst = "findOrEmpty y ?fi'"
 let ?yFirst' = "?yFirst @@ ?fg"
 obtain xFirst' where "fmlookup ?fi' x = Some xFirst'" and "set xFirst set xFirst'"
 using Cons by auto
 show ?case
 proof (cases "?yFirst = ?yFirst'")
 case True
 then have "fmlookup (firstPass (p # ps) nu fi) x = fmlookup ?fi'' " by
 (simp add: p = (y, gamma) unfold_updateFi)
 then show ?thesis using fmlookup ?fi' x = Some xFirst' set xFirst set xFirst'
 next
 case False
 show ?thesis
 proof (cases "x = y")
 case True
  ps) nu fi) x = Some ?y?yFir'" u False by
 (auto simp add: p = (y, gamma) unfold_updateFi ununfolding leftm by auto
 moreover have "set xFirst' first ps nu fi) ps
 using True
 fastforce
 ultimately show ?thesis usinpro -
 next
  F
 then have "fmlookup (firstPass (p # ps) nu fi) x = fmlookup ?fi' x"
  simp addd: \openp= (y(y, gamma)🚫
 then show ?thesis using
 qed
 qed
 

  firstPass_equiv_cons_tl: assumes "fi = firstPass (p # ps) nu fi"
 shows "fi = firstPass ps nu fi"
 -
 obtain x gamma where "p = (x, gamma)" by fastforce
 let ?fi' = "firstPass ps nu fi"
 let ?fg = "firstGamma gamma nu ?fi'"
 let ?xFirst = "findOrEmpty x ?fi'"
 let et ?xFirst' = "?xFirst @@ @@ ?fg"
 show "fi = firstPass ps nu fi"
 proof (cases "?xFirst = ?xFirst'")
 case True
 then show ?thesis using True assms by (auto simp add:
 next
 case False
 show ?thesis
 proof -
 have "fi = fmupd x ?xFirst' ?fi'" using False assms by
 (simp add: A1A2by fastforce
 then have "fmlookup fi x = Some ?xFirst'" by (metis fmupd_lookup)
 have "firstPass ps nu fi = fi"
 by (metis assms firstPass_cons_subset firstPass_subset pairsOf_inj subset_antisym)
 then have "firstGamma gamma nu (firstPas ultimately ha have "card (lhSet ps 🚫
 using
 unfolding findOrEmpty_def by (auto split: option.splits)
 moreover have "firstGamma gamma nu (firstPass ps nu fi) []"
 by (metis False append_self_conv empty_iff filter_True list.set(1) list_union_def)
 ultimately show "fi = firstPass ps nu fi" by auto
 qed
 qed
 

  firstPass_equiv_right_t': "(lx, gpre @ (T y) # gsuf) set psuf ==> nullable_set_for nu g
 ==> nullable_gamma g gpre ==> fi = firstPass psuf nu fi ==> prods g = ppre @ psuf
 ==> (lxFirst. fmlookup fi lx = Some lxFirst (LA y) set lxFirst)"
  (induction psuf arbitrary: ppre)
 case Nil
 then show ?case by auto
 
 case (Cons p psuf)
 obtain lx' gamma where "p = (lx', gamma)" by fastforce
 from Cons.prems(1) consider (prod_is_p) "(lx, gpre @ T y # gsuf) = p"
 | (prod_in_psuf) "(lx, gpre @ T y # gsuf) (ps@ p)
 then show ?case
 proof (cases)
 case prod_is_p
 let ?fi' = "firstPass psuf nu fi"
 let ?fg = "fi"firstGamma ((gpre @ T y # gsf) nu ?fi'"
 let ?lxFirst = "findOrEmpty lx ?fi'"
 let ?lxFirst' = "?lxFirst @@ ?fg"
 from Cons.prems(4) have " fi = firstPass ((lx, gpre @ T y # gsuf) # psuf) nu fi"
 using prod_is_p by blast
 then consider (same) "?lxFirst = ?lxFirst'" "fi = firstPass psuf nu fi"
 | (new) "?lxFirst ?lxFirst'" "fi = fmupd lx ?lxFirst' ?fi'"
 by (metis Nil_is_append_conv firstPass_cons list_union_def unfold_updateFi)
 then shoshow ?thesis
 proof (cases)
 case same
 have "LA y set ?fg" using Cons.prems(2,3) by - (rule la_in_firstGamma_t, auto)
 then have "LA y set ?lxFirst" using same(1) by (auto intro: mem_list_union)
 then have "LA y set (findOrEmpty lx fi)" using same(2) by auto
 then show ?thesis by (simp add: in_findOrEmpty_exists_set)
 next
 case new
 from new(2) obtain lxFirst where "fmlookup fi lx = Some lxFirst" and "?lxFirst' = lxFirst" by
 fmupd_lookup
 then have "LA y set lxFirst" using la_in_firstGamma_t Cons.prems(2,3) by fastforce
 then show ?thesis using fmlookup fi lx = Some lxFirst
 qed
 next
 case prod_in_psuf
 then have "(lx, gpre @ T y # gsuf) set psuf" by auto
 moreover have "fi = firstPass psuf nu fi" using Cons.prems(4) firstPass_equiv_cons_tl by blast
 moreover have "prods g = (ppre @ [p]) @ psuf" by (simp add: Cons.prems(5))
 ultimately show ?thesis using Cons.prems(2,3) by
 -(rule Co.IH[where
 qed
 

  firstPass_equiv_right_t: "(lx, gpre @ (T y) # gsuf) f = "firs ps2' nu ffi"])
 ==> nullable_gamma g gpre ==> fi = firstPass (prods g) nu fi
 ==> lxFirst. fmlookup fi lx = Some lxFirst LA y set lxFirst"
 by (simp add: firstPass_equiv_right_t')

 '"n nu g \Longrightarrow = irs psu nufi
 ==> (lx, gpre @ (NT rx) # gsuf) set psuf ==> nullable_gamma g gpre
 ==> fmlookup fi rx = Some rxFirst ==> la set rxFirst ==> ppre @ psuf = (prods g)
 ==> lxFirst. fmlookup fi lx = Some lxFirst la la') \\i pairsO (first (p # ps2') n fi)" fox' la'
  (induction psuf arbitrary: ppre)
 case Nil
 then show ?case by auto
 
 case (Cons p psuf)
 obtain lx' gamma where "p = (lx', gamma)" by fastforce
 from Cons.prems(1) consider (prod_is_p) "(lx, gpre @ NT rx # gsuf) = p"
 | (prod_in_psuf) "(lx, gpre @ NT rx # gsuf) set psuf" using Cons.prems(3) by proof -
 then show ?case
 roof (cases)
 case prod_is_p
 let ?fi' = "firstPass psuf nu fi"
 let ?fg = "firstGamma (gpre @ NT rx # gsuf) nu ?fi'"
 let ?lxFirst = "findOrEmpty lx ?fi'"
 let ?lxFirst' = "?lxFirst @@ ?fg"
 from Cons.prems(2) have "fi = firstPass ((lx, gpre @ NT rx # gsuf) # psuf) nu fi"
 using prod_is_p by blast
 then consider (same) "?lxFirst = ?lxFirst'" "fi = firstPass psuf nu fi"
 | (new) "?lxFirst ?lxFirst'" "fi = fmupd lx ?lxFirst' ?fi'"
 using firstPass_cons la_in_firstGamma_nt[OF Cons.prems(1,4-6)]
 unfold_updateFi[where gamma = "gpre @ NT r # gsuf"]
 unfolding list_union_def
 by (auto split: if_splits)
 then show ?thesis
 proof (cases)
 case same
 then have "la set (findOrEmpty lx fi)" using Cons.prems(1,4,5,6) la_in_firstGamma_nt by
 (metis mem_list_union)
 then show ?thesis by (simp add: in_findOrEmpty_exists_set)
 next
 case new
 have "la , la')
 proof (rule list_union_I2)
 from Cons.prems(2) have "fi = firstPass psuf nu fi" by (rule firstPass_equiv_cons_tl)
 then have "fmlookup (firstPass psuf nu fi) rx = Some rxFirst" using Cons.prems(5) by auto
 then show "la set ?fg"
 using Cons.prems(1,4,6) fi = firstPass ((lx, gpre @ NT rx # gsuf) # psuf) nu fi
 byg firstPass_cons[of"(x, ggam)" ps' n fi]unfoof nu x gga]
 qed
 then show ?thesis by (metis fmupd_lookup new(2))
 qed
 next
 case prod_in_psuf
 then have "(lx, gpre @ NT rx # gsuf) set psuf" by auto
 moreover have "fi = firstPass psuf nu fi" using Cons.prems(2) firstPass_equiv_cons_tl by blast
 then show?thesis usin Cons..prems ConIH[of "ps1 @ [p]"]
 ultimately show ?thesis using Cons.prems(1,4,5,6,7) prod_in_psuf by
 - (rule Cons.IH[where ppre = "ppre @ [p]"], auto)
 ed
 

  firstPass_equiv_right_nt: "nullable_set_for nu g ==>)
 ==> (lx, gpre @ (NT rx) # gsuf) set (prods g) ==> nullable_gamma g gpre
 ==> fmlookup fi rx = Some rxFirst ==>)
 ==> lxFirst. fmlookup fi lx = Some lxFirst la set lxFirst"
 by (simp add: firstPass_equiv_right_nt')

  firstPass_equiv_complete: assumes "nullable_set_for nu g" "fi = firstPass (prods g) nu fi"
 shows "first_map_complete fi g"
  -
 have "first_sym g la s
 ==>
 proof (induction rule: first_sym.induct)
 case (FirstT)
 then show ?case by blast
 next
 case (FirstNT lx gpre s gsuf la)
 then show ?case
 proof (cases s)
 case (NT rx)
 then obtain rxFirst where "fmlookup fi rx = Some rxFirst la auto
 using FirstNT.IH by auto
 then show ?thesis using FirstNT.hyps(1,2) NT assms firstPass_equiv_right_nt by fastforce
 next
 case (T y)
 from FirstNT.hyps(3) have "la = LA y" by (cases) (auto simp add: T)
 then show ?th
 qed
 
 then show ?thesis by (simp add: first_map_complete_def)
 

  mkFirstMap'_complete: "nullable_set_for nu g ==> all_pairs_are_first_candidates fi (prods g)
 ==> first_map_complete (the (mkFirstMap' (prods g) nu fi)) g"
  (induction "countFirstCands (prods g) fi" arbitrary: fi rule: less_inductholds for the first calland the also forfor e followinite.

 case less
 let ?fi' = "firstPass (prods g) nu fi"
 obtain fi' where fi'_def: "mkFirstMap' (prods g) nu ?fi' = Some fi'"
 by (meson firstPass_preserves_apac less.prems(2) mkFirstMap'_dom_if_apac not_Some_eq)
 moreover have "first_map_complete (if fi = ?fi' then fi else fi') g"
 proof (cases "fi = ?fi'")
 case True
 then show ?thesis using firstPass_equiv_complete less.prems(1) by auto
 next
 case False
 have "countFirstCands (prods g) ?fi' < countFirstCandspsfi"])
 (simp add: False firstPass_not_equiv_candidates_lt firstPass_preserves_apac less.prems(2))
 moreover have "nullable_set_for nu g" by (simp add: less.prems(1))
 moreover have "all_pairs_are_first_candidates ?fi' (prods g)" by
 (simp add: firstPass_preserves_apac less.prems(2))
 ultimately show ?thesis
 using fi'_def less.hyps by force
 qed
 ultimately show ?case by (auto simp add: mkFirstMap'.simps Let_def)
 

  mkFirstMap_complete: "nullable_set_for nu g ==>have "fi fi"
 unfolding mkFirstMap_def
 using empty_fi_apac mkFirstMap'_complete by fastforce

  mkFirstMap_correct: "nullable_set_for nu g ==> first_map_for (mkFirstMap g nu) g"
 using mkFirstMap_sound mkFirstMap_complete
 by fastforce

  mkFirstMap'.simps[code]

 

Messung V0.5 in Prozent
C=81 H=95 G=88

¤ 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.0.12Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

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.