author  berghofe 
Sat, 30 Jan 2010 16:58:46 +0100  
changeset 34987  c1e8af37ee75 
parent 34907  b0aaec87751c 
child 35360  df2b2168e43a 
permissions  rwrr 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

1 
(* Title: Tools/induct.ML 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

2 
Author: Markus Wenzel, TU Muenchen 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

3 

26924  4 
Proof by cases, induction, and coinduction. 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

5 
*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

6 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

7 
signature INDUCT_DATA = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

8 
sig 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

9 
val cases_default: thm 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

10 
val atomize: thm list 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

11 
val rulify: thm list 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

12 
val rulify_fallback: thm list 
34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

13 
val equal_def: thm 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

14 
val dest_def: term > (term * term) option 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

15 
val trivial_tac: int > tactic 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

16 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

17 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

18 
signature INDUCT = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

19 
sig 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

20 
(*rule declarations*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

21 
val vars_of: term > term list 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

22 
val dest_rules: Proof.context > 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

23 
{type_cases: (string * thm) list, pred_cases: (string * thm) list, 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

24 
type_induct: (string * thm) list, pred_induct: (string * thm) list, 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

25 
type_coinduct: (string * thm) list, pred_coinduct: (string * thm) list} 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

26 
val print_rules: Proof.context > unit 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

27 
val lookup_casesT: Proof.context > string > thm option 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

28 
val lookup_casesP: Proof.context > string > thm option 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

29 
val lookup_inductT: Proof.context > string > thm option 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

30 
val lookup_inductP: Proof.context > string > thm option 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

31 
val lookup_coinductT: Proof.context > string > thm option 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

32 
val lookup_coinductP: Proof.context > string > thm option 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

33 
val find_casesT: Proof.context > typ > thm list 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

34 
val find_casesP: Proof.context > term > thm list 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

35 
val find_inductT: Proof.context > typ > thm list 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

36 
val find_inductP: Proof.context > term > thm list 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

37 
val find_coinductT: Proof.context > typ > thm list 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

38 
val find_coinductP: Proof.context > term > thm list 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

39 
val cases_type: string > attribute 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

40 
val cases_pred: string > attribute 
27140  41 
val cases_del: attribute 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

42 
val induct_type: string > attribute 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

43 
val induct_pred: string > attribute 
27140  44 
val induct_del: attribute 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

45 
val coinduct_type: string > attribute 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

46 
val coinduct_pred: string > attribute 
27140  47 
val coinduct_del: attribute 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

48 
val map_simpset: (simpset > simpset) > Context.generic > Context.generic 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

49 
val add_simp_rule: attribute 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

50 
val no_simpN: string 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

51 
val casesN: string 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

52 
val inductN: string 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

53 
val coinductN: string 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

54 
val typeN: string 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

55 
val predN: string 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

56 
val setN: string 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

57 
(*proof methods*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

58 
val fix_tac: Proof.context > int > (string * typ) list > int > tactic 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

59 
val add_defs: (binding option * (term * bool)) option list > Proof.context > 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

60 
(term option list * thm list) * Proof.context 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

61 
val atomize_term: theory > term > term 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

62 
val atomize_cterm: conv 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

63 
val atomize_tac: int > tactic 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

64 
val inner_atomize_tac: int > tactic 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

65 
val rulified_term: thm > theory * term 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

66 
val rulify_tac: int > tactic 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

67 
val simplified_rule: Proof.context > thm > thm 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

68 
val simplify_tac: Proof.context > int > tactic 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

69 
val trivial_tac: int > tactic 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

70 
val rotate_tac: int > int > int > tactic 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

71 
val internalize: int > thm > thm 
26940  72 
val guess_instance: Proof.context > thm > int > thm > thm Seq.seq 
34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

73 
val cases_tac: Proof.context > bool > term option list list > thm option > 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

74 
thm list > int > cases_tactic 
27323
385c0ce33173
tuned get_inductT: *all* rules for missing instantiation;
wenzelm
parents:
27140
diff
changeset

75 
val get_inductT: Proof.context > term option list list > thm list list 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

76 
val induct_tac: Proof.context > bool > (binding option * (term * bool)) option list list > 
26924  77 
(string * typ) list list > term option list > thm list option > 
78 
thm list > int > cases_tactic 

79 
val coinduct_tac: Proof.context > term option list > term option list > thm option > 

80 
thm list > int > cases_tactic 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

81 
val setup: theory > theory 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

82 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

83 

32171  84 
functor Induct(Data: INDUCT_DATA): INDUCT = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

85 
struct 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

86 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

87 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

88 
(** misc utils **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

89 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

90 
(* encode_type  for indexing purposes *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

91 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

92 
fun encode_type (Type (c, Ts)) = Term.list_comb (Const (c, dummyT), map encode_type Ts) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

93 
 encode_type (TFree (a, _)) = Free (a, dummyT) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

94 
 encode_type (TVar (a, _)) = Var (a, dummyT); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

95 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

96 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

97 
(* variables  ordered lefttoright, preferring right *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

98 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

99 
fun vars_of tm = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

100 
rev (distinct (op =) (Term.fold_aterms (fn (t as Var _) => cons t  _ => I) tm [])); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

101 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

102 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

103 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

104 
val mk_var = encode_type o #2 o Term.dest_Var; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

105 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

106 
fun concl_var which thm = mk_var (which (vars_of (Thm.concl_of thm))) handle Empty => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

107 
raise THM ("No variables in conclusion of rule", 0, [thm]); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

108 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

109 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

110 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

111 
fun left_var_prem thm = mk_var (hd (vars_of (hd (Thm.prems_of thm)))) handle Empty => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

112 
raise THM ("No variables in major premise of rule", 0, [thm]); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

113 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

114 
val left_var_concl = concl_var hd; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

115 
val right_var_concl = concl_var List.last; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

116 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

117 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

118 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

119 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

120 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

121 
(** constraint simplification **) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

122 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

123 
(* rearrange parameters and premises to allow application of onepointrules *) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

124 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

125 
fun swap_params_conv ctxt i j cv = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

126 
let 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

127 
fun conv1 0 ctxt = Conv.forall_conv (cv o snd) ctxt 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

128 
 conv1 k ctxt = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

129 
Conv.rewr_conv @{thm swap_params} then_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

130 
Conv.forall_conv (conv1 (k1) o snd) ctxt 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

131 
fun conv2 0 ctxt = conv1 j ctxt 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

132 
 conv2 k ctxt = Conv.forall_conv (conv2 (k1) o snd) ctxt 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

133 
in conv2 i ctxt end; 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

134 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

135 
fun swap_prems_conv 0 = Conv.all_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

136 
 swap_prems_conv i = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

137 
Conv.implies_concl_conv (swap_prems_conv (i1)) then_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

138 
Conv.rewr_conv Drule.swap_prems_eq 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

139 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

140 
fun drop_judgment ctxt = ObjectLogic.drop_judgment (ProofContext.theory_of ctxt); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

141 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

142 
fun find_eq ctxt t = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

143 
let 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

144 
val l = length (Logic.strip_params t); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

145 
val Hs = Logic.strip_assums_hyp t; 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

146 
fun find (i, t) = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

147 
case Data.dest_def (drop_judgment ctxt t) of 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

148 
SOME (Bound j, _) => SOME (i, j) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

149 
 SOME (_, Bound j) => SOME (i, j) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

150 
 _ => NONE 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

151 
in 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

152 
case get_first find (map_index I Hs) of 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

153 
NONE => NONE 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

154 
 SOME (0, 0) => NONE 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

155 
 SOME (i, j) => SOME (i, lj1, j) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

156 
end; 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

157 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

158 
fun mk_swap_rrule ctxt ct = case find_eq ctxt (term_of ct) of 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

159 
NONE => NONE 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

160 
 SOME (i, k, j) => SOME (swap_params_conv ctxt k j (K (swap_prems_conv i)) ct); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

161 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

162 
val rearrange_eqs_simproc = Simplifier.simproc 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

163 
(Thm.theory_of_thm Drule.swap_prems_eq) "rearrange_eqs" ["all t"] 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

164 
(fn thy => fn ss => fn t => 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

165 
mk_swap_rrule (Simplifier.the_context ss) (cterm_of thy t)) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

166 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

167 
(* rotate k premises to the left by j, skipping over first j premises *) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

168 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

169 
fun rotate_conv 0 j 0 = Conv.all_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

170 
 rotate_conv 0 j k = swap_prems_conv j then_conv rotate_conv 1 j (k1) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

171 
 rotate_conv i j k = Conv.implies_concl_conv (rotate_conv (i1) j k); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

172 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

173 
fun rotate_tac j 0 = K all_tac 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

174 
 rotate_tac j k = SUBGOAL (fn (goal, i) => CONVERSION (rotate_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

175 
j (length (Logic.strip_assums_hyp goal)  j  k) k) i); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

176 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

177 
(* rulify operators around definition *) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

178 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

179 
fun rulify_defs_conv ctxt ct = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

180 
if exists_subterm (is_some o Data.dest_def) (term_of ct) andalso 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

181 
not (is_some (Data.dest_def (drop_judgment ctxt (term_of ct)))) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

182 
then 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

183 
(Conv.forall_conv (rulify_defs_conv o snd) ctxt else_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

184 
Conv.implies_conv (Conv.try_conv (rulify_defs_conv ctxt)) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

185 
(Conv.try_conv (rulify_defs_conv ctxt)) else_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

186 
Conv.first_conv (map Conv.rewr_conv Data.rulify) then_conv 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

187 
Conv.try_conv (rulify_defs_conv ctxt)) ct 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

188 
else Conv.no_conv ct; 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

189 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

190 

b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

191 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

192 
(** induct data **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

193 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

194 
(* rules *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

195 

30560  196 
type rules = (string * thm) Item_Net.T; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

197 

33373  198 
fun init_rules index : rules = 
199 
Item_Net.init 

200 
(fn ((s1, th1), (s2, th2)) => s1 = s2 andalso Thm.eq_thm_prop (th1, th2)) 

201 
(single o index); 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

202 

27140  203 
fun filter_rules (rs: rules) th = 
30560  204 
filter (fn (_, th') => Thm.eq_thm_prop (th, th')) (Item_Net.content rs); 
27140  205 

30560  206 
fun lookup_rule (rs: rules) = AList.lookup (op =) (Item_Net.content rs); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

207 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

208 
fun pretty_rules ctxt kind rs = 
30560  209 
let val thms = map snd (Item_Net.content rs) 
32091
30e2ffbba718
proper context for Display.pretty_thm etc. or oldstyle versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents:
32032
diff
changeset

210 
in Pretty.big_list kind (map (Display.pretty_thm ctxt) thms) end; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

211 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

212 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

213 
(* context data *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

214 

33519  215 
structure InductData = Generic_Data 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

216 
( 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

217 
type T = (rules * rules) * (rules * rules) * (rules * rules) * simpset; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

218 
val empty = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

219 
((init_rules (left_var_prem o #2), init_rules (Thm.major_prem_of o #2)), 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

220 
(init_rules (right_var_concl o #2), init_rules (Thm.major_prem_of o #2)), 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

221 
(init_rules (left_var_concl o #2), init_rules (Thm.concl_of o #2)), 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

222 
empty_ss addsimprocs [rearrange_eqs_simproc] addsimps [Drule.norm_hhf_eq]); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

223 
val extend = I; 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

224 
fun merge (((casesT1, casesP1), (inductT1, inductP1), (coinductT1, coinductP1), simpset1), 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

225 
((casesT2, casesP2), (inductT2, inductP2), (coinductT2, coinductP2), simpset2)) = 
30560  226 
((Item_Net.merge (casesT1, casesT2), Item_Net.merge (casesP1, casesP2)), 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

227 
(Item_Net.merge (inductT1, inductT2), Item_Net.merge (inductP1, inductP2)), 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

228 
(Item_Net.merge (coinductT1, coinductT2), Item_Net.merge (coinductP1, coinductP2)), 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

229 
merge_ss (simpset1, simpset2)); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

230 
); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

231 

27140  232 
val get_local = InductData.get o Context.Proof; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

233 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

234 
fun dest_rules ctxt = 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

235 
let val ((casesT, casesP), (inductT, inductP), (coinductT, coinductP), _) = get_local ctxt in 
30560  236 
{type_cases = Item_Net.content casesT, 
237 
pred_cases = Item_Net.content casesP, 

238 
type_induct = Item_Net.content inductT, 

239 
pred_induct = Item_Net.content inductP, 

240 
type_coinduct = Item_Net.content coinductT, 

241 
pred_coinduct = Item_Net.content coinductP} 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

242 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

243 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

244 
fun print_rules ctxt = 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

245 
let val ((casesT, casesP), (inductT, inductP), (coinductT, coinductP), _) = get_local ctxt in 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

246 
[pretty_rules ctxt "coinduct type:" coinductT, 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

247 
pretty_rules ctxt "coinduct pred:" coinductP, 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

248 
pretty_rules ctxt "induct type:" inductT, 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

249 
pretty_rules ctxt "induct pred:" inductP, 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

250 
pretty_rules ctxt "cases type:" casesT, 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

251 
pretty_rules ctxt "cases pred:" casesP] 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

252 
> Pretty.chunks > Pretty.writeln 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

253 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

254 

24867  255 
val _ = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

256 
OuterSyntax.improper_command "print_induct_rules" "print induction and cases rules" 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

257 
OuterKeyword.diag (Scan.succeed (Toplevel.no_timing o Toplevel.unknown_context o 
24867  258 
Toplevel.keep (print_rules o Toplevel.context_of))); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

259 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

260 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

261 
(* access rules *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

262 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

263 
val lookup_casesT = lookup_rule o #1 o #1 o get_local; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

264 
val lookup_casesP = lookup_rule o #2 o #1 o get_local; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

265 
val lookup_inductT = lookup_rule o #1 o #2 o get_local; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

266 
val lookup_inductP = lookup_rule o #2 o #2 o get_local; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

267 
val lookup_coinductT = lookup_rule o #1 o #3 o get_local; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

268 
val lookup_coinductP = lookup_rule o #2 o #3 o get_local; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

269 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

270 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

271 
fun find_rules which how ctxt x = 
30560  272 
map snd (Item_Net.retrieve (which (get_local ctxt)) (how x)); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

273 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

274 
val find_casesT = find_rules (#1 o #1) encode_type; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

275 
val find_casesP = find_rules (#2 o #1) I; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

276 
val find_inductT = find_rules (#1 o #2) encode_type; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

277 
val find_inductP = find_rules (#2 o #2) I; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

278 
val find_coinductT = find_rules (#1 o #3) encode_type; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

279 
val find_coinductP = find_rules (#2 o #3) I; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

280 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

281 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

282 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

283 
(** attributes **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

284 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

285 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

286 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

287 
fun mk_att f g name arg = 
27140  288 
let val (x, thm) = g arg in (InductData.map (f (name, thm)) x, thm) end; 
289 

290 
fun del_att which = Thm.declaration_attribute (fn th => InductData.map (which (pairself (fn rs => 

33373  291 
fold Item_Net.remove (filter_rules rs th) rs)))); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

292 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

293 
fun map1 f (x, y, z, s) = (f x, y, z, s); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

294 
fun map2 f (x, y, z, s) = (x, f y, z, s); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

295 
fun map3 f (x, y, z, s) = (x, y, f z, s); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

296 
fun map4 f (x, y, z, s) = (x, y, z, f s); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

297 

33373  298 
fun add_casesT rule x = map1 (apfst (Item_Net.update rule)) x; 
299 
fun add_casesP rule x = map1 (apsnd (Item_Net.update rule)) x; 

300 
fun add_inductT rule x = map2 (apfst (Item_Net.update rule)) x; 

301 
fun add_inductP rule x = map2 (apsnd (Item_Net.update rule)) x; 

302 
fun add_coinductT rule x = map3 (apfst (Item_Net.update rule)) x; 

303 
fun add_coinductP rule x = map3 (apsnd (Item_Net.update rule)) x; 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

304 

33368  305 
val consumes0 = Rule_Cases.consumes_default 0; 
306 
val consumes1 = Rule_Cases.consumes_default 1; 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

307 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

308 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

309 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

310 
val cases_type = mk_att add_casesT consumes0; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

311 
val cases_pred = mk_att add_casesP consumes1; 
27140  312 
val cases_del = del_att map1; 
313 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

314 
val induct_type = mk_att add_inductT consumes0; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

315 
val induct_pred = mk_att add_inductP consumes1; 
27140  316 
val induct_del = del_att map2; 
317 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

318 
val coinduct_type = mk_att add_coinductT consumes0; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

319 
val coinduct_pred = mk_att add_coinductP consumes1; 
27140  320 
val coinduct_del = del_att map3; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

321 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

322 
fun map_simpset f = InductData.map (map4 f); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

323 
fun add_simp_rule (ctxt, thm) = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

324 
(map_simpset (fn ss => ss addsimps [thm]) ctxt, thm); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

325 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

326 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

327 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

328 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

329 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

330 
(** attribute syntax **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

331 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

332 
val no_simpN = "no_simp"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

333 
val casesN = "cases"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

334 
val inductN = "induct"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

335 
val coinductN = "coinduct"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

336 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

337 
val typeN = "type"; 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

338 
val predN = "pred"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

339 
val setN = "set"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

340 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

341 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

342 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

343 
fun spec k arg = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

344 
Scan.lift (Args.$$$ k  Args.colon)  arg  
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

345 
Scan.lift (Args.$$$ k) >> K ""; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

346 

30528  347 
fun attrib add_type add_pred del = 
348 
spec typeN Args.tyname >> add_type  

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

349 
spec predN Args.const >> add_pred  
27140  350 
spec setN Args.const >> add_pred  
30528  351 
Scan.lift Args.del >> K del; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

352 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

353 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

354 

30528  355 
val attrib_setup = 
30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

356 
Attrib.setup @{binding cases} (attrib cases_type cases_pred cases_del) 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

357 
"declaration of cases rule" #> 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

358 
Attrib.setup @{binding induct} (attrib induct_type induct_pred induct_del) 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

359 
"declaration of induction rule" #> 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

360 
Attrib.setup @{binding coinduct} (attrib coinduct_type coinduct_pred coinduct_del) 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

361 
"declaration of coinduction rule" #> 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

362 
Attrib.setup @{binding induct_simp} (Scan.succeed add_simp_rule) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

363 
"declaration of rules for simplifying induction or cases rules"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

364 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

365 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

366 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

367 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

368 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

369 
(** method utils **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

370 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

371 
(* alignment *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

372 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

373 
fun align_left msg xs ys = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

374 
let val m = length xs and n = length ys 
33957  375 
in if m < n then error msg else (take n xs ~~ ys) end; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

376 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

377 
fun align_right msg xs ys = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

378 
let val m = length xs and n = length ys 
33957  379 
in if m < n then error msg else (drop (m  n) xs ~~ ys) end; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

380 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

381 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

382 
(* prep_inst *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

383 

32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

384 
fun prep_inst ctxt align tune (tm, ts) = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

385 
let 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

386 
val cert = Thm.cterm_of (ProofContext.theory_of ctxt); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

387 
fun prep_var (x, SOME t) = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

388 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

389 
val cx = cert x; 
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26568
diff
changeset

390 
val xT = #T (Thm.rep_cterm cx); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

391 
val ct = cert (tune t); 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

392 
val tT = #T (Thm.rep_cterm ct); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

393 
in 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

394 
if Type.could_unify (tT, xT) then SOME (cx, ct) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

395 
else error (Pretty.string_of (Pretty.block 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

396 
[Pretty.str "Illtyped instantiation:", Pretty.fbrk, 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

397 
Syntax.pretty_term ctxt (Thm.term_of ct), Pretty.str " ::", Pretty.brk 1, 
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

398 
Syntax.pretty_typ ctxt tT])) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

399 
end 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

400 
 prep_var (_, NONE) = NONE; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

401 
val xs = vars_of tm; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

402 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

403 
align "Rule has fewer variables than instantiations given" xs ts 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

404 
> map_filter prep_var 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

405 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

406 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

407 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

408 
(* trace_rules *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

409 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

410 
fun trace_rules _ kind [] = error ("Unable to figure out " ^ kind ^ " rule") 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

411 
 trace_rules ctxt _ rules = Method.trace ctxt rules; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

412 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

413 

34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

414 
(* mark equality constraints in cases rule *) 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

415 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

416 
val equal_def' = Thm.symmetric Data.equal_def; 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

417 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

418 
fun mark_constraints n ctxt = Conv.fconv_rule 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

419 
(Conv.prems_conv (~1) (Conv.params_conv ~1 (K (Conv.prems_conv n 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

420 
(MetaSimplifier.rewrite false [equal_def']))) ctxt)); 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

421 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

422 
val unmark_constraints = Conv.fconv_rule 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

423 
(MetaSimplifier.rewrite true [Data.equal_def]); 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

424 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

425 
(* simplify *) 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

426 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

427 
fun simplify_conv' ctxt = 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

428 
Simplifier.full_rewrite (Simplifier.context ctxt (#4 (get_local ctxt))); 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

429 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

430 
fun simplify_conv ctxt ct = 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

431 
if exists_subterm (is_some o Data.dest_def) (term_of ct) then 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

432 
(Conv.try_conv (rulify_defs_conv ctxt) then_conv simplify_conv' ctxt) ct 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

433 
else Conv.all_conv ct; 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

434 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

435 
fun gen_simplified_rule cv ctxt = 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

436 
Conv.fconv_rule (Conv.prems_conv ~1 (cv ctxt)); 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

437 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

438 
val simplified_rule' = gen_simplified_rule simplify_conv'; 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

439 
val simplified_rule = gen_simplified_rule simplify_conv; 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

440 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

441 
fun simplify_tac ctxt = CONVERSION (simplify_conv ctxt); 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

442 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

443 
val trivial_tac = Data.trivial_tac; 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

444 

c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

445 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

446 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

447 
(** cases method **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

448 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

449 
(* 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

450 
rule selection scheme: 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

451 
cases  default case split 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

452 
`A t` cases ...  predicate/set cases 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

453 
cases t  type cases 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

454 
... cases ... r  explicit rule 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

455 
*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

456 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

457 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

458 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

459 
fun get_casesT ctxt ((SOME t :: _) :: _) = find_casesT ctxt (Term.fastype_of t) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

460 
 get_casesT _ _ = []; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

461 

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

462 
fun get_casesP ctxt (fact :: _) = find_casesP ctxt (Thm.concl_of fact) 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

463 
 get_casesP _ _ = []; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

464 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

465 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

466 

34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

467 
fun cases_tac ctxt simp insts opt_rule facts = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

468 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

469 
val thy = ProofContext.theory_of ctxt; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

470 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

471 
fun inst_rule r = 
34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

472 
(if null insts then r 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

473 
else (align_left "Rule has fewer premises than arguments given" (Thm.prems_of r) insts 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

474 
> maps (prep_inst ctxt align_left I) 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

475 
> Drule.cterm_instantiate) r) > 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

476 
(if simp then mark_constraints (Rule_Cases.get_constraints r) ctxt else I) > 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

477 
pair (Rule_Cases.get r); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

478 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

479 
val ruleq = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

480 
(case opt_rule of 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

481 
SOME r => Seq.single (inst_rule r) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

482 
 NONE => 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

483 
(get_casesP ctxt facts @ get_casesT ctxt insts @ [Data.cases_default]) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

484 
> tap (trace_rules ctxt casesN) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

485 
> Seq.of_list > Seq.maps (Seq.try inst_rule)); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

486 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

487 
fn i => fn st => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

488 
ruleq 
33368  489 
> Seq.maps (Rule_Cases.consume [] facts) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

490 
> Seq.maps (fn ((cases, (_, more_facts)), rule) => 
34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

491 
let val rule' = 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

492 
(if simp then simplified_rule' ctxt #> unmark_constraints else I) rule 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

493 
in 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

494 
CASES (Rule_Cases.make_common (thy, 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

495 
Thm.prop_of (Rule_Cases.internalize_params rule')) cases) 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

496 
((Method.insert_tac more_facts THEN' Tactic.rtac rule' THEN_ALL_NEW 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

497 
(if simp then TRY o trivial_tac else K all_tac)) i) st 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

498 
end) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

499 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

500 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

501 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

502 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

503 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

504 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

505 
(** induct method **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

506 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

507 
val conjunction_congs = [@{thm Pure.all_conjunction}, @{thm imp_conjunction}]; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

508 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

509 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

510 
(* atomize *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

511 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

512 
fun atomize_term thy = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

513 
MetaSimplifier.rewrite_term thy Data.atomize [] 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

514 
#> ObjectLogic.drop_judgment thy; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

515 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

516 
val atomize_cterm = MetaSimplifier.rewrite true Data.atomize; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

517 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

518 
val atomize_tac = Simplifier.rewrite_goal_tac Data.atomize; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

519 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

520 
val inner_atomize_tac = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

521 
Simplifier.rewrite_goal_tac (map Thm.symmetric conjunction_congs) THEN' atomize_tac; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

522 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

523 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

524 
(* rulify *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

525 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

526 
fun rulify_term thy = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

527 
MetaSimplifier.rewrite_term thy (Data.rulify @ conjunction_congs) [] #> 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

528 
MetaSimplifier.rewrite_term thy Data.rulify_fallback []; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

529 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

530 
fun rulified_term thm = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

531 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

532 
val thy = Thm.theory_of_thm thm; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

533 
val rulify = rulify_term thy; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

534 
val (As, B) = Logic.strip_horn (Thm.prop_of thm); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

535 
in (thy, Logic.list_implies (map rulify As, rulify B)) end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

536 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

537 
val rulify_tac = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

538 
Simplifier.rewrite_goal_tac (Data.rulify @ conjunction_congs) THEN' 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

539 
Simplifier.rewrite_goal_tac Data.rulify_fallback THEN' 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

540 
Goal.conjunction_tac THEN_ALL_NEW 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

541 
(Simplifier.rewrite_goal_tac [@{thm Pure.conjunction_imp}] THEN' Goal.norm_hhf_tac); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

542 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

543 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

544 
(* prepare rule *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

545 

32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

546 
fun rule_instance ctxt inst rule = 
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

547 
Drule.cterm_instantiate (prep_inst ctxt align_left I (Thm.prop_of rule, inst)) rule; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

548 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

549 
fun internalize k th = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

550 
th > Thm.permute_prems 0 k 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

551 
> Conv.fconv_rule (Conv.concl_conv (Thm.nprems_of th  k) atomize_cterm); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

552 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

553 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

554 
(* guess rule instantiation  cannot handle pending goal parameters *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

555 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

556 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

557 

32032  558 
fun dest_env thy env = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

559 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

560 
val cert = Thm.cterm_of thy; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

561 
val certT = Thm.ctyp_of thy; 
32032  562 
val pairs = Vartab.dest (Envir.term_env env); 
563 
val types = Vartab.dest (Envir.type_env env); 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

564 
val ts = map (cert o Envir.norm_term env o #2 o #2) pairs; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

565 
val xs = map2 (curry (cert o Var)) (map #1 pairs) (map (#T o Thm.rep_cterm) ts); 
32032  566 
in (map (fn (xi, (S, T)) => (certT (TVar (xi, S)), certT T)) types, xs ~~ ts) end; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

567 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

568 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

569 

26940  570 
fun guess_instance ctxt rule i st = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

571 
let 
26940  572 
val thy = ProofContext.theory_of ctxt; 
26626
c6231d64d264
rep_cterm/rep_thm: no longer dereference theory_ref;
wenzelm
parents:
26568
diff
changeset

573 
val maxidx = Thm.maxidx_of st; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

574 
val goal = Thm.term_of (Thm.cprem_of st i); (*exception Subscript*) 
29276  575 
val params = rev (Term.rename_wrt_term goal (Logic.strip_params goal)); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

576 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

577 
if not (null params) then 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

578 
(warning ("Cannot determine rule instantiation due to pending parameter(s): " ^ 
26940  579 
commas_quote (map (Syntax.string_of_term ctxt o Syntax.mark_boundT) params)); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

580 
Seq.single rule) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

581 
else 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

582 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

583 
val rule' = Thm.incr_indexes (maxidx + 1) rule; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

584 
val concl = Logic.strip_assums_concl goal; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

585 
in 
32032  586 
Unify.smash_unifiers thy [(Thm.concl_of rule', concl)] (Envir.empty (Thm.maxidx_of rule')) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

587 
> Seq.map (fn env => Drule.instantiate (dest_env thy env) rule') 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

588 
end 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

589 
end handle Subscript => Seq.empty; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

590 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

591 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

592 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

593 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

594 
(* special renaming of rule parameters *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

595 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

596 
fun special_rename_params ctxt [[SOME (Free (z, Type (T, _)))]] [thm] = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

597 
let 
26712
e2dcda7b0401
adapted to ProofContext.revert_skolem: extra Name.clean required;
wenzelm
parents:
26626
diff
changeset

598 
val x = Name.clean (ProofContext.revert_skolem ctxt z); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

599 
fun index i [] = [] 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

600 
 index i (y :: ys) = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

601 
if x = y then x ^ string_of_int i :: index (i + 1) ys 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

602 
else y :: index i ys; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

603 
fun rename_params [] = [] 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

604 
 rename_params ((y, Type (U, _)) :: ys) = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

605 
(if U = T then x else y) :: rename_params ys 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

606 
 rename_params ((y, _) :: ys) = y :: rename_params ys; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

607 
fun rename_asm A = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

608 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

609 
val xs = rename_params (Logic.strip_params A); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

610 
val xs' = 
28375  611 
(case filter (fn x' => x' = x) xs of 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

612 
[] => xs  [_] => xs  _ => index 1 xs); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

613 
in Logic.list_rename_params (xs', A) end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

614 
fun rename_prop p = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

615 
let val (As, C) = Logic.strip_horn p 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

616 
in Logic.list_implies (map rename_asm As, C) end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

617 
val cp' = cterm_fun rename_prop (Thm.cprop_of thm); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

618 
val thm' = Thm.equal_elim (Thm.reflexive cp') thm; 
33368  619 
in [Rule_Cases.save thm thm'] end 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

620 
 special_rename_params _ _ ths = ths; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

621 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

622 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

623 
(* fix_tac *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

624 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

625 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

626 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

627 
fun goal_prefix k ((c as Const ("all", _)) $ Abs (a, T, B)) = c $ Abs (a, T, goal_prefix k B) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

628 
 goal_prefix 0 _ = Term.dummy_pattern propT 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

629 
 goal_prefix k ((c as Const ("==>", _)) $ A $ B) = c $ A $ goal_prefix (k  1) B 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

630 
 goal_prefix _ _ = Term.dummy_pattern propT; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

631 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

632 
fun goal_params k (Const ("all", _) $ Abs (_, _, B)) = goal_params k B + 1 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

633 
 goal_params 0 _ = 0 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

634 
 goal_params k (Const ("==>", _) $ _ $ B) = goal_params (k  1) B 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

635 
 goal_params _ _ = 0; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

636 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

637 
fun meta_spec_tac ctxt n (x, T) = SUBGOAL (fn (goal, i) => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

638 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

639 
val thy = ProofContext.theory_of ctxt; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

640 
val cert = Thm.cterm_of thy; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

641 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

642 
val v = Free (x, T); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

643 
fun spec_rule prfx (xs, body) = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

644 
@{thm Pure.meta_spec} 
26712
e2dcda7b0401
adapted to ProofContext.revert_skolem: extra Name.clean required;
wenzelm
parents:
26626
diff
changeset

645 
> Thm.rename_params_rule ([Name.clean (ProofContext.revert_skolem ctxt x)], 1) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

646 
> Thm.lift_rule (cert prfx) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

647 
> `(Thm.prop_of #> Logic.strip_assums_concl) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

648 
> (fn pred $ arg => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

649 
Drule.cterm_instantiate 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

650 
[(cert (Term.head_of pred), cert (Logic.rlist_abs (xs, body))), 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

651 
(cert (Term.head_of arg), cert (Logic.rlist_abs (xs, v)))]); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

652 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

653 
fun goal_concl k xs (Const ("all", _) $ Abs (a, T, B)) = goal_concl k ((a, T) :: xs) B 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

654 
 goal_concl 0 xs B = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

655 
if not (Term.exists_subterm (fn t => t aconv v) B) then NONE 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

656 
else SOME (xs, Term.absfree (x, T, Term.incr_boundvars 1 B)) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

657 
 goal_concl k xs (Const ("==>", _) $ _ $ B) = goal_concl (k  1) xs B 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

658 
 goal_concl _ _ _ = NONE; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

659 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

660 
(case goal_concl n [] goal of 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

661 
SOME concl => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

662 
(compose_tac (false, spec_rule (goal_prefix n goal) concl, 1) THEN' rtac asm_rl) i 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

663 
 NONE => all_tac) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

664 
end); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

665 

24832  666 
fun miniscope_tac p = CONVERSION o 
26568  667 
Conv.params_conv p (K (MetaSimplifier.rewrite true [Thm.symmetric Drule.norm_hhf_eq])); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

668 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

669 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

670 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

671 
fun fix_tac _ _ [] = K all_tac 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

672 
 fix_tac ctxt n xs = SUBGOAL (fn (goal, i) => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

673 
(EVERY' (map (meta_spec_tac ctxt n) xs) THEN' 
24832  674 
(miniscope_tac (goal_params n goal) ctxt)) i); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

675 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

676 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

677 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

678 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

679 
(* add_defs *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

680 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

681 
fun add_defs def_insts = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

682 
let 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

683 
fun add (SOME (_, (t, true))) ctxt = ((SOME t, []), ctxt) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

684 
 add (SOME (SOME x, (t, _))) ctxt = 
28083
103d9282a946
explicit type Name.binding for higherspecification elements;
wenzelm
parents:
27865
diff
changeset

685 
let val ([(lhs, (_, th))], ctxt') = 
30211  686 
LocalDefs.add_defs [((x, NoSyn), (Thm.empty_binding, t))] ctxt 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

687 
in ((SOME lhs, [th]), ctxt') end 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

688 
 add (SOME (NONE, (t as Free _, _))) ctxt = ((SOME t, []), ctxt) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

689 
 add (SOME (NONE, (t, _))) ctxt = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

690 
let 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

691 
val ([s], _) = Name.variants ["x"] (Variable.names_of ctxt); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

692 
val ([(lhs, (_, th))], ctxt') = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

693 
LocalDefs.add_defs [((Binding.name s, NoSyn), 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

694 
(Thm.empty_binding, t))] ctxt 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

695 
in ((SOME lhs, [th]), ctxt') end 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

696 
 add NONE ctxt = ((NONE, []), ctxt); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

697 
in fold_map add def_insts #> apfst (split_list #> apsnd flat) end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

698 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

699 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

700 
(* induct_tac *) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

701 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

702 
(* 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

703 
rule selection scheme: 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

704 
`A x` induct ...  predicate/set induction 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

705 
induct x  type induction 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

706 
... induct ... r  explicit rule 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

707 
*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

708 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

709 
fun get_inductT ctxt insts = 
32188  710 
fold_rev (map_product cons) (insts > map 
27323
385c0ce33173
tuned get_inductT: *all* rules for missing instantiation;
wenzelm
parents:
27140
diff
changeset

711 
((fn [] => NONE  ts => List.last ts) #> 
385c0ce33173
tuned get_inductT: *all* rules for missing instantiation;
wenzelm
parents:
27140
diff
changeset

712 
(fn NONE => TVar (("'a", 0), [])  SOME t => Term.fastype_of t) #> 
385c0ce33173
tuned get_inductT: *all* rules for missing instantiation;
wenzelm
parents:
27140
diff
changeset

713 
find_inductT ctxt)) [[]] 
33368  714 
> filter_out (forall Rule_Cases.is_inner_rule); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

715 

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

716 
fun get_inductP ctxt (fact :: _) = map single (find_inductP ctxt (Thm.concl_of fact)) 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

717 
 get_inductP _ _ = []; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

718 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

719 
fun induct_tac ctxt simp def_insts arbitrary taking opt_rule facts = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

720 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

721 
val thy = ProofContext.theory_of ctxt; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

722 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

723 
val ((insts, defs), defs_ctxt) = fold_map add_defs def_insts ctxt >> split_list; 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

724 
val atomized_defs = map (map (Conv.fconv_rule atomize_cterm)) defs; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

725 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

726 
fun inst_rule (concls, r) = 
33368  727 
(if null insts then `Rule_Cases.get r 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

728 
else (align_left "Rule has fewer conclusions than arguments given" 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

729 
(map Logic.strip_imp_concl (Logic.dest_conjunctions (Thm.concl_of r))) insts 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

730 
> maps (prep_inst ctxt align_right (atomize_term thy)) 
33368  731 
> Drule.cterm_instantiate) r > pair (Rule_Cases.get r)) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

732 
> (fn ((cases, consumes), th) => (((cases, concls), consumes), th)); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

733 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

734 
val ruleq = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

735 
(case opt_rule of 
33368  736 
SOME rs => Seq.single (inst_rule (Rule_Cases.strict_mutual_rule ctxt rs)) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

737 
 NONE => 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

738 
(get_inductP ctxt facts @ 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

739 
map (special_rename_params defs_ctxt insts) (get_inductT ctxt insts)) 
33368  740 
> map_filter (Rule_Cases.mutual_rule ctxt) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

741 
> tap (trace_rules ctxt inductN o map #2) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

742 
> Seq.of_list > Seq.maps (Seq.try inst_rule)); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

743 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

744 
fun rule_cases ctxt rule = 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

745 
let val rule' = (if simp then simplified_rule ctxt else I) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

746 
(Rule_Cases.internalize_params rule); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

747 
in Rule_Cases.make_nested (Thm.prop_of rule') (rulified_term rule') end; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

748 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

749 
(fn i => fn st => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

750 
ruleq 
33368  751 
> Seq.maps (Rule_Cases.consume (flat defs) facts) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

752 
> Seq.maps (fn (((cases, concls), (more_consumes, more_facts)), rule) => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

753 
(PRECISE_CONJUNCTS (length concls) (ALLGOALS (fn j => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

754 
(CONJUNCTS (ALLGOALS 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

755 
let 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

756 
val adefs = nth_list atomized_defs (j  1); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

757 
val frees = fold (Term.add_frees o prop_of) adefs []; 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

758 
val xs = nth_list arbitrary (j  1); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

759 
val k = nth concls (j  1) + more_consumes 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

760 
in 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

761 
Method.insert_tac (more_facts @ adefs) THEN' 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

762 
(if simp then 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

763 
rotate_tac k (length adefs) THEN' 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

764 
fix_tac defs_ctxt k 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

765 
(List.partition (member op = frees) xs > op @) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

766 
else 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

767 
fix_tac defs_ctxt k xs) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

768 
end) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

769 
THEN' inner_atomize_tac) j)) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

770 
THEN' atomize_tac) i st > Seq.maps (fn st' => 
26940  771 
guess_instance ctxt (internalize more_consumes rule) i st' 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

772 
> Seq.map (rule_instance ctxt (burrow_options (Variable.polymorphic ctxt) taking)) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

773 
> Seq.maps (fn rule' => 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

774 
CASES (rule_cases ctxt rule' cases) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

775 
(Tactic.rtac rule' i THEN 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

776 
PRIMITIVE (singleton (ProofContext.export defs_ctxt ctxt))) st')))) 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

777 
THEN_ALL_NEW_CASES 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

778 
((if simp then simplify_tac ctxt THEN' (TRY o trivial_tac) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

779 
else K all_tac) 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

780 
THEN_ALL_NEW rulify_tac) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

781 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

782 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

783 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

784 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

785 
(** coinduct method **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

786 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

787 
(* 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

788 
rule selection scheme: 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

789 
goal "A x" coinduct ...  predicate/set coinduction 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

790 
coinduct x  type coinduction 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

791 
coinduct ... r  explicit rule 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

792 
*) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

793 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

794 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

795 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

796 
fun get_coinductT ctxt (SOME t :: _) = find_coinductT ctxt (Term.fastype_of t) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

797 
 get_coinductT _ _ = []; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

798 

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

799 
fun get_coinductP ctxt goal = find_coinductP ctxt (Logic.strip_assums_concl goal); 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

800 

cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

801 
fun main_prop_of th = 
33368  802 
if Rule_Cases.get_consumes th > 0 then Thm.major_prem_of th else Thm.concl_of th; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

803 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

804 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

805 

26924  806 
fun coinduct_tac ctxt inst taking opt_rule facts = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

807 
let 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

808 
val thy = ProofContext.theory_of ctxt; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

809 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

810 
fun inst_rule r = 
33368  811 
if null inst then `Rule_Cases.get r 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

812 
else Drule.cterm_instantiate (prep_inst ctxt align_right I (main_prop_of r, inst)) r 
33368  813 
> pair (Rule_Cases.get r); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

814 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

815 
fun ruleq goal = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

816 
(case opt_rule of 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

817 
SOME r => Seq.single (inst_rule r) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

818 
 NONE => 
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

819 
(get_coinductP ctxt goal @ get_coinductT ctxt inst) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

820 
> tap (trace_rules ctxt coinductN) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

821 
> Seq.of_list > Seq.maps (Seq.try inst_rule)); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

822 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

823 
SUBGOAL_CASES (fn (goal, i) => fn st => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

824 
ruleq goal 
33368  825 
> Seq.maps (Rule_Cases.consume [] facts) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

826 
> Seq.maps (fn ((cases, (_, more_facts)), rule) => 
26940  827 
guess_instance ctxt rule i st 
32432
64f30bdd3ba1
modernized messages  eliminated ctyp/cterm operations;
wenzelm
parents:
32188
diff
changeset

828 
> Seq.map (rule_instance ctxt (burrow_options (Variable.polymorphic ctxt) taking)) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

829 
> Seq.maps (fn rule' => 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

830 
CASES (Rule_Cases.make_common (thy, 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

831 
Thm.prop_of (Rule_Cases.internalize_params rule')) cases) 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

832 
(Method.insert_tac more_facts i THEN Tactic.rtac rule' i) st))) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

833 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

834 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

835 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

836 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

837 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

838 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

839 
(** concrete syntax **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

840 

27809
a1e409db516b
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27370
diff
changeset

841 
structure P = OuterParse; 
a1e409db516b
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27370
diff
changeset

842 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

843 
val arbitraryN = "arbitrary"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

844 
val takingN = "taking"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

845 
val ruleN = "rule"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

846 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

847 
local 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

848 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

849 
fun single_rule [rule] = rule 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

850 
 single_rule _ = error "Single rule expected"; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

851 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

852 
fun named_rule k arg get = 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

853 
Scan.lift (Args.$$$ k  Args.colon)  Scan.repeat arg : 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

854 
(fn names => Scan.peek (fn context => Scan.succeed (names > map (fn name => 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

855 
(case get (Context.proof_of context) name of SOME x => x 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

856 
 NONE => error ("No rule for " ^ k ^ " " ^ quote name)))))); 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

857 

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

858 
fun rule get_type get_pred = 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

859 
named_rule typeN Args.tyname get_type  
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

860 
named_rule predN Args.const get_pred  
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

861 
named_rule setN Args.const get_pred  
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

862 
Scan.lift (Args.$$$ ruleN  Args.colon)  Attrib.thms; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

863 

24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

864 
val cases_rule = rule lookup_casesT lookup_casesP >> single_rule; 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

865 
val induct_rule = rule lookup_inductT lookup_inductP; 
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

866 
val coinduct_rule = rule lookup_coinductT lookup_coinductP >> single_rule; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

867 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

868 
val inst = Scan.lift (Args.$$$ "_") >> K NONE  Args.term >> SOME; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

869 

34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

870 
val inst' = Scan.lift (Args.$$$ "_") >> K NONE  
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

871 
Args.term >> (SOME o rpair false)  
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

872 
Scan.lift (Args.$$$ "(")  (Args.term >> (SOME o rpair true))  
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

873 
Scan.lift (Args.$$$ ")"); 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

874 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

875 
val def_inst = 
28083
103d9282a946
explicit type Name.binding for higherspecification elements;
wenzelm
parents:
27865
diff
changeset

876 
((Scan.lift (Args.binding  (Args.$$$ "\<equiv>"  Args.$$$ "==")) >> SOME) 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

877 
 (Args.term >> rpair false)) >> SOME  
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

878 
inst' >> Option.map (pair NONE); 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

879 

27370  880 
val free = Args.context  Args.term >> (fn (_, Free v) => v  (ctxt, t) => 
881 
error ("Bad free variable: " ^ Syntax.string_of_term ctxt t)); 

24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

882 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

883 
fun unless_more_args scan = Scan.unless (Scan.lift 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

884 
((Args.$$$ arbitraryN  Args.$$$ takingN  Args.$$$ typeN  
24861
cc669ca5f382
tuned Induct interface: prefer pred'' over set'';
wenzelm
parents:
24832
diff
changeset

885 
Args.$$$ predN  Args.$$$ setN  Args.$$$ ruleN)  Args.colon)) scan; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

886 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

887 
val arbitrary = Scan.optional (Scan.lift (Args.$$$ arbitraryN  Args.colon)  
27809
a1e409db516b
unified Args.T with OuterLex.token, renamed some operations;
wenzelm
parents:
27370
diff
changeset

888 
P.and_list1' (Scan.repeat (unless_more_args free))) []; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

889 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

890 
val taking = Scan.optional (Scan.lift (Args.$$$ takingN  Args.colon)  
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

891 
Scan.repeat1 (unless_more_args inst)) []; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

892 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

893 
in 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

894 

30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

895 
val cases_setup = 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

896 
Method.setup @{binding cases} 
34987
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

897 
(Args.mode no_simpN  
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

898 
(P.and_list' (Scan.repeat (unless_more_args inst))  Scan.option cases_rule) >> 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

899 
(fn (no_simp, (insts, opt_rule)) => fn ctxt => 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

900 
METHOD_CASES (fn facts => Seq.DETERM (HEADGOAL 
c1e8af37ee75
Added infrastructure for simplifying equality constraints in cases rules.
berghofe
parents:
34907
diff
changeset

901 
(cases_tac ctxt (not no_simp) insts opt_rule facts))))) 
30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

902 
"case analysis on types or predicates/sets"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

903 

30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

904 
val induct_setup = 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

905 
Method.setup @{binding induct} 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

906 
(Args.mode no_simpN  (P.and_list' (Scan.repeat (unless_more_args def_inst))  
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

907 
(arbitrary  taking  Scan.option induct_rule)) >> 
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

908 
(fn (no_simp, (insts, ((arbitrary, taking), opt_rule))) => fn ctxt => 
30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

909 
RAW_METHOD_CASES (fn facts => 
34907
b0aaec87751c
Added infrastructure for simplifying equality constraints.
berghofe
parents:
33957
diff
changeset

910 
Seq.DETERM (HEADGOAL (induct_tac ctxt (not no_simp) insts arbitrary taking opt_rule facts))))) 
30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

911 
"induction on types or predicates/sets"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

912 

30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

913 
val coinduct_setup = 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

914 
Method.setup @{binding coinduct} 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

915 
(Scan.repeat (unless_more_args inst)  taking  Scan.option coinduct_rule >> 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

916 
(fn ((insts, taking), opt_rule) => fn ctxt => 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

917 
RAW_METHOD_CASES (fn facts => 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

918 
Seq.DETERM (HEADGOAL (coinduct_tac ctxt insts taking opt_rule facts))))) 
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

919 
"coinduction on types or predicates/sets"; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

920 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

921 
end; 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

922 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

923 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

924 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

925 
(** theory setup **) 
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

926 

30722
623d4831c8cf
simplified attribute and method setup: eliminating bottomup styles makes it easier to keep things in one place, and also SML/NJ happy;
wenzelm
parents:
30560
diff
changeset

927 
val setup = attrib_setup #> cases_setup #> induct_setup #> coinduct_setup; 
24830
a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

928 

a7b3ab44d993
moved Pure/Isar/induct_attrib.ML and Provers/induct_method.ML to Tools/induct.ML;
wenzelm
parents:
diff
changeset

929 
end; 