Nominal/Ex/Lambda.thy
author Christian Urban <urbanc@in.tum.de>
Sun, 09 Jan 2011 01:17:44 +0000
changeset 2653 d0f774d06e6e
parent 2649 a8ebcb368a15
child 2654 0f0335d91456
permissions -rw-r--r--
added eqvt_at premises in function definition - however not proved at the moment
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1797
fddb470720f1 renamed ExLam to Lambda and completed the proof of the strong ind principle; tuned paper
Christian Urban <urbanc@in.tum.de>
parents: 1773
diff changeset
     1
theory Lambda
2454
9ffee4eb1ae1 renamed NewParser to Nominal2
Christian Urban <urbanc@in.tum.de>
parents: 2442
diff changeset
     2
imports "../Nominal2" 
1594
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     3
begin
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     4
2645
Christian Urban <urbanc@in.tum.de>
parents: 2634
diff changeset
     5
1594
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     6
atom_decl name
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
     7
2649
a8ebcb368a15 a modified function package where, as a test, True has been injected into the compatibility condictions
Christian Urban <urbanc@in.tum.de>
parents: 2645
diff changeset
     8
ML {* suffix *}
a8ebcb368a15 a modified function package where, as a test, True has been injected into the compatibility condictions
Christian Urban <urbanc@in.tum.de>
parents: 2645
diff changeset
     9
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    10
nominal_datatype lam =
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    11
  Var "name"
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    12
| App "lam" "lam"
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    13
| Lam x::"name" l::"lam"  bind x in l
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2425
diff changeset
    14
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    15
thm lam.distinct
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    16
thm lam.induct
2617
e44551d067e6 properly exported strong exhaust theorem; cleaned up some examples
Christian Urban <urbanc@in.tum.de>
parents: 2559
diff changeset
    17
thm lam.exhaust lam.strong_exhaust
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    18
thm lam.fv_defs
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    19
thm lam.bn_defs
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    20
thm lam.perm_simps
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    21
thm lam.eq_iff
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    22
thm lam.fv_bn_eqvt
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
    23
thm lam.size_eqvt
2431
331873ebc5cd can now deal with type variables in nominal datatype definitions
Christian Urban <urbanc@in.tum.de>
parents: 2425
diff changeset
    24
1810
894930834ca8 fixed bug in thmdecls with destructing Trueprop; some initial infrastructure for eqvt-theorems of the form _ ==> _
Christian Urban <urbanc@in.tum.de>
parents: 1805
diff changeset
    25
1800
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    26
section {* Matching *}
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    27
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    28
definition
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    29
  MATCH :: "('c::pt \<Rightarrow> (bool * 'a::pt * 'b::pt)) \<Rightarrow> 'b \<Rightarrow> 'a \<Rightarrow> 'b"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    30
where
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    31
  "MATCH M d x \<equiv> if (\<exists>!r. \<exists>q. M q = (True, x, r)) then (THE r. \<exists>q. M q = (True, x, r)) else d"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    32
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    33
(*
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    34
lemma MATCH_eqvt:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    35
  shows "p \<bullet> (MATCH M d x) = MATCH (p \<bullet> M) (p \<bullet> d) (p \<bullet> x)"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    36
unfolding MATCH_def
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    37
apply(perm_simp the_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    38
apply (tactic {* Nominal_Permeq.eqvt_tac @{context} 1 *})
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    39
apply(simp)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    40
thm eqvts_raw 
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    41
apply(subst if_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    42
apply(subst ex1_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    43
apply(subst permute_fun_def)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    44
apply(subst ex_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    45
apply(subst permute_fun_def)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    46
apply(subst eq_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    47
apply(subst permute_fun_app_eq[where f="M"])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    48
apply(simp only: permute_minus_cancel)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    49
apply(subst permute_prod.simps)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    50
apply(subst permute_prod.simps)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    51
apply(simp only: permute_minus_cancel)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    52
apply(simp only: permute_bool_def)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    53
apply(simp)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    54
apply(subst ex1_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    55
apply(subst permute_fun_def)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    56
apply(subst ex_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    57
apply(subst permute_fun_def)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    58
apply(subst eq_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    59
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    60
apply(simp only: eqvts)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    61
apply(simp)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    62
apply(subgoal_tac "(p \<bullet> (\<exists>!r. \<exists>q. M q = (True, x, r))) = (\<exists>!r. \<exists>q. (p \<bullet> M) q = (True, p \<bullet> x, r))")
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    63
apply(drule sym)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    64
apply(simp)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    65
apply(rule impI)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    66
apply(simp add: perm_bool)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    67
apply(rule trans)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    68
apply(rule pt_the_eqvt[OF pta at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    69
apply(assumption)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    70
apply(simp add: pt_ex_eqvt[OF pt at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    71
apply(simp add: pt_eq_eqvt[OF ptb at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    72
apply(rule cheat)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    73
apply(rule trans)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    74
apply(rule pt_ex1_eqvt)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    75
apply(rule pta)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    76
apply(rule at)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    77
apply(simp add: pt_ex_eqvt[OF pt at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    78
apply(simp add: pt_eq_eqvt[OF ptb at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    79
apply(subst pt_pi_rev[OF pta at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    80
apply(subst pt_fun_app_eq[OF pt at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    81
apply(subst pt_pi_rev[OF pt at])
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    82
apply(simp)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    83
done
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    84
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    85
lemma MATCH_cng:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    86
  assumes a: "M1 = M2" "d1 = d2"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    87
  shows "MATCH M1 d1 x = MATCH M2 d2 x"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    88
using a by simp
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    89
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    90
lemma MATCH_eq:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    91
  assumes a: "t = l x" "G x" "\<And>x'. t = l x' \<Longrightarrow> G x' \<Longrightarrow> r x' = r x"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    92
  shows "MATCH (\<lambda>x. (G x, l x, r x)) d t = r x"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    93
using a
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    94
unfolding MATCH_def
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    95
apply(subst if_P)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    96
apply(rule_tac a="r x" in ex1I)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    97
apply(rule_tac x="x" in exI)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    98
apply(blast)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
    99
apply(erule exE)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   100
apply(drule_tac x="q" in meta_spec)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   101
apply(auto)[1]
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   102
apply(rule the_equality)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   103
apply(blast)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   104
apply(erule exE)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   105
apply(drule_tac x="q" in meta_spec)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   106
apply(auto)[1]
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   107
done
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   108
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   109
lemma MATCH_eq2:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   110
  assumes a: "t = l x1 x2" "G x1 x2" "\<And>x1' x2'. t = l x1' x2' \<Longrightarrow> G x1' x2' \<Longrightarrow> r x1' x2' = r x1 x2"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   111
  shows "MATCH (\<lambda>(x1,x2). (G x1 x2, l x1 x2, r x1 x2)) d t = r x1 x2"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   112
sorry
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   113
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   114
lemma MATCH_neq:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   115
  assumes a: "\<And>x. t = l x \<Longrightarrow> G x \<Longrightarrow> False"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   116
  shows "MATCH (\<lambda>x. (G x, l x, r x)) d t = d"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   117
using a
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   118
unfolding MATCH_def
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   119
apply(subst if_not_P)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   120
apply(blast)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   121
apply(rule refl)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   122
done
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   123
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   124
lemma MATCH_neq2:
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   125
  assumes a: "\<And>x1 x2. t = l x1 x2 \<Longrightarrow> G x1 x2 \<Longrightarrow> False"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   126
  shows "MATCH (\<lambda>(x1,x2). (G x1 x2, l x1 x2, r x1 x2)) d t = d"
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   127
using a
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   128
unfolding MATCH_def
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   129
apply(subst if_not_P)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   130
apply(auto)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   131
done
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   132
*)
78fdc6b36a1c changed the eqvt-tac to move only outermost permutations inside; added tracing infrastructure for the eqvt-tac
Christian Urban <urbanc@in.tum.de>
parents: 1797
diff changeset
   133
1954
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   134
ML {*
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   135
fun mk_avoids ctxt params name set =
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   136
  let
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   137
    val (_, ctxt') = ProofContext.add_fixes
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   138
      (map (fn (s, T) => (Binding.name s, SOME T, NoSyn)) params) ctxt;
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   139
    fun mk s =
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   140
      let
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   141
        val t = Syntax.read_term ctxt' s;
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   142
        val t' = list_abs_free (params, t) |>
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   143
          funpow (length params) (fn Abs (_, _, t) => t)
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   144
      in (t', HOLogic.dest_setT (fastype_of t)) end
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   145
      handle TERM _ =>
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   146
        error ("Expression " ^ quote s ^ " to be avoided in case " ^
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   147
          quote name ^ " is not a set type");
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   148
    fun add_set p [] = [p]
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   149
      | add_set (t, T) ((u, U) :: ps) =
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   150
          if T = U then
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   151
            let val S = HOLogic.mk_setT T
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   152
            in (Const (@{const_name sup}, S --> S --> S) $ u $ t, T) :: ps
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   153
            end
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   154
          else (u, U) :: add_set (t, T) ps
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   155
  in
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   156
    (mk #> add_set) set 
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   157
  end;
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   158
*}
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   159
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   160
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   161
ML {* 
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   162
  writeln (commas (map (Syntax.string_of_term @{context} o fst) 
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   163
    (mk_avoids @{context} [] "t_Var" "{x}" []))) 
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   164
*}
23480003f9c5 some changes to the paper
Christian Urban <urbanc@in.tum.de>
parents: 1950
diff changeset
   165
1947
51f411b1197d tuned and cleaned
Christian Urban <urbanc@in.tum.de>
parents: 1866
diff changeset
   166
1949
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   167
ML {*
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   168
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   169
fun prove_strong_ind (pred_name, avoids) ctxt = 
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   170
  Proof.theorem NONE (K I) [] ctxt
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   171
2169
61a89e41c55b Renamings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2162
diff changeset
   172
local structure P = Parse and K = Keyword in
1949
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   173
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   174
val _ =
2169
61a89e41c55b Renamings.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2162
diff changeset
   175
  Outer_Syntax.local_theory_to_proof "nominal_inductive"
1949
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   176
    "proves strong induction theorem for inductive predicate involving nominal datatypes" K.thy_goal
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   177
      (P.xname -- (Scan.optional (P.$$$ "avoids" |-- P.enum1 "|" (P.name --
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   178
        (P.$$$ ":" |-- P.and_list1 P.term))) []) >>  prove_strong_ind)
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   179
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   180
end;
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   181
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   182
*}
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   183
1950
7de54c9f81ac eliminated command so that all compiles
Christian Urban <urbanc@in.tum.de>
parents: 1949
diff changeset
   184
(*
1949
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   185
nominal_inductive typing
1950
7de54c9f81ac eliminated command so that all compiles
Christian Urban <urbanc@in.tum.de>
parents: 1949
diff changeset
   186
*)
1949
0b692f37a771 changed theorem_i to theorem....requires new Isabelle
Christian Urban <urbanc@in.tum.de>
parents: 1947
diff changeset
   187
2157
a1d27083e688 subst experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   188
(* Substitution *)
2159
ce00205e07ab Single variable substitution
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2158
diff changeset
   189
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   190
primrec match_Var_raw where
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   191
  "match_Var_raw (Var_raw x) = Some x"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   192
| "match_Var_raw (App_raw x y) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   193
| "match_Var_raw (Lam_raw n t) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   194
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   195
quotient_definition
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   196
  "match_Var :: lam \<Rightarrow> name option"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   197
is match_Var_raw
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   198
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   199
lemma [quot_respect]: "(alpha_lam_raw ===> op =) match_Var_raw match_Var_raw"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   200
  apply rule
2559
add799cf0817 adapted to changes by Florian on the quotient package and removed local fix for function package
Christian Urban <urbanc@in.tum.de>
parents: 2503
diff changeset
   201
  apply (induct_tac x y rule: alpha_lam_raw.induct)
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   202
  apply simp_all
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   203
  done
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   204
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   205
lemmas match_Var_simps = match_Var_raw.simps[quot_lifted]
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   206
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   207
primrec match_App_raw where
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   208
  "match_App_raw (Var_raw x) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   209
| "match_App_raw (App_raw x y) = Some (x, y)"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   210
| "match_App_raw (Lam_raw n t) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   211
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
   212
(*
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   213
quotient_definition
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   214
  "match_App :: lam \<Rightarrow> (lam \<times> lam) option"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   215
is match_App_raw
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   216
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   217
lemma [quot_respect]:
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   218
  "(alpha_lam_raw ===> option_rel (prod_rel alpha_lam_raw alpha_lam_raw)) match_App_raw match_App_raw"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   219
  apply (intro fun_relI)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   220
  apply (induct_tac a b rule: alpha_lam_raw.induct)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   221
  apply simp_all
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   222
  done
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   223
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   224
lemmas match_App_simps = match_App_raw.simps[quot_lifted]
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   225
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   226
definition new where
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   227
  "new (s :: 'a :: fs) = (THE x. \<forall>a \<in> supp s. atom x \<noteq> a)"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   228
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   229
definition
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   230
  "match_Lam (S :: 'a :: fs) t = (if (\<exists>n s. (t = Lam n s)) then
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   231
    (let z = new (S, t) in Some (z, THE s. t = Lam z s)) else None)"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   232
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   233
lemma lam_half_inj: "(Lam z s = Lam z sa) = (s = sa)"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   234
  apply auto
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   235
  apply (simp only: lam.eq_iff alphas)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   236
  apply clarify
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   237
  apply (simp add: eqvts)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   238
  sorry
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   239
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   240
lemma match_Lam_simps:
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   241
  "match_Lam S (Var n) = None"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   242
  "match_Lam S (App l r) = None"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   243
  "z = new (S, (Lam z s)) \<Longrightarrow> match_Lam S (Lam z s) = Some (z, s)"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   244
  apply (simp_all add: match_Lam_def)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   245
  apply (simp add: lam_half_inj)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   246
  apply auto
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   247
  done
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
   248
*)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   249
(*
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   250
lemma match_Lam_simps2:
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   251
  "atom n \<sharp> ((S :: 'a :: fs), Lam n s) \<Longrightarrow> match_Lam S (Lam n s) = Some (n, s)"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   252
  apply (rule_tac t="Lam n s"
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   253
              and s="Lam (new (S, (Lam n s))) ((n \<leftrightarrow> (new (S, (Lam n s)))) \<bullet> s)" in subst)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   254
  defer
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   255
  apply (subst match_Lam_simps(3))
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   256
  defer
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   257
  apply simp
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   258
*)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   259
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   260
(*primrec match_Lam_raw where
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   261
  "match_Lam_raw (S :: atom set) (Var_raw x) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   262
| "match_Lam_raw S (App_raw x y) = None"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   263
| "match_Lam_raw S (Lam_raw n t) = (let z = new (S \<union> (fv_lam_raw t - {atom n})) in Some (z, (n \<leftrightarrow> z) \<bullet> t))"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   264
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   265
quotient_definition
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   266
  "match_Lam :: (atom set) \<Rightarrow> lam \<Rightarrow> (name \<times> lam) option"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   267
is match_Lam_raw
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   268
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   269
lemma swap_fresh:
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   270
  assumes a: "fv_lam_raw t \<sharp>* p"
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   271
  shows "alpha_lam_raw (p \<bullet> t) t"
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   272
  using a apply (induct t)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   273
  apply (simp add: supp_at_base fresh_star_def)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   274
  apply (rule alpha_lam_raw.intros)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   275
  apply (metis Rep_name_inverse atom_eqvt atom_name_def fresh_perm)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   276
  apply (simp)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   277
  apply (simp only: fresh_star_union)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   278
  apply clarify
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   279
  apply (rule alpha_lam_raw.intros)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   280
  apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   281
  apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   282
  apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   283
  apply (rule alpha_lam_raw.intros)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   284
  sorry
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   285
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   286
lemma [quot_respect]:
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   287
  "(op = ===> alpha_lam_raw ===> option_rel (prod_rel op = alpha_lam_raw)) match_Lam_raw match_Lam_raw"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   288
  proof (intro fun_relI, clarify)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   289
    fix S t s
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   290
    assume a: "alpha_lam_raw t s"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   291
    show "option_rel (prod_rel op = alpha_lam_raw) (match_Lam_raw S t) (match_Lam_raw S s)"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   292
      using a proof (induct t s rule: alpha_lam_raw.induct)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   293
      case goal1 show ?case by simp
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   294
    next
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   295
      case goal2 show ?case by simp
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   296
    next
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   297
      case (goal3 x t y s)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   298
      then obtain p where "({atom x}, t) \<approx>gen (\<lambda>x1 x2. alpha_lam_raw x1 x2 \<and>
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   299
                              option_rel (prod_rel op = alpha_lam_raw) (match_Lam_raw S x1)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   300
                               (match_Lam_raw S x2)) fv_lam_raw p ({atom y}, s)" ..
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   301
      then have
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   302
        c: "fv_lam_raw t - {atom x} = fv_lam_raw s - {atom y}" and
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   303
        d: "(fv_lam_raw t - {atom x}) \<sharp>* p" and
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   304
        e: "alpha_lam_raw (p \<bullet> t) s" and
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   305
        f: "option_rel (prod_rel op = alpha_lam_raw) (match_Lam_raw S (p \<bullet> t)) (match_Lam_raw S s)" and
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   306
        g: "p \<bullet> {atom x} = {atom y}" unfolding alphas(1) by - (elim conjE, assumption)+
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   307
      let ?z = "new (S \<union> (fv_lam_raw t - {atom x}))"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   308
      have h: "?z = new (S \<union> (fv_lam_raw s - {atom y}))" using c by simp
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   309
      show ?case
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   310
        unfolding match_Lam_raw.simps Let_def option_rel.simps prod_rel.simps split_conv
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   311
      proof
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   312
        show "?z = new (S \<union> (fv_lam_raw s - {atom y}))" by (fact h)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   313
      next
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   314
        have "atom y \<sharp> p" sorry
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   315
        have "fv_lam_raw t \<sharp>* ((x \<leftrightarrow> y) \<bullet> p)" sorry
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   316
        then have "alpha_lam_raw (((x \<leftrightarrow> y) \<bullet> p) \<bullet> t) t" using swap_fresh by auto
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   317
        then have "alpha_lam_raw (p \<bullet> t) ((x \<leftrightarrow> y) \<bullet> t)" sorry
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   318
        have "alpha_lam_raw t ((x \<leftrightarrow> y) \<bullet> s)" sorry
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   319
        then have "alpha_lam_raw ((x \<leftrightarrow> ?z) \<bullet> t) ((y \<leftrightarrow> ?z) \<bullet> s)" using eqvts(15) sorry
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   320
        then show "alpha_lam_raw ((x \<leftrightarrow> new (S \<union> (fv_lam_raw t - {atom x}))) \<bullet> t)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   321
                  ((y \<leftrightarrow> new (S \<union> (fv_lam_raw s - {atom y}))) \<bullet> s)" unfolding h .
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   322
      qed
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   323
    qed
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   324
  qed
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   325
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   326
lemmas match_Lam_simps = match_Lam_raw.simps[quot_lifted]
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   327
*)
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
   328
(*
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   329
lemma app_some: "match_App x = Some (a, b) \<Longrightarrow> x = App a b"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   330
by (induct x rule: lam.induct) (simp_all add: match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   331
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   332
lemma lam_some: "match_Lam S x = Some (z, s) \<Longrightarrow> x = Lam z s \<and> atom z \<sharp> S"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   333
  apply (induct x rule: lam.induct)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   334
  apply (simp_all add: match_Lam_simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   335
  apply (thin_tac "match_Lam S lam = Some (z, s) \<Longrightarrow> lam = Lam z s \<and> atom z \<sharp> S")
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   336
  apply (simp add: match_Lam_def)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   337
  apply (subgoal_tac "\<exists>n s. Lam name lam = Lam n s")
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   338
  prefer 2
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   339
  apply auto[1]
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   340
  apply (simp add: Let_def)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   341
  apply (thin_tac "\<exists>n s. Lam name lam = Lam n s")
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   342
  apply clarify
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   343
  apply (rule conjI)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   344
  apply (rule_tac t="THE s. Lam name lam = Lam (new (S, Lam name lam)) s" and
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   345
                  s="(name \<leftrightarrow> (new (S, Lam name lam))) \<bullet> lam" in subst)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   346
  defer
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   347
  apply (simp add: lam.eq_iff)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   348
  apply (rule_tac x="(name \<leftrightarrow> (new (S, Lam name lam)))" in exI)
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   349
  apply (simp add: alphas)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   350
  apply (simp add: eqvts)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   351
  apply (rule conjI)
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   352
  sorry
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   353
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   354
function subst where
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   355
"subst v s t = (
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   356
  case match_Var t of Some n \<Rightarrow> if n = v then s else Var n | None \<Rightarrow>
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   357
  case match_App t of Some (l, r) \<Rightarrow> App (subst v s l) (subst v s r) | None \<Rightarrow>
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   358
  case match_Lam (v,s) t of Some (n, t) \<Rightarrow> Lam n (subst v s t) | None \<Rightarrow> undefined)"
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   359
by pat_completeness auto
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   360
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   361
termination apply (relation "measure (\<lambda>(_, _, t). size t)")
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   362
  apply auto[1]
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   363
  apply (case_tac a) apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   364
  apply (frule lam_some) apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   365
  apply (case_tac a) apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   366
  apply (frule app_some) apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   367
  apply (case_tac a) apply simp
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   368
  apply (frule app_some) apply simp
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   369
done
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   370
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   371
lemmas lam_exhaust = lam_raw.exhaust[quot_lifted]
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   372
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   373
lemma subst_eqvt:
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   374
  "p \<bullet> (subst v s t) = subst (p \<bullet> v) (p \<bullet> s) (p \<bullet> t)"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   375
  proof (induct v s t rule: subst.induct)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   376
    case (1 v s t)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   377
    show ?case proof (cases t rule: lam_exhaust)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   378
      fix n
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   379
      assume "t = Var n"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   380
      then show ?thesis by (simp add: match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   381
    next
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   382
      fix l r
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   383
      assume "t = App l r"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   384
      then show ?thesis
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   385
        apply (simp only:)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   386
        apply (subst subst.simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   387
        apply (subst match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   388
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   389
        apply (subst match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   390
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   391
        apply (simp only: prod.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   392
        apply (simp only: lam.perm)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   393
        apply (subst (3) subst.simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   394
        apply (subst match_Var_simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   395
        apply (simp only: option.cases)
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   396
        apply (subst match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   397
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   398
        apply (simp only: prod.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   399
        apply (subst 1(2)[of "(l, r)" "l" "r"])
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   400
        apply (simp add: match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   401
        apply (simp add: match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   402
        apply (rule refl)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   403
        apply (subst 1(3)[of "(l, r)" "l" "r"])
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   404
        apply (simp add: match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   405
        apply (simp add: match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   406
        apply (rule refl)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   407
        apply (rule refl)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   408
        done
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   409
    next
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   410
      fix n t'
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   411
      assume "t = Lam n t'"
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   412
      then show ?thesis
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   413
        apply (simp only: )
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   414
        apply (simp only: lam.perm)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   415
        apply (subst subst.simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   416
        apply (subst match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   417
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   418
        apply (subst match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   419
        apply (simp only: option.cases)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   420
        apply (rule_tac t="Lam n t'" and s="Lam (new ((v, s), Lam n t')) ((n \<leftrightarrow> new ((v, s), Lam n t')) \<bullet> t')" in subst)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   421
        defer
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   422
        apply (subst match_Lam_simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   423
        defer
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   424
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   425
        apply (simp only: prod.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   426
        apply (subst (2) subst.simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   427
        apply (subst match_Var_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   428
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   429
        apply (subst match_App_simps)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   430
        apply (simp only: option.cases)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   431
        apply (rule_tac t="Lam (p \<bullet> n) (p \<bullet> t')" and s="Lam (new ((p \<bullet> v, p \<bullet> s), Lam (p \<bullet> n) (p \<bullet> t'))) (((p \<bullet> n) \<leftrightarrow> new ((p \<bullet> v, p \<bullet> s), Lam (p \<bullet> n) (p \<bullet> t'))) \<bullet> t')" in subst)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   432
        defer
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   433
        apply (subst match_Lam_simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   434
        defer
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   435
        apply (simp only: option.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   436
        apply (simp only: prod.cases)
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   437
        apply (simp only: lam.perm)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   438
        thm 1(1)
2165
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   439
        sorry
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   440
    qed
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   441
  qed
e838f7d90f81 Function experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   442
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   443
lemma subst_proper_eqs:
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   444
  "subst y s (Var x) = (if x = y then s else (Var x))"
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   445
  "subst y s (App l r) = App (subst y s l) (subst y s r)"
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   446
  "atom x \<sharp> (t, s) \<Longrightarrow> subst y s (Lam x t) = Lam x (subst y s t)"
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   447
  apply (subst subst.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   448
  apply (simp only: match_Var_simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   449
  apply (simp only: option.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   450
  apply (subst subst.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   451
  apply (simp only: match_App_simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   452
  apply (simp only: option.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   453
  apply (simp only: prod.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   454
  apply (simp only: match_Var_simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   455
  apply (simp only: option.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   456
  apply (subst subst.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   457
  apply (simp only: match_Var_simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   458
  apply (simp only: option.simps)
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   459
  apply (simp only: match_App_simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   460
  apply (simp only: option.simps)
2173
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   461
  apply (rule_tac t="Lam x t" and s="Lam (new ((y, s), Lam x t)) ((x \<leftrightarrow> new ((y, s), Lam x t)) \<bullet> t)" in subst)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   462
  defer
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   463
  apply (subst match_Lam_simps)
477293d841e8 Match_Lam defined on Quotient Level.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2172
diff changeset
   464
  defer
2172
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   465
  apply (simp only: option.simps)
fd5eec72c3f5 More on Function-defined subst.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2170
diff changeset
   466
  apply (simp only: prod.simps)
2157
a1d27083e688 subst experiments
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents: 2120
diff changeset
   467
  sorry
2436
3885dc2669f9 cleaned up (almost completely) the examples
Christian Urban <urbanc@in.tum.de>
parents: 2434
diff changeset
   468
*)
1594
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   469
end
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   470
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   471
892fcdb96c96 Move LamEx out of Test.
Cezary Kaliszyk <kaliszyk@in.tum.de>
parents:
diff changeset
   472