src/HOL/ex/Predicate_Compile_ex.thy
changeset 33139 9c01ee6f8ee9
parent 33138 e2e23987c59a
child 33140 83951822bfd0
equal deleted inserted replaced
33138:e2e23987c59a 33139:9c01ee6f8ee9
   407 values [depth_limit = 5] "{x. test_lexord ([1, 2, 3], [1, 2, 5])}"
   407 values [depth_limit = 5] "{x. test_lexord ([1, 2, 3], [1, 2, 5])}"
   408 
   408 
   409 values [depth_limit = 25 random] "{xys. test_lexord xys}"
   409 values [depth_limit = 25 random] "{xys. test_lexord xys}"
   410 
   410 
   411 values [depth_limit = 5 random] "{xy. lexord less_than_nat xy}"
   411 values [depth_limit = 5 random] "{xy. lexord less_than_nat xy}"
   412 
   412 ML {* Predicate_Compile_Core.do_proofs := false *}
   413 lemma "(u, v) : lexord r ==> (x @ u, y @ v) : lexord r"
   413 lemma "(u, v) : lexord less_than_nat ==> (x @ u, y @ v) : lexord less_than_nat"
   414 quickcheck[generator=pred_compile]
   414 quickcheck[generator=pred_compile]
   415 oops
   415 oops
   416 
   416 
   417 lemmas [code_pred_def] = lexn_conv lex_conv lenlex_conv
   417 lemmas [code_pred_def] = lexn_conv lex_conv lenlex_conv
   418 
   418 (*
   419 code_pred [inductify] lexn .
   419 code_pred [inductify] lexn .
   420 thm lexn.equation
   420 thm lexn.equation
       
   421 *)
       
   422 code_pred [inductify, rpred] lexn .
       
   423 
       
   424 thm lexn.rpred_equation
   421 
   425 
   422 code_pred [inductify] lenlex .
   426 code_pred [inductify] lenlex .
   423 thm lenlex.equation
   427 thm lenlex.equation
   424 (*
   428 (*
   425 code_pred [inductify, rpred] lenlex .
   429 code_pred [inductify, rpred] lenlex .
   445 (*
   449 (*
   446 code_pred [inductify] avl .
   450 code_pred [inductify] avl .
   447 thm avl.equation
   451 thm avl.equation
   448 *)
   452 *)
   449 code_pred [inductify, rpred] avl .
   453 code_pred [inductify, rpred] avl .
   450 find_theorems "avl_aux"
       
   451 thm avl.rpred_equation
   454 thm avl.rpred_equation
   452 values [depth_limit = 50 random] 10 "{t. avl (t::int tree)}"
   455 values [depth_limit = 50 random] 10 "{t. avl (t::int tree)}"
       
   456 
       
   457 lemma "avl t ==> t = ET"
       
   458 quickcheck[generator=code]
       
   459 quickcheck[generator = pred_compile]
       
   460 oops
       
   461 
   453 fun set_of
   462 fun set_of
   454 where
   463 where
   455 "set_of ET = {}"
   464 "set_of ET = {}"
   456 | "set_of (MKT n l r h) = insert n (set_of l \<union> set_of r)"
   465 | "set_of (MKT n l r h) = insert n (set_of l \<union> set_of r)"
   457 
   466 
   544 thm S\<^isub>1p.equation
   553 thm S\<^isub>1p.equation
   545 thm S\<^isub>1p.rpred_equation
   554 thm S\<^isub>1p.rpred_equation
   546 
   555 
   547 values [depth_limit = 5 random] "{x. S\<^isub>1p x}"
   556 values [depth_limit = 5 random] "{x. S\<^isub>1p x}"
   548 
   557 
       
   558 inductive is_a where
       
   559 "is_a a"
       
   560 
       
   561 inductive is_b where
       
   562   "is_b b"
       
   563 
       
   564 code_pred is_a .
       
   565 code_pred [depth_limited] is_a .
       
   566 code_pred [rpred] is_a .
       
   567 
       
   568 values [depth_limit=5 random] "{x. is_a x}"
       
   569 code_pred [rpred] is_b .
       
   570 
       
   571 code_pred [rpred] filterP .
       
   572 values [depth_limit=5 random] "{x. filterP is_a [a, b] x}"
       
   573 values [depth_limit=3 random] "{x. filterP is_b [a, b] x}"
       
   574 
       
   575 lemma "w \<in> S\<^isub>1 \<Longrightarrow> length (filter (\<lambda>x. x = a) w) = 1"
       
   576 quickcheck[generator=pred_compile, size=10]
       
   577 oops
       
   578 
       
   579 inductive test_lemma where
       
   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"
       
   581 
       
   582 code_pred [rpred] test_lemma .
       
   583 
       
   584 definition test_lemma' where
       
   585   "test_lemma' w == (w \<in> S\<^isub>1 \<and> (\<not> length [x <- w. x = a] = length [x <- w. x = b]))"
       
   586 
       
   587 code_pred [inductify, rpred] test_lemma' .
       
   588 thm test_lemma'.rpred_equation
       
   589 (*thm test_lemma'.rpred_equation*)
       
   590 (*
       
   591 values [depth_limit=3 random] "{x. S\<^isub>1 x}"
       
   592 *)
       
   593 code_pred [depth_limited] is_b .
       
   594 code_pred [inductify, depth_limited] filter .
       
   595 thm  filterP.intros
       
   596 thm filterP.equation
       
   597 
       
   598 values [depth_limit=3] "{x. filterP is_b [a, b] x}"
       
   599 find_theorems "test_lemma'_hoaux"
       
   600 code_pred [depth_limited] test_lemma'_hoaux .
       
   601 thm test_lemma'_hoaux.depth_limited_equation
       
   602 values [depth_limit=2] "{x. test_lemma'_hoaux b}"
       
   603 inductive test1 where
       
   604   "\<not> test_lemma'_hoaux x ==> test1 x"
       
   605 code_pred test1 .
       
   606 code_pred [depth_limited] test1 .
       
   607 thm test1.depth_limited_equation
       
   608 thm test_lemma'_hoaux.depth_limited_equation
       
   609 thm test1.intros
       
   610 
       
   611 values [depth_limit=2] "{x. test1 b}"
       
   612 
       
   613 thm filterP.intros
       
   614 thm filterP.depth_limited_equation
       
   615 values [depth_limit=3] "{x. filterP test_lemma'_hoaux [a, b] x}"
       
   616 values [depth_limit=4 random] "{w. test_lemma w}"
       
   617 values [depth_limit=4 random] "{w. test_lemma' w}"
   549 
   618 
   550 theorem S\<^isub>1_sound:
   619 theorem S\<^isub>1_sound:
   551 "w \<in> S\<^isub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   620 "w \<in> S\<^isub>1p \<Longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   552 (*quickcheck[generator=pred_compile]*)
   621 quickcheck[generator=pred_compile, size=5]
   553 oops
   622 oops
       
   623 
   554 
   624 
   555 inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
   625 inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where
   556   "[] \<in> S\<^isub>2"
   626   "[] \<in> S\<^isub>2"
   557 | "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
   627 | "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2"
   558 | "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
   628 | "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2"
   563 code_pred [inductify, rpred] S\<^isub>2 .
   633 code_pred [inductify, rpred] S\<^isub>2 .
   564 thm S\<^isub>2.rpred_equation
   634 thm S\<^isub>2.rpred_equation
   565 thm A\<^isub>2.rpred_equation
   635 thm A\<^isub>2.rpred_equation
   566 thm B\<^isub>2.rpred_equation
   636 thm B\<^isub>2.rpred_equation
   567 
   637 
   568 values [depth_limit = 10 random] "{x. S\<^isub>2 x}"
   638 values [depth_limit = 4 random] "{x. S\<^isub>2 x}"
   569 
   639 
   570 theorem S\<^isub>2_sound:
   640 theorem S\<^isub>2_sound:
   571 "w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   641 "w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   572 (*quickcheck[generator=SML]*)
   642 (*quickcheck[generator=SML]*)
   573 (*quickcheck[generator=pred_compile, size=15, iterations=100]*)
   643 quickcheck[generator=pred_compile, size=4, iterations=1]
   574 oops
   644 oops
   575 
   645 
   576 inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
   646 inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where
   577   "[] \<in> S\<^isub>3"
   647   "[] \<in> S\<^isub>3"
   578 | "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
   648 | "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3"
   586 
   656 
   587 values 10 "{x. S\<^isub>3 x}"
   657 values 10 "{x. S\<^isub>3 x}"
   588 
   658 
   589 theorem S\<^isub>3_sound:
   659 theorem S\<^isub>3_sound:
   590 "w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   660 "w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]"
   591 (*quickcheck[generator=pred_compile, size=10, iterations=1]*)
   661 quickcheck[generator=pred_compile, size=10, iterations=1]
   592 oops
   662 oops
   593 
   663 
   594 lemma "\<not> (length w > 2) \<or> \<not> (length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b])"
   664 lemma "\<not> (length w > 2) \<or> \<not> (length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b])"
   595 (*quickcheck[size=10, generator = pred_compile]*)
   665 (*quickcheck[size=10, generator = pred_compile]*)
   596 oops
   666 oops