80 * bool * local_theory |
80 * bool * local_theory |
81 |
81 |
82 val gfp_rec_sugar_interpretation: string -> |
82 val gfp_rec_sugar_interpretation: string -> |
83 (BNF_FP_Rec_Sugar_Util.fp_rec_sugar -> local_theory -> local_theory) -> theory -> theory |
83 (BNF_FP_Rec_Sugar_Util.fp_rec_sugar -> local_theory -> local_theory) -> theory -> theory |
84 |
84 |
85 val primcorec_ursive: bool -> corec_option list -> ((binding * typ) * mixfix) list -> |
85 val primcorec_ursive: bool -> bool -> corec_option list -> ((binding * typ) * mixfix) list -> |
86 ((binding * Token.T list list) * term) list -> term option list -> Proof.context -> |
86 ((binding * Token.T list list) * term) list -> term option list -> Proof.context -> |
87 (term * 'a list) list list * (thm list list -> local_theory -> local_theory) * local_theory |
87 (term * 'a list) list list * (thm list list -> local_theory -> local_theory) * local_theory |
88 val primcorec_ursive_cmd: bool -> corec_option list -> |
88 val primcorec_ursive_cmd: bool -> bool -> corec_option list -> |
89 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
89 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
90 Proof.context -> |
90 Proof.context -> |
91 (term * 'a list) list list * (thm list list -> local_theory -> local_theory) * local_theory |
91 (term * 'a list) list list * (thm list list -> local_theory -> local_theory) * local_theory |
92 val primcorecursive_cmd: corec_option list -> |
92 val primcorecursive_cmd: bool -> corec_option list -> |
93 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
93 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
94 Proof.context -> Proof.state |
94 Proof.context -> Proof.state |
95 val primcorec_cmd: corec_option list -> |
95 val primcorec_cmd: bool -> corec_option list -> |
96 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
96 (binding * string option * mixfix) list * ((Attrib.binding * string) * string option) list -> |
97 local_theory -> local_theory |
97 local_theory -> local_theory |
98 end; |
98 end; |
99 |
99 |
100 structure BNF_GFP_Rec_Sugar : BNF_GFP_REC_SUGAR = |
100 structure BNF_GFP_Rec_Sugar : BNF_GFP_REC_SUGAR = |
1080 Term.list_comb (Free (fun_name, fun_T), map Bound (length fun_args - 1 downto 0)); |
1080 Term.list_comb (Free (fun_name, fun_T), map Bound (length fun_args - 1 downto 0)); |
1081 |
1081 |
1082 fun is_trivial_implies thm = |
1082 fun is_trivial_implies thm = |
1083 uncurry (member (op aconv)) (Logic.strip_horn (Thm.prop_of thm)); |
1083 uncurry (member (op aconv)) (Logic.strip_horn (Thm.prop_of thm)); |
1084 |
1084 |
1085 fun primcorec_ursive auto opts fixes specs of_specs_opt lthy = |
1085 fun primcorec_ursive int auto opts fixes specs of_specs_opt lthy = |
1086 let |
1086 let |
1087 val thy = Proof_Context.theory_of lthy; |
1087 val thy = Proof_Context.theory_of lthy; |
1088 |
1088 |
1089 val (bs, mxs) = map_split (apfst fst) fixes; |
1089 val (bs, mxs) = map_split (apfst fst) fixes; |
1090 val (arg_Ts, res_Ts) = map (strip_type o snd o fst #>> mk_tupleT_balanced) fixes |> split_list; |
1090 val (arg_Ts, res_Ts) = map (strip_type o snd o fst #>> mk_tupleT_balanced) fixes |> split_list; |
1579 in |
1579 in |
1580 interpret_gfp_rec_sugar plugins fp_rec_sugar lthy |
1580 interpret_gfp_rec_sugar plugins fp_rec_sugar lthy |
1581 end) |
1581 end) |
1582 end; |
1582 end; |
1583 |
1583 |
1584 fun after_qed thmss' = fold_map Local_Theory.define defs #-> prove thmss'; |
1584 fun after_qed thmss' = |
|
1585 fold_map Local_Theory.define defs |
|
1586 #> tap (uncurry (print_def_consts int)) |
|
1587 #-> prove thmss'; |
1585 in |
1588 in |
1586 (goalss, after_qed, lthy) |
1589 (goalss, after_qed, lthy) |
1587 end; |
1590 end; |
1588 |
1591 |
1589 fun primcorec_ursive_cmd auto opts (raw_fixes, raw_specs_of) lthy = |
1592 fun primcorec_ursive_cmd int auto opts (raw_fixes, raw_specs_of) lthy = |
1590 let |
1593 let |
1591 val dups = duplicates (op =) (map (Binding.name_of o #1) raw_fixes); |
1594 val dups = duplicates (op =) (map (Binding.name_of o #1) raw_fixes); |
1592 val _ = null dups orelse error ("Duplicate function name " ^ quote (hd dups)); |
1595 val _ = null dups orelse error ("Duplicate function name " ^ quote (hd dups)); |
1593 |
1596 |
1594 val (raw_specs, of_specs_opt) = |
1597 val (raw_specs, of_specs_opt) = |
1595 split_list raw_specs_of ||> map (Option.map (Syntax.read_term lthy)); |
1598 split_list raw_specs_of ||> map (Option.map (Syntax.read_term lthy)); |
1596 val (fixes, specs) = |
1599 val (fixes, specs) = |
1597 fst (Specification.read_multi_specs raw_fixes (map (fn spec => (spec, [], [])) raw_specs) lthy); |
1600 fst (Specification.read_multi_specs raw_fixes (map (fn spec => (spec, [], [])) raw_specs) lthy); |
1598 in |
1601 in |
1599 primcorec_ursive auto opts fixes specs of_specs_opt lthy |
1602 primcorec_ursive int auto opts fixes specs of_specs_opt lthy |
1600 end; |
1603 end; |
1601 |
1604 |
1602 val primcorecursive_cmd = (fn (goalss, after_qed, lthy) => |
1605 fun primcorecursive_cmd int = (fn (goalss, after_qed, lthy) => |
1603 lthy |
1606 lthy |
1604 |> Proof.theorem NONE after_qed goalss |
1607 |> Proof.theorem NONE after_qed goalss |
1605 |> Proof.refine_singleton (Method.primitive_text (K I))) ooo primcorec_ursive_cmd false; |
1608 |> Proof.refine_singleton (Method.primitive_text (K I))) ooo |
1606 |
1609 primcorec_ursive_cmd int false; |
1607 val primcorec_cmd = (fn (goalss, after_qed, lthy) => |
1610 |
|
1611 fun primcorec_cmd int = (fn (goalss, after_qed, lthy) => |
1608 lthy |> after_qed (map (fn [] => [] | _ => use_primcorecursive ()) goalss)) ooo |
1612 lthy |> after_qed (map (fn [] => [] | _ => use_primcorecursive ()) goalss)) ooo |
1609 primcorec_ursive_cmd true; |
1613 primcorec_ursive_cmd int true; |
1610 |
1614 |
1611 val corec_option_parser = Parse.group (K "option") |
1615 val corec_option_parser = Parse.group (K "option") |
1612 (Plugin_Name.parse_filter >> Plugins_Option |
1616 (Plugin_Name.parse_filter >> Plugins_Option |
1613 || Parse.reserved "sequential" >> K Sequential_Option |
1617 || Parse.reserved "sequential" >> K Sequential_Option |
1614 || Parse.reserved "exhaustive" >> K Exhaustive_Option |
1618 || Parse.reserved "exhaustive" >> K Exhaustive_Option |
1619 |
1623 |
1620 val _ = Outer_Syntax.local_theory_to_proof @{command_keyword primcorecursive} |
1624 val _ = Outer_Syntax.local_theory_to_proof @{command_keyword primcorecursive} |
1621 "define primitive corecursive functions" |
1625 "define primitive corecursive functions" |
1622 ((Scan.optional (@{keyword "("} |-- |
1626 ((Scan.optional (@{keyword "("} |-- |
1623 Parse.!!! (Parse.list1 corec_option_parser) --| @{keyword ")"}) []) -- |
1627 Parse.!!! (Parse.list1 corec_option_parser) --| @{keyword ")"}) []) -- |
1624 (Parse.vars -- where_alt_props_of_parser) >> uncurry primcorecursive_cmd); |
1628 (Parse.vars -- where_alt_props_of_parser) >> uncurry (primcorecursive_cmd true)); |
1625 |
1629 |
1626 val _ = Outer_Syntax.local_theory @{command_keyword primcorec} |
1630 val _ = Outer_Syntax.local_theory @{command_keyword primcorec} |
1627 "define primitive corecursive functions" |
1631 "define primitive corecursive functions" |
1628 ((Scan.optional (@{keyword "("} |-- Parse.!!! (Parse.list1 corec_option_parser) |
1632 ((Scan.optional (@{keyword "("} |-- Parse.!!! (Parse.list1 corec_option_parser) |
1629 --| @{keyword ")"}) []) -- |
1633 --| @{keyword ")"}) []) -- |
1630 (Parse.vars -- where_alt_props_of_parser) >> uncurry primcorec_cmd); |
1634 (Parse.vars -- where_alt_props_of_parser) >> uncurry (primcorec_cmd true)); |
1631 |
1635 |
1632 val _ = Theory.setup (gfp_rec_sugar_interpretation transfer_plugin |
1636 val _ = Theory.setup (gfp_rec_sugar_interpretation transfer_plugin |
1633 gfp_rec_sugar_transfer_interpretation); |
1637 gfp_rec_sugar_transfer_interpretation); |
1634 |
1638 |
1635 end; |
1639 end; |