thys2/Recs.thy
author Christian Urban <urbanc@in.tum.de>
Thu, 10 Jan 2019 13:00:04 +0000
changeset 295 fa6f654cbc13
parent 294 6836da75b3ac
child 296 3fee65a40838
permissions -rwxr-xr-x
updated to Isabelle 2017
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
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
     2
  imports Main
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
     3
     "~~/src/HOL/Library/Nat_Bijection"
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
     4
     "~~/src/HOL/Library/Discrete"
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
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
     7
declare One_nat_def[simp del]
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
     8
244
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
  some definitions from 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    11
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    12
    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
    13
    I M Chiswell 
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
  and
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    16
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    17
    Lecture on undecidability
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    18
    Michael M. Wolf 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    19
*)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    20
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    21
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
    22
  "(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
    23
  "(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
    24
  "(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
    25
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
    26
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    27
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
    28
  "(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
    29
  "(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
    30
  "(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
    31
  "(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
    32
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
    33
243
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
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
    36
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    37
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
    38
  "(\<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
    39
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
    40
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    41
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
    42
  "(\<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
    43
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
    44
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    45
lemma setsum_add_nat_ivl2: "n \<le> p  \<Longrightarrow>
294
6836da75b3ac updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
    46
  sum f {..<n} + sum f {n..p} = sum f {..p::nat}"
6836da75b3ac updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
    47
  apply(subst sum.union_disjoint[symmetric])
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    48
  apply(auto simp add: ivl_disj_un_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
    49
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    50
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    51
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
    52
  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
    53
  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
    54
        "(\<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
    55
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
    56
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    57
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
    58
  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
    59
  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
    60
        "(\<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
    61
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
    62
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    63
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
    64
  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
    65
  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
    66
  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
    67
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
    68
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
    69
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    70
lemma setsum_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    71
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    72
  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
    73
  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
    74
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    75
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    76
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    77
lemma setsum_eq_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    78
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    79
  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
    80
  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
    81
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    82
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    83
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
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
    85
  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
    86
  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
    87
  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
    88
  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
    89
  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
    90
proof -
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_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
    92
    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
    93
  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
    94
    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
    95
  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
    96
    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
    97
  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
    98
  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
    99
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   100
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   101
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
   102
  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
   103
  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
   104
  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
   105
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
   106
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   107
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
   108
  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
   109
  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
   110
  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
   111
using assms 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   112
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
   113
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   114
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
   115
  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
   116
  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
   117
  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
   118
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
   119
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   120
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
   121
  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
   122
  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
   123
  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
   124
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
   125
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   126
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
   127
  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
   128
  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
   129
  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
   130
  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
   131
proof -
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 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
   133
    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
   134
  have "(\<Sum>i < n. f i) = (\<Sum>i \<in> {..<m}. f i) + (\<Sum>i \<in> {m..<n}. f i)"
294
6836da75b3ac updated to Isabelle 2016-1
Christian Urban <urbanc@in.tum.de>
parents: 293
diff changeset
   135
    using h1 by (metis atLeast0LessThan le0 sum_add_nat_ivl) 
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   136
  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
   137
  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
   138
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   139
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   140
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
   141
  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
   142
  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
   143
  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
   144
  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
   145
proof -
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 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
   147
    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
   148
  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
   149
    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
   150
  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
   151
  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
   152
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   153
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   154
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
   155
  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
   156
  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
   157
        "(\<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
   158
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
   159
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   160
243
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
section {* Recursive Functions *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   163
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   164
datatype recf =  Z
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   165
              |  S
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   166
              |  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
   167
              |  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
   168
              |  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
   169
              |  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
   170
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   171
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
   172
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   173
  "arity Z = 1" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   174
| "arity S = 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   175
| "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
   176
| "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
   177
| "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
   178
| "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
   179
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   180
text {* Abbreviations for calculating the arity of the constructors *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   181
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   182
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   183
  "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
   184
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   185
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   186
  "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
   187
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   188
abbreviation
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   189
  "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
   190
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   191
text {* the evaluation function and termination relation *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   192
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   193
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
   194
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   195
  "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
   196
| "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
   197
| "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
   198
| "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
   199
| "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
   200
| "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
   201
     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
   202
| "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
   203
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   204
inductive 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   205
  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
   206
where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   207
  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
   208
| 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
   209
| 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
   210
| 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
   211
              \<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
   212
| 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
   213
              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
   214
              length xs = n\<rbrakk> 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   215
              \<Longrightarrow> terminates (Pr n f g) (x # 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
   216
| 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
   217
              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
   218
              \<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
   219
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   220
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   221
section {* Arithmetic Functions *}
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   222
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   223
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   224
  @{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
   225
  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
   226
*}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
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
   228
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   229
  "constn 0 = Z"  |
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   230
  "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
   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_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
   234
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   235
definition
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   236
  "rec_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
   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_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
   240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   242
  "rec_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
   243
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   244
definition 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   245
  "rec_fact_aux = PR (constn 1) (CN rec_mult [CN S [Id 3 0], Id 3 1])"
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   246
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   247
definition
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   248
  "rec_fact = CN rec_fact_aux [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
   249
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   250
definition 
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
   251
  "rec_predi = 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
   252
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   253
definition 
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
   254
  "rec_minus = rec_swap (PR (Id 1 0) (CN rec_predi [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
   255
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   256
lemma constn_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   257
  "rec_eval (constn n) xs = n"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   258
by (induct n) (simp_all)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   259
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   260
lemma swap_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   261
  "rec_eval (rec_swap f) [x, y] = rec_eval f [y, x]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   262
by (simp add: rec_swap_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   263
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   264
lemma add_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   265
  "rec_eval rec_add [x, y] =  x + y"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   266
by (induct x) (simp_all add: rec_add_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   267
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   268
lemma mult_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   269
  "rec_eval rec_mult [x, y] = x * y"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   270
by (induct x) (simp_all add: rec_mult_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   271
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   272
lemma power_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   273
  "rec_eval rec_power [x, y] = x ^ y"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   274
by (induct y) (simp_all add: rec_power_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   275
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   276
lemma fact_aux_lemma [simp]: 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   277
  "rec_eval rec_fact_aux [x, y] = fact x"
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   278
by (induct x) (simp_all add: rec_fact_aux_def)
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   279
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   280
lemma fact_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   281
  "rec_eval rec_fact [x] = fact x"
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   282
by (simp add: rec_fact_def)
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   283
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   284
lemma pred_lemma [simp]: 
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
   285
  "rec_eval rec_predi [x] =  x - 1"
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
   286
by (induct x) (simp_all add: rec_predi_def)
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   287
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   288
lemma minus_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   289
  "rec_eval rec_minus [x, y] = x - y"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   290
by (induct y) (simp_all add: rec_minus_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   291
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   292
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   293
section {* Logical functions *}
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   294
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   295
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   296
  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
   297
  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
   298
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   299
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   300
  "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
   301
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   302
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   303
  "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
   304
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   305
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   306
  @{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
   307
  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
   308
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   309
  "rec_eq = CN rec_minus [CN (constn 1) [Id 2 0], 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
   310
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   311
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   312
  "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
   313
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   314
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   315
  "rec_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
   316
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   317
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   318
  "rec_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
   319
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   321
  "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
   322
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   323
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
   324
  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
   325
  zero, y otherwise *}
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   326
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   327
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   328
  "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
   329
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   330
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   331
  "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
   332
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   333
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   334
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
   335
  "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
   336
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
   337
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   338
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
   339
  "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
   340
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
   341
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   342
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
   343
  "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
   344
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
   345
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   346
lemma 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
   347
  "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
   348
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
   349
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   350
lemma 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
   351
  "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
   352
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
   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 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
   355
  "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
   356
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
   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 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
   359
  "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
   360
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
   361
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   362
lemma ifz_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   363
  "rec_eval rec_ifz [z, x, y] = (if z = 0 then x else y)" 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   364
by (case_tac z) (simp_all add: rec_ifz_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   365
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   366
lemma if_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   367
  "rec_eval rec_if [z, x, y] = (if 0 < z then x else y)" 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   368
by (simp add: rec_if_def)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   369
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   370
section {* Less and Le Relations *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   371
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   372
text {*
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   373
  @{text "rec_less"} compares two arguments and returns @{text "1"} if
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   374
  the first is less than the second; otherwise returns @{text "0"}. *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   375
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   376
definition 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   377
  "rec_less = CN rec_sign [rec_swap rec_minus]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   378
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   379
definition 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   380
  "rec_le = CN rec_disj [rec_less, rec_eq]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   381
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   382
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
   383
  "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
   384
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
   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 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
   387
  "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
   388
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
   389
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   390
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   391
section {* Summation and Product Functions *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   392
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   393
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   394
  "rec_sigma1 f = PR (CN f [CN Z [Id 1 0], Id 1 0]) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   395
                     (CN rec_add [Id 3 1, CN f [CN S [Id 3 0], Id 3 2]])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   396
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   397
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   398
  "rec_sigma2 f = PR (CN f [CN Z [Id 2 0], Id 2 0, Id 2 1]) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   399
                     (CN rec_add [Id 4 1, CN f [CN S [Id 4 0], 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
   400
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   401
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   402
  "rec_accum1 f = PR (CN f [CN Z [Id 1 0], Id 1 0]) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   403
                     (CN rec_mult [Id 3 1, CN f [CN S [Id 3 0], Id 3 2]])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   404
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   405
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   406
  "rec_accum2 f = PR (CN f [CN Z [Id 2 0], Id 2 0, Id 2 1]) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   407
                     (CN rec_mult [Id 4 1, CN f [CN S [Id 4 0], Id 4 2, Id 4 3]])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   408
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   409
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   410
  "rec_accum3 f = PR (CN f [CN Z [Id 3 0], Id 3 0, Id 3 1, Id 3 2]) 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   411
                     (CN rec_mult [Id 5 1, CN f [CN S [Id 5 0], Id 5 2, Id 5 3, Id 5 4]])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   412
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   413
240
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 sigma1_lemma [simp]: 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   415
  shows "rec_eval (rec_sigma1 f) [x, y] = (\<Sum> z \<le> x. rec_eval f [z, 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
   416
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
   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 sigma2_lemma [simp]: 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   419
  shows "rec_eval (rec_sigma2 f) [x, y1, y2] = (\<Sum> z \<le> x. rec_eval f  [z, y1, y2])"
240
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 (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
   421
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   422
lemma accum1_lemma [simp]: 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   423
  shows "rec_eval (rec_accum1 f) [x, y] = (\<Prod> z \<le> x. rec_eval f  [z, 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
   424
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
   425
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   426
lemma accum2_lemma [simp]: 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   427
  shows "rec_eval (rec_accum2 f) [x, y1, y2] = (\<Prod> z \<le> x. rec_eval f  [z, y1, y2])"
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   428
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
   429
265
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   430
lemma accum3_lemma [simp]: 
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   431
  shows "rec_eval (rec_accum3 f) [x, y1, y2, y3] = (\<Prod> z \<le> x. (rec_eval f)  [z, y1, y2, y3])"
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   432
by (induct x) (simp_all add: rec_accum3_def)
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   433
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   434
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   435
section {* Bounded Quantifiers *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   436
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   437
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   438
  "rec_all1 f = CN rec_sign [rec_accum1 f]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   439
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   440
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   441
  "rec_all2 f = CN rec_sign [rec_accum2 f]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   442
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   443
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   444
  "rec_all3 f = CN rec_sign [rec_accum3 f]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   445
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   446
definition
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   447
  "rec_all1_less f = (let cond1 = CN rec_eq [Id 3 0, Id 3 1] in
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   448
                      let cond2 = CN f [Id 3 0, Id 3 2] 
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   449
                      in CN (rec_all2 (CN rec_disj [cond1, cond2])) [Id 2 0, Id 2 0, Id 2 1])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   450
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   451
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   452
  "rec_all2_less f = (let cond1 = CN rec_eq [Id 4 0, Id 4 1] in 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   453
                      let cond2 = CN f [Id 4 0, Id 4 2, Id 4 3] in 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   454
                      CN (rec_all3 (CN rec_disj [cond1, cond2])) [Id 3 0, Id 3 0, Id 3 1, Id 3 2])"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   455
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   456
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   457
  "rec_ex1 f = CN rec_sign [rec_sigma1 f]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   458
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   459
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   460
  "rec_ex2 f = CN rec_sign [rec_sigma2 f]"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   461
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   462
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   463
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
   464
 "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
   465
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
   466
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   467
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
   468
 "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
   469
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
   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 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
   472
 "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
   473
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
   474
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   475
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
   476
 "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
   477
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
   478
265
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   479
lemma all3_lemma [simp]:
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   480
 "rec_eval (rec_all3 f) [x, y1, y2, y3] = (if (\<forall>z \<le> x. 0 < rec_eval f [z, y1, y2, y3]) then 1 else 0)"
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   481
by (simp add: rec_all3_def)
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   482
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   483
lemma all1_less_lemma [simp]:
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   484
  "rec_eval (rec_all1_less f) [x, y] = (if (\<forall>z < x. 0 < rec_eval f [z, y]) then 1 else 0)"
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   485
apply(auto simp add: Let_def rec_all1_less_def)
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   486
apply (metis nat_less_le)+
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   487
done
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   488
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   489
lemma all2_less_lemma [simp]:
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   490
  "rec_eval (rec_all2_less f) [x, y1, y2] = (if (\<forall>z < x. 0 < rec_eval f [z, y1, y2]) then 1 else 0)"
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   491
apply(auto simp add: Let_def rec_all2_less_def)
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   492
apply(metis nat_less_le)+
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   493
done
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   494
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   495
section {* Quotients *}
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   496
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   497
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   498
  "rec_quo = (let lhs = CN S [Id 3 0] in
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   499
              let rhs = CN rec_mult [Id 3 2, CN S [Id 3 1]] in
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   500
              let cond = CN rec_eq [lhs, rhs] in
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   501
              let if_stmt = CN rec_if [cond, CN S [Id 3 1], Id 3 1]
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   502
              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
   503
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   504
fun Quo where
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   505
  "Quo x 0 = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   506
| "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
   507
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   508
lemma Quo0:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   509
  shows "Quo 0 y = 0"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   510
by (induct y) (auto)
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   511
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   512
lemma Quo1:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   513
  "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
   514
by (induct y) (simp_all)
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 Quo2: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   517
  "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
   518
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
   519
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   520
lemma Quo3:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   521
  "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
   522
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
   523
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   524
lemma Quo4:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   525
  assumes h: "0 < x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   526
  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
   527
proof -
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   528
  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
   529
  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
   530
  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
   531
  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
   532
qed
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   533
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   534
lemma Quo_div: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   535
  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
   536
apply(case_tac "x = 0")
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   537
apply(simp add: Quo0)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   538
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
   539
apply(auto intro: Quo1 Quo4)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   540
done
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   541
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   542
lemma Quo_rec_quo:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   543
  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
   544
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
   545
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   546
lemma quo_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   547
  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
   548
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
   549
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   550
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   551
section {* Iteration *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   552
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   553
definition
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   554
   "rec_iter f = PR (Id 1 0) (CN f [Id 3 1])"
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   555
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   556
fun Iter where
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   557
  "Iter f 0 = id"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   558
| "Iter f (Suc n) = f \<circ> (Iter f n)"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   559
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   560
lemma Iter_comm:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   561
  "(Iter f n) (f x) = f ((Iter f n) x)"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   562
by (induct n) (simp_all)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   563
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   564
lemma iter_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   565
  "rec_eval (rec_iter f) [n, x] =  Iter (\<lambda>x. rec_eval f [x]) n x"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   566
by (induct n) (simp_all add: rec_iter_def)
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   567
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   568
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   569
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
   570
281
00ac265b251b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 269
diff changeset
   571
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   572
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
   573
  "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
   574
| "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
   575
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   576
definition 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   577
  BMax_set :: "(nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   578
where 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   579
  "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
   580
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   581
lemma BMax_rec_eq1:
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   582
 "BMax_rec R x = (GREATEST z. (R z \<and> z \<le> x) \<or> z = 0)"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   583
apply(induct x)
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   584
apply(auto intro: Greatest_equality Greatest_equality[symmetric])
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   585
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
   586
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   587
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   588
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
   589
  "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
   590
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   591
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
   592
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
   593
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   594
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   595
lemma BMax_rec_eq3:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   596
  "BMax_rec R x = Max (Set.filter (\<lambda>z. R z) {..x} \<union> {0})"
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   597
by (simp add: BMax_rec_eq2 Set.filter_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   598
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   599
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   600
  "rec_max1 f = PR Z (CN rec_ifz [CN f [CN S [Id 3 0], Id 3 2], CN S [Id 3 0], Id 3 1])"
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   601
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   602
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
   603
  "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
   604
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
   605
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   606
definition 
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   607
  "rec_max2 f = PR Z (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
   608
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   609
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
   610
  "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
   611
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
   612
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   613
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   614
section {* Encodings using Cantor's pairing function *}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   615
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   616
text {*
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   617
  We use Cantor's pairing function from Nat_Bijection.
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   618
  However, we need to prove that the formulation of the
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   619
  decoding function there is recursive. For this we first 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   620
  prove that we can extract the maximal triangle number 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   621
  using @{term prod_decode}.
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   622
*}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   623
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   624
abbreviation Max_triangle_aux where
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   625
  "Max_triangle_aux k z \<equiv> fst (prod_decode_aux k z) + snd (prod_decode_aux k z)"
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   626
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   627
abbreviation Max_triangle where
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   628
  "Max_triangle z \<equiv> Max_triangle_aux 0 z"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   629
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   630
abbreviation
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   631
  "pdec1 z \<equiv> fst (prod_decode z)"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   632
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   633
abbreviation
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   634
  "pdec2 z \<equiv> snd (prod_decode z)"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   635
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   636
abbreviation 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   637
  "penc m n \<equiv> prod_encode (m, n)"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   638
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   639
lemma fst_prod_decode: 
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   640
  "pdec1 z = z - triangle (Max_triangle z)"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   641
by (subst (3) prod_decode_inverse[symmetric]) 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   642
   (simp add: prod_encode_def prod_decode_def split: prod.split)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   643
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   644
lemma snd_prod_decode: 
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   645
  "pdec2 z = Max_triangle z - pdec1 z"
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   646
by (simp only: prod_decode_def)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   647
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   648
lemma le_triangle:
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   649
  "m \<le> triangle (n + m)"
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   650
by (induct_tac m) (simp_all)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   651
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   652
lemma Max_triangle_triangle_le:
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   653
  "triangle (Max_triangle z) \<le> z"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   654
by (subst (9) prod_decode_inverse[symmetric])
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   655
   (simp add: prod_decode_def prod_encode_def split: prod.split)
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   656
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   657
lemma Max_triangle_le: 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   658
  "Max_triangle z \<le> z"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   659
proof -
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   660
  have "Max_triangle z \<le> triangle (Max_triangle z)"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   661
    using le_triangle[of _ 0, simplified] by simp
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   662
  also have "... \<le> z" by (rule Max_triangle_triangle_le)
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   663
  finally show "Max_triangle z \<le> z" .
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   664
qed
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   665
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   666
lemma w_aux: 
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   667
  "Max_triangle (triangle k + m) = Max_triangle_aux k m"
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   668
by (simp add: prod_decode_def[symmetric] prod_decode_triangle_add)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   669
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   670
lemma y_aux: "y \<le> Max_triangle_aux y k"
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   671
apply(induct k arbitrary: y rule: nat_less_induct)
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   672
apply(subst (1 2) prod_decode_aux.simps)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   673
apply(simp)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   674
apply(rule impI)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   675
apply(drule_tac x="n - Suc y" in spec)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   676
apply(drule mp)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   677
apply(auto)[1]
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   678
apply(drule_tac x="Suc y" in spec)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   679
apply(erule Suc_leD)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   680
done
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   681
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   682
lemma Max_triangle_greatest: 
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   683
  "Max_triangle z = (GREATEST k. (triangle k \<le> z \<and> k \<le> z) \<or> k = 0)"
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   684
apply(rule Greatest_equality[symmetric])
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   685
apply(rule disjI1)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   686
apply(rule conjI)
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   687
apply(rule Max_triangle_triangle_le)
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   688
apply(rule Max_triangle_le)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   689
apply(erule disjE)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   690
apply(erule conjE)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   691
apply(subst (asm) (1) le_iff_add)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   692
apply(erule exE)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   693
apply(clarify)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   694
apply(simp only: w_aux)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   695
apply(rule y_aux)
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   696
apply(simp)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   697
done
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   698
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   699
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   700
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   701
  "rec_triangle = CN rec_quo [CN rec_mult [Id 1 0, S], constn 2]"
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   702
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   703
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   704
  "rec_max_triangle = 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   705
       (let cond = CN rec_not [CN rec_le [CN rec_triangle [Id 2 0], Id 2 1]] in
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   706
        CN (rec_max1 cond) [Id 1 0, Id 1 0])"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   707
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   708
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   709
lemma triangle_lemma [simp]:
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   710
  "rec_eval rec_triangle [x] = triangle x"
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   711
by (simp add: rec_triangle_def triangle_def)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   712
 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   713
lemma max_triangle_lemma [simp]:
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   714
  "rec_eval rec_max_triangle [x] = Max_triangle x"
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   715
by (simp add: Max_triangle_greatest rec_max_triangle_def Let_def BMax_rec_eq1) 
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   716
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   717
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   718
text {* Encodings for Products *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   719
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   720
definition
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   721
  "rec_penc = CN rec_add [CN rec_triangle [CN rec_add [Id 2 0, Id 2 1]], Id 2 0]"
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   722
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   723
definition 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   724
  "rec_pdec1 = CN rec_minus [Id 1 0, CN rec_triangle [CN rec_max_triangle [Id 1 0]]]" 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   725
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   726
definition 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   727
  "rec_pdec2 = CN rec_minus [CN rec_max_triangle [Id 1 0], CN rec_pdec1 [Id 1 0]]" 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   728
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   729
lemma pdec1_lemma [simp]:
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   730
  "rec_eval rec_pdec1 [z] = pdec1 z"
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   731
by (simp add: rec_pdec1_def fst_prod_decode)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   732
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   733
lemma pdec2_lemma [simp]:
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   734
  "rec_eval rec_pdec2 [z] = pdec2 z"
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   735
by (simp add: rec_pdec2_def snd_prod_decode)
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   736
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   737
lemma penc_lemma [simp]:
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   738
  "rec_eval rec_penc [m, n] = penc m n"
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   739
by (simp add: rec_penc_def prod_encode_def)
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   740
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   741
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   742
text {* Encodings of Lists *}
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   743
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   744
fun 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   745
  lenc :: "nat list \<Rightarrow> nat" 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   746
where
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   747
  "lenc [] = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   748
| "lenc (x # xs) = penc (Suc x) (lenc xs)"
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   749
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   750
fun
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   751
  ldec :: "nat \<Rightarrow> nat \<Rightarrow> nat"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   752
where
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   753
  "ldec z 0 = (pdec1 z) - 1"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   754
| "ldec z (Suc n) = ldec (pdec2 z) n"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   755
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   756
lemma pdec_zero_simps [simp]:
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   757
  "pdec1 0 = 0" 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   758
  "pdec2 0 = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   759
by (simp_all add: prod_decode_def prod_decode_aux.simps)
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   760
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   761
lemma ldec_zero:
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   762
  "ldec 0 n = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   763
by (induct n) (simp_all add: prod_decode_def prod_decode_aux.simps)
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   764
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   765
lemma list_encode_inverse: 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   766
  "ldec (lenc xs) n = (if n < length xs then xs ! n else 0)"
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   767
by (induct xs arbitrary: n rule: lenc.induct) 
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   768
   (auto simp add: ldec_zero nth_Cons split: nat.splits)
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   769
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   770
lemma lenc_length_le:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   771
  "length xs \<le> lenc xs"  
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   772
by (induct xs) (simp_all add: prod_encode_def)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   773
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   774
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   775
text {* Membership for the List Encoding *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   776
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   777
fun inside :: "nat \<Rightarrow> nat \<Rightarrow> bool" where
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   778
  "inside z 0 = (0 < z)"
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   779
| "inside z (Suc n) = inside (pdec2 z) n"
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   780
    
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   781
definition enclen :: "nat \<Rightarrow> nat" where
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   782
  "enclen z = BMax_rec (\<lambda>x. inside z (x - 1)) z"
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   783
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   784
lemma inside_False [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   785
  "inside 0 n = False"
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   786
by (induct n) (simp_all)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   787
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   788
lemma inside_length [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   789
  "inside (lenc xs) s = (s < length xs)"
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   790
apply(induct s arbitrary: xs)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   791
apply(case_tac xs)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   792
apply(simp_all add: prod_encode_def)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   793
apply(case_tac xs)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   794
apply(simp_all)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   795
done
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   796
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   797
text {* Length of Encoded Lists *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   798
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   799
lemma enclen_length [simp]:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   800
  "enclen (lenc xs) = length xs"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   801
unfolding enclen_def
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   802
apply(simp add: BMax_rec_eq1)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   803
apply(rule Greatest_equality)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   804
apply(auto simp add: lenc_length_le)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   805
done
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   806
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   807
lemma enclen_penc [simp]:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   808
  "enclen (penc (Suc x) (lenc xs)) = Suc (enclen (lenc xs))"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   809
by (simp only: lenc.simps[symmetric] enclen_length) (simp)
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   810
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   811
lemma enclen_zero [simp]:
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   812
  "enclen 0 = 0"
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   813
by (simp add: enclen_def)
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   814
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   815
269
fa40fd8abb54 implemented new UF in scala; made some small adjustments to the definitions in the theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 266
diff changeset
   816
text {* Recursive Definitions for List Encodings *}
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   817
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   818
fun 
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   819
  rec_lenc :: "recf list \<Rightarrow> recf" 
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   820
where
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   821
  "rec_lenc [] = Z"
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   822
| "rec_lenc (f # fs) = CN rec_penc [CN S [f], rec_lenc fs]"
260
1e45b5b6482a added definitions and proofs for right-std and left-std tapes
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 259
diff changeset
   823
262
5704925ad138 started with the definitions of the recursive functions for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   824
definition 
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
   825
  "rec_ldec = CN rec_predi [CN rec_pdec1 [rec_swap (rec_iter rec_pdec2)]]"
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   826
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   827
definition 
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   828
  "rec_inside = CN rec_less [Z, rec_swap (rec_iter rec_pdec2)]"
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   829
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   830
definition
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   831
  "rec_enclen = CN (rec_max1 (CN rec_not [CN rec_inside [Id 2 1, CN rec_predi [Id 2 0]]])) [Id 1 0, Id 1 0]"
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   832
262
5704925ad138 started with the definitions of the recursive functions for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   833
lemma ldec_iter:
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   834
  "ldec z n = pdec1 (Iter pdec2 n z) - 1"
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   835
by (induct n arbitrary: z) (simp | subst Iter_comm)+
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   836
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   837
lemma inside_iter:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   838
  "inside z n = (0 < Iter pdec2 n z)"
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   839
by (induct n arbitrary: z) (simp | subst Iter_comm)+
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   840
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   841
lemma lenc_lemma [simp]:
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   842
  "rec_eval (rec_lenc fs) xs = lenc (map (\<lambda>f. rec_eval f xs) fs)"
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   843
by (induct fs) (simp_all)
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   844
262
5704925ad138 started with the definitions of the recursive functions for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   845
lemma ldec_lemma [simp]:
5704925ad138 started with the definitions of the recursive functions for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   846
  "rec_eval rec_ldec [z, n] = ldec z n"
5704925ad138 started with the definitions of the recursive functions for the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 260
diff changeset
   847
by (simp add: ldec_iter rec_ldec_def)
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   848
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   849
lemma inside_lemma [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   850
  "rec_eval rec_inside [z, n] = (if inside z n then 1 else 0)"
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   851
by (simp add: inside_iter rec_inside_def)
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   852
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   853
lemma enclen_lemma [simp]:
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   854
  "rec_eval rec_enclen [z] = enclen z"
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   855
by (simp add: rec_enclen_def enclen_def)
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   856
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   857
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   858
end
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   859