Skip to content

Commit 5eeb184

Browse files
committed
Improved proof efficiency of chantyperep instantiation using meson.
1 parent fdd89c0 commit 5eeb184

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

Channel_Type.ML

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ fun chantyperep_instance name raw_chans thy =
7777
open Syntax; open HOLogic; open Global_Theory;
7878
val ty = Syntax.read_typ (Named_Target.theory_init thy) name;
7979
val tyco = fst (dest_Type ty);
80-
val disc_intro_thms = if length raw_chans = 1 then [] else get_thms thy (tyco ^ ".disc");
81-
val disc_elim_thms = if length raw_chans = 1 then [] else get_thms thy (tyco ^ ".exhaust_disc");
80+
val disc_thms = if length raw_chans = 1 then [] else get_thms thy (tyco ^ ".disc") @ get_thms thy (tyco ^ ".exhaust_disc")
81+
@ (if length raw_chans = 2 then [] else get_thms thy (tyco ^ ".distinct_disc"));
8282
val ctx0 = Class.instantiation ([tyco], [], \<^sort>\<open>chantyperep\<close>) thy;
8383
val chans = map (fn (n, t) => (n, mk_typerep (read_typ ctx0 t))) raw_chans
8484
val lhs = \<^Const>\<open>chantyperep ty\<close> $ Free ("T", Term.itselfT ty);
@@ -87,10 +87,9 @@ fun chantyperep_instance name raw_chans thy =
8787
val eq = check_term ctx1 (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, rhs)));
8888
val (_, ctx2) = Specification.definition NONE [] [] ((Binding.empty, @{attributes [chantyperep_defs]}), eq) ctx1;
8989
val ctx3 = Local_Theory.end_nested ctx2;
90-
val ctx4 = fold (Context.proof_map o Named_Theorems.add_thm "Channel_Type.datatype_disc_intros") disc_intro_thms ctx3;
91-
val ctx5 = fold (Context.proof_map o Named_Theorems.add_thm "Channel_Type.datatype_disc_elims") disc_elim_thms ctx4;
90+
val ctx4 = fold (Context.proof_map o Named_Theorems.add_thm "Channel_Type.datatype_disc_thms") disc_thms ctx3;
9291
in
93-
Class.prove_instantiation_exit (fn _ => NO_CONTEXT_TACTIC ctx5 (Method_Closure.apply_method ctx5 @{method chantyperep_inst} [] [] [] ctx5 [])) ctx5
92+
Class.prove_instantiation_exit (fn _ => NO_CONTEXT_TACTIC ctx4 (Method_Closure.apply_method ctx4 @{method chantyperep_inst} [] [] [] ctx4 [])) ctx4
9493
end;
9594

9695
fun compile_chantype (name, chans) thy =
@@ -100,7 +99,6 @@ fun compile_chantype (name, chans) thy =
10099
val ctx = Named_Target.theory_init thy;
101100
val ctrs = map (fn (n, t) => (((Binding.empty, Binding.name (n ^ ctor_suffix)), [(Binding.empty, t)]), Mixfix.NoSyn)) chans
102101
val pnames = map fst chans
103-
val tyreps = map (mk_typerep o read_typ ctx o snd) chans
104102
val thypfx =
105103
case (Named_Target.locale_of ctx) of
106104
SOME loc => loc ^ "." |

Channel_Type.thy

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,10 @@ definition set_chan :: "'a chantyperep \<Rightarrow> String.literal \<Rightarrow
7070
definition set_chans :: "'a chantyperep \<Rightarrow> String.literal set \<Rightarrow> 'a set" where
7171
"set_chans ct ns = \<Union> (set_chan ct ` ns)"
7272

73-
named_theorems datatype_disc_elims
74-
named_theorems datatype_disc_intros
73+
named_theorems datatype_disc_thms
7574
named_theorems chantyperep_defs
7675

77-
method wf_chantyperep = (force intro: datatype_disc_intros simp add: comp_def wf_chantyperep_def chantyperep_defs)
76+
method wf_chantyperep = (simp add: comp_def wf_chantyperep_def chantyperep_defs, (meson datatype_disc_thms)?)
7877

7978
lemma foldr_disj_one_True: "foldr (\<or>) Ps False \<Longrightarrow> (\<exists> P\<in>set Ps. P)"
8079
by (induct Ps, auto)
@@ -102,9 +101,7 @@ class chantyperep =
102101
fixes chantyperep :: "'a itself \<Rightarrow> 'a raw_chantyperep"
103102
assumes wf_chantyperep: "wf_chantyperep (chantyperep TYPE('a))"
104103

105-
(* The following method works, but relies too much on auto. It should be optimised *)
106-
107-
method chantyperep_inst = (rule chantyperep_class.intro, (intro_classes)[1], rule_tac class.chantyperep.intro, insert datatype_disc_elims, auto intro!:datatype_disc_intros simp add: comp_def wf_chantyperep_def chantyperep_defs)
104+
method chantyperep_inst = (rule chantyperep_class.intro, (intro_classes)[1], rule_tac class.chantyperep.intro, wf_chantyperep)
108105

109106
syntax "_chantyperep" :: "type \<Rightarrow> logic" ("CHANTYPEREP'(_')")
110107
translations "CHANTYPEREP('a)" == "CONST chantyperep TYPE('a)"

Channel_Type_Example.thy

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,15 @@ chantype ch_buffer2 =
2323
outp2 :: nat
2424
mod2 :: bool
2525

26+
chantype chbig =
27+
a1 :: int
28+
a2 :: int
29+
a3 :: int
30+
a4 :: int
31+
a5 :: int
32+
a6 :: bool
33+
a7 :: bool
34+
a8 :: unit
35+
a9 :: nat
36+
2637
end

0 commit comments

Comments
 (0)