thys/Recs.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 02 May 2013 08:31:48 +0100
changeset 245 af60d84e0677
parent 244 8dba6ae39bf0
child 246 e113420a2fce
permissions -rwxr-xr-x
introduced rec_if
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     1
theory Recs
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     2
imports Main Fact "~~/src/HOL/Number_Theory/Primes"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     3
begin
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     4
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     5
(*
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     6
  some definitions from 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     7
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     8
    A Course in Formal Languages, Automata and Groups
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     9
    I M Chiswell 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    10
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    11
  and
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    12
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    13
    Lecture on undecidability
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    14
    Michael M. Wolf 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    15
*)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    16
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    17
lemma if_zero_one [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    18
  "(if P then 1 else 0) = (0::nat) \<longleftrightarrow> \<not> P"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
  "(0::nat) < (if P then 1 else 0) = P"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    20
  "(if P then 0 else 1) = (if \<not>P then 1 else (0::nat))"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
by (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    22
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    23
lemma nth:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
  "(x # xs) ! 0 = x"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
  "(x # y # xs) ! 1 = y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    26
  "(x # y # z # xs) ! 2 = z"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
  "(x # y # z # u # xs) ! 3 = u"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    28
by (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    30
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    31
section {* Some auxiliary lemmas about @{text "\<Sum>"} and @{text "\<Prod>"} *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    32
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    33
lemma setprod_atMost_Suc[simp]: 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    34
  "(\<Prod>i \<le> Suc n. f i) = (\<Prod>i \<le> n. f i) * f(Suc n)"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    35
by(simp add:atMost_Suc mult_ac)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    36
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    37
lemma setprod_lessThan_Suc[simp]: 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    38
  "(\<Prod>i < Suc n. f i) = (\<Prod>i < n. f i) * f n"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    39
by (simp add:lessThan_Suc mult_ac)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    40
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    41
lemma setsum_add_nat_ivl2: "n \<le> p  \<Longrightarrow>
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    42
  setsum f {..<n} + setsum f {n..p} = setsum f {..p::nat}"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
apply(subst setsum_Un_disjoint[symmetric])
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    44
apply(auto simp add: ivl_disj_un_one)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    46
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    47
lemma setsum_eq_zero [simp]:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    48
  fixes f::"nat \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    49
  shows "(\<Sum>i < n. f i) = 0 \<longleftrightarrow> (\<forall>i < n. f i = 0)" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    50
        "(\<Sum>i \<le> n. f i) = 0 \<longleftrightarrow> (\<forall>i \<le> n. f i = 0)" 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
by (auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    52
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
lemma setprod_eq_zero [simp]:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    54
  fixes f::"nat \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    55
  shows "(\<Prod>i < n. f i) = 0 \<longleftrightarrow> (\<exists>i < n. f i = 0)" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    56
        "(\<Prod>i \<le> n. f i) = 0 \<longleftrightarrow> (\<exists>i \<le> n. f i = 0)" 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
by (auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    58
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    59
lemma setsum_one_less:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
  fixes n::nat
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
  assumes "\<forall>i < n. f i \<le> 1" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    62
  shows "(\<Sum>i < n. f i) \<le> n"  
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
using assms
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    64
by (induct n) (auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    65
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    66
lemma setsum_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    67
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    68
  assumes "\<forall>i \<le> n. f i \<le> 1" 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    69
  shows "(\<Sum>i \<le> n. f i) \<le> Suc n"  
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    70
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    71
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    72
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    73
lemma setsum_eq_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    74
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    75
  assumes "\<forall>i \<le> n. f i = 1" 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    76
  shows "(\<Sum>i \<le> n. f i) = Suc n"  
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    77
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    78
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    79
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    80
lemma setsum_least_eq:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    81
  fixes f::"nat \<Rightarrow> nat"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    82
  assumes h0: "p \<le> n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    83
  assumes h1: "\<forall>i \<in> {..<p}. f i = 1"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    84
  assumes h2: "\<forall>i \<in> {p..n}. f i = 0"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    85
  shows "(\<Sum>i \<le> n. f i) = p"  
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    86
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
  have eq_p: "(\<Sum>i \<in> {..<p}. f i) = p" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    88
    using h1 by (induct p) (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    89
  have eq_zero: "(\<Sum>i \<in> {p..n}. f i) = 0" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    90
    using h2 by auto
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    91
  have "(\<Sum>i \<le> n. f i) = (\<Sum>i \<in> {..<p}. f i) + (\<Sum>i \<in> {p..n}. f i)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    92
    using h0 by (simp add: setsum_add_nat_ivl2) 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    93
  also have "... = (\<Sum>i \<in> {..<p}. f i)" using eq_zero by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  finally show "(\<Sum>i \<le> n. f i) = p" using eq_p by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    95
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    96
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    97
lemma nat_mult_le_one:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    98
  fixes m n::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    99
  assumes "m \<le> 1" "n \<le> 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   100
  shows "m * n \<le> 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   101
using assms by (induct n) (auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   102
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
lemma setprod_one_le:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   104
  fixes f::"nat \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   105
  assumes "\<forall>i \<le> n. f i \<le> 1" 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   106
  shows "(\<Prod>i \<le> n. f i) \<le> 1" 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   107
using assms by (induct n) (auto intro: nat_mult_le_one)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   108
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   109
lemma setprod_greater_zero:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   110
  fixes f::"nat \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   111
  assumes "\<forall>i \<le> n. f i \<ge> 0" 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
  shows "(\<Prod>i \<le> n. f i) \<ge> 0" 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   113
using assms by (induct n) (auto)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   115
lemma setprod_eq_one:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   116
  fixes f::"nat \<Rightarrow> nat"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
  assumes "\<forall>i \<le> n. f i = Suc 0" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
  shows "(\<Prod>i \<le> n. f i) = Suc 0" 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   119
using assms by (induct n) (auto)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   121
lemma setsum_cut_off_less:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   122
  fixes f::"nat \<Rightarrow> nat"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
  assumes h1: "m \<le> n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
  and     h2: "\<forall>i \<in> {m..<n}. f i = 0"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   125
  shows "(\<Sum>i < n. f i) = (\<Sum>i < m. f i)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   127
  have eq_zero: "(\<Sum>i \<in> {m..<n}. f i) = 0" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   128
    using h2 by auto
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
  have "(\<Sum>i < n. f i) = (\<Sum>i \<in> {..<m}. f i) + (\<Sum>i \<in> {m..<n}. f i)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
    using h1 by (metis atLeast0LessThan le0 setsum_add_nat_ivl) 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   131
  also have "... = (\<Sum>i \<in> {..<m}. f i)" using eq_zero by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   132
  finally show "(\<Sum>i < n. f i) = (\<Sum>i < m. f i)" by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   133
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   134
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
lemma setsum_cut_off_le:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   136
  fixes f::"nat \<Rightarrow> nat"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
  assumes h1: "m \<le> n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
  and     h2: "\<forall>i \<in> {m..n}. f i = 0"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
  shows "(\<Sum>i \<le> n. f i) = (\<Sum>i < m. f i)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   141
  have eq_zero: "(\<Sum>i \<in> {m..n}. f i) = 0" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
    using h2 by auto
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
  have "(\<Sum>i \<le> n. f i) = (\<Sum>i \<in> {..<m}. f i) + (\<Sum>i \<in> {m..n}. f i)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
    using h1 by (simp add: setsum_add_nat_ivl2)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   145
  also have "... = (\<Sum>i \<in> {..<m}. f i)" using eq_zero by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   146
  finally show "(\<Sum>i \<le> n. f i) = (\<Sum>i < m. f i)" by simp
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   147
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   148
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
lemma setprod_one [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   150
  fixes n::nat
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
  shows "(\<Prod>i < n. Suc 0) = Suc 0"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
        "(\<Prod>i \<le> n. Suc 0) = Suc 0"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
by (induct n) (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   155
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   156
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   157
section {* Recursive Functions *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   158
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   159
datatype recf =  Z
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   160
              |  S
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   161
              |  Id nat nat
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   162
              |  Cn nat recf "recf list"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
              |  Pr nat recf recf
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   164
              |  Mn nat recf 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   165
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   166
fun arity :: "recf \<Rightarrow> nat"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   167
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   168
  "arity Z = 1" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   169
| "arity S = 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   170
| "arity (Id m n) = m"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
| "arity (Cn n f gs) = n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   172
| "arity (Pr n f g) = Suc n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   173
| "arity (Mn n f) = n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   175
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   176
  "CN f gs \<equiv> Cn (arity (hd gs)) f gs"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   177
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   178
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   179
  "PR f g \<equiv> Pr (arity f) f g"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   180
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   181
abbreviation
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   182
  "MN f \<equiv> Mn (arity f - 1) f"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   183
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   184
fun rec_eval :: "recf \<Rightarrow> nat list \<Rightarrow> nat"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   186
  "rec_eval Z xs = 0" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   187
| "rec_eval S xs = Suc (xs ! 0)" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   188
| "rec_eval (Id m n) xs = xs ! n" 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
| "rec_eval (Cn n f gs) xs = rec_eval f (map (\<lambda>x. rec_eval x xs) gs)" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   190
| "rec_eval (Pr n f g) (0 # xs) = rec_eval f xs"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   191
| "rec_eval (Pr n f g) (Suc x # xs) = 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   192
     rec_eval g (x # (rec_eval (Pr n f g) (x # xs)) # xs)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
| "rec_eval (Mn n f) xs = (LEAST x. rec_eval f (x # xs) = 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   194
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   195
inductive 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
  terminates :: "recf \<Rightarrow> nat list \<Rightarrow> bool"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   197
where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   198
  termi_z: "terminates Z [n]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   199
| termi_s: "terminates S [n]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   200
| termi_id: "\<lbrakk>n < m; length xs = m\<rbrakk> \<Longrightarrow> terminates (Id m n) xs"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   201
| termi_cn: "\<lbrakk>terminates f (map (\<lambda>g. rec_eval g xs) gs); 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   202
              \<forall>g \<in> set gs. terminates g xs; length xs = n\<rbrakk> \<Longrightarrow> terminates (Cn n f gs) xs"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   203
| termi_pr: "\<lbrakk>\<forall> y < x. terminates g (y # (rec_eval (Pr n f g) (y # xs) # xs));
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
              terminates f xs;
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
              length xs = n\<rbrakk> 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   206
              \<Longrightarrow> terminates (Pr n f g) (xs @ [x])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
| termi_mn: "\<lbrakk>length xs = n; terminates f (r # xs); 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
              rec_eval f (r # xs) = 0;
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   209
              \<forall> i < r. terminates f (i # xs) \<and> rec_eval f (i # xs) > 0\<rbrakk> \<Longrightarrow> terminates (Mn n f) xs"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   210
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   211
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   212
section {* Recursive Function Definitions *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   213
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   214
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
  @{text "constn n"} is the recursive function which computes 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   216
  natural number @{text "n"}.
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
*}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
fun constn :: "nat \<Rightarrow> recf"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   219
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   220
  "constn 0 = Z"  |
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   221
  "constn (Suc n) = CN S [constn n]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
definition
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   224
  "rec_swap f = CN f [Id 2 1, Id 2 0]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   225
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
definition
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   227
  "rec_add = PR (Id 1 0) (CN S [Id 3 1])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   228
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   229
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   230
  "rec_mult = PR Z (CN rec_add [Id 3 1, Id 3 2])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   231
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   233
  "rec_power_swap = PR (constn 1) (CN rec_mult [Id 3 1, Id 3 2])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   234
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   236
  "rec_power = rec_swap rec_power_swap"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   237
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
definition
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   239
  "rec_fact = PR (constn 1) (CN rec_mult [CN S [Id 3 0], Id 3 1])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   242
  "rec_pred = CN (PR Z (Id 3 0)) [Id 1 0, Id 1 0]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   245
  "rec_minus_swap = (PR (Id 1 0) (CN rec_pred [Id 3 1]))"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   246
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   248
  "rec_minus = rec_swap rec_minus_swap"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
text {* Sign function returning 1 when the input argument is greater than @{text "0"}. *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   251
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   253
  "rec_sign = CN rec_minus [constn 1, CN rec_minus [constn 1, Id 1 0]]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   254
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   255
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   256
  "rec_not = CN rec_minus [constn 1, Id 1 0]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  @{text "rec_eq"} compares two arguments: returns @{text "1"}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
  if they are equal; @{text "0"} otherwise. *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   262
  "rec_eq = CN rec_minus 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   263
             [CN (constn 1) [Id 2 0], 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
              CN rec_add [rec_minus, rec_swap rec_minus]]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   266
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
  "rec_noteq = CN rec_not [rec_eq]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   269
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
  "rec_conj = CN rec_sign [rec_mult]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   272
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
  "rec_disj = CN rec_sign [rec_add]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   274
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   275
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   276
  "rec_imp = CN rec_disj [CN rec_not [Id 2 0], Id 2 1]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   277
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   278
text {* @{term "rec_ifz [z, x, y]"} returns x if z is zero,
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   279
  y otherwise *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   280
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   281
  "rec_ifz = PR (Id 2 0) (Id 4 3)"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   283
text {* @{term "rec_if [z, x, y]"} returns x if z is *not* zero,
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   284
  y otherwise *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   285
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   286
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   287
  "rec_if = CN rec_ifz [CN rec_not [Id 3 0], Id 3 1, Id 3 2]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   288
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   289
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
  @{text "rec_less"} compares two arguments and returns @{text "1"} if
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
  the first is less than the second; otherwise returns @{text "0"}. *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   292
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
  "rec_less = CN rec_sign [rec_swap rec_minus]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   295
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
  "rec_le = CN rec_disj [rec_less, rec_eq]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   297
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   298
text {* Sigma and Accum for function with one and two arguments *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   300
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   301
  "rec_sigma1 f = PR (CN f [Z, Id 1 0]) (CN rec_add [Id 3 1, CN f [S, Id 3 2]])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   303
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   304
  "rec_sigma2 f = PR (CN f [Z, Id 2 0, Id 2 1]) (CN rec_add [Id 4 1, CN f [S, Id 4 2, Id 4 3]])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   307
  "rec_accum1 f = PR (CN f [Z, Id 1 0]) (CN rec_mult [Id 3 1, CN f [S, Id 3 2]])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   310
  "rec_accum2 f = PR (CN f [Z, Id 2 0, Id 2 1]) (CN rec_mult [Id 4 1, CN f [S, Id 4 2, Id 4 3]])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
text {* Bounded quantifiers for one and two arguments *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
  "rec_all1 f = CN rec_sign [rec_accum1 f]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  "rec_all2 f = CN rec_sign [rec_accum2 f]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
  "rec_ex1 f = CN rec_sign [rec_sigma1 f]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   324
  "rec_ex2 f = CN rec_sign [rec_sigma2 f]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   325
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   326
text {* Dvd, Quotient, Reminder *}
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   327
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   328
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   329
  "rec_dvd_swap = CN (rec_ex2 (CN rec_eq [Id 3 2, CN rec_mult [Id 3 1, Id 3 0]])) [Id 2 0, Id 2 1, Id 2 0]"  
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   330
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   331
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   332
  "rec_dvd = rec_swap rec_dvd_swap" 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   334
definition
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   335
  "rec_quo = (let lhs = CN S [Id 3 0] in
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   336
              let rhs = CN rec_mult [Id 3 2, CN S [Id 3 1]] in
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   337
              let cond = CN rec_eq [lhs, rhs] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   338
              let if_stmt = CN rec_if [cond, CN S [Id 3 1], Id 3 1]
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   339
              in PR Z if_stmt)"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   340
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   341
definition
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   342
  "rec_rem = CN rec_minus [Id 2 0, CN rec_mult [Id 2 1, rec_quo]]"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   343
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   344
section {* Correctness of Recursive Functions *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
lemma constn_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   347
  "rec_eval (constn n) xs = n"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   348
by (induct n) (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
lemma swap_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
  "rec_eval (rec_swap f) [x, y] = rec_eval f [y, x]"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
by (simp add: rec_swap_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
lemma add_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
  "rec_eval rec_add [x, y] =  x + y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   356
by (induct x) (simp_all add: rec_add_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
lemma mult_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
  "rec_eval rec_mult [x, y] = x * y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   360
by (induct x) (simp_all add: rec_mult_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
lemma power_swap_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
  "rec_eval rec_power_swap [y, x] = x ^ y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   364
by (induct y) (simp_all add: rec_power_swap_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   365
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
lemma power_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
  "rec_eval rec_power [x, y] = x ^ y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   368
by (simp add: rec_power_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   369
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
lemma fact_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
  "rec_eval rec_fact [x] = fact x"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   372
by (induct x) (simp_all add: rec_fact_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   373
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
lemma pred_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
  "rec_eval rec_pred [x] =  x - 1"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   376
by (induct x) (simp_all add: rec_pred_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   377
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
lemma minus_swap_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
  "rec_eval rec_minus_swap [x, y] = y - x"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   380
by (induct x) (simp_all add: rec_minus_swap_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   381
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
lemma minus_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
  "rec_eval rec_minus [x, y] = x - y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   384
by (simp add: rec_minus_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
lemma sign_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
  "rec_eval rec_sign [x] = (if x = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
by (simp add: rec_sign_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
lemma not_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
  "rec_eval rec_not [x] = (if x = 0 then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
by (simp add: rec_not_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
lemma eq_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
  "rec_eval rec_eq [x, y] = (if x = y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
by (simp add: rec_eq_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
lemma noteq_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
  "rec_eval rec_noteq [x, y] = (if x \<noteq> y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
by (simp add: rec_noteq_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
lemma conj_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
  "rec_eval rec_conj [x, y] = (if x = 0 \<or> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
by (simp add: rec_conj_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
lemma disj_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
  "rec_eval rec_disj [x, y] = (if x = 0 \<and> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
by (simp add: rec_disj_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
lemma imp_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
  "rec_eval rec_imp [x, y] = (if 0 < x \<and> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
by (simp add: rec_imp_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
lemma less_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
  "rec_eval rec_less [x, y] = (if x < y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
by (simp add: rec_less_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
lemma le_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
  "rec_eval rec_le [x, y] = (if (x \<le> y) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
by(simp add: rec_le_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   422
lemma ifz_lemma [simp]:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   423
  "rec_eval rec_ifz [z, x, y] = (if z = 0 then x else y)" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   424
by (case_tac z) (simp_all add: rec_ifz_def)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   426
lemma if_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   427
  "rec_eval rec_if [z, x, y] = (if 0 < z then x else y)" 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   428
by (simp add: rec_if_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   429
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
lemma sigma1_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
  shows "rec_eval (rec_sigma1 f) [x, y] = (\<Sum> z \<le> x. (rec_eval f)  [z, y])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
by (induct x) (simp_all add: rec_sigma1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
lemma sigma2_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
  shows "rec_eval (rec_sigma2 f) [x, y1, y2] = (\<Sum> z \<le> x. (rec_eval f)  [z, y1, y2])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
by (induct x) (simp_all add: rec_sigma2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
lemma accum1_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
  shows "rec_eval (rec_accum1 f) [x, y] = (\<Prod> z \<le> x. (rec_eval f)  [z, y])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
by (induct x) (simp_all add: rec_accum1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
lemma accum2_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  shows "rec_eval (rec_accum2 f) [x, y1, y2] = (\<Prod> z \<le> x. (rec_eval f)  [z, y1, y2])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
by (induct x) (simp_all add: rec_accum2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
lemma ex1_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
 "rec_eval (rec_ex1 f) [x, y] = (if (\<exists>z \<le> x. 0 < rec_eval f [z, y]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
by (simp add: rec_ex1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
lemma ex2_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
 "rec_eval (rec_ex2 f) [x, y1, y2] = (if (\<exists>z \<le> x. 0 < rec_eval f [z, y1, y2]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
by (simp add: rec_ex2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
lemma all1_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
 "rec_eval (rec_all1 f) [x, y] = (if (\<forall>z \<le> x. 0 < rec_eval f [z, y]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
by (simp add: rec_all1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
lemma all2_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
 "rec_eval (rec_all2 f) [x, y1, y2] = (if (\<forall>z \<le> x. 0 < rec_eval f [z, y1, y2]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
by (simp add: rec_all2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
lemma dvd_alt_def:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   464
  fixes x y k:: nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   465
  shows "(x dvd y) = (\<exists> k \<le> y. y = x * k)"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
apply(auto simp add: dvd_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
apply(case_tac x)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
apply(auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
lemma dvd_swap_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
  "rec_eval rec_dvd_swap [x, y] = (if y dvd x then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   473
unfolding dvd_alt_def
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
by (auto simp add: rec_dvd_swap_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   476
lemma dvd_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   477
  "rec_eval rec_dvd [x, y] = (if x dvd y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
by (simp add: rec_dvd_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   479
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   480
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   481
fun Quo where
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   482
  "Quo x 0 = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   483
| "Quo x (Suc y) = (if (Suc y = x * (Suc (Quo x y))) then Suc (Quo x y) else Quo x y)"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   484
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   485
lemma Quo0:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   486
  shows "Quo 0 y = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   487
apply(induct y)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   488
apply(auto)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   489
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   490
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   491
lemma Quo1:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   492
  "x * (Quo x y) \<le> y"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   493
by (induct y) (simp_all)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   494
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   495
lemma Quo2: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   496
  "b * (Quo b a) + a mod b = a"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   497
by (induct a) (auto simp add: mod_Suc)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   498
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   499
lemma Quo3:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   500
  "n * (Quo n m) = m - m mod n"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   501
using Quo2[of n m] by (auto)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   502
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   503
lemma Quo4:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   504
  assumes h: "0 < x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   505
  shows "y < x + x * Quo x y"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   506
proof -
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   507
  have "x - (y mod x) > 0" using mod_less_divisor assms by auto
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   508
  then have "y < y + (x - (y mod x))" by simp
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   509
  then have "y < x + (y - (y mod x))" by simp
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   510
  then show "y < x + x * (Quo x y)" by (simp add: Quo3) 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   511
qed
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   512
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   513
lemma Quo_div: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   514
  shows "Quo x y = y div x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   515
apply(case_tac "x = 0")
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   516
apply(simp add: Quo0)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   517
apply(subst split_div_lemma[symmetric])
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   518
apply(auto intro: Quo1 Quo4)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   519
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   520
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   521
lemma Quo_rec_quo:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   522
  shows "rec_eval rec_quo [y, x] = Quo x y"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   523
by (induct y) (simp_all add: rec_quo_def)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   524
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   525
lemma quo_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   526
  shows "rec_eval rec_quo [y, x] = y div x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   527
by (simp add: Quo_div Quo_rec_quo)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   528
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   529
lemma rem_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   530
  shows "rec_eval rec_rem [y, x] = y mod x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   531
by (simp add: rec_rem_def mod_div_equality' nat_mult_commute)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   532
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   533
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   534
section {* Prime Numbers *}
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   535
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   536
lemma prime_alt_def:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   537
  fixes p::nat
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   538
  shows "prime p = (1 < p \<and> (\<forall>m \<le> p. m dvd p \<longrightarrow> m = 1 \<or> m = p))"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
apply(auto simp add: prime_nat_def dvd_def)
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   540
apply(drule_tac x="k" in spec)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   541
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   542
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   543
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   544
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   545
  "rec_prime = 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   546
    (let conj1 = CN rec_less [constn 1, Id 1 0] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   547
     let disj  = CN rec_disj [CN rec_eq [Id 2 0, constn 1], rec_eq] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   548
     let imp   = CN rec_imp [rec_dvd, disj] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   549
     let conj2 = CN (rec_all1 imp) [Id 1 0, Id 1 0] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   550
     CN rec_conj [conj1, conj2])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   551
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   552
lemma prime_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   553
  "rec_eval rec_prime [x] = (if prime x then 1 else 0)"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   554
by (auto simp add: rec_prime_def Let_def prime_alt_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   555
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   556
section {* Bounded Min and Maximisation *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   557
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   558
fun BMax_rec where
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   559
  "BMax_rec R 0 = 0"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   560
| "BMax_rec R (Suc n) = (if R (Suc n) then (Suc n) else BMax_rec R n)"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   561
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   562
definition BMax_set :: "(nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   563
  where "BMax_set R x = Max ({z | z. z \<le> x \<and> R z} \<union> {0})"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   564
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   565
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   566
  Great :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "GREAT " 10) where
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   567
  "Great P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> y \<le> x))"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   568
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   569
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   570
  fixes x::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   571
  assumes "P x" "\<And>y. P y \<Longrightarrow> y \<le> x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   572
  shows "Great P = x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   573
unfolding Great_def 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   574
using assms 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   575
by(rule_tac the_equality) (auto intro: le_antisym)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   576
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   577
lemma BMax_rec_eq1:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   578
 "BMax_rec R x = (GREAT z. (R z \<and> z \<le> x) \<or> z = 0)"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   579
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   580
apply(auto intro: Great_equality Great_equality[symmetric])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   581
apply(simp add: le_Suc_eq)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   582
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   583
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   584
lemma BMax_rec_eq2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   585
  "BMax_rec R x = Max ({z | z. z \<le> x \<and> R z} \<union> {0})"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   586
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   587
apply(auto intro: Max_eqI Max_eqI[symmetric])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   588
apply(simp add: le_Suc_eq)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   589
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   590
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   591
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   592
  "rec_max1 f = PR (constn 0)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   593
                   (CN rec_ifz [CN f [CN S [Id 3 0], Id 3 2], CN S [Id 4 0], Id 4 1])"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   594
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   595
lemma max1_lemma [simp]:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   596
  "rec_eval (rec_max1 f) [x, y] = BMax_rec (\<lambda>u. rec_eval f [u, y] = 0) x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   597
by (induct x) (simp_all add: rec_max1_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   598
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   599
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   600
  "rec_max2 f = PR (constn 0)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   601
                   (CN rec_ifz [CN f [CN S [Id 4 0], Id 4 2, Id 4 3], CN S [Id 4 0], Id 4 1])"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   602
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   603
lemma max2_lemma [simp]:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   604
  "rec_eval (rec_max2 f) [x, y1, y2] = BMax_rec (\<lambda>u. rec_eval f [u, y1, y2] = 0) x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   605
by (induct x) (simp_all add: rec_max2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   606
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   607
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   608
section {* Discrete Logarithms *}
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   609
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   610
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   611
  "rec_lg = 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   612
     (let calc = CN rec_not [CN rec_le [CN rec_power [Id 3 2, Id 3 0], Id 3 1]] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   613
      let max  = CN (rec_max2 calc) [Id 2 0, Id 2 0, Id 2 1] in
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   614
      let cond = CN rec_conj [CN rec_less [constn 1, Id 2 0], CN rec_less [constn 1, Id 2 1]] 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   615
      in CN rec_ifz [cond, Z, max])"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   616
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   617
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   618
  "Lg x y = (if 1 < x \<and> 1 < y then BMax_rec (\<lambda>u. y ^ u \<le> x) x else 0)"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   619
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   620
lemma lg_lemma [simp]:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   621
  "rec_eval rec_lg [x, y] = Lg x y"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   622
by (simp add: rec_lg_def Lg_def Let_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   623
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   624
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   625
  "Lo x y = (if 1 < x \<and> 1 < y then BMax_rec (\<lambda>u. x mod (y ^ u) = 0) x else 0)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   626
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   627
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   628
  "rec_lo = 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   629
     (let calc = CN rec_noteq [CN rec_rem [Id 3 1, CN rec_power [Id 3 2, Id 3 0]], Z] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   630
      let max  = CN (rec_max2 calc) [Id 2 0, Id 2 0, Id 2 1] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   631
      let cond = CN rec_conj [CN rec_less [constn 1, Id 2 0], CN rec_less [constn 1, Id 2 1]] 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   632
      in CN rec_ifz [cond, Z, max])"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   633
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   634
lemma lo_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   635
  "rec_eval rec_lo [x, y] = Lo x y"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   636
by (simp add: rec_lo_def Lo_def Let_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   637
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   638
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   639
section {* Universal Function *}
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   640
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   641
text {* @{text "NextPrime x"} returns the first prime number after @{text "x"}. *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   642
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   643
fun NextPrime ::"nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   644
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   645
  "NextPrime x = (LEAST y. y \<le> Suc (fact x) \<and> x < y \<and> prime y)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   646
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   647
definition rec_nextprime :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   648
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   649
  "rec_nextprime = (let conj1 = CN rec_le [Id 2 0, CN S [CN rec_fact [Id 2 1]]] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   650
                    let conj2 = CN rec_less [Id 2 1, Id 2 0] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   651
                    let conj3 = CN rec_prime [Id 2 0] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   652
                    let conjs = CN rec_conj [CN rec_conj [conj2, conj1], conj3]
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   653
                    in MN (CN rec_not [conjs]))"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   654
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   655
lemma nextprime_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   656
  "rec_eval rec_nextprime [x] = NextPrime x"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   657
by (simp add: rec_nextprime_def Let_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   658
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   659
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   660
fun Pi :: "nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   661
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   662
  "Pi 0 = 2" |
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   663
  "Pi (Suc x) = NextPrime (Pi x)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   664
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   665
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   666
  "rec_pi = PR (constn 2) (CN rec_nextprime [Id 2 1])"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   667
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   668
lemma pi_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   669
  "rec_eval rec_pi [x] = Pi x"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   670
by (induct x) (simp_all add: rec_pi_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   671
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   672
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   673
fun Left where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   674
  "Left c = Lo c (Pi 0)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   675
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   676
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   677
  "rec_left = CN rec_lo [Id 1 0, constn (Pi 0)]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   678
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   679
lemma left_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   680
  "rec_eval rec_left [c] = Left c" 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   681
by(simp add: rec_left_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   682
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   683
fun Right where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   684
  "Right c = Lo c (Pi 2)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   685
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   686
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   687
  "rec_right = CN rec_lo [Id 1 0, constn (Pi 2)]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   688
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   689
lemma right_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   690
  "rec_eval rec_right [c] = Right c" 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   691
by(simp add: rec_right_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   692
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   693
fun Stat where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   694
  "Stat c = Lo c (Pi 1)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   695
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   696
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   697
  "rec_stat = CN rec_lo [Id 1 0, constn (Pi 1)]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   698
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   699
lemma stat_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   700
  "rec_eval rec_stat [c] = Stat c" 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   701
by(simp add: rec_stat_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   702
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   703
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   704
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   705
text{* coding of the configuration *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   706
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   707
text {*
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   708
  @{text "Entry sr i"} returns the @{text "i"}-th entry of a list of natural 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   709
  numbers encoded by number @{text "sr"} using Godel's coding.
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   710
  *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   711
fun Entry where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   712
  "Entry sr i = Lo sr (Pi (Suc i))"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   713
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   714
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   715
  "rec_entry = CN rec_lo [Id 2 0, CN rec_pi [CN S [Id 2 1]]]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   716
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   717
lemma entry_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   718
  "rec_eval rec_entry [sr, i] = Entry sr i"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   719
by(simp add: rec_entry_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   720
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   721
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   722
fun Listsum2 :: "nat list \<Rightarrow> nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   723
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   724
  "Listsum2 xs 0 = 0"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   725
| "Listsum2 xs (Suc n) = Listsum2 xs n + xs ! n"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   726
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   727
fun rec_listsum2 :: "nat \<Rightarrow> nat \<Rightarrow> recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   728
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   729
  "rec_listsum2 vl 0 = CN Z [Id vl 0]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   730
| "rec_listsum2 vl (Suc n) = CN rec_add [rec_listsum2 vl n, Id vl n]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   731
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   732
lemma listsum2_lemma [simp]: 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   733
  "length xs = vl \<Longrightarrow> rec_eval (rec_listsum2 vl n) xs = Listsum2 xs n"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   734
by (induct n) (simp_all)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   735
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   736
text {*
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   737
  @{text "Strt"} corresponds to the @{text "strt"} function on page 90 of the 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   738
  B book, but this definition generalises the original one to deal with multiple 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   739
  input arguments.
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   740
  *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   741
fun Strt' :: "nat list \<Rightarrow> nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   742
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   743
  "Strt' xs 0 = 0"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   744
| "Strt' xs (Suc n) = (let dbound = Listsum2 xs n + n 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   745
                       in Strt' xs n + (2 ^ (xs ! n + dbound) - 2 ^ dbound))"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   746
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   747
fun Strt :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   748
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   749
  "Strt xs = (let ys = map Suc xs in Strt' ys (length ys))"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   750
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   751
fun rec_strt' :: "nat \<Rightarrow> nat \<Rightarrow> recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   752
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   753
  "rec_strt' xs 0 = Z"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   754
| "rec_strt' xs (Suc n) = 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   755
      (let dbound = CN rec_add [rec_listsum2 xs n, constn n] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   756
       let t1 = CN rec_power [constn 2, dbound] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   757
       let t2 = CN rec_power [constn 2, CN rec_add [Id xs n, dbound]] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   758
       CN rec_add [rec_strt' xs n, CN rec_minus [t2, t1]])"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   759
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   760
fun rec_map :: "recf \<Rightarrow> nat \<Rightarrow> recf list"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   761
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   762
  "rec_map rf vl = map (\<lambda>i. CN rf [Id vl i]) [0..<vl]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   763
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   764
fun rec_strt :: "nat \<Rightarrow> recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   765
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   766
  "rec_strt xs = CN (rec_strt' xs xs) (rec_map S xs)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   767
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   768
lemma strt'_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   769
  "length xs = vl \<Longrightarrow> rec_eval (rec_strt' vl n) xs = Strt' xs n"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   770
by (induct n) (simp_all add: Let_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   771
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   772
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   773
lemma map_suc:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   774
  "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   775
proof -
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   776
  have "Suc \<circ> (\<lambda>x. xs ! x) = (\<lambda>x. Suc (xs ! x))" by (simp add: comp_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   777
  then have "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map (Suc \<circ> (\<lambda>x. xs ! x)) [0..<length xs]" by simp
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   778
  also have "... = map Suc (map (\<lambda>x. xs ! x) [0..<length xs])" by simp
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   779
  also have "... = map Suc xs" by (simp add: map_nth)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   780
  finally show "map (\<lambda>x. Suc (xs ! x)) [0..<length xs] = map Suc xs" .
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   781
qed
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   782
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   783
lemma strt_lemma [simp]: 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   784
  "length xs = vl \<Longrightarrow> rec_eval (rec_strt vl) xs = Strt xs"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   785
by (simp add: comp_def map_suc[symmetric])
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   786
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   787
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   788
text {* The @{text "Scan"} function on page 90 of B book. *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   789
fun Scan :: "nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   790
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   791
  "Scan r = r mod 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   792
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   793
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   794
  "rec_scan = CN rec_rem [Id 1 0, constn 2]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   795
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   796
lemma scan_lemma [simp]: 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   797
  "rec_eval rec_scan [r] = r mod 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   798
by(simp add: rec_scan_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   799
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   800
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   801
text {* The specifation of the mutli-way branching statement on
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   802
  page 79 of Boolos's book. *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   803
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   804
type_synonym ftype = "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   805
type_synonym rtype = "nat list \<Rightarrow> bool"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   806
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   807
fun Embranch :: "(ftype * rtype) list \<Rightarrow> nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   808
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   809
  "Embranch [] xs = 0" |
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   810
  "Embranch ((g, c) # gcs) xs = (if c xs then g xs else Embranch gcs xs)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   811
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   812
fun rec_embranch' :: "(recf * recf) list \<Rightarrow> nat \<Rightarrow> recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   813
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   814
  "rec_embranch' [] xs = Z" |
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   815
  "rec_embranch' ((g, c) # gcs) xs = 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   816
      CN rec_add [CN rec_mult [g, c], rec_embranch' gcs xs]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   817
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   818
fun rec_embranch :: "(recf * recf) list \<Rightarrow> recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   819
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   820
  "rec_embranch [] = Z"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   821
| "rec_embranch ((rg, rc) # rgcs) = (let vl = arity rg in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   822
                                     rec_embranch' ((rg, rc) # rgcs) vl)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   823
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   824
(*
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   825
lemma embranch_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   826
  shows "rec_eval (rec_embranch (zip rgs rcs)) xs =
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   827
           Embranch (zip (map rec_eval rgs) (map (\<lambda>r args. 0 < rec_eval r args) rcs)) xs"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   828
apply(induct rcs arbitrary: rgs)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   829
apply(simp)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   830
apply(simp)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   831
apply(case_tac rgs)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   832
apply(simp)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   833
apply(simp)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   834
apply(case_tac rcs)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   835
apply(simp_all)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   836
apply(rule conjI)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   837
*)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   838
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   839
fun Newleft0 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   840
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   841
  "Newleft0 [p, r] = p"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   842
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   843
definition rec_newleft0 :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   844
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   845
  "rec_newleft0 = Id 2 0"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   846
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   847
fun Newrgt0 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   848
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   849
  "Newrgt0 [p, r] = r - Scan r"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   850
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   851
definition rec_newrgt0 :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   852
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   853
  "rec_newrgt0 = CN rec_minus [Id 2 1, CN rec_scan [Id 2 1]]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   854
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   855
(*newleft1, newrgt1: left rgt number after execute on step*)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   856
fun Newleft1 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   857
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   858
  "Newleft1 [p, r] = p"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   859
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   860
definition rec_newleft1 :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   861
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   862
  "rec_newleft1 = Id 2 0"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   863
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   864
fun Newrgt1 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   865
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   866
  "Newrgt1 [p, r] = r + 1 - Scan r"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   867
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   868
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   869
  "rec_newrgt1 = CN rec_minus [CN rec_add [Id 2 1, constn 1], CN rec_scan [Id 2 1]]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   870
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   871
fun Newleft2 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   872
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   873
  "Newleft2 [p, r] = p div 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   874
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   875
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   876
  "rec_newleft2 = CN rec_quo [Id 2 0, constn 2]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   877
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   878
fun Newrgt2 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   879
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   880
  "Newrgt2 [p, r] = 2 * r + p mod 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   881
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   882
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   883
  "rec_newrgt2 = CN rec_add [CN rec_mult [constn 2, Id 2 1],                     
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   884
                             CN rec_rem [Id 2 0, constn 2]]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   885
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   886
fun Newleft3 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   887
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   888
  "Newleft3 [p, r] = 2 * p + r mod 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   889
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   890
definition rec_newleft3 :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   891
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   892
  "rec_newleft3 = CN rec_add [CN rec_mult [constn 2, Id 2 0], 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   893
                              CN rec_rem [Id 2 1, constn 2]]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   894
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   895
fun Newrgt3 :: "nat list \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   896
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   897
  "Newrgt3 [p, r] = r div 2"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   898
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   899
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   900
  "rec_newrgt3 = CN rec_quo [Id 2 1, constn 2]"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   901
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   902
text {* The @{text "new_left"} function on page 91 of B book. *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   903
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   904
fun Newleft :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   905
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   906
  "Newleft p r a = (if a = 0 \<or> a = 1 then Newleft0 [p, r] 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   907
                    else if a = 2 then Newleft2 [p, r]
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   908
                    else if a = 3 then Newleft3 [p, r]
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   909
                    else p)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   910
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   911
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   912
    "rec_newleft =
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   913
       (let g0 = CN rec_newleft0 [Id 3 0, Id 3 1] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   914
        let g1 = CN rec_newleft2 [Id 3 0, Id 3 1] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   915
        let g2 = CN rec_newleft3 [Id 3 0, Id 3 1] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   916
        let g3 = Id 3 0 in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   917
        let r0 = CN rec_disj [CN rec_eq [Id 3 2, constn 0],
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   918
                              CN rec_eq [Id 3 2, constn 1]] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   919
        let r1 = CN rec_eq [Id 3 2, constn 2] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   920
        let r2 = CN rec_eq [Id 3 2, constn 3] in
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   921
        let r3 = CN rec_less [constn 3, Id 3 2] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   922
        let gs = [g0, g1, g2, g3] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   923
        let rs = [r0, r1, r2, r3] in 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   924
        rec_embranch (zip gs rs))"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   925
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   926
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   927
fun Trpl :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   928
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   929
  "Trpl p q r = (Pi 0) ^ p * (Pi 1) ^ q * (Pi 2) ^ r"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   930
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   931
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   932
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   933
text {*
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   934
  @{text "Nstd c"} returns true if the configuration coded 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   935
  by @{text "c"} is not a stardard final configuration.
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   936
  *}
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   937
fun Nstd :: "nat \<Rightarrow> bool"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   938
  where
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   939
  "Nstd c = (Stat c \<noteq> 0 \<or> Left c \<noteq> 0 \<or> 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   940
             Right c \<noteq> 2 ^ (Lg (Suc (Right c)) 2) - 1 \<or> 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   941
             Right c = 0)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   942
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   943
text {*
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   944
  @{text "Conf m r k"} computes the TM configuration after 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   945
  @{text "k"} steps of execution of the TM coded as @{text "m"} 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   946
  starting from the initial configuration where the left number 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   947
  equals @{text "0"} and the right number equals @{text "r"}. 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   948
  *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   949
fun Conf 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   950
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   951
  "Conf m r 0 = Trpl 0 (Suc 0) r"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   952
| "Conf m r (Suc t) = Newconf m (Conf m r t)"
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   953
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   954
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   955
text{* 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   956
  @{text "Nonstop m r t"} means that afer @{text "t"} steps of 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   957
  execution, the TM coded by @{text "m"} is not at a stardard 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   958
  final configuration.
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   959
  *}
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   960
fun Nostop 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   961
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   962
  "Nostop m r t = Nstd (Conf m r t)"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   963
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   964
fun Value where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   965
  "Value x = (Lg (Suc x) 2) - 1"
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   966
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   967
definition 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   968
  "rec_value = CN rec_pred [CN rec_lg [S, constn 2]]"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   969
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   970
lemma value_lemma [simp]:
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   971
  "rec_eval rec_value [x] = Value x"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   972
by (simp add: rec_value_def)
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   973
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   974
definition 
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   975
  "rec_UF = CN rec_value [CN rec_right [CN rec_conf [Id 2 0, Id 2 1, rec_halt]]]"
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   976
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   977
end
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   978
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   979
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   980
(*
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   981
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   982
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   983
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   984
fun mtest where
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   985
  "mtest R 0 = if R 0 then 0 else 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   986
| "mtest R (Suc n) = (if R n then mtest R n else (Suc n))"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   987
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   988
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   989
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   990
  "rec_eval (rec_maxr2 f) [x, y1, y2] = XXX"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   991
apply(simp only: rec_maxr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   992
apply(case_tac x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   993
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   994
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   995
apply(simp only: constn_lemma)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   996
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   997
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   998
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   999
apply(simp only: rec_maxr2_def[symmetric])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1000
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1001
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1002
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1003
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1004
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1005
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1006
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1007
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1008
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1009
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1010
apply(subst rec_eval.simps)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1011
apply(simp only: map.simps nth)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1012
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1013
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1014
definition
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1015
  "rec_minr2 f = rec_sigma2 (rec_accum2 (CN rec_not [f]))"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1016
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1017
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1018
  "rec_maxr2 f = rec_sigma2 (CN rec_sign [CN (rec_sigma2 f) [S]])"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1019
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1020
definition Minr :: "(nat \<Rightarrow> nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1021
  where "Minr R x ys = Min ({z | z. z \<le> x \<and> R z ys} \<union> {Suc x})"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1022
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1023
definition Maxr :: "(nat \<Rightarrow> nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1024
  where "Maxr R x ys = Max ({z | z. z \<le> x \<and> R z ys} \<union> {0})"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1025
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1026
lemma rec_minr2_le_Suc:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1027
  "rec_eval (rec_minr2 f) [x, y1, y2] \<le> Suc x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1028
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1029
apply(auto intro!: setsum_one_le setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1030
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1031
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1032
lemma rec_minr2_eq_Suc:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1033
  assumes "\<forall>z \<le> x. rec_eval f [z, y1, y2] = 0"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1034
  shows "rec_eval (rec_minr2 f) [x, y1, y2] = Suc x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1035
using assms by (simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1036
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1037
lemma rec_minr2_le:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1038
  assumes h1: "y \<le> x" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1039
  and     h2: "0 < rec_eval f [y, y1, y2]" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1040
  shows "rec_eval (rec_minr2 f) [x, y1, y2] \<le> y"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1041
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1042
apply(subst setsum_cut_off_le[OF h1])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1043
using h2 apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1044
apply(auto intro!: setsum_one_less setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1045
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1046
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1047
(* ??? *)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1048
lemma setsum_eq_one_le2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1049
  fixes n::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1050
  assumes "\<forall>i \<le> n. f i \<le> 1" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1051
  shows "((\<Sum>i \<le> n. f i) \<ge> Suc n) \<Longrightarrow> (\<forall>i \<le> n. f i = 1)"  
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1052
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1053
apply(induct n)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1054
apply(simp add: One_nat_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1055
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1056
apply(auto simp add: One_nat_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1057
apply(drule_tac x="Suc n" in spec)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1058
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1059
by (metis le_Suc_eq)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1060
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1061
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1062
lemma rec_min2_not:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1063
  assumes "rec_eval (rec_minr2 f) [x, y1, y2] = Suc x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1064
  shows "\<forall>z \<le> x. rec_eval f [z, y1, y2] = 0"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1065
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1066
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1067
apply(subgoal_tac "\<forall>i \<le> x. (\<Prod>z\<le>i. if rec_eval f [z, y1, y2] = 0 then 1 else 0) = (1::nat)")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1068
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1069
apply (metis atMost_iff le_refl zero_neq_one)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1070
apply(rule setsum_eq_one_le2)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1071
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1072
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1073
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1074
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1075
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1076
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1077
  assumes "~P ==> Q" shows "P|Q"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1078
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1079
apply (iprover intro: assms disjI1 disjI2 notI elim: notE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1080
done
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1081
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1082
lemma minr_lemma [simp]:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1083
shows "rec_eval (rec_minr2 f) [x, y1, y2] = (LEAST z.  (z \<le> x \<and> 0 < rec_eval f [z, y1, y2]) \<or> z = Suc x)"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1084
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1085
apply(rule Least_equality[symmetric])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1086
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1087
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1088
apply(rule rec_minr2_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1089
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1090
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1091
apply(rule rec_minr2_le_Suc)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1092
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1093
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1094
apply(rule rec_minr2_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1095
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1096
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1097
apply(rule rec_minr2_le_Suc)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1098
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1099
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1100
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1101
apply(ru le setsum_one_less)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1102
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1103
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1104
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1105
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1106
apply(rule setsum_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1107
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1108
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1109
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1110
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1111
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1112
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1113
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1114
shows "rec_eval (rec_minr2 f) [x, y1, y2] = Minr (\<lambda>x xs. (0 < rec_eval f (x #xs))) x [y1, y2]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1115
apply(simp only: Minr_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1116
apply(rule sym)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1117
apply(rule Min_eqI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1118
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1119
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1120
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1121
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1122
apply(rule rec_minr2_le_Suc)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1123
apply(rule rec_minr2_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1124
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1125
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1126
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1127
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1128
apply(
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1129
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1130
apply(rule rec_minr2_eq_Suc)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1131
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1132
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1133
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1134
apply(rule setsum_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1135
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1136
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1137
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1138
apply(subst setsum_cut_off_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1139
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1140
apply(rule setsum_one_less)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1141
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1142
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1143
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1144
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1145
thm setsum_eq_one_le
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1146
apply(subgoal_tac "(\<forall>z\<le>x. (\<Prod>z\<le>z. if rec_eval f [z, y1, y2] = (0::nat) then 1 else 0) > (0::nat)) \<or>
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1147
                   (\<not> (\<forall>z\<le>x. (\<Prod>z\<le>z. if rec_eval f [z, y1, y2] = (0::nat) then 1 else 0) > (0::nat)))")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1148
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1149
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1150
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1151
apply(rule disjI1)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1152
apply(rule setsum_eq_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1153
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1154
apply(rule disjI2)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1155
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1156
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1157
apply(subgoal_tac "\<exists>l. l = (LEAST z. 0 < rec_eval f [z, y1, y2])")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1158
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1159
apply metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1160
apply(erule exE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1161
apply(subgoal_tac "l \<le> x")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1162
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1163
apply (metis not_leE not_less_Least order_trans)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1164
apply(subst setsum_least_eq)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1165
apply(rotate_tac 4)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1166
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1167
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1168
apply(subgoal_tac "a < (LEAST z. 0 < rec_eval f [z, y1, y2])")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1169
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1170
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1171
apply(rotate_tac 5)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1172
apply(drule not_less_Least)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1173
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1174
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1175
apply(rule_tac x="(LEAST z. 0 < rec_eval f [z, y1, y2])" in exI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1176
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1177
apply (metis LeastI_ex)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1178
apply(subst setsum_least_eq)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1179
apply(rotate_tac 3)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1180
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1181
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1182
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1183
apply(subgoal_tac "a < (LEAST z. 0 < rec_eval f [z, y1, y2])")
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1184
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1185
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1186
apply (metis neq0_conv not_less_Least)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1187
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1188
apply (metis (mono_tags) LeastI_ex)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1189
by (metis LeastI_ex)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1190
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1191
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1192
shows "rec_eval (rec_minr2 f) [x, y1, y2] = Minr (\<lambda>x xs. (0 < rec_eval f (x #xs))) x [y1, y2]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1193
apply(simp only: Minr_def rec_minr2_def)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1194
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1195
apply(rule sym)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1196
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1197
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1198
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1199
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1200
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1201
apply(rule setsum_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1202
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1203
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1204
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1205
apply(subst setsum_cut_off_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1206
apply(auto)[2]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1207
apply(rule setsum_one_less)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1208
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1209
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1210
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1211
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1212
thm setsum_eq_one_le
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1213
apply(subgoal_tac "(\<forall>z\<le>x. (\<Prod>z\<le>z. if rec_eval f [z, y1, y2] = (0::nat) then 1 else 0) > (0::nat)) \<or>
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1214
                   (\<not> (\<forall>z\<le>x. (\<Prod>z\<le>z. if rec_eval f [z, y1, y2] = (0::nat) then 1 else 0) > (0::nat)))")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1215
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1216
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1217
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1218
apply(rule disjI1)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1219
apply(rule setsum_eq_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1220
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1221
apply(rule disjI2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1222
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1223
apply(clarify)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1224
apply(subgoal_tac "\<exists>l. l = (LEAST z. 0 < rec_eval f [z, y1, y2])")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1225
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1226
apply metis
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1227
apply(erule exE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1228
apply(subgoal_tac "l \<le> x")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1229
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1230
apply (metis not_leE not_less_Least order_trans)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1231
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1232
apply(rotate_tac 4)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1233
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1234
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1235
apply(subgoal_tac "a < (LEAST z. 0 < rec_eval f [z, y1, y2])")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1236
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1237
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1238
apply(rotate_tac 5)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1239
apply(drule not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1240
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1241
apply(auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1242
apply(rule_tac x="(LEAST z. 0 < rec_eval f [z, y1, y2])" in exI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1243
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1244
apply (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1245
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1246
apply(rotate_tac 3)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1247
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1248
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1249
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1250
apply(subgoal_tac "a < (LEAST z. 0 < rec_eval f [z, y1, y2])")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1251
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1252
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1253
apply (metis neq0_conv not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1254
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1255
apply (metis (mono_tags) LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1256
by (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1257
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1258
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1259
  assumes "~P ==> Q" shows "P|Q"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1260
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1261
apply (iprover intro: assms disjI1 disjI2 notI elim: notE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1262
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1263
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1264
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1265
lemma minr_lemma [simp]:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1266
shows "rec_eval (rec_minr2 f) [x, y1, y2] = (LEAST z.  (z \<le> x \<and> 0 < rec_eval f [z, y1, y2]) \<or> z = Suc x)"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1267
(*apply(simp add: rec_minr2_def)*)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1268
apply(rule Least_equality[symmetric])
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1269
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1270
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1271
apply(rule rec_minr2_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1272
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1273
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1274
apply(rule rec_minr2_le_Suc)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1275
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1276
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1277
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1278
apply(ru le setsum_one_less)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1279
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1280
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1281
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1282
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1283
apply(rule setsum_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1284
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1285
apply(rule setprod_one_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1286
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1287
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1288
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1289
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1290
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1291
apply(rule le_tran
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1292
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1293
apply(rule le_trans)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1294
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1295
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1296
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1297
apply(subst setsum_cut_off_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1298
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1299
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1300
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1301
  "Minr R x ys = (LEAST z. (R z ys \<or> z = Suc x))" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1302
apply(simp add: Minr_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1303
apply(rule Min_eqI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1304
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1305
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1306
apply(rule Least_le)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1307
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1308
apply(rule LeastI2_wellorder)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1309
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1310
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1311
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1312
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1313
  Great :: "('a \<Rightarrow> bool) \<Rightarrow> 'a" (binder "GREAT " 10) where
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1314
  "Great P = (THE x. P x \<and> (\<forall>y. P y \<longrightarrow> y \<le> x))"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1315
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1316
(*
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1317
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1318
  assumes "P x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1319
    and "\<And>y. P y \<Longrightarrow> y \<le> x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1320
  shows "Great P = x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1321
unfolding Great_def 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1322
apply(rule the_equality)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1323
apply(blast intro: assms)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1324
*)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1325
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1326
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1327
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1328
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1329
  "Maxr R x ys = (GREAT z. (R z ys \<or> z = 0))" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1330
apply(simp add: Maxr_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1331
apply(rule Max_eqI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1332
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1333
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1334
thm Least_le Greatest_le
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1335
oops
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1336
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1337
lemma
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1338
  "Maxr R x ys = x - Minr (\<lambda>z. R (x - z)) x ys"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1339
apply(simp add: Maxr_def Minr_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1340
apply(rule Max_eqI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1341
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1342
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1343
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1344
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1345
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1346
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1347
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1348
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1349
thm Min_insert
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1350
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1351
oops
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1352
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1353
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1354
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1355
definition quo :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1356
  where
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1357
  "quo x y = (if y = 0 then 0 else x div y)"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1358
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1359
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1360
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1361
  "rec_quo = CN rec_mult [CN rec_sign [Id 2 1],  
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1362
      CN (rec_minr2 (CN rec_less [Id 3 1, CN rec_mult [CN S [Id 3 0], Id 3 2]])) 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1363
                [Id 2 0, Id 2 0, Id 2 1]]"
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1364
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1365
lemma div_lemma [simp]:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1366
  "rec_eval rec_quo [x, y] = quo x y"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1367
apply(simp add: rec_quo_def quo_def)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1368
apply(rule impI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1369
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1370
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1371
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1372
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1373
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1374
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1375
apply (metis div_le_dividend le_SucI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1376
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1377
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1378
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1379
apply (metis mult_Suc_right nat_mult_commute split_div_lemma)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1380
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1381
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1382
apply (smt div_le_dividend fst_divmod_nat)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1383
apply(simp add: quo_def)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1384
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1385
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1386
apply(auto)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1387
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1388
fun Minr :: "(nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1389
  where "Minr R x y = (let setx = {z | z. z \<le> x \<and> R [z, y]} in 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1390
                        if (setx = {}) then (Suc x) else (Min setx))"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1391
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1392
definition
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1393
  "rec_minr f = rec_sigma1 (rec_accum1 (CN rec_not [f]))"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1394
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1395
lemma minr_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1396
shows "rec_eval (rec_minr f) [x, y] = Minr (\<lambda>xs. (0 < rec_eval f xs)) x y"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1397
apply(simp only: rec_minr_def)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1398
apply(simp only: sigma1_lemma)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1399
apply(simp only: accum1_lemma)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1400
apply(subst rec_eval.simps)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1401
apply(simp only: map.simps nth)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1402
apply(simp only: Minr.simps Let_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1403
apply(auto simp del: not_lemma)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1404
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1405
apply(simp only: not_lemma sign_lemma)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1406
apply(rule sym)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1407
apply(rule Min_eqI)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1408
apply(auto)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1409
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1410
apply(subst setsum_cut_off_le[where m="ya"])
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1411
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1412
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1413
apply(metis Icc_subset_Ici_iff atLeast_def in_mono le_refl mem_Collect_eq)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1414
apply(rule setsum_one_less)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1415
apply(default)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1416
apply(rule impI)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1417
apply(rule setprod_one_le)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1418
apply(auto split: if_splits)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1419
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1420
apply(rule conjI)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1421
apply(subst setsum_cut_off_le[where m="xa"])
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1422
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1423
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1424
apply (metis Icc_subset_Ici_iff atLeast_def in_mono le_refl mem_Collect_eq)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1425
apply(rule le_trans)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1426
apply(rule setsum_one_less)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1427
apply(default)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1428
apply(rule impI)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1429
apply(rule setprod_one_le)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1430
apply(auto split: if_splits)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1431
apply(simp)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1432
apply(subgoal_tac "\<exists>l. l = (LEAST z. 0 < rec_eval f [z, y])")
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1433
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1434
apply metis
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1435
apply(erule exE)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1436
apply(subgoal_tac "l \<le> x")
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1437
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1438
apply (metis not_leE not_less_Least order_trans)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1439
apply(subst setsum_least_eq)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1440
apply(rotate_tac 3)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1441
apply(assumption)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1442
prefer 3
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1443
apply (metis LeastI_ex)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1444
apply(auto)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1445
apply(subgoal_tac "a < (LEAST z. 0 < rec_eval f [z, y])")
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1446
prefer 2
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1447
apply(auto)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1448
apply(rotate_tac 5)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1449
apply(drule not_less_Least)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1450
apply(auto)[1]
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1451
apply(auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1452
by (metis (mono_tags) LeastI_ex)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1453
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1454
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1455
fun Minr2 :: "(nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1456
  where "Minr2 R x y = (let setx = {z | z. z \<le> x \<and> R [z, y]} in 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1457
                        Min (setx \<union> {Suc x}))"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1458
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1459
lemma Minr2_Minr: 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1460
  "Minr2 R x y = Minr R x y"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1461
apply(auto)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1462
apply (metis (lifting, no_types) Min_singleton empty_Collect_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1463
apply(rule min_absorb2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1464
apply(subst Min_le_iff)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1465
apply(auto)  
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1466
done
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
  1467
 *)