QuotMain.thy
changeset 45 d98224cafb86
parent 44 f078dbf557b7
child 46 e801b929216b
equal deleted inserted replaced
44:f078dbf557b7 45:d98224cafb86
   149   val [x, c] = [("x", ty), ("c", ty --> @{typ bool})]
   149   val [x, c] = [("x", ty), ("c", ty --> @{typ bool})]
   150                |> Variable.variant_frees lthy [rel]
   150                |> Variable.variant_frees lthy [rel]
   151                |> map Free
   151                |> map Free
   152 in
   152 in
   153   lambda c
   153   lambda c
   154     (HOLogic.exists_const ty $ 
   154     (HOLogic.exists_const ty $
   155        lambda x (HOLogic.mk_eq (c, (rel $ x))))
   155        lambda x (HOLogic.mk_eq (c, (rel $ x))))
   156 end
   156 end
   157 
   157 
   158 
   158 
   159 (* makes the new type definitions and proves non-emptyness*)
   159 (* makes the new type definitions and proves non-emptyness*)
   160 fun typedef_make (qty_name, rel, ty) lthy =
   160 fun typedef_make (qty_name, rel, ty) lthy =
   161 let  
   161 let
   162   val typedef_tac =
   162   val typedef_tac =
   163      EVERY1 [rewrite_goal_tac @{thms mem_def},
   163      EVERY1 [rewrite_goal_tac @{thms mem_def},
   164              rtac @{thm exI}, 
   164              rtac @{thm exI},
   165              rtac @{thm exI}, 
   165              rtac @{thm exI},
   166              rtac @{thm refl}]
   166              rtac @{thm refl}]
   167 in
   167 in
   168   LocalTheory.theory_result
   168   LocalTheory.theory_result
   169     (Typedef.add_typedef false NONE
   169     (Typedef.add_typedef false NONE
   170        (qty_name, map fst (Term.add_tfreesT ty []), NoSyn)
   170        (qty_name, map fst (Term.add_tfreesT ty []), NoSyn)
   215   val typedef_quotient_thm_tac =
   215   val typedef_quotient_thm_tac =
   216     EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]),
   216     EVERY1 [K (rewrite_goals_tac [abs_def, rep_def]),
   217             rtac @{thm QUOT_TYPE.QUOTIENT},
   217             rtac @{thm QUOT_TYPE.QUOTIENT},
   218             rtac quot_type_thm]
   218             rtac quot_type_thm]
   219 in
   219 in
   220   Goal.prove lthy [] [] goal 
   220   Goal.prove lthy [] [] goal
   221     (K typedef_quotient_thm_tac)
   221     (K typedef_quotient_thm_tac)
   222 end
   222 end
   223 *}
   223 *}
   224 
   224 
   225 text {* two wrappers for define and note *}
   225 text {* two wrappers for define and note *}
   322 datatype trm =
   322 datatype trm =
   323   var  "nat"
   323   var  "nat"
   324 | app  "trm" "trm"
   324 | app  "trm" "trm"
   325 | lam  "nat" "trm"
   325 | lam  "nat" "trm"
   326 
   326 
   327 axiomatization 
   327 axiomatization
   328   RR :: "trm \<Rightarrow> trm \<Rightarrow> bool" 
   328   RR :: "trm \<Rightarrow> trm \<Rightarrow> bool"
   329 where
   329 where
   330   r_eq: "EQUIV RR"
   330   r_eq: "EQUIV RR"
   331 
   331 
   332 local_setup {*
   332 local_setup {*
   333   typedef_main (@{binding "qtrm"}, @{term "RR"}, @{typ trm}, @{thm r_eq}) #> snd
   333   typedef_main (@{binding "qtrm"}, @{term "RR"}, @{typ trm}, @{thm r_eq}) #> snd
   478 end
   478 end
   479 *}
   479 *}
   480 
   480 
   481 ML {*
   481 ML {*
   482 fun exchange_ty rty qty ty =
   482 fun exchange_ty rty qty ty =
   483   if ty = rty 
   483   if ty = rty
   484   then qty
   484   then qty
   485   else
   485   else
   486     (case ty of
   486     (case ty of
   487        Type (s, tys) => Type (s, map (exchange_ty rty qty) tys)
   487        Type (s, tys) => Type (s, map (exchange_ty rty qty) tys)
   488       | _ => ty
   488       | _ => ty
   672 lemma mem_cons:
   672 lemma mem_cons:
   673   fixes x :: "'a"
   673   fixes x :: "'a"
   674   fixes xs :: "'a list"
   674   fixes xs :: "'a list"
   675   assumes a : "x memb xs"
   675   assumes a : "x memb xs"
   676   shows "x # xs \<approx> xs"
   676   shows "x # xs \<approx> xs"
   677   using a 
   677   using a
   678   apply (induct xs)
   678   apply (induct xs)
   679   apply (auto intro: list_eq.intros)
   679   apply (auto intro: list_eq.intros)
   680   done
   680   done
   681 
   681 
   682 lemma card1_suc:
   682 lemma card1_suc:
   683   fixes xs :: "'a list"
   683   fixes xs :: "'a list"
   684   fixes n :: "nat"
   684   fixes n :: "nat"
   685   assumes c: "card1 xs = Suc n"
   685   assumes c: "card1 xs = Suc n"
   686   shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
   686   shows "\<exists>a ys. ~(a memb ys) \<and> xs \<approx> (a # ys)"
   687   using c 
   687   using c
   688 apply(induct xs)
   688 apply(induct xs)
   689 apply (metis Suc_neq_Zero card1_0)
   689 apply (metis Suc_neq_Zero card1_0)
   690 apply (metis QUOT_TYPE_I_fset.R_trans QuotMain.card1_cons list_eq_sym mem_cons)
   690 apply (metis QUOT_TYPE_I_fset.R_trans QuotMain.card1_cons list_eq_refl mem_cons)
   691 done
   691 done
   692 
   692 
   693 lemma cons_preserves:
   693 lemma cons_preserves:
   694   fixes z
   694   fixes z
   695   assumes a: "xs \<approx> ys"
   695   assumes a: "xs \<approx> ys"
   696   shows "(z # xs) \<approx> (z # ys)"
   696   shows "(z # xs) \<approx> (z # ys)"
   697   using a by (rule QuotMain.list_eq.intros(5))
   697   using a by (rule QuotMain.list_eq.intros(5))
   698 
   698 
   699 
   699 
   700 text {*
   700 text {*
   701   Unlam_def converts a definition given as 
   701   Unlam_def converts a definition given as
   702 
   702 
   703     c \<equiv> %x. %y. f x y
   703     c \<equiv> %x. %y. f x y
   704 
   704 
   705   to a theorem of the form 
   705   to a theorem of the form
   706    
   706 
   707     c x y \<equiv> f x y 
   707     c x y \<equiv> f x y
   708 
   708 
   709   This function is needed to rewrite the right-hand
   709   This function is needed to rewrite the right-hand
   710   side to the left-hand side.
   710   side to the left-hand side.
   711 *}
   711 *}
   712 
   712 
   815   apply (simp add: QUOT_TYPE_I_fset.thm10)
   815   apply (simp add: QUOT_TYPE_I_fset.thm10)
   816   done
   816   done
   817 
   817 
   818 ML {*
   818 ML {*
   819   fun mk_rep_abs x = @{term REP_fset} $ (@{term ABS_fset} $ x)
   819   fun mk_rep_abs x = @{term REP_fset} $ (@{term ABS_fset} $ x)
   820   val consts = [@{const_name "Nil"}, @{const_name "append"}, 
   820   val consts = [@{const_name "Nil"}, @{const_name "append"},
   821                 @{const_name "Cons"}, @{const_name "membship"}, 
   821                 @{const_name "Cons"}, @{const_name "membship"},
   822                 @{const_name "card1"}]
   822                 @{const_name "card1"}]
   823 *}
   823 *}
   824 
   824 
   825 ML {*
   825 ML {*
   826 fun build_goal ctxt thm constructors lifted_type mk_rep_abs =
   826 fun build_goal ctxt thm constructors lifted_type mk_rep_abs =
   863 ML {*
   863 ML {*
   864 fun build_goal' ctxt thm constructors lifted_type mk_rep_abs =
   864 fun build_goal' ctxt thm constructors lifted_type mk_rep_abs =
   865   let
   865   let
   866     fun is_const (Const (x, t)) = member (op =) constructors x
   866     fun is_const (Const (x, t)) = member (op =) constructors x
   867       | is_const _ = false
   867       | is_const _ = false
   868   
   868 
   869     fun maybe_mk_rep_abs t =
   869     fun maybe_mk_rep_abs t =
   870       let
   870       let
   871         val _ = writeln ("Maybe: " ^ Syntax.string_of_term ctxt t)
   871         val _ = writeln ("Maybe: " ^ Syntax.string_of_term ctxt t)
   872       in
   872       in
   873         if type_of t = lifted_type then mk_rep_abs t else t
   873         if type_of t = lifted_type then mk_rep_abs t else t
   890                 (list_comb (f, map maybe_mk_rep_abs (map (build_aux ctxt1) args)))
   890                 (list_comb (f, map maybe_mk_rep_abs (map (build_aux ctxt1) args)))
   891             else list_comb (build_aux ctxt1 f, map (build_aux ctxt1) args)
   891             else list_comb (build_aux ctxt1 f, map (build_aux ctxt1) args)
   892           end
   892           end
   893       | build_aux _ x =
   893       | build_aux _ x =
   894           if is_const x then maybe_mk_rep_abs x else x
   894           if is_const x then maybe_mk_rep_abs x else x
   895     
   895 
   896     val concl2 = term_of (#prop (crep_thm thm))
   896     val concl2 = term_of (#prop (crep_thm thm))
   897   in
   897   in
   898   Logic.mk_equals (build_aux ctxt concl2, concl2)
   898   Logic.mk_equals (build_aux ctxt concl2, concl2)
   899 end *}
   899 end *}
   900 
   900 
  1002       CHANGED o (ObjectLogic.full_atomize_tac)
  1002       CHANGED o (ObjectLogic.full_atomize_tac)
  1003     ])
  1003     ])
  1004 *}
  1004 *}
  1005 
  1005 
  1006 ML {*
  1006 ML {*
  1007 <<<<<<< variant A
       
  1008   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
  1007   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
  1009   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1008   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1010 >>>>>>> variant B
       
  1011   val m1_novars = snd(no_vars ((Context.Theory @{theory}),@{thm m1}))
       
  1012   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
       
  1013 ####### Ancestor
       
  1014   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m1}))
       
  1015   val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
       
  1016 ======= end
       
  1017   val cgoal = cterm_of @{theory} goal
  1009   val cgoal = cterm_of @{theory} goal
  1018   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1010   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1019 *}
  1011 *}
  1020 
  1012 
  1021 (*notation ( output) "prop" ("#_" [1000] 1000) *)
  1013 (*notation ( output) "prop" ("#_" [1000] 1000) *)
  1041 qed
  1033 qed
  1042 
  1034 
  1043 
  1035 
  1044 prove {* (Thm.term_of cgoal2) *}
  1036 prove {* (Thm.term_of cgoal2) *}
  1045   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1037   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1046   apply (atomize (full))
       
  1047   
       
  1048   apply (rule trueprop_cong)
       
  1049   apply (tactic {* foo_tac' @{context} 1 *})
  1038   apply (tactic {* foo_tac' @{context} 1 *})
  1050   thm eq_reflection
       
  1051   done
  1039   done
  1052 
  1040 
  1053 thm length_append (* Not true but worth checking that the goal is correct *)
  1041 thm length_append (* Not true but worth checking that the goal is correct *)
  1054 ML {*
  1042 ML {*
  1055   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append}))
  1043   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm length_append}))
  1056   val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
  1044   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1057   val cgoal = cterm_of @{theory} goal
  1045   val cgoal = cterm_of @{theory} goal
  1058   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1046   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1059 *}
  1047 *}
  1060 prove {* Thm.term_of cgoal2 *}
  1048 prove {* Thm.term_of cgoal2 *}
  1061   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1049   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1063   sorry
  1051   sorry
  1064 
  1052 
  1065 thm m2
  1053 thm m2
  1066 ML {*
  1054 ML {*
  1067   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
  1055   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm m2}))
  1068   val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
  1056   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1069   val cgoal = cterm_of @{theory} goal
  1057   val cgoal = cterm_of @{theory} goal
  1070   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1058   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1071 *}
  1059 *}
  1072 prove {* Thm.term_of cgoal2 *}
  1060 prove {* Thm.term_of cgoal2 *}
  1073   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1061   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1075   done
  1063   done
  1076 
  1064 
  1077 thm list_eq.intros(4)
  1065 thm list_eq.intros(4)
  1078 ML {*
  1066 ML {*
  1079   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)}))
  1067   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(4)}))
  1080   val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
  1068   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1081   val cgoal = cterm_of @{theory} goal
  1069   val cgoal = cterm_of @{theory} goal
  1082   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1070   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite false fset_defs_sym cgoal)
  1083   val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2)
  1071   val cgoal3 = Thm.rhs_of (MetaSimplifier.rewrite true @{thms QUOT_TYPE_I_fset.thm10} cgoal2)
  1084 *}
  1072 *}
  1085 
  1073 
  1103 ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *}
  1091 ML {* val zzz'' = MetaSimplifier.rewrite_rule @{thms QUOT_TYPE_I_fset.REPS_same} @{thm zzz'} *}
  1104 
  1092 
  1105 thm list_eq.intros(5)
  1093 thm list_eq.intros(5)
  1106 ML {*
  1094 ML {*
  1107   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)}))
  1095   val m1_novars = snd(no_vars ((Context.Theory @{theory}), @{thm list_eq.intros(5)}))
  1108   val goal = build_goal m1_novars consts @{typ "'a list"} mk_rep_abs
  1096   val goal = build_goal @{context} m1_novars consts @{typ "'a list"} mk_rep_abs
  1109 *}
  1097 *}
  1110 ML {*
  1098 ML {*
  1111   val cgoal =
  1099   val cgoal =
  1112     Toplevel.program (fn () =>
  1100     Toplevel.program (fn () =>
  1113       cterm_of @{theory} goal
  1101       cterm_of @{theory} goal
  1146 
  1134 
  1147 ML {*
  1135 ML {*
  1148   fun lift_theorem_fset_aux thm lthy =
  1136   fun lift_theorem_fset_aux thm lthy =
  1149     let
  1137     let
  1150       val ((_, [novars]), lthy2) = Variable.import true [thm] lthy;
  1138       val ((_, [novars]), lthy2) = Variable.import true [thm] lthy;
  1151       val goal = build_goal novars consts @{typ "'a list"} mk_rep_abs;
  1139       val goal = build_goal @{context} novars consts @{typ "'a list"} mk_rep_abs;
  1152       val cgoal = cterm_of @{theory} goal;
  1140       val cgoal = cterm_of @{theory} goal;
  1153       val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal);
  1141       val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal);
  1154       val tac = (LocalDefs.unfold_tac @{context} fset_defs) THEN (foo_tac' @{context}) 1;
  1142       val tac = (LocalDefs.unfold_tac @{context} fset_defs) THEN (foo_tac' @{context}) 1;
  1155       val cthm = Goal.prove_internal [] cgoal2 (fn _ => tac);
  1143       val cthm = Goal.prove_internal [] cgoal2 (fn _ => tac);
  1156       val nthm = MetaSimplifier.rewrite_rule [symmetric cthm] (snd (no_vars (Context.Theory @{theory}, thm)))
  1144       val nthm = MetaSimplifier.rewrite_rule [symmetric cthm] (snd (no_vars (Context.Theory @{theory}, thm)))
  1235   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
  1223   val cgoal2 = Thm.rhs_of (MetaSimplifier.rewrite true fset_defs_sym cgoal)
  1236 *}
  1224 *}
  1237 ML {* @{term "\<exists>x. P x"} *}
  1225 ML {* @{term "\<exists>x. P x"} *}
  1238 ML {*  Thm.bicompose *}
  1226 ML {*  Thm.bicompose *}
  1239 prove {* (Thm.term_of cgoal2) *}
  1227 prove {* (Thm.term_of cgoal2) *}
  1240   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} ) 
  1228   apply (tactic {* LocalDefs.unfold_tac @{context} fset_defs *} )
  1241   apply (tactic {* foo_tac' @{context} 1 *})
  1229   apply (tactic {* foo_tac' @{context} 1 *})
  1242 
  1230 
  1243 
  1231 
  1244 (*
  1232 (*
  1245 datatype obj1 =
  1233 datatype obj1 =