Nominal/Ex/LetRecFunNo.thy
author Christian Urban <urbanc@in.tum.de>
Tue, 10 Apr 2012 16:02:30 +0100
changeset 3158 89f9d7e85e88
parent 3150 7ad3b1421b82
child 3235 5ebd327ffb96
permissions -rw-r--r--
moved lift_raw_const from Quotient to Nominal
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3150
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     1
theory Let
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     2
imports "../Nominal2"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     3
begin
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     4
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     5
atom_decl name
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     6
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     7
nominal_datatype trm =
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     8
  Var "name"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
     9
| App "trm" "trm"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    10
| Let as::"assn" t::"trm"   binds "bn as" in as t
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    11
and assn =
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    12
  ANil
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    13
| ACons "name" "trm" "assn"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    14
binder
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    15
  bn
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    16
where
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    17
  "bn ANil = []"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    18
| "bn (ACons x t as) = (atom x) # (bn as)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    19
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    20
nominal_primrec substrec where
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    21
  "substrec fa fl fd y z (Var x) = (if (y = x) then z else (Var x))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    22
| "substrec fa fl fd y z (App l r) = fa l r"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    23
| "(set (bn as) \<sharp>* (Let as t, y, z) \<and> (\<forall>bs s. set (bn bs) \<sharp>* (Let bs s, y, z) \<longrightarrow> Let as t = Let bs s \<longrightarrow> fl as t = fl bs s)) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    24
   substrec fa fl fd y z (Let as t) = fl as t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    25
| "(set (bn as) \<sharp>* (Let as t, y, z) \<and> \<not>(\<forall>bs s. set (bn bs) \<sharp>* (Let bs s, y, z) \<longrightarrow> Let as t = Let bs s \<longrightarrow> fl as t = fl bs s)) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    26
   substrec fa fl fd y z (Let as t) = fd"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    27
  unfolding eqvt_def substrec_graph_def
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    28
  apply (rule, perm_simp, rule, rule)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    29
  apply (case_tac x)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    30
  apply (rule_tac y="f" and c="(f, d, e)" in trm_assn.strong_exhaust(1))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    31
  apply metis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    32
  apply metis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    33
  apply (thin_tac "\<And>fa fl fd y z xa. x = (fa, fl, fd, y, z, Var xa) \<Longrightarrow> P")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    34
  apply (thin_tac "\<And>fa fl fd y z l r. x = (fa, fl, fd, y, z, App l r) \<Longrightarrow> P")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    35
  apply (drule_tac x="assn" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    36
  apply (drule_tac x="trm" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    37
  apply (drule_tac x="d" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    38
  apply (drule_tac x="e" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    39
  apply (drule_tac x="b" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    40
  apply (drule_tac x="a" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    41
  apply (drule_tac x="c" in meta_spec)+
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    42
  apply (case_tac "(\<forall>bs s.
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    43
             set (bn bs) \<sharp>* (Let bs s, d, e) \<longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    44
             Let.Let assn trm = Let.Let bs s \<longrightarrow> b assn trm = b bs s)")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    45
  apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    46
  apply (thin_tac "set (bn assn) \<sharp>* (Let assn trm, d, e) \<and>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    47
         (\<forall>bs s.
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    48
             set (bn bs) \<sharp>* (Let bs s, d, e) \<longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    49
             Let.Let assn trm = Let.Let bs s \<longrightarrow> b assn trm = b bs s) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    50
         x = (a, b, c, d, e, Let.Let assn trm) \<Longrightarrow> P")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    51
  apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    52
  apply simp_all
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    53
  apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    54
  apply metis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    55
  done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    56
termination (eqvt) by lexicographic_order
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    57
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    58
nominal_primrec substarec :: "(name \<Rightarrow> trm \<Rightarrow> assn \<Rightarrow> assn) \<Rightarrow> assn \<Rightarrow> assn" where
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    59
  "substarec fac ANil = ANil"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    60
| "substarec fac (ACons x t as) = fac x t as"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    61
  unfolding eqvt_def substarec_graph_def
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    62
  apply (rule, perm_simp, rule, rule)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    63
  apply (case_tac x)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    64
  apply (rule_tac y="b" in trm_assn.exhaust(2))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    65
  apply auto
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    66
  done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    67
termination (eqvt) by lexicographic_order
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    68
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    69
lemma [fundef_cong]:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    70
 "(\<And>t1 t2. t = App t1 t2 \<Longrightarrow> fa t1 t2 = fa' t1 t2) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    71
  (\<And>as s. t = Let as s \<Longrightarrow> fl as s = fl' as s) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    72
  substrec fa fl fd y z t = substrec fa' fl' fd y z t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    73
  apply (rule_tac y="t" and c="(t, y, z)" in trm_assn.strong_exhaust(1))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    74
  apply auto
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    75
  apply (case_tac "(\<forall>bs s. set (bn bs) \<sharp>* (Let bs s, y, z) \<longrightarrow> Let assn trm = Let bs s \<longrightarrow> fl assn trm = fl bs s)")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    76
  apply (subst substrec.simps(3)) apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    77
  apply (subst substrec.simps(3)) apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    78
  apply metis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    79
  apply (subst substrec.simps(4)) apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    80
  apply (subst substrec.simps(4)) apply simp_all
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    81
  done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    82
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    83
lemma [fundef_cong]:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    84
 "(\<And>x s as. t = ACons x s as \<Longrightarrow> fac x s as = fac' x s as) \<Longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    85
  substarec fac t = substarec fac' t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    86
  by (rule_tac y="t" in trm_assn.exhaust(2)) simp_all
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    87
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    88
function
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    89
    subst  :: "name \<Rightarrow> trm \<Rightarrow> trm \<Rightarrow> trm"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    90
and substa :: "name \<Rightarrow> trm \<Rightarrow> assn \<Rightarrow> assn"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    91
where
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    92
  [simp del]: "subst y z t = substrec
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    93
     (\<lambda>l r. App (subst y z l) (subst y z r))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    94
     (\<lambda>as t. Let (substa y z as) (subst y z t))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    95
     (Let (ACons y (Var y) ANil) (Var y)) y z t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    96
| [simp del]: "substa y z t = substarec
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    97
     (\<lambda>x t as. ACons x (subst y z t) (substa y z as)) t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    98
  by pat_completeness auto
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
    99
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   100
termination by lexicographic_order
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   101
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   102
lemma testl:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   103
  assumes a: "\<exists>y. f x = Inl y"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   104
  shows "(p \<bullet> (Sum_Type.Projl (f x))) = Sum_Type.Projl ((p \<bullet> f) (p \<bullet> x))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   105
using a
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   106
apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   107
apply(frule_tac p="p" in permute_boolI)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   108
apply(simp (no_asm_use) only: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   109
apply(subst (asm) permute_fun_app_eq)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   110
back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   111
apply(simp)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   112
done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   113
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   114
lemma testr:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   115
  assumes a: "\<exists>y. f x = Inr y"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   116
  shows "(p \<bullet> (Sum_Type.Projr (f x))) = Sum_Type.Projr ((p \<bullet> f) (p \<bullet> x))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   117
using a
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   118
apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   119
apply(frule_tac p="p" in permute_boolI)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   120
apply(simp (no_asm_use) only: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   121
apply(subst (asm) permute_fun_app_eq)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   122
back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   123
apply(simp)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   124
done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   125
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   126
lemma permute_move: "p \<bullet> x = y \<longleftrightarrow> x = -p \<bullet> y"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   127
  by (metis eqvt_bound unpermute_def)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   128
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   129
lemma "subst_substa_graph x t \<Longrightarrow> subst_substa_graph (p \<bullet> x) (p \<bullet> t)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   130
proof (induct arbitrary: p rule: subst_substa_graph.induct)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   131
fix f y z t p
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   132
assume a: "\<And>t1 t2 p. t = App t1 t2 \<Longrightarrow> subst_substa_graph (p \<bullet> Inl (y, z, t1)) (p \<bullet> f (Inl (y, z, t1)))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   133
   and b: "\<And>t1 t2 p. t = App t1 t2 \<Longrightarrow> subst_substa_graph (p \<bullet> Inl (y, z, t2)) (p \<bullet> f (Inl (y, z, t2)))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   134
   and c: "\<And>as s p. t = Let.Let as s \<Longrightarrow> subst_substa_graph (p \<bullet> Inr (y, z, as)) (p \<bullet> f (Inr (y, z, as)))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   135
   and d: "\<And>as s p. t = Let.Let as s \<Longrightarrow> subst_substa_graph (p \<bullet> Inl (y, z, s)) (p \<bullet> f (Inl (y, z, s)))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   136
   then show "subst_substa_graph (p \<bullet> Inl (y, z, t))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   137
           (p \<bullet> Inl (substrec
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   138
                      (\<lambda>l r. App (Sum_Type.Projl (f (Inl (y, z, l))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   139
                              (Sum_Type.Projl (f (Inl (y, z, r)))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   140
                      (\<lambda>as t. Let.Let (Sum_Type.Projr (f (Inr (y, z, as))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   141
                               (Sum_Type.Projl (f (Inl (y, z, t)))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   142
                      (Let.Let (ACons y (Var y) ANil) (Var y)) y z t))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   143
     proof (rule_tac y="t" and c="(t, y, z)" in trm_assn.strong_exhaust(1))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   144
       fix name
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   145
       assume "t = Var name"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   146
       then show ?thesis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   147
         apply (simp add: eqvts split del: if_splits)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   148
         apply (simp only:  trm_assn.perm_simps)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   149
         apply (rule subst_substa_graph.intros(1)[of "Var (p \<bullet> name)" "p \<bullet> y" "p \<bullet> z", simplified])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   150
         by simp_all
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   151
     next
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   152
       fix trm1 trm2
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   153
       assume e: "t = App trm1 trm2"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   154
       then show ?thesis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   155
         apply (simp add: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   156
         apply (subst testl) back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   157
         apply (rule subst_substa_graph.cases[OF a[OF e, of 0, simplified]])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   158
         apply metis apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   159
         apply (subst testl) back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   160
         apply (rule subst_substa_graph.cases[OF b[OF e, of 0, simplified]])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   161
         apply metis apply (simp add: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   162
         apply (simp only: Inl_eqvt) apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   163
         apply (rule subst_substa_graph.intros(1)[of "App (p \<bullet> trm1) (p \<bullet> trm2)" "p \<bullet> y" "p \<bullet> z", simplified])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   164
         apply simp_all apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   165
         using a[OF e, simplified Inl_eqvt, simplified]
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   166
         apply (metis (lifting) Inl_eqvt permute_fun_app_eq permute_prod.simps)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   167
         apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   168
         using b[OF e, simplified Inl_eqvt, simplified]
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   169
         by (metis (lifting) Inl_eqvt permute_fun_app_eq permute_prod.simps)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   170
     next
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   171
       fix assn trm
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   172
       assume e: "t = Let.Let assn trm" and f: "set (bn assn) \<sharp>* (t, y, z)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   173
       then show ?thesis
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   174
         apply (simp add: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   175
         apply (simp only: permute_fun_def)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   176
         apply (simp only: eqvts permute_minus_cancel)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   177
         apply (case_tac "(\<forall>bs s. set (bn bs) \<sharp>* (Let.Let bs s, p \<bullet> y, p \<bullet> z) \<longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   178
                 Let.Let (p \<bullet> assn) (p \<bullet> trm) = Let.Let bs s \<longrightarrow>
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   179
                 Let.Let (p \<bullet> Sum_Type.Projr (f (Inr (y, z, - p \<bullet> p \<bullet> assn))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   180
                  (p \<bullet> Sum_Type.Projl (f (Inl (y, z, - p \<bullet> p \<bullet> trm)))) =
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   181
                 Let.Let (p \<bullet> Sum_Type.Projr (f (Inr (y, z, - p \<bullet> bs))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   182
                  (p \<bullet> Sum_Type.Projl (f (Inl (y, z, - p \<bullet> s)))))")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   183
         prefer 2
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   184
         apply (subst substrec.simps(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   185
         apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   186
         apply (simp add: fresh_star_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   187
         apply (intro conjI)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   188
         apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   189
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   190
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   191
         apply assumption
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   192
         prefer 2
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   193
         apply (subst substrec.simps(3))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   194
         apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   195
         apply (simp add: fresh_star_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   196
         apply (intro conjI)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   197
         apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   198
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   199
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   200
         apply assumption
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   201
(*       The following subgoal is motivated by:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   202
   thm subst_substa_graph.intros(1)[of "Let (p \<bullet> assn) (p \<bullet> trm)" "p \<bullet> y" "p \<bullet> z" "(p \<bullet> f)", simplified]*)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   203
         apply (subgoal_tac "subst_substa_graph (Inl (p \<bullet> y, p \<bullet> z, Let.Let (p \<bullet> assn) (p \<bullet> trm)))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   204
           (Inl (substrec
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   205
           (\<lambda>l r. App (Sum_Type.Projl ((p \<bullet> f) (Inl (p \<bullet> y, p \<bullet> z, l))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   206
                   (Sum_Type.Projl ((p \<bullet> f) (Inl (p \<bullet> y, p \<bullet> z, r)))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   207
           (\<lambda>as t. Let.Let (Sum_Type.Projr ((p \<bullet> f) (Inr (p \<bullet> y, p \<bullet> z, as))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   208
                    (Sum_Type.Projl ((p \<bullet> f) (Inl (p \<bullet> y, p \<bullet> z, t)))))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   209
           (Let.Let (ACons (p \<bullet> y) (Var (p \<bullet> y)) ANil) (Var (p \<bullet> y))) (p \<bullet> y) (p \<bullet> z)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   210
           (Let.Let (p \<bullet> assn) (p \<bullet> trm))))")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   211
         apply (subst (asm) substrec.simps(3))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   212
         apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   213
         apply (simp add: fresh_star_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   214
         apply (intro conjI)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   215
         apply (metis fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4) trm_assn.perm_simps(3))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   216
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   217
         apply (metis (lifting) fresh_star_permute_iff set_eqvt trm_assn.fv_bn_eqvt(4))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   218
         (* We don't have equivariance of Projl/Projr at the arbitrary 'bs' point *)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   219
         defer
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   220
         apply (subst testr) back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   221
         apply (rule subst_substa_graph.cases[OF c[OF e, of 0, simplified]])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   222
         apply simp apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   223
         apply (subst testl) back
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   224
         apply (rule subst_substa_graph.cases[OF d[OF e, of 0, simplified]])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   225
         apply simp apply simp apply simp
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   226
         apply (rule subst_substa_graph.intros(1)[of "Let (p \<bullet> assn) (p \<bullet> trm)" "p \<bullet> y" "p \<bullet> z" "(p \<bullet> f)", simplified])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   227
         apply simp apply simp (* These two should follow by d for arbitrary 'as' point *)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   228
         defer defer
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   229
         sorry
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   230
     qed
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   231
   next
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   232
     fix f y z t p
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   233
     show "subst_substa_graph (p \<bullet> Inr (y, z, t)) (p \<bullet> Inr (substarec (\<lambda>x t as. ACons
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   234
       x (Sum_Type.Projl (f (Inl (y, z, t)))) (Sum_Type.Projr (f (Inr (y, z, as))))) t))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   235
       sorry
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   236
   qed
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   237
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   238
(* Will follow from above and accp *)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   239
lemma [eqvt]:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   240
  "p \<bullet> (subst y z t) = subst (p \<bullet> y) (p \<bullet> z) (p \<bullet> t)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   241
  "p \<bullet> (substa y z t2) = substa (p \<bullet> y) (p \<bullet> z) (p \<bullet> t2)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   242
  sorry
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   243
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   244
lemma substa_simps[simp]:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   245
  "substa y z ANil = ANil"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   246
  "substa y z (ACons x t as) = ACons x (subst y z t) (substa y z as)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   247
  apply (subst substa.simps) apply (subst substarec.simps) apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   248
  apply (subst substa.simps) apply (subst substarec.simps) apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   249
  done
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   250
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   251
lemma bn_substa: "bn (substa y z t) = bn t"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   252
  by (induct t rule: trm_assn.inducts(2)) (simp_all add: trm_assn.bn_defs)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   253
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   254
lemma fresh_fun_eqvt_app3:
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   255
  assumes e: "eqvt f"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   256
  shows "\<lbrakk>a \<sharp> x; a \<sharp> y; a \<sharp> z\<rbrakk> \<Longrightarrow> a \<sharp> f x y z"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   257
  using fresh_fun_eqvt_app[OF e] fresh_fun_app by (metis (lifting, full_types))
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   258
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   259
lemma
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   260
  "subst y z (Var x) = (if (y = x) then z else (Var x))"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   261
  "subst y z (App l r) = App (subst y z l) (subst y z r)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   262
  "set (bn as) \<sharp>* (Let as t, y, z) \<Longrightarrow> subst y z (Let as t) = Let (substa y z as) (subst y z t)"
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   263
  apply (subst subst.simps) apply (subst substrec.simps) apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   264
  apply (subst subst.simps) apply (subst substrec.simps) apply rule
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   265
  apply (subst subst.simps) apply (subst substrec.simps) apply auto
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   266
  apply (subst (asm) Abs_eq_iff2)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   267
  apply clarify
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   268
  apply (simp add: alphas bn_substa)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   269
  apply (rule_tac s="p \<bullet> ([bn as]lst. (substa y z as, subst y z t))" in trans)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   270
  apply (rule sym)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   271
  defer
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   272
  apply (simp add: eqvts)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   273
  apply (subgoal_tac "supp p \<sharp>* y")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   274
  apply (subgoal_tac "supp p \<sharp>* z")
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   275
  apply (simp add: perm_supp_eq)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   276
  apply (simp add: fresh_Pair fresh_star_def)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   277
  apply blast
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   278
  apply (simp add: fresh_Pair fresh_star_def)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   279
  apply blast
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   280
  apply (rule perm_supp_eq)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   281
  apply (simp add: fresh_star_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   282
  apply (simp add: fresh_star_def Abs_fresh_iff)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   283
  apply (auto)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   284
  apply (simp add: bn_substa fresh_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   285
  apply (rule)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   286
  apply (rule fresh_fun_eqvt_app3[of substa])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   287
  apply (simp add: eqvt_def eqvts_raw)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   288
  apply (metis (lifting) Diff_partition Un_iff)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   289
  apply (metis (lifting) Diff_partition Un_iff)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   290
  apply (simp add: fresh_def trm_assn.supp)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   291
  apply (metis (lifting) DiffI UnI1 supp_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   292
  apply (rule fresh_fun_eqvt_app3[of subst])
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   293
  apply (simp add: eqvt_def eqvts_raw)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   294
  apply (metis (lifting) Diff_partition Un_iff)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   295
  apply (metis (lifting) Diff_partition Un_iff)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   296
  apply (simp add: fresh_def trm_assn.supp)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   297
  by (metis Diff_iff Un_iff supp_Pair)
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   298
7ad3b1421b82 A recursive function over let-recs with eqvt problems
Cezary Kaliszyk <cezarykaliszyk@gmail.com>
parents:
diff changeset
   299
end