QuotMain.thy
changeset 423 2f0ad33f0241
parent 420 dcfe009c98aa
child 424 ab6ddf2ec00c
equal deleted inserted replaced
422:1f2c8be84be7 423:2f0ad33f0241
   715 14) simplifying (= ===> =) for simpler respectfullness
   715 14) simplifying (= ===> =) for simpler respectfullness
   716 
   716 
   717 *)
   717 *)
   718 
   718 
   719 ML {*
   719 ML {*
   720 fun instantiate_tac thm = Subgoal.FOCUS (fn {concl, ...} =>
   720 fun instantiate_tac thm = 
       
   721   Subgoal.FOCUS (fn {concl, ...} =>
   721   let
   722   let
   722     val pat = Drule.strip_imp_concl (cprop_of thm)
   723     val pat = Drule.strip_imp_concl (cprop_of thm)
   723     val insts = Thm.match (pat, concl)
   724     val insts = Thm.match (pat, concl)
   724   in
   725   in
   725     rtac (Drule.instantiate insts thm) 1
   726     rtac (Drule.instantiate insts thm) 1
   737      (* For functional identity quotients, (op = ---> op =) *)
   738      (* For functional identity quotients, (op = ---> op =) *)
   738      (* TODO: think about the other way around, if we need to shorten the relation *)
   739      (* TODO: think about the other way around, if we need to shorten the relation *)
   739      CHANGED o (simp_tac (HOL_ss addsimps @{thms id_simps}))])
   740      CHANGED o (simp_tac (HOL_ss addsimps @{thms id_simps}))])
   740 *}
   741 *}
   741 
   742 
   742 ML {*
   743 lemma FUN_REL_I:
   743 fun LAMBDA_RES_TAC ctxt i st =
   744   assumes a: "\<And>x y. R1 x y \<Longrightarrow> R2 (f x) (g y)"
   744   (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
   745   shows "(R1 ===> R2) f g"
   745     (_ $ (_ $ (Abs(_, _, _)) $ (Abs(_, _, _)))) =>
   746 using a by (simp add: FUN_REL.simps)
   746       (EqSubst.eqsubst_tac ctxt [0] @{thms FUN_REL.simps}) THEN'
   747 
   747       (rtac @{thm allI}) THEN' (rtac @{thm allI}) THEN' (rtac @{thm impI})
   748 ML {*
   748   | _ => fn _ => no_tac) i st
   749 val LAMBDA_RES_TAC =
       
   750   SUBGOAL (fn (goal, i) =>
       
   751     case goal of
       
   752        (_ $ (_ $ (Abs _) $ (Abs _))) => rtac @{thm FUN_REL_I} i
       
   753      | _ => no_tac)
   749 *}
   754 *}
   750 
   755 
   751 ML {*
   756 ML {*
   752 fun WEAK_LAMBDA_RES_TAC ctxt i st =
   757 fun WEAK_LAMBDA_RES_TAC ctxt i st =
   753   (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
   758   (case (term_of o #concl o fst) (Subgoal.focus ctxt i st) of
   813 
   818 
   814 ML {*
   819 ML {*
   815 fun r_mk_comb_tac ctxt rty quot_thms rel_refl trans2 rsp_thms =
   820 fun r_mk_comb_tac ctxt rty quot_thms rel_refl trans2 rsp_thms =
   816   (FIRST' [
   821   (FIRST' [
   817     resolve_tac trans2,
   822     resolve_tac trans2,
   818     LAMBDA_RES_TAC ctxt,
   823     LAMBDA_RES_TAC,
   819     rtac @{thm RES_FORALL_RSP},
   824     rtac @{thm RES_FORALL_RSP},
   820     ball_rsp_tac ctxt,
   825     ball_rsp_tac ctxt,
   821     rtac @{thm RES_EXISTS_RSP},
   826     rtac @{thm RES_EXISTS_RSP},
   822     bex_rsp_tac ctxt,
   827     bex_rsp_tac ctxt,
   823     resolve_tac rsp_thms,
   828     resolve_tac rsp_thms,
   832     atac,
   837     atac,
   833     SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
   838     SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps})),
   834     WEAK_LAMBDA_RES_TAC ctxt,
   839     WEAK_LAMBDA_RES_TAC ctxt,
   835     CHANGED o (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
   840     CHANGED o (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ}))
   836     ])
   841     ])
       
   842 
       
   843 fun all_r_mk_comb_tac ctxt rty quot_thms rel_refl trans2 rsp_thms =
       
   844   REPEAT_ALL_NEW (r_mk_comb_tac ctxt rty quot_thms rel_refl trans2 rsp_thms)
   837 *}
   845 *}
   838 
   846 
   839 (*
   847 (*
   840 To prove that the regularised theorem implies the abs/rep injected, 
   848 To prove that the regularised theorem implies the abs/rep injected, 
   841 we try:
   849 we try:
   842 
   850 
   843  1) theorems 'trans2' from the appropriate QUOT_TYPE
   851  1) theorems 'trans2' from the appropriate QUOT_TYPE
   844  2) remove lambdas from both sides (LAMBDA_RES_TAC)
   852  2) remove lambdas from both sides: LAMBDA_RES_TAC
   845  3) remove Ball/Bex from the right hand side
   853  3) remove Ball/Bex from the right hand side
   846  4) use user-supplied RSP theorems
   854  4) use user-supplied RSP theorems
   847  5) remove rep_abs from the right side
   855  5) remove rep_abs from the right side
   848  6) reflexivity of equality
   856  6) reflexivity of equality
   849  7) split applications of lifted type (apply_rsp)
   857  7) split applications of lifted type (apply_rsp)
   850  8) split applications of non-lifted type (cong_tac)
   858  8) split applications of non-lifted type (cong_tac)
   851  9) apply extentionality
   859  9) apply extentionality
   852 10) reflexivity of the relation
   860  A) reflexivity of the relation
   853 11) assumption
   861  B) assumption
   854     (Lambdas under respects may have left us some assumptions)
   862     (Lambdas under respects may have left us some assumptions)
   855 12) proving obvious higher order equalities by simplifying fun_rel
   863  C) proving obvious higher order equalities by simplifying fun_rel
   856     (not sure if it is still needed?)
   864     (not sure if it is still needed?)
   857 13) unfolding lambda on one side
   865  D) unfolding lambda on one side
   858 14) simplifying (= ===> =) for simpler respectfulness
   866  E) simplifying (= ===> =) for simpler respectfulness
   859 
   867 
   860 *)
   868 *)
   861 
   869 
   862 ML {*
   870 ML {*
   863 fun r_mk_comb_tac' ctxt rty quot_thms rel_refl trans2 rsp_thms =
   871 fun r_mk_comb_tac' ctxt rty quot_thms rel_refl trans2 rsp_thms =
   864   REPEAT_ALL_NEW (FIRST' [
   872   (FIRST' [
   865     (K (print_tac "start")) THEN' (K no_tac), 
   873     (K (print_tac "start")) THEN' (K no_tac), 
       
   874   
       
   875     (* "cong" rule of the of the relation    *)
       
   876     (* \<lbrakk>a \<approx> c; b \<approx> d\<rbrakk> \<Longrightarrow> (a \<approx> b) = (c \<approx> d) *)
   866     DT ctxt "1" (resolve_tac trans2),
   877     DT ctxt "1" (resolve_tac trans2),
   867     DT ctxt "2" (LAMBDA_RES_TAC ctxt),
   878 
       
   879     (* (R1 ===> R2) (\<lambda>x\<dots>) (\<lambda>\<dots>) \<Longrightarrow> \<lbrakk>R1 x y\<rbrakk> \<Longrightarrow> R2 (\<dots>x) (\<dots>y) *) 
       
   880     DT ctxt "2" (LAMBDA_RES_TAC),
       
   881 
       
   882     (* R (Ball\<dots>) (Ball\<dots>) \<Longrightarrow> R (\<dots>) (\<dots>) *)
   868     DT ctxt "3" (rtac @{thm RES_FORALL_RSP}),
   883     DT ctxt "3" (rtac @{thm RES_FORALL_RSP}),
       
   884 
   869     DT ctxt "4" (ball_rsp_tac ctxt),
   885     DT ctxt "4" (ball_rsp_tac ctxt),
   870     DT ctxt "5" (rtac @{thm RES_EXISTS_RSP}),
   886     DT ctxt "5" (rtac @{thm RES_EXISTS_RSP}),
   871     DT ctxt "6" (bex_rsp_tac ctxt),
   887     DT ctxt "6" (bex_rsp_tac ctxt),
       
   888 
       
   889     (* respectfulness of ops *)
   872     DT ctxt "7" (resolve_tac rsp_thms),
   890     DT ctxt "7" (resolve_tac rsp_thms),
       
   891 
       
   892     (* reflexivity of operators arising from Cong_tac *)
   873     DT ctxt "8" (rtac @{thm refl}),
   893     DT ctxt "8" (rtac @{thm refl}),
       
   894 
       
   895     (* R (\<dots>) (Rep (Abs \<dots>)) \<Longrightarrow> R (\<dots>) (\<dots>) *)
       
   896     (* observe ---> *) 
   874     DT ctxt "9" ((instantiate_tac @{thm REP_ABS_RSP(1)} ctxt 
   897     DT ctxt "9" ((instantiate_tac @{thm REP_ABS_RSP(1)} ctxt 
   875                   THEN' (RANGE [SOLVES' (quotient_tac quot_thms)]))),
   898                   THEN' (RANGE [SOLVES' (quotient_tac quot_thms)]))),
       
   899 
       
   900     (* R (t $ \<dots>) (t' $ \<dots>) \<Longrightarrow> APPLY_RSP   provided type of t needs lifting *)
   876     DT ctxt "A" ((APPLY_RSP_TAC rty ctxt THEN' 
   901     DT ctxt "A" ((APPLY_RSP_TAC rty ctxt THEN' 
   877                 (RANGE [SOLVES' (quotient_tac quot_thms), SOLVES' (quotient_tac quot_thms)]))),
   902                 (RANGE [SOLVES' (quotient_tac quot_thms), SOLVES' (quotient_tac quot_thms)]))),
       
   903 
       
   904     (* R (t $ \<dots>) (t' $ \<dots>) \<Longrightarrow> Cong provided R = (op =) and t does not need lifting *)
   878     DT ctxt "B" (Cong_Tac.cong_tac @{thm cong}),
   905     DT ctxt "B" (Cong_Tac.cong_tac @{thm cong}),
       
   906 
       
   907     (* = (\<lambda>x\<dots>) (\<lambda>x\<dots>) \<Longrightarrow> = (\<dots>) (\<dots>) *)
   879     DT ctxt "C" (rtac @{thm ext}),
   908     DT ctxt "C" (rtac @{thm ext}),
       
   909     
       
   910     (* reflexivity of the basic relations *)
   880     DT ctxt "D" (resolve_tac rel_refl),
   911     DT ctxt "D" (resolve_tac rel_refl),
       
   912 
       
   913     (* resolving with R x y assumptions *)
   881     DT ctxt "E" (atac),
   914     DT ctxt "E" (atac),
       
   915 
   882     DT ctxt "F" (SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))),
   916     DT ctxt "F" (SOLVES' (simp_tac (HOL_ss addsimps @{thms FUN_REL.simps}))),
   883     DT ctxt "G" (WEAK_LAMBDA_RES_TAC ctxt),
   917     DT ctxt "G" (WEAK_LAMBDA_RES_TAC ctxt),
   884     DT ctxt "H" (CHANGED o (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ})))
   918     DT ctxt "H" (CHANGED o (asm_full_simp_tac (HOL_ss addsimps @{thms FUN_REL_EQ})))
   885     ])
   919     ])
   886 *}
   920 
   887 
   921 fun all_r_mk_comb_tac' ctxt rty quot_thms rel_refl trans2 rsp_thms =
   888 
   922   REPEAT_ALL_NEW (r_mk_comb_tac' ctxt rty quot_thms rel_refl trans2 rsp_thms)
   889 
   923 *}
       
   924 
       
   925 ML {*
       
   926 fun get_inj_repabs_tac ctxt rel lhs rhs =
       
   927 let
       
   928   val _ = tracing "input"
       
   929   val _ = tracing ("rel: " ^ Syntax.string_of_term ctxt rel)
       
   930   val _ = tracing ("lhs: " ^ Syntax.string_of_term ctxt lhs)
       
   931   val _ = tracing ("rhs: " ^ Syntax.string_of_term ctxt rhs)
       
   932 in  
       
   933   case (rel, lhs, rhs) of
       
   934     (_, l, Const _ $ (Const _ $ r)) (* FIXME: not right_match *)
       
   935       => rtac @{thm REP_ABS_RSP(1)}
       
   936   | (_, Const (@{const_name "Ball"}, _) $ _, 
       
   937         Const (@{const_name "Ball"}, _) $ _)
       
   938       => rtac @{thm RES_FORALL_RSP}
       
   939   | _ => K no_tac
       
   940 end
       
   941 *}
       
   942 
       
   943 ML {* 
       
   944 fun inj_repabs_tac ctxt =
       
   945   SUBGOAL (fn (goal, i) =>
       
   946      (case (HOLogic.dest_Trueprop goal) of
       
   947         (rel $ lhs $ rhs) => get_inj_repabs_tac ctxt rel lhs rhs
       
   948       | _ => K no_tac) i)
       
   949 *}
   890 
   950 
   891 section {* Cleaning of the theorem *}
   951 section {* Cleaning of the theorem *}
   892 
   952 
   893 ML {*
   953 ML {*
   894 fun applic_prs lthy absrep (rty, qty) =
   954 fun applic_prs lthy absrep (rty, qty) =