equal
deleted
inserted
replaced
162 (rep_isom_data_of_code_dt code_dt) |
162 (rep_isom_data_of_code_dt code_dt) |
163 |
163 |
164 |
164 |
165 (** unique name for a type **) |
165 (** unique name for a type **) |
166 |
166 |
167 fun var_name name sort = if sort = @{sort "{type}"} orelse sort = [] then ["x" ^ name] |
167 fun var_name name sort = if sort = \<^sort>\<open>{type}\<close> orelse sort = [] then ["x" ^ name] |
168 else "x" ^ name :: "x_" :: sort @ ["x_"]; |
168 else "x" ^ name :: "x_" :: sort @ ["x_"]; |
169 |
169 |
170 fun concat_Tnames (Type (name, ts)) = name :: maps concat_Tnames ts |
170 fun concat_Tnames (Type (name, ts)) = name :: maps concat_Tnames ts |
171 | concat_Tnames (TFree (name, sort)) = var_name name sort |
171 | concat_Tnames (TFree (name, sort)) = var_name name sort |
172 | concat_Tnames (TVar ((name, _), sort)) = var_name name sort; |
172 | concat_Tnames (TVar ((name, _), sort)) = var_name name sort; |
178 fold (Binding.qualify false) (tl Tnames) (Binding.name (hd Tnames)) |
178 fold (Binding.qualify false) (tl Tnames) (Binding.name (hd Tnames)) |
179 end; |
179 end; |
180 |
180 |
181 (** witnesses **) |
181 (** witnesses **) |
182 |
182 |
183 fun mk_undefined T = Const (@{const_name undefined}, T); |
183 fun mk_undefined T = Const (\<^const_name>\<open>undefined\<close>, T); |
184 |
184 |
185 fun mk_witness quot_thm = |
185 fun mk_witness quot_thm = |
186 let |
186 let |
187 val wit_thm = quot_thm RS @{thm type_definition_Quotient_not_empty_witness} |
187 val wit_thm = quot_thm RS @{thm type_definition_Quotient_not_empty_witness} |
188 val wit = quot_thm_rep quot_thm $ mk_undefined (quot_thm_rty_qty quot_thm |> snd) |
188 val wit = quot_thm_rep quot_thm $ mk_undefined (quot_thm_rty_qty quot_thm |> snd) |
237 and add_lift_def_code_dt config var qty rhs rsp_thm par_thms lthy = |
237 and add_lift_def_code_dt config var qty rhs rsp_thm par_thms lthy = |
238 let |
238 let |
239 fun binop_conv2 cv1 cv2 = Conv.combination_conv (Conv.arg_conv cv1) cv2 |
239 fun binop_conv2 cv1 cv2 = Conv.combination_conv (Conv.arg_conv cv1) cv2 |
240 fun ret_rel_conv conv ctm = |
240 fun ret_rel_conv conv ctm = |
241 case (Thm.term_of ctm) of |
241 case (Thm.term_of ctm) of |
242 Const (@{const_name "rel_fun"}, _) $ _ $ _ => |
242 Const (\<^const_name>\<open>rel_fun\<close>, _) $ _ $ _ => |
243 binop_conv2 Conv.all_conv conv ctm |
243 binop_conv2 Conv.all_conv conv ctm |
244 | _ => conv ctm |
244 | _ => conv ctm |
245 fun R_conv rel_eq_onps = Transfer.top_sweep_rewr_conv @{thms eq_onp_top_eq_eq[symmetric, THEN eq_reflection]} |
245 fun R_conv rel_eq_onps = Transfer.top_sweep_rewr_conv @{thms eq_onp_top_eq_eq[symmetric, THEN eq_reflection]} |
246 then_conv Transfer.bottom_rewr_conv rel_eq_onps |
246 then_conv Transfer.bottom_rewr_conv rel_eq_onps |
247 |
247 |
435 |
435 |
436 (* now we can execute the qty qty_isom isomorphism *) |
436 (* now we can execute the qty qty_isom isomorphism *) |
437 fun mk_type_definition newT oldT RepC AbsC A = |
437 fun mk_type_definition newT oldT RepC AbsC A = |
438 let |
438 let |
439 val typedefC = |
439 val typedefC = |
440 Const (@{const_name type_definition}, |
440 Const (\<^const_name>\<open>type_definition\<close>, |
441 (newT --> oldT) --> (oldT --> newT) --> HOLogic.mk_setT oldT --> HOLogic.boolT); |
441 (newT --> oldT) --> (oldT --> newT) --> HOLogic.mk_setT oldT --> HOLogic.boolT); |
442 in typedefC $ RepC $ AbsC $ A end; |
442 in typedefC $ RepC $ AbsC $ A end; |
443 val typedef_goal = mk_type_definition qty_isom qty rep_isom abs_isom (HOLogic.mk_UNIV qty) |> |
443 val typedef_goal = mk_type_definition qty_isom qty rep_isom abs_isom (HOLogic.mk_UNIV qty) |> |
444 HOLogic.mk_Trueprop; |
444 HOLogic.mk_Trueprop; |
445 fun typ_isom_tac ctxt i = |
445 fun typ_isom_tac ctxt i = |
481 |
481 |
482 fun rep_isom lthy t (rty, qty) = |
482 fun rep_isom lthy t (rty, qty) = |
483 let |
483 let |
484 val rep = quot_isom_rep lthy (rty, qty) |
484 val rep = quot_isom_rep lthy (rty, qty) |
485 in |
485 in |
486 if is_Const rep andalso (rep |> dest_Const |> fst) = @{const_name id} then |
486 if is_Const rep andalso (rep |> dest_Const |> fst) = \<^const_name>\<open>id\<close> then |
487 t else rep $ t |
487 t else rep $ t |
488 end; |
488 end; |
489 in |
489 in |
490 @{fold 3} (fn sel => fn ctr_T => fn sel_ret_T => fn ctr => |
490 @{fold 3} (fn sel => fn ctr_T => fn sel_ret_T => fn ctr => |
491 ctr $ rep_isom lthy (sel $ x) (ctr_T, sel_ret_T)) sels ctr_Ts sel_ret_Ts ctr |
491 ctr $ rep_isom lthy (sel $ x) (ctr_T, sel_ret_T)) sels ctr_Ts sel_ret_Ts ctr |
628 theorem in a user-friendly, readable form. Then add_lift_def_code_dt is called internally. |
628 theorem in a user-friendly, readable form. Then add_lift_def_code_dt is called internally. |
629 |
629 |
630 **) |
630 **) |
631 |
631 |
632 local |
632 local |
633 val eq_onp_assms_tac_fixed_rules = map (Transfer.prep_transfer_domain_thm @{context}) |
633 val eq_onp_assms_tac_fixed_rules = map (Transfer.prep_transfer_domain_thm \<^context>) |
634 [@{thm pcr_Domainp_total}, @{thm pcr_Domainp_par_left_total}, @{thm pcr_Domainp_par}, |
634 [@{thm pcr_Domainp_total}, @{thm pcr_Domainp_par_left_total}, @{thm pcr_Domainp_par}, |
635 @{thm pcr_Domainp}] |
635 @{thm pcr_Domainp}] |
636 in |
636 in |
637 fun mk_readable_rsp_thm_eq tm lthy = |
637 fun mk_readable_rsp_thm_eq tm lthy = |
638 let |
638 let |
697 then_conv kill_tops |
697 then_conv kill_tops |
698 val relator_eq_conv = Conv.bottom_conv |
698 val relator_eq_conv = Conv.bottom_conv |
699 (K (Conv.try_conv (Conv.rewrs_conv (Transfer.get_relator_eq lthy)))) lthy |
699 (K (Conv.try_conv (Conv.rewrs_conv (Transfer.get_relator_eq lthy)))) lthy |
700 in |
700 in |
701 case (Thm.term_of ctm) of |
701 case (Thm.term_of ctm) of |
702 Const (@{const_name "rel_fun"}, _) $ _ $ _ => |
702 Const (\<^const_name>\<open>rel_fun\<close>, _) $ _ $ _ => |
703 (binop_conv2 simp_arrows_conv simp_arrows_conv then_conv unfold_conv) ctm |
703 (binop_conv2 simp_arrows_conv simp_arrows_conv then_conv unfold_conv) ctm |
704 | _ => (relator_eq_onp_conv then_conv relator_eq_conv) ctm |
704 | _ => (relator_eq_onp_conv then_conv relator_eq_conv) ctm |
705 end |
705 end |
706 |
706 |
707 val unfold_ret_val_invs = Conv.bottom_conv |
707 val unfold_ret_val_invs = Conv.bottom_conv |
720 end |
720 end |
721 end |
721 end |
722 |
722 |
723 fun rename_to_tnames ctxt term = |
723 fun rename_to_tnames ctxt term = |
724 let |
724 let |
725 fun all_typs (Const (@{const_name Pure.all}, _) $ Abs (_, T, t)) = T :: all_typs t |
725 fun all_typs (Const (\<^const_name>\<open>Pure.all\<close>, _) $ Abs (_, T, t)) = T :: all_typs t |
726 | all_typs _ = [] |
726 | all_typs _ = [] |
727 |
727 |
728 fun rename (Const (@{const_name Pure.all}, T1) $ Abs (_, T2, t)) (new_name :: names) = |
728 fun rename (Const (\<^const_name>\<open>Pure.all\<close>, T1) $ Abs (_, T2, t)) (new_name :: names) = |
729 (Const (@{const_name Pure.all}, T1) $ Abs (new_name, T2, rename t names)) |
729 (Const (\<^const_name>\<open>Pure.all\<close>, T1) $ Abs (new_name, T2, rename t names)) |
730 | rename t _ = t |
730 | rename t _ = t |
731 |
731 |
732 val (fixed_def_t, _) = yield_singleton (Variable.importT_terms) term ctxt |
732 val (fixed_def_t, _) = yield_singleton (Variable.importT_terms) term ctxt |
733 val new_names = Old_Datatype_Prop.make_tnames (all_typs fixed_def_t) |
733 val new_names = Old_Datatype_Prop.make_tnames (all_typs fixed_def_t) |
734 in |
734 in |
819 |
819 |
820 |
820 |
821 (* command syntax *) |
821 (* command syntax *) |
822 |
822 |
823 val _ = |
823 val _ = |
824 Outer_Syntax.local_theory_to_proof @{command_keyword lift_definition} |
824 Outer_Syntax.local_theory_to_proof \<^command_keyword>\<open>lift_definition\<close> |
825 "definition for constants over the quotient type" |
825 "definition for constants over the quotient type" |
826 (parse_params -- |
826 (parse_params -- |
827 (((Parse.binding -- (@{keyword "::"} |-- (Parse.typ >> SOME) -- Parse.opt_mixfix') |
827 (((Parse.binding -- (\<^keyword>\<open>::\<close> |-- (Parse.typ >> SOME) -- Parse.opt_mixfix') |
828 >> Scan.triple2) -- |
828 >> Scan.triple2) -- |
829 (@{keyword "is"} |-- Parse.term) -- |
829 (\<^keyword>\<open>is\<close> |-- Parse.term) -- |
830 Scan.optional (@{keyword "parametric"} |-- Parse.!!! Parse.thms1) []) >> Scan.triple1) |
830 Scan.optional (\<^keyword>\<open>parametric\<close> |-- Parse.!!! Parse.thms1) []) >> Scan.triple1) |
831 >> lift_def_cmd_with_err_handling); |
831 >> lift_def_cmd_with_err_handling); |
832 |
832 |
833 end |
833 end |