author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Tue, 30 Apr 2013 12:53:11 +0100 | |
changeset 243 | ac32cc069e30 |
parent 241 | e59e549e6ab6 |
child 244 | 8dba6ae39bf0 |
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
2 |
imports Main Fact "~~/src/HOL/Number_Theory/Primes" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
3 |
begin |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
4 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
5 |
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
|
6 |
"(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
|
7 |
"(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
|
8 |
"(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
|
9 |
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
|
10 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
11 |
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
|
12 |
"(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
|
13 |
"(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
|
14 |
"(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
|
15 |
"(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
|
16 |
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
|
17 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
18 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
19 |
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
|
20 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
21 |
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
|
22 |
"(\<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
|
23 |
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
|
24 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
25 |
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
|
26 |
"(\<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
|
27 |
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
|
28 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
34 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
35 |
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
|
36 |
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
|
37 |
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
|
38 |
"(\<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
|
39 |
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
|
40 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
41 |
lemma 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
|
42 |
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
|
43 |
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
|
44 |
"(\<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
|
45 |
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
|
46 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
47 |
lemma setsum_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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
|
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
54 |
lemma setsum_one_le: |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
55 |
fixes n::nat |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
56 |
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
|
57 |
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
|
58 |
using assms |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
59 |
by (induct n) (auto) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
60 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
61 |
lemma setsum_eq_one_le: |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
62 |
fixes n::nat |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
63 |
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
|
64 |
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
|
65 |
using assms |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
66 |
by (induct n) (auto) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
67 |
|
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
68 |
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
|
69 |
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
|
70 |
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
|
71 |
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
|
72 |
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
|
73 |
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
|
74 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
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
|
76 |
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
|
77 |
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
|
78 |
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
|
79 |
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
|
80 |
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
|
81 |
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
|
82 |
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
|
83 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
85 |
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
|
86 |
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
|
87 |
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
|
88 |
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
|
89 |
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
|
90 |
|
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
shows "(\<Prod>i \<le> n. f i) \<le> 1" |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
95 |
using assms by (induct n) (auto intro: nat_mult_le_one) |
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
97 |
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
|
98 |
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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
lemma setprod_eq_one: |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
104 |
fixes f::"nat \<Rightarrow> nat" |
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
109 |
lemma 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
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
115 |
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
|
116 |
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
|
117 |
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
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
122 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
123 |
lemma 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
|
124 |
fixes f::"nat \<Rightarrow> nat" |
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
assumes 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
|
126 |
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
|
127 |
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
|
128 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
129 |
have 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
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
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
|
134 |
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
|
135 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
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
|
138 |
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
|
139 |
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
|
140 |
"(\<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
|
141 |
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
|
142 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
143 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
144 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
145 |
section {* Recursive Functions *} |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
146 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
147 |
datatype recf = Z |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
148 |
| S |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
149 |
| 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
|
150 |
| 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
|
151 |
| 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
|
152 |
| 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
|
153 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
154 |
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
|
155 |
where |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
156 |
"arity Z = 1" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
157 |
| "arity S = 1" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
158 |
| "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
|
159 |
| "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
|
160 |
| "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
|
161 |
| "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
|
162 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
abbreviation |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
"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
|
165 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
166 |
abbreviation |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
167 |
"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
|
168 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
169 |
fun 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
|
170 |
where |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
171 |
"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
|
172 |
| "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
|
173 |
| "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
|
174 |
| "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
|
175 |
| "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
|
176 |
| "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
|
177 |
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
|
178 |
| "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
|
179 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
180 |
inductive |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
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
|
182 |
where |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
183 |
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
|
184 |
| 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
|
185 |
| 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
|
186 |
| 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
|
187 |
\<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
|
188 |
| 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
|
189 |
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
|
190 |
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
|
191 |
\<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
|
192 |
| 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
|
193 |
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
|
194 |
\<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
|
195 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
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
|
198 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
200 |
@{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
|
201 |
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
|
202 |
*} |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
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
|
204 |
where |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
205 |
"constn 0 = Z" | |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
206 |
"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
|
207 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
209 |
"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
|
210 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
212 |
"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
|
213 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
214 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
215 |
"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
|
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 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
218 |
"rec_power_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
|
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 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
"rec_power = rec_swap rec_power_swap" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
222 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
223 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
224 |
"rec_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
|
225 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
227 |
"rec_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
|
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_minus_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
|
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
233 |
"rec_minus = rec_swap rec_minus_swap" |
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 |
text {* Sign function returning 1 when the input argument is greater than @{text "0"}. *} |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
236 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
237 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
238 |
"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
|
239 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
240 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
241 |
"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
|
242 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
243 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
@{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
|
245 |
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
|
246 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
247 |
"rec_eq = CN rec_minus |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
248 |
[CN (constn 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
|
249 |
CN rec_add [rec_minus, 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
|
250 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
251 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
252 |
"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
|
253 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
254 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
255 |
"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
|
256 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
257 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
258 |
"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
|
259 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
260 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
261 |
"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
|
262 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
263 |
text {* @{term "rec_ifz [z, x, y]"} returns x if z is zero, |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
264 |
y otherwise *} |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
265 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
266 |
"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
|
267 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
268 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
@{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
|
270 |
the first is less than the second; otherwise returns @{text "0"}. *} |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
271 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
272 |
"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
|
273 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
274 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
275 |
"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
|
276 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
277 |
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
|
278 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
279 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
280 |
"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
|
281 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
282 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
283 |
"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
|
284 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
285 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
286 |
"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
|
287 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
288 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
289 |
"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
|
290 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
291 |
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
|
292 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
293 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
294 |
"rec_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
|
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_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
|
298 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
299 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
300 |
"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
|
301 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
302 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
"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
|
304 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
305 |
text {* Dvd *} |
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_dvd_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
|
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
"rec_dvd = rec_swap rec_dvd_swap" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
312 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
313 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
314 |
|
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
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
|
316 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
317 |
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
|
318 |
"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
|
319 |
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
|
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 |
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
|
322 |
"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
|
323 |
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
|
324 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
325 |
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
|
326 |
"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
|
327 |
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
|
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 |
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
|
330 |
"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
|
331 |
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
|
332 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
333 |
lemma power_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
|
334 |
"rec_eval rec_power_swap [y, x] = 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
|
335 |
by (induct y) (simp_all add: rec_power_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
|
336 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
337 |
lemma 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
|
338 |
"rec_eval rec_power [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
|
339 |
by (simp add: rec_power_def) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
340 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
341 |
lemma 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
|
342 |
"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
|
343 |
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
|
344 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
345 |
lemma 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
|
346 |
"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
|
347 |
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
|
348 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
349 |
lemma minus_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
|
350 |
"rec_eval rec_minus_swap [x, y] = 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
|
351 |
by (induct x) (simp_all add: rec_minus_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
|
352 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
353 |
lemma 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
|
354 |
"rec_eval rec_minus [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
|
355 |
by (simp add: rec_minus_def) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
356 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
357 |
lemma 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
|
358 |
"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
|
359 |
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
|
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 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
|
362 |
"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
|
363 |
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
|
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 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
|
366 |
"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
|
367 |
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
|
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 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
|
370 |
"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
|
371 |
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
|
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 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
|
374 |
"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
|
375 |
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
|
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 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
|
378 |
"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
|
379 |
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
|
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 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
|
382 |
"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
|
383 |
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
|
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 less_lemma [simp]: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
386 |
"rec_eval rec_less [x, y] = (if x < y then 1 else 0)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
387 |
by (simp add: rec_less_def) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
388 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
389 |
lemma le_lemma [simp]: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
390 |
"rec_eval rec_le [x, y] = (if (x \<le> y) then 1 else 0)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
391 |
by(simp add: rec_le_def) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
392 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
393 |
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
|
394 |
"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
|
395 |
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
|
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 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
|
398 |
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
|
399 |
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
|
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 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
|
402 |
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
|
403 |
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
|
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 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
|
406 |
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
|
407 |
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
|
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 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
|
410 |
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
|
411 |
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
|
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 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
|
414 |
"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
|
415 |
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
|
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 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
|
418 |
"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
|
419 |
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
|
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 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
|
422 |
"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
|
423 |
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
|
424 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
425 |
lemma 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
|
426 |
"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
|
427 |
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
|
428 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
429 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
430 |
lemma 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
|
431 |
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
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
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
|
436 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
437 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
438 |
lemma dvd_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
|
439 |
"rec_eval rec_dvd_swap [x, y] = (if y dvd x 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
|
440 |
unfolding dvd_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
|
441 |
by (auto simp add: rec_dvd_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
|
442 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
443 |
lemma 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
|
444 |
"rec_eval rec_dvd [x, y] = (if x dvd y then 1 else 0)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
445 |
by (simp add: rec_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
|
446 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
447 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
448 |
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
|
449 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
450 |
lemma 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
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
456 |
done |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
457 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
458 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
459 |
"rec_prime = |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
460 |
(let conj1 = CN rec_less [constn 1, Id 1 0] in |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
461 |
let disj = CN rec_disj [CN rec_eq [Id 2 0, constn 1], rec_eq] in |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
462 |
let imp = CN rec_imp [rec_dvd, disj] in |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
463 |
let conj2 = CN (rec_all1 imp) [Id 1 0, Id 1 0] in |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
464 |
CN rec_conj [conj1, conj2])" |
240
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 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
|
467 |
"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
|
468 |
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
|
469 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
470 |
section {* Bounded Min and Maximisation *} |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
471 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
472 |
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
|
473 |
"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
|
474 |
| "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
|
475 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
476 |
definition BMax_set :: "(nat \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
477 |
where "BMax_set R x = Max ({z | z. z \<le> x \<and> R z} \<union> {0})" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
478 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
479 |
definition (in ord) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
480 |
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
|
481 |
"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
|
482 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
483 |
lemma Great_equality: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
484 |
fixes x::nat |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
485 |
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
|
486 |
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
|
487 |
unfolding Great_def |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
488 |
using assms |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
489 |
by(rule_tac the_equality) (auto intro: le_antisym) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
490 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
491 |
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
|
492 |
"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
|
493 |
apply(induct x) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
494 |
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
|
495 |
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
|
496 |
by metis |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
497 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
498 |
lemma BMax_rec_eq2: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
499 |
"BMax_rec R x = Max ({z | z. z \<le> x \<and> R z} \<union> {0})" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
500 |
apply(induct x) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
501 |
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
|
502 |
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
|
503 |
by metis |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
504 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
505 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
506 |
"rec_max1 f = PR (constn 0) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
507 |
(CN rec_ifz [CN f [CN S [Id 3 0], Id 3 2], CN S [Id 4 0], Id 4 1])" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
508 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
509 |
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
|
510 |
"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
|
511 |
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
|
512 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
513 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
514 |
"rec_max2 f = PR (constn 0) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
515 |
(CN rec_ifz [CN f [CN S [Id 4 0], Id 4 2, Id 4 3], CN S [Id 4 0], Id 4 1])" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
516 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
517 |
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
|
518 |
"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
|
519 |
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
|
520 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
521 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
522 |
"rec_lg = |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
523 |
(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
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
528 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
529 |
"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
|
530 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
531 |
lemma lg_lemma: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
532 |
"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
|
533 |
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
|
534 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
535 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
536 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
537 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
538 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
539 |
fun mtest where |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
540 |
"mtest R 0 = if R 0 then 0 else 1" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
541 |
| "mtest R (Suc n) = (if R n then mtest R n else (Suc n))" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
542 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
543 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
544 |
lemma |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
545 |
"rec_eval (rec_maxr2 f) [x, y1, y2] = XXX" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
546 |
apply(simp only: rec_maxr2_def) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
547 |
apply(case_tac x) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
548 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
549 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
550 |
apply(simp only: constn_lemma) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
551 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
552 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
553 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
554 |
apply(simp only: rec_maxr2_def[symmetric]) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
555 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
556 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
557 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
558 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
559 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
560 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
561 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
562 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
563 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
564 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
565 |
apply(subst rec_eval.simps) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
566 |
apply(simp only: map.simps nth) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
567 |
|
240
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
568 |
|
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
569 |
definition |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
570 |
"rec_minr2 f = rec_sigma2 (rec_accum2 (CN rec_not [f]))" |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
571 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
572 |
definition |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
573 |
"rec_maxr2 f = rec_sigma2 (CN rec_sign [CN (rec_sigma2 f) [S]])" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
574 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
575 |
definition Minr :: "(nat \<Rightarrow> nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
576 |
where "Minr R x ys = Min ({z | z. z \<le> x \<and> R z ys} \<union> {Suc x})" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
577 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
578 |
definition Maxr :: "(nat \<Rightarrow> nat list \<Rightarrow> bool) \<Rightarrow> nat \<Rightarrow> nat list \<Rightarrow> nat" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
579 |
where "Maxr R x ys = Max ({z | z. z \<le> x \<and> R z ys} \<union> {0})" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
580 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
581 |
lemma 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
|
582 |
"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
|
583 |
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
|
584 |
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
|
585 |
done |
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 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
|
588 |
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
|
589 |
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
|
590 |
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
|
591 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
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
|
597 |
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
|
598 |
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
|
599 |
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
|
600 |
done |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
601 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
602 |
(* ??? *) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
603 |
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
|
604 |
fixes n::nat |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
605 |
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
|
606 |
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
|
607 |
using assms |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
608 |
apply(induct n) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
609 |
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
|
610 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
611 |
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
|
612 |
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
|
613 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
614 |
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
|
615 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
616 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
617 |
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
|
618 |
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
|
619 |
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
|
620 |
using assms |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
621 |
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
|
622 |
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
|
623 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
624 |
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
|
625 |
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
|
626 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
627 |
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
|
628 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
629 |
done |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
630 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
631 |
lemma disjCI2: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
632 |
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
|
633 |
apply (rule classical) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
634 |
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
|
635 |
done |
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
636 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
637 |
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
|
638 |
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
|
639 |
apply(induct x) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
640 |
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
|
641 |
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
|
642 |
apply(erule disjE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
643 |
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
|
644 |
apply(auto)[2] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
645 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
646 |
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
|
647 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
648 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
649 |
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
|
650 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
651 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
652 |
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
|
653 |
apply(rule disjCI) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
654 |
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
|
655 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
656 |
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
|
657 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
658 |
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
|
659 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
660 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
661 |
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
|
662 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
663 |
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
|
664 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
665 |
thm disj_CE |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
666 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
667 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
668 |
lemma minr_lemma: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
669 |
shows "rec_eval (rec_minr2 f) [x, y1, y2] = 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
|
670 |
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
|
671 |
apply(rule sym) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
672 |
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
|
673 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
674 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
675 |
apply(erule disjE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
676 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
677 |
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
|
678 |
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
|
679 |
apply(auto)[2] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
680 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
681 |
apply(induct x) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
682 |
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
|
683 |
apply( |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
684 |
apply(rule disjCI) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
685 |
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
|
686 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
687 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
688 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
689 |
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
|
690 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
691 |
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
|
692 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
693 |
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
|
694 |
apply(auto)[2] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
695 |
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
|
696 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
697 |
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
|
698 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
699 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
700 |
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
|
701 |
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
|
702 |
(\<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
|
703 |
prefer 2 |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
704 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
705 |
apply(erule disjE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
706 |
apply(rule disjI1) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
707 |
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
|
708 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
709 |
apply(rule disjI2) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
710 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
711 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
712 |
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
|
713 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
714 |
apply metis |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
715 |
apply(erule exE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
716 |
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
|
717 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
718 |
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
|
719 |
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
|
720 |
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
|
721 |
apply(assumption) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
722 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
723 |
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
|
724 |
prefer 2 |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
725 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
726 |
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
|
727 |
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
|
728 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
729 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
730 |
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
|
731 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
732 |
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
|
733 |
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
|
734 |
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
|
735 |
apply(assumption) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
736 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
737 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
738 |
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
|
739 |
prefer 2 |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
740 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
741 |
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
|
742 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
743 |
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
|
744 |
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
|
745 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
746 |
lemma minr_lemma: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
747 |
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
|
748 |
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
|
749 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
750 |
apply(rule sym) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
751 |
apply(rule Min_eqI) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
752 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
753 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
754 |
apply(erule disjE) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
755 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
756 |
apply(rule setsum_one_le) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
757 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
758 |
apply(rule setprod_one_le) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
759 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
760 |
apply(subst setsum_cut_off_le) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
761 |
apply(auto)[2] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
762 |
apply(rule setsum_one_less) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
763 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
764 |
apply(rule setprod_one_le) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
765 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
766 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
767 |
thm setsum_eq_one_le |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
768 |
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
|
769 |
(\<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
|
770 |
prefer 2 |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
771 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
772 |
apply(erule disjE) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
773 |
apply(rule disjI1) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
774 |
apply(rule setsum_eq_one_le) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
775 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
776 |
apply(rule disjI2) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
777 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
778 |
apply(clarify) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
779 |
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
|
780 |
defer |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
781 |
apply metis |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
782 |
apply(erule exE) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
783 |
apply(subgoal_tac "l \<le> x") |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
784 |
defer |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
785 |
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
|
786 |
apply(subst setsum_least_eq) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
787 |
apply(rotate_tac 4) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
788 |
apply(assumption) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
789 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
790 |
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
|
791 |
prefer 2 |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
792 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
793 |
apply(rotate_tac 5) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
794 |
apply(drule not_less_Least) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
795 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
796 |
apply(auto) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
797 |
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
|
798 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
799 |
apply (metis LeastI_ex) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
800 |
apply(subst setsum_least_eq) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
801 |
apply(rotate_tac 3) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
802 |
apply(assumption) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
803 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
804 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
805 |
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
|
806 |
prefer 2 |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
807 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
808 |
apply (metis neq0_conv not_less_Least) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
809 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
810 |
apply (metis (mono_tags) LeastI_ex) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
811 |
by (metis LeastI_ex) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
812 |
|
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
813 |
lemma disjCI2: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
814 |
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
|
815 |
apply (rule classical) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
816 |
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
|
817 |
done |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
818 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
819 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
820 |
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
|
821 |
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
|
822 |
(*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
|
823 |
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
|
824 |
prefer 2 |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
825 |
apply(erule disjE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
826 |
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
|
827 |
apply(auto)[2] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
828 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
829 |
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
|
830 |
apply(rule disjCI) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
831 |
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
|
832 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
833 |
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
|
834 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
835 |
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
|
836 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
837 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
838 |
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
|
839 |
apply(clarify) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
840 |
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
|
841 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
842 |
thm disj_CE |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
843 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
844 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
845 |
prefer 2 |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
846 |
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
|
847 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
848 |
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
|
849 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
850 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
851 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
852 |
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
|
853 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
854 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
855 |
lemma |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
856 |
"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
|
857 |
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
|
858 |
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
|
859 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
860 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
861 |
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
|
862 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
863 |
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
|
864 |
apply(auto) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
865 |
done |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
866 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
867 |
definition (in ord) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
868 |
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
|
869 |
"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
|
870 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
871 |
(* |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
872 |
lemma Great_equality: |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
873 |
assumes "P x" |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
874 |
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
|
875 |
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
|
876 |
unfolding Great_def |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
877 |
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
|
878 |
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
|
879 |
*) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
880 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
881 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
882 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
883 |
lemma |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
884 |
"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
|
885 |
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
|
886 |
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
|
887 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
888 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
889 |
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
|
890 |
oops |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
891 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
892 |
lemma |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
893 |
"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
|
894 |
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
|
895 |
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
|
896 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
897 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
898 |
apply(erule disjE) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
899 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
900 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
901 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
902 |
apply(simp) |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
903 |
apply(auto)[1] |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
904 |
thm Min_insert |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
905 |
defer |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
906 |
oops |
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
907 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
908 |
|
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
909 |
|
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
910 |
definition quo :: "nat \<Rightarrow> nat \<Rightarrow> nat" |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
911 |
where |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
912 |
"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
|
913 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
914 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
915 |
definition |
243
ac32cc069e30
added max and lg functions
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
241
diff
changeset
|
916 |
"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
|
917 |
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
|
918 |
[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
|
919 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
920 |
lemma div_lemma [simp]: |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
921 |
"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
|
922 |
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
|
923 |
apply(rule impI) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
924 |
apply(rule Min_eqI) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
925 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
926 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
927 |
apply(erule disjE) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
928 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
929 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
930 |
apply (metis div_le_dividend le_SucI) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
931 |
defer |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
932 |
apply(simp) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
933 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
934 |
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
|
935 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
936 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
937 |
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
|
938 |
apply(simp add: quo_def) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
939 |
apply(auto)[1] |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
940 |
|
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
941 |
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
|
942 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
943 |
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
|
944 |
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
|
945 |
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
|
946 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
947 |
definition |
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
948 |
"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
|
949 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
950 |
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
|
951 |
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
|
952 |
apply(simp only: rec_minr_def) |
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
953 |
apply(simp only: sigma1_lemma) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
954 |
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
|
955 |
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
|
956 |
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
|
957 |
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
|
958 |
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
|
959 |
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
|
960 |
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
|
961 |
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
|
962 |
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
|
963 |
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
|
964 |
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
|
965 |
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
|
966 |
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
|
967 |
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
|
968 |
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
|
969 |
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
|
970 |
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
|
971 |
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
|
972 |
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
|
973 |
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
|
974 |
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
|
975 |
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
|
976 |
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
|
977 |
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
|
978 |
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
|
979 |
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
|
980 |
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
|
981 |
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
|
982 |
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
|
983 |
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
|
984 |
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
|
985 |
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
|
986 |
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
|
987 |
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
|
988 |
defer |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
989 |
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
|
990 |
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
|
991 |
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
|
992 |
defer |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
993 |
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
|
994 |
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
|
995 |
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
|
996 |
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
|
997 |
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
|
998 |
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
|
999 |
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
|
1000 |
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
|
1001 |
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
|
1002 |
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
|
1003 |
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
|
1004 |
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
|
1005 |
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
|
1006 |
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
|
1007 |
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
|
1008 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1009 |
|
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1010 |
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
|
1011 |
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
|
1012 |
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
|
1013 |
|
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1014 |
lemma Minr2_Minr: |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1015 |
"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
|
1016 |
apply(auto) |
241
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1017 |
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
|
1018 |
apply(rule min_absorb2) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1019 |
apply(subst Min_le_iff) |
e59e549e6ab6
uodated
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
240
diff
changeset
|
1020 |
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
|
1021 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1022 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
1023 |
end |