equal
deleted
inserted
replaced
466 *} |
466 *} |
467 |
467 |
468 |
468 |
469 subsection {* Simplification procedures *} |
469 subsection {* Simplification procedures *} |
470 |
470 |
471 text {* |
471 text {* Simplification procedures are ML functions that produce proven |
|
472 rewrite rules on demand. They are associated with higher-order |
|
473 patterns that approximate the left-hand sides of equations. The |
|
474 Simplifier first matches the current redex against one of the LHS |
|
475 patterns; if this succeeds, the corresponding ML function is |
|
476 invoked, passing the Simplifier context and redex term. Thus rules |
|
477 may be specifically fashioned for particular situations, resulting |
|
478 in a more powerful mechanism than term rewriting by a fixed set of |
|
479 rules. |
|
480 |
|
481 Any successful result needs to be a (possibly conditional) rewrite |
|
482 rule @{text "t \<equiv> u"} that is applicable to the current redex. The |
|
483 rule will be applied just as any ordinary rewrite rule. It is |
|
484 expected to be already in \emph{internal form}, bypassing the |
|
485 automatic preprocessing of object-level equivalences. |
|
486 |
472 \begin{matharray}{rcl} |
487 \begin{matharray}{rcl} |
473 @{command_def "simproc_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
488 @{command_def "simproc_setup"} & : & @{text "local_theory \<rightarrow> local_theory"} \\ |
474 simproc & : & @{text attribute} \\ |
489 simproc & : & @{text attribute} \\ |
475 \end{matharray} |
490 \end{matharray} |
476 |
491 |
510 |
525 |
511 \end{description} |
526 \end{description} |
512 *} |
527 *} |
513 |
528 |
514 |
529 |
|
530 subsubsection {* Example *} |
|
531 |
|
532 text {* The following simplification procedure for @{thm |
|
533 [source=false, show_types] unit_eq} in HOL performs fine-grained |
|
534 control over rule application, beyond higher-order pattern matching. |
|
535 Declaring @{thm unit_eq} as @{attribute simp} directly would make |
|
536 the simplifier loop! Note that a version of this simplification |
|
537 procedure is already active in Isabelle/HOL. *} |
|
538 |
|
539 simproc_setup unit ("x::unit") = {* |
|
540 fn _ => fn _ => fn ct => |
|
541 if HOLogic.is_unit (term_of ct) then NONE |
|
542 else SOME (mk_meta_eq @{thm unit_eq}) |
|
543 *} |
|
544 |
|
545 text {* Since the Simplifier applies simplification procedures |
|
546 frequently, it is important to make the failure check in ML |
|
547 reasonably fast. *} |
|
548 |
|
549 |
515 subsection {* Forward simplification *} |
550 subsection {* Forward simplification *} |
516 |
551 |
517 text {* |
552 text {* |
518 \begin{matharray}{rcl} |
553 \begin{matharray}{rcl} |
519 @{attribute_def simplified} & : & @{text attribute} \\ |
554 @{attribute_def simplified} & : & @{text attribute} \\ |