src/HOL/ex/Predicate_Compile_ex.thy
author bulwahn
Sat, 24 Oct 2009 16:55:43 +0200
changeset 33147 180dc60bd88c
parent 33146 bf852ef586f2
child 33250 5c2af18a3237
permissions -rw-r--r--
improving the compilation with higher-order arguments in 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
33120
ca77d8c34ce2 cleaned up
bulwahn
parents: 33119
diff changeset
     2
imports Main Predicate_Compile_Alternative_Defs
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
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    10
code_pred (mode: [], [1]) even .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    11
code_pred [depth_limited] even .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    12
code_pred [rpred] even .
33137
0d16c07f8d24 added option to generate random values to values command in the predicate compiler
bulwahn
parents: 33136
diff changeset
    13
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
    14
thm odd.equation
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    15
thm even.equation
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    16
thm odd.depth_limited_equation
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    17
thm even.depth_limited_equation
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    18
thm even.rpred_equation
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    19
thm odd.rpred_equation
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    20
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    21
values "{x. even 2}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    22
values "{x. odd 2}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    23
values 10 "{n. even n}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    24
values 10 "{n. odd n}"
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    25
values [depth_limit = 2] "{x. even 6}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    26
values [depth_limit = 7] "{x. even 6}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    27
values [depth_limit = 2] "{x. odd 7}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    28
values [depth_limit = 8] "{x. odd 7}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    29
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    30
values [depth_limit = 7] 10 "{n. even n}"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    31
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    32
definition odd' where "odd' x == \<not> even x"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    33
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    34
code_pred [inductify] odd' .
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    35
code_pred [inductify, depth_limited] odd' .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    36
code_pred [inductify, rpred] odd' .
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    37
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    38
thm odd'.depth_limited_equation
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    39
values [depth_limit = 2] "{x. odd' 7}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    40
values [depth_limit = 9] "{x. odd' 7}"
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    41
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    42
inductive append :: "'a list \<Rightarrow> 'a list \<Rightarrow> 'a list \<Rightarrow> bool" where
32340
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
    43
    "append [] xs xs"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
    44
  | "append xs ys zs \<Longrightarrow> append (x # xs) ys (x # zs)"
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    45
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
    46
code_pred (mode: [1, 2], [3], [2, 3], [1, 3], [1, 2, 3]) append .
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    47
code_pred [depth_limited] append .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    48
code_pred [rpred] append .
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    49
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
    50
thm append.equation
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    51
thm append.depth_limited_equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    52
thm append.rpred_equation
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
    53
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    54
values "{(ys, xs). append xs ys [0, Suc 0, 2]}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
    55
values "{zs. append [0, Suc 0, 2] [17, 8] zs}"
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
    56
values "{ys. append [0, Suc 0, 2] ys [0, Suc 0, 2, 17, 0, 5]}"
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
    57
values [depth_limit = 3] "{(xs, ys). append xs ys [1, 2, 3, 4, (5::nat)]}"
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
    58
values [random] 15 "{(ys, zs). append [1::nat, 2] ys zs}"
31195
12741f23527d added example on ML level
haftmann
parents: 31129
diff changeset
    59
33111
db5af7b86a2f developing an executable the operator
bulwahn
parents: 33108
diff changeset
    60
value [code] "Predicate.the (append_1_2 [0::int, 1, 2] [3, 4, 5])"
db5af7b86a2f developing an executable the operator
bulwahn
parents: 33108
diff changeset
    61
value [code] "Predicate.the (append_3 ([]::int list))"
db5af7b86a2f developing an executable the operator
bulwahn
parents: 33108
diff changeset
    62
33116
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    63
subsection {* Tricky case with alternative rules *}
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
    64
33116
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    65
inductive append2
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    66
where
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    67
  "append2 [] xs xs"
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    68
| "append2 xs ys zs \<Longrightarrow> append2 (x # xs) ys (x # zs)"
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    69
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    70
lemma append2_Nil: "append2 [] (xs::'b list) xs"
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    71
  by (simp add: append2.intros(1))
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    72
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    73
lemmas [code_pred_intros] = append2_Nil append2.intros(2)
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    74
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    75
code_pred append2
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    76
proof -
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    77
  case append2
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    78
  from append2.cases[OF append2(1)] append2(2-3) show thesis by blast
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
    79
qed
33128
1f990689349f further cleaning up
bulwahn
parents: 33126
diff changeset
    80
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
    81
subsection {* Tricky cases with tuples *}
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
    82
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    83
inductive zerozero :: "nat * nat => bool"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    84
where
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    85
  "zerozero (0, 0)"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    86
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    87
code_pred zerozero .
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    88
code_pred [rpred] zerozero .
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
    89
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    90
inductive tupled_append :: "'a list \<times> 'a list \<times> 'a list \<Rightarrow> bool"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    91
where
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    92
  "tupled_append ([], xs, xs)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    93
| "tupled_append (xs, ys, zs) \<Longrightarrow> tupled_append (x # xs, ys, x # zs)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    94
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    95
code_pred tupled_append .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
    96
code_pred [rpred] tupled_append .
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    97
thm tupled_append.equation
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
    98
(*
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
    99
TODO: values with tupled modes
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   100
values "{xs. tupled_append ([1,2,3], [4,5], xs)}"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   101
*)
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   102
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   103
inductive tupled_append'
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   104
where
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   105
"tupled_append' ([], xs, xs)"
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   106
| "[| ys = fst (xa, y); x # zs = snd (xa, y);
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   107
 tupled_append' (xs, ys, zs) |] ==> tupled_append' (x # xs, xa, y)"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   108
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   109
code_pred tupled_append' .
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   110
thm tupled_append'.equation
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   111
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   112
inductive tupled_append'' :: "'a list \<times> 'a list \<times> 'a list \<Rightarrow> bool"
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   113
where
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   114
  "tupled_append'' ([], xs, xs)"
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   115
| "ys = fst yszs ==> x # zs = snd yszs ==> tupled_append'' (xs, ys, zs) \<Longrightarrow> tupled_append'' (x # xs, yszs)"
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   116
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   117
thm tupled_append''.cases
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   118
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   119
code_pred [inductify] tupled_append'' .
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   120
thm tupled_append''.equation
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   121
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   122
inductive tupled_append''' :: "'a list \<times> 'a list \<times> 'a list \<Rightarrow> bool"
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   123
where
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   124
  "tupled_append''' ([], xs, xs)"
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   125
| "yszs = (ys, zs) ==> tupled_append''' (xs, yszs) \<Longrightarrow> tupled_append''' (x # xs, ys, x # zs)"
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   126
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   127
code_pred [inductify] tupled_append''' .
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   128
thm tupled_append'''.equation
33114
4785ef554dcc added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents: 33113
diff changeset
   129
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   130
inductive map_ofP :: "('a \<times> 'b) list \<Rightarrow> 'a \<Rightarrow> 'b \<Rightarrow> bool"
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   131
where
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   132
  "map_ofP ((a, b)#xs) a b"
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   133
| "map_ofP xs a b \<Longrightarrow> map_ofP (x#xs) a b"
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   134
33120
ca77d8c34ce2 cleaned up
bulwahn
parents: 33119
diff changeset
   135
code_pred (mode: [1], [1, 2], [1, 2, 3], [1, 3]) map_ofP .
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   136
thm map_ofP.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   137
33147
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   138
inductive filter1
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   139
for P
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   140
where
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   141
  "filter1 P [] []"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   142
| "P x ==> filter1 P xs ys ==> filter1 P (x#xs) (x#ys)"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   143
| "\<not> P x ==> filter1 P xs ys ==> filter1 P (x#xs) ys"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   144
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   145
code_pred (mode: [1], [1, 2]) filter1 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   146
code_pred [depth_limited] filter1 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   147
code_pred [rpred] filter1 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   148
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   149
thm filter1.equation
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   150
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   151
inductive filter2
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   152
where
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   153
  "filter2 P [] []"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   154
| "P x ==> filter2 P xs ys ==> filter2 P (x#xs) (x#ys)"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   155
| "\<not> P x ==> filter2 P xs ys ==> filter2 P (x#xs) ys"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   156
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   157
code_pred (mode: [1, 2, 3], [1, 2]) filter2 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   158
code_pred [depth_limited] filter2 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   159
code_pred [rpred] filter2 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   160
thm filter2.equation
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   161
thm filter2.rpred_equation
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   162
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   163
inductive filter3
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   164
for P
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   165
where
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   166
  "List.filter P xs = ys ==> filter3 P xs ys"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   167
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   168
code_pred filter3 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   169
code_pred [depth_limited] filter3 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   170
thm filter3.depth_limited_equation
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   171
(*code_pred [rpred] filter3 .*)
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   172
inductive filter4
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   173
where
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   174
  "List.filter P xs = ys ==> filter4 P xs ys"
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   175
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   176
code_pred filter4 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   177
code_pred [depth_limited] filter4 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   178
code_pred [rpred] filter4 .
180dc60bd88c improving the compilation with higher-order arguments in the predicate compiler
bulwahn
parents: 33146
diff changeset
   179
33112
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   180
section {* reverse *}
6672184a736b added a few tricky examples with tuples; added alternative introduction rules for some constants; corrected mode analysis with negation; improved fetching of definitions
bulwahn
parents: 33111
diff changeset
   181
32340
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   182
inductive rev where
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   183
    "rev [] []"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   184
  | "rev xs xs' ==> append xs' [x] ys ==> rev (x#xs) ys"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   185
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   186
code_pred (mode: [1], [2], [1, 2]) rev .
32340
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   187
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   188
thm rev.equation
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   189
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   190
values "{xs. rev [0, 1, 2, 3::nat] xs}"
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
   191
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   192
inductive tupled_rev where
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   193
  "tupled_rev ([], [])"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   194
| "tupled_rev (xs, xs') \<Longrightarrow> tupled_append (xs', [x], ys) \<Longrightarrow> tupled_rev (x#xs, ys)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   195
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   196
code_pred tupled_rev .
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   197
thm tupled_rev.equation
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   198
30972
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
   199
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
   200
  for f where
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
   201
    "partition f [] [] []"
5b65835ccc92 some experiements towards user interface for predicate compiler
haftmann
parents: 30953
diff changeset
   202
  | "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
   203
  | "\<not> f x \<Longrightarrow> partition f xs ys zs \<Longrightarrow> partition f (x # xs) ys (x # zs)"
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   204
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   205
code_pred (mode: [1], [2, 3], [1, 2], [1, 3], [1, 2, 3]) partition .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   206
code_pred [depth_limited] partition .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   207
code_pred [rpred] partition .
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
   208
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   209
inductive tupled_partition :: "('a \<Rightarrow> bool) \<Rightarrow> ('a list \<times> 'a list \<times> 'a list) \<Rightarrow> bool"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   210
  for f where
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   211
   "tupled_partition f ([], [], [])"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   212
  | "f x \<Longrightarrow> tupled_partition f (xs, ys, zs) \<Longrightarrow> tupled_partition f (x # xs, x # ys, zs)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   213
  | "\<not> f x \<Longrightarrow> tupled_partition f (xs, ys, zs) \<Longrightarrow> tupled_partition f (x # xs, ys, x # zs)"
32314
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   214
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   215
code_pred tupled_partition .
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   216
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   217
thm tupled_partition.equation
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   218
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   219
32314
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   220
inductive is_even :: "nat \<Rightarrow> bool"
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   221
where
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   222
  "n mod 2 = 0 \<Longrightarrow> is_even n"
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   223
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   224
code_pred is_even .
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
   225
32314
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   226
values 10 "{(ys, zs). partition is_even
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   227
  [0, Suc 0, 2, 3, 4, 5, 6, 7] ys zs}"
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   228
values 10 "{zs. partition is_even zs [0, 2] [3, 5]}"
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   229
values 10 "{zs. partition is_even zs [0, 7] [3, 5]}"
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   230
31550
b63d253ed9e2 code_pred command now also requires proofs for dependent predicates; changed handling of parameters in introrules of executable function
bulwahn
parents: 31514
diff changeset
   231
lemma [code_pred_intros]:
32340
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   232
  "r a b \<Longrightarrow> tranclp r a b"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   233
  "r a b \<Longrightarrow> tranclp r b c \<Longrightarrow> tranclp r a c"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   234
  by auto
31573
0047df9eb347 improved infrastructure of predicate compiler for adding manual introduction rules
bulwahn
parents: 31551
diff changeset
   235
0047df9eb347 improved infrastructure of predicate compiler for adding manual introduction rules
bulwahn
parents: 31551
diff changeset
   236
code_pred tranclp
0047df9eb347 improved infrastructure of predicate compiler for adding manual introduction rules
bulwahn
parents: 31551
diff changeset
   237
proof -
31580
1c143f6a2226 added cases to code_pred command
bulwahn
parents: 31575
diff changeset
   238
  case tranclp
1c143f6a2226 added cases to code_pred command
bulwahn
parents: 31575
diff changeset
   239
  from this converse_tranclpE[OF this(1)] show thesis by metis
31573
0047df9eb347 improved infrastructure of predicate compiler for adding manual introduction rules
bulwahn
parents: 31551
diff changeset
   240
qed
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   241
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   242
code_pred [depth_limited] tranclp .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   243
code_pred [rpred] tranclp .
31123
e3b4e52c01c2 examples using code_pred
haftmann
parents: 31111
diff changeset
   244
thm tranclp.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   245
thm tranclp.rpred_equation
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   246
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   247
inductive succ :: "nat \<Rightarrow> nat \<Rightarrow> bool" where
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   248
    "succ 0 1"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   249
  | "succ m n \<Longrightarrow> succ (Suc m) (Suc n)"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   250
31550
b63d253ed9e2 code_pred command now also requires proofs for dependent predicates; changed handling of parameters in introrules of executable function
bulwahn
parents: 31514
diff changeset
   251
code_pred succ .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   252
code_pred [rpred] succ .
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   253
thm succ.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   254
thm succ.rpred_equation
32340
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   255
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   256
values 10 "{(m, n). succ n m}"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   257
values "{m. succ 0 m}"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   258
values "{m. succ m 0}"
b4632820e74c cleaned up
haftmann
parents: 31879
diff changeset
   259
32314
66bbad0bfef9 changed resolving depending predicates and fetching in the predicate compiler
bulwahn
parents: 32310
diff changeset
   260
(* FIXME: why does this not terminate? -- value chooses mode [] --> [1] and then starts enumerating all successors *)
32355
806d2df4d79d properly merged
haftmann
parents: 32351
diff changeset
   261
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
   262
(*
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   263
values 20 "{n. tranclp succ 10 n}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   264
values "{n. tranclp succ n 10}"
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   265
values 20 "{(n, m). tranclp succ n m}"
31514
fed8a95f54db refactoring the predicate compiler
bulwahn
parents: 31217
diff changeset
   266
*)
31217
c025f32afd4e experimental values command
haftmann
parents: 31195
diff changeset
   267
32424
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   268
subsection{* IMP *}
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   269
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   270
types
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   271
  var = nat
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   272
  state = "int list"
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   273
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   274
datatype com =
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   275
  Skip |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   276
  Ass var "state => int" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   277
  Seq com com |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   278
  IF "state => bool" com com |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   279
  While "state => bool" com
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   280
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   281
inductive exec :: "com => state => state => bool" where
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   282
"exec Skip s s" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   283
"exec (Ass x e) s (s[x := e(s)])" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   284
"exec c1 s1 s2 ==> exec c2 s2 s3 ==> exec (Seq c1 c2) s1 s3" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   285
"b s ==> exec c1 s t ==> exec (IF b c1 c2) s t" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   286
"~b s ==> exec c2 s t ==> exec (IF b c1 c2) s t" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   287
"~b s ==> exec (While b c) s s" |
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   288
"b s1 ==> exec c s1 s2 ==> exec (While b c) s2 s3 ==> exec (While b c) s1 s3"
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   289
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   290
code_pred exec .
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   291
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   292
values "{t. exec
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   293
 (While (%s. s!0 > 0) (Seq (Ass 0 (%s. s!0 - 1)) (Ass 1 (%s. s!1 + 1))))
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   294
 [3,5] t}"
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   295
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   296
inductive tupled_exec :: "(com \<times> state \<times> state) \<Rightarrow> bool" where
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   297
"tupled_exec (Skip, s, s)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   298
"tupled_exec (Ass x e, s, s[x := e(s)])" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   299
"tupled_exec (c1, s1, s2) ==> tupled_exec (c2, s2, s3) ==> tupled_exec (Seq c1 c2, s1, s3)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   300
"b s ==> tupled_exec (c1, s, t) ==> tupled_exec (IF b c1 c2, s, t)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   301
"~b s ==> tupled_exec (c2, s, t) ==> tupled_exec (IF b c1 c2, s, t)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   302
"~b s ==> tupled_exec (While b c, s, s)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   303
"b s1 ==> tupled_exec (c, s1, s2) ==> tupled_exec (While b c, s2, s3) ==> tupled_exec (While b c, s1, s3)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   304
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   305
code_pred tupled_exec .
32424
0fb428f9b5b0 New example: IMP
nipkow
parents: 32408
diff changeset
   306
32408
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   307
subsection{* CCS *}
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   308
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   309
text{* This example formalizes finite CCS processes without communication or
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   310
recursion. For simplicity, labels are natural numbers. *}
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   311
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   312
datatype proc = nil | pre nat proc | or proc proc | par proc proc
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   313
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   314
inductive step :: "proc \<Rightarrow> nat \<Rightarrow> proc \<Rightarrow> bool" where
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   315
"step (pre n p) n p" |
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   316
"step p1 a q \<Longrightarrow> step (or p1 p2) a q" |
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   317
"step p2 a q \<Longrightarrow> step (or p1 p2) a q" |
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   318
"step p1 a q \<Longrightarrow> step (par p1 p2) a (par q p2)" |
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   319
"step p2 a q \<Longrightarrow> step (par p1 p2) a (par p1 q)"
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   320
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   321
code_pred step .
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   322
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   323
inductive steps where
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   324
"steps p [] p" |
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   325
"step p a q \<Longrightarrow> steps q as r \<Longrightarrow> steps p (a#as) r"
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   326
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   327
code_pred steps .
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   328
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   329
values 5
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   330
 "{as . steps (par (or (pre 0 nil) (pre 1 nil)) (pre 2 nil)) as (par nil nil)}"
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   331
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   332
(* FIXME
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   333
values 3 "{(a,q). step (par nil nil) a q}"
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   334
*)
a1a85b0a26f7 new interval lemma
nipkow
parents: 32355
diff changeset
   335
33105
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   336
inductive tupled_step :: "(proc \<times> nat \<times> proc) \<Rightarrow> bool"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   337
where
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   338
"tupled_step (pre n p, n, p)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   339
"tupled_step (p1, a, q) \<Longrightarrow> tupled_step (or p1 p2, a, q)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   340
"tupled_step (p2, a, q) \<Longrightarrow> tupled_step (or p1 p2, a, q)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   341
"tupled_step (p1, a, q) \<Longrightarrow> tupled_step (par p1 p2, a, par q p2)" |
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   342
"tupled_step (p2, a, q) \<Longrightarrow> tupled_step (par p1 p2, a, par p1 q)"
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   343
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   344
code_pred tupled_step .
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   345
thm tupled_step.equation
1e4146bf841c added tupled versions of examples for the predicate compiler
bulwahn
parents: 33104
diff changeset
   346
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   347
subsection {* divmod *}
32579
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   348
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   349
inductive divmod_rel :: "nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> nat \<Rightarrow> bool" where
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   350
    "k < l \<Longrightarrow> divmod_rel k l 0 k"
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   351
  | "k \<ge> l \<Longrightarrow> divmod_rel (k - l) l q r \<Longrightarrow> divmod_rel k l (Suc q) r"
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   352
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   353
code_pred divmod_rel ..
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   354
33111
db5af7b86a2f developing an executable the operator
bulwahn
parents: 33108
diff changeset
   355
value [code] "Predicate.the (divmod_rel_1_2 1705 42)"
32579
73ad5dbf1034 added singleton example
haftmann
parents: 32424
diff changeset
   356
32670
cc0bae788b7e added a new example for the predicate compiler
bulwahn
parents: 32669
diff changeset
   357
section {* Executing definitions *}
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   358
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   359
definition Min
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   360
where "Min s r x \<equiv> s x \<and> (\<forall>y. r x y \<longrightarrow> x = y)"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   361
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   362
code_pred [inductify] Min .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   363
32670
cc0bae788b7e added a new example for the predicate compiler
bulwahn
parents: 32669
diff changeset
   364
subsection {* Examples with lists *}
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   365
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   366
subsubsection {* Lexicographic order *}
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   367
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   368
thm lexord_def
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   369
code_pred [inductify] lexord .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   370
code_pred [inductify, rpred] lexord .
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   371
thm lexord.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   372
thm lexord.rpred_equation
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   373
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   374
inductive less_than_nat :: "nat * nat => bool"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   375
where
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   376
  "less_than_nat (0, x)"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   377
| "less_than_nat (x, y) ==> less_than_nat (Suc x, Suc y)"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   378
 
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   379
code_pred less_than_nat .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   380
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   381
code_pred [depth_limited] less_than_nat .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   382
code_pred [rpred] less_than_nat .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   383
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   384
inductive test_lexord :: "nat list * nat list => bool"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   385
where
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   386
  "lexord less_than_nat (xs, ys) ==> test_lexord (xs, ys)"
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   387
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   388
code_pred [rpred] test_lexord .
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   389
code_pred [depth_limited] test_lexord .
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   390
thm test_lexord.depth_limited_equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   391
thm test_lexord.rpred_equation
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   392
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   393
values "{x. test_lexord ([1, 2, 3], [1, 2, 5])}"
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   394
values [depth_limit = 5] "{x. test_lexord ([1, 2, 3], [1, 2, 5])}"
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   395
(*values [random] "{xys. test_lexord xys}"*)
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   396
(*values [depth_limit = 5 random] "{xy. lexord less_than_nat xy}"*)
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   397
(*
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   398
lemma "(u, v) : lexord less_than_nat ==> (x @ u, y @ v) : lexord less_than_nat"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   399
quickcheck[generator=pred_compile]
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   400
oops
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   401
*)
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   402
lemmas [code_pred_def] = lexn_conv lex_conv lenlex_conv
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   403
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   404
code_pred [inductify] lexn .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   405
thm lexn.equation
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   406
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   407
code_pred [rpred] lexn .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   408
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   409
thm lexn.rpred_equation
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   410
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   411
code_pred [inductify, show_steps] lenlex .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   412
thm lenlex.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   413
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   414
code_pred [inductify, rpred] lenlex .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   415
thm lenlex.rpred_equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   416
32670
cc0bae788b7e added a new example for the predicate compiler
bulwahn
parents: 32669
diff changeset
   417
thm lists.intros
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   418
code_pred [inductify] lists .
32670
cc0bae788b7e added a new example for the predicate compiler
bulwahn
parents: 32669
diff changeset
   419
cc0bae788b7e added a new example for the predicate compiler
bulwahn
parents: 32669
diff changeset
   420
thm lists.equation
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   421
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   422
section {* AVL Tree Example *}
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   423
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   424
datatype 'a tree = ET | MKT 'a "'a tree" "'a tree" nat
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   425
fun height :: "'a tree => nat" where
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   426
"height ET = 0"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   427
| "height (MKT x l r h) = max (height l) (height r) + 1"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   428
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   429
consts avl :: "'a tree => bool"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   430
primrec
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   431
  "avl ET = True"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   432
  "avl (MKT x l r h) = ((height l = height r \<or> height l = 1 + height r \<or> height r = 1+height l) \<and> 
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   433
  h = max (height l) (height r) + 1 \<and> avl l \<and> avl r)"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   434
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   435
code_pred [inductify] avl .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   436
thm avl.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   437
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   438
code_pred [rpred] avl .
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   439
thm avl.rpred_equation
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   440
(*values [random] 10 "{t. avl (t::int tree)}"*)
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   441
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   442
fun set_of
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   443
where
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   444
"set_of ET = {}"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   445
| "set_of (MKT n l r h) = insert n (set_of l \<union> set_of r)"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   446
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   447
fun is_ord :: "nat tree => bool"
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   448
where
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   449
"is_ord ET = True"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   450
| "is_ord (MKT n l r h) =
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   451
 ((\<forall>n' \<in> set_of l. n' < n) \<and> (\<forall>n' \<in> set_of r. n < n') \<and> is_ord l \<and> is_ord r)"
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   452
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   453
code_pred (mode: [1], [1, 2]) [inductify] set_of .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   454
thm set_of.equation
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   455
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   456
code_pred [inductify] is_ord .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   457
thm is_ord.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   458
code_pred [rpred] is_ord .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   459
thm is_ord.rpred_equation
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   460
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   461
section {* Definitions about Relations *}
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   462
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   463
code_pred [inductify] converse .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   464
thm converse.equation
33145
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   465
code_pred [inductify] rel_comp .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   466
thm rel_comp.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   467
code_pred [inductify] Image .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   468
thm Image.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   469
(*TODO: *)
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   470
ML {* Toplevel.debug := true *}
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   471
declare Id_on_def[unfolded UNION_def, code_pred_def]
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   472
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   473
code_pred [inductify] Id_on .
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   474
thm Id_on.equation
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   475
code_pred [inductify] Domain .
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   476
thm Domain.equation
33145
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   477
code_pred [inductify] Range .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   478
thm sym_def
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   479
code_pred [inductify] Field .
33146
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   480
declare Sigma_def[unfolded UNION_def, code_pred_def]
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   481
declare refl_on_def[unfolded UNION_def, code_pred_def]
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   482
code_pred [inductify] refl_on .
bf852ef586f2 now the predicate compilere handles the predicate without introduction rules better as before
bulwahn
parents: 33145
diff changeset
   483
thm refl_on.equation
33145
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   484
code_pred [inductify] total_on .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   485
thm total_on.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   486
(*
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   487
code_pred [inductify] sym .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   488
thm sym.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   489
*)
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   490
code_pred [inductify] antisym .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   491
thm antisym.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   492
code_pred [inductify] trans .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   493
thm trans.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   494
code_pred [inductify] single_valued .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   495
thm single_valued.equation
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   496
code_pred [inductify] inv_image .
1a22f7ca1dfc removed dead code; added examples
bulwahn
parents: 33143
diff changeset
   497
thm inv_image.equation
32668
b2de45007537 added first prototype of the extended predicate compiler
bulwahn
parents: 32665
diff changeset
   498
33114
4785ef554dcc added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents: 33113
diff changeset
   499
section {* List functions *}
4785ef554dcc added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents: 33113
diff changeset
   500
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   501
code_pred [inductify] length .
33114
4785ef554dcc added further examples; added mode to code_pred command; tuned; some temporary things in Predicate_Compile_ex
bulwahn
parents: 33113
diff changeset
   502
thm size_listP.equation
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   503
code_pred [inductify, rpred] length .
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   504
thm size_listP.rpred_equation
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   505
values [random] 20 "{xs. size_listP (xs::nat list) (5::nat)}"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   506
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   507
code_pred [inductify] concat .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   508
code_pred [inductify] hd .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   509
code_pred [inductify] tl .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   510
code_pred [inductify] last .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   511
code_pred [inductify] butlast .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   512
(*code_pred [inductify] listsum .*)
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   513
code_pred [inductify] take .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   514
code_pred [inductify] drop .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   515
code_pred [inductify] zip .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   516
code_pred [inductify] upt .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   517
code_pred [inductify] remdups .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   518
code_pred [inductify] remove1 .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   519
code_pred [inductify] removeAll .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   520
code_pred [inductify] distinct .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   521
code_pred [inductify] replicate .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   522
code_pred [inductify] splice .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   523
code_pred [inductify] List.rev .
33129
3085da75ed54 changed import_intros to handle parameters differently; changed handling of higher-order function compilation; reverted MicroJava change; tuned
bulwahn
parents: 33128
diff changeset
   524
code_pred [inductify] map .
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   525
code_pred [inductify] foldr .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   526
code_pred [inductify] foldl .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   527
code_pred [inductify] filter .
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   528
code_pred [inductify, rpred] filter .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   529
thm filterP.rpred_equation
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   530
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   531
definition test where "test xs = filter (\<lambda>x. x = (1::nat)) xs"
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   532
code_pred [inductify] test .
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   533
thm testP.equation
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   534
code_pred [inductify, rpred] test .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   535
thm testP.rpred_equation
33116
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
   536
32669
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   537
section {* Context Free Grammar *}
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   538
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   539
datatype alphabet = a | b
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   540
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   541
inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   542
  "[] \<in> S\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   543
| "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   544
| "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   545
| "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   546
| "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   547
| "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1"
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   548
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   549
code_pred [inductify] S\<^isub>1p .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   550
code_pred [inductify, rpred] S\<^isub>1p .
32669
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   551
thm S\<^isub>1p.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   552
thm S\<^isub>1p.rpred_equation
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   553
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   554
values [random] 5 "{x. S\<^isub>1p x}"
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   555
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   556
inductive is_a where
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   557
  "is_a a"
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   558
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   559
inductive is_b where
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   560
  "is_b b"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   561
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   562
code_pred is_a .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   563
code_pred [depth_limited] is_a .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   564
code_pred [rpred] is_a .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   565
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   566
values [random] "{x. is_a x}"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   567
code_pred [depth_limited] is_b .
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   568
code_pred [rpred] is_b .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   569
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   570
code_pred [inductify, depth_limited] filter .
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   571
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   572
values [depth_limit=5] "{x. filterP is_a [a, b] x}"
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   573
values [depth_limit=3] "{x. filterP is_b [a, b] x}"
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   574
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   575
lemma "w \<in> S\<^isub>1 \<Longrightarrow> length (filter (\<lambda>x. x = a) w) = 1"
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   576
(*quickcheck[generator=pred_compile, size=10]*)
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   577
oops
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   578
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   579
inductive test_lemma where
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   580
  "S\<^isub>1p w ==> filterP is_a w r1 ==> size_listP r1 r2 ==> filterP is_b w r3 ==> size_listP r3 r4 ==> r2 \<noteq> r4 ==> test_lemma w"
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   581
(*
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   582
code_pred [rpred] test_lemma .
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   583
*)
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   584
(*
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   585
definition test_lemma' where
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   586
  "test_lemma' w == (w \<in> S\<^isub>1 \<and> (\<not> length [x <- w. x = a] = length [x <- w. x = b]))"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   587
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   588
code_pred [inductify, rpred] test_lemma' .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   589
thm test_lemma'.rpred_equation
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   590
*)
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   591
(*thm test_lemma'.rpred_equation*)
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   592
(*
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   593
values [depth_limit=3 random] "{x. S\<^isub>1 x}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   594
*)
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   595
code_pred [depth_limited] is_b .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   596
(*
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   597
code_pred [inductify, depth_limited] filter .
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   598
*)
33140
83951822bfd0 cleaning the signature of the predicate compiler core; renaming signature and structures to uniform long names
bulwahn
parents: 33139
diff changeset
   599
thm filterP.intros
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   600
thm filterP.equation
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   601
(*
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   602
values [depth_limit=3] "{x. filterP is_b [a, b] x}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   603
find_theorems "test_lemma'_hoaux"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   604
code_pred [depth_limited] test_lemma'_hoaux .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   605
thm test_lemma'_hoaux.depth_limited_equation
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   606
values [depth_limit=2] "{x. test_lemma'_hoaux b}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   607
inductive test1 where
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   608
  "\<not> test_lemma'_hoaux x ==> test1 x"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   609
code_pred test1 .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   610
code_pred [depth_limited] test1 .
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   611
thm test1.depth_limited_equation
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   612
thm test_lemma'_hoaux.depth_limited_equation
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   613
thm test1.intros
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   614
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   615
values [depth_limit=2] "{x. test1 b}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   616
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   617
thm filterP.intros
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   618
thm filterP.depth_limited_equation
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   619
values [depth_limit=3] "{x. filterP test_lemma'_hoaux [a, b] x}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   620
values [depth_limit=4 random] "{w. test_lemma w}"
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   621
values [depth_limit=4 random] "{w. test_lemma' w}"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   622
*)
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   623
(*
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   624
theorem S\<^isub>1_sound:
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   625
"w \<in> S\<^isub>1p \<Longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   626
quickcheck[generator=pred_compile, size=15]
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   627
oops
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   628
*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   629
inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   630
  "[] \<in> S\<^isub>2"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   631
| "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   632
| "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   633
| "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   634
| "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   635
| "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2"
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   636
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   637
code_pred [inductify, rpred] S\<^isub>2 .
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   638
thm S\<^isub>2.rpred_equation
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   639
thm A\<^isub>2.rpred_equation
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   640
thm B\<^isub>2.rpred_equation
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   641
33143
730a2e8a6ec6 modularized the compilation in the predicate compiler
bulwahn
parents: 33141
diff changeset
   642
values [random] 10 "{x. S\<^isub>2 x}"
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   643
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   644
theorem S\<^isub>2_sound:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   645
"w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   646
(*quickcheck[generator=SML]*)
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   647
(*quickcheck[generator=pred_compile, size=15, iterations=1]*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   648
oops
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   649
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   650
inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   651
  "[] \<in> S\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   652
| "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   653
| "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   654
| "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   655
| "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   656
| "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   657
33124
5378e61add1a continued cleaning up; moved tuple expanding to core
bulwahn
parents: 33123
diff changeset
   658
code_pred [inductify] S\<^isub>3 .
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   659
thm S\<^isub>3.equation
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   660
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   661
values 10 "{x. S\<^isub>3 x}"
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   662
(*
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   663
theorem S\<^isub>3_sound:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   664
"w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
33139
9c01ee6f8ee9 added skip_proof option; playing with compilation of depth-limited predicates
bulwahn
parents: 33138
diff changeset
   665
quickcheck[generator=pred_compile, size=10, iterations=1]
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   666
oops
33141
89b23fad5e02 modifying the depth-limited compilation to be sound, but now throws an error undefined in case of hitting the depth limit in an negative context; cleaning up the examples
bulwahn
parents: 33140
diff changeset
   667
*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   668
lemma "\<not> (length w > 2) \<or> \<not> (length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b])"
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   669
(*quickcheck[size=10, generator = pred_compile]*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   670
oops
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   671
(*
33108
9d9afd478016 added test for higher-order function inductification; added debug messages
bulwahn
parents: 33105
diff changeset
   672
inductive test
9d9afd478016 added test for higher-order function inductification; added debug messages
bulwahn
parents: 33105
diff changeset
   673
where
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   674
  "length [x \<leftarrow> w. a = x] = length [x \<leftarrow> w. x = b] ==> test w"
33108
9d9afd478016 added test for higher-order function inductification; added debug messages
bulwahn
parents: 33105
diff changeset
   675
ML {* @{term "[x \<leftarrow> w. x = a]"} *}
9d9afd478016 added test for higher-order function inductification; added debug messages
bulwahn
parents: 33105
diff changeset
   676
code_pred (inductify_all) test .
33116
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
   677
b379ee2cddb1 changed importing introduction rules to fix the same type variables in all introduction rules; improved mode analysis for partially applied relations; added test case; tuned
bulwahn
parents: 33114
diff changeset
   678
thm test.equation
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   679
*)
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   680
(*
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   681
theorem S\<^isub>3_complete:
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   682
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. b = x] \<longrightarrow> w \<in> S\<^isub>3"
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   683
(*quickcheck[generator=SML]*)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   684
quickcheck[generator=pred_compile, size=10, iterations=100]
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   685
oops
33113
0f6e30b87cf1 processing of tuples in introduction rules
bulwahn
parents: 33112
diff changeset
   686
*)
33138
e2e23987c59a reinvestigating the compilation of the random computation in the predicate compiler
bulwahn
parents: 33137
diff changeset
   687
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   688
inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   689
  "[] \<in> S\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   690
| "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   691
| "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   692
| "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   693
| "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   694
| "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   695
| "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4"
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   696
(*
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   697
theorem S\<^isub>4_sound:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   698
"w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   699
quickcheck[generator = pred_compile, size=2, iterations=1]
32673
d5db9cf85401 replaced sorry by oops; removed old debug functions in predicate compiler
bulwahn
parents: 32672
diff changeset
   700
oops
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   701
*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   702
theorem S\<^isub>4_complete:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   703
"length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4"
33123
3c7c4372f9ad cleaned up debugging messages; added options to code_pred command
bulwahn
parents: 33120
diff changeset
   704
(*quickcheck[generator = pred_compile, size=5, iterations=1]*)
32673
d5db9cf85401 replaced sorry by oops; removed old debug functions in predicate compiler
bulwahn
parents: 32672
diff changeset
   705
oops
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   706
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   707
theorem S\<^isub>4_A\<^isub>4_B\<^isub>4_sound_and_complete:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   708
"w \<in> S\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   709
"w \<in> A\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   710
"w \<in> B\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   711
(*quickcheck[generator = pred_compile, size=5, iterations=1]*)
32673
d5db9cf85401 replaced sorry by oops; removed old debug functions in predicate compiler
bulwahn
parents: 32672
diff changeset
   712
oops
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   713
33104
560372b461e5 moved meta_fun_cong lemma into ML-file; tuned
bulwahn
parents: 32673
diff changeset
   714
section {* Lambda *}
32669
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   715
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   716
datatype type =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   717
    Atom nat
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   718
  | Fun type type    (infixr "\<Rightarrow>" 200)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   719
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   720
datatype dB =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   721
    Var nat
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   722
  | App dB dB (infixl "\<degree>" 200)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   723
  | Abs type dB
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   724
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   725
primrec
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   726
  nth_el :: "'a list \<Rightarrow> nat \<Rightarrow> 'a option" ("_\<langle>_\<rangle>" [90, 0] 91)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   727
where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   728
  "[]\<langle>i\<rangle> = None"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   729
| "(x # xs)\<langle>i\<rangle> = (case i of 0 \<Rightarrow> Some x | Suc j \<Rightarrow> xs \<langle>j\<rangle>)"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   730
33128
1f990689349f further cleaning up
bulwahn
parents: 33126
diff changeset
   731
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   732
inductive nth_el' :: "'a list \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> bool"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   733
where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   734
  "nth_el' (x # xs) 0 x"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   735
| "nth_el' xs i y \<Longrightarrow> nth_el' (x # xs) (Suc i) y"
33128
1f990689349f further cleaning up
bulwahn
parents: 33126
diff changeset
   736
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   737
inductive typing :: "type list \<Rightarrow> dB \<Rightarrow> type \<Rightarrow> bool"  ("_ \<turnstile> _ : _" [50, 50, 50] 50)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   738
  where
33128
1f990689349f further cleaning up
bulwahn
parents: 33126
diff changeset
   739
    Var [intro!]: "nth_el' env x T \<Longrightarrow> env \<turnstile> Var x : T"
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   740
  | Abs [intro!]: "T # env \<turnstile> t : U \<Longrightarrow> env \<turnstile> Abs T t : (T \<Rightarrow> U)"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   741
(*  | App [intro!]: "env \<turnstile> s : T \<Rightarrow> U \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U" *)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   742
  | App [intro!]: "env \<turnstile> s : U \<Rightarrow> T \<Longrightarrow> env \<turnstile> t : T \<Longrightarrow> env \<turnstile> (s \<degree> t) : U"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   743
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   744
primrec
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   745
  lift :: "[dB, nat] => dB"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   746
where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   747
    "lift (Var i) k = (if i < k then Var i else Var (i + 1))"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   748
  | "lift (s \<degree> t) k = lift s k \<degree> lift t k"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   749
  | "lift (Abs T s) k = Abs T (lift s (k + 1))"
32669
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   750
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   751
primrec
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   752
  subst :: "[dB, dB, nat] => dB"  ("_[_'/_]" [300, 0, 0] 300)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   753
where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   754
    subst_Var: "(Var i)[s/k] =
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   755
      (if k < i then Var (i - 1) else if i = k then s else Var i)"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   756
  | subst_App: "(t \<degree> u)[s/k] = t[s/k] \<degree> u[s/k]"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   757
  | subst_Abs: "(Abs T t)[s/k] = Abs T (t[lift s 0 / k+1])"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   758
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   759
inductive beta :: "[dB, dB] => bool"  (infixl "\<rightarrow>\<^sub>\<beta>" 50)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   760
  where
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   761
    beta [simp, intro!]: "Abs T s \<degree> t \<rightarrow>\<^sub>\<beta> s[t/0]"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   762
  | appL [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> s \<degree> u \<rightarrow>\<^sub>\<beta> t \<degree> u"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   763
  | appR [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> u \<degree> s \<rightarrow>\<^sub>\<beta> u \<degree> t"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   764
  | abs [simp, intro!]: "s \<rightarrow>\<^sub>\<beta> t ==> Abs T s \<rightarrow>\<^sub>\<beta> Abs T t"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   765
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   766
lemma "Gamma \<turnstile> t : T \<Longrightarrow> t \<rightarrow>\<^sub>\<beta> t' \<Longrightarrow> Gamma \<turnstile> t' : T"
33136
74d51fb3be2e commented out the random generator compilation in the example file
bulwahn
parents: 33129
diff changeset
   767
(*quickcheck[generator = pred_compile, size = 10, iterations = 1]*)
32672
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   768
oops
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   769
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   770
lemma filter_eq_ConsD:
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   771
 "filter P ys = x#xs \<Longrightarrow>
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   772
  \<exists>us vs. ys = ts @ x # vs \<and> (\<forall>u\<in>set us. \<not> P u) \<and> P x \<and> xs = filter P vs"
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   773
(*quickcheck[generator = pred_compile]*)
90f3ce5d27ae added first version of quickcheck based on the predicate compiler; added a few quickcheck examples
bulwahn
parents: 32670
diff changeset
   774
oops
32669
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   775
462b1dd67a58 added context free grammar example; removed dead code; adapted to work without quick and dirty mode; fixed typo
bulwahn
parents: 32668
diff changeset
   776
30374
7311a1546d85 added predicate compiler, as formally checked prototype, not as user package
haftmann
parents:
diff changeset
   777
end