389 (@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * ) |
404 (@@{method simp} | @@{method simp_all}) opt? (@{syntax simpmod} * ) |
390 ; |
405 ; |
391 |
406 |
392 opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')' |
407 opt: '(' ('no_asm' | 'no_asm_simp' | 'no_asm_use' | 'asm_lr' ) ')' |
393 ; |
408 ; |
394 @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'cong' (() | 'add' | 'del') | |
409 @{syntax_def simpmod}: ('add' | 'del' | 'only' | 'split' (() | 'add' | 'del') | |
395 'split' (() | 'add' | 'del')) ':' @{syntax thmrefs} |
410 'cong' (() | 'add' | 'del')) ':' @{syntax thmrefs} |
396 "} |
411 "} |
397 |
412 |
398 \begin{description} |
413 \begin{description} |
399 |
414 |
400 \item @{method simp} invokes the Simplifier, after declaring |
415 \item @{method simp} invokes the Simplifier on the first subgoal, |
401 additional rules according to the arguments given. Note that the |
416 after inserting chained facts as additional goal premises; further |
402 @{text only} modifier first removes all other rewrite rules, |
417 rule declarations may be included via @{text "(simp add: facts)"}. |
403 congruences, and looper tactics (including splits), and then behaves |
418 The proof method fails if the subgoal remains unchanged after |
404 like @{text add}. |
419 simplification. |
405 |
420 |
406 \medskip The @{text cong} modifiers add or delete Simplifier |
421 Note that the original goal premises and chained facts are subject |
407 congruence rules (see also \secref{sec:simp-cong}), the default is |
422 to simplification themselves, while declarations via @{text |
408 to add. |
423 "add"}/@{text "del"} merely follow the policies of the object-logic |
|
424 to extract rewrite rules from theorems, without further |
|
425 simplification. This may lead to slightly different behavior in |
|
426 either case, which might be required precisely like that in some |
|
427 boundary situations to perform the intended simplification step! |
|
428 |
|
429 \medskip The @{text only} modifier first removes all other rewrite |
|
430 rules, looper tactics (including split rules), congruence rules, and |
|
431 then behaves like @{text add}. Implicit solvers remain, which means |
|
432 that trivial rules like reflexivity or introduction of @{text |
|
433 "True"} are available to solve the simplified subgoals, but also |
|
434 non-trivial tools like linear arithmetic in HOL. The latter may |
|
435 lead to some surprise of the meaning of ``only'' in Isabelle/HOL |
|
436 compared to English! |
409 |
437 |
410 \medskip The @{text split} modifiers add or delete rules for the |
438 \medskip The @{text split} modifiers add or delete rules for the |
411 Splitter (see also \cite{isabelle-ref}), the default is to add. |
439 Splitter (see also \cite{isabelle-ref}), the default is to add. |
412 This works only if the Simplifier method has been properly setup to |
440 This works only if the Simplifier method has been properly setup to |
413 include the Splitter (all major object logics such HOL, HOLCF, FOL, |
441 include the Splitter (all major object logics such HOL, HOLCF, FOL, |
414 ZF do this already). |
442 ZF do this already). |
415 |
443 |
|
444 \medskip The @{text cong} modifiers add or delete Simplifier |
|
445 congruence rules (see also \secref{sec:simp-rules}); the default is |
|
446 to add. |
|
447 |
416 \item @{method simp_all} is similar to @{method simp}, but acts on |
448 \item @{method simp_all} is similar to @{method simp}, but acts on |
417 all goals (backwards from the last to the first one). |
449 all goals, working backwards from the last to the first one as usual |
418 |
450 in Isabelle.\footnote{The order is irrelevant for goals without |
419 \end{description} |
451 schematic variables, so simplification might actually be performed |
420 |
452 in parallel here.} |
421 By default the Simplifier methods take local assumptions fully into |
453 |
422 account, using equational assumptions in the subsequent |
454 Chained facts are inserted into all subgoals, before the |
423 normalization process, or simplifying assumptions themselves (cf.\ |
455 simplification process starts. Further rule declarations are the |
424 @{ML asm_full_simp_tac} in \cite{isabelle-ref}). In structured |
456 same as for @{method simp}. |
425 proofs this is usually quite well behaved in practice: just the |
457 |
426 local premises of the actual goal are involved, additional facts may |
458 The proof method fails if all subgoals remain unchanged after |
427 be inserted via explicit forward-chaining (via @{command "then"}, |
459 simplification. |
428 @{command "from"}, @{command "using"} etc.). |
460 |
429 |
461 \end{description} |
430 Additional Simplifier options may be specified to tune the behavior |
462 |
431 further (mostly for unstructured scripts with many accidental local |
463 By default the Simplifier methods above take local assumptions fully |
432 facts): ``@{text "(no_asm)"}'' means assumptions are ignored |
464 into account, using equational assumptions in the subsequent |
433 completely (cf.\ @{ML simp_tac}), ``@{text "(no_asm_simp)"}'' means |
465 normalization process, or simplifying assumptions themselves. |
434 assumptions are used in the simplification of the conclusion but are |
466 Further options allow to fine-tune the behavior of the Simplifier |
435 not themselves simplified (cf.\ @{ML asm_simp_tac}), and ``@{text |
467 in this respect, corresponding to a variety of ML tactics as |
436 "(no_asm_use)"}'' means assumptions are simplified but are not used |
468 follows.\footnote{Unlike the corresponding Isar proof methods, the |
437 in the simplification of each other or the conclusion (cf.\ @{ML |
469 ML tactics do not insist in changing the goal state.} |
438 full_simp_tac}). For compatibility reasons, there is also an option |
470 |
439 ``@{text "(asm_lr)"}'', which means that an assumption is only used |
471 \begin{center} |
440 for simplifying assumptions which are to the right of it (cf.\ @{ML |
472 \small |
441 asm_lr_simp_tac}). |
473 \begin{tabular}{|l|l|p{0.3\textwidth}|} |
442 |
474 \hline |
443 The configuration option @{text "depth_limit"} limits the number of |
475 Isar method & ML tactic & behavior \\\hline |
444 recursive invocations of the simplifier during conditional |
476 |
445 rewriting. |
477 @{text "(simp (no_asm))"} & @{ML simp_tac} & assumptions are ignored |
|
478 completely \\\hline |
|
479 |
|
480 @{text "(simp (no_asm_simp))"} & @{ML asm_simp_tac} & assumptions |
|
481 are used in the simplification of the conclusion but are not |
|
482 themselves simplified \\\hline |
|
483 |
|
484 @{text "(simp (no_asm_use))"} & @{ML full_simp_tac} & assumptions |
|
485 are simplified but are not used in the simplification of each other |
|
486 or the conclusion \\\hline |
|
487 |
|
488 @{text "(simp)"} & @{ML asm_full_simp_tac} & assumptions are used in |
|
489 the simplification of the conclusion and to simplify other |
|
490 assumptions \\\hline |
|
491 |
|
492 @{text "(simp (asm_lr))"} & @{ML asm_lr_simp_tac} & compatibility |
|
493 mode: an assumption is only used for simplifying assumptions which |
|
494 are to the right of it \\\hline |
|
495 |
|
496 \end{tabular} |
|
497 \end{center} |
446 |
498 |
447 \medskip The Splitter package is usually configured to work as part |
499 \medskip The Splitter package is usually configured to work as part |
448 of the Simplifier. The effect of repeatedly applying @{ML |
500 of the Simplifier. The effect of repeatedly applying @{ML |
449 split_tac} can be simulated by ``@{text "(simp only: split: |
501 split_tac} can be simulated by ``@{text "(simp only: split: |
450 a\<^sub>1 \<dots> a\<^sub>n)"}''. There is also a separate @{text split} |
502 a\<^sub>1 \<dots> a\<^sub>n)"}''. There is also a separate @{text split} |
451 method available for single-step case splitting. |
503 method available for single-step case splitting. |
452 *} |
504 *} |
453 |
505 |
454 |
506 |
455 subsection {* Declaring rules *} |
507 subsection {* Declaring rules \label{sec:simp-rules} *} |
456 |
508 |
457 text {* |
509 text {* |
458 \begin{matharray}{rcl} |
510 \begin{matharray}{rcl} |
459 @{command_def "print_simpset"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
511 @{command_def "print_simpset"}@{text "\<^sup>*"} & : & @{text "context \<rightarrow>"} \\ |
460 @{attribute_def simp} & : & @{text attribute} \\ |
512 @{attribute_def simp} & : & @{text attribute} \\ |
461 @{attribute_def split} & : & @{text attribute} \\ |
513 @{attribute_def split} & : & @{text attribute} \\ |
|
514 @{attribute_def cong} & : & @{text attribute} \\ |
462 \end{matharray} |
515 \end{matharray} |
463 |
516 |
464 @{rail " |
517 @{rail " |
465 (@@{attribute simp} | @@{attribute split}) (() | 'add' | 'del') |
518 (@@{attribute simp} | @@{attribute split} | @@{attribute cong}) |
|
519 (() | 'add' | 'del') |
466 "} |
520 "} |
467 |
521 |
468 \begin{description} |
522 \begin{description} |
469 |
523 |
470 \item @{command "print_simpset"} prints the collection of rules |
524 \item @{command "print_simpset"} prints the collection of rules |
471 declared to the Simplifier, which is also known as ``simpset'' |
525 declared to the Simplifier, which is also known as ``simpset'' |
472 internally \cite{isabelle-ref}. |
526 internally. |
|
527 |
|
528 For historical reasons, simpsets may occur independently from the |
|
529 current context, but are conceptually dependent on it. When the |
|
530 Simplifier is invoked via one of its main entry points in the Isar |
|
531 source language (as proof method \secref{sec:simp-meth} or rule |
|
532 attribute \secref{sec:simp-meth}), its simpset is derived from the |
|
533 current proof context, and carries a back-reference to that for |
|
534 other tools that might get invoked internally (e.g.\ simplification |
|
535 procedures \secref{sec:simproc}). A mismatch of the context of the |
|
536 simpset and the context of the problem being simplified may lead to |
|
537 unexpected results. |
473 |
538 |
474 \item @{attribute simp} declares simplification rules. |
539 \item @{attribute simp} declares simplification rules. |
475 |
540 |
476 \item @{attribute split} declares case split rules. |
541 \item @{attribute split} declares case split rules. |
477 |
|
478 \end{description} |
|
479 *} |
|
480 |
|
481 |
|
482 subsection {* Congruence rules\label{sec:simp-cong} *} |
|
483 |
|
484 text {* |
|
485 \begin{matharray}{rcl} |
|
486 @{attribute_def cong} & : & @{text attribute} \\ |
|
487 \end{matharray} |
|
488 |
|
489 @{rail " |
|
490 @@{attribute cong} (() | 'add' | 'del') |
|
491 "} |
|
492 |
|
493 \begin{description} |
|
494 |
542 |
495 \item @{attribute cong} declares congruence rules to the Simplifier |
543 \item @{attribute cong} declares congruence rules to the Simplifier |
496 context. |
544 context. |
497 |
|
498 \end{description} |
|
499 |
545 |
500 Congruence rules are equalities of the form @{text [display] |
546 Congruence rules are equalities of the form @{text [display] |
501 "\<dots> \<Longrightarrow> f ?x\<^sub>1 \<dots> ?x\<^sub>n = f ?y\<^sub>1 \<dots> ?y\<^sub>n"} |
547 "\<dots> \<Longrightarrow> f ?x\<^sub>1 \<dots> ?x\<^sub>n = f ?y\<^sub>1 \<dots> ?y\<^sub>n"} |
502 |
548 |
503 This controls the simplification of the arguments of @{text f}. For |
549 This controls the simplification of the arguments of @{text f}. For |
530 @{text [display] "?p = ?q \<Longrightarrow> (if ?p then ?a else ?b) = (if ?q then ?a else ?b)"} |
576 @{text [display] "?p = ?q \<Longrightarrow> (if ?p then ?a else ?b) = (if ?q then ?a else ?b)"} |
531 |
577 |
532 Only the first argument is simplified; the others remain unchanged. |
578 Only the first argument is simplified; the others remain unchanged. |
533 This can make simplification much faster, but may require an extra |
579 This can make simplification much faster, but may require an extra |
534 case split over the condition @{text "?q"} to prove the goal. |
580 case split over the condition @{text "?q"} to prove the goal. |
535 *} |
581 |
536 |
582 \end{description} |
537 |
583 *} |
538 subsection {* Simplification procedures *} |
584 |
|
585 |
|
586 subsection {* Configuration options \label{sec:simp-config} *} |
|
587 |
|
588 text {* |
|
589 \begin{tabular}{rcll} |
|
590 @{attribute_def simp_depth_limit} & : & @{text attribute} & default @{text 100} \\ |
|
591 @{attribute_def simp_trace} & : & @{text attribute} & default @{text false} \\ |
|
592 @{attribute_def simp_trace_depth_limit} & : & @{text attribute} & default @{text 1} \\ |
|
593 @{attribute_def simp_debug} & : & @{text attribute} & default @{text false} \\ |
|
594 \end{tabular} |
|
595 \medskip |
|
596 |
|
597 These configurations options control further aspects of the Simplifier. |
|
598 See also \secref{sec:config}. |
|
599 |
|
600 \begin{description} |
|
601 |
|
602 \item @{attribute simp_depth_limit} limits the number of recursive |
|
603 invocations of the Simplifier during conditional rewriting. |
|
604 |
|
605 \item @{attribute simp_trace} makes the Simplifier output internal |
|
606 operations. This includes rewrite steps, but also bookkeeping like |
|
607 modifications of the simpset. |
|
608 |
|
609 \item @{attribute simp_trace_depth_limit} limits the effect of |
|
610 @{attribute simp_trace} to the given depth of recursive Simplifier |
|
611 invocations (when solving conditions of rewrite rules). |
|
612 |
|
613 \item @{attribute simp_debug} makes the Simplifier output some extra |
|
614 information about internal operations. This includes any attempted |
|
615 invocation of simplification procedures. |
|
616 |
|
617 \end{description} |
|
618 *} |
|
619 |
|
620 |
|
621 subsection {* Simplification procedures \label{sec:simproc} *} |
539 |
622 |
540 text {* Simplification procedures are ML functions that produce proven |
623 text {* Simplification procedures are ML functions that produce proven |
541 rewrite rules on demand. They are associated with higher-order |
624 rewrite rules on demand. They are associated with higher-order |
542 patterns that approximate the left-hand sides of equations. The |
625 patterns that approximate the left-hand sides of equations. The |
543 Simplifier first matches the current redex against one of the LHS |
626 Simplifier first matches the current redex against one of the LHS |