src/HOL/Tools/record.ML
changeset 36610 bafd82950e24
parent 36173 99212848c933
child 36945 9bec62c10714
equal deleted inserted replaced
36609:6ed6112f0a95 36610:bafd82950e24
  1036 
  1036 
  1037 fun future_forward_prf_standard thy prf prop () =
  1037 fun future_forward_prf_standard thy prf prop () =
  1038   let val thm =
  1038   let val thm =
  1039     if ! quick_and_dirty then Skip_Proof.make_thm thy prop
  1039     if ! quick_and_dirty then Skip_Proof.make_thm thy prop
  1040     else if Goal.future_enabled () then
  1040     else if Goal.future_enabled () then
  1041       Goal.future_result (ProofContext.init thy) (Future.fork_pri ~1 prf) prop
  1041       Goal.future_result (ProofContext.init_global thy) (Future.fork_pri ~1 prf) prop
  1042     else prf ()
  1042     else prf ()
  1043   in Drule.export_without_context thm end;
  1043   in Drule.export_without_context thm end;
  1044 
  1044 
  1045 fun prove_common immediate stndrd thy asms prop tac =
  1045 fun prove_common immediate stndrd thy asms prop tac =
  1046   let
  1046   let
  1047     val prv =
  1047     val prv =
  1048       if ! quick_and_dirty then Skip_Proof.prove
  1048       if ! quick_and_dirty then Skip_Proof.prove
  1049       else if immediate orelse not (Goal.future_enabled ()) then Goal.prove
  1049       else if immediate orelse not (Goal.future_enabled ()) then Goal.prove
  1050       else Goal.prove_future;
  1050       else Goal.prove_future;
  1051     val prf = prv (ProofContext.init thy) [] asms prop tac;
  1051     val prf = prv (ProofContext.init_global thy) [] asms prop tac;
  1052   in if stndrd then Drule.export_without_context prf else prf end;
  1052   in if stndrd then Drule.export_without_context prf else prf end;
  1053 
  1053 
  1054 val prove_future_global = prove_common false;
  1054 val prove_future_global = prove_common false;
  1055 val prove_global = prove_common true;
  1055 val prove_global = prove_common true;
  1056 
  1056 
  1088           if is_sel_upd_pair thy acc upd
  1088           if is_sel_upd_pair thy acc upd
  1089           then mk_comp (Free ("f", T)) acc
  1089           then mk_comp (Free ("f", T)) acc
  1090           else mk_comp_id acc;
  1090           else mk_comp_id acc;
  1091         val prop = lhs === rhs;
  1091         val prop = lhs === rhs;
  1092         val othm =
  1092         val othm =
  1093           Goal.prove (ProofContext.init thy) [] [] prop
  1093           Goal.prove (ProofContext.init_global thy) [] [] prop
  1094             (fn _ =>
  1094             (fn _ =>
  1095               simp_tac defset 1 THEN
  1095               simp_tac defset 1 THEN
  1096               REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1096               REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1097               TRY (simp_tac (HOL_ss addsimps id_o_apps) 1));
  1097               TRY (simp_tac (HOL_ss addsimps id_o_apps) 1));
  1098         val dest =
  1098         val dest =
  1112       if comp
  1112       if comp
  1113       then u $ mk_comp f f'
  1113       then u $ mk_comp f f'
  1114       else mk_comp (u' $ f') (u $ f);
  1114       else mk_comp (u' $ f') (u $ f);
  1115     val prop = lhs === rhs;
  1115     val prop = lhs === rhs;
  1116     val othm =
  1116     val othm =
  1117       Goal.prove (ProofContext.init thy) [] [] prop
  1117       Goal.prove (ProofContext.init_global thy) [] [] prop
  1118         (fn _ =>
  1118         (fn _ =>
  1119           simp_tac defset 1 THEN
  1119           simp_tac defset 1 THEN
  1120           REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1120           REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1121           TRY (simp_tac (HOL_ss addsimps [id_apply]) 1));
  1121           TRY (simp_tac (HOL_ss addsimps [id_apply]) 1));
  1122     val dest = if comp then o_eq_dest_lhs else o_eq_dest;
  1122     val dest = if comp then o_eq_dest_lhs else o_eq_dest;
  1153     val prop' = Envir.beta_eta_contract prop;
  1153     val prop' = Envir.beta_eta_contract prop;
  1154     val (lhs, _) = Logic.dest_equals (Logic.strip_assums_concl prop');
  1154     val (lhs, _) = Logic.dest_equals (Logic.strip_assums_concl prop');
  1155     val (_, args) = strip_comb lhs;
  1155     val (_, args) = strip_comb lhs;
  1156     val simps = (if length args = 1 then get_accupd_simps else get_updupd_simps) thy lhs defset;
  1156     val simps = (if length args = 1 then get_accupd_simps else get_updupd_simps) thy lhs defset;
  1157   in
  1157   in
  1158     Goal.prove (ProofContext.init thy) [] [] prop'
  1158     Goal.prove (ProofContext.init_global thy) [] [] prop'
  1159       (fn _ =>
  1159       (fn _ =>
  1160         simp_tac (HOL_basic_ss addsimps (simps @ [K_record_comp])) 1 THEN
  1160         simp_tac (HOL_basic_ss addsimps (simps @ [K_record_comp])) 1 THEN
  1161         TRY (simp_tac (HOL_basic_ss addsimps ex_simps addsimprocs ex_simprs) 1))
  1161         TRY (simp_tac (HOL_basic_ss addsimps ex_simps addsimprocs ex_simprs) 1))
  1162   end;
  1162   end;
  1163 
  1163 
  1245 fun get_upd_acc_cong_thm upd acc thy simpset =
  1245 fun get_upd_acc_cong_thm upd acc thy simpset =
  1246   let
  1246   let
  1247     val insts = [("upd", cterm_of thy upd), ("acc", cterm_of thy acc)];
  1247     val insts = [("upd", cterm_of thy upd), ("acc", cterm_of thy acc)];
  1248     val prop = Thm.concl_of (named_cterm_instantiate insts updacc_cong_triv);
  1248     val prop = Thm.concl_of (named_cterm_instantiate insts updacc_cong_triv);
  1249   in
  1249   in
  1250     Goal.prove (ProofContext.init thy) [] [] prop
  1250     Goal.prove (ProofContext.init_global thy) [] [] prop
  1251       (fn _ =>
  1251       (fn _ =>
  1252         simp_tac simpset 1 THEN
  1252         simp_tac simpset 1 THEN
  1253         REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1253         REPEAT_DETERM (Iso_Tuple_Support.iso_tuple_intros_tac 1) THEN
  1254         TRY (resolve_tac [updacc_cong_idI] 1))
  1254         TRY (resolve_tac [updacc_cong_idI] 1))
  1255   end;
  1255   end;
  2386     val _ = Theory.requires thy "Record" "record definitions";
  2386     val _ = Theory.requires thy "Record" "record definitions";
  2387     val _ =
  2387     val _ =
  2388       if quiet_mode then ()
  2388       if quiet_mode then ()
  2389       else writeln ("Defining record " ^ quote (Binding.str_of binding) ^ " ...");
  2389       else writeln ("Defining record " ^ quote (Binding.str_of binding) ^ " ...");
  2390 
  2390 
  2391     val ctxt = ProofContext.init thy;
  2391     val ctxt = ProofContext.init_global thy;
  2392     fun cert_typ T = Type.no_tvars (ProofContext.cert_typ ctxt T)
  2392     fun cert_typ T = Type.no_tvars (ProofContext.cert_typ ctxt T)
  2393       handle TYPE (msg, _, _) => error msg;
  2393       handle TYPE (msg, _, _) => error msg;
  2394 
  2394 
  2395 
  2395 
  2396     (* specification *)
  2396     (* specification *)
  2436   end
  2436   end
  2437   handle ERROR msg => cat_error msg ("Failed to define record " ^ quote (Binding.str_of binding));
  2437   handle ERROR msg => cat_error msg ("Failed to define record " ^ quote (Binding.str_of binding));
  2438 
  2438 
  2439 fun add_record_cmd quiet_mode (raw_params, binding) raw_parent raw_fields thy =
  2439 fun add_record_cmd quiet_mode (raw_params, binding) raw_parent raw_fields thy =
  2440   let
  2440   let
  2441     val ctxt = ProofContext.init thy;
  2441     val ctxt = ProofContext.init_global thy;
  2442     val params = map (apsnd (Typedecl.read_constraint ctxt)) raw_params;
  2442     val params = map (apsnd (Typedecl.read_constraint ctxt)) raw_params;
  2443     val ctxt1 = fold (Variable.declare_typ o TFree) params ctxt;
  2443     val ctxt1 = fold (Variable.declare_typ o TFree) params ctxt;
  2444     val (parent, ctxt2) = read_parent raw_parent ctxt1;
  2444     val (parent, ctxt2) = read_parent raw_parent ctxt1;
  2445     val (fields, ctxt3) = fold_map read_field raw_fields ctxt2;
  2445     val (fields, ctxt3) = fold_map read_field raw_fields ctxt2;
  2446     val params' = map (ProofContext.check_tfree ctxt3) params;
  2446     val params' = map (ProofContext.check_tfree ctxt3) params;