src/HOL/Lambda/InductTermi.thy
author wenzelm
Fri Jan 25 23:05:23 2008 +0100 (2008-01-25)
changeset 25972 94b15338da8d
parent 23750 a1db5f819d00
child 26806 40b411ec05aa
permissions -rw-r--r--
tuned document;
     1 (*  Title:      HOL/Lambda/InductTermi.thy
     2     ID:         $Id$
     3     Author:     Tobias Nipkow
     4     Copyright   1998 TU Muenchen
     5 
     6 Inductive characterization of terminating lambda terms.  Goes back to
     7 Raamsdonk & Severi. On normalization. CWI TR CS-R9545, 1995.  Also
     8 rediscovered by Matthes and Joachimski.
     9 *)
    10 
    11 header {* Inductive characterization of terminating lambda terms *}
    12 
    13 theory InductTermi imports ListBeta begin
    14 
    15 subsection {* Terminating lambda terms *}
    16 
    17 inductive IT :: "dB => bool"
    18   where
    19     Var [intro]: "listsp IT rs ==> IT (Var n \<degree>\<degree> rs)"
    20   | Lambda [intro]: "IT r ==> IT (Abs r)"
    21   | Beta [intro]: "IT ((r[s/0]) \<degree>\<degree> ss) ==> IT s ==> IT ((Abs r \<degree> s) \<degree>\<degree> ss)"
    22 
    23 
    24 subsection {* Every term in @{text "IT"} terminates *}
    25 
    26 lemma double_induction_lemma [rule_format]:
    27   "termip beta s ==> \<forall>t. termip beta t -->
    28     (\<forall>r ss. t = r[s/0] \<degree>\<degree> ss --> termip beta (Abs r \<degree> s \<degree>\<degree> ss))"
    29   apply (erule accp_induct)
    30   apply (rule allI)
    31   apply (rule impI)
    32   apply (erule thin_rl)
    33   apply (erule accp_induct)
    34   apply clarify
    35   apply (rule accp.accI)
    36   apply (safe elim!: apps_betasE)
    37      apply assumption
    38     apply (blast intro: subst_preserves_beta apps_preserves_beta)
    39    apply (blast intro: apps_preserves_beta2 subst_preserves_beta2 rtranclp_converseI
    40      dest: accp_downwards)  (* FIXME: acc_downwards can be replaced by acc(R ^* ) = acc(r) *)
    41   apply (blast dest: apps_preserves_betas)
    42   done
    43 
    44 lemma IT_implies_termi: "IT t ==> termip beta t"
    45   apply (induct set: IT)
    46     apply (drule rev_predicate1D [OF _ listsp_mono [where B="termip beta"]])
    47     apply fast
    48     apply (drule lists_accD)
    49     apply (erule accp_induct)
    50     apply (rule accp.accI)
    51     apply (blast dest: head_Var_reduction)
    52    apply (erule accp_induct)
    53    apply (rule accp.accI)
    54    apply blast
    55   apply (blast intro: double_induction_lemma)
    56   done
    57 
    58 
    59 subsection {* Every terminating term is in @{text "IT"} *}
    60 
    61 declare Var_apps_neq_Abs_apps [symmetric, simp]
    62 
    63 lemma [simp, THEN not_sym, simp]: "Var n \<degree>\<degree> ss \<noteq> Abs r \<degree> s \<degree>\<degree> ts"
    64   by (simp add: foldl_Cons [symmetric] del: foldl_Cons)
    65 
    66 lemma [simp]:
    67   "(Abs r \<degree> s \<degree>\<degree> ss = Abs r' \<degree> s' \<degree>\<degree> ss') = (r = r' \<and> s = s' \<and> ss = ss')"
    68   by (simp add: foldl_Cons [symmetric] del: foldl_Cons)
    69 
    70 inductive_cases [elim!]:
    71   "IT (Var n \<degree>\<degree> ss)"
    72   "IT (Abs t)"
    73   "IT (Abs r \<degree> s \<degree>\<degree> ts)"
    74 
    75 theorem termi_implies_IT: "termip beta r ==> IT r"
    76   apply (erule accp_induct)
    77   apply (rename_tac r)
    78   apply (erule thin_rl)
    79   apply (erule rev_mp)
    80   apply simp
    81   apply (rule_tac t = r in Apps_dB_induct)
    82    apply clarify
    83    apply (rule IT.intros)
    84    apply clarify
    85    apply (drule bspec, assumption)
    86    apply (erule mp)
    87    apply clarify
    88    apply (drule_tac r=beta in conversepI)
    89    apply (drule_tac r="beta^--1" in ex_step1I, assumption)
    90    apply clarify
    91    apply (rename_tac us)
    92    apply (erule_tac x = "Var n \<degree>\<degree> us" in allE)
    93    apply force
    94    apply (rename_tac u ts)
    95    apply (case_tac ts)
    96     apply simp
    97     apply blast
    98    apply (rename_tac s ss)
    99    apply simp
   100    apply clarify
   101    apply (rule IT.intros)
   102     apply (blast intro: apps_preserves_beta)
   103    apply (erule mp)
   104    apply clarify
   105    apply (rename_tac t)
   106    apply (erule_tac x = "Abs u \<degree> t \<degree>\<degree> ss" in allE)
   107    apply force
   108    done
   109 
   110 end