src/HOL/ex/Predicate_Compile_ex.thy
author bulwahn
Tue, 09 Jun 2009 12:05:22 +0200
changeset 31514 fed8a95f54db
parent 31217 c025f32afd4e
child 31550 b63d253ed9e2
permissions -rw-r--r--
refactoring the predicate compiler
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    10
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    11
(*
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    12
code_pred even
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    13
  using assms by (rule even.cases)
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    14
*)
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    15
setup {* Predicate_Compile.add_equations @{const_name even} *}
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    16
thm odd.equation
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    17
thm even.equation
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    18
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    19
values "{x. even 2}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    20
values "{x. odd 2}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    21
values 10 "{n. even n}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    22
values 10 "{n. odd n}"
31195
12741f23527d added example on ML level
haftmann
parents: 31129
diff changeset
    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
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    29
inductive rev
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    30
where
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    31
"rev [] []"
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    32
| "rev xs xs' ==> append xs' [x] ys ==> rev (x#xs) ys"
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    33
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    34
setup {* Predicate_Compile.add_equations @{const_name rev} *}
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    35
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    36
thm rev.equation
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    37
thm append.equation
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    38
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    39
(*
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    40
code_pred append
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    41
  using assms by (rule append.cases)
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    42
*)
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    43
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    44
thm append.equation
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    45
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    46
values "{(ys, xs). append xs ys [0, Suc 0, 2]}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    47
values "{zs. append [0, Suc 0, 2] [17, 8] zs}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    48
values "{ys. append [0, Suc 0, 2] ys [0, Suc 0, 2, 17, 0,5]}"
31195
12741f23527d added example on ML level
haftmann
parents: 31129
diff changeset
    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
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    57
setup {* Predicate_Compile.add_equations @{const_name partition} *}
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    58
(*
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    59
code_pred partition
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    60
  using assms by (rule partition.cases)
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    61
*)
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    62
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    63
thm partition.equation
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    64
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    65
(*FIXME values 10 "{(ys, zs). partition (\<lambda>n. n mod 2 = 0)
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    66
  [0, Suc 0, 2, 3, 4, 5, 6, 7] ys zs}"*)
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    67
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    68
setup {* Predicate_Compile.add_equations @{const_name tranclp} *}
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    69
(*
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    70
code_pred tranclp
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    71
  using assms by (rule tranclp.cases)
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    72
*)
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    73
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    74
thm tranclp.equation
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    75
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    76
inductive succ :: "nat \<Rightarrow> nat \<Rightarrow> bool" where
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    77
    "succ 0 1"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    78
  | "succ m n \<Longrightarrow> succ (Suc m) (Suc n)"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    79
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    80
setup {* Predicate_Compile.add_equations @{const_name succ} *} 
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    81
(*
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    82
code_pred succ
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    83
  using assms by (rule succ.cases)
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    84
*)
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    85
thm succ.equation
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    86
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    87
(*
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    88
values 20 "{n. tranclp succ 10 n}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    89
values "{n. tranclp succ n 10}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    90
values 20 "{(n, m). tranclp succ n m}"
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    91
*)
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    92
30374
7311a1546d85 added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff changeset
    93
end