thys2/Recs.thy
author Christian Urban <christian.urban@kcl.ac.uk>
Thu, 22 Feb 2024 14:06:37 +0000
changeset 299 a2707a5652d9
parent 297 bee184c83071
permissions -rwxr-xr-x
test
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
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
     8
text{*
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
     9
  A more streamlined and cleaned-up version of Recursive 
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    10
  Functions following 
244
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
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    13
    I. M. Chiswell 
244
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
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    17
    Lecture on Undecidability
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    18
    Michael M. Wolf 
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    19
*}
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    20
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    21
declare One_nat_def[simp del]
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
    22
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
    23
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    24
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
    25
  "(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
    26
  "(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
    27
  "(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
    28
by (simp_all)
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    29
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    30
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
    31
  "(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
    32
  "(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
    33
  "(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
    34
  "(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
    35
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
    36
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    37
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    38
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
    39
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    40
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
    41
  "(\<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
    42
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
    43
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
    44
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
    45
  "(\<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
    46
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
    47
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    48
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
    49
  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
    50
  apply(subst sum.union_disjoint[symmetric])
293
8b55240e12c6 upodated to Isabelle 2016
Christian Urban <urbanc@in.tum.de>
parents: 281
diff changeset
    51
  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
    52
done
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    53
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    54
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
    55
  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
    56
  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
    57
        "(\<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
    58
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
    59
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    60
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
    61
  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
    62
  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
    63
        "(\<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
    64
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
    65
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    66
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
    67
  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
    68
  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
    69
  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
    70
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
    71
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
    72
241
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    73
lemma setsum_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    74
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    75
  assumes "\<forall>i \<le> n. f i \<le> 1" 
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    76
  shows "(\<Sum>i \<le> n. f i) \<le> Suc n"  
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    77
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    78
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    79
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    80
lemma setsum_eq_one_le:
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    81
  fixes n::nat
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    82
  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
    83
  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
    84
using assms
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    85
by (induct n) (auto)
e59e549e6ab6 uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 240
diff changeset
    86
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    87
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
    88
  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
    89
  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
    90
  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
    91
  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
    92
  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
    93
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
    94
  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
    95
    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
    96
  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
    97
    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
    98
  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
    99
    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
   100
  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
   101
  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
   102
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   103
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   104
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
   105
  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
   106
  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
   107
  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
   108
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
   109
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
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
   111
  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
   112
  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
   113
  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
   114
using assms 
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   115
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
   116
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   117
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
   118
  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
   119
  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
   120
  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
   121
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
   122
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   123
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
   124
  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
   125
  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
   126
  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
   127
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
   128
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   129
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
   130
  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
   131
  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
   132
  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
   133
  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
   134
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   135
  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
   136
    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
   137
  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
   138
    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
   139
  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
   140
  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
   141
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   142
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   143
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
   144
  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
   145
  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
   146
  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
   147
  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
   148
proof -
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   149
  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
   150
    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
   151
  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
   152
    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
   153
  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
   154
  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
   155
qed
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   156
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   157
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
   158
  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
   159
  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
   160
        "(\<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
   161
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
   162
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   163
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   164
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   165
section {* Recursive Functions *}
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   166
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   167
datatype recf =  Z
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   168
              |  S
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   169
              |  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
   170
              |  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
   171
              |  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
   172
              |  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
   173
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   174
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
   175
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   176
  "arity Z = 1" 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   177
| "arity S = 1"
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   178
| "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
   179
| "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
   180
| "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
   181
| "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
   182
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   183
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
   184
240
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
  "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
   187
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   188
abbreviation
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   189
  "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
   190
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   191
abbreviation
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   192
  "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
   193
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   194
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
   195
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   196
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
   197
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   198
  "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
   199
| "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
   200
| "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
   201
| "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
   202
| "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
   203
| "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
   204
     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
   205
| "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
   206
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   207
inductive 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   208
  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
   209
where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   210
  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
   211
| 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
   212
| 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
   213
| 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
   214
              \<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
   215
| 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
   216
              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
   217
              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
   218
              \<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
   219
| 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
   220
              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
   221
              \<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
   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
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   224
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
   225
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   226
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   227
  @{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
   228
  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
   229
*}
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   230
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
   231
  where
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   232
  "constn 0 = Z"  |
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   233
  "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
   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_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
   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_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
   240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   241
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   242
  "rec_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
   243
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   244
definition 
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   245
  "rec_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
   246
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
   247
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
   248
  "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
   249
240
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
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
   251
  "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
   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 
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   254
  "rec_predecessor = 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
   255
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   256
definition 
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   257
  "rec_minus = rec_swap (PR (Id 1 0) (CN rec_predecessor [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
   258
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   259
lemma constn_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   260
  "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
   261
by (induct n) (simp_all)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   262
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   263
lemma swap_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   264
  "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
   265
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
   266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   267
lemma add_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   268
  "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
   269
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
   270
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   271
lemma mult_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   272
  "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
   273
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
   274
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   275
lemma power_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   276
  "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
   277
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
   278
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
   279
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
   280
  "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
   281
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
   282
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   283
lemma fact_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   284
  "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
   285
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
   286
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   287
lemma pred_lemma [simp]: 
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   288
  "rec_eval rec_predecessor [x] =  x - 1"
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   289
by (induct x) (simp_all add: rec_predecessor_def)
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   290
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   291
lemma minus_lemma [simp]: 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   292
  "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
   293
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
   294
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   295
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   296
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
   297
249
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   298
text {* 
6e7244ae43b8 polised a bit of the Recs-theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 247
diff changeset
   299
  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
   300
  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
   301
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   302
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   303
  "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
   304
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   305
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   306
  "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
   307
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   308
text {*
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   309
  @{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
   310
  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
   311
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
   312
  "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
   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_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
   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_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
   319
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   320
definition 
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   321
  "rec_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
   322
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   323
definition 
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   324
  "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
   325
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   326
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
   327
  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
   328
  zero, y otherwise *}
247
89ed51d72e4a eliminated explicit swap_lemmas
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 246
diff changeset
   329
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   330
definition 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   331
  "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
   332
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   333
definition 
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   334
  "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
   335
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   336
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   337
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
   338
  "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
   339
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
   340
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   341
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
   342
  "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
   343
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
   344
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   345
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
   346
  "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
   347
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
   348
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   349
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
   350
  "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
   351
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
   352
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   353
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
   354
  "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
   355
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
   356
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   357
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
   358
  "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
   359
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
   360
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   361
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
   362
  "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
   363
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
   364
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   365
lemma ifz_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   366
  "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
   367
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
   368
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   369
lemma if_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   370
  "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
   371
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
   372
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   373
section {* Less and Le Relations *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   374
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   375
text {*
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   376
  @{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
   377
  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
   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_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
   381
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   382
definition 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   383
  "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
   384
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   385
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
   386
  "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
   387
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
   388
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   389
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
   390
  "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
   391
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
   392
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   393
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   394
section {* Summation and Product Functions *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   395
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   396
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
   397
  "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
   398
                     (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
   399
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   400
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
   401
  "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
   402
                     (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
   403
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   404
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
   405
  "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
   406
                     (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
   407
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   408
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
   409
  "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
   410
                     (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
   411
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   412
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
   413
  "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
   414
                     (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
   415
245
af60d84e0677 introduced rec_if
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 244
diff changeset
   416
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   417
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
   418
  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
   419
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
   420
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   421
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
   422
  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
   423
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
   424
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   425
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
   426
  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
   427
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
   428
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   429
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
   430
  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
   431
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
   432
265
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   433
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
   434
  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
   435
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
   436
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   437
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   438
section {* Bounded Quantifiers *}
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_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
   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_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
   445
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   446
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   447
  "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
   448
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   449
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
   450
  "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
   451
                      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
   452
                      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
   453
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   454
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   455
  "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
   456
                      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
   457
                      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
   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_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
   461
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   462
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   463
  "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
   464
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   465
240
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   466
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
   467
 "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
   468
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
   469
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   470
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
   471
 "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
   472
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
   473
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   474
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
   475
 "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
   476
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
   477
696081f445c2 added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff changeset
   478
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
   479
 "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
   480
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
   481
265
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   482
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
   483
 "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
   484
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
   485
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   486
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
   487
  "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
   488
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
   489
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
   490
done
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   491
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   492
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
   493
  "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
   494
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
   495
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
   496
done
fa3c214559b0 finished recusive version of the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 263
diff changeset
   497
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   498
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
   499
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   500
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   501
  "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
   502
              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
   503
              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
   504
              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
   505
              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
   506
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   507
fun Quo where
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   508
  "Quo x 0 = 0"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   509
| "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
   510
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   511
lemma Quo0:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   512
  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
   513
by (induct y) (auto)
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   514
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   515
lemma Quo1:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   516
  "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
   517
by (induct y) (simp_all)
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   518
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   519
lemma Quo2: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   520
  "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
   521
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
   522
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   523
lemma Quo3:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   524
  "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
   525
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
   526
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   527
lemma Quo4:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   528
  assumes h: "0 < x"
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   529
  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
   530
proof -
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   531
  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
   532
  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
   533
  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
   534
  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
   535
qed
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   536
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   537
lemma Quo_div: 
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   538
  shows "Quo x y = y div x"
296
3fee65a40838 updated to Isabelle 2018
Christian Urban <urbanc@in.tum.de>
parents: 295
diff changeset
   539
by (metis Quo0 Quo1 Quo4 div_by_0 div_nat_eqI mult_Suc_right neq0_conv)
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   540
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   541
lemma Quo_rec_quo:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   542
  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
   543
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
   544
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   545
lemma quo_lemma [simp]:
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   546
  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
   547
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
   548
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   549
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   550
section {* Iteration *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   551
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   552
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
   553
   "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
   554
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   555
fun Iter where
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   556
  "Iter f 0 = id"
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   557
| "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
   558
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   559
lemma Iter_comm:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   560
  "(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
   561
by (induct n) (simp_all)
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   562
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   563
lemma iter_lemma [simp]:
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   564
  "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
   565
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
   566
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   567
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   568
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
   569
281
00ac265b251b updated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 269
diff changeset
   570
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   571
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
   572
  "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
   573
| "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
   574
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   575
definition 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   576
  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
   577
where 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   578
  "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
   579
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   580
lemma BMax_rec_eq1:
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   581
 "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
   582
apply(induct x)
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   583
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
   584
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
   585
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   586
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   587
lemma 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
   588
  "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
   589
apply(induct x)
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   590
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
   591
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
   592
by metis
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   593
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   594
lemma BMax_rec_eq3:
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   595
  "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
   596
by (simp add: BMax_rec_eq2 Set.filter_def)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   597
243
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   598
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
   599
  "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
   600
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   601
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
   602
  "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
   603
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
   604
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   605
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
   606
  "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
   607
 
ac32cc069e30 added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 241
diff changeset
   608
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
   609
  "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
   610
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
   611
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   612
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   613
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
   614
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   615
text {*
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   616
  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
   617
  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
   618
  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
   619
  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
   620
  using @{term prod_decode}.
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   621
*}
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   622
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   623
abbreviation Max_triangle_aux where
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   624
  "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
   625
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   626
abbreviation Max_triangle where
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   627
  "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
   628
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   629
abbreviation
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   630
  "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
   631
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   632
abbreviation
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   633
  "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
   634
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   635
abbreviation 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   636
  "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
   637
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   638
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
   639
  "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
   640
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
   641
   (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
   642
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   643
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
   644
  "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
   645
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
   646
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   647
lemma le_triangle:
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   648
  "m \<le> triangle (n + m)"
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   649
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
   650
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   651
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
   652
  "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
   653
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
   654
   (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
   655
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   656
lemma Max_triangle_le: 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   657
  "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
   658
proof -
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   659
  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
   660
    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
   661
  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
   662
  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
   663
qed
254
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 251
diff changeset
   664
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   665
lemma w_aux: 
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   666
  "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
   667
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
   668
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   669
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
   670
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
   671
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
   672
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
   673
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
   674
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
   675
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
   676
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
   677
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
   678
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
   679
done
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   680
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   681
lemma Max_triangle_greatest: 
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   682
  "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
   683
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
   684
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
   685
apply(rule conjI)
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   686
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
   687
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
   688
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
   689
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
   690
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
   691
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
   692
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
   693
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
   694
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
   695
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
   696
done
250
745547bdc1c7 added lemmas about a pairing function
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 249
diff changeset
   697
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   698
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   699
definition 
256
04700724250f completed coding functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 255
diff changeset
   700
  "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
   701
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   702
definition
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   703
  "rec_max_triangle = 
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   704
       (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
   705
        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
   706
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   707
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   708
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
   709
  "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
   710
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
   711
 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   712
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
   713
  "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
   714
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
   715
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   716
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   717
text {* Encodings for Products *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   718
255
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   719
definition
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   720
  "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
   721
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   722
definition 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   723
  "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
   724
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   725
definition 
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   726
  "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
   727
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   728
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
   729
  "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
   730
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
   731
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   732
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
   733
  "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
   734
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
   735
4bf4d425e65d added recusive functions that decode triangle numbers
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 254
diff changeset
   736
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
   737
  "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
   738
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
   739
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   740
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   741
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
   742
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   743
fun 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   744
  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
   745
where
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   746
  "lenc [] = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   747
| "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
   748
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   749
fun
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   750
  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
   751
where
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   752
  "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
   753
| "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
   754
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   755
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
   756
  "pdec1 0 = 0" 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   757
  "pdec2 0 = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   758
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
   759
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   760
lemma ldec_zero:
257
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   761
  "ldec 0 n = 0"
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   762
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
   763
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   764
lemma list_encode_inverse: 
df6e8cb22995 more about the UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 256
diff changeset
   765
  "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
   766
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
   767
   (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
   768
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   769
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
   770
  "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
   771
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
   772
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   773
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   774
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
   775
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   776
fun inside :: "nat \<Rightarrow> nat \<Rightarrow> bool" where
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   777
  "inside z 0 = (0 < z)"
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   778
| "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
   779
    
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   780
definition enclen :: "nat \<Rightarrow> nat" where
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   781
  "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
   782
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   783
lemma inside_False [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   784
  "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
   785
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
   786
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   787
lemma inside_length [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   788
  "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
   789
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
   790
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
   791
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
   792
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
   793
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
   794
done
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   795
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   796
text {* Length of Encoded Lists *}
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   797
259
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   798
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
   799
  "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
   800
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
   801
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
   802
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
   803
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
   804
done
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   805
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   806
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
   807
  "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
   808
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
   809
4524c5edcafb moved new theries into a separate directory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 257
diff changeset
   810
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
   811
  "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
   812
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
   813
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   814
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
   815
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
   816
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   817
fun 
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   818
  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
   819
where
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   820
  "rec_lenc [] = Z"
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   821
| "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
   822
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
   823
definition 
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   824
  "rec_ldec = CN rec_predecessor [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
   825
263
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   826
definition 
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   827
  "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
   828
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   829
definition
297
bee184c83071 added some text at the beginning
Christian Urban <urbanc@in.tum.de>
parents: 296
diff changeset
   830
  "rec_enclen = CN (rec_max1 (CN rec_not [CN rec_inside [Id 2 1, CN rec_predecessor [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
   831
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
   832
lemma ldec_iter:
266
b1b47d28c295 polished Recs theory
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 265
diff changeset
   833
  "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
   834
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
   835
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   836
lemma inside_iter:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   837
  "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
   838
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
   839
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   840
lemma lenc_lemma [simp]:
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   841
  "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
   842
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
   843
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
   844
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
   845
  "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
   846
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
   847
295
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   848
lemma inside_lemma [simp]:
fa6f654cbc13 updated to Isabelle 2017
Christian Urban <urbanc@in.tum.de>
parents: 294
diff changeset
   849
  "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
   850
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
   851
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   852
lemma enclen_lemma [simp]:
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   853
  "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
   854
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
   855
aa102c182132 more rec-funs definitions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 262
diff changeset
   856
244
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   857
end
8dba6ae39bf0 started with UF
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents: 243
diff changeset
   858