Nominal/Ex/NBE.thy
author Christian Urban <urbanc@in.tum.de>
Wed, 06 Jul 2011 01:04:09 +0200
changeset 2954 dc6007dd9c30
parent 2953 80f01215d1a6
child 2955 4049a2651dd9
permissions -rw-r--r--
a little further with NBE
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
theory Lambda
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
imports 
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
  "../Nominal2"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
begin
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
atom_decl name
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
nominal_datatype lam =
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  Var "name"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
| App "lam" "lam"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
| Lam x::"name" l::"lam"  binds x in l ("Lam [_]. _" [100, 100] 100)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
nominal_datatype sem =
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
  L "env" x::"name" l::"lam" binds x in l
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
| N "neu"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
and neu = 
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
  V "name"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    20
| A "neu" "sem"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    21
and env =
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    22
  ENil
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    23
| ECons "env" "name" "sem"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    24
2953
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    25
nominal_primrec
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    26
  evals :: "env \<Rightarrow> lam \<Rightarrow> sem" and
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    27
  evals_aux :: "sem \<Rightarrow> lam \<Rightarrow> env \<Rightarrow> sem"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    28
where
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    29
  "evals ENil (Var x) = N (V x)"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    30
| "evals (ECons tail y v) (Var x) = (if x = y then v else evals tail (Var x))" 
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    31
| "evals env (Lam [x]. t) = L env x t"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    32
| "evals env (App t1 t2) = evals_aux (evals env t1) t2 env"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    33
| "evals_aux (L cenv x t) t2 env = evals (ECons cenv x (evals env t2)) t"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    34
| "evals_aux (N n) t2 env = N (A n (evals env t2))"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    35
defer
2953
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    36
apply (rule TrueI)
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    37
--"completeness"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    38
apply(case_tac x)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    39
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    40
apply(case_tac a)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    41
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    42
apply(case_tac aa rule: sem_neu_env.exhaust(3))
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    43
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    44
apply(case_tac b rule: lam.exhaust)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    45
apply(metis)+
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    46
apply(case_tac b rule: lam.exhaust)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    47
apply(metis)+
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    48
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    49
apply(case_tac b)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    50
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    51
apply(case_tac a rule: sem_neu_env.exhaust(1))
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    52
apply(metis)+
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    53
--"compatibility"
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    54
apply(all_trivials)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    55
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    56
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    57
apply(simp)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    58
apply(simp)
2953
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    59
apply (simp add: meta_eq_to_obj_eq[OF evals_def, symmetric, unfolded fun_eq_iff])
2954
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    60
apply (subgoal_tac "eqvt_at (\<lambda>(a, b). evals a b) (ECons cenva x (evals enva t2a), t)")
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    61
apply (subgoal_tac "eqvt_at (\<lambda>(a, b). evals a b) (enva, t2a)")
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    62
apply (subgoal_tac "eqvt_at (\<lambda>(a, b). evals a b) (ECons cenva xa (evals enva t2a), ta)")
2953
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    63
apply (thin_tac "eqvt_at evals_evals_aux_sumC (Inl (ECons cenva x (evals enva t2a), t))")
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    64
apply (thin_tac "eqvt_at evals_evals_aux_sumC (Inl (enva, t2a))")
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    65
apply (thin_tac "eqvt_at evals_evals_aux_sumC (Inl (ECons cenva xa (evals enva t2a), ta))")
2954
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    66
apply(erule conjE)+
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    67
defer
2953
80f01215d1a6 Setup eqvt_at for first goal
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2952
diff changeset
    68
apply (simp_all add: eqvt_at_def evals_def)[3]
2954
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    69
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    70
defer
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    71
apply(erule_tac c="(cenv, env)" in  Abs_lst1_fcb2')
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    72
apply(rule fresh_eqvt_at)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    73
back
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    74
apply(simp add: eqvt_at_def)
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    75
sorry
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    76
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    77
(* can probably not proved by a trivial size argument *)
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    78
termination sorry
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    79
2954
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    80
nominal_primrec
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    81
  reify :: "sem \<Rightarrow> lam" and
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    82
  reifyn :: "neu \<Rightarrow> lam"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    83
where
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    84
  "reify (L env y t) = (fresh_fun (\<lambda>x::name. Lam [x]. (reify (evals (ECons env y (N (V x))) t))))"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    85
| "reify (N n) = reifyn n"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    86
| "reifyn (V x) = Var x"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    87
| "reifyn (A n d) = App (reifyn n) (reify d)"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    88
defer
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    89
defer
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    90
--"completeness"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    91
apply(case_tac x)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    92
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    93
apply(case_tac a rule: sem_neu_env.exhaust(1))
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    94
apply(metis)+
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    95
apply(case_tac b rule: sem_neu_env.exhaust(2))
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    96
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    97
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    98
apply(metis)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
    99
--"compatibility"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   100
apply(all_trivials)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   101
defer
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   102
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   103
apply(simp)
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   104
sorry
2952
e4c2854833ad attempt for NBE
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
   105
2954
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   106
termination sorry
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   107
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   108
definition
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   109
  eval :: "lam \<Rightarrow> sem"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   110
where
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   111
  "eval t = evals ENil t"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   112
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   113
definition
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   114
  normalize :: "lam \<Rightarrow> lam"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   115
where
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   116
  "normalize t = reify (eval t)"
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   117
dc6007dd9c30 a little further with NBE
Christian Urban <urbanc@in.tum.de>
parents: 2953
diff changeset
   118
end