221 @{text "For a finite set of atoms S, there exists an atom a such that |
221 @{text "For a finite set of atoms S, there exists an atom a such that |
222 sort a = s and a \<notin> S"}. |
222 sort a = s and a \<notin> S"}. |
223 \end{proposition} |
223 \end{proposition} |
224 |
224 |
225 \noindent |
225 \noindent |
226 This property will be used later on whenever we have to chose a `fresh' atom. |
226 This property will be used later whenever we have to chose a `fresh' atom. |
227 |
227 |
228 For implementing sort-respecting permutations, we use functions of type @{typ |
228 For implementing sort-respecting permutations, we use functions of type @{typ |
229 "atom => atom"} that are bijective; are the |
229 "atom => atom"} that are bijective; are the |
230 identity on all atoms, except a finite number of them; and map |
230 identity on all atoms, except a finite number of them; and map |
231 each atom to one of the same sort. These properties can be conveniently stated |
231 each atom to one of the same sort. These properties can be conveniently stated |
518 @{text x} is a constant, but of course there is no way in |
518 @{text x} is a constant, but of course there is no way in |
519 Isabelle/HOL to restrict this definition to just these cases. |
519 Isabelle/HOL to restrict this definition to just these cases. |
520 |
520 |
521 There are a number of equivalent formulations for the equivariance |
521 There are a number of equivalent formulations for the equivariance |
522 property. For example, assuming @{text f} is a function of permutation |
522 property. For example, assuming @{text f} is a function of permutation |
523 type @{text "\<alpha> \<Rightarrow> \<beta>"}, then equivariance can also be stated as |
523 type @{text "\<alpha> \<Rightarrow> \<beta>"}, then equivariance of @{text f} can also be stated as |
524 |
524 |
525 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
525 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
526 \begin{tabular}{@ {}l} |
526 \begin{tabular}{@ {}l} |
527 @{text "\<forall>\<pi> x. \<pi> \<bullet> (f x) = f (\<pi> \<bullet> x)"} |
527 @{text "\<forall>\<pi> x. \<pi> \<bullet> (f x) = f (\<pi> \<bullet> x)"} |
528 \end{tabular}\hfill\numbered{altequivariance} |
528 \end{tabular}\hfill\numbered{altequivariance} |
631 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
631 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
632 @{text "\<pi> \<bullet> (\<forall>x. P x) \<equiv> \<pi> \<bullet> (P = (\<lambda>x. True)) = ((\<pi> \<bullet> P) = (\<lambda>x. True)) \<equiv> \<forall>x. (\<pi> \<bullet> P) x"} |
632 @{text "\<pi> \<bullet> (\<forall>x. P x) \<equiv> \<pi> \<bullet> (P = (\<lambda>x. True)) = ((\<pi> \<bullet> P) = (\<lambda>x. True)) \<equiv> \<forall>x. (\<pi> \<bullet> P) x"} |
633 \end{isabelle} |
633 \end{isabelle} |
634 |
634 |
635 \noindent |
635 \noindent |
636 and consequently, the constant @{text "\<forall>"} must be equivariant. From this |
636 which means the constant @{text "\<forall>"} must be equivariant. From this |
637 we can deduce that the existential quantifier @{text "\<exists>"} is equivariant. |
637 we can deduce that the existential quantifier @{text "\<exists>"} is equivariant. |
638 Its definition in HOL is |
638 Its definition in HOL is |
639 |
639 |
640 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
640 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
641 @{text "\<exists>x. P x \<equiv> "}~@{thm (rhs) Ex_def[no_vars]} |
641 @{text "\<exists>x. P x \<equiv> "}~@{thm (rhs) Ex_def[no_vars]} |
654 \noindent |
654 \noindent |
655 with all constants on the right-hand side being equivariant. With this kind |
655 with all constants on the right-hand side being equivariant. With this kind |
656 of reasoning we can build up a database of equivariant constants. |
656 of reasoning we can build up a database of equivariant constants. |
657 |
657 |
658 Before we proceed, let us give a justification for the equivariance principle. |
658 Before we proceed, let us give a justification for the equivariance principle. |
659 For this we will use a rewrite system consisting of a series of equalities |
659 This justification cannot be given directly inside Isabelle/HOL since we cannot |
|
660 prove any statement about HOL-terms. Instead, we will use a rewrite |
|
661 system consisting of a series of equalities |
660 |
662 |
661 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
663 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
662 @{text "\<pi> \<cdot> t = ... = t'"} |
664 @{text "\<pi> \<cdot> t = ... = t'"} |
663 \end{isabelle} |
665 \end{isabelle} |
664 |
666 |
674 four `oriented' equations. We will first give a naive version of |
676 four `oriented' equations. We will first give a naive version of |
675 this tactic, which however in some cornercases produces incorrect |
677 this tactic, which however in some cornercases produces incorrect |
676 results or does not terminate. We then give a modification in order |
678 results or does not terminate. We then give a modification in order |
677 to obtain the desired properties. |
679 to obtain the desired properties. |
678 |
680 |
679 Consider the following oriented equations |
681 Consider the following for oriented equations |
680 |
682 |
681 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
683 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
682 \begin{tabular}{@ {}lr@ {\hspace{3mm}}c@ {\hspace{3mm}}l} |
684 \begin{tabular}{@ {}lr@ {\hspace{3mm}}c@ {\hspace{3mm}}l} |
683 i) & @{text "\<pi> \<bullet> (t\<^isub>1 t\<^isub>2)"} & \rrh & @{term "(\<pi> \<bullet> t\<^isub>1) (\<pi> \<bullet> t\<^isub>2)"}\\ |
685 i) & @{text "\<pi> \<bullet> (t\<^isub>1 t\<^isub>2)"} & \rrh & @{term "(\<pi> \<bullet> t\<^isub>1) (\<pi> \<bullet> t\<^isub>2)"}\\ |
684 ii) & @{text "\<pi> \<bullet> (\<lambda>x. t)"} & \rrh & @{text "\<lambda>x. \<pi> \<bullet> (t[x := (-\<pi>) \<bullet> x])"}\\ |
686 ii) & @{text "\<pi> \<bullet> (\<lambda>x. t)"} & \rrh & @{text "\<lambda>x. \<pi> \<bullet> (t[x := (-\<pi>) \<bullet> x])"}\\ |
687 {\rm @{term "c"}\hspace{6mm}provided @{text c} is equivariant}\\ |
689 {\rm @{term "c"}\hspace{6mm}provided @{text c} is equivariant}\\ |
688 \end{tabular}\hfill\numbered{rewriteapplam} |
690 \end{tabular}\hfill\numbered{rewriteapplam} |
689 \end{isabelle} |
691 \end{isabelle} |
690 |
692 |
691 \noindent |
693 \noindent |
692 A permutation @{text \<pi>} can be pushed into applications and abstractions as follows |
694 These equation are oriented in the sense of being applied in the left-to-right |
693 |
695 direction. The first equation we established in \eqref{permutefunapp}; |
694 The first equation we established in \eqref{permutefunapp}; |
|
695 the second follows from the definition of permutations acting on functions |
696 the second follows from the definition of permutations acting on functions |
696 and the fact that HOL-terms are equal modulo beta-equivalence. |
697 and the fact that HOL-terms are equal modulo beta-equivalence. |
697 Once the permutations are pushed towards the leaves, we need the |
698 The third is a consequence of \eqref{cancel} and the fourth from |
698 following two equations |
699 Definition~\ref{equivariance}. Unfortunately, we have to be careful with |
699 |
700 the rules {\it i)} and {\it iv}) since they can lead to a loop whenever |
700 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
701 \mbox{@{text "t\<^isub>1 t\<^isub>2"}} is of the form @{text "((op \<bullet>) \<pi>') t"}.\footnote{Note we |
701 \begin{tabular}{@ {}lr@ {\hspace{3mm}}c@ {\hspace{3mm}}l} |
702 deviate here from our usual convention of writing the permutation operation infix, |
702 |
703 instead as an application.} Recall that we established in Lemma \ref{permutecompose} that the |
703 \end{tabular}\hfill\numbered{rewriteother} |
|
704 \end{isabelle} |
|
705 |
|
706 \noindent |
|
707 in order to remove permuations in front of bound variables and |
|
708 equivariant constants. Unfortunately, we have to be careful with |
|
709 the rules {\it i)} and {\it iv}): they can lead to a loop whenever |
|
710 \mbox{@{text "t\<^isub>1 t\<^isub>2"}} is of the form @{text "((op \<bullet>) \<pi>') t"}, where |
|
711 we do not write the permutation operation infix, as usual, but |
|
712 as an application. Recall that we established in Lemma \ref{permutecompose} that the |
|
713 constant @{text "(op \<bullet>)"} is equivariant and consider the infinite |
704 constant @{text "(op \<bullet>)"} is equivariant and consider the infinite |
714 reduction sequence |
705 reduction sequence |
715 |
706 |
716 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
707 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
717 \begin{tabular}{@ {}l} |
708 \begin{tabular}{@ {}l} |
723 |
714 |
724 \end{tabular} |
715 \end{tabular} |
725 \end{isabelle} |
716 \end{isabelle} |
726 |
717 |
727 \noindent |
718 \noindent |
728 The last term is again an instance of rewrite rule {\it i}), but the term |
719 where the last term is again an instance of rewrite rule {\it i}), but bigger. |
729 is bigger. To avoid this loop we need to apply our rewrite rule |
720 To avoid this loop we will apply the rewrite rule |
730 using an `outside to inside' strategy. This strategy is sufficient |
721 using an `outside to inside' strategy. This strategy is sufficient |
731 since we are only interested of rewriting terms of the form @{term |
722 since we are only interested of rewriting terms of the form @{term |
732 "\<pi> \<bullet> t"}, where an outermost permutation needs to pushed inside a term. |
723 "\<pi> \<bullet> t"}, where an outermost permutation needs to pushed inside a term. |
733 |
724 |
734 Another problem we have to avoid is that the rules {\it i)} and {\it |
725 Another problem we have to avoid is that the rules {\it i)} and {\it |
735 iii)} can `overlap'. For this note that the term @{term "\<pi> |
726 iii)} can `overlap'. For this note that the term @{term "\<pi> |
736 \<bullet>(\<lambda>x. x)"} reduces by {\it ii)} to @{term "\<lambda>x. \<pi> \<bullet> (- \<pi>) \<bullet> x"}, to |
727 \<bullet>(\<lambda>x. x)"} reduces by {\it ii)} to @{term "\<lambda>x. \<pi> \<bullet> (- \<pi>) \<bullet> x"}, to |
737 which we can apply rule {\it iii)} in order to obtain @{term |
728 which we can apply rule {\it iii)} in order to obtain @{term |
738 "\<lambda>x. x"}, as is desired---there is no free variable in the original |
729 "\<lambda>x. x"}, as is desired---since there is no free variable in the original |
739 term and so the permutation should completely vanish. However, the |
730 term. the permutation should completely vanish. However, the |
740 subterm @{text "(- \<pi>) \<bullet> x"} is also an application. Consequently, |
731 subterm @{text "(- \<pi>) \<bullet> x"} is also an application. Consequently, |
741 the term @{term "\<lambda>x. \<pi> \<bullet> (- \<pi>) \<bullet>x"} can reduce to @{text "\<lambda>x. (- (\<pi> |
732 the term @{term "\<lambda>x. \<pi> \<bullet> (- \<pi>) \<bullet>x"} can also reduce to @{text "\<lambda>x. (- (\<pi> |
742 \<bullet> \<pi>)) \<bullet> (\<pi> \<bullet> x)"} using {\it i)}. Given our strategy we cannot |
733 \<bullet> \<pi>)) \<bullet> (\<pi> \<bullet> x)"} using {\it i)}. Given our strategy, we cannot |
743 apply rule {\it iii)} anymore and even worse the measure we will |
734 apply rule {\it iii)} anymore in order to eliminate the permutation. |
744 introduce shortly increased. On the other hand, if we had started |
735 In contrast, if we start |
745 with the term @{text "\<pi> \<bullet> ((- \<pi>) \<bullet> x)"} where @{text \<pi>} and @{text |
736 with the term @{text "\<pi> \<bullet> ((- \<pi>) \<bullet> x)"} where @{text \<pi>} and @{text |
746 x} are free variables, then we \emph{do} want to apply rule {\it i)} |
737 x} are free variables, then we \emph{do} want to apply rule {\it i)} |
|
738 in order to obtain @{text "(\<pi> \<bullet> (- \<pi>)) \<bullet> (\<pi> \<bullet> x)"} |
747 and not rule {\it iii)}. The latter would eliminate @{text \<pi>} |
739 and not rule {\it iii)}. The latter would eliminate @{text \<pi>} |
748 completely. The problem is that rule {\it iii)} should only apply to |
740 completely and thus violating our correctness property. The problem is that |
749 instances where the variable is to bound; for free variables we want |
741 rule {\it iii)} should only apply to |
|
742 instances where the corresponding variable is to bound; for free variables we want |
750 to use {\it ii)}. In order to distinguish these cases we have to |
743 to use {\it ii)}. In order to distinguish these cases we have to |
751 maintain the information which variable is bound when inductively |
744 maintain the information which variable is bound when inductively |
752 taking a term `apart'. This, unfortunately, does not mesh well with |
745 taking a term `apart'. This, unfortunately, does not mesh well with |
753 the way how conversion tactics are implemented in Isabelle/HOL. |
746 the way how conversion tactics are implemented in Isabelle/HOL. |
754 |
747 |
759 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
752 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
760 @{term "unpermute \<pi> x \<equiv> (- \<pi>) \<bullet> x"} |
753 @{term "unpermute \<pi> x \<equiv> (- \<pi>) \<bullet> x"} |
761 \end{isabelle} |
754 \end{isabelle} |
762 |
755 |
763 \noindent |
756 \noindent |
764 The point is that now we can formulate the rewrite rules as follows |
757 The point is that now we can re-formulate the rewrite rules as follows |
765 |
758 |
766 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
759 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
767 \begin{tabular}{@ {}lrcl} |
760 \begin{tabular}{@ {}lrcl} |
768 i') & @{text "\<pi> \<bullet> (t\<^isub>1 t\<^isub>2)"} & \rrh & |
761 i') & @{text "\<pi> \<bullet> (t\<^isub>1 t\<^isub>2)"} & \rrh & |
769 @{term "(\<pi> \<bullet> t\<^isub>1) (\<pi> \<bullet> t\<^isub>2)"}\hspace{45mm}\mbox{}\\ |
762 @{term "(\<pi> \<bullet> t\<^isub>1) (\<pi> \<bullet> t\<^isub>2)"}\hspace{45mm}\mbox{}\\ |
774 \hspace{6mm}{\rm provided @{text c} is equivariant}\\ |
767 \hspace{6mm}{\rm provided @{text c} is equivariant}\\ |
775 \end{tabular} |
768 \end{tabular} |
776 \end{isabelle} |
769 \end{isabelle} |
777 |
770 |
778 \noindent |
771 \noindent |
779 and @{text unpermutes} are only generated in case of bound variables. |
772 where @{text unpermutes} are only generated in case of bound variables. |
780 Clearly none of these rules overlap. Moreover, given our |
773 Clearly none of these rules overlap. Moreover, given our |
781 outside-to-inside strategy, they terminate. To see this, notice that |
774 outside-to-inside strategy, applying them repeatedly must terminate. |
|
775 To see this, notice that |
782 the permutation on the right-hand side of the rewrite rules is |
776 the permutation on the right-hand side of the rewrite rules is |
783 always applied to a smaller term, provided we take the measure consisting |
777 always applied to a smaller term, provided we take the measure consisting |
784 of lexicographically ordered pairs whose first component is the size |
778 of lexicographically ordered pairs whose first component is the size |
785 of a term (counting terms of the form @{text "unpermute \<pi> x"} as |
779 of a term (counting terms of the form @{text "unpermute \<pi> x"} as |
786 leaves) and the second is the number of occurences of @{text |
780 leaves) and the second is the number of occurences of @{text |
787 "unpermute \<pi> x"} and @{text "\<pi> \<bullet> c"}. |
781 "unpermute \<pi> x"} and @{text "\<pi> \<bullet> c"}. |
788 |
782 |
789 With the rules of the conversions tactic in place, we can |
783 With the rewrite rules of the conversions tactic in place, we can |
790 establish its correctness. The property we are after is that |
784 establish its correctness. The property we are after is that |
791 for a HOL-term @{text t} whose constants are all equivariant the |
785 for a HOL-term @{text t} whose constants are all equivariant the |
792 term \mbox{@{text "\<pi> \<bullet> t"}} is equal to @{text "t'"} with @{text "t'"} |
786 term \mbox{@{text "\<pi> \<bullet> t"}} is equal to @{text "t'"} with @{text "t'"} |
793 being equal to @{text t} except that every free variable @{text x} |
787 being equal to @{text t} except that every free variable @{text x} |
794 in @{text t} is replaced by \mbox{@{text "\<pi> \<bullet> x"}}. Let us call |
788 in @{text t} is replaced by \mbox{@{text "\<pi> \<bullet> x"}}. Let us call |
795 a variable @{text x} \emph{really free}, if it is free and not occuring |
789 a variable @{text x} \emph{really free}, if it is free and not occuring |
796 in an unpermute, such as @{text "unpermute _ x"} and @{text "unpermute x _"}. |
790 in an @{term unpermute}, such as @{text "unpermute _ x"} and @{text "unpermute x _"}. |
797 We need the following technical notion characterising a \emph{@{text "\<pi>"}-proper} HOL-term |
791 We need the following technical notion characterising \emph{@{text "\<pi>"}-proper} HOL-terms |
798 |
792 |
799 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
793 \begin{isabelle}\ \ \ \ \ \ \ \ \ \ %%% |
800 \begin{tabular}{@ {}ll} |
794 \begin{tabular}{@ {}ll} |
801 $\bullet$ & variables and constants are @{text \<pi>}-proper,\\ |
795 $\bullet$ & variables and constants are @{text \<pi>}-proper,\\ |
802 $\bullet$ & @{term "unpermute \<pi> x"} is @{text \<pi>}-proper,\\ |
796 $\bullet$ & @{term "unpermute \<pi> x"} is @{text \<pi>}-proper,\\ |