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