src/ZF/indrule.ML
author paulson
Fri, 22 Dec 1995 11:09:28 +0100
changeset 1418 f5f97ee67cbb
parent 1104 141f73abbafc
child 1461 6bcb44e4d6e5
permissions -rw-r--r--
Improving space efficiency of inductive/datatype definitions. Reduce usage of "open" and change struct open X; D end to let open X in struct D end end whenever possible -- removes X from the final structure. Especially needed for functors Intr_elim and Indrule. intr_elim.ML and constructor.ML now use a common Su.free_SEs instead of generating a new one. Inductive defs no longer export sumprod_free_SEs ZF/intr_elim: Removed unfold:thm from signature INTR_ELIM. It is never used outside, is easily recovered using bnd_mono and def_lfp_Tarski, and takes up considerable store. Moved raw_induct and rec_names to separate signature INTR_ELIM_AUX, for items no longer exported. mutual_induct is simply "True" unless it is going to be significantly different from induct -- either because there is mutual recursion or because it involves tuples.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/indrule.ML
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
     4
    Copyright   1994  University of Cambridge
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     6
Induction rule module -- for Inductive/Coinductive Definitions
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     8
Proves a strong induction rule and a mutual induction rule
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     9
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
signature INDRULE =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
  sig
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
  val induct        : thm			(*main induction rule*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
  val mutual_induct : thm			(*mutual induction rule*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    15
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    16
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    18
functor Indrule_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    19
    (structure Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    20
     and Pr: PR and Su : SU and 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    21
     Intr_elim: sig include INTR_ELIM INTR_ELIM_AUX end) : INDRULE  =
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    22
let
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    23
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    24
val sign = sign_of Inductive.thy;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    26
val (Const(_,recT),rec_params) = strip_comb (hd Inductive.rec_tms);
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    27
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    28
val big_rec_name = space_implode "_" Intr_elim.rec_names;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    29
val big_rec_tm = list_comb(Const(big_rec_name,recT), rec_params);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 366
diff changeset
    30
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
    31
val _ = writeln "  Proving the induction rule...";
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
(*** Prove the main induction rule ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
val pred_name = "P";		(*name for predicate variables*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
val big_rec_def::part_rec_defs = Intr_elim.defs;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
(*Used to make induction rules;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
   ind_alist = [(rec_tm1,pred1),...]  -- associates predicates with rec ops
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
   prem is a premise of an intr rule*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
fun add_induct_prem ind_alist (prem as Const("Trueprop",_) $ 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
		 (Const("op :",_)$t$X), iprems) =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
     (case gen_assoc (op aconv) (ind_alist, X) of
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    45
	  Some pred => prem :: Ind_Syntax.mk_tprop (pred $ t) :: iprems
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
	| None => (*possibly membership in M(rec_tm), for M monotone*)
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    47
	    let fun mk_sb (rec_tm,pred) = 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    48
			(rec_tm, Ind_Syntax.Collect_const$rec_tm$pred)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
	    in  subst_free (map mk_sb ind_alist) prem :: iprems  end)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
  | add_induct_prem ind_alist (prem,iprems) = prem :: iprems;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
(*Make a premise of the induction rule.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    53
fun induct_prem ind_alist intr =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
  let val quantfrees = map dest_Free (term_frees intr \\ rec_params)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    55
      val iprems = foldr (add_induct_prem ind_alist)
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    56
			 (Logic.strip_imp_prems intr,[])
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    57
      val (t,X) = Ind_Syntax.rule_concl intr
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
      val (Some pred) = gen_assoc (op aconv) (ind_alist, X)
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    59
      val concl = Ind_Syntax.mk_tprop (pred $ t)
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    60
  in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
  handle Bind => error"Recursion term not found in conclusion";
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    62
633
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
    63
(*Reduces backtracking by delivering the correct premise to each goal.
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
    64
  Intro rules with extra Vars in premises still cause some backtracking *)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
fun ind_tac [] 0 = all_tac
633
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
    66
  | ind_tac(prem::prems) i = 
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
    67
    	DEPTH_SOLVE_1 (ares_tac [prem, refl] i) THEN
633
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
    68
	ind_tac prems (i-1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    69
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    70
val pred = Free(pred_name, Ind_Syntax.iT --> Ind_Syntax.oT);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    71
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    72
val ind_prems = map (induct_prem (map (rpair pred) Inductive.rec_tms)) 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    73
                    Inductive.intr_tms;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    74
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    75
val quant_induct = 
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    76
    prove_goalw_cterm part_rec_defs 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    77
      (cterm_of sign 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    78
       (Logic.list_implies (ind_prems, 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    79
		Ind_Syntax.mk_tprop (Ind_Syntax.mk_all_imp(big_rec_tm,pred)))))
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
    80
      (fn prems =>
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    81
       [rtac (impI RS allI) 1,
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    82
	DETERM (etac Intr_elim.raw_induct 1),
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
    83
	(*Push Part inside Collect*)
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
    84
	asm_full_simp_tac (FOL_ss addsimps [Part_Collect]) 1,
590
800603278425 {HOL,ZF}/indrule/quant_induct: replaced ssubst in eresolve_tac by
lcp
parents: 543
diff changeset
    85
	REPEAT (FIRSTGOAL (eresolve_tac [CollectE, exE, conjE, disjE] ORELSE'
800603278425 {HOL,ZF}/indrule/quant_induct: replaced ssubst in eresolve_tac by
lcp
parents: 543
diff changeset
    86
			   hyp_subst_tac)),
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    87
	ind_tac (rev prems) (length prems) ]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    88
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    89
(*** Prove the simultaneous induction rule ***)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    90
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    91
(*Make distinct predicates for each inductive set*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    92
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    93
(*Sigmas and Cartesian products may nest ONLY to the right!*)
366
5b6e4340085b ZF/indrule/mk_pred_typ: corrected pattern to include Abs, allowing it to
lcp
parents: 0
diff changeset
    94
fun mk_pred_typ (t $ A $ Abs(_,_,B)) = 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    95
        if t = Pr.sigma  then  Ind_Syntax.iT --> mk_pred_typ B
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    96
                         else  Ind_Syntax.iT --> Ind_Syntax.oT
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    97
  | mk_pred_typ _           =  Ind_Syntax.iT --> Ind_Syntax.oT
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    98
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
    99
(*For testing whether the inductive set is a relation*)
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   100
fun is_sigma (t$_$_) = (t = Pr.sigma)
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   101
  | is_sigma _       =  false;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   102
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   103
(*Given a recursive set and its domain, return the "fsplit" predicate
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   104
  and a conclusion for the simultaneous induction rule.
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   105
  NOTE.  This will not work for mutually recursive predicates.  Previously
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   106
  a summand 'domt' was also an argument, but this required the domain of
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   107
  mutual recursion to invariably be a disjoint sum.*)
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   108
fun mk_predpair rec_tm = 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   109
  let val rec_name = (#1 o dest_Const o head_of) rec_tm
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   110
      val T = mk_pred_typ Inductive.dom_sum
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   111
      val pfree = Free(pred_name ^ "_" ^ rec_name, T)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   112
      val frees = mk_frees "za" (binder_types T)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   113
      val qconcl = 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   114
	foldr Ind_Syntax.mk_all (frees, 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   115
	                Ind_Syntax.imp $ 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   116
			  (Ind_Syntax.mem_const $ foldr1 (app Pr.pair) frees $
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   117
			   rec_tm)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   118
			  $ (list_comb (pfree,frees)))
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   119
  in  (Ind_Syntax.ap_split Pr.fsplit_const pfree (binder_types T), 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   120
      qconcl)  
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   121
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   122
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   123
val (preds,qconcls) = split_list (map mk_predpair Inductive.rec_tms);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   124
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   125
(*Used to form simultaneous induction lemma*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   126
fun mk_rec_imp (rec_tm,pred) = 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   127
    Ind_Syntax.imp $ (Ind_Syntax.mem_const $ Bound 0 $ rec_tm) $ 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   128
                     (pred $ Bound 0);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   129
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   130
(*To instantiate the main induction rule*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   131
val induct_concl = 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   132
 Ind_Syntax.mk_tprop(Ind_Syntax.mk_all_imp(big_rec_tm,
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   133
	     Abs("z", Ind_Syntax.iT, 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   134
		 fold_bal (app Ind_Syntax.conj) 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   135
		 (map mk_rec_imp (Inductive.rec_tms~~preds)))))
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   136
and mutual_induct_concl =
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   137
 Ind_Syntax.mk_tprop(fold_bal (app Ind_Syntax.conj) qconcls);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   138
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   139
val lemma = (*makes the link between the two induction rules*)
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
   140
    prove_goalw_cterm part_rec_defs 
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   141
	  (cterm_of sign (Logic.mk_implies (induct_concl,mutual_induct_concl)))
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
   142
	  (fn prems =>
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   143
	   [cut_facts_tac prems 1, 
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   144
	    REPEAT (eresolve_tac [asm_rl, conjE, PartE, mp] 1
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   145
	     ORELSE resolve_tac [allI, impI, conjI, Part_eqI] 1
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   146
	     ORELSE dresolve_tac [spec, mp, Pr.fsplitD] 1)]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   147
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   148
(*Mutual induction follows by freeness of Inl/Inr.*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   149
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   150
(*Simplification largely reduces the mutual induction rule to the 
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   151
  standard rule*)
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   152
val mut_ss = 
751
f0aacbcedb77 ZF/indrule/mutual_ind_tac: ensured that asm_full_simp_tac ignores any
lcp
parents: 724
diff changeset
   153
    FOL_ss addsimps   [Su.distinct, Su.distinct', Su.inl_iff, Su.inr_iff];
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   154
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   155
val all_defs = Inductive.con_defs @ part_rec_defs;
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   156
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   157
(*Removes Collects caused by M-operators in the intro rules.  It is very
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   158
  hard to simplify
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   159
    list({v: tf. (v : t --> P_t(v)) & (v : f --> P_f(v))}) 
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   160
  where t==Part(tf,Inl) and f==Part(tf,Inr) to  list({v: tf. P_t(v)}).
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   161
  Instead the following rules extract the relevant conjunct.
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   162
*)
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   163
val cmonos = [subset_refl RS Collect_mono] RL Inductive.monos RLN (2,[rev_subsetD]);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   164
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   165
(*Avoids backtracking by delivering the correct premise to each goal*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   166
fun mutual_ind_tac [] 0 = all_tac
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   167
  | mutual_ind_tac(prem::prems) i = 
633
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
   168
      DETERM
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
   169
       (SELECT_GOAL 
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   170
	  (
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   171
	   (*Simplify the assumptions and goal by unfolding Part and
751
f0aacbcedb77 ZF/indrule/mutual_ind_tac: ensured that asm_full_simp_tac ignores any
lcp
parents: 724
diff changeset
   172
	     using freeness of the Sum constructors; proves all but one
f0aacbcedb77 ZF/indrule/mutual_ind_tac: ensured that asm_full_simp_tac ignores any
lcp
parents: 724
diff changeset
   173
             conjunct by contradiction*)
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   174
	   rewrite_goals_tac all_defs  THEN
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   175
	   simp_tac (mut_ss addsimps [Part_iff]) 1  THEN
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   176
	   IF_UNSOLVED (*simp_tac may have finished it off!*)
751
f0aacbcedb77 ZF/indrule/mutual_ind_tac: ensured that asm_full_simp_tac ignores any
lcp
parents: 724
diff changeset
   177
	     ((*simplify assumptions, but don't accept new rewrite rules!*)
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   178
	      asm_full_simp_tac (mut_ss setmksimps (fn _=>[])) 1  THEN
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   179
	      (*unpackage and use "prem" in the corresponding place*)
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   180
	      REPEAT (rtac impI 1)  THEN
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   181
	      rtac (rewrite_rule all_defs prem) 1  THEN
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   182
	      (*prem must not be REPEATed below: could loop!*)
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   183
	      DEPTH_SOLVE (FIRSTGOAL (ares_tac [impI] ORELSE' 
751
f0aacbcedb77 ZF/indrule/mutual_ind_tac: ensured that asm_full_simp_tac ignores any
lcp
parents: 724
diff changeset
   184
				      eresolve_tac (conjE::mp::cmonos))))
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   185
	  ) i)
633
9e4d4f3eb812 {HOL,ZF}/indrule/ind_tac: now calls DEPTH_SOLVE_1 instead of REPEAT, to
lcp
parents: 590
diff changeset
   186
       THEN mutual_ind_tac prems (i-1);
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   187
724
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   188
val _ = writeln "  Proving the mutual induction rule...";
36c0ac2f4935 ZF/indrule/mutual_ind_tac: backtracks using DEPTH_SOLVE to be certain of
lcp
parents: 633
diff changeset
   189
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   190
val mutual_induct_fsplit = 
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
   191
    prove_goalw_cterm []
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
   192
	  (cterm_of sign
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   193
	   (Logic.list_implies 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   194
	      (map (induct_prem (Inductive.rec_tms~~preds)) Inductive.intr_tms,
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   195
	       mutual_induct_concl)))
543
e961b2092869 ZF/ind_syntax/unvarifyT, unvarify: moved to Pure/logic.ML
lcp
parents: 516
diff changeset
   196
	  (fn prems =>
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   197
	   [rtac (quant_induct RS lemma) 1,
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   198
	    mutual_ind_tac (rev prems) (length prems)]);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   199
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   200
(*Attempts to remove all occurrences of fsplit*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   201
val fsplit_tac =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   202
    REPEAT (SOMEGOAL (FIRST' [rtac Pr.fsplitI, 
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   203
			      dtac Pr.fsplitD,
1104
141f73abbafc Changed to use split instead of fsplit. The weakening of fsplitE appears not
lcp
parents: 751
diff changeset
   204
			      etac Pr.fsplitE,	(*apparently never used!*)
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   205
			      bound_hyp_subst_tac]))
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   206
    THEN prune_params_tac
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   207
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   208
in
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   209
  struct
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   210
  (*strip quantifier*)
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   211
  val induct = standard (quant_induct RS spec RSN (2,rev_mp));
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   212
1418
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   213
  (*Just "True" unless significantly different from induct, with mutual
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   214
    recursion or because it involves tuples.  This saves storage.*)
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   215
  val mutual_induct = 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   216
      if length Intr_elim.rec_names > 1 orelse
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   217
	 is_sigma Inductive.dom_sum 
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   218
      then rule_by_tactic fsplit_tac mutual_induct_fsplit
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   219
      else TrueI;
f5f97ee67cbb Improving space efficiency of inductive/datatype definitions.
paulson
parents: 1104
diff changeset
   220
  end
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
   221
end;