src/HOL/Datatype_Examples/Free_Idempotent_Monoid.thy
author wenzelm
Tue, 28 Sep 2021 22:50:22 +0200
changeset 74386 40804452ab6b
parent 73398 180981b87929
permissions -rw-r--r--
recover some Linux test, using virtual machine node (Ubuntu 20.04, 4 cores, 16 GB);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
71393
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     1
theory Free_Idempotent_Monoid imports
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     2
  "HOL-Library.Confluent_Quotient"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     3
begin
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     4
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     5
inductive cancel1 :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     6
where cancel1: "xs \<noteq> [] \<Longrightarrow> cancel1 (gs @ xs @ xs @ gs') (gs @ xs @ gs')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     7
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     8
abbreviation cancel where "cancel \<equiv> cancel1\<^sup>*\<^sup>*"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
     9
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    10
lemma cancel1_append_same1:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    11
  assumes "cancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    12
  shows "cancel1 (zs @ xs) (zs @ ys)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    13
using assms
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    14
proof cases
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    15
  case (cancel1 ys gs gs')
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    16
  from \<open>ys \<noteq> []\<close> have "cancel1 ((zs @ gs) @ ys @ ys @ gs') ((zs @ gs) @ ys @ gs')" ..
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    17
  with cancel1 show ?thesis by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    18
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    19
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    20
lemma cancel_append_same1: "cancel (zs @ xs) (zs @ ys)" if "cancel xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    21
  using that by induction(blast intro: rtranclp.rtrancl_into_rtrancl cancel1_append_same1)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    22
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    23
lemma cancel1_append_same2: "cancel1 xs ys \<Longrightarrow> cancel1 (xs @ zs) (ys @ zs)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    24
by(cases rule: cancel1.cases)(auto intro: cancel1.intros)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    25
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    26
lemma cancel_append_same2: "cancel (xs @ zs) (ys @ zs)" if "cancel xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    27
  using that by induction(blast intro: rtranclp.rtrancl_into_rtrancl cancel1_append_same2)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    28
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    29
lemma cancel1_same:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    30
  assumes "xs \<noteq> []"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    31
  shows "cancel1 (xs @ xs) xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    32
proof -
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    33
  have "cancel1 ([] @ xs @ xs @ []) ([] @ xs @ [])" using assms ..
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    34
  thus ?thesis by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    35
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    36
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    37
lemma cancel_same: "cancel (xs @ xs) xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    38
  by(cases "xs = []")(auto intro: cancel1_same)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    39
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    40
abbreviation (input) eq :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    41
where "eq \<equiv> equivclp cancel1"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    42
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    43
lemma eq_sym: "eq x y \<Longrightarrow> eq y x"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    44
  by(rule equivclp_sym)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    45
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    46
lemma equivp_eq: "equivp eq" by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    47
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    48
lemma eq_append_same1: "eq xs' ys' \<Longrightarrow> eq (xs @ xs') (xs @ ys')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    49
  by(induction rule: equivclp_induct)(auto intro: cancel1_append_same1 equivclp_into_equivclp)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    50
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    51
lemma append_eq_cong: "\<lbrakk>eq xs ys; eq xs' ys'\<rbrakk> \<Longrightarrow> eq (xs @ xs') (ys @ ys')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    52
  by(induction rule: equivclp_induct)(auto intro: eq_append_same1 equivclp_into_equivclp cancel1_append_same2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    53
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    54
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    55
quotient_type 'a fim = "'a list" / eq by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    56
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    57
instantiation fim :: (type) monoid_add begin
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    58
lift_definition zero_fim :: "'a fim" is "[]" .
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    59
lift_definition plus_fim :: "'a fim \<Rightarrow> 'a fim \<Rightarrow> 'a fim" is "(@)" by(rule append_eq_cong)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    60
instance by(intro_classes; transfer; simp)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    61
end
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    62
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    63
lemma plus_idem_fim [simp]: fixes x :: "'a fim" shows "x + x = x"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    64
proof transfer
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    65
  fix xs :: "'a list"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    66
  show "eq (xs @ xs) xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    67
  proof(cases "xs = []")
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    68
    case False thus ?thesis using cancel1_same[of xs] by(auto)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    69
  qed simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    70
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    71
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    72
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    73
inductive pcancel1 :: "'a list \<Rightarrow> 'a list \<Rightarrow> bool" where
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    74
  pcancel1: "pcancel1 (concat xss) (concat yss)" if "list_all2 (\<lambda>xs ys. xs = ys \<or> xs = ys @ ys) xss yss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    75
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    76
lemma cancel1_into_pcancel1: "pcancel1 xs ys" if "cancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    77
  using that
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    78
proof cases
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    79
  case (cancel1 xs gs gs')
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    80
  let ?xss = "[gs, xs @ xs, gs']" and ?yss = "[gs, xs, gs']"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    81
  have "pcancel1 (concat ?xss) (concat ?yss)" by(rule pcancel1.intros) simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    82
  then show ?thesis using cancel1 by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    83
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    84
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    85
lemma pcancel_into_cancel: "cancel1\<^sup>*\<^sup>* xs ys" if "pcancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    86
  using that
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    87
proof cases
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    88
  case (pcancel1 xss yss)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    89
  from pcancel1(3) show ?thesis unfolding pcancel1(1-2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    90
    apply induction
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    91
     apply simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    92
    apply(auto intro: cancel_append_same1)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    93
    apply(rule rtranclp_trans)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    94
    apply(subst append_assoc[symmetric])
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    95
     apply(rule cancel_append_same2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    96
     apply(rule cancel_same)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    97
    apply(auto intro: cancel_append_same1)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    98
    done
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
    99
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   100
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   101
lemma pcancel1_cancel1_confluent:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   102
  assumes "pcancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   103
    and "cancel1 zs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   104
  shows "\<exists>us. cancel us xs \<and> pcancel1 us zs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   105
proof -
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   106
  let ?P = "\<lambda>xs ys. xs = ys \<or> xs = ys @ ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   107
  consider ass as2 bs1 bss bs2 cs1 css ass' as2bs1 bss' bs2cs1 css'
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   108
    where "ys = concat ass @ as2 @ bs1 @ concat bss @ bs2 @ cs1 @ concat css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   109
     and "xs = concat ass' @ as2bs1 @ concat bss' @ bs2cs1 @ concat css'"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   110
     and "zs = concat ass @ as2 @ bs1 @ concat bss @ bs2 @ bs1 @ concat bss @ bs2 @ cs1 @ concat css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   111
     and "list_all2 ?P ass' ass"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   112
     and "list_all2 ?P bss' bss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   113
     and "list_all2 ?P css' css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   114
     and "?P as2bs1 (as2 @ bs1)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   115
     and "?P bs2cs1 (bs2 @ cs1)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   116
   | ass as2 bs cs1 css ass' css'
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   117
   where "ys = concat ass @ as2 @ bs @ cs1 @ concat css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   118
     and "xs = concat ass' @ as2 @ bs @ cs1 @ as2 @ bs @ cs1 @ concat css'"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   119
     and "zs = concat ass @ as2 @ bs @ bs @ cs1 @ concat css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   120
     and "list_all2 ?P ass' ass"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   121
     and "list_all2 ?P css' css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   122
  proof -
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   123
    from assms obtain xss bs as cs yss
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   124
      where xs: "xs = concat xss" and zs: "zs = as @ bs @ bs @ cs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   125
      and xss: "list_all2 (\<lambda>xs ys. xs = ys \<or> xs = ys @ ys) xss yss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   126
      and ys: "ys = as @ bs @ cs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   127
      and yss: "concat yss = as @ bs @ cs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   128
      and bs: "bs \<noteq> []"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   129
      by(clarsimp simp add: pcancel1.simps cancel1.simps)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   130
    from yss bs obtain ass as2 BS bcss
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   131
      where yss: "yss = ass @ (as2 @ BS) # bcss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   132
       and as: "as = concat ass @ as2"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   133
       and eq: "bs @ cs = BS @ concat bcss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   134
      by(auto simp add: concat_eq_append_conv split: if_split_asm)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   135
    define bcss' where "bcss' = (if bcss = [] then [[]] else bcss)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   136
    have bcss': "bcss' \<noteq> []" by(simp add: bcss'_def)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   137
    from eq consider us where "bs = BS @ us" "concat bcss = us @ cs" "bcss \<noteq> []" |
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   138
      "BS = bs @ cs" "bcss = []" |
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   139
      us where "BS = bs @ us" "cs = us @ concat bcss"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   140
      by(cases "bcss = []")(auto simp add: append_eq_append_conv2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   141
    then show thesis
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   142
    proof cases
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   143
      case 1
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   144
      from 1(2,3) obtain bss bs2 cs1 css
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   145
        where "bcss = bss @ (bs2 @ cs1) # css"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   146
          and us: "us = concat bss @ bs2"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   147
          and cs: "cs = cs1 @ concat css" by(auto simp add: concat_eq_append_conv)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   148
      with 1 xs xss ys yss zs as that(1)[of ass as2 BS bss bs2 cs1 css] show ?thesis
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   149
        by(clarsimp simp add: list_all2_append2 list_all2_Cons2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   150
    next
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   151
      case 2
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   152
      with xs xss ys yss zs as show ?thesis
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   153
        using that(1)[of ass as2 bs "[]" "[]" "[]" "[cs]" _ "as2 @ bs" "[]" "[]" "[cs]"]
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   154
        using that(2)[of ass as2 bs cs "[]"]
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   155
        by(auto simp add: list_all2_append2 list_all2_Cons2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   156
    next
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   157
      case 3
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   158
      with xs xss ys yss zs as show ?thesis
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   159
        using that(1)[of ass as2 "[]" "[bs]" "[]" "us" "bcss" _ "as2" "[bs]"] that(2)[of ass as2 bs us bcss]
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   160
        by(auto simp add: list_all2_append2 list_all2_Cons2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   161
    qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   162
  qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   163
  then show ?thesis
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   164
  proof cases
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   165
    case 1
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   166
    let ?us = "concat ass' @ as2bs1 @ concat bss' @ bs2 @ bs1 @ concat bss' @ bs2cs1 @ concat css'"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   167
    have "?us = concat (ass' @ [as2bs1] @ bss' @ [bs2 @ bs1] @ bss' @ [bs2cs1] @ css')" by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   168
    also have "pcancel1 \<dots> (concat (ass @ [as2 @ bs1] @ bss @ [bs2 @ bs1] @ bss @ [bs2 @ cs1] @ css))"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   169
      by(rule pcancel1.intros)(use 1 in \<open>simp add: list_all2_appendI\<close>)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   170
    also have "\<dots> = zs" using 1 by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   171
    also have "cancel ?us xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   172
    proof -
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   173
      define as2b where "as2b = (if as2bs1 = as2 @ bs1 then as2 else as2 @ bs1 @ as2)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   174
      have as2bs1: "as2bs1 = as2b @ bs1" using 1 by(auto simp add: as2b_def)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   175
      define b2cs where "b2cs = (if bs2cs1 = bs2 @ cs1 then cs1 else cs1 @ bs2 @ cs1)"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   176
      have bs2cs1: "bs2cs1 = bs2 @ b2cs" using 1 by(auto simp add: b2cs_def)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   177
      have "?us = (concat ass' @ as2b) @ ((bs1 @ concat bss' @ bs2) @ (bs1 @ concat bss' @ bs2)) @ b2cs @ concat css'"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   178
        by(simp add: as2bs1 bs2cs1)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   179
      also have "cancel \<dots> ((concat ass' @ as2b) @ (bs1 @ concat bss' @ bs2) @ b2cs @ concat css')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   180
        by(rule cancel_append_same1 cancel_append_same2 cancel_same)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   181
      also have "\<dots> = xs" using 1 bs2cs1 as2bs1 by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   182
      finally show ?thesis .
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   183
    qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   184
    ultimately show ?thesis by blast
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   185
  next
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   186
    case 2
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   187
    let ?us = "concat ass' @ as2 @ bs @ bs @ cs1 @ as2 @ bs @ bs @ cs1 @ concat css'"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   188
    have "?us = concat (ass' @ [as2 @ bs @ bs @ cs1 @ as2 @ bs @ bs @ cs1] @ css')" by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   189
    also have "pcancel1 \<dots> (concat (ass @ [as2 @ bs @ bs @ cs1] @ css))"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   190
      by(intro pcancel1.intros list_all2_appendI)(simp_all add: 2)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   191
    also have "\<dots> = zs" using 2 by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   192
    also have "cancel ?us xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   193
    proof -
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   194
      have "?us = (concat ass' @ as2) @ (bs @ bs) @ cs1 @ as2 @ bs @ bs @ cs1 @ concat css'" by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   195
      also have "cancel \<dots> ((concat ass' @ as2) @ bs @ cs1 @ as2 @ bs @ bs @ cs1 @ concat css')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   196
        by(rule cancel_append_same1 cancel_append_same2 cancel_same)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   197
      also have "\<dots> = (concat ass' @ as2 @ bs @ cs1 @ as2) @ (bs @ bs) @ cs1 @ concat css'" by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   198
      also have "cancel \<dots> ((concat ass' @ as2 @ bs @ cs1 @ as2) @ bs @ cs1 @ concat css')"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   199
        by(rule cancel_append_same1 cancel_append_same2 cancel_same)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   200
      also have "\<dots> = xs" using 2 by simp
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   201
      finally show ?thesis .
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   202
    qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   203
    ultimately show ?thesis by blast
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   204
  qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   205
qed
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   206
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   207
lemma pcancel1_cancel_confluent:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   208
  assumes "pcancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   209
    and "cancel zs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   210
  shows "\<exists>us. cancel us xs \<and> pcancel1 us zs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   211
  using assms(2,1)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   212
  by(induction arbitrary: xs)(fastforce elim!: rtranclp_trans dest: pcancel1_cancel1_confluent)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   213
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   214
lemma cancel1_semiconfluent:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   215
  assumes "cancel1 xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   216
    and "cancel zs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   217
  shows "\<exists>us. cancel us xs \<and> cancel us zs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   218
  using pcancel1_cancel_confluent[OF cancel1_into_pcancel1, OF assms]
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   219
  by(blast intro: pcancel_into_cancel)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   220
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   221
lemma semiconfluentp_cancel1: "semiconfluentp cancel1\<inverse>\<inverse>"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   222
  by(auto simp add: semiconfluentp_def rtranclp_conversep dest: cancel1_semiconfluent)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   223
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   224
lemma retract_cancel1_aux:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   225
  assumes "cancel1 ys (map f xs)"
73398
180981b87929 generalized confluence-based subdistributivity theorem for quotients;
traytel
parents: 71469
diff changeset
   226
  shows "\<exists>zs. cancel1 zs xs \<and> ys = map f zs \<and> set zs \<subseteq> set xs"
71393
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   227
  using assms
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   228
  by cases(fastforce simp add: map_eq_append_conv append_eq_map_conv intro: cancel1.intros)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   229
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   230
lemma retract_cancel1:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   231
  assumes "cancel1 ys (map f xs)"
73398
180981b87929 generalized confluence-based subdistributivity theorem for quotients;
traytel
parents: 71469
diff changeset
   232
  shows "\<exists>zs. eq xs zs \<and> ys = map f zs \<and> set zs \<subseteq> set xs"
71393
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   233
  using retract_cancel1_aux[OF assms] by(blast intro: symclpI)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   234
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   235
lemma cancel1_set_eq:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   236
  assumes "cancel1 ys xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   237
  shows "set ys = set xs"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   238
  using assms by cases auto
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   239
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   240
lemma eq_set_eq: "set xs = set ys" if "eq xs ys"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   241
  using that by(induction)(auto dest!: cancel1_set_eq elim!: symclpE)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   242
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   243
context includes lifting_syntax begin
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   244
lemma map_respect_cancel1: "((=) ===> cancel1 ===> eq) map map"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   245
  by(auto 4 4 simp add: rel_fun_def cancel1.simps intro: symclpI cancel1.intros)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   246
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   247
lemma map_respect_eq: "((=) ===> eq ===> eq) map map"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   248
  apply(intro rel_funI; hypsubst)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   249
  subgoal for _ f x y
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   250
    by(induction rule: equivclp_induct)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   251
      (auto dest: map_respect_cancel1[THEN rel_funD, THEN rel_funD, OF refl] intro: eq_sym equivclp_trans)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   252
  done
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   253
end
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   254
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   255
lemma confluent_quotient_fim:
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   256
  "confluent_quotient cancel1\<inverse>\<inverse> eq eq eq eq eq (map fst) (map snd) (map fst) (map snd) list_all2 list_all2 list_all2 set set"
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   257
  by(unfold_locales)(auto dest: retract_cancel1 eq_set_eq simp add: list.in_rel list.rel_compp map_respect_eq[THEN rel_funD, OF refl] semiconfluentp_imp_confluentp semiconfluentp_cancel1)+
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   258
71469
d7ef73df3d15 lift BNF witnesses for quotients (unless better ones are specified by the user)
traytel
parents: 71393
diff changeset
   259
lift_bnf 'a fim
71393
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   260
  subgoal for A B by(rule confluent_quotient.subdistributivity[OF confluent_quotient_fim])
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   261
  subgoal by(force dest: eq_set_eq)
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   262
  done
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   263
fce780f9c9c6 new examples of BNF lifting across quotients using a new theory of confluence,
traytel
parents:
diff changeset
   264
end