author | bulwahn |
Tue, 09 Jun 2009 12:05:22 +0200 | |
changeset 31514 | fed8a95f54db |
parent 31217 | c025f32afd4e |
child 31550 | b63d253ed9e2 |
permissions | -rw-r--r-- |
31129
d2cead76fca2
split Predicate_Compile examples into separate theory
haftmann
parents:
31123
diff
changeset
|
1 |
theory Predicate_Compile_ex |
d2cead76fca2
split Predicate_Compile examples into separate theory
haftmann
parents:
31123
diff
changeset
|
2 |
imports Complex_Main Predicate_Compile |
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
3 |
begin |
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
4 |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
5 |
inductive even :: "nat \<Rightarrow> bool" and odd :: "nat \<Rightarrow> bool" where |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
6 |
"even 0" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
7 |
| "even n \<Longrightarrow> odd (Suc n)" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
8 |
| "odd n \<Longrightarrow> even (Suc n)" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
9 |
|
31514 | 10 |
|
11 |
(* |
|
31123 | 12 |
code_pred even |
13 |
using assms by (rule even.cases) |
|
31514 | 14 |
*) |
15 |
setup {* Predicate_Compile.add_equations @{const_name even} *} |
|
16 |
thm odd.equation |
|
31123 | 17 |
thm even.equation |
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
18 |
|
31217 | 19 |
values "{x. even 2}" |
20 |
values "{x. odd 2}" |
|
21 |
values 10 "{n. even n}" |
|
22 |
values 10 "{n. odd n}" |
|
31195 | 23 |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
24 |
|
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
25 |
inductive append :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" where |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
26 |
append_Nil: "append [] xs xs" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
27 |
| append_Cons: "append xs ys zs \<Longrightarrow> append (x # xs) ys (x # zs)" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
28 |
|
31514 | 29 |
inductive rev |
30 |
where |
|
31 |
"rev [] []" |
|
32 |
| "rev xs xs' ==> append xs' [x] ys ==> rev (x#xs) ys" |
|
33 |
||
34 |
setup {* Predicate_Compile.add_equations @{const_name rev} *} |
|
35 |
||
36 |
thm rev.equation |
|
37 |
thm append.equation |
|
38 |
||
39 |
(* |
|
31123 | 40 |
code_pred append |
41 |
using assms by (rule append.cases) |
|
31514 | 42 |
*) |
31123 | 43 |
|
44 |
thm append.equation |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
45 |
|
31217 | 46 |
values "{(ys, xs). append xs ys [0, Suc 0, 2]}" |
47 |
values "{zs. append [0, Suc 0, 2] [17, 8] zs}" |
|
48 |
values "{ys. append [0, Suc 0, 2] ys [0, Suc 0, 2, 17, 0,5]}" |
|
31195 | 49 |
|
30972
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
50 |
|
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
51 |
inductive partition :: "('a \<Rightarrow> bool) \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
52 |
for f where |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
53 |
"partition f [] [] []" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
54 |
| "f x \<Longrightarrow> partition f xs ys zs \<Longrightarrow> partition f (x # xs) (x # ys) zs" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
55 |
| "\<not> f x \<Longrightarrow> partition f xs ys zs \<Longrightarrow> partition f (x # xs) ys (x # zs)" |
5b65835ccc92
some experiements towards user interface for predicate compiler
haftmann
parents:
30953
diff
changeset
|
56 |
|
31514 | 57 |
setup {* Predicate_Compile.add_equations @{const_name partition} *} |
58 |
(* |
|
31123 | 59 |
code_pred partition |
60 |
using assms by (rule partition.cases) |
|
31514 | 61 |
*) |
31123 | 62 |
|
63 |
thm partition.equation |
|
64 |
||
31217 | 65 |
(*FIXME values 10 "{(ys, zs). partition (\<lambda>n. n mod 2 = 0) |
66 |
[0, Suc 0, 2, 3, 4, 5, 6, 7] ys zs}"*) |
|
67 |
||
31514 | 68 |
setup {* Predicate_Compile.add_equations @{const_name tranclp} *} |
69 |
(* |
|
31123 | 70 |
code_pred tranclp |
71 |
using assms by (rule tranclp.cases) |
|
31514 | 72 |
*) |
31123 | 73 |
|
74 |
thm tranclp.equation |
|
75 |
||
31217 | 76 |
inductive succ :: "nat \<Rightarrow> nat \<Rightarrow> bool" where |
77 |
"succ 0 1" |
|
78 |
| "succ m n \<Longrightarrow> succ (Suc m) (Suc n)" |
|
79 |
||
31514 | 80 |
setup {* Predicate_Compile.add_equations @{const_name succ} *} |
81 |
(* |
|
31217 | 82 |
code_pred succ |
83 |
using assms by (rule succ.cases) |
|
31514 | 84 |
*) |
31217 | 85 |
thm succ.equation |
86 |
||
31514 | 87 |
(* |
31217 | 88 |
values 20 "{n. tranclp succ 10 n}" |
89 |
values "{n. tranclp succ n 10}" |
|
90 |
values 20 "{(n, m). tranclp succ n m}" |
|
31514 | 91 |
*) |
31217 | 92 |
|
30374
7311a1546d85
added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff
changeset
|
93 |
end |