src/HOL/Proofs/Lambda/NormalForm.thy
author wenzelm
Wed, 12 Mar 2025 11:39:00 +0100
changeset 82265 4b875a4c83b0
parent 81292 137b0b107c4b
permissions -rw-r--r--
update for release;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39157
b98909faaea8 more explicit HOL-Proofs sessions, including former ex/Hilbert_Classical.thy which works in parallel mode without the antiquotation option "margin" (which is still critical);
wenzelm
parents: 33704
diff changeset
     1
(*  Title:      HOL/Proofs/Lambda/NormalForm.thy
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     2
    Author:     Stefan Berghofer, TU Muenchen, 2003
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     3
*)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     4
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
     5
section \<open>Inductive characterization of lambda terms in normal form\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     6
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     7
theory NormalForm
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     8
imports ListBeta
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
     9
begin
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    10
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    11
subsection \<open>Terms in normal form\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    12
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    13
definition
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    14
  listall :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> bool" where
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    15
  "listall P xs \<equiv> (\<forall>i. i < length xs \<longrightarrow> P (xs ! i))"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    16
33704
6aeb8454efc1 add_expand_thm: explicit indication of is_def instead of fragile heuristic, tuned signature;
wenzelm
parents: 32960
diff changeset
    17
declare listall_def [extraction_expand_def]
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    18
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    19
theorem listall_nil: "listall P []"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    20
  by (simp add: listall_def)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    21
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    22
theorem listall_nil_eq [simp]: "listall P [] = True"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    23
  by (iprover intro: listall_nil)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    24
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    25
theorem listall_cons: "P x \<Longrightarrow> listall P xs \<Longrightarrow> listall P (x # xs)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    26
  apply (simp add: listall_def)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    27
  apply (rule allI impI)+
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    28
  apply (case_tac i)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    29
  apply simp+
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    30
  done
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    31
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    32
theorem listall_cons_eq [simp]: "listall P (x # xs) = (P x \<and> listall P xs)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    33
  apply (rule iffI)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    34
  prefer 2
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    35
  apply (erule conjE)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    36
  apply (erule listall_cons)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    37
  apply assumption
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    38
  apply (unfold listall_def)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    39
  apply (rule conjI)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    40
  apply (erule_tac x=0 in allE)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    41
  apply simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    42
  apply simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    43
  apply (rule allI)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    44
  apply (erule_tac x="Suc i" in allE)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    45
  apply simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    46
  done
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    47
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    48
lemma listall_conj1: "listall (\<lambda>x. P x \<and> Q x) xs \<Longrightarrow> listall P xs"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    49
  by (induct xs) simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    50
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    51
lemma listall_conj2: "listall (\<lambda>x. P x \<and> Q x) xs \<Longrightarrow> listall Q xs"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    52
  by (induct xs) simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    53
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    54
lemma listall_app: "listall P (xs @ ys) = (listall P xs \<and> listall P ys)"
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    55
  by (induct xs; intro iffI; simp)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    56
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    57
lemma listall_snoc [simp]: "listall P (xs @ [x]) = (listall P xs \<and> P x)"
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    58
  by (rule iffI; simp add: listall_app)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    59
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    60
lemma listall_cong [cong, extraction_expand]:
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    61
  "xs = ys \<Longrightarrow> listall P xs = listall P ys"
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    62
  \<comment> \<open>Currently needed for strange technical reasons\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    63
  by (unfold listall_def) simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    64
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    65
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67443
diff changeset
    66
\<^term>\<open>listsp\<close> is equivalent to \<^term>\<open>listall\<close>, but cannot be
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    67
used for program extraction.
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
    68
\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    69
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    70
lemma listall_listsp_eq: "listall P xs = listsp P xs"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    71
  by (induct xs) (auto intro: listsp.intros)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    72
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    73
inductive NF :: "dB \<Rightarrow> bool"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    74
where
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    75
  App: "listall NF ts \<Longrightarrow> NF (Var x \<degree>\<degree> ts)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    76
| Abs: "NF t \<Longrightarrow> NF (Abs t)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    77
monos listall_def
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    78
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    79
lemma nat_eq_dec: "\<And>n::nat. m = n \<or> m \<noteq> n"
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    80
proof (induction m)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    81
  case 0
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    82
  then show ?case
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    83
    by (cases n; simp only: nat.simps; iprover)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    84
next
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    85
  case (Suc m)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    86
  then show ?case
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    87
    by (cases n; simp only: nat.simps; iprover)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    88
qed
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    89
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
    90
lemma nat_le_dec: "\<And>n::nat. m < n \<or> \<not> (m < n)"
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    91
proof (induction m)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    92
  case 0
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    93
  then show ?case
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    94
    by (cases n; simp only: order.irrefl zero_less_Suc; iprover)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    95
next
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    96
  case (Suc m)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    97
  then show ?case
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    98
    by (cases n; simp only: not_less_zero Suc_less_eq; iprover)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
    99
qed
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   100
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   101
lemma App_NF_D: assumes NF: "NF (Var n \<degree>\<degree> ts)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   102
  shows "listall NF ts" using NF
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   103
  by cases simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   104
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   105
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   106
subsection \<open>Properties of \<open>NF\<close>\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   107
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   108
lemma Var_NF: "NF (Var n)"
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   109
proof -
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   110
  have "NF (Var n \<degree>\<degree> [])"
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   111
    by (rule NF.App) simp
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   112
  then show ?thesis by simp
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   113
qed
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   114
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   115
lemma Abs_NF:
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   116
  assumes NF: "NF (Abs t \<degree>\<degree> ts)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   117
  shows "ts = []" using NF
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   118
proof cases
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   119
  case (App us i)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   120
  thus ?thesis by (simp add: Var_apps_neq_Abs_apps [THEN not_sym])
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   121
next
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   122
  case (Abs u)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   123
  thus ?thesis by simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   124
qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   125
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   126
lemma subst_terms_NF: "listall NF ts \<Longrightarrow>
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   127
    listall (\<lambda>t. \<forall>i j. NF (t[Var i/j])) ts \<Longrightarrow>
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   128
    listall NF (map (\<lambda>t. t[Var i/j]) ts)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   129
  by (induct ts) simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   130
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   131
lemma subst_Var_NF: "NF t \<Longrightarrow> NF (t[Var i/j])"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   132
  apply (induct arbitrary: i j set: NF)
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   133
   apply simp
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   134
   apply (frule listall_conj1)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   135
   apply (drule listall_conj2)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   136
   apply (drule_tac i=i and j=j in subst_terms_NF)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   137
    apply assumption
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   138
   apply (rule_tac m1=x and n1=j in nat_eq_dec [THEN disjE])
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   139
    apply simp
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   140
    apply (erule NF.App)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   141
   apply (rule_tac m1=j and n1=x in nat_le_dec [THEN disjE])
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   142
    apply (simp_all add: NF.App NF.Abs)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   143
  done
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   144
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   145
lemma app_Var_NF: "NF t \<Longrightarrow> \<exists>t'. t \<degree> Var i \<rightarrow>\<^sub>\<beta>\<^sup>* t' \<and> NF t'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   146
  apply (induct set: NF)
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   147
   apply (simplesubst app_last)  \<comment> \<open>Using \<open>subst\<close> makes extraction fail\<close>
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   148
   apply (rule exI)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   149
   apply (rule conjI)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   150
    apply (rule rtranclp.rtrancl_refl)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   151
   apply (rule NF.App)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   152
   apply (drule listall_conj1)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   153
   apply (simp add: listall_app)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   154
   apply (rule Var_NF)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   155
  apply (iprover intro: rtranclp.rtrancl_into_rtrancl rtranclp.rtrancl_refl beta subst_Var_NF)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   156
  done
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   157
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   158
lemma lift_terms_NF: "listall NF ts \<Longrightarrow>
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   159
    listall (\<lambda>t. \<forall>i. NF (lift t i)) ts \<Longrightarrow>
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   160
    listall NF (map (\<lambda>t. lift t i) ts)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   161
  by (induct ts) simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   162
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   163
lemma lift_NF: "NF t \<Longrightarrow> NF (lift t i)"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   164
  apply (induct arbitrary: i set: NF)
81292
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   165
   apply (frule listall_conj1)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   166
   apply (drule listall_conj2)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   167
   apply (drule_tac i=i in lift_terms_NF)
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   168
    apply assumption
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   169
   apply (rule_tac m1=x and n1=i in nat_le_dec [THEN disjE])
137b0b107c4b Trying to clean up these horribly ugly old proofs, but the requirement of constructivity makes it very difficult
paulson <lp15@cam.ac.uk>
parents: 71959
diff changeset
   170
    apply (simp_all add: NF.App NF.Abs)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   171
  done
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   172
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   173
text \<open>
69597
ff784d5a5bfb isabelle update -u control_cartouches;
wenzelm
parents: 67443
diff changeset
   174
\<^term>\<open>NF\<close> characterizes exactly the terms that are in normal form.
61986
2461779da2b8 isabelle update_cartouches -c -t;
wenzelm
parents: 58889
diff changeset
   175
\<close>
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   176
  
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   177
lemma NF_eq: "NF t = (\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t')"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   178
proof
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   179
  assume "NF t"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   180
  then have "\<And>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   181
  proof induct
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   182
    case (App ts t)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   183
    show ?case
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   184
    proof
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   185
      assume "Var t \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> t'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   186
      then obtain rs where "ts => rs"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24537
diff changeset
   187
        by (iprover dest: head_Var_reduction)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   188
      with App show False
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24537
diff changeset
   189
        by (induct rs arbitrary: ts) auto
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   190
    qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   191
  next
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   192
    case (Abs t)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   193
    show ?case
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   194
    proof
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   195
      assume "Abs t \<rightarrow>\<^sub>\<beta> t'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   196
      then show False using Abs by cases simp_all
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   197
    qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   198
  qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   199
  then show "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'" ..
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   200
next
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   201
  assume H: "\<forall>t'. \<not> t \<rightarrow>\<^sub>\<beta> t'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   202
  then show "NF t"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   203
  proof (induct t rule: Apps_dB_induct)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   204
    case (1 n ts)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   205
    then have "\<forall>ts'. \<not> ts => ts'"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   206
      by (iprover intro: apps_preserves_betas)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   207
    with 1(1) have "listall NF ts"
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   208
      by (induct ts) auto
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   209
    then show ?case by (rule NF.App)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   210
  next
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   211
    case (2 u ts)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   212
    show ?case
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   213
    proof (cases ts)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   214
      case Nil
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   215
      from 2 have "\<forall>u'. \<not> u \<rightarrow>\<^sub>\<beta> u'"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24537
diff changeset
   216
        by (auto intro: apps_preserves_beta)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   217
      then have "NF u" by (rule 2)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   218
      then have "NF (Abs u)" by (rule NF.Abs)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   219
      with Nil show ?thesis by simp
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   220
    next
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   221
      case (Cons r rs)
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   222
      have "Abs u \<degree> r \<rightarrow>\<^sub>\<beta> u[r/0]" ..
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   223
      then have "Abs u \<degree> r \<degree>\<degree> rs \<rightarrow>\<^sub>\<beta> u[r/0] \<degree>\<degree> rs"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24537
diff changeset
   224
        by (rule apps_preserves_beta)
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   225
      with Cons have "Abs u \<degree>\<degree> ts \<rightarrow>\<^sub>\<beta> u[r/0] \<degree>\<degree> rs"
32960
69916a850301 eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents: 24537
diff changeset
   226
        by simp
24537
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   227
      with 2 show ?thesis by iprover
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   228
    qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   229
  qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   230
qed
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   231
57c7dfaa0153 Definition of normal forms (taken from theory WeakNorm).
berghofe
parents:
diff changeset
   232
end