thys/Recs.thy
author Christian Urban <christian dot urban at kcl dot ac dot uk>
Fri, 10 May 2013 09:06:48 +0100
changeset 251 ff54a3308fd6
parent 250 745547bdc1c7
child 254 0546ae452747
permissions -rwxr-xr-x
added test version
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
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
     2
imports Main 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
     3
        "~~/src/HOL/Number_Theory/Primes" 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
     4
         Fact
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     5
begin
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
     6
244
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
  some definitions from 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
     9
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    10
    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
    11
    I M Chiswell 
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
  and
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    14
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    15
    Lecture on undecidability
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    16
    Michael M. Wolf 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    17
*)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    18
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    19
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
    20
  "(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
    21
  "(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
    22
  "(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
    23
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
    24
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    25
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
    26
  "(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
    27
  "(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
    28
  "(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
    29
  "(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
    30
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
    31
243
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
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
    34
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    35
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
    36
  "(\<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
    37
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
    38
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    39
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
    40
  "(\<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
    41
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
    42
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    43
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
    44
  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
    45
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
    46
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
    47
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    49
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
    50
  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
    51
  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
    52
        "(\<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
    53
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
    54
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    55
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
    56
  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
    57
  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
    58
        "(\<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
    59
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
    60
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    61
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
    62
  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
    63
  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
    64
  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
    65
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
    66
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
    67
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    68
lemma setsum_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    69
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    70
  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
    71
  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
    72
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    73
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    74
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    75
lemma setsum_eq_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    76
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    77
  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
    78
  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
    79
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    80
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    81
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
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
    83
  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
    84
  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
    85
  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
    86
  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
    87
  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
    88
proof -
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_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
    90
    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
    91
  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
    92
    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
    93
  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
    94
    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
    95
  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
    96
  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
    97
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    98
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    99
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
   100
  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
   101
  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
   102
  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
   103
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
   104
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   105
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
   106
  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
   107
  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
   108
  shows "(\<Prod>i \<le> n. f i) \<le> 1" 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   109
using assms 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   110
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
   111
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   112
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
   113
  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
   114
  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
   115
  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
   116
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
   117
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   118
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
   119
  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
   120
  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
   121
  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
   122
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
   123
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   124
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
   125
  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
   126
  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
   127
  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
   128
  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
   129
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   130
  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
   131
    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
   132
  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
   133
    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
   134
  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
   135
  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
   136
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   137
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   138
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
   139
  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
   140
  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
   141
  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
   142
  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
   143
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   144
  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
   145
    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
   146
  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
   147
    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
   148
  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
   149
  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
   150
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   151
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   152
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
   153
  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
   154
  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
   155
        "(\<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
   156
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
   157
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   158
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   159
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   160
section {* Recursive Functions *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   161
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   162
datatype recf =  Z
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   163
              |  S
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   164
              |  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
   165
              |  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
   166
              |  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
   167
              |  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
   168
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   169
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
   170
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   171
  "arity Z = 1" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   172
| "arity S = 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   173
| "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
   174
| "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
   175
| "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
   176
| "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
   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
  "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
   180
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   181
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
  "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
   183
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   184
abbreviation
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   185
  "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
   186
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   187
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
   188
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   189
  "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
   190
| "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
   191
| "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
   192
| "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
   193
| "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
   194
| "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
   195
     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
   196
| "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
   197
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   198
inductive 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   199
  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
   200
where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   201
  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
   202
| 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
   203
| 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
   204
| 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
   205
              \<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
   206
| 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
   207
              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
   208
              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
   209
              \<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
   210
| 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
   211
              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
   212
              \<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
   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
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   215
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
   216
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   217
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   218
  @{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
   219
  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
   220
*}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   221
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
   222
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   223
  "constn 0 = Z"  |
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   224
  "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
   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_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
   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_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
   231
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   232
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   233
  "rec_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
   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 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   236
  "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
   237
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   238
definition
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   239
  "rec_fact = PR (constn 1) (CN rec_mult [CN S [Id 3 0], Id 3 1])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   242
  "rec_pred = CN (PR Z (Id 3 0)) [Id 1 0, Id 1 0]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   243
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   245
  "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
   246
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   248
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   249
  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
   250
  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
   251
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   252
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   253
  "rec_sign = CN rec_minus [constn 1, CN rec_minus [constn 1, Id 1 0]]"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   254
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   255
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   256
  "rec_not = CN rec_minus [constn 1, Id 1 0]"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   257
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   258
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   259
  @{text "rec_eq"} compares two arguments: returns @{text "1"}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   260
  if they are equal; @{text "0"} otherwise. *}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   261
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   262
  "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
   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_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
   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_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
   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 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   271
  "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
   272
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   273
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   274
  "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
   275
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   276
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
   277
  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
   278
  zero, y otherwise *}
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   279
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   280
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   281
  "rec_ifz = PR (Id 2 0) (Id 4 3)"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   282
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   283
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   284
  "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
   285
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   286
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   287
  @{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
   288
  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
   289
240
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_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
   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
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
  "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
   295
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   296
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
   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_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
   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_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
   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_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
   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
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   308
  "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
   309
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   310
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
   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_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
   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_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
   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_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
   320
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
definition
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   322
  "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
   323
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   324
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
   325
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   326
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   327
  "rec_dvd = 
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   328
     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
   329
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   330
definition
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   331
  "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
   332
              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
   333
              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
   334
              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
   335
              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
   336
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   337
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
   338
  "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
   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
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   341
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
   342
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   343
definition 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   344
  "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
   345
    (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
   346
     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
   347
     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
   348
     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
   349
     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
   350
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   351
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   352
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
   353
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   354
lemma 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
   355
  "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
   356
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
   357
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   358
lemma 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
   359
  "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
   360
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
   361
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   362
lemma 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
   363
  "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
   364
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
   365
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   366
lemma 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
   367
  "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
   368
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
   369
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   370
lemma 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
   371
  "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
   372
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
   373
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   374
lemma 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
   375
  "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
   376
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
   377
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   378
lemma 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
   379
  "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
   380
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
   381
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
lemma minus_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   383
  "rec_eval rec_minus [x, y] = x - y"
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   384
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
   385
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   386
lemma sign_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   387
  "rec_eval rec_sign [x] = (if x = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   388
by (simp add: rec_sign_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   390
lemma not_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   391
  "rec_eval rec_not [x] = (if x = 0 then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   392
by (simp add: rec_not_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   393
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   394
lemma eq_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   395
  "rec_eval rec_eq [x, y] = (if x = y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   396
by (simp add: rec_eq_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   397
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   398
lemma noteq_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   399
  "rec_eval rec_noteq [x, y] = (if x \<noteq> y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   400
by (simp add: rec_noteq_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   401
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   402
lemma conj_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   403
  "rec_eval rec_conj [x, y] = (if x = 0 \<or> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   404
by (simp add: rec_conj_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   405
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   406
lemma disj_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   407
  "rec_eval rec_disj [x, y] = (if x = 0 \<and> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   408
by (simp add: rec_disj_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   409
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   410
lemma imp_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   411
  "rec_eval rec_imp [x, y] = (if 0 < x \<and> y = 0 then 0 else 1)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   412
by (simp add: rec_imp_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   413
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   414
lemma less_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   415
  "rec_eval rec_less [x, y] = (if x < y then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   416
by (simp add: rec_less_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   418
lemma le_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   419
  "rec_eval rec_le [x, y] = (if (x \<le> y) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   420
by(simp add: rec_le_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   422
lemma ifz_lemma [simp]:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   423
  "rec_eval rec_ifz [z, x, y] = (if z = 0 then x else y)" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   424
by (case_tac z) (simp_all add: rec_ifz_def)
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   426
lemma if_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   427
  "rec_eval rec_if [z, x, y] = (if 0 < z then x else y)" 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   428
by (simp add: rec_if_def)
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   429
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   430
lemma sigma1_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   431
  shows "rec_eval (rec_sigma1 f) [x, y] = (\<Sum> z \<le> x. (rec_eval f)  [z, y])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   432
by (induct x) (simp_all add: rec_sigma1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   433
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   434
lemma sigma2_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   435
  shows "rec_eval (rec_sigma2 f) [x, y1, y2] = (\<Sum> z \<le> x. (rec_eval f)  [z, y1, y2])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   436
by (induct x) (simp_all add: rec_sigma2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   437
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   438
lemma accum1_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   439
  shows "rec_eval (rec_accum1 f) [x, y] = (\<Prod> z \<le> x. (rec_eval f)  [z, y])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   440
by (induct x) (simp_all add: rec_accum1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   441
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   442
lemma accum2_lemma [simp]: 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   443
  shows "rec_eval (rec_accum2 f) [x, y1, y2] = (\<Prod> z \<le> x. (rec_eval f)  [z, y1, y2])"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   444
by (induct x) (simp_all add: rec_accum2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   445
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   446
lemma ex1_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   447
 "rec_eval (rec_ex1 f) [x, y] = (if (\<exists>z \<le> x. 0 < rec_eval f [z, y]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   448
by (simp add: rec_ex1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   449
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   450
lemma ex2_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   451
 "rec_eval (rec_ex2 f) [x, y1, y2] = (if (\<exists>z \<le> x. 0 < rec_eval f [z, y1, y2]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   452
by (simp add: rec_ex2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   453
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   454
lemma all1_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   455
 "rec_eval (rec_all1 f) [x, y] = (if (\<forall>z \<le> x. 0 < rec_eval f [z, y]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   456
by (simp add: rec_all1_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   457
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   458
lemma all2_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   459
 "rec_eval (rec_all2 f) [x, y1, y2] = (if (\<forall>z \<le> x. 0 < rec_eval f [z, y1, y2]) then 1 else 0)"
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   460
by (simp add: rec_all2_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   461
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   462
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
lemma dvd_alt_def:
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   464
  fixes x y k:: nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   465
  shows "(x dvd y) = (\<exists> k \<le> y. y = x * k)"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
apply(auto simp add: dvd_def)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
apply(case_tac x)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   468
apply(auto)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   469
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   471
lemma dvd_lemma [simp]:
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   472
  "rec_eval rec_dvd [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
   473
unfolding dvd_alt_def
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   474
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
   475
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   476
fun Quo where
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   477
  "Quo x 0 = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   478
| "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
   479
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   480
lemma Quo0:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   481
  shows "Quo 0 y = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   482
apply(induct y)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   483
apply(auto)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   484
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   485
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   486
lemma Quo1:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   487
  "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
   488
by (induct y) (simp_all)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   489
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   490
lemma Quo2: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   491
  "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
   492
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
   493
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   494
lemma Quo3:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   495
  "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
   496
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
   497
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   498
lemma Quo4:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   499
  assumes h: "0 < x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   500
  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
   501
proof -
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   502
  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
   503
  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
   504
  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
   505
  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
   506
qed
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   507
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   508
lemma Quo_div: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   509
  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
   510
apply(case_tac "x = 0")
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   511
apply(simp add: Quo0)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   512
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
   513
apply(auto intro: Quo1 Quo4)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   514
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   515
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   516
lemma Quo_rec_quo:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   517
  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
   518
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
   519
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   520
lemma quo_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   521
  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
   522
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
   523
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   524
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
   525
  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
   526
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
   527
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   528
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   529
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
   530
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   531
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
   532
  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
   533
  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
   534
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
   535
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
   536
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   537
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   538
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   539
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
   540
  "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
   541
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
   542
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   543
section {* Bounded Maximisation *}
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   544
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   545
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
   546
  "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
   547
| "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
   548
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   549
definition BMax_set :: "(nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   550
  where "BMax_set R x = Max ({z. z \<le> x \<and> R z} \<union> {0})"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   551
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   552
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   553
  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
   554
  "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
   555
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   556
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   557
  fixes x::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   558
  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
   559
  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
   560
unfolding Great_def 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   561
using assms by(rule_tac the_equality) (auto intro: le_antisym)
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   562
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   563
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
   564
 "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
   565
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   566
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
   567
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
   568
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   569
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   570
lemma BMax_rec_eq2:
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   571
  "BMax_rec R x = Max ({z. z \<le> x \<and> R z} \<union> {0})"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   572
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   573
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
   574
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
   575
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   576
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   577
definition 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   578
  "rec_max1 f = PR (constn 0) (CN rec_ifz [CN f [CN S [Id 3 0], Id 3 2], CN S [Id 4 0], Id 4 1])"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   579
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   580
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
   581
  "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
   582
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
   583
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   584
definition 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   585
  "rec_max2 f = PR (constn 0) (CN rec_ifz [CN f [CN S [Id 4 0], Id 4 2, Id 4 3], CN S [Id 4 0], Id 4 1])"
243
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
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   591
section {* Encodings *}
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   592
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   593
fun log :: "nat \<Rightarrow> nat" where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   594
  [simp del]: "log n = (if n < 2 then 0 else Suc (log (n div 2)))"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   595
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   596
lemma log_zero [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   597
  "log 0 = 0"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   598
  by (simp add: log.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   599
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   600
lemma log_one [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   601
  "log 1 = 0"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   602
  by (simp add: log.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   603
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   604
lemma log_suc [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   605
  "log (Suc 0) = 0"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   606
  by (simp add: log.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   607
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   608
lemma log_rec:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   609
  "n \<ge> 2 \<Longrightarrow> log n = Suc (log (n div 2))"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   610
  by (simp add: log.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   611
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   612
lemma log_twice [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   613
  "n \<noteq> 0 \<Longrightarrow> log (2 * n) = Suc (log n)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   614
  by (simp add: log_rec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   615
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   616
lemma log_half [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   617
  "log (n div 2) = log n - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   618
proof (cases "n < 2")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   619
  case True
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   620
  then have "n = 0 \<or> n = 1" by arith
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   621
  then show ?thesis by (auto simp del: One_nat_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   622
next
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   623
  case False then show ?thesis by (simp add: log_rec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   624
qed
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   625
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   626
lemma log_exp [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   627
  "log (2 ^ n) = n"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   628
  by (induct n) simp_all
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   629
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   630
fun oddfactor :: "nat \<Rightarrow> nat" where
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   631
  [simp del]: "oddfactor n = (if n = 0 then 0 else if even n then oddfactor (n div 2) else n)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   632
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   633
lemma oddfactor[simp]:
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   634
  "oddfactor 0 = 0"
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   635
  "odd n \<Longrightarrow> oddfactor n = n"
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   636
  "even n \<Longrightarrow> oddfactor n = oddfactor (n div 2)"
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   637
apply(simp_all add: oddfactor.simps)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   638
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   639
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   640
lemma oddfactor_odd:
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   641
  "oddfactor n = 0 \<or> odd (oddfactor n)" 
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   642
apply(induct n rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   643
apply(case_tac "n = 0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   644
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   645
apply(case_tac "odd n")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   646
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   647
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   648
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   649
lemma bigger: "oddfactor (Suc n) > 0"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   650
apply(induct n rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   651
apply(case_tac "n = 0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   652
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   653
apply(case_tac "odd n")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   654
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   655
apply(drule_tac x="n div 2" in spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   656
apply(drule mp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   657
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   658
by (smt numeral_2_eq_2 odd_nat_plus_one_div_two)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   659
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   660
fun pencode :: "nat \<Rightarrow> nat \<Rightarrow> nat" where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   661
  "pencode m n = (2 ^ m) * ((2 * n) + 1) - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   662
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   663
fun pdecode2 :: "nat \<Rightarrow> nat" where
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   664
  "pdecode2 z = (oddfactor (Suc z) - 1) div 2"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   665
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   666
fun pdecode1 :: "nat \<Rightarrow> nat" where
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   667
  "pdecode1 z = log ((Suc z) div (oddfactor (Suc z)))"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   668
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   669
lemma k:
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   670
  "odd n \<Longrightarrow> oddfactor (2 ^ m * n) = n"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   671
apply(induct m)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   672
apply(simp_all)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   673
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   674
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   675
lemma ww: "\<exists>k. n = 2 ^ k * oddfactor n"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   676
apply(induct n rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   677
apply(case_tac "n=0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   678
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   679
apply(case_tac "odd n")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   680
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   681
apply(rule_tac x="0" in exI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   682
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   683
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   684
apply(drule_tac x="n div 2" in spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   685
apply(erule impE)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   686
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   687
apply(erule exE)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   688
apply(rule_tac x="Suc k" in exI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   689
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   690
by (metis div_mult_self2_is_id even_mult_two_ex nat_mult_assoc nat_mult_commute zero_neq_numeral)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   691
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   692
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   693
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   694
lemma t:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   695
  "(Suc (Suc m)) div 2 = Suc (m div 2)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   696
by (induct m) (auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   697
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   698
lemma u:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   699
  "((Suc (Suc m)) mod 2 = 0) <-> m mod 2 = 0"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   700
by (auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   701
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   702
lemma u2: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   703
  "0 < n ==> 2 * 2 ^ (n - 1) = (2::nat) ^ (n::nat)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   704
by (induct n) (simp_all)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   705
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   706
lemma test: "x = y \<Longrightarrow> 2 * x = 2 * y"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   707
by simp
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   708
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   709
lemma m: "0 < n ==> 2 ^ log (n div (oddfactor n)) = n div (oddfactor n)"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   710
apply(induct n rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   711
apply(case_tac "n=0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   712
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   713
apply(case_tac "odd n")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   714
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   715
apply(drule_tac x="n div 2" in spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   716
apply(drule mp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   717
apply(auto)[1]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   718
apply(drule mp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   719
apply (metis One_nat_def Suc_lessI div_2_gt_zero odd_1_nat)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   720
apply(subst (asm) oddfactor(3)[symmetric])
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   721
apply(simp)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   722
apply(subst (asm) oddfactor(3)[symmetric])
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   723
apply(simp)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   724
apply(subgoal_tac "n div 2 div oddfactor n = n div (oddfactor n) div 2")
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   725
prefer 2
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   726
apply (metis div_mult2_eq nat_mult_commute)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   727
apply(simp only: log_half)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   728
apply(case_tac "n div oddfactor n = 0")
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   729
apply(simp)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   730
apply(simp del: oddfactor)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   731
apply(drule test)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   732
apply(subst (asm) power.simps(2)[symmetric])
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   733
apply(subgoal_tac "Suc (log (n div oddfactor n) - 1) = log (n div oddfactor n)")
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   734
prefer 2
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   735
apply (smt Recs.log.simps Suc_1 div_less div_mult_self1_is_id log_half log_zero numeral_1_eq_Suc_0 numeral_One odd_1_nat odd_nat_plus_one_div_two one_less_numeral_iff power_one_right semiring_norm(76))
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   736
apply(simp only:)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   737
apply(subst dvd_mult_div_cancel)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   738
apply (smt Suc_1 div_by_0 div_mult_self2_is_id oddfactor_odd dvd_power even_Suc even_numeral_nat even_product_nat nat_even_iff_2_dvd power_0 ww)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   739
apply(simp (no_asm))
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   740
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   741
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   742
lemma m1: "n div oddfactor n * oddfactor n = n"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   743
apply(induct n rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   744
apply(case_tac "n=0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   745
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   746
apply(case_tac "odd n")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   747
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   748
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   749
apply(drule_tac x="n div 2" in spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   750
apply(drule mp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   751
apply(auto)[1]
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   752
by (metis add_eq_if diff_add_inverse oddfactor(3) mod_eq_0_iff mult_div_cancel nat_mult_commute ww)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   753
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   754
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   755
lemma m2: "0 < n ==> 2 ^ log (n div (oddfactor n)) * (oddfactor n) = n"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   756
apply(subst m)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   757
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   758
apply(subst m1)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   759
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   760
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   761
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   762
lemma y1:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   763
  "pdecode2 (pencode m n) = n"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   764
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   765
apply(subst k)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   766
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   767
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   768
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   769
lemma y2:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   770
  "pdecode1 (pencode m n) = m"
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   771
using [[simp_trace]]
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   772
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   773
apply(subst k)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   774
apply(auto)[1]
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   775
using [[simp_trace_depth_limit=10]]
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   776
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   777
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   778
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   779
lemma yy: 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   780
  "pencode (pdecode1 m) (pdecode2 m) = m"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   781
apply(induct m rule: nat_less_induct)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   782
apply(simp (no_asm))
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   783
apply(case_tac "n = 0")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   784
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   785
apply(subst dvd_mult_div_cancel)
251
ff54a3308fd6 added test version
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 250
diff changeset
   786
using oddfactor_odd
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   787
apply -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   788
apply(drule_tac x="Suc n" in meta_spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   789
apply(erule disjE)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   790
apply(auto)[1]
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   791
apply (metis even_num_iff nat_even_iff_2_dvd odd_pos)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   792
using bigger
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   793
apply -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   794
apply(rotate_tac 3)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   795
apply(drule_tac x="n" in meta_spec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   796
apply(simp del: pencode.simps pdecode2.simps pdecode1.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   797
apply(subst m2)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   798
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   799
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   800
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   801
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   802
fun penc where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   803
 "penc (m, n) = pencode m n"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   804
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   805
fun pdec where
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   806
 "pdec m = (pdecode1 m, pdecode2 m)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   807
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   808
lemma q1: "penc (pdec m) = m"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   809
apply(simp only: penc.simps pdec.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   810
apply(rule yy)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   811
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   812
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   813
lemma q2: "pdec (penc m) = m"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   814
apply(simp only: penc.simps pdec.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   815
apply(case_tac m)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   816
apply(simp only: penc.simps pdec.simps)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   817
apply(subst y1)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   818
apply(subst y2)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   819
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   820
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   821
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   822
lemma inj_penc: "inj_on penc A"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   823
apply(rule inj_on_inverseI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   824
apply(rule q2)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   825
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   826
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   827
lemma inj_pdec: "inj_on pdec A"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   828
apply(rule inj_on_inverseI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   829
apply(rule q1)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   830
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   831
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   832
lemma surj_penc: "surj penc"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   833
apply(rule surjI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   834
apply(rule q1)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   835
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   836
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   837
lemma surj_pdec: "surj pdec"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   838
apply(rule surjI)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   839
apply(rule q2)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   840
done
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   841
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   842
lemma 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   843
  "bij pdec"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   844
by(simp add: bij_def surj_pdec inj_pdec)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   845
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   846
lemma 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   847
  "bij penc"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   848
by(simp add: bij_def surj_penc inj_penc)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   849
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   850
lemma "a \<le> penc (a, 0)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   851
apply(induct a)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   852
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   853
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   854
by (smt nat_one_le_power)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   855
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   856
lemma "penc(a, 0) \<le> penc (a, b)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   857
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   858
by (metis diff_le_mono le_add1 mult_2_right mult_le_mono1 nat_add_commute nat_mult_1 nat_mult_commute)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   859
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   860
lemma "b \<le> penc (a, b)"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   861
apply(simp)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   862
proof -
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   863
  have f1: "(1\<Colon>nat) + 1 = 2"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   864
    by (metis mult_2 nat_mult_1_right)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   865
  have f2: "\<And>x\<^isub>1 x\<^isub>2. (x\<^isub>1\<Colon>nat) \<le> x\<^isub>1 * x\<^isub>2 \<or> \<not> 1 \<le> x\<^isub>2"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   866
    by (metis mult_le_mono2 nat_mult_1_right)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   867
  have "1 + (b + b) \<le> 1 + b \<longrightarrow> b \<le> (1 + (b + b)) * (1 + 1) ^ a - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   868
    by (metis le_add1 le_trans nat_add_left_cancel_le)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   869
  hence "(1 + (b + b)) * (1 + 1) ^ a \<le> 1 + b \<longrightarrow> b \<le> (1 + (b + b)) * (1 + 1) ^ a - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   870
    using f2 by (metis le_add1 le_trans one_le_power)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   871
  hence "b \<le> 2 ^ a * (b + b + 1) - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   872
    using f1 by (metis le_diff_conv nat_add_commute nat_le_linear nat_mult_commute)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   873
  thus "b \<le> 2 ^ a * (2 * b + 1) - 1"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   874
    by (metis mult_2)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   875
qed
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   876
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   877
section {* Discrete Logarithms *}
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   878
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   879
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   880
  "rec_lg = 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   881
     (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
   882
      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
   883
      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
   884
      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
   885
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   886
definition
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   887
  "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
   888
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   889
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
   890
  "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
   891
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
   892
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   893
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   894
  "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
   895
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   896
definition
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   897
  "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
   898
     (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
   899
      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
   900
      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
   901
      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
   902
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   903
lemma lo_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   904
  "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
   905
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
   906
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   907
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   908
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   909
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   910
  @{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
   911
  @{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
   912
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   913
definition NextPrime ::"nat \<Rightarrow> nat"
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   914
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   915
  "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
   916
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   917
definition rec_nextprime :: "recf"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   918
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   919
  "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
   920
                    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
   921
                    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
   922
                    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
   923
                    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
   924
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   925
lemma nextprime_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   926
  "rec_eval rec_nextprime [x] = NextPrime x"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   927
by (simp add: rec_nextprime_def Let_def NextPrime_def)
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   928
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   929
lemma NextPrime_simps [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   930
  shows "NextPrime 2 = 3"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   931
  and   "NextPrime 3 = 5"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   932
apply(simp_all add: NextPrime_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   933
apply(rule Least_equality)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   934
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   935
apply(eval)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   936
apply(rule Least_equality)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   937
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   938
apply(eval)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   939
apply(case_tac "y = 4")
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   940
apply(auto)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   941
done
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   942
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   943
fun Pi :: "nat \<Rightarrow> nat"
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   944
  where
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   945
  "Pi 0 = 2" |
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   946
  "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
   947
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   948
lemma Pi_simps [simp]:
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   949
  shows "Pi 1 = 3"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   950
  and   "Pi 2 = 5"
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   951
using NextPrime_simps
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   952
by(simp_all add: numeral_eq_Suc One_nat_def)
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   953
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   954
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   955
  "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
   956
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   957
lemma pi_lemma [simp]:
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   958
  "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
   959
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
   960
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   961
end
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   962
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   963
(*
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   964
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   965
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
   966
  "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
   967
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
   968
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
   969
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   970
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   971
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
   972
  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
   973
  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
   974
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
   975
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   976
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
   977
  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
   978
  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
   979
  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
   980
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
   981
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
   982
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
   983
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
   984
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   985
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   986
(* ??? *)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   987
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
   988
  fixes n::nat
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   989
  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
   990
  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
   991
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   992
apply(induct n)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   993
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
   994
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   995
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
   996
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
   997
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   998
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
   999
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1000
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1001
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
  1002
  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
  1003
  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
  1004
using assms
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1005
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
  1006
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
  1007
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1008
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
  1009
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
  1010
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1011
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
  1012
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1013
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1014
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1015
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1016
  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
  1017
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1018
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
  1019
done
241
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
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
  1022
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
  1023
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1024
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
  1025
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
  1026
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1027
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
  1028
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1029
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1030
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
  1031
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1032
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1033
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
  1034
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1035
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1036
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
  1037
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1038
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
  1039
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1040
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
  1041
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1042
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
  1043
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1044
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1045
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
  1046
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1047
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
  1048
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1049
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1050
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1051
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1052
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1053
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
  1054
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
  1055
apply(rule sym)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1056
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
  1057
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1058
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1059
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1060
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1061
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
  1062
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
  1063
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1064
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1065
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1066
apply(simp add: rec_minr2_def)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1067
apply(
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1068
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1069
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
  1070
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1071
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1072
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1073
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
  1074
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1075
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
  1076
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1077
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
  1078
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1079
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
  1080
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1081
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
  1082
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1083
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1084
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
  1085
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
  1086
                   (\<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
  1087
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1088
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1089
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1090
apply(rule disjI1)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1091
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
  1092
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1093
apply(rule disjI2)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1094
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1095
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1096
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
  1097
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1098
apply metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1099
apply(erule exE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1100
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
  1101
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1102
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
  1103
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
  1104
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
  1105
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1106
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1107
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
  1108
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1109
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1110
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
  1111
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
  1112
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1113
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1114
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
  1115
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1116
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
  1117
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
  1118
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
  1119
apply(assumption)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1120
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1121
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1122
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
  1123
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1124
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1125
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
  1126
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1127
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
  1128
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
  1129
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1130
lemma minr_lemma:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1131
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
  1132
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
  1133
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1134
apply(rule sym)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1135
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1136
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1137
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1138
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1139
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1140
apply(rule setsum_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1141
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1142
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1143
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1144
apply(subst setsum_cut_off_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1145
apply(auto)[2]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1146
apply(rule setsum_one_less)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1147
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1148
apply(rule setprod_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1149
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1150
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1151
thm setsum_eq_one_le
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1152
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
  1153
                   (\<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
  1154
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1155
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1156
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1157
apply(rule disjI1)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1158
apply(rule setsum_eq_one_le)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1159
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1160
apply(rule disjI2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1161
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1162
apply(clarify)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1163
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
  1164
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1165
apply metis
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1166
apply(erule exE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1167
apply(subgoal_tac "l \<le> x")
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1168
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1169
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
  1170
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1171
apply(rotate_tac 4)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1172
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1173
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1174
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
  1175
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1176
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1177
apply(rotate_tac 5)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1178
apply(drule not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1179
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1180
apply(auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1181
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
  1182
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1183
apply (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1184
apply(subst setsum_least_eq)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1185
apply(rotate_tac 3)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1186
apply(assumption)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1187
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1188
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1189
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
  1190
prefer 2
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1191
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1192
apply (metis neq0_conv not_less_Least)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1193
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1194
apply (metis (mono_tags) LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1195
by (metis LeastI_ex)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1196
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1197
lemma disjCI2:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1198
  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
  1199
apply (rule classical)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1200
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
  1201
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1202
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1203
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1204
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
  1205
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
  1206
(*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
  1207
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
  1208
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1209
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1210
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
  1211
apply(auto)[2]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1212
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1213
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
  1214
apply(rule disjCI)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1215
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
  1216
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1217
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
  1218
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1219
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
  1220
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1221
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1222
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
  1223
apply(clarify)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1224
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
  1225
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1226
thm disj_CE
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1227
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1228
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1229
prefer 2
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1230
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
  1231
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1232
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
  1233
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1234
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1235
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1236
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
  1237
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1238
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1239
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1240
  "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
  1241
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
  1242
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
  1243
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1244
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1245
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
  1246
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1247
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
  1248
apply(auto)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1249
done
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1250
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1251
definition (in ord)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1252
  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
  1253
  "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
  1254
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1255
(*
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1256
lemma Great_equality:
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1257
  assumes "P x"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1258
    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
  1259
  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
  1260
unfolding Great_def 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1261
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
  1262
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
  1263
*)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1264
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1265
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1266
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1267
lemma 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1268
  "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
  1269
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
  1270
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
  1271
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1272
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1273
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
  1274
oops
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1275
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1276
lemma
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1277
  "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
  1278
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
  1279
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
  1280
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1281
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1282
apply(erule disjE)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1283
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1284
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1285
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1286
apply(simp)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1287
apply(auto)[1]
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1288
thm Min_insert
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1289
defer
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1290
oops
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1291
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1292
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1293
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1294
definition quo :: "nat \<Rightarrow> nat \<Rightarrow> nat"
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1295
  where
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1296
  "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
  1297
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1298
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1299
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
  1300
  "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
  1301
      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
  1302
                [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
  1303
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1304
lemma div_lemma [simp]:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1305
  "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
  1306
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
  1307
apply(rule impI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1308
apply(rule Min_eqI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1309
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1310
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1311
apply(erule disjE)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1312
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1313
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1314
apply (metis div_le_dividend le_SucI)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1315
defer
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1316
apply(simp)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1317
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1318
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
  1319
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1320
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1321
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
  1322
apply(simp add: quo_def)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1323
apply(auto)[1]
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1324
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1325
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
  1326
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1327
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
  1328
  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
  1329
                        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
  1330
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1331
definition
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1332
  "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
  1333
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1334
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
  1335
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
  1336
apply(simp only: rec_minr_def)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1337
apply(simp only: sigma1_lemma)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1338
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
  1339
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
  1340
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
  1341
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
  1342
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
  1343
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
  1344
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
  1345
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
  1346
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
  1347
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
  1348
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
  1349
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
  1350
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
  1351
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
  1352
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
  1353
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
  1354
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
  1355
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
  1356
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
  1357
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
  1358
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
  1359
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
  1360
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
  1361
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
  1362
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
  1363
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
  1364
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
  1365
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
  1366
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
  1367
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
  1368
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
  1369
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
  1370
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
  1371
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
  1372
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1373
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
  1374
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
  1375
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
  1376
defer
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1377
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
  1378
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
  1379
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
  1380
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
  1381
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
  1382
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
  1383
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
  1384
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
  1385
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
  1386
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
  1387
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
  1388
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
  1389
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
  1390
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
  1391
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
  1392
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
  1393
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1394
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
  1395
  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
  1396
                        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
  1397
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1398
lemma Minr2_Minr: 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1399
  "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
  1400
apply(auto)
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1401
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
  1402
apply(rule min_absorb2)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1403
apply(subst Min_le_iff)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
  1404
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
  1405
done
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
  1406
 *)