author | Christian Urban <christian dot urban at kcl dot ac dot uk> |
Thu, 25 Apr 2013 21:37:05 +0100 | |
changeset 240 | 696081f445c2 |
child 241 | e59e549e6ab6 |
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 |
"(if P then 0 else 1) = (0::nat) \<longleftrightarrow> P" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
8 |
"(0::nat) < (if P then 1 else 0) = P" |
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 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
18 |
lemma setprod_atMost_Suc[simp]: "(\<Prod>i \<le> Suc n. f i) = (\<Prod>i \<le> n. f i) * f(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
|
19 |
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
|
20 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
21 |
lemma setprod_lessThan_Suc[simp]: "(\<Prod>i < Suc n. f i) = (\<Prod>i < n. f i) * 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
|
22 |
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
|
23 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
24 |
lemma 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
|
25 |
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
|
26 |
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
|
27 |
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
|
28 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
29 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
30 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
31 |
lemma setsum_eq_zero [simp]: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
32 |
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
|
33 |
shows "(\<Sum>i < n. f i) = (0::nat) \<longleftrightarrow> (\<forall>i < 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
|
34 |
"(\<Sum>i \<le> n. f i) = (0::nat) \<longleftrightarrow> (\<forall>i \<le> 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
|
35 |
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
|
36 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
37 |
lemma setprod_eq_zero [simp]: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
38 |
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
|
39 |
shows "(\<Prod>i < n. f i) = (0::nat) \<longleftrightarrow> (\<exists>i < 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
|
40 |
"(\<Prod>i \<le> n. f i) = (0::nat) \<longleftrightarrow> (\<exists>i \<le> 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
|
41 |
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
|
42 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
43 |
lemma setsum_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
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
50 |
lemma 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
|
51 |
fixes n 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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
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
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
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
|
64 |
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
|
65 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
66 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
67 |
lemma 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
|
68 |
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
|
69 |
assumes "\<forall>i \<le> n. f i \<le> (1::nat)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
70 |
shows "(\<Prod>i \<le> 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
|
71 |
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
|
72 |
apply(induct n) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
73 |
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
|
74 |
by (metis One_nat_def eq_iff le_0_eq le_SucE mult_0 nat_mult_1) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
75 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
76 |
lemma setprod_greater_zero: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
77 |
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
|
78 |
assumes "\<forall>i \<le> n. f i \<ge> (0::nat)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
79 |
shows "(\<Prod>i \<le> n. f i) \<ge> 0" |
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 assms |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
81 |
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
|
82 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
83 |
lemma setprod_eq_one: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
84 |
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
|
85 |
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
|
86 |
shows "(\<Prod>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
|
87 |
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
|
88 |
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
|
89 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
90 |
lemma setsum_cut_off_less: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
91 |
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
|
92 |
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
|
93 |
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
|
94 |
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
|
95 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
96 |
have eq_zero: "(\<Sum>i \<in> {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
|
97 |
using h2 by auto |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
98 |
have "(\<Sum>i < 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
|
99 |
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
|
100 |
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
|
101 |
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
|
102 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
103 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
104 |
lemma setsum_cut_off_le: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
105 |
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
|
106 |
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
|
107 |
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
|
108 |
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
|
109 |
proof - |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
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
|
116 |
qed |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
117 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
118 |
lemma setprod_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
|
119 |
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
|
120 |
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
|
121 |
"(\<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
|
122 |
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
|
123 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
124 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
125 |
datatype recf = z |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
126 |
| s |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
127 |
| id nat nat |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
128 |
| 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
|
129 |
| 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
|
130 |
| 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
|
131 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
132 |
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
|
133 |
where |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
134 |
"arity z = 1" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
135 |
| "arity s = 1" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
136 |
| "arity (id m n) = m" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
137 |
| "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
|
138 |
| "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
|
139 |
| "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
|
140 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
141 |
abbreviation |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
142 |
"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
|
143 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
144 |
abbreviation |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
145 |
"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
|
146 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
147 |
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
|
148 |
where |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
149 |
"rec_eval z 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
|
150 |
| "rec_eval s xs = Suc (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
|
151 |
| "rec_eval (id m n) xs = 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
|
152 |
| "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
|
153 |
| "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
|
154 |
| "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
|
155 |
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
|
156 |
| "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
|
157 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
158 |
inductive |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
159 |
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
|
160 |
where |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
161 |
termi_z: "terminates z [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 |
| termi_s: "terminates s [n]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
163 |
| termi_id: "\<lbrakk>n < m; length xs = m\<rbrakk> \<Longrightarrow> terminates (id m n) xs" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
164 |
| 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
|
165 |
\<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
|
166 |
| 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
|
167 |
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
|
168 |
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
|
169 |
\<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
|
170 |
| 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
|
171 |
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
|
172 |
\<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
|
173 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
174 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
175 |
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
|
176 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
177 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
178 |
@{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
|
179 |
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
|
180 |
*} |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
181 |
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
|
182 |
where |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
183 |
"constn 0 = z" | |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
184 |
"constn (Suc n) = CN s [constn n]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
185 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
186 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
187 |
"rec_swap f = CN f [id 2 1, id 2 0]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
188 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
189 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
190 |
"rec_add = PR (id 1 0) (CN s [id 3 1])" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
191 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
192 |
definition |
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_mult = PR z (CN rec_add [id 3 1, id 3 2])" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
194 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
195 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
196 |
"rec_power_swap = PR (constn 1) (CN rec_mult [id 3 1, id 3 2])" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
197 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
198 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
199 |
"rec_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
|
200 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
201 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
202 |
"rec_fact = PR (constn 1) (CN rec_mult [CN s [id 3 0], id 3 1])" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
203 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
204 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
205 |
"rec_pred = CN (PR z (id 3 0)) [id 1 0, id 1 0]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
206 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
207 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
208 |
"rec_minus_swap = (PR (id 1 0) (CN rec_pred [id 3 1]))" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
209 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
210 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
211 |
"rec_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
|
212 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
213 |
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
|
214 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
215 |
"rec_sign = CN rec_minus [constn 1, CN rec_minus [constn 1, id 1 0]]" |
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
218 |
"rec_not = CN rec_minus [constn 1, id 1 0]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
219 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
220 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
221 |
@{text "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
|
222 |
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
|
223 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
224 |
"rec_eq = CN 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
|
225 |
[CN (constn 1) [id 2 0], |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
226 |
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
|
227 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
228 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
229 |
"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
|
230 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
231 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
232 |
"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
|
233 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
234 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
235 |
"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
|
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
238 |
"rec_imp = CN rec_disj [CN rec_not [id 2 0], id 2 1]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
239 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
240 |
text {* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
241 |
@{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
|
242 |
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
|
243 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
244 |
"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
|
245 |
|
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_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
|
248 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
249 |
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
|
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_sigma1 f = PR (CN f [z, id 1 0]) (CN rec_add [id 3 1, CN f [s, id 3 2]])" |
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_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]])" |
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_accum1 f = PR (CN f [z, id 1 0]) (CN rec_mult [id 3 1, CN f [s, id 3 2]])" |
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
261 |
"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]])" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
262 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
263 |
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
|
264 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
265 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
266 |
"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
|
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 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
269 |
"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
|
270 |
|
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_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
|
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_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
|
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 {* Dvd *} |
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
280 |
"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]" |
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 |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
283 |
"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
|
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 |
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
|
286 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
287 |
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
|
288 |
"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
|
289 |
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
|
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 |
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
|
292 |
"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
|
293 |
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
|
294 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
295 |
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
|
296 |
"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
|
297 |
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
|
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 |
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
|
300 |
"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
|
301 |
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
|
302 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
303 |
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
|
304 |
"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
|
305 |
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
|
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 |
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
|
308 |
"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
|
309 |
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
|
310 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
311 |
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
|
312 |
"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
|
313 |
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
|
314 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
315 |
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
|
316 |
"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
|
317 |
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
|
318 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
319 |
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
|
320 |
"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
|
321 |
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
|
322 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
323 |
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
|
324 |
"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
|
325 |
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
|
326 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
327 |
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
|
328 |
"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
|
329 |
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
|
330 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
331 |
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
|
332 |
"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
|
333 |
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
|
334 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
335 |
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
|
336 |
"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
|
337 |
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
|
338 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
339 |
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
|
340 |
"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
|
341 |
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
|
342 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
343 |
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
|
344 |
"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
|
345 |
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
|
346 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
347 |
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
|
348 |
"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
|
349 |
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
|
350 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
351 |
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
|
352 |
"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
|
353 |
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
|
354 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
355 |
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
|
356 |
"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
|
357 |
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
|
358 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
359 |
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
|
360 |
"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
|
361 |
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
|
362 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
363 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
364 |
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
|
365 |
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
|
366 |
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
|
367 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
368 |
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
|
369 |
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
|
370 |
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
|
371 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
372 |
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
|
373 |
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
|
374 |
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
|
375 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
376 |
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
|
377 |
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
|
378 |
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
|
379 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
380 |
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
|
381 |
"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
|
382 |
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
|
383 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
384 |
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
|
385 |
"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
|
386 |
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
|
387 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
388 |
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
|
389 |
"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
|
390 |
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
|
391 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
392 |
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
|
393 |
"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
|
394 |
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
|
395 |
|
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 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
|
398 |
"(x dvd y) = (\<exists>k\<le>y. y = x * (k::nat))" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
399 |
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
|
400 |
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
|
401 |
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
|
402 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
403 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
404 |
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
|
405 |
"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
|
406 |
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
|
407 |
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
|
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 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
|
410 |
"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
|
411 |
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
|
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 |
definition |
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_prime = |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
415 |
(let conj1 = CN rec_less [constn 1, id 1 0] in |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
416 |
let disj = CN rec_disj [CN rec_eq [id 2 0, constn 1], rec_eq] in |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
417 |
let imp = CN rec_imp [rec_dvd, disj] in |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
418 |
let conj2 = CN (rec_all1 imp) [id 1 0, id 1 0] in |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
419 |
CN rec_conj [conj1, conj2])" |
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 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
|
422 |
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
|
423 |
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
|
424 |
apply(auto simp add: prime_nat_def 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
|
425 |
by (metis One_nat_def le_neq_implies_less less_SucI less_Suc_eq_0_disj less_Suc_eq_le mult_is_0 n_less_n_mult_m not_less_eq_eq) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
426 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
427 |
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
|
428 |
"rec_eval rec_prime [x] = (if prime 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
|
429 |
by (simp add: rec_prime_def Let_def 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
|
430 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
431 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
432 |
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
|
433 |
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
|
434 |
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
|
435 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
436 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
437 |
"rec_minr f = rec_sigma (rec_accum (CN rec_not [f]))" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
438 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
439 |
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
|
440 |
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
|
441 |
apply(simp only: rec_minr_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 |
apply(simp only: sigma_lemma) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
443 |
apply(simp only: accum_lemma) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
444 |
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
|
445 |
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
|
446 |
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
|
447 |
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
|
448 |
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
|
449 |
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
|
450 |
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
|
451 |
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
|
452 |
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
|
453 |
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
|
454 |
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
|
455 |
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
|
456 |
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
|
457 |
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
|
458 |
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
|
459 |
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
|
460 |
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
|
461 |
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
|
462 |
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
|
463 |
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
|
464 |
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
|
465 |
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
|
466 |
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
|
467 |
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
|
468 |
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
|
469 |
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
|
470 |
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
|
471 |
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
|
472 |
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
|
473 |
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
|
474 |
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
|
475 |
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
|
476 |
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
|
477 |
defer |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
478 |
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
|
479 |
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
|
480 |
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
|
481 |
defer |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
482 |
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
|
483 |
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
|
484 |
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
|
485 |
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
|
486 |
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
|
487 |
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
|
488 |
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
|
489 |
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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
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
|
495 |
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
|
496 |
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
|
497 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
498 |
(* |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
499 |
lemma prime_alt_iff: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
500 |
fixes x::nat |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
501 |
shows "prime x \<longleftrightarrow> 1 < x \<and> (\<forall>u < x. \<forall>v < x. x \<noteq> u * v)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
502 |
unfolding prime_nat_simp 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
|
503 |
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
|
504 |
by (smt n_less_m_mult_n nat_mult_commute) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
505 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
506 |
lemma prime_alt2_iff: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
507 |
fixes x::nat |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
508 |
shows "prime x \<longleftrightarrow> 1 < x \<and> (\<forall>u \<le> x - 1. \<forall>v \<le> x - 1. x \<noteq> u * v)" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
509 |
unfolding prime_alt_iff |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
510 |
sorry |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
511 |
*) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
512 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
513 |
definition |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
514 |
"rec_prime = CN rec_conj |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
515 |
[CN rec_less [constn 1, id 1 0], |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
516 |
CN (rec_all (CN (rec_all2 (CN rec_noteq [id 3 2, CN rec_mult [id 3 1, id 3 0]])) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
517 |
[CN rec_pred [id 2 1], id 2 0, id 2 1])) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
518 |
[CN rec_pred [id 1 0], id 1 0]]" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
519 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
520 |
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
|
521 |
"rec_eval rec_prime [x] = (if prime 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
|
522 |
apply(rule trans) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
523 |
apply(simp add: rec_prime_def) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
524 |
apply(simp only: prime_nat_def 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
|
525 |
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
|
526 |
apply(drule_tac x="m" in spec) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
527 |
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
|
528 |
apply(case_tac m) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
529 |
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
|
530 |
apply(case_tac nat) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
531 |
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
|
532 |
apply(case_tac k) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
533 |
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
|
534 |
apply(case_tac nat) |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
535 |
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
|
536 |
done |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
537 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
538 |
lemma if_zero [simp]: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
539 |
"(0::nat) < (if P then 1 else 0) = P" |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
540 |
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
|
541 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
542 |
lemma if_cong: |
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
543 |
"P = Q \<Longrightarrow> (if P then 1 else (0::nat)) = (if Q 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
|
544 |
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
|
545 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
546 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
547 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
548 |
|
696081f445c2
added improved Recsursive function theory (not yet finished)
Christian Urban <christian dot urban at kcl dot ac dot uk>
parents:
diff
changeset
|
549 |
end |