1417 code_pred [inductify] test_minus_bool . |
1417 code_pred [inductify] test_minus_bool . |
1418 thm test_minus_bool.equation |
1418 thm test_minus_bool.equation |
1419 |
1419 |
1420 values "{x. test_minus_bool x}" |
1420 values "{x. test_minus_bool x}" |
1421 |
1421 |
|
1422 subsection {* Functions *} |
|
1423 |
|
1424 fun partial_hd :: "'a list => 'a option" |
|
1425 where |
|
1426 "partial_hd [] = Option.None" |
|
1427 | "partial_hd (x # xs) = Some x" |
|
1428 |
|
1429 inductive hd_predicate |
|
1430 where |
|
1431 "partial_hd xs = Some x ==> hd_predicate xs x" |
|
1432 |
|
1433 code_pred (expected_modes: i => i => bool, i => o => bool) hd_predicate . |
|
1434 |
|
1435 thm hd_predicate.equation |
|
1436 |
|
1437 subsection {* Locales *} |
|
1438 |
|
1439 inductive hd_predicate2 :: "('a list => 'a option) => 'a list => 'a => bool" |
|
1440 where |
|
1441 "partial_hd' xs = Some x ==> hd_predicate2 partial_hd' xs x" |
|
1442 |
|
1443 |
|
1444 thm hd_predicate2.intros |
|
1445 |
|
1446 code_pred (expected_modes: i => i => i => bool, i => i => o => bool) hd_predicate2 . |
|
1447 thm hd_predicate2.equation |
|
1448 |
|
1449 locale A = fixes partial_hd :: "'a list => 'a option" begin |
|
1450 |
|
1451 inductive hd_predicate_in_locale :: "'a list => 'a => bool" |
|
1452 where |
|
1453 "partial_hd xs = Some x ==> hd_predicate_in_locale xs x" |
|
1454 |
|
1455 end |
|
1456 |
|
1457 text {* The global introduction rules must be redeclared as introduction rules and then |
|
1458 one could invoke code_pred. *} |
|
1459 |
|
1460 declare A.hd_predicate_in_locale.intros [unfolded Predicate.eq_is_eq[symmetric], code_pred_intro] |
|
1461 |
|
1462 code_pred (expected_modes: i => i => i => bool, i => i => o => bool) A.hd_predicate_in_locale |
|
1463 unfolding eq_is_eq by (auto elim: A.hd_predicate_in_locale.cases) |
|
1464 |
|
1465 interpretation A partial_hd . |
|
1466 thm hd_predicate_in_locale.intros |
|
1467 text {* A locally compliant solution with a trivial interpretation fails, because |
|
1468 the predicate compiler has very strict assumptions about the terms and their structure. *} |
|
1469 |
|
1470 (*code_pred hd_predicate_in_locale .*) |
|
1471 |
1422 subsection {* Examples for detecting switches *} |
1472 subsection {* Examples for detecting switches *} |
1423 |
1473 |
1424 inductive detect_switches1 where |
1474 inductive detect_switches1 where |
1425 "detect_switches1 [] []" |
1475 "detect_switches1 [] []" |
1426 | "detect_switches1 (x # xs) (y # ys)" |
1476 | "detect_switches1 (x # xs) (y # ys)" |