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