3 begin |
3 begin |
4 (* |
4 (* |
5 declare mem_def[code_pred_inline] |
5 declare mem_def[code_pred_inline] |
6 *) |
6 *) |
7 |
7 |
8 subsection {* Alternative rules for length *} |
8 subsection \<open>Alternative rules for length\<close> |
9 |
9 |
10 definition size_list :: "'a list => nat" |
10 definition size_list :: "'a list => nat" |
11 where "size_list = size" |
11 where "size_list = size" |
12 |
12 |
13 lemma size_list_simps: |
13 lemma size_list_simps: |
17 |
17 |
18 declare size_list_simps[code_pred_def] |
18 declare size_list_simps[code_pred_def] |
19 declare size_list_def[symmetric, code_pred_inline] |
19 declare size_list_def[symmetric, code_pred_inline] |
20 |
20 |
21 |
21 |
22 setup {* |
22 setup \<open> |
23 Context.theory_map |
23 Context.theory_map |
24 (Quickcheck.add_tester ("prolog", (Code_Prolog.active, Code_Prolog.test_goals))) |
24 (Quickcheck.add_tester ("prolog", (Code_Prolog.active, Code_Prolog.test_goals))) |
25 *} |
25 \<close> |
26 |
26 |
27 datatype alphabet = a | b |
27 datatype alphabet = a | b |
28 |
28 |
29 inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where |
29 inductive_set S\<^sub>1 and A\<^sub>1 and B\<^sub>1 where |
30 "[] \<in> S\<^sub>1" |
30 "[] \<in> S\<^sub>1" |
57 lemma [code_pred_def]: "filter_b (x#xs) = (if x = b then x # filter_b xs else filter_b xs)" |
57 lemma [code_pred_def]: "filter_b (x#xs) = (if x = b then x # filter_b xs else filter_b xs)" |
58 unfolding filter_b_def by simp |
58 unfolding filter_b_def by simp |
59 |
59 |
60 declare filter_b_def[symmetric, code_pred_inline] |
60 declare filter_b_def[symmetric, code_pred_inline] |
61 |
61 |
62 setup {* Code_Prolog.map_code_options (K |
62 setup \<open>Code_Prolog.map_code_options (K |
63 {ensure_groundness = true, |
63 {ensure_groundness = true, |
64 limit_globally = NONE, |
64 limit_globally = NONE, |
65 limited_types = [], |
65 limited_types = [], |
66 limited_predicates = [(["s1p", "a1p", "b1p"], 2)], |
66 limited_predicates = [(["s1p", "a1p", "b1p"], 2)], |
67 replacing = [(("s1p", "limited_s1p"), "quickcheck")], |
67 replacing = [(("s1p", "limited_s1p"), "quickcheck")], |
68 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]}) *} |
68 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]})\<close> |
69 |
69 |
70 |
70 |
71 theorem S\<^sub>1_sound: |
71 theorem S\<^sub>1_sound: |
72 "S\<^sub>1p w \<Longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
72 "S\<^sub>1p w \<Longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
73 quickcheck[tester = prolog, iterations=1, expect = counterexample] |
73 quickcheck[tester = prolog, iterations=1, expect = counterexample] |
81 | "w \<in> S\<^sub>2 \<Longrightarrow> a # w \<in> A\<^sub>2" |
81 | "w \<in> S\<^sub>2 \<Longrightarrow> a # w \<in> A\<^sub>2" |
82 | "w \<in> S\<^sub>2 \<Longrightarrow> b # w \<in> B\<^sub>2" |
82 | "w \<in> S\<^sub>2 \<Longrightarrow> b # w \<in> B\<^sub>2" |
83 | "\<lbrakk>v \<in> B\<^sub>2; v \<in> B\<^sub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>2" |
83 | "\<lbrakk>v \<in> B\<^sub>2; v \<in> B\<^sub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>2" |
84 |
84 |
85 |
85 |
86 setup {* Code_Prolog.map_code_options (K |
86 setup \<open>Code_Prolog.map_code_options (K |
87 {ensure_groundness = true, |
87 {ensure_groundness = true, |
88 limit_globally = NONE, |
88 limit_globally = NONE, |
89 limited_types = [], |
89 limited_types = [], |
90 limited_predicates = [(["s2p", "a2p", "b2p"], 3)], |
90 limited_predicates = [(["s2p", "a2p", "b2p"], 3)], |
91 replacing = [(("s2p", "limited_s2p"), "quickcheck")], |
91 replacing = [(("s2p", "limited_s2p"), "quickcheck")], |
92 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]}) *} |
92 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]})\<close> |
93 |
93 |
94 |
94 |
95 theorem S\<^sub>2_sound: |
95 theorem S\<^sub>2_sound: |
96 "S\<^sub>2p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
96 "S\<^sub>2p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
97 quickcheck[tester = prolog, iterations=1, expect = counterexample] |
97 quickcheck[tester = prolog, iterations=1, expect = counterexample] |
104 | "w \<in> S\<^sub>3 \<Longrightarrow> a # w \<in> A\<^sub>3" |
104 | "w \<in> S\<^sub>3 \<Longrightarrow> a # w \<in> A\<^sub>3" |
105 | "w \<in> S\<^sub>3 \<Longrightarrow> b # w \<in> B\<^sub>3" |
105 | "w \<in> S\<^sub>3 \<Longrightarrow> b # w \<in> B\<^sub>3" |
106 | "\<lbrakk>v \<in> B\<^sub>3; w \<in> B\<^sub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>3" |
106 | "\<lbrakk>v \<in> B\<^sub>3; w \<in> B\<^sub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>3" |
107 |
107 |
108 |
108 |
109 setup {* Code_Prolog.map_code_options (K |
109 setup \<open>Code_Prolog.map_code_options (K |
110 {ensure_groundness = true, |
110 {ensure_groundness = true, |
111 limit_globally = NONE, |
111 limit_globally = NONE, |
112 limited_types = [], |
112 limited_types = [], |
113 limited_predicates = [(["s3p", "a3p", "b3p"], 6)], |
113 limited_predicates = [(["s3p", "a3p", "b3p"], 6)], |
114 replacing = [(("s3p", "limited_s3p"), "quickcheck")], |
114 replacing = [(("s3p", "limited_s3p"), "quickcheck")], |
115 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]}) *} |
115 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]})\<close> |
116 |
116 |
117 lemma S\<^sub>3_sound: |
117 lemma S\<^sub>3_sound: |
118 "S\<^sub>3p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
118 "S\<^sub>3p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
119 quickcheck[tester = prolog, iterations=1, size=1, expect = no_counterexample] |
119 quickcheck[tester = prolog, iterations=1, size=1, expect = no_counterexample] |
120 oops |
120 oops |
146 | "\<lbrakk>v \<in> A\<^sub>4; w \<in> A\<^sub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^sub>4" |
146 | "\<lbrakk>v \<in> A\<^sub>4; w \<in> A\<^sub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^sub>4" |
147 | "w \<in> S\<^sub>4 \<Longrightarrow> b # w \<in> B\<^sub>4" |
147 | "w \<in> S\<^sub>4 \<Longrightarrow> b # w \<in> B\<^sub>4" |
148 | "\<lbrakk>v \<in> B\<^sub>4; w \<in> B\<^sub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>4" |
148 | "\<lbrakk>v \<in> B\<^sub>4; w \<in> B\<^sub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^sub>4" |
149 |
149 |
150 |
150 |
151 setup {* Code_Prolog.map_code_options (K |
151 setup \<open>Code_Prolog.map_code_options (K |
152 {ensure_groundness = true, |
152 {ensure_groundness = true, |
153 limit_globally = NONE, |
153 limit_globally = NONE, |
154 limited_types = [], |
154 limited_types = [], |
155 limited_predicates = [(["s4p", "a4p", "b4p"], 6)], |
155 limited_predicates = [(["s4p", "a4p", "b4p"], 6)], |
156 replacing = [(("s4p", "limited_s4p"), "quickcheck")], |
156 replacing = [(("s4p", "limited_s4p"), "quickcheck")], |
157 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]}) *} |
157 manual_reorder = [(("quickcheck", 1), [0,2,1,4,3,5])]})\<close> |
158 |
158 |
159 |
159 |
160 theorem S\<^sub>4_sound: |
160 theorem S\<^sub>4_sound: |
161 "S\<^sub>4p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
161 "S\<^sub>4p w \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" |
162 quickcheck[tester = prolog, size=1, iterations=1, expect = no_counterexample] |
162 quickcheck[tester = prolog, size=1, iterations=1, expect = no_counterexample] |