\<comment> ‹type inference algorithm W› fun W :: "[expr, ctxt, nat] => result_W" where "W (Var i) A n =
(if i < length A then Some( id_subst,
bound_typ_inst (λb. TVar(b+n)) (A!i),
n + (min_new_bound_tv (A!i)) )
else None)"
| "W (Abs e) A n = ( (S,t,m) := W e ((FVar n)#A) (Suc n);
Some( S, (S n) -> t, m) )"
| "W (App e1 e2) A n = ( (S1,t1,m1) := W e1 A n;
(S2,t2,m2) := W e2 ($S1 A) m1;
U := mgu ($S2 t1) (t2 -> (TVar m2));
Some( $U ∘ $S2 ∘ S1, U m2, Suc m2) )"
| "W (LET e1 e2) A n = ( (S1,t1,m1) := W e1 A n;
(S2,t2,m2) := W e2 ((gen*
( $2<>,type inference algorithm W›"expr,t nt] => resW"
declare Suc_le_lessD [simp]
inductive_simps _pe_simps >b. TVar(b+n), "A ⊨2m): W ($1A 1;U =mu(S 1 t > TVar m2)) "A <turnstile S1, t2, m2) )" "A ⊨ Var n :: t" "Aturnstile LET e1 e2 ::t"
\<comment> ‹the resulting type variable is always greater or equal than the given one› lemma W_var_ge: "WeAn=Some(S,t,m)\<Longrightarrow>n\<le>m" proof(inductionearbitrary:AnStm) caseVarthus?caseby(autosplit:if_splits) next caseAbsthus?caseby(fastforcesplit:split_option_bind_asm) next caseAppthus?caseby(fastforcesplit:split_option_bind_asm) next caseLETthus?caseby(fastforcesplit:split_option_bind_asm) qed
declare W_var_ge [simp] (* FIXME*)
lemma W_var_geD: "Some (S,t,m) = W e A n ==> n≤m" by (metis W_var_ge)
lemma new_tv_compatible_W: "new_tv n A ==> Some (S,t,m) = W e A n ==> new_tv m A" by (metis W_var_ge new_tv_le)
lemma new_tv_bound_typ_inst_sch: "new_tv n sch ==> new_tv (n + (min_new_bound_tv sch)) (bound_typ_inst (λb. TVar (b + n)) sch)" proof (induction sch) case FVar thus ?caseby simp next case BVar thus ?caseby simp next case SFun thus ?caseby(auto simp add: max_def nle_le dest: new_tv_le add_left_mono) qed
―‹resulting type variable is new› lemma new_tv_W [rule_format]: "∀n A S t m. new_tv n A ⟶ W e A n = Some (S,t,m) ⟶ new_tv m S ∧ LET e1 e2 ::t" proof (induction e) case"W A nn SomStm <> n <le m" by (auto simpary next case
by (metis_Consw_tv_SucW next case App ?case apply (imp split: split_option_bind) by (smt (verit, ccfv_threshold) W_var_geD fun.map_comp lessI mgu_new new_tv_Fun new_tv_Suc new_tv_le new_tv_subst new_tv_subst_comp_1 new_tv_subst_scheme_list new_tv_subst_te) next caseLETthus ?case apply (simp split: split_option_bind) by (metis W_var_ge new_tv_Cons new_tv_compatible_gen new_tv_le new_tv_subst_comp_1 new_tv_subst_scheme_list) qed
lemma free_tv_bound_typ_inst1: "v ∉ free_tv sch ==> v ∈ free_tv (bound_typ_inst (TVar ∘ S) sch) ==>∃x. v = S" by (induction sch)auto
lemma W_var_genew_tv_le) "W e A n = Some (S,tm \Longrightarrow >free_tv S ∨free_tv t) ==> v∈ proof (induction e arbitrary: n A S t m v) case (Var i) show ?case proof (cases "v case with by(etis(1) free_tv_nth_A_impl_free_tv_A) next case False new_tv_W]: with Var show ?thesis by (forcempl_free_tv_A_nd_typ_inst1
split: if_split_asm qed next
m then re"e(FVn # A) (Suc n) = So (S1, t1, n1)" by (metis) .(2) not_None_eq option_bind_eq_None prod_cases3) then (, ccfv_threshold .map_complessI new_tv_Fun new_tv_le new_tv_subst_comp_1 new_tv_subst_te using? by (force:codD) nextbymetis W_var_genew_tv_Consnew_tv_compatible_gen new_tv_subst_comp_1) case (Appfree_tv_bound_typ_inst1 thenshow ?case proof (clarsimpWeAn (Stm \> fix(<>free_tv v∈ v<n <Longrightarrow free_tvA assume v: "v ∈proofsesv in fre(A!i)")
and: "W A n = Some (S', t' )" and and: "gu $ t') (t1 -> TVar n2) =So S2"
n1n1 n2" using e1 b aut show "\in>free_tv using v nAS proof
v1\ free_tv ($ S2 ∘ thenv< e_tv free_tv (λ by ( Abs [of"nA"Suc vs
setD moreover have"free_tv S2 ⊆ free_tv ($ S2 ∘ S') ∨ free_tv (S2 n2)" usingmgu mgu_freeby fastforce ultimately show"v <> free_tv A" using.IH open<n› codD
smt_ee_tv_app_subst_te funhaven<>n1 next assume: " in free_tv (S2 n2)" thenhave"v < n1" using.premslinarith
then free_tv S2 <on v<n› e1st_scheme_list using.compct_trans2 thenshow"v ∈" using App.IH \>v<n›v<n1›e1bst_scheme_list by tit _st usingblast qed
u Appv<n›‹› e1 e2 codD free_tv_app_subst_scheme_list next (nASt2n3v) thenshow?case proof(p:plit_option_bind_asmsm.it_asm fixS1t1n2S2 assumev<free_tv($S2\<circ>S1>v\<in>free_tvt2" and"v<n" and"WnmeS12java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40 and"We2(gen($S1A)t1#$S1A)n2=Some(S2,t2,n3)" withLET.IH show"ome1 byeritn_iffvar_geDgeDcodDfree_tv_app_subst_scheme_list _mp_scheme_list ue2
lemmajava.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
lemmaa
\<comment>\<open>correctnessofWwithrespecto{ext_ype<> lemmaW_correct_lemma:"\<lbrakk>new_tvnA;Some(S,t,m)=WeAn\rbrakk>\<Longrightarrow>$SA\<turnstile>e::t" roofinductionduction"arbitraryitrarySmn caseVarthus usingis_bound_typ_instancebytof_splits next caseshowase apply(simpsplit1e2java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19 by(metisAbsIapp_subst_ConsandSa$)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56 new_tv_FVarnew_tv_Suc) next casemetis.)r_geDWe21 thenshow?casese proof(simpsplit:split_option_bind_asmprod.splits) fixS1t1n1S2t2n2S3 assumee1:"We1AthenhaveveRSa and:21n1met2" andmgu:"mgu($S2t1)(t2->TVarn2)=SomeS3" is proof(ruleas_type_type.) tiscomp_scheme_listt) _yburger withAppshow"$ yiso_typestypes)pebst_Funep_subst_TVar_ras_type_cl_subt_comp_scheme_liste_listlist show"$prooftroree_eq_subst_scheme_listlist usinge1e2mguApp by(show"aa$(xjava.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31 subst_comp_scheme_listnalast qed qed next ()sse proof(simpsplit:bydef<ma\<noteq>na\<close>comp_apply) fix(simpimpadde1 assume"new_tvnA" andn(A(#<>2:'" ande2:"We2(gen($S1 show"$(<>.)\>LETe1e2::t" of(rulehas_typeypeETI show"$(\<lambda>a.$S2(S1a))<>e1::$S2t1" usingLETe1by(metis(no_types,lifting)has_type_cl_subsubst_comp_scheme_list) have"free_tvS2\<inter>(free_tvt1-free_tv($S1A))={}" usinge1e2LET by(smt(verit)DiffD2Diff_subsetfree_tv_Wfree_tv_gen_cons free_tv_le_new_tvnew_tv_WsubsetDweaken_A_Int_B_eq_empty) then show"gen($(\<lambda>a.$S2(S1a))A)($S2t1)#$(\<lambda>a.$S2(S1a))A\<turnstile>e2::t" usinge1e2LET by(metisapp_subst_Consgen_subst_commutesnew_tv_Consnew_tv_Wnew_tv_compatible_W new_tv_compatible_gennew_tv_subst_scheme_listsubst_comp_scheme_list) qed qed qed
\<comment>\<open>CompletenessofWw.r.t.@{texthas_type}\<close> lemmaW_complete_lemma: "\<lbrakk>$S'A\<turnstile>e::t';new_tvnA\<rbrakk>\<Longrightarrow> \<exists>St.(\<exists>m.WeAn=Some(S,t,m))\<and>(\<exists>R.$S'A=$R($SA)\<and>t'=$Rt)" proof(inductionearbitrary:S'At'n) case(Varu)thus?case proof(clarsimpsimpadd:has_type_simpsis_bound_typ_instance) fixS::"nat\<Rightarrow>typ" assumeA:"new_tvnA""u<lengthA" show"\<exists>R.$S'A=$RA\<and> bound_typ_instS($S'A!u)=$R(bound_typ_inst(\<lambda>b.TVar(b+n))(A!u))" proof(introexIconjI) show"$S'A=$(\<lambda>x.ifx<nthenS'xelseS(x-n))A" usingVar.prems(2)new_if_subst_type_scheme_listbyforce show"bound_typ_instS($S'A!u)=$(\<lambda>x.ifx<nthenS'xelseS(x-n))(bound_typ_inst(\<lambda>b.TVar(b+n))(A!u))" usingA by(simpadd:new_if_subst_type_schemenew_tv_nth_nat_Ao_defnth_subst flip:bound_typ_inst_composed_subst) qed qed next case(AbseS'At'n) thenobtaint1t2where"t'=t1->t2""mk_schemet1#$S'A\<turnstile>e::t2" by(autosimp:has_type_simps) withAbs.premsAbs.IH[of"\<lambda>x.ifx=nthent1else(S'x)""(FVarn)#A"t2"Sucn"] show?case by(forcedest!:mk_scheme_injective) next case(Appe1e2) thenobtaint2wheree2t:"$S'A\<turnstile>e2::t2"ande1t:"$S'A\<turnstile>e1::t2->t'" by(autosimp:has_type_simps) thenobtainStmR wheree1:"We1An=Some(S,t,m)"andR:"$S'A=$R($SA)""t2->t'=$Rt" usingAppbyblast withApp.premshavenew_tv_m:"new_tvm($SA)" by(metisnew_tv_Wnew_tv_compatible_Wnew_tv_subst_scheme_list) withAppR obtainSatamaRawhereWe2:"We2($SA)m=Some(Sa,ta,ma)" andRSA:"$R($SA)=$Ra($Sa($SA))" andt2eq:"t2=$Rata" by(metise2t) defineFwhere"F\<equiv>(\<lambda>x.ifx=mathent' elseifx\<in>free_tvt-free_tvSathenRx elseRax)" have"ma\<notin>free_tvt" by(metisApp.prems(2)W_var_geDWe2e1new_tv_Wnew_tv_le new_tv_not_free_tv) have"$F(Sana)=Rna"if"na\<in>free_tvt"forna proof- have"na\<noteq>ma" using\<open>ma\<notin>free_tvt\<close>thatbyauto show?thesis proof(cases"na\<in>free_tvSa") caseTrue thenhave"Rna=$Ra(Sana)" by(metis(lifting)App.prems(2)RSAWe2e1eq_subst_scheme_list_eq_freefree_tv_W free_tv_le_new_tvnew_tv_Wsubst_comp_scheme_listthat) thenshow?thesis by(metisF_defTrueWe2new_tv_mcodDcod_app_substeq_free_eq_subst_te new_tv_Wnew_tv_not_free_tvweaken_not_elem_A_minus_B) next caseFalse thenshow?thesis usingnot_free_impl_id[OFFalse]\<open>na\<noteq>ma\<close>that by(simpadd:F_def) qed qed thenhave*:"$F($Sat)=$Rata->t'" usingeq_free_eq_subst_tesubst_comp_teusingRt2eqbyfastforce moreoverhave"Rana=Fna" if"na\<in>free_tvta"forna proof- have"na\<noteq>ma" usingWe2new_tv_Wnew_tv_mnew_tv_not_free_tvthatbyblast show?thesis proof(cases"na\<in>free_tvt-free_tvSa") caseTrue thenhave"$R($SA)=$(\<lambda>x.$Ra(Sax))($SA)" by(metisRSAsubst_comp_scheme_list) thenhave"Rana=Rna" by(metisthatApp.prems(2)DiffETrueType.app_subst_TVarWe2free_tv_We1 eq_subst_scheme_list_eq_freefree_tv_le_new_tvnew_tv_Wnot_free_impl_id) with\<open>na\<noteq>ma\<close>Trueshow?thesis by(simpadd:F_def) next caseFalse thenshow?thesis usingF_def\<open>na\<noteq>ma\<close>bypresburger qed qed ultimatelyhave"$F($Sat)=$F(ta->(TVarma))" by(metiseq_free_eq_subst_teF_defType.app_subst_FunType.app_subst_TVar) withmgu_SomeobtainSxRbwhereSx:"mgu($Sat)(ta->TVarma)=SomeSx" andRb:"F=$Rb\<circ>Sx" usingmgu_mgbyblast havet':"t'=$Rb(Sxma)" by(metisF_defRbcomp_def) have"$Ra($Sa($SA))=$(\<lambda>x.$Rb(Sxx))($Sa($SA))" proof(introeq_free_eq_subst_scheme_list) fixna::nat assumena:"na\<in>free_tv($Sa($SA))" thenhave"ma\<noteq>na" by(metisWe2new_tv_Wnew_tv_compatible_Wnew_tv_mnew_tv_not_free_tv new_tv_subst_scheme_list) show"Rana=$Rb(Sxna)" proof(cases"na\<in>free_tvt-free_tvSa") caseTrue thenhave"na\<in>codSa\<union>free_tv($SA)" usingfree_tv_app_subst_scheme_listnabyblast with\<open>ma\<noteq>na\<close>Rbshow?thesis by(smt(verit,ccfv_SIG)DiffD2F_defRSARbType.app_subst_TVarUn_iffcodD comp_applyeq_subst_scheme_list_eq_freenot_free_impl_idsubst_comp_scheme_list) next caseFalse thenshow?thesis by(metisF_defRb\<open>ma\<noteq>na\<close>comp_apply) qed qed thenhave"$S'A=$Rb($($Sx\<circ>$Sa\<circ>S)A)" by(metis(no_types,lifting)extR(1)RSAcomp_applyfun.map_comp subst_comp_scheme_list) withWe2Sxshow?case by(autosimpadd:e1t') next case(LETe1e2) thenobtaint1wheret1:"$S'A\<turnstile>e1::t1""gen($S'A)t1#$S'A\<turnstile>e2::t'" by(autosimp:has_type_simps) thenobtainStmRwheree1:"We1An=Some(S,t,m)""$S'A=$R($SA)" and"gen($R($SA))($Rt)#$R($SA)\<turnstile>e2::t'" usingLETbymetis thenhave"$R(gen($SA)t)#$R($SA)\<turnstile>e2::t'" usinggen_bound_typ_instancehas_type_le_envle_env_Consle_env_refl bypresburger moreover have"new_tvm(gen($SA)t)\<and>new_tvm($SA)" usingLET.premse1 by(metisnew_tv_Wnew_tv_compatible_Wnew_tv_compatible_gennew_tv_subst_scheme_list) ultimatelyshow?case usingLET.IH(2)[ofR"gen($SA)t#$SA"t'm]e1subst_comp_scheme_list byauto 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.0.13Bemerkung:
¤
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.