Nominal/Ex/PaperTest.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 04 Jan 2012 17:42:16 +0000
changeset 3105 1b0d230445ce
parent 2802 3b9ef98a03d2
child 3235 5ebd327ffb96
permissions -rw-r--r--
added an FCB for res (will not define evry function, but is a good datapoint)
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2783
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory PaperTest
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports "../Nominal2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
begin
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
atom_decl name 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
datatype trm = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
  Const "string"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
| Var "name"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
| App "trm" "trm"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
| Lam "name" "trm"  ("Lam [_]. _" [100, 100] 100)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
  subst :: "trm \<Rightarrow> name \<Rightarrow> name \<Rightarrow> trm"  ("_[_::=_]" [100,100,100] 100)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  "(Var x)[y::=p] = (if x=y then (App (App (Const ''unpermute'') (Var p)) (Var x)) else (Var x))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
| "(App t\<^isub>1 t\<^isub>2)[y::=p] = App (t\<^isub>1[y::=p]) (t\<^isub>2[y::=p])"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
| "(Lam [x].t)[y::=p] = (if x=y then (Lam [x].t) else Lam [x].(t[y::=p]))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
| "(Const n)[y::=p] = Const n"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
datatype utrm = 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  UConst "string"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
| UnPermute "name" "name"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
| UVar "name"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    25
| UApp "utrm" "utrm"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
| ULam "name" "utrm"  ("ULam [_]. _" [100, 100] 100)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  usubst :: "utrm \<Rightarrow> name \<Rightarrow> name \<Rightarrow> utrm"  ("_[_:::=_]" [100,100,100] 100)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
where
2802
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    31
  "(UVar x)[y:::=p] = (if x=y then UnPermute p x else (UVar x))"
2783
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
| "(UApp t\<^isub>1 t\<^isub>2)[y:::=p] = UApp (t\<^isub>1[y:::=p]) (t\<^isub>2[y:::=p])"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
| "(ULam [x].t)[y:::=p] = (if x=y then (ULam [x].t) else ULam [x].(t[y:::=p]))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
| "(UConst n)[y:::=p] = UConst n"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
| "(UnPermute x q)[y:::=p] = UnPermute x q"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    36
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
function
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
  ss :: "trm \<Rightarrow> nat"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
  "ss (Var x) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
| "ss (Const s) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
| "ss (Lam [x].t) = 1 + ss t"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
| "ss (App (App (Const ''unpermute'') (Var p)) (Var x)) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
| "\<not>(\<exists>p x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x)) \<Longrightarrow> ss (App t1 t2) = 1 + ss t1 + ss t2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
defer
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
apply(case_tac x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
apply(blast)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
termination
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
  apply(relation "measure (\<lambda>t. size t)")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
  apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
  done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    59
fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    60
  uss :: "utrm \<Rightarrow> nat"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    61
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    62
  "uss (UVar x) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    63
| "uss (UConst s) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    64
| "uss (ULam [x].t) = 1 + uss t"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    65
| "uss (UnPermute x y) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    66
| "uss (UApp t1 t2) = 1 + uss t1 + uss t2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    68
lemma trm_uss:
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    69
  shows "uss (t[x:::=p]) = uss t"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    70
apply(induct rule: uss.induct)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    71
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    72
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    73
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    74
inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
  ufree :: "utrm \<Rightarrow> bool"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
  "ufree (UVar x)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
| "s \<noteq> ''unpermute'' \<Longrightarrow> ufree (UConst s)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
| "ufree t \<Longrightarrow> ufree (ULam [x].t)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    80
| "ufree (UnPermute x y)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    81
| "\<lbrakk>ufree t1; ufree t2\<rbrakk> \<Longrightarrow> ufree (UApp t1 t2)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    82
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    83
fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    84
  trans :: "utrm \<Rightarrow> trm" ("\<parallel>_\<parallel>" [100] 100)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    85
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    86
  "\<parallel>(UVar x)\<parallel> = Var x"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    87
| "\<parallel>(UConst x)\<parallel> = Const x"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    88
| "\<parallel>(UnPermute p x)\<parallel> = (App (App (Const ''unpermute'') (Var p)) (Var x))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    89
| "\<parallel>(ULam [x].t)\<parallel> = Lam [x].(\<parallel>t\<parallel>)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    90
| "\<parallel>(UApp t1 t2)\<parallel> = App (\<parallel>t1\<parallel>) (\<parallel>t2\<parallel>)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    91
2802
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    92
function
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    93
  utrans :: "trm \<Rightarrow> utrm" ("\<lparr>_\<rparr>" [90] 100)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    94
where
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    95
  "\<lparr>Var x\<rparr> = UVar x"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    96
| "\<lparr>Const x\<rparr> = UConst x"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    97
| "\<lparr>Lam [x].t\<rparr> = ULam [x].\<lparr>t\<rparr>"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    98
| "\<lparr>App (App (Const ''unpermute'') (Var p)) (Var x)\<rparr> = UnPermute p x"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
    99
| "\<not>(\<exists>p x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x)) \<Longrightarrow> \<lparr>App t1 t2\<rparr> = UApp (\<lparr>t1\<rparr>) (\<lparr>t2\<rparr>)"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   100
defer
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   101
apply(simp_all)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   102
apply(auto)[1]
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   103
apply(case_tac x)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   104
apply(simp_all)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   105
apply(auto)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   106
apply(blast)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   107
done
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   108
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   109
termination
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   110
  apply(relation "measure (\<lambda>t. size t)")
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   111
  apply(simp_all)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   112
  done
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   113
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   114
2783
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   115
lemma elim1:
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   116
  "ufree t \<Longrightarrow> \<parallel>t\<parallel> \<noteq>(Const ''unpermute'')"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   117
apply(erule ufree.induct)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   118
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   119
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   120
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   121
lemma elim2:
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   122
  "ufree t \<Longrightarrow> \<not>(\<exists>p. \<parallel>t\<parallel> = App (Const ''unpermute'') (Var p))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   123
apply(erule ufree.induct)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   124
apply(auto dest: elim1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   125
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   126
2802
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   127
lemma ss1:
2783
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   128
  "ufree t \<Longrightarrow> uss t = ss (\<parallel>t\<parallel>)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   129
apply(erule ufree.induct)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   130
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   131
apply(subst ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   132
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   133
apply(drule elim2)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   134
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   135
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   136
2802
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   137
lemma trans1:
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   138
  shows "\<parallel>\<lparr>t\<rparr>\<parallel> = t"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   139
apply(induct t)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   140
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   141
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   142
prefer 2
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   143
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   144
apply(case_tac "(\<exists>p x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x))")
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   145
apply(erule exE)+
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   146
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   147
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   148
done
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   149
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   150
lemma trans_subst:
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   151
  shows "\<lparr>t[x ::= p]\<rparr> = \<lparr>t\<rparr>[x :::= p]"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   152
apply(induct rule: subst.induct)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   153
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   154
defer
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   155
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   156
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   157
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   158
apply(case_tac "(t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x))")
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   159
apply(erule exE)+
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   160
apply(simp only:)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   161
apply(subst utrans.simps)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   162
apply(subst usubst.simps)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   163
apply(case_tac "xa = x")
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   164
apply(subst (asm) subst.simps)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   165
apply(simp only:)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   166
apply(subst (asm) utrans.simps)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   167
apply(simp only: usubst.simps)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   168
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   169
apply(auto)[1]
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   170
apply(case_tac "pa = x")
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   171
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   172
prefer 2
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   173
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   174
apply(simp)
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   175
done
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   176
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   177
lemma 
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   178
  "ss (t[x ::= p]) = ss t"
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   179
apply(subst (2) trans1[symmetric])
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   180
apply(subst ss1[symmetric])
3b9ef98a03d2 first test to fix the problem with free variables
Christian Urban <urbanc@in.tum.de>
parents: 2783
diff changeset
   181
2783
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   182
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   183
fun
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   184
  fr :: "trm \<Rightarrow> name set"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   185
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   186
  "fr (Var x) = {x}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   187
| "fr (Const s) = {}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   188
| "fr (Lam [x].t) = fr t - {x}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   189
| "fr (App t1 t2) = fr t1 \<union> fr t2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   190
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   191
function
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   192
  sfr :: "trm \<Rightarrow> name set"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   193
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   194
  "sfr (Var x) = {}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   195
| "sfr (Const s) = {}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   196
| "sfr (Lam [x].t) = sfr t - {x}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   197
| "sfr (App (App (Const ''unpermute'') (Var p)) (Var x)) = {p, x}"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   198
| "\<not>(\<exists>p x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x)) \<Longrightarrow> sfr (App t1 t2) = sfr t1 \<union> sfr t2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   199
defer
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   200
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   201
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   202
apply(case_tac x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   203
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   204
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   205
apply(blast)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   206
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   207
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   208
termination
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   209
  apply(relation "measure (\<lambda>t. size t)")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   210
  apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   211
  done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   212
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   213
function
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   214
  ss :: "trm \<Rightarrow> nat"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   215
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   216
  "ss (Var x) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   217
| "ss (Const s) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   218
| "ss (Lam [x].t) = 1 + ss t"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   219
| "ss (App (App (Const ''unpermute'') (Var p)) (Var x)) = 1"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   220
| "\<not>(\<exists>p x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x)) \<Longrightarrow> ss (App t1 t2) = 1 + ss t1 + ss t2"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   221
defer
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   222
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   223
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   224
apply(case_tac x)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   225
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   226
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   227
apply(blast)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   228
done 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   229
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   230
termination
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   231
  apply(relation "measure (\<lambda>t. size t)")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   232
  apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   233
  done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   234
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   235
inductive
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   236
  improper :: "trm \<Rightarrow> bool"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   237
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   238
  "improper (App (App (Const ''unpermute'') (Var p)) (Var x))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   239
| "improper p x t \<Longrightarrow> improper p x (Lam [y].t)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   240
| "\<lbrakk>improper p x t1; improper p x t2\<rbrakk> \<Longrightarrow> improper p x (App t1 t2)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   241
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   242
lemma trm_ss:
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   243
  shows "\<not>improper p x t \<Longrightarrow> ss (t[x::= p]) = ss t"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   244
apply(induct rule: ss.induct)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   245
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   246
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   247
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   248
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   249
apply(case_tac "improper p x t")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   250
apply(drule improper.intros(2))
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   251
apply(blast)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   252
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   253
using improper.intros(1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   254
apply(blast)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   255
apply(erule contrapos_pn)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   256
thm contrapos_np
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   257
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   258
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   259
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   260
apply(erule disjE)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   261
apply(erule conjE)+
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   262
apply(subst ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   263
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   264
apply(rule disjI1)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   265
apply(rule allI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   266
apply(rule notI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   267
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   268
apply(simp del: ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   269
apply(erule disjE)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   270
apply(subst ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   271
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   272
apply(simp only: subst.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   273
apply(subst ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   274
apply(simp del: ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   275
apply(rule conjI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   276
apply(rule impI)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   277
apply(erule conjE)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   278
apply(erule exE)+
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   279
apply(subst ss.simps)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   280
apply(simp)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   281
apply(auto)[1]
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   282
apply(simp add: if_splits)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   283
apply()
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   284
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   285
function
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   286
  simp :: "name \<Rightarrow> trm \<Rightarrow> trm"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   287
where
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   288
  "simp p (Const c) = (Const c)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   289
| "simp p (Var x) = App (App (Const ''permute'') (Var p)) (Var x)"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   290
| "simp p (App t1 t2) = (if ((\<exists>x. t1 = App (Const ''unpermute'') (Var p) \<and> t2 = (Var x))) 
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   291
                         then t2
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   292
                         else App (simp p t1) (simp p t2))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   293
| "simp p (Lam [x].t) = Lam [x]. (simp p (t[x ::= p]))"
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   294
apply(pat_completeness)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   295
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   296
apply(auto)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   297
done
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   298
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   299
termination
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   300
apply(relation "measure (\<lambda>(_, t). size t)")
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   301
apply(simp_all)
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   302
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   303
end