1(*<*)2theoryAOT_RestrictedVariables3importsAOT_PLM4keywords"AOT_register_rigid_restricted_type":: thy_goal
5and"AOT_register_restricted_type":: thy_goal
6begin7(*>*)89section‹Restricted Variables›1011localeAOT_restriction_condition=12fixesψ::‹'a::AOT_Term_id_2⇒𝗈›13assumes"res-var:2"[AOT]:‹[v⊨∃αψ{α}]›14assumes"res-var:3"[AOT]:‹[v⊨ψ{τ}→τ↓]›1516ML‹17funregister_restricted_type(name:string,restriction:string)thy=18let19valctxt=thy20valctxt=setupStrictWorldctxt21valtrm=Syntax.check_termctxt(AOT_read_term@{nonterminalφ'}ctxtrestriction)22valfree=case(Term.add_freestrm[])of[f]=>f|23_=>raiseTerm.TERM("Expected single free variable.",[trm])24valtrm=Term.absfreefreetrm25vallocaleTerm=Const(\<^const_name>‹AOT_restriction_condition›,dummyT)$trm26vallocaleTerm=Syntax.check_termctxtlocaleTerm27funafter_qedthmsthy=let28valst=Interpretation.global_interpretation29(([(@{localeAOT_restriction_condition},((name,true),30(Expression.Named[("ψ",trm)],[])))],[]))[]thy31valst=Proof.refine_insert(flatthms)st32valthy=Proof.global_immediate_proofst3334valthy=Local_Theory.background_theory35(AOT_Constraints.map(Symtab.update36(name,(term_of(sndfree),term_of(sndfree)))))thy37valthy=Local_Theory.background_theory38(AOT_Restriction.map(Symtab.update39(name,(trm,Const(\<^const_name>‹AOT_term_of_var›,dummyT)))))thy4041inthyend42in43Proof.theoremNONEafter_qed[[(HOLogic.mk_TrueproplocaleTerm,[])]]ctxt44end4546val_=47Outer_Syntax.command48\<^command_keyword>‹AOT_register_restricted_type›49"Register a restricted type."50(((Parse.short_ident--|Parse.$$$":")--Parse.term)>>51(Toplevel.local_theory_to_proofNONENONEoregister_restricted_type));52›5354localeAOT_rigid_restriction_condition=AOT_restriction_condition+55assumesrigid[AOT]:‹[v⊨∀α(ψ{α}→□ψ{α})]›56begin57lemmarigid_condition[AOT]:‹[v⊨□(ψ{α}→□ψ{α})]›58usingrigid[THEN"∀E"(2)]RNbysimp59lemmatype_set_nonempty[AOT_no_atp,no_atp]:‹∃x.x∈{α.[w⇩0⊨ψ{α}]}›60by(metis"instantiation"mem_Collect_eq"res-var:2")61end6263localeAOT_restricted_type=AOT_rigid_restriction_condition+64fixesRepandAbs65assumesAOT_restricted_type_definition[AOT_no_atp]:66‹type_definitionRepAbs{α.[w⇩0⊨ψ{α}]}›67begin6869AOT_theoremrestricted_var_condition:‹ψ{«AOT_term_of_var(Repα)»}›70proof-71interprettype_definitionRepAbs"{α.[w⇩0⊨ψ{α}]}"72usingAOT_restricted_type_definition.73AOT_actually {74AOT_have‹«AOT_term_of_var(Repα)»↓›and‹ψ{«AOT_term_of_var(Repα)»}›75usingAOT_sem_impRep"res-var:3"byauto76}77moreoverAOT_actually {78AOT_have‹ψ{α}→□ψ{α}›forα79usingAOT_sem_boxrigid_conditionbypresburger80AOT_hence‹ψ{τ}→□ψ{τ}›if‹τ↓›forτ81by(metisAOT_model.AOT_term_of_var_casesAOT_sem_denotesthat)82}83ultimatelyAOT_show‹ψ{«AOT_term_of_var(Repα)»}›84usingAOT_sem_boxAOT_sem_impbyblast85qed86lemmas"ψ"=restricted_var_condition8788AOT_theoremGEN:assumes‹forarbitraryα:φ{«AOT_term_of_var(Repα)»}›89shows‹∀α(ψ{α}→φ{α})›90proof(ruleGEN;rule"→I")91interprettype_definitionRepAbs"{α.[w⇩0⊨ψ{α}]}"92usingAOT_restricted_type_definition.93fixα94AOT_assume‹ψ{α}›95AOT_hence‹❙𝒜ψ{α}›96by(metisAOT_model_axiom_defAOT_sem_boxAOT_sem_impact_closurerigid_condition)97hence0:‹[w⇩0⊨ψ{α}]›by(metisAOT_sem_act)98{99fixτ100assumeα_def:‹α=Repτ›101AOT_have‹φ{α}›102unfoldingα_def103usingassmsbyblast104}105AOT_thus‹φ{α}›106usingRep_cases[simplified,OF0]107byblast108qed109lemmas"∀I"=GEN110111end112113114lemmaAOT_restricted_type_intro[AOT_no_atp,no_atp]:115assumes‹type_definitionRepAbs{α.[w⇩0⊨ψ{α}]}›116and‹AOT_rigid_restriction_conditionψ›117shows‹AOT_restricted_typeψRepAbs›118by(autointro!:assmsAOT_restricted_type_axioms.introAOT_restricted_type.intro)119120121122ML‹123funregister_rigid_restricted_type(name:string,restriction:string)thy=124let125valctxt=thy126valctxt=setupStrictWorldctxt127valtrm=Syntax.check_termctxt(AOT_read_term@{nonterminalφ'}ctxtrestriction)128valfree=case(Term.add_freestrm[])of[f]=>f129|_=>raiseTerm.TERM("Expected single free variable.",[trm])130valtrm=Term.absfreefreetrm131vallocaleTerm=HOLogic.mk_Trueprop132(Const(\<^const_name>‹AOT_rigid_restriction_condition›,dummyT)$trm)133vallocaleTerm=Syntax.check_propctxtlocaleTerm134valint_bnd=Binding.concealed(Binding.qualifytrue"internal"(Binding.namename))135valbnds={Rep_name=Binding.qualifytruename(Binding.name"Rep"),136Abs_name=Binding.qualifytrue"Abs"int_bnd,137type_definition_name=Binding.qualifytrue"type_definition"int_bnd}138139funafter_qedwittsthy=let140valthms=(map(Element.conclude_witnessctxt)(flatwitts))141142valtypeset=HOLogic.mk_Collect("α",dummyT,143\<^const>‹AOT_model_valid_in›$\<^const>‹w⇩0›$144(trm$(Const(\<^const_name>‹AOT_term_of_var›,dummyT)$Bound0)))145valtypeset=Syntax.check_termthytypeset146valnonempty_thm=Drule.OF147(@{thmAOT_rigid_restriction_condition.type_set_nonempty},thms)148149val((_,st),thy)=Typedef.add_typedef{overloaded=true}150(Binding.namename,[],Mixfix.NoSyn)typeset(SOMEbnds)151(fnctxt=>(Tactic.resolve_tacctxt([nonempty_thm])1))thy152val({rep_type=_,abs_type=_,Rep_name=Rep_name,Abs_name=Abs_name,153axiom_name=_},154{inhabited=_,type_definition=type_definition,Rep=_,155Rep_inverse=_,Abs_inverse=_,Rep_inject=_,Abs_inject=_,156Rep_cases=_,Abs_cases=_,Rep_induct=_,Abs_induct=_})=st157158vallocale_thm=Drule.OF(@{thmAOT_restricted_type_intro},type_definition::thms)159160valst=Interpretation.global_interpretation(([(@{localeAOT_restricted_type},161((name,true),(Expression.Named[162("ψ",trm),163("Rep",Const(Rep_name,dummyT)),164("Abs",Const(Abs_name,dummyT))],[])))165],[]))[]thy166167valst=Proof.refine_insert[locale_thm]st168valthy=Proof.global_immediate_proofst169170valthy=Local_Theory.background_theory(AOT_Constraints.map(171Symtab.update(name,(term_of(sndfree),term_of(sndfree)))))thy172valthy=Local_Theory.background_theory(AOT_Restriction.map(173Symtab.update(name,(trm,Const(Rep_name,dummyT)))))thy174175inthyend176in177Element.witness_proofafter_qed[[localeTerm]]thy178end179180val_=181Outer_Syntax.command182\<^command_keyword>‹AOT_register_rigid_restricted_type›183"Register a restricted type."184(((Parse.short_ident--|Parse.$$$":")--Parse.term)>>185(Toplevel.local_theory_to_proofNONENONEoregister_rigid_restricted_type));186›187188(* Generalized mechanism for "AOT_restricted_type.∀I" followed by ∀E *)189ML‹190funget_instantiated_allIctxtvarnamethm=let191valtrm=Thm.concl_ofthm192valtrm=casetrmof(@{constTrueprop}$(@{constAOT_model_valid_in}$_$x))=>x193|_=>raiseTerm.TERM("Expected simple theorem.",[trm])194funextractVars(Const(\<^const_name>‹AOT_term_of_var›,t)$(Constrep$Varv))=195(iffst(fstv)=fstvarname196then[Const(\<^const_name>‹AOT_term_of_var›,t)$(Constrep$Varv)]197else[])(* TODO: care about the index *)198|extractVars(t1$t2)=extractVarst1@extractVarst2199|extractVars(Abs(_,_,t))=extractVarst200|extractVars_=[]201valvars=extractVarstrm202valvartrm=hdvars203valvars=foldTerm.add_varsvars[]204valvar=hdvars205valtrmty=(casevartrmof(Const(_,Type("fun",[_,ty]))$_)=>ty206|_=>raiseMatch)207valvarty=sndvar208valtyname=fst(Term.dest_Typevarty)209valb=tyname^".∀I"(* TODO: better way to find the theorem *)210valthms=fst(Context.map_proof_result(fnctxt=>(Attrib.eval_thmsctxt211[(Facts.Named((b,Position.none),NONE),[])],ctxt))ctxt)212valallthm=(casethmsof(thm::_)=>thm213|_=>raiseFail"Unknown restricted type.")214valtrm=Abs(Term.string_of_vname(fstvar),trmty,Term.abstract_over(vartrm,trm))215valtrm=Thm.cterm_of(Context.proof_ofctxt)trm216valphi=hd(Term.add_vars(Thm.prop_ofallthm)[])217valallthm=Drule.instantiate_normalize(TVars.empty,Vars.make[(phi,trm)])allthm218in219allthm220end221›222223(* TODO: unconstraining multiple variables does not work yet *)224attribute_setup"unconstrain"=225‹Scan.lift(Scan.repeat1Args.var)>>(fnargs=>Thm.rule_attribute[]226(fnctxt=>fnthm=>227let228valthm=fold(fnarg=>fnthm=>thmRSget_instantiated_allIctxtargthm)229argsthm230valthm=fold(fn_=>fnthm=>thmRS@{thm "∀E"(2)})argsthm231in232thm233end))›234"Generalize a statement about restricted variables to a statement about
235 unrestricted variables with explicit restriction condition."236237238239contextAOT_restricted_type240begin241242AOT_theorem"rule-ui":243assumes‹∀α(ψ{α}→φ{α})›244shows‹φ{«AOT_term_of_var(Repα)»}›245proof-246AOT_have‹φ{α}›if‹ψ{α}›forαusingassms[THEN"∀E"(2),THEN"→E"]thatbyblast247moreoverAOT_have‹ψ{«AOT_term_of_var(Repα)»}›248by(autosimp:ψ)249ultimatelyshow?thesisbyblast250qed251lemmas"∀E"="rule-ui"252253AOT_theorem"instantiation":254assumes‹forarbitraryβ:φ{«AOT_term_of_var(Repβ)»}❙⊢χ›and‹∃α(ψ{α}&φ{α})›255shows‹χ›256proof-257AOT_have‹φ{«AOT_term_of_var(Repα)»}→χ›forα258usingassms(1)259by(simpadd:"deduction-theorem")260AOT_hence0:‹∀α(ψ{α}→(φ{α}→χ))›261usingGENbysimp262moreoverAOT_obtainαwhere‹ψ{α}&φ{α}›usingassms(2)"∃E"[rotated]byblast263ultimatelyAOT_show‹χ›using"AOT_PLM.∀E"(2)[THEN"→E",THEN"→E"]"&E"byfast264qed265lemmas"∃E"="instantiation"266267AOT_theoremexistential:assumes‹φ{«AOT_term_of_var(Repβ)»}›268shows‹∃α(ψ{α}&φ{α})›269by(mesonAOT_restricted_type.ψAOT_restricted_type_axiomsassms270"&I""existential:2[const_var]")271lemmas"∃I"=existential272end273274275contextAOT_rigid_restriction_condition276begin277278AOT_theorem"res-var-bound-reas[1]":279‹∀α(ψ{α}→∀βφ{α,β})≡∀β∀α(ψ{α}→φ{α,β})›280proof(safeintro!:"≡I""→I"GEN)281fixβα282AOT_assume‹∀α(ψ{α}→∀βφ{α,β})›283AOT_hence‹ψ{α}→∀βφ{α,β}›using"∀E"(2)byblast284moreoverAOT_assume‹ψ{α}›285ultimatelyAOT_have‹∀βφ{α,β}›using"→E"byblast286AOT_thus‹φ{α,β}›using"∀E"(2)byblast287next288fixαβ289AOT_assume‹∀β∀α(ψ{α}→φ{α,β})›290AOT_hence‹∀α(ψ{α}→φ{α,β})›using"∀E"(2)byblast291AOT_hence‹ψ{α}→φ{α,β}›using"∀E"(2)byblast292moreoverAOT_assume‹ψ{α}›293ultimatelyAOT_show‹φ{α,β}›using"→E"byblast294qed295296AOT_theorem"res-var-bound-reas[BF]":297‹∀α(ψ{α}→□φ{α})→□∀α(ψ{α}→φ{α})›298proof(safeintro!:"→I")299AOT_assume‹∀α(ψ{α}→□φ{α})›300AOT_hence‹ψ{α}→□φ{α}›forα301using"∀E"(2)byblast302AOT_hence‹□(ψ{α}→φ{α})›forα303by(metis"sc-eq-box-box:6"rigid_condition"vdash-properties:6")304AOT_hence‹∀α□(ψ{α}→φ{α})›305by(ruleGEN)306AOT_thus‹□∀α(ψ{α}→φ{α})›307by(metis"BF""vdash-properties:6")308qed309310AOT_theorem"res-var-bound-reas[CBF]":311‹□∀α(ψ{α}→φ{α})→∀α(ψ{α}→□φ{α})›312proof(safeintro!:"→I"GEN)313fixα314AOT_assume‹□∀α(ψ{α}→φ{α})›315AOT_hence‹∀α□(ψ{α}→φ{α})›316by(metis"CBF""vdash-properties:6")317AOT_hence1:‹□(ψ{α}→φ{α})›318using"∀E"(2)byblast319AOT_assume‹ψ{α}›320AOT_hence‹□ψ{α}›321by(metis"B◇""T◇"rigid_condition"vdash-properties:6")322AOT_thus‹□φ{α}›323using1"qml:1"[axiom_inst,THEN"→E",THEN"→E"]byblast324qed325326AOT_theorem"res-var-bound-reas[2]":327‹∀α(ψ{α}→❙𝒜φ{α})→❙𝒜∀α(ψ{α}→φ{α})›328proof(safeintro!:"→I")329AOT_assume‹∀α(ψ{α}→❙𝒜φ{α})›330AOT_hence‹ψ{α}→❙𝒜φ{α}›forα331using"∀E"(2)byblast332AOT_hence‹❙𝒜(ψ{α}→φ{α})›forα333by(metis"sc-eq-box-box:7"rigid_condition"vdash-properties:6")334AOT_hence‹∀α❙𝒜(ψ{α}→φ{α})›335by(ruleGEN)336AOT_thus‹❙𝒜∀α(ψ{α}→φ{α})›337by(metis"≡E"(2)"logic-actual-nec:3"[axiom_inst])338qed339340341AOT_theorem"res-var-bound-reas[3]":342‹❙𝒜∀α(ψ{α}→φ{α})→∀α(ψ{α}→❙𝒜φ{α})›343proof(safeintro!:"→I"GEN)344fixα345AOT_assume‹❙𝒜∀α(ψ{α}→φ{α})›346AOT_hence‹∀α❙𝒜(ψ{α}→φ{α})›347by(metis"≡E"(1)"logic-actual-nec:3"[axiom_inst])348AOT_hence1:‹❙𝒜(ψ{α}→φ{α})›by(metis"rule-ui:3")349AOT_assume‹ψ{α}›350AOT_hence‹❙𝒜ψ{α}›351by(metis"nec-imp-act""qml:2"[axiom_inst]rigid_condition"→E")352AOT_thus‹❙𝒜φ{α}›353using1by(metis"act-cond""→E")354qed355356AOT_theorem"res-var-bound-reas[Buridan]":357‹∃α(ψ{α}&□φ{α})→□∃α(ψ{α}&φ{α})›358proof(rule"→I")359AOT_assume‹∃α(ψ{α}&□φ{α})›360thenAOT_obtainαwhere‹ψ{α}&□φ{α}›361using"∃E"[rotated]byblast362AOT_hence‹□(ψ{α}&φ{α})›363by(metis"KBasic:11""KBasic:3""T◇""&I""&E"(1)"&E"(2)364"≡E"(2)"reductio-aa:1"rigid_condition"vdash-properties:6")365AOT_hence‹∃α□(ψ{α}&φ{α})›366by(rule"∃I")367AOT_thus‹□∃α(ψ{α}&φ{α})›368by(ruleBuridan[THEN"→E"])369qed370371AOT_theorem"res-var-bound-reas[BF◇]":372‹◇∃α(ψ{α}&φ{α})→∃α(ψ{α}&◇φ{α})›373proof(rule"→I")374AOT_assume‹◇∃α(ψ{α}&φ{α})›375AOT_hence‹∃α◇(ψ{α}&φ{α})›376using"BF◇"[THEN"→E"]byblast377thenAOT_obtainαwhere‹◇(ψ{α}&φ{α})›378using"∃E"[rotated]byblast379AOT_hence‹◇ψ{α}›and‹◇φ{α}›380using"KBasic2:3""&E""→E"byblast+381moreoverAOT_have‹ψ{α}›382usingcalculationrigid_conditionby(metis"B◇""K◇""→E")383ultimatelyAOT_have‹ψ{α}&◇φ{α}›384using"&I"byblast385AOT_thus‹∃α(ψ{α}&◇φ{α})›386by(rule"∃I")387qed388389AOT_theorem"res-var-bound-reas[CBF◇]":390‹∃α(ψ{α}&◇φ{α})→◇∃α(ψ{α}&φ{α})›391proof(rule"→I")392AOT_assume‹∃α(ψ{α}&◇φ{α})›393thenAOT_obtainαwhere‹ψ{α}&◇φ{α}›394using"∃E"[rotated]byblast395AOT_hence‹□ψ{α}›and‹◇φ{α}›396usingrigid_condition[THEN"qml:2"[axiom_inst,THEN"→E"],THEN"→E"]"&E"byblast+397AOT_hence‹◇(ψ{α}&φ{α})›398by(metis"KBasic:16""con-dis-taut:5""→E")399AOT_hence‹∃α◇(ψ{α}&φ{α})›400by(rule"∃I")401AOT_thus‹◇∃α(ψ{α}&φ{α})›402using"CBF◇"[THEN"→E"]byfast403qed404405AOT_theorem"res-var-bound-reas[A-Exists:1]":406‹❙𝒜∃!α(ψ{α}&φ{α})≡∃!α(ψ{α}&❙𝒜φ{α})›407proof(safeintro!:"≡I""→I")408AOT_assume‹❙𝒜∃!α(ψ{α}&φ{α})›409AOT_hence‹∃!α❙𝒜(ψ{α}&φ{α})›410using"A-Exists:1"[THEN"≡E"(1)]byblast411AOT_hence‹∃!α(❙𝒜ψ{α}&❙𝒜φ{α})›412apply(AOT_subst‹❙𝒜ψ{α}&❙𝒜φ{α}›‹❙𝒜(ψ{α}&φ{α})›for:α)413apply(meson"Act-Basic:2""intro-elim:3:f""oth-class-taut:3:a")414bysimp415AOT_thus‹∃!α(ψ{α}&❙𝒜φ{α})›416apply(AOT_subst‹ψ{α}›‹❙𝒜ψ{α}›for:α)417using"Commutativity of ≡""intro-elim:3:b""sc-eq-fur:2"418"→E"rigid_conditionbyblast419next420AOT_assume‹∃!α(ψ{α}&❙𝒜φ{α})›421AOT_hence‹∃!α(❙𝒜ψ{α}&❙𝒜φ{α})›422apply(AOT_subst‹❙𝒜ψ{α}›‹ψ{α}›for:α)423apply(meson"sc-eq-fur:2""→E"rigid_condition)424bysimp425AOT_hence‹∃!α❙𝒜(ψ{α}&φ{α})›426apply(AOT_subst‹❙𝒜(ψ{α}&φ{α})›‹❙𝒜ψ{α}&❙𝒜φ{α}›for:α)427using"Act-Basic:2"applypresburger428bysimp429AOT_thus‹❙𝒜∃!α(ψ{α}&φ{α})›430by(metis"A-Exists:1""intro-elim:3:b")431qed432433end434435(*<*)436end437(*>*)