src/HOL/Lambda/Commutation.thy
 author wenzelm Fri Dec 23 20:02:30 2005 +0100 (2005-12-23) changeset 18513 791b53bf4073 parent 18241 afdba6b3e383 child 19086 1b3780be6cc2 permissions -rw-r--r--
tuned proofs;
```     1 (*  Title:      HOL/Lambda/Commutation.thy
```
```     2     ID:         \$Id\$
```
```     3     Author:     Tobias Nipkow
```
```     4     Copyright   1995  TU Muenchen
```
```     5 *)
```
```     6
```
```     7 header {* Abstract commutation and confluence notions *}
```
```     8
```
```     9 theory Commutation imports Main begin
```
```    10
```
```    11 subsection {* Basic definitions *}
```
```    12
```
```    13 constdefs
```
```    14   square :: "[('a \<times> 'a) set, ('a \<times> 'a) set, ('a \<times> 'a) set, ('a \<times> 'a) set] => bool"
```
```    15   "square R S T U ==
```
```    16     \<forall>x y. (x, y) \<in> R --> (\<forall>z. (x, z) \<in> S --> (\<exists>u. (y, u) \<in> T \<and> (z, u) \<in> U))"
```
```    17
```
```    18   commute :: "[('a \<times> 'a) set, ('a \<times> 'a) set] => bool"
```
```    19   "commute R S == square R S S R"
```
```    20
```
```    21   diamond :: "('a \<times> 'a) set => bool"
```
```    22   "diamond R == commute R R"
```
```    23
```
```    24   Church_Rosser :: "('a \<times> 'a) set => bool"
```
```    25   "Church_Rosser R ==
```
```    26     \<forall>x y. (x, y) \<in> (R \<union> R^-1)^* --> (\<exists>z. (x, z) \<in> R^* \<and> (y, z) \<in> R^*)"
```
```    27
```
```    28 syntax
```
```    29   confluent :: "('a \<times> 'a) set => bool"
```
```    30 translations
```
```    31   "confluent R" == "diamond (R^*)"
```
```    32
```
```    33
```
```    34 subsection {* Basic lemmas *}
```
```    35
```
```    36 subsubsection {* square *}
```
```    37
```
```    38 lemma square_sym: "square R S T U ==> square S R U T"
```
```    39   apply (unfold square_def)
```
```    40   apply blast
```
```    41   done
```
```    42
```
```    43 lemma square_subset:
```
```    44     "[| square R S T U; T \<subseteq> T' |] ==> square R S T' U"
```
```    45   apply (unfold square_def)
```
```    46   apply blast
```
```    47   done
```
```    48
```
```    49 lemma square_reflcl:
```
```    50     "[| square R S T (R^=); S \<subseteq> T |] ==> square (R^=) S T (R^=)"
```
```    51   apply (unfold square_def)
```
```    52   apply blast
```
```    53   done
```
```    54
```
```    55 lemma square_rtrancl:
```
```    56     "square R S S T ==> square (R^*) S S (T^*)"
```
```    57   apply (unfold square_def)
```
```    58   apply (intro strip)
```
```    59   apply (erule rtrancl_induct)
```
```    60    apply blast
```
```    61   apply (blast intro: rtrancl_into_rtrancl)
```
```    62   done
```
```    63
```
```    64 lemma square_rtrancl_reflcl_commute:
```
```    65     "square R S (S^*) (R^=) ==> commute (R^*) (S^*)"
```
```    66   apply (unfold commute_def)
```
```    67   apply (fastsimp dest: square_reflcl square_sym [THEN square_rtrancl]
```
```    68     elim: r_into_rtrancl)
```
```    69   done
```
```    70
```
```    71
```
```    72 subsubsection {* commute *}
```
```    73
```
```    74 lemma commute_sym: "commute R S ==> commute S R"
```
```    75   apply (unfold commute_def)
```
```    76   apply (blast intro: square_sym)
```
```    77   done
```
```    78
```
```    79 lemma commute_rtrancl: "commute R S ==> commute (R^*) (S^*)"
```
```    80   apply (unfold commute_def)
```
```    81   apply (blast intro: square_rtrancl square_sym)
```
```    82   done
```
```    83
```
```    84 lemma commute_Un:
```
```    85     "[| commute R T; commute S T |] ==> commute (R \<union> S) T"
```
```    86   apply (unfold commute_def square_def)
```
```    87   apply blast
```
```    88   done
```
```    89
```
```    90
```
```    91 subsubsection {* diamond, confluence, and union *}
```
```    92
```
```    93 lemma diamond_Un:
```
```    94     "[| diamond R; diamond S; commute R S |] ==> diamond (R \<union> S)"
```
```    95   apply (unfold diamond_def)
```
```    96   apply (assumption | rule commute_Un commute_sym)+
```
```    97   done
```
```    98
```
```    99 lemma diamond_confluent: "diamond R ==> confluent R"
```
```   100   apply (unfold diamond_def)
```
```   101   apply (erule commute_rtrancl)
```
```   102   done
```
```   103
```
```   104 lemma square_reflcl_confluent:
```
```   105     "square R R (R^=) (R^=) ==> confluent R"
```
```   106   apply (unfold diamond_def)
```
```   107   apply (fast intro: square_rtrancl_reflcl_commute r_into_rtrancl
```
```   108     elim: square_subset)
```
```   109   done
```
```   110
```
```   111 lemma confluent_Un:
```
```   112     "[| confluent R; confluent S; commute (R^*) (S^*) |] ==> confluent (R \<union> S)"
```
```   113   apply (rule rtrancl_Un_rtrancl [THEN subst])
```
```   114   apply (blast dest: diamond_Un intro: diamond_confluent)
```
```   115   done
```
```   116
```
```   117 lemma diamond_to_confluence:
```
```   118     "[| diamond R; T \<subseteq> R; R \<subseteq> T^* |] ==> confluent T"
```
```   119   apply (force intro: diamond_confluent
```
```   120     dest: rtrancl_subset [symmetric])
```
```   121   done
```
```   122
```
```   123
```
```   124 subsection {* Church-Rosser *}
```
```   125
```
```   126 lemma Church_Rosser_confluent: "Church_Rosser R = confluent R"
```
```   127   apply (unfold square_def commute_def diamond_def Church_Rosser_def)
```
```   128   apply (tactic {* safe_tac HOL_cs *})
```
```   129    apply (tactic {*
```
```   130      blast_tac (HOL_cs addIs
```
```   131        [Un_upper2 RS rtrancl_mono RS subsetD RS rtrancl_trans,
```
```   132        rtrancl_converseI, converseI, Un_upper1 RS rtrancl_mono RS subsetD]) 1 *})
```
```   133   apply (erule rtrancl_induct)
```
```   134    apply blast
```
```   135   apply (blast del: rtrancl_refl intro: rtrancl_trans)
```
```   136   done
```
```   137
```
```   138
```
```   139 subsection {* Newman's lemma *}
```
```   140
```
```   141 text {* Proof by Stefan Berghofer *}
```
```   142
```
```   143 theorem newman:
```
```   144   assumes wf: "wf (R\<inverse>)"
```
```   145   and lc: "\<And>a b c. (a, b) \<in> R \<Longrightarrow> (a, c) \<in> R \<Longrightarrow>
```
```   146     \<exists>d. (b, d) \<in> R\<^sup>* \<and> (c, d) \<in> R\<^sup>*"
```
```   147   shows "\<And>b c. (a, b) \<in> R\<^sup>* \<Longrightarrow> (a, c) \<in> R\<^sup>* \<Longrightarrow>
```
```   148     \<exists>d. (b, d) \<in> R\<^sup>* \<and> (c, d) \<in> R\<^sup>*"
```
```   149   using wf
```
```   150 proof induct
```
```   151   case (less x b c)
```
```   152   have xc: "(x, c) \<in> R\<^sup>*" .
```
```   153   have xb: "(x, b) \<in> R\<^sup>*" . thus ?case
```
```   154   proof (rule converse_rtranclE)
```
```   155     assume "x = b"
```
```   156     with xc have "(b, c) \<in> R\<^sup>*" by simp
```
```   157     thus ?thesis by iprover
```
```   158   next
```
```   159     fix y
```
```   160     assume xy: "(x, y) \<in> R"
```
```   161     assume yb: "(y, b) \<in> R\<^sup>*"
```
```   162     from xc show ?thesis
```
```   163     proof (rule converse_rtranclE)
```
```   164       assume "x = c"
```
```   165       with xb have "(c, b) \<in> R\<^sup>*" by simp
```
```   166       thus ?thesis by iprover
```
```   167     next
```
```   168       fix y'
```
```   169       assume y'c: "(y', c) \<in> R\<^sup>*"
```
```   170       assume xy': "(x, y') \<in> R"
```
```   171       with xy have "\<exists>u. (y, u) \<in> R\<^sup>* \<and> (y', u) \<in> R\<^sup>*" by (rule lc)
```
```   172       then obtain u where yu: "(y, u) \<in> R\<^sup>*" and y'u: "(y', u) \<in> R\<^sup>*" by iprover
```
```   173       from xy have "(y, x) \<in> R\<inverse>" ..
```
```   174       from this and yb yu have "\<exists>d. (b, d) \<in> R\<^sup>* \<and> (u, d) \<in> R\<^sup>*" by (rule less)
```
```   175       then obtain v where bv: "(b, v) \<in> R\<^sup>*" and uv: "(u, v) \<in> R\<^sup>*" by iprover
```
```   176       from xy' have "(y', x) \<in> R\<inverse>" ..
```
```   177       moreover from y'u and uv have "(y', v) \<in> R\<^sup>*" by (rule rtrancl_trans)
```
```   178       moreover note y'c
```
```   179       ultimately have "\<exists>d. (v, d) \<in> R\<^sup>* \<and> (c, d) \<in> R\<^sup>*" by (rule less)
```
```   180       then obtain w where vw: "(v, w) \<in> R\<^sup>*" and cw: "(c, w) \<in> R\<^sup>*" by iprover
```
```   181       from bv vw have "(b, w) \<in> R\<^sup>*" by (rule rtrancl_trans)
```
```   182       with cw show ?thesis by iprover
```
```   183     qed
```
```   184   qed
```
```   185 qed
```
```   186
```
```   187 text {*
```
```   188   \medskip Alternative version.  Partly automated by Tobias
```
```   189   Nipkow. Takes 2 minutes (2002).
```
```   190
```
```   191   This is the maximal amount of automation possible at the moment.
```
```   192 *}
```
```   193
```
```   194 theorem newman':
```
```   195   assumes wf: "wf (R\<inverse>)"
```
```   196   and lc: "\<And>a b c. (a, b) \<in> R \<Longrightarrow> (a, c) \<in> R \<Longrightarrow>
```
```   197     \<exists>d. (b, d) \<in> R\<^sup>* \<and> (c, d) \<in> R\<^sup>*"
```
```   198   shows "\<And>b c. (a, b) \<in> R\<^sup>* \<Longrightarrow> (a, c) \<in> R\<^sup>* \<Longrightarrow>
```
```   199     \<exists>d. (b, d) \<in> R\<^sup>* \<and> (c, d) \<in> R\<^sup>*"
```
```   200   using wf
```
```   201 proof induct
```
```   202   case (less x b c)
```
```   203   note IH = `\<And>y b c. \<lbrakk>(y,x) \<in> R\<inverse>; (y,b) \<in> R\<^sup>*; (y,c) \<in> R\<^sup>*\<rbrakk>
```
```   204                      \<Longrightarrow> \<exists>d. (b,d) \<in> R\<^sup>* \<and> (c,d) \<in> R\<^sup>*`
```
```   205   have xc: "(x, c) \<in> R\<^sup>*" .
```
```   206   have xb: "(x, b) \<in> R\<^sup>*" .
```
```   207   thus ?case
```
```   208   proof (rule converse_rtranclE)
```
```   209     assume "x = b"
```
```   210     with xc have "(b, c) \<in> R\<^sup>*" by simp
```
```   211     thus ?thesis by iprover
```
```   212   next
```
```   213     fix y
```
```   214     assume xy: "(x, y) \<in> R"
```
```   215     assume yb: "(y, b) \<in> R\<^sup>*"
```
```   216     from xc show ?thesis
```
```   217     proof (rule converse_rtranclE)
```
```   218       assume "x = c"
```
```   219       with xb have "(c, b) \<in> R\<^sup>*" by simp
```
```   220       thus ?thesis by iprover
```
```   221     next
```
```   222       fix y'
```
```   223       assume y'c: "(y', c) \<in> R\<^sup>*"
```
```   224       assume xy': "(x, y') \<in> R"
```
```   225       with xy obtain u where u: "(y, u) \<in> R\<^sup>*" "(y', u) \<in> R\<^sup>*"
```
```   226         by (blast dest: lc)
```
```   227       from yb u y'c show ?thesis
```
```   228         by (blast del: rtrancl_refl
```
```   229             intro: rtrancl_trans
```
```   230             dest: IH [OF xy [symmetric]] IH [OF xy' [symmetric]])
```
```   231     qed
```
```   232   qed
```
```   233 qed
```
```   234
```
```   235 end
```