src/HOL/indrule.ML
author nipkow
Thu, 11 Apr 1996 08:30:25 +0200
changeset 1655 5be64540f275
parent 1653 1a2ffa2fbf7d
child 1728 01beef6262aa
permissions -rw-r--r--
Added a number of lemmas
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
     1
(*  Title:      HOL/indrule.ML
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     2
    ID:         $Id$
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
     3
    Author:     Lawrence C Paulson, Cambridge University Computer Laboratory
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     4
    Copyright   1994  University of Cambridge
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     5
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     6
Induction rule module -- for Inductive/Coinductive Definitions
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     7
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     8
Proves a strong induction rule and a mutual induction rule
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
     9
*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    10
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    11
signature INDRULE =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    12
  sig
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    13
  val induct        : thm                       (*main induction rule*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    14
  val mutual_induct : thm                       (*mutual induction rule*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    15
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    16
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    17
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    18
functor Indrule_Fun
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    19
    (structure Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end and
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    20
         Intr_elim: sig include INTR_ELIM INTR_ELIM_AUX end) : INDRULE  =
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    21
let
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    22
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    23
val sign = sign_of Inductive.thy;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    24
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    25
val (Const(_,recT),rec_params) = strip_comb (hd Inductive.rec_tms);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    26
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    27
val elem_type = Ind_Syntax.dest_setT (body_type recT);
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    28
val big_rec_name = space_implode "_" Intr_elim.rec_names;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    29
val big_rec_tm = list_comb(Const(big_rec_name,recT), rec_params);
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    30
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    31
val _ = writeln "  Proving the induction rule...";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    32
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    33
(*** Prove the main induction rule ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    34
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    35
val pred_name = "P";            (*name for predicate variables*)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    36
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    37
val big_rec_def::part_rec_defs = Intr_elim.defs;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    38
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    39
(*Used to express induction rules: adds induction hypotheses.
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    40
   ind_alist = [(rec_tm1,pred1),...]  -- associates predicates with rec ops
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    41
   prem is a premise of an intr rule*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    42
fun add_induct_prem ind_alist (prem as Const("Trueprop",_) $ 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    43
                 (Const("op :",_)$t$X), iprems) =
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    44
     (case gen_assoc (op aconv) (ind_alist, X) of
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    45
          Some pred => prem :: Ind_Syntax.mk_Trueprop (pred $ t) :: iprems
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    46
        | None => (*possibly membership in M(rec_tm), for M monotone*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    47
            let fun mk_sb (rec_tm,pred) = 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    48
                 (case binder_types (fastype_of pred) of
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    49
                      [T] => (rec_tm, 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    50
                              Ind_Syntax.Int_const T $ rec_tm $ 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    51
                                (Ind_Syntax.Collect_const T $ pred))
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    52
                    | _ => error 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    53
                      "Bug: add_induct_prem called with non-unary predicate")
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    54
            in  subst_free (map mk_sb ind_alist) prem :: iprems  end)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    55
  | add_induct_prem ind_alist (prem,iprems) = prem :: iprems;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    56
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    57
(*Make a premise of the induction rule.*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    58
fun induct_prem ind_alist intr =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    59
  let val quantfrees = map dest_Free (term_frees intr \\ rec_params)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    60
      val iprems = foldr (add_induct_prem ind_alist)
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    61
                         (Logic.strip_imp_prems intr,[])
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    62
      val (t,X) = Ind_Syntax.rule_concl intr
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    63
      val (Some pred) = gen_assoc (op aconv) (ind_alist, X)
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    64
      val concl = Ind_Syntax.mk_Trueprop (pred $ t)
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    65
  in list_all_free (quantfrees, Logic.list_implies (iprems,concl)) end
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    66
  handle Bind => error"Recursion term not found in conclusion";
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    67
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    68
(*Avoids backtracking by delivering the correct premise to each goal*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    69
fun ind_tac [] 0 = all_tac
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    70
  | ind_tac(prem::prems) i = 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    71
        DEPTH_SOLVE_1 (ares_tac [Part_eqI, prem, refl] i) THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    72
        ind_tac prems (i-1);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    73
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    74
val pred = Free(pred_name, elem_type --> Ind_Syntax.boolT);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    75
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    76
val ind_prems = map (induct_prem (map (rpair pred) Inductive.rec_tms)) 
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    77
                    Inductive.intr_tms;
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    78
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    79
(*Debugging code...
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    80
val _ = writeln "ind_prems = ";
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    81
val _ = seq (writeln o Sign.string_of_term sign) ind_prems;
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    82
*)
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
    83
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    84
val quant_induct = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    85
    prove_goalw_cterm part_rec_defs 
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    86
      (cterm_of sign 
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
    87
       (Logic.list_implies (ind_prems, 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    88
                            Ind_Syntax.mk_Trueprop (Ind_Syntax.mk_all_imp 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    89
                                                    (big_rec_tm,pred)))))
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    90
      (fn prems =>
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    91
       [rtac (impI RS allI) 1,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    92
        DETERM (etac Intr_elim.raw_induct 1),
1653
1a2ffa2fbf7d Replaced !simpset by HOL_ss on line 93.
nipkow
parents: 1465
diff changeset
    93
        asm_full_simp_tac (HOL_ss addsimps [Part_Collect]) 1,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    94
        REPEAT (FIRSTGOAL (eresolve_tac [IntE, CollectE, exE, conjE, disjE] 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    95
                           ORELSE' hyp_subst_tac)),
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
    96
        ind_tac (rev prems) (length prems)])
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    97
    handle e => print_sign_exn sign e;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    98
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
    99
(*** Prove the simultaneous induction rule ***)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   100
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   101
(*Make distinct predicates for each inductive set.
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   102
  Splits cartesian products in elem_type, IF nested to the right! *)
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   103
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   104
(*Given a recursive set, return the "split" predicate
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   105
  and a conclusion for the simultaneous induction rule*)
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   106
fun mk_predpair rec_tm = 
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   107
  let val rec_name = (#1 o dest_Const o head_of) rec_tm
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   108
      val T = Ind_Syntax.factors elem_type ---> Ind_Syntax.boolT
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   109
      val pfree = Free(pred_name ^ "_" ^ rec_name, T)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   110
      val frees = mk_frees "za" (binder_types T)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   111
      val qconcl = 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   112
        foldr Ind_Syntax.mk_all 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   113
          (frees, 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   114
           Ind_Syntax.imp $ (Ind_Syntax.mk_mem 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   115
                             (foldr1 Ind_Syntax.mk_Pair frees, rec_tm))
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   116
                $ (list_comb (pfree,frees)))
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   117
  in  (Ind_Syntax.ap_split Ind_Syntax.boolT pfree (binder_types T), 
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   118
      qconcl)  
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   119
  end;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   120
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   121
val (preds,qconcls) = split_list (map mk_predpair Inductive.rec_tms);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   122
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   123
(*Used to form simultaneous induction lemma*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   124
fun mk_rec_imp (rec_tm,pred) = 
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   125
    Ind_Syntax.imp $ (Ind_Syntax.mk_mem (Bound 0, rec_tm)) $  (pred $ Bound 0);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   126
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   127
(*To instantiate the main induction rule*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   128
val induct_concl = 
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   129
    Ind_Syntax.mk_Trueprop
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   130
      (Ind_Syntax.mk_all_imp
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   131
       (big_rec_tm,
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   132
        Abs("z", elem_type, 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   133
            fold_bal (app Ind_Syntax.conj) 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   134
            (map mk_rec_imp (Inductive.rec_tms~~preds)))))
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   135
and mutual_induct_concl = 
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   136
    Ind_Syntax.mk_Trueprop (fold_bal (app Ind_Syntax.conj) qconcls);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   137
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   138
val lemma = (*makes the link between the two induction rules*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   139
    prove_goalw_cterm part_rec_defs 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   140
          (cterm_of sign (Logic.mk_implies (induct_concl,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   141
                                            mutual_induct_concl)))
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   142
          (fn prems =>
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   143
           [cut_facts_tac prems 1,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   144
            REPEAT (eresolve_tac [asm_rl, conjE, PartE, mp] 1
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   145
             ORELSE resolve_tac [allI, impI, conjI, Part_eqI, refl] 1
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   146
             ORELSE dresolve_tac [spec, mp, splitD] 1)])
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   147
    handle e => print_sign_exn sign e;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   148
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   149
(*Mutual induction follows by freeness of Inl/Inr.*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   150
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   151
(*Simplification largely reduces the mutual induction rule to the 
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   152
  standard rule*)
1264
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1190
diff changeset
   153
val mut_ss = simpset_of "Fun"
3eb91524b938 added local simpsets; removed IOA from 'make test'
clasohm
parents: 1190
diff changeset
   154
             addsimps [Inl_Inr_eq, Inr_Inl_eq, Inl_eq, Inr_eq];
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   155
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   156
val all_defs = Inductive.con_defs @ part_rec_defs;
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   157
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   158
(*Removes Collects caused by M-operators in the intro rules*)
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   159
val cmonos = [subset_refl RS Int_Collect_mono] RL Inductive.monos RLN
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   160
             (2,[rev_subsetD]);
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   161
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   162
(*Avoids backtracking by delivering the correct premise to each goal*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   163
fun mutual_ind_tac [] 0 = all_tac
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   164
  | mutual_ind_tac(prem::prems) i = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   165
      DETERM
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   166
       (SELECT_GOAL 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   167
          (
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   168
           (*Simplify the assumptions and goal by unfolding Part and
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   169
             using freeness of the Sum constructors; proves all but one
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   170
             conjunct by contradiction*)
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   171
           rewrite_goals_tac all_defs  THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   172
           simp_tac (mut_ss addsimps [Part_def]) 1  THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   173
           IF_UNSOLVED (*simp_tac may have finished it off!*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   174
             ((*simplify assumptions, but don't accept new rewrite rules!*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   175
              asm_full_simp_tac (mut_ss setmksimps K[]) 1  THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   176
              (*unpackage and use "prem" in the corresponding place*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   177
              REPEAT (rtac impI 1)  THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   178
              rtac (rewrite_rule all_defs prem) 1  THEN
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   179
              (*prem must not be REPEATed below: could loop!*)
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   180
              DEPTH_SOLVE (FIRSTGOAL (ares_tac [impI] ORELSE' 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   181
                                      eresolve_tac (conjE::mp::cmonos))))
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   182
          ) i)
1190
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   183
       THEN mutual_ind_tac prems (i-1);
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   184
9d1bdce3a38e Old version of mutual induction never worked. Now ensures that
lcp
parents: 923
diff changeset
   185
val _ = writeln "  Proving the mutual induction rule...";
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   186
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   187
val mutual_induct_split = 
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   188
    prove_goalw_cterm []
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   189
          (cterm_of sign
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   190
           (Logic.list_implies (map (induct_prem (Inductive.rec_tms ~~ preds)) 
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   191
                              Inductive.intr_tms,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   192
                          mutual_induct_concl)))
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   193
          (fn prems =>
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   194
           [rtac (quant_induct RS lemma) 1,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   195
            mutual_ind_tac (rev prems) (length prems)])
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   196
    handle e => print_sign_exn sign e;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   197
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   198
(*Attempts to remove all occurrences of split*)
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   199
val split_tac =
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   200
    REPEAT (SOMEGOAL (FIRST' [rtac splitI, 
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   201
                              dtac splitD,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   202
                              etac splitE,
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   203
                              bound_hyp_subst_tac]))
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   204
    THEN prune_params_tac;
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   205
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   206
in
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   207
  struct
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   208
  (*strip quantifier*)
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   209
  val induct = standard (quant_induct RS spec RSN (2,rev_mp));
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   210
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   211
  val mutual_induct = 
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   212
      if length Intr_elim.rec_names > 1 orelse
1465
5d7a7e439cec expanded tabs
clasohm
parents: 1424
diff changeset
   213
         length (Ind_Syntax.factors elem_type) > 1
1424
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   214
      then rule_by_tactic split_tac mutual_induct_split
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   215
      else TrueI;
ccb3c5ff6707 Now mutual_induct is simply "True" unless it is going to be
paulson
parents: 1264
diff changeset
   216
  end
923
ff1574a81019 new version of HOL with curried function application
clasohm
parents:
diff changeset
   217
end;