src/HOL/Accessible_Part.thy
changeset 22262 96ba62dff413
parent 21404 eb85850d3eb7
child 23735 afc12f93f64f
equal deleted inserted replaced
22261:9e185f78e7d4 22262:96ba62dff413
    15 text {*
    15 text {*
    16  Inductive definition of the accessible part @{term "acc r"} of a
    16  Inductive definition of the accessible part @{term "acc r"} of a
    17  relation; see also \cite{paulin-tlca}.
    17  relation; see also \cite{paulin-tlca}.
    18 *}
    18 *}
    19 
    19 
    20 consts
    20 inductive2
    21   acc :: "('a \<times> 'a) set => 'a set"
    21   acc :: "('a => 'a => bool) => 'a => bool"
    22 inductive "acc r"
    22   for r :: "'a => 'a => bool"
    23   intros
    23   where
    24     accI: "(!!y. (y, x) \<in> r ==> y \<in> acc r) ==> x \<in> acc r"
    24     accI: "(!!y. r y x ==> acc r y) ==> acc r x"
    25 
    25 
    26 abbreviation
    26 abbreviation
    27   termi :: "('a \<times> 'a) set => 'a set" where
    27   termi :: "('a => 'a => bool) => 'a => bool" where
    28   "termi r == acc (r\<inverse>)"
    28   "termi r == acc (r\<inverse>\<inverse>)"
    29 
    29 
    30 
    30 
    31 subsection {* Induction rules *}
    31 subsection {* Induction rules *}
    32 
    32 
    33 theorem acc_induct:
    33 theorem acc_induct:
    34   assumes major: "a \<in> acc r"
    34   assumes major: "acc r a"
    35   assumes hyp: "!!x. x \<in> acc r ==> \<forall>y. (y, x) \<in> r --> P y ==> P x"
    35   assumes hyp: "!!x. acc r x ==> \<forall>y. r y x --> P y ==> P x"
    36   shows "P a"
    36   shows "P a"
    37   apply (rule major [THEN acc.induct])
    37   apply (rule major [THEN acc.induct])
    38   apply (rule hyp)
    38   apply (rule hyp)
    39    apply (rule accI)
    39    apply (rule accI)
    40    apply fast
    40    apply fast
    41   apply fast
    41   apply fast
    42   done
    42   done
    43 
    43 
    44 theorems acc_induct_rule = acc_induct [rule_format, induct set: acc]
    44 theorems acc_induct_rule = acc_induct [rule_format, induct set: acc]
    45 
    45 
    46 theorem acc_downward: "b \<in> acc r ==> (a, b) \<in> r ==> a \<in> acc r"
    46 theorem acc_downward: "acc r b ==> r a b ==> acc r a"
    47   apply (erule acc.elims)
    47   apply (erule acc.cases)
    48   apply fast
    48   apply fast
    49   done
    49   done
    50 
    50 
    51 lemma acc_downwards_aux: "(b, a) \<in> r\<^sup>* ==> a \<in> acc r --> b \<in> acc r"
    51 lemma not_acc_down:
    52   apply (erule rtrancl_induct)
    52   assumes na: "\<not> acc R x"
       
    53   obtains z where "R z x" and "\<not> acc R z"
       
    54 proof -
       
    55   assume a: "\<And>z. \<lbrakk>R z x; \<not> acc R z\<rbrakk> \<Longrightarrow> thesis"
       
    56 
       
    57   show thesis
       
    58   proof (cases "\<forall>z. R z x \<longrightarrow> acc R z")
       
    59     case True
       
    60     hence "\<And>z. R z x \<Longrightarrow> acc R z" by auto
       
    61     hence "acc R x"
       
    62       by (rule accI)
       
    63     with na show thesis ..
       
    64   next
       
    65     case False then obtain z where "R z x" and "\<not> acc R z"
       
    66       by auto
       
    67     with a show thesis .
       
    68   qed
       
    69 qed
       
    70 
       
    71 lemma acc_downwards_aux: "r\<^sup>*\<^sup>* b a ==> acc r a --> acc r b"
       
    72   apply (erule rtrancl_induct')
    53    apply blast
    73    apply blast
    54   apply (blast dest: acc_downward)
    74   apply (blast dest: acc_downward)
    55   done
    75   done
    56 
    76 
    57 theorem acc_downwards: "a \<in> acc r ==> (b, a) \<in> r\<^sup>* ==> b \<in> acc r"
    77 theorem acc_downwards: "acc r a ==> r\<^sup>*\<^sup>* b a ==> acc r b"
    58   apply (blast dest: acc_downwards_aux)
    78   apply (blast dest: acc_downwards_aux)
    59   done
    79   done
    60 
    80 
    61 theorem acc_wfI: "\<forall>x. x \<in> acc r ==> wf r"
    81 theorem acc_wfI: "\<forall>x. acc r x ==> wfP r"
    62   apply (rule wfUNIVI)
    82   apply (rule wfPUNIVI)
    63   apply (induct_tac P x rule: acc_induct)
    83   apply (induct_tac P x rule: acc_induct)
    64    apply blast
    84    apply blast
    65   apply blast
    85   apply blast
    66   done
    86   done
    67 
    87 
    68 theorem acc_wfD: "wf r ==> x \<in> acc r"
    88 theorem acc_wfD: "wfP r ==> acc r x"
    69   apply (erule wf_induct)
    89   apply (erule wfP_induct_rule)
    70   apply (rule accI)
    90   apply (rule accI)
    71   apply blast
    91   apply blast
    72   done
    92   done
    73 
    93 
    74 theorem wf_acc_iff: "wf r = (\<forall>x. x \<in> acc r)"
    94 theorem wf_acc_iff: "wfP r = (\<forall>x. acc r x)"
    75   apply (blast intro: acc_wfI dest: acc_wfD)
    95   apply (blast intro: acc_wfI dest: acc_wfD)
    76   done
    96   done
    77 
    97 
    78 
    98 
    79 text {* Smaller relations have bigger accessible parts: *}
    99 text {* Smaller relations have bigger accessible parts: *}
    80 
   100 
    81 lemma acc_subset:
   101 lemma acc_subset:
    82   assumes sub: "R1 \<subseteq> R2"
   102   assumes sub: "R1 \<le> R2"
    83   shows "acc R2 \<subseteq> acc R1"
   103   shows "acc R2 \<le> acc R1"
    84 proof
   104 proof
    85   fix x assume "x \<in> acc R2"
   105   fix x assume "acc R2 x"
    86   then show "x \<in> acc R1"
   106   then show "acc R1 x"
    87   proof (induct x)
   107   proof (induct x)
    88     fix x
   108     fix x
    89     assume ih: "\<And>y. (y, x) \<in> R2 \<Longrightarrow> y \<in> acc R1"
   109     assume ih: "\<And>y. R2 y x \<Longrightarrow> acc R1 y"
    90     with sub show "x \<in> acc R1"
   110     with sub show "acc R1 x"
    91       by (blast intro:accI)
   111       by (blast intro: accI)
    92   qed
   112   qed
    93 qed
   113 qed
    94 
   114 
    95 
   115 
    96 text {* This is a generalized induction theorem that works on
   116 text {* This is a generalized induction theorem that works on
    97   subsets of the accessible part. *}
   117   subsets of the accessible part. *}
    98 
   118 
    99 lemma acc_subset_induct:
   119 lemma acc_subset_induct:
   100   assumes subset: "D \<subseteq> acc R"
   120   assumes subset: "D \<le> acc R"
   101     and dcl: "\<And>x z. \<lbrakk>x \<in> D; (z, x)\<in>R\<rbrakk> \<Longrightarrow> z \<in> D"
   121     and dcl: "\<And>x z. \<lbrakk>D x; R z x\<rbrakk> \<Longrightarrow> D z"
   102     and "x \<in> D"
   122     and "D x"
   103     and istep: "\<And>x. \<lbrakk>x \<in> D; (\<And>z. (z, x)\<in>R \<Longrightarrow> P z)\<rbrakk> \<Longrightarrow> P x"
   123     and istep: "\<And>x. \<lbrakk>D x; (\<And>z. R z x \<Longrightarrow> P z)\<rbrakk> \<Longrightarrow> P x"
   104   shows "P x"
   124   shows "P x"
   105 proof -
   125 proof -
   106   from `x \<in> D` and subset 
   126   from subset and `D x`
   107   have "x \<in> acc R" ..
   127   have "acc R x" ..
   108   then show "P x" using `x \<in> D`
   128   then show "P x" using `D x`
   109   proof (induct x)
   129   proof (induct x)
   110     fix x
   130     fix x
   111     assume "x \<in> D"
   131     assume "D x"
   112       and "\<And>y. (y, x) \<in> R \<Longrightarrow> y \<in> D \<Longrightarrow> P y"
   132       and "\<And>y. R y x \<Longrightarrow> D y \<Longrightarrow> P y"
   113     with dcl and istep show "P x" by blast
   133     with dcl and istep show "P x" by blast
   114   qed
   134   qed
   115 qed
   135 qed
   116 
   136 
   117 end
   137 end