51 |
51 |
52 fun add_iffs_global (thy, th) = |
52 fun add_iffs_global (thy, th) = |
53 let |
53 let |
54 val ss = Simplifier.simpset_ref_of thy; |
54 val ss = Simplifier.simpset_ref_of thy; |
55 val cs = Classical.claset_ref_of thy; |
55 val cs = Classical.claset_ref_of thy; |
56 val (cs', ss') = (! cs, ! ss) addIffs [Attribute.thm_of th]; |
56 val (cs', ss') = (! cs, ! ss) addIffs [th]; |
57 in ss := ss'; cs := cs'; (thy, th) end; |
57 in ss := ss'; cs := cs'; (thy, th) end; |
58 |
58 |
59 fun add_wrapper wrapper thy = |
59 fun add_wrapper wrapper thy = |
60 let val r = Classical.claset_ref_of thy |
60 let val r = Classical.claset_ref_of thy |
61 in r := ! r addSWrapper wrapper; thy end; |
61 in r := ! r addSWrapper wrapper; thy end; |
66 infix 0 :== ===; |
66 infix 0 :== ===; |
67 |
67 |
68 val (op :==) = Logic.mk_defpair; |
68 val (op :==) = Logic.mk_defpair; |
69 val (op ===) = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
69 val (op ===) = HOLogic.mk_Trueprop o HOLogic.mk_eq; |
70 |
70 |
71 fun get_defs thy specs = map (PureThy.get_tthm thy o fst) specs; |
71 fun get_defs thy specs = map (PureThy.get_thm thy o fst) specs; |
72 |
72 |
73 |
73 |
74 (* proof by simplification *) |
74 (* proof by simplification *) |
75 |
75 |
76 fun prove_simp thy tacs simps = |
76 fun prove_simp thy tacs simps = |
77 let |
77 let |
78 val sign = Theory.sign_of thy; |
78 val sign = Theory.sign_of thy; |
79 val ss = Simplifier.addsimps (HOL_basic_ss, Attribute.thms_of simps); |
79 val ss = Simplifier.addsimps (HOL_basic_ss, simps); |
80 |
80 |
81 fun prove goal = |
81 fun prove goal = |
82 Attribute.tthm_of |
82 Goals.prove_goalw_cterm [] (Thm.cterm_of sign goal) |
83 (Goals.prove_goalw_cterm [] (Thm.cterm_of sign goal) |
83 (K (tacs @ [ALLGOALS (Simplifier.simp_tac ss)])) |
84 (K (tacs @ [ALLGOALS (Simplifier.simp_tac ss)])) |
84 handle ERROR => error ("The error(s) above occurred while trying to prove " |
85 handle ERROR => error ("The error(s) above occurred while trying to prove " |
85 ^ quote (Sign.string_of_term sign goal)); |
86 ^ quote (Sign.string_of_term sign goal))); |
|
87 in prove end; |
86 in prove end; |
88 |
87 |
89 |
88 |
90 |
89 |
91 (*** syntax operations ***) |
90 (*** syntax operations ***) |
326 |
325 |
327 type record_info = |
326 type record_info = |
328 {args: (string * sort) list, |
327 {args: (string * sort) list, |
329 parent: (typ list * string) option, |
328 parent: (typ list * string) option, |
330 fields: (string * typ) list, |
329 fields: (string * typ) list, |
331 simps: tthm list}; |
330 simps: thm list}; |
332 |
331 |
333 type parent_info = |
332 type parent_info = |
334 {name: string, |
333 {name: string, |
335 fields: (string * typ) list, |
334 fields: (string * typ) list, |
336 simps: tthm list}; |
335 simps: thm list}; |
337 |
336 |
338 |
337 |
339 (* data kind 'HOL/records' *) |
338 (* data kind 'HOL/records' *) |
340 |
339 |
341 structure RecordsArgs = |
340 structure RecordsArgs = |
517 val surj_props = map mk_surj_prop fields; |
516 val surj_props = map mk_surj_prop fields; |
518 |
517 |
519 |
518 |
520 (* 1st stage: types_thy *) |
519 (* 1st stage: types_thy *) |
521 |
520 |
522 val (types_thy, simps) = |
521 val (types_thy, datatype_simps) = |
523 thy |
522 thy |
524 |> field_type_defs fieldT_specs; |
523 |> field_type_defs fieldT_specs; |
525 |
|
526 val datatype_simps = Attribute.tthms_of simps; |
|
527 |
524 |
528 |
525 |
529 (* 2nd stage: defs_thy *) |
526 (* 2nd stage: defs_thy *) |
530 |
527 |
531 val defs_thy = |
528 val defs_thy = |
532 types_thy |
529 types_thy |
533 |> (Theory.add_consts_i o map (Syntax.no_syn o apfst base)) |
530 |> (Theory.add_consts_i o map (Syntax.no_syn o apfst base)) |
534 (field_decls @ dest_decls) |
531 (field_decls @ dest_decls) |
535 |> (PureThy.add_defs_i o map (fn x => (x, [Attribute.tag_internal]))) |
532 |> (PureThy.add_defs_i o map (fn x => (x, [Drule.tag_internal]))) |
536 (field_specs @ dest_specs); |
533 (field_specs @ dest_specs); |
537 |
534 |
538 val field_defs = get_defs defs_thy field_specs; |
535 val field_defs = get_defs defs_thy field_specs; |
539 val dest_defs = get_defs defs_thy dest_specs; |
536 val dest_defs = get_defs defs_thy dest_specs; |
540 |
537 |
545 val prove_std = prove [] (field_defs @ dest_defs @ datatype_simps); |
542 val prove_std = prove [] (field_defs @ dest_defs @ datatype_simps); |
546 |
543 |
547 val field_injects = map prove_std inject_props; |
544 val field_injects = map prove_std inject_props; |
548 val dest_convs = map prove_std dest_props; |
545 val dest_convs = map prove_std dest_props; |
549 val surj_pairs = map (prove [DatatypePackage.induct_tac "p" 1] |
546 val surj_pairs = map (prove [DatatypePackage.induct_tac "p" 1] |
550 (map (apfst Thm.symmetric) field_defs @ dest_convs)) surj_props; |
547 (map Thm.symmetric field_defs @ dest_convs)) surj_props; |
551 |
548 |
552 fun mk_split th = SplitPairedAll.rule (th RS eq_reflection); |
549 fun mk_split th = SplitPairedAll.rule (th RS eq_reflection); |
553 val field_splits = map (fn (th, _) => Attribute.tthm_of (mk_split th)) surj_pairs; |
550 val field_splits = map mk_split surj_pairs; |
554 |
551 |
555 val thms_thy = |
552 val thms_thy = |
556 defs_thy |
553 defs_thy |
557 |> (PureThy.add_tthmss o map Attribute.none) |
554 |> (PureThy.add_thmss o map Thm.no_attributes) |
558 [("field_defs", field_defs), |
555 [("field_defs", field_defs), |
559 ("dest_defs", dest_defs), |
556 ("dest_defs", dest_defs), |
560 ("dest_convs", dest_convs), |
557 ("dest_convs", dest_convs), |
561 ("surj_pairs", surj_pairs), |
558 ("surj_pairs", surj_pairs), |
562 ("field_splits", field_splits)]; |
559 ("field_splits", field_splits)]; |
690 val (fields_thy, field_simps, field_injects, field_splits) = |
687 val (fields_thy, field_simps, field_injects, field_splits) = |
691 thy |
688 thy |
692 |> Theory.add_path bname |
689 |> Theory.add_path bname |
693 |> field_definitions fields names zeta moreT more vars named_vars; |
690 |> field_definitions fields names zeta moreT more vars named_vars; |
694 |
691 |
695 val named_splits = map2 (fn (c, (th, _)) => (suffix field_typeN c, th)) (names, field_splits); |
692 val named_splits = map2 (fn (c, th) => (suffix field_typeN c, th)) (names, field_splits); |
696 |
693 |
697 |
694 |
698 (* 2nd stage: defs_thy *) |
695 (* 2nd stage: defs_thy *) |
699 |
696 |
700 val defs_thy = |
697 val defs_thy = |
703 |> Theory.add_tyabbrs_i recordT_specs (*not made part of record name space!*) |
700 |> Theory.add_tyabbrs_i recordT_specs (*not made part of record name space!*) |
704 |> Theory.add_path bname |
701 |> Theory.add_path bname |
705 |> Theory.add_trfuns ([], [], field_tr's, []) |
702 |> Theory.add_trfuns ([], [], field_tr's, []) |
706 |> (Theory.add_consts_i o map Syntax.no_syn) |
703 |> (Theory.add_consts_i o map Syntax.no_syn) |
707 (sel_decls @ update_decls @ make_decls) |
704 (sel_decls @ update_decls @ make_decls) |
708 |> (PureThy.add_defs_i o map (fn x => (x, [Attribute.tag_internal]))) |
705 |> (PureThy.add_defs_i o map (fn x => (x, [Drule.tag_internal]))) |
709 (sel_specs @ update_specs) |
706 (sel_specs @ update_specs) |
710 |> (PureThy.add_defs_i o map Attribute.none) make_specs; |
707 |> (PureThy.add_defs_i o map Thm.no_attributes) make_specs; |
711 |
708 |
712 val sel_defs = get_defs defs_thy sel_specs; |
709 val sel_defs = get_defs defs_thy sel_specs; |
713 val update_defs = get_defs defs_thy update_specs; |
710 val update_defs = get_defs defs_thy update_specs; |
714 val make_defs = get_defs defs_thy make_specs; |
711 val make_defs = get_defs defs_thy make_specs; |
715 |
712 |
724 |
721 |
725 val simps = field_simps @ sel_convs @ update_convs @ make_defs; |
722 val simps = field_simps @ sel_convs @ update_convs @ make_defs; |
726 |
723 |
727 val thms_thy = |
724 val thms_thy = |
728 defs_thy |
725 defs_thy |
729 |> (PureThy.add_tthmss o map Attribute.none) |
726 |> (PureThy.add_thmss o map Thm.no_attributes) |
730 [("select_defs", sel_defs), |
727 [("select_defs", sel_defs), |
731 ("update_defs", update_defs), |
728 ("update_defs", update_defs), |
732 ("make_defs", make_defs), |
729 ("make_defs", make_defs), |
733 ("select_convs", sel_convs), |
730 ("select_convs", sel_convs), |
734 ("update_convs", update_convs)] |
731 ("update_convs", update_convs)] |
735 |> PureThy.add_tthmss |
732 |> PureThy.add_thmss |
736 [(("simps", simps), [Simplifier.simp_add_global]), |
733 [(("simps", simps), [Simplifier.simp_add_global]), |
737 (("iffs", field_injects), [add_iffs_global])]; |
734 (("iffs", field_injects), [add_iffs_global])]; |
738 |
735 |
739 |
736 |
740 (* 4th stage: final_thy *) |
737 (* 4th stage: final_thy *) |