thys/Recs.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Thu, 02 May 2013 13:19:50 +0100
changeset 249 6e7244ae43b8
parent 247 89ed51d72e4a
child 250 745547bdc1c7
permissions -rwxr-xr-x
polised a bit of the Recs-theory
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 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   233
  "rec_power = rec_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
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   236
  "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
   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_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
   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 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   242
  "rec_minus = rec_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
   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
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   245
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   246
  The @{text "sign"} function returns 1 when the input argument 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   247
  is greater than @{text "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
   248
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   249
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   250
  "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
   251
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   252
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   253
  "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
   254
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   255
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
  @{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
   257
  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
   258
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   259
  "rec_eq = CN rec_minus [constn 1, CN rec_add [rec_minus, rec_swap rec_minus]]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
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_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
   263
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   264
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   265
  "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
   266
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   267
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   268
  "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
   269
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   270
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   271
  "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
   272
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   273
text {* @{term "rec_ifz [z, x, y]"} returns x if z is zero,
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   274
  y otherwise;  @{term "rec_if [z, x, y]"} returns x if z is *not*
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   275
  zero, y otherwise *}
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   276
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   277
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   278
  "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
   279
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   280
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   281
  "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
   282
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   283
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   284
  @{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
   285
  the first is less than the second; otherwise returns @{text "0"}. *}
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   286
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   288
  "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
   289
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   290
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   291
  "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
   292
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   293
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
   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 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   296
  "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
   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
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   299
  "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
   300
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   301
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   302
  "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
   303
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   304
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   305
  "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
   306
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   307
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
   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
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
  "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
   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
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   313
  "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
   314
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   316
  "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
   317
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   319
  "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
   320
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   321
text {* Dvd, Quotient, Modulo *}
240
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 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   324
  "rec_dvd = 
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   325
     rec_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
   326
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   327
definition
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   328
  "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
   329
              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
   330
              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
   331
              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
   332
              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
   333
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   334
definition
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   335
  "rec_mod = CN rec_minus [Id 2 0, CN rec_mult [Id 2 1, rec_quo]]"
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   336
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   337
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   338
section {* Prime Numbers *}
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   339
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   340
definition 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   341
  "rec_prime = 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   342
    (let conj1 = CN rec_less [constn 1, Id 1 0] in
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   343
     let disj  = CN rec_disj [CN rec_eq [Id 2 0, constn 1], rec_eq] in
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   344
     let imp   = CN rec_imp [rec_dvd, disj] in
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   345
     let conj2 = CN (rec_all1 imp) [Id 1 0, Id 1 0] in
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   346
     CN rec_conj [conj1, conj2])"
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   347
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   348
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
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
   350
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   351
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
   352
  "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
   353
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
   354
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   355
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
   356
  "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
   357
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
   358
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   359
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
   360
  "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
   361
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
   362
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   363
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
   364
  "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
   365
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
   366
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   367
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
   368
  "rec_eval rec_power [x, y] = x ^ y"
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   369
by (induct y) (simp_all add: rec_power_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
   370
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   371
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
   372
  "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
   373
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
   374
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   375
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
   376
  "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
   377
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
   378
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   379
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
   380
  "rec_eval rec_minus [x, y] = x - y"
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   381
by (induct y) (simp_all add: rec_minus_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
   382
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
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
   384
  "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
   385
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
   386
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
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
   388
  "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
   389
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
   390
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
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
   392
  "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
   393
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
   394
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
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
   396
  "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
   397
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
   398
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
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
   400
  "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
   401
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
   402
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
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
   404
  "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
   405
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
   406
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
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
   408
  "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
   409
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
   410
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
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
   412
  "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
   413
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
   414
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
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
   416
  "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
   417
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
   418
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   419
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
   420
  "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
   421
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
   422
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   423
lemma if_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   424
  "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
   425
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
   426
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   427
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
   428
  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
   429
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
   430
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
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
   432
  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
   433
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
   434
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
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
   436
  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
   437
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
   438
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
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
   440
  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
   441
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
   442
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
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
   444
 "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
   445
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
   446
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
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
   448
 "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
   449
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
   450
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
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
   452
 "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
   453
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
   454
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
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
   456
 "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
   457
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
   458
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
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
   461
  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
   462
  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
   463
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
   464
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
   465
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
   466
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
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
   469
  "rec_eval rec_dvd [x, y] = (if x dvd y then 1 else 0)"
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   470
unfolding dvd_alt_def
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   471
by (auto simp add: rec_dvd_def)
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   472
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   473
fun Quo where
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   474
  "Quo x 0 = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   475
| "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
   476
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   477
lemma Quo0:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   478
  shows "Quo 0 y = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   479
apply(induct y)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   480
apply(auto)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   481
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   482
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   483
lemma Quo1:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   484
  "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
   485
by (induct y) (simp_all)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   486
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   487
lemma Quo2: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   488
  "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
   489
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
   490
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   491
lemma Quo3:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   492
  "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
   493
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
   494
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   495
lemma Quo4:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   496
  assumes h: "0 < x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   497
  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
   498
proof -
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   499
  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
   500
  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
   501
  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
   502
  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
   503
qed
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   504
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   505
lemma Quo_div: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   506
  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
   507
apply(case_tac "x = 0")
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   508
apply(simp add: Quo0)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   509
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
   510
apply(auto intro: Quo1 Quo4)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   511
done
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_rec_quo:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   514
  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
   515
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
   516
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   517
lemma quo_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   518
  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
   519
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
   520
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   521
lemma rem_lemma [simp]:
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   522
  shows "rec_eval rec_mod [y, x] = y mod x"
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   523
by (simp add: rec_mod_def mod_div_equality' nat_mult_commute)
244
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
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   526
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
   527
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   528
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
   529
  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
   530
  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
   531
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
   532
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
   533
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   534
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   535
240
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_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
   537
  "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
   538
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
   539
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   540
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
   541
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   542
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
   543
  "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
   544
| "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
   545
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   546
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
   547
  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
   548
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   549
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   550
  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
   551
  "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
   552
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   553
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   554
  fixes x::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   555
  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
   556
  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
   557
unfolding Great_def 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   558
using assms 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   559
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
   560
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   561
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
   562
 "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
   563
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   564
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
   565
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
   566
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   567
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   568
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
   569
  "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
   570
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   571
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
   572
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
   573
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   574
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   575
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   576
  "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
   577
                   (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
   578
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   579
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
   580
  "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
   581
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
   582
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   583
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   584
  "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
   585
                   (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
   586
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   587
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
   588
  "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
   589
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
   590
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   591
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   592
section {* Discrete Logarithms *}
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   593
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   594
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   595
  "rec_lg = 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   596
     (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
   597
      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
   598
      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
   599
      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
   600
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   601
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   602
  "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
   603
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   604
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
   605
  "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
   606
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
   607
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   608
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   609
  "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
   610
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   611
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   612
  "rec_lo = 
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   613
     (let calc = CN rec_noteq [CN rec_mod [Id 3 1, CN rec_power [Id 3 2, Id 3 0]], Z] in
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   614
      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
   615
      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
   616
      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
   617
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   618
lemma lo_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   619
  "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
   620
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
   621
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   622
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   623
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   624
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   625
  @{text "NextPrime x"} returns the first prime number after @{text "x"};
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   626
  @{text "Pi i"} returns the i-th prime number. *}
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   627
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   628
fun NextPrime ::"nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   629
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   630
  "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
   631
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   632
definition rec_nextprime :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   633
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   634
  "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
   635
                    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
   636
                    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
   637
                    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
   638
                    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
   639
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   640
lemma nextprime_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   641
  "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
   642
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
   643
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   644
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   645
fun Pi :: "nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   646
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   647
  "Pi 0 = 2" |
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   648
  "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
   649
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   650
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   651
  "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
   652
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   653
lemma pi_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   654
  "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
   655
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
   656
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   657
end
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   658
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   659
(*
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   660
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   661
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
   662
  "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
   663
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
   664
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
   665
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   666
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   667
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
   668
  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
   669
  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
   670
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
   671
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   672
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
   673
  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
   674
  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
   675
  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
   676
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
   677
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
   678
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
   679
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
   680
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   681
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   682
(* ??? *)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   683
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
   684
  fixes n::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   685
  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
   686
  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
   687
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   688
apply(induct n)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   689
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
   690
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   691
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
   692
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
   693
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   694
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
   695
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   696
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   697
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
   698
  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
   699
  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
   700
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   701
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
   702
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
   703
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   704
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
   705
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
   706
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   707
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
   708
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   709
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   710
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   711
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   712
  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
   713
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   714
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
   715
done
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   716
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   717
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
   718
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
   719
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   720
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
   721
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
   722
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   723
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
   724
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   725
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   726
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
   727
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   728
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   729
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
   730
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   731
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   732
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
   733
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   734
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
   735
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   736
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
   737
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   738
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
   739
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   740
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   741
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
   742
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   743
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
   744
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   745
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   746
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   747
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   748
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   749
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
   750
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
   751
apply(rule sym)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   752
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
   753
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   754
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   755
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   756
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   757
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
   758
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
   759
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   760
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   761
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   762
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
   763
apply(
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   764
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   765
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
   766
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   767
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   768
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   769
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
   770
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   771
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
   772
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   773
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
   774
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   775
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
   776
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   777
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
   778
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   779
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   780
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
   781
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
   782
                   (\<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
   783
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   784
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   785
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   786
apply(rule disjI1)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   787
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
   788
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   789
apply(rule disjI2)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   790
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   791
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   792
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
   793
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   794
apply metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   795
apply(erule exE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   796
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
   797
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   798
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
   799
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
   800
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
   801
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   802
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   803
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
   804
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   805
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   806
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
   807
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
   808
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   809
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   810
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
   811
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   812
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
   813
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
   814
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
   815
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   816
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   817
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   818
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
   819
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   820
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   821
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
   822
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   823
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
   824
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
   825
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   826
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   827
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
   828
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
   829
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   830
apply(rule sym)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   831
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   832
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   833
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   834
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   835
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   836
apply(rule setsum_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   837
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   838
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   839
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   840
apply(subst setsum_cut_off_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   841
apply(auto)[2]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   842
apply(rule setsum_one_less)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   843
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   844
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   845
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   846
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   847
thm setsum_eq_one_le
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   848
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
   849
                   (\<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
   850
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   851
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   852
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   853
apply(rule disjI1)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   854
apply(rule setsum_eq_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   855
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   856
apply(rule disjI2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   857
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   858
apply(clarify)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   859
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
   860
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   861
apply metis
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   862
apply(erule exE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   863
apply(subgoal_tac "l \<le> x")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   864
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   865
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
   866
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   867
apply(rotate_tac 4)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   868
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   869
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   870
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
   871
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   872
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   873
apply(rotate_tac 5)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   874
apply(drule not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   875
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   876
apply(auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   877
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
   878
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   879
apply (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   880
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   881
apply(rotate_tac 3)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   882
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   883
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   884
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   885
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
   886
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   887
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   888
apply (metis neq0_conv not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   889
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   890
apply (metis (mono_tags) LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   891
by (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   892
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   893
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   894
  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
   895
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   896
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
   897
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   898
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   899
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   900
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
   901
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
   902
(*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
   903
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
   904
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   905
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   906
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
   907
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   908
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   909
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
   910
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   911
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
   912
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   913
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
   914
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   915
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
   916
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   917
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   918
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
   919
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   920
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
   921
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   922
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   923
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   924
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   925
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   926
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
   927
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   928
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
   929
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   930
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   931
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   932
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
   933
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   934
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   935
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   936
  "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
   937
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
   938
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
   939
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   940
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   941
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
   942
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   943
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
   944
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   945
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   946
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   947
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   948
  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
   949
  "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
   950
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   951
(*
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   952
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   953
  assumes "P x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   954
    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
   955
  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
   956
unfolding Great_def 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   957
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
   958
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
   959
*)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   960
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   961
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   962
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   963
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   964
  "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
   965
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
   966
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
   967
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   968
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   969
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
   970
oops
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   971
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   972
lemma
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   973
  "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
   974
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
   975
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
   976
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   977
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   978
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   979
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   980
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   981
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   982
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   983
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   984
thm Min_insert
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   985
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   986
oops
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
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   990
definition quo :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   991
  where
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   992
  "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
   993
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   994
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
   995
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   996
  "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
   997
      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
   998
                [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
   999
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1000
lemma div_lemma [simp]:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1001
  "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
  1002
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
  1003
apply(rule impI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1004
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1005
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1006
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1007
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1008
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1009
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1010
apply (metis div_le_dividend le_SucI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1011
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1012
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1013
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1014
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
  1015
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1016
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1017
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
  1018
apply(simp add: quo_def)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1019
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1020
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1021
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
  1022
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1023
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
  1024
  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
  1025
                        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
  1026
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1027
definition
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1028
  "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
  1029
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1030
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
  1031
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
  1032
apply(simp only: rec_minr_def)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1033
apply(simp only: sigma1_lemma)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1034
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
  1035
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
  1036
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
  1037
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
  1038
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
  1039
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
  1040
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
  1041
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
  1042
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
  1043
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
  1044
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
  1045
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
  1046
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
  1047
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
  1048
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
  1049
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
  1050
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
  1051
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
  1052
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
  1053
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
  1054
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
  1055
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
  1056
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
  1057
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
  1058
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
  1059
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
  1060
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
  1061
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
  1062
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
  1063
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
  1064
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
  1065
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
  1066
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
  1067
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
  1068
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1069
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
  1070
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
  1071
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
  1072
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1073
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
  1074
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
  1075
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
  1076
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
  1077
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
  1078
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
  1079
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
  1080
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
  1081
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
  1082
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
  1083
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
  1084
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
  1085
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
  1086
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
  1087
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
  1088
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1089
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1090
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
  1091
  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
  1092
                        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
  1093
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1094
lemma Minr2_Minr: 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1095
  "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
  1096
apply(auto)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1097
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
  1098
apply(rule min_absorb2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1099
apply(subst Min_le_iff)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1100
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
  1101
done
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
  1102
 *)