src/HOL/ZF/LProd.thy
author wenzelm
Thu May 24 17:25:53 2012 +0200 (2012-05-24)
changeset 47988 e4b69e10b990
parent 44011 f67c93f52d13
child 60495 d7ff0a1df90a
permissions -rw-r--r--
tuned proofs;
obua@19203
     1
(*  Title:      HOL/ZF/LProd.thy
obua@19203
     2
    Author:     Steven Obua
obua@19203
     3
obua@19203
     4
    Introduces the lprod relation.
obua@19203
     5
    See "Partizan Games in Isabelle/HOLZF", available from http://www4.in.tum.de/~obua/partizan
obua@19203
     6
*)
obua@19203
     7
obua@19203
     8
theory LProd 
wenzelm@41413
     9
imports "~~/src/HOL/Library/Multiset"
obua@19203
    10
begin
obua@19203
    11
berghofe@23771
    12
inductive_set
berghofe@23771
    13
  lprod :: "('a * 'a) set \<Rightarrow> ('a list * 'a list) set"
berghofe@23771
    14
  for R :: "('a * 'a) set"
berghofe@22282
    15
where
berghofe@23771
    16
  lprod_single[intro!]: "(a, b) \<in> R \<Longrightarrow> ([a], [b]) \<in> lprod R"
berghofe@23771
    17
| lprod_list[intro!]: "(ah@at, bh@bt) \<in> lprod R \<Longrightarrow> (a,b) \<in> R \<or> a = b \<Longrightarrow> (ah@a#at, bh@b#bt) \<in> lprod R"
obua@19203
    18
berghofe@23771
    19
lemma "(as,bs) \<in> lprod R \<Longrightarrow> length as = length bs"
obua@19203
    20
  apply (induct as bs rule: lprod.induct)
obua@19203
    21
  apply auto
obua@19203
    22
  done
obua@19203
    23
berghofe@23771
    24
lemma "(as, bs) \<in> lprod R \<Longrightarrow> 1 \<le> length as \<and> 1 \<le> length bs"
obua@19203
    25
  apply (induct as bs rule: lprod.induct)
obua@19203
    26
  apply auto
obua@19203
    27
  done
obua@19203
    28
berghofe@23771
    29
lemma lprod_subset_elem: "(as, bs) \<in> lprod S \<Longrightarrow> S \<subseteq> R \<Longrightarrow> (as, bs) \<in> lprod R"
obua@19203
    30
  apply (induct as bs rule: lprod.induct)
obua@19203
    31
  apply (auto)
obua@19203
    32
  done
obua@19203
    33
berghofe@23771
    34
lemma lprod_subset: "S \<subseteq> R \<Longrightarrow> lprod S \<subseteq> lprod R"
obua@19203
    35
  by (auto intro: lprod_subset_elem)
obua@19203
    36
berghofe@23771
    37
lemma lprod_implies_mult: "(as, bs) \<in> lprod R \<Longrightarrow> trans R \<Longrightarrow> (multiset_of as, multiset_of bs) \<in> mult R"
obua@19203
    38
proof (induct as bs rule: lprod.induct)
obua@19203
    39
  case (lprod_single a b)
obua@19203
    40
  note step = one_step_implies_mult[
obua@19203
    41
    where r=R and I="{#}" and K="{#a#}" and J="{#b#}", simplified]    
obua@19203
    42
  show ?case by (auto intro: lprod_single step)
obua@19203
    43
next
berghofe@23771
    44
  case (lprod_list ah at bh bt a b)
wenzelm@41528
    45
  then have transR: "trans R" by auto
obua@19203
    46
  have as: "multiset_of (ah @ a # at) = multiset_of (ah @ at) + {#a#}" (is "_ = ?ma + _")
nipkow@29667
    47
    by (simp add: algebra_simps)
obua@19203
    48
  have bs: "multiset_of (bh @ b # bt) = multiset_of (bh @ bt) + {#b#}" (is "_ = ?mb + _")
nipkow@29667
    49
    by (simp add: algebra_simps)
wenzelm@41528
    50
  from lprod_list have "(?ma, ?mb) \<in> mult R"
obua@19203
    51
    by auto
obua@19203
    52
  with mult_implies_one_step[OF transR] have 
berghofe@23771
    53
    "\<exists>I J K. ?mb = I + J \<and> ?ma = I + K \<and> J \<noteq> {#} \<and> (\<forall>k\<in>set_of K. \<exists>j\<in>set_of J. (k, j) \<in> R)"
obua@19203
    54
    by blast
obua@19203
    55
  then obtain I J K where 
berghofe@23771
    56
    decomposed: "?mb = I + J \<and> ?ma = I + K \<and> J \<noteq> {#} \<and> (\<forall>k\<in>set_of K. \<exists>j\<in>set_of J. (k, j) \<in> R)"
obua@19203
    57
    by blast   
obua@19203
    58
  show ?case
obua@19203
    59
  proof (cases "a = b")
obua@19203
    60
    case True    
berghofe@23771
    61
    have "((I + {#b#}) + K, (I + {#b#}) + J) \<in> mult R"
berghofe@23771
    62
      apply (rule one_step_implies_mult[OF transR])
obua@19203
    63
      apply (auto simp add: decomposed)
obua@19203
    64
      done
obua@19203
    65
    then show ?thesis
obua@19203
    66
      apply (simp only: as bs)
obua@19203
    67
      apply (simp only: decomposed True)
nipkow@29667
    68
      apply (simp add: algebra_simps)
obua@19203
    69
      done
obua@19203
    70
  next
obua@19203
    71
    case False
berghofe@23771
    72
    from False lprod_list have False: "(a, b) \<in> R" by blast
berghofe@23771
    73
    have "(I + (K + {#a#}), I + (J + {#b#})) \<in> mult R"
berghofe@23771
    74
      apply (rule one_step_implies_mult[OF transR])
obua@19203
    75
      apply (auto simp add: False decomposed)
obua@19203
    76
      done
obua@19203
    77
    then show ?thesis
obua@19203
    78
      apply (simp only: as bs)
obua@19203
    79
      apply (simp only: decomposed)
nipkow@29667
    80
      apply (simp add: algebra_simps)
obua@19203
    81
      done
obua@19203
    82
  qed
obua@19203
    83
qed
obua@19203
    84
krauss@44011
    85
lemma wf_lprod[simp,intro]:
berghofe@23771
    86
  assumes wf_R: "wf R"
berghofe@23771
    87
  shows "wf (lprod R)"
obua@19203
    88
proof -
berghofe@23771
    89
  have subset: "lprod (R^+) \<subseteq> inv_image (mult (R^+)) multiset_of"
berghofe@23771
    90
    by (auto simp add: lprod_implies_mult trans_trancl)
berghofe@23771
    91
  note lprodtrancl = wf_subset[OF wf_inv_image[where r="mult (R^+)" and f="multiset_of", 
berghofe@23771
    92
    OF wf_mult[OF wf_trancl[OF wf_R]]], OF subset]
berghofe@23771
    93
  note lprod = wf_subset[OF lprodtrancl, where p="lprod R", OF lprod_subset, simplified]
obua@19203
    94
  show ?thesis by (auto intro: lprod)
obua@19203
    95
qed
obua@19203
    96
haftmann@35416
    97
definition gprod_2_2 :: "('a * 'a) set \<Rightarrow> (('a * 'a) * ('a * 'a)) set" where
berghofe@23771
    98
  "gprod_2_2 R \<equiv> { ((a,b), (c,d)) . (a = c \<and> (b,d) \<in> R) \<or> (b = d \<and> (a,c) \<in> R) }"
haftmann@35416
    99
haftmann@35416
   100
definition gprod_2_1 :: "('a * 'a) set \<Rightarrow> (('a * 'a) * ('a * 'a)) set" where
berghofe@23771
   101
  "gprod_2_1 R \<equiv>  { ((a,b), (c,d)) . (a = d \<and> (b,c) \<in> R) \<or> (b = c \<and> (a,d) \<in> R) }"
obua@19203
   102
berghofe@23771
   103
lemma lprod_2_3: "(a, b) \<in> R \<Longrightarrow> ([a, c], [b, c]) \<in> lprod R"
obua@19203
   104
  by (auto intro: lprod_list[where a=c and b=c and 
obua@19203
   105
    ah = "[a]" and at = "[]" and bh="[b]" and bt="[]", simplified]) 
obua@19203
   106
berghofe@23771
   107
lemma lprod_2_4: "(a, b) \<in> R \<Longrightarrow> ([c, a], [c, b]) \<in> lprod R"
obua@19203
   108
  by (auto intro: lprod_list[where a=c and b=c and 
obua@19203
   109
    ah = "[]" and at = "[a]" and bh="[]" and bt="[b]", simplified])
obua@19203
   110
berghofe@23771
   111
lemma lprod_2_1: "(a, b) \<in> R \<Longrightarrow> ([c, a], [b, c]) \<in> lprod R"
obua@19203
   112
  by (auto intro: lprod_list[where a=c and b=c and 
obua@19203
   113
    ah = "[]" and at = "[a]" and bh="[b]" and bt="[]", simplified]) 
obua@19203
   114
berghofe@23771
   115
lemma lprod_2_2: "(a, b) \<in> R \<Longrightarrow> ([a, c], [c, b]) \<in> lprod R"
obua@19203
   116
  by (auto intro: lprod_list[where a=c and b=c and 
obua@19203
   117
    ah = "[a]" and at = "[]" and bh="[]" and bt="[b]", simplified])
obua@19203
   118
krauss@44011
   119
lemma [simp, intro]:
berghofe@23771
   120
  assumes wfR: "wf R" shows "wf (gprod_2_1 R)"
obua@19203
   121
proof -
berghofe@23771
   122
  have "gprod_2_1 R \<subseteq> inv_image (lprod R) (\<lambda> (a,b). [a,b])"
krauss@19769
   123
    by (auto simp add: gprod_2_1_def lprod_2_1 lprod_2_2)
obua@19203
   124
  with wfR show ?thesis
berghofe@23771
   125
    by (rule_tac wf_subset, auto)
obua@19203
   126
qed
obua@19203
   127
krauss@44011
   128
lemma [simp, intro]:
berghofe@23771
   129
  assumes wfR: "wf R" shows "wf (gprod_2_2 R)"
obua@19203
   130
proof -
berghofe@23771
   131
  have "gprod_2_2 R \<subseteq> inv_image (lprod R) (\<lambda> (a,b). [a,b])"
krauss@19769
   132
    by (auto simp add: gprod_2_2_def lprod_2_3 lprod_2_4)
obua@19203
   133
  with wfR show ?thesis
berghofe@23771
   134
    by (rule_tac wf_subset, auto)
obua@19203
   135
qed
obua@19203
   136
berghofe@23771
   137
lemma lprod_3_1: assumes "(x', x) \<in> R" shows "([y, z, x'], [x, y, z]) \<in> lprod R"
obua@19203
   138
  apply (rule lprod_list[where a="y" and b="y" and ah="[]" and at="[z,x']" and bh="[x]" and bt="[z]", simplified])
wenzelm@41528
   139
  apply (auto simp add: lprod_2_1 assms)
obua@19203
   140
  done
obua@19203
   141
berghofe@23771
   142
lemma lprod_3_2: assumes "(z',z) \<in> R" shows "([z', x, y], [x,y,z]) \<in> lprod R"
obua@19203
   143
  apply (rule lprod_list[where a="y" and b="y" and ah="[z',x]" and at="[]" and bh="[x]" and bt="[z]", simplified])
wenzelm@41528
   144
  apply (auto simp add: lprod_2_2 assms)
obua@19203
   145
  done
obua@19203
   146
berghofe@23771
   147
lemma lprod_3_3: assumes xr: "(xr, x) \<in> R" shows "([xr, y, z], [x, y, z]) \<in> lprod R"
obua@19203
   148
  apply (rule lprod_list[where a="y" and b="y" and ah="[xr]" and at="[z]" and bh="[x]" and bt="[z]", simplified])
obua@19203
   149
  apply (simp add: xr lprod_2_3)
obua@19203
   150
  done
obua@19203
   151
berghofe@23771
   152
lemma lprod_3_4: assumes yr: "(yr, y) \<in> R" shows "([x, yr, z], [x, y, z]) \<in> lprod R"
obua@19203
   153
  apply (rule lprod_list[where a="x" and b="x" and ah="[]" and at="[yr,z]" and bh="[]" and bt="[y,z]", simplified])
obua@19203
   154
  apply (simp add: yr lprod_2_3)
obua@19203
   155
  done
obua@19203
   156
berghofe@23771
   157
lemma lprod_3_5: assumes zr: "(zr, z) \<in> R" shows "([x, y, zr], [x, y, z]) \<in> lprod R"
obua@19203
   158
  apply (rule lprod_list[where a="x" and b="x" and ah="[]" and at="[y,zr]" and bh="[]" and bt="[y,z]", simplified])
obua@19203
   159
  apply (simp add: zr lprod_2_4)
obua@19203
   160
  done
obua@19203
   161
berghofe@23771
   162
lemma lprod_3_6: assumes y': "(y', y) \<in> R" shows "([x, z, y'], [x, y, z]) \<in> lprod R"
obua@19203
   163
  apply (rule lprod_list[where a="z" and b="z" and ah="[x]" and at="[y']" and bh="[x,y]" and bt="[]", simplified])
obua@19203
   164
  apply (simp add: y' lprod_2_4)
obua@19203
   165
  done
obua@19203
   166
berghofe@23771
   167
lemma lprod_3_7: assumes z': "(z',z) \<in> R" shows "([x, z', y], [x, y, z]) \<in> lprod R"
obua@19203
   168
  apply (rule lprod_list[where a="y" and b="y" and ah="[x, z']" and at="[]" and bh="[x]" and bt="[z]", simplified])
obua@19203
   169
  apply (simp add: z' lprod_2_4)
obua@19203
   170
  done
obua@19203
   171
haftmann@35416
   172
definition perm :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a set \<Rightarrow> bool" where
obua@19203
   173
   "perm f A \<equiv> inj_on f A \<and> f ` A = A"
obua@19203
   174
berghofe@23771
   175
lemma "((as,bs) \<in> lprod R) = 
obua@19203
   176
  (\<exists> f. perm f {0 ..< (length as)} \<and> 
berghofe@23771
   177
  (\<forall> j. j < length as \<longrightarrow> ((nth as j, nth bs (f j)) \<in> R \<or> (nth as j = nth bs (f j)))) \<and> 
berghofe@23771
   178
  (\<exists> i. i < length as \<and> (nth as i, nth bs (f i)) \<in> R))"
obua@19203
   179
oops
obua@19203
   180
berghofe@23771
   181
lemma "trans R \<Longrightarrow> (ah@a#at, bh@b#bt) \<in> lprod R \<Longrightarrow> (b, a) \<in> R \<or> a = b \<Longrightarrow> (ah@at, bh@bt) \<in> lprod R" 
obua@19203
   182
oops
obua@19203
   183
wenzelm@35422
   184
end