ChengsongTanPhdThesis/Chapters/Finite.tex
changeset 555 aecf1ddf3541
parent 554 15d182ffbc76
child 556 c27f04bb2262
equal deleted inserted replaced
554:15d182ffbc76 555:aecf1ddf3541
   274 \subsubsection{$\textit{rdistinct}$'s Deduplicates Successfully}
   274 \subsubsection{$\textit{rdistinct}$'s Deduplicates Successfully}
   275 The $\textit{rdistinct}$ function, as its name suggests, will
   275 The $\textit{rdistinct}$ function, as its name suggests, will
   276 remove duplicates in an \emph{r}$\textit{rexp}$ list, 
   276 remove duplicates in an \emph{r}$\textit{rexp}$ list, 
   277 according to the accumulator
   277 according to the accumulator
   278 and leave only one of each different element in a list:
   278 and leave only one of each different element in a list:
   279 \begin{lemma}
   279 \begin{lemma}\label{rdistinctDoesTheJob}
   280 	The function $\textit{rdistinct}$ satisfies the following
   280 	The function $\textit{rdistinct}$ satisfies the following
   281 	properties:
   281 	properties:
   282 	\begin{itemize}
   282 	\begin{itemize}
   283 		\item
   283 		\item
   284 			If $a \in acc$ then $a \notin (\rdistinct{rs}{acc})$.
   284 			If $a \in acc$ then $a \notin (\rdistinct{rs}{acc})$.
   285 		\item
   285 		\item
   286 			If list $rs'$ is the result of $\rdistinct{rs}{acc}$,
   286 			If list $rs'$ is the result of $\rdistinct{rs}{acc}$,
   287 			All the elements in $rs'$ are unique.
   287 			then $\textit{isDistinct} \; rs'$.
       
   288 		\item
       
   289 			$\rdistinct{rs}{acc} = rs - acc$
   288 	\end{itemize}
   290 	\end{itemize}
   289 \end{lemma}
   291 \end{lemma}
       
   292 \noindent
       
   293 The predicate $\textit{isDistinct}$ is for testing
       
   294 whether a list's elements are all unique. It is defined
       
   295 recursively on the structure of a regular expression,
       
   296 and we omit the precise definition here.
   290 \begin{proof}
   297 \begin{proof}
   291 	The first part is by an induction on $rs$.
   298 	The first part is by an induction on $rs$.
   292 	The second part can be proven by using the 
   299 	The second and third part can be proven by using the 
   293 	induction rules of $\rdistinct{\_}{\_}$.
   300 	induction rules of $\rdistinct{\_}{\_}$.
   294 	
   301 	
   295 \end{proof}
   302 \end{proof}
   296 
   303 
   297 \noindent
   304 \noindent
   336 \noindent
   343 \noindent
   337 The next property gives the condition for
   344 The next property gives the condition for
   338 when $\rdistinct{\_}{\_}$ becomes an identical mapping
   345 when $\rdistinct{\_}{\_}$ becomes an identical mapping
   339 for any prefix of an input list, in other words, when can 
   346 for any prefix of an input list, in other words, when can 
   340 we ``push out" the arguments of $\rdistinct{\_}{\_}$:
   347 we ``push out" the arguments of $\rdistinct{\_}{\_}$:
   341 \begin{lemma}
   348 \begin{lemma}\label{distinctRdistinctAppend}
   342 	If $\textit{isDistinct} \; rs_1$, and $rs_1 \cap acc = \varnothing$,
   349 	If $\textit{isDistinct} \; rs_1$, and $rs_1 \cap acc = \varnothing$,
   343 	then it can be taken out and left untouched in the output:
   350 	then 
   344 	\[\textit{rdistinct}\;  (rs_1 @ rsa)\;\, acc
   351 	\[\textit{rdistinct}\;  (rs_1 @ rsa)\;\, acc
   345 	= rs_1@(\textit{rdistinct} rsa \; (acc \cup rs_1))\]
   352 	= rs_1@(\textit{rdistinct} rsa \; (acc \cup rs_1))\]
   346 \end{lemma}
   353 \end{lemma}
   347 \noindent
   354 \noindent
   348 The predicate $\textit{isDistinct}$ is for testing
   355 In other words, it can be taken out and left untouched in the output.
   349 whether a list's elements are all unique. It is defined
       
   350 recursively on the structure of a regular expression,
       
   351 and we omit the precise definition here.
       
   352 \begin{proof}
   356 \begin{proof}
   353 By an induction on $rs_1$, where $rsa$ and $acc$ are allowed to be arbitrary.
   357 By an induction on $rs_1$, where $rsa$ and $acc$ are allowed to be arbitrary.
   354 \end{proof}
   358 \end{proof}
   355 \noindent
   359 \noindent
   356 $\rdistinct{}{}$ removes any element in anywhere of a list, if it
   360 $\rdistinct{}{}$ removes any element in anywhere of a list, if it
   357 had appeared previously:
   361 had appeared previously:
   358 \begin{lemma}\label{distinctRemovesMiddle}
   362 \begin{lemma}\label{distinctRemovesMiddle}
   359 	The two properties hold if $r \in rs$:
   363 	The two properties hold if $r \in rs$:
   360 	\begin{itemize}
   364 	\begin{itemize}
   361 		\item
   365 		\item
   362 			$\rdistinct{rs}{rset} = \rdistinct{(rs @ [r])}{rset}$
   366 			$\rdistinct{rs}{rset} = \rdistinct{(rs @ [r])}{rset}$\\
   363 			and 
   367 			and\\
   364 			$\rdistinct{(ab :: rs @ [ab])}{rset'} = \rdistinct{(ab :: rs)}{rset'}$
   368 			$\rdistinct{(ab :: rs @ [ab])}{rset'} = \rdistinct{(ab :: rs)}{rset'}$
   365 		\item
   369 		\item
   366 			$\rdistinct{ (rs @ rs') }{rset} = \rdistinct{rs @ [r] @ rs'}{rset}$
   370 			$\rdistinct{ (rs @ rs') }{rset} = \rdistinct{rs @ [r] @ rs'}{rset}$\\
   367 			and
   371 			and\\
   368 			$\rdistinct{(ab :: rs @ [ab] @ rs'')}{rset'} = 
   372 			$\rdistinct{(ab :: rs @ [ab] @ rs'')}{rset'} = 
   369 			 \rdistinct{(ab :: rs @ rs'')}{rset'}$
   373 			 \rdistinct{(ab :: rs @ rs'')}{rset'}$
   370 	\end{itemize}
   374 	\end{itemize}
   371 \end{lemma}
   375 \end{lemma}
   372 \noindent
   376 \noindent
   373 \begin{proof}
   377 \begin{proof}
   374 By induction on $rs$. All other variables are allowed to be arbitrary.
   378 By induction on $rs$. All other variables are allowed to be arbitrary.
   375 The second half of the lemma requires the first half.
   379 The second half of the lemma requires the first half.
   376 Note that for each half's two sub-propositions need to be proven concurrently,
   380 Note that for each half's two sub-propositions need to be proven concurrently,
   377 so that the induction goes through.
   381 so that the induction goes through.
       
   382 \end{proof}
       
   383 
       
   384 \noindent
       
   385 This allows us to prove ``Idempotency" of $\rdistinct{}{}$ of some kind:
       
   386 \begin{lemma}\label{rdistinctConcatGeneral}
       
   387 	The following equalities involving multiple applications  of $\rdistinct{}{}$ hold:
       
   388 	\begin{itemize}
       
   389 		\item
       
   390 			$\rdistinct{(rs @ rs')}{\varnothing} = \rdistinct{((\rdistinct{rs}{\varnothing})@ rs')}{\varnothing}$
       
   391 		\item
       
   392 			$\rdistinct{(rs @ rs')}{\varnothing} = \rdistinct{(\rdistinct{rs}{\varnothing} @ rs')}{\varnothing}$
       
   393 		\item
       
   394 			If $rset' \subseteq rset$, then $\rdistinct{rs}{rset} = 
       
   395 			\rdistinct{(\rdistinct{rs}{rset'})}{rset}$. As a corollary
       
   396 			of this,
       
   397 		\item
       
   398 			$\rdistinct{(rs @ rs')}{rset} = \rdistinct{
       
   399 			(\rdistinct{rs}{\varnothing}) @ rs')}{rset}$. This
       
   400 			gives another corollary use later:
       
   401 		\item
       
   402 			If $a \in rset$, then $\rdistinct{(rs @ rs')}{rset} = \rdistinct{
       
   403 			(\rdistinct{(a :: rs)}{\varnothing} @ rs')}{rset} $,
       
   404 
       
   405 	\end{itemize}
       
   406 \end{lemma}
       
   407 \begin{proof}
       
   408 	By \ref{rdistinctDoesTheJob} and \ref{distinctRemovesMiddle}.
   378 \end{proof}
   409 \end{proof}
   379 
   410 
   380 \subsubsection{The Properties of $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS}$} 
   411 \subsubsection{The Properties of $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS}$} 
   381 We give in this subsection some properties of how $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS} $ interact with each other and with $@$, the concatenation operator.
   412 We give in this subsection some properties of how $\backslash_r$, $\backslash_{rsimp}$, $\textit{Rflts}$ and $\textit{Rsimp}_{ALTS} $ interact with each other and with $@$, the concatenation operator.
   382 These will be helpful in later closed form proofs, when
   413 These will be helpful in later closed form proofs, when
   401 		\item
   432 		\item
   402 			$\rflts \; (rs @ [\RONE]) = \rflts \; rs @ [\RONE]$
   433 			$\rflts \; (rs @ [\RONE]) = \rflts \; rs @ [\RONE]$
   403 		\item
   434 		\item
   404 			If $r \neq \RZERO$ and $\nexists rs'. r = \RALTS{rs'}$ then $\rflts \; (rs @ [r])
   435 			If $r \neq \RZERO$ and $\nexists rs'. r = \RALTS{rs'}$ then $\rflts \; (rs @ [r])
   405 			= (\rflts \; rs) @ [r]$
   436 			= (\rflts \; rs) @ [r]$
       
   437 		\item
       
   438 			If $r = \RALTS{rs}$ and $r \in rs'$ then for all $r_1 \in rs. 
       
   439 			r_1 \in \rflts \; rs'$.
       
   440 		\item
       
   441 			$\rflts \; (rs_a @ \RZERO :: rs_b) = \rflts \; (rs_a @ rs_b)$
   406 	\end{itemize}
   442 	\end{itemize}
   407 \end{lemma}
   443 \end{lemma}
   408 \noindent
   444 \noindent
   409 \begin{proof}
   445 \begin{proof}
   410 	By induction on $rs_1$ in the first part, and induction on $r$ in the second part,
   446 	By induction on $rs_1$ in the first sub-lemma, and induction on $r$ in the second part,
   411 	and induction on $rs$, $rs'$ in the third and fourth sub-lemma.
   447 	and induction on $rs$, $rs'$, $rs$, $rs'$, $rs_a$ in the third, fourth, fifth, sixth and 
   412 \end{proof}
   448 	last sub-lemma.
       
   449 \end{proof}
       
   450 
   413 \subsubsection{The $RL$ Function: Language Interpretation of $\textit{Rrexp}$s}
   451 \subsubsection{The $RL$ Function: Language Interpretation of $\textit{Rrexp}$s}
   414 Much like the definition of $L$ on plain regular expressions, one could also 
   452 Much like the definition of $L$ on plain regular expressions, one could also 
   415 define the language interpretation of $\rrexp$s.
   453 define the language interpretation of $\rrexp$s.
   416 \begin{center}
   454 \begin{center}
   417 \begin{tabular}{lcl}
   455 \begin{tabular}{lcl}
   592 \begin{proof}
   630 \begin{proof}
   593 	By an induction on the inductive cases of $\good$.
   631 	By an induction on the inductive cases of $\good$.
   594 	The lemma \ref{goodaltsNonalt} is used in the alternative
   632 	The lemma \ref{goodaltsNonalt} is used in the alternative
   595 	case where 2 or more elements are present in the list.
   633 	case where 2 or more elements are present in the list.
   596 \end{proof}
   634 \end{proof}
   597 
   635 \noindent
       
   636 Given below is a property involving $\rflts$, $\rdistinct{}{}$, $\rsimp{}$ and $\rsimp_{ALTS}$,
       
   637 which requires $\ref{good1}$ to go through smoothly.
       
   638 It says that an application of $\rsimp_{ALTS}$ can be "absorbed",
       
   639 if it its output is concatenated with a list and then applied to $\rflts$.
       
   640 \begin{lemma}\label{flattenRsimpalts}
       
   641 	$\rflts \; ( (\rsimp_{ALTS} \; 
       
   642 	(\rdistinct{(\rflts \; (\map \; \rsimp{}\; rs))}{\varnothing})) :: 
       
   643 	\map \; \rsimp{} \; rs' ) = 
       
   644 	\rflts \; ( (\rdistinct{(\rflts \; (\map \; \rsimp{}\; rs))}{\varnothing}) @ (
       
   645 	\map \; \rsimp{rs'}))$
       
   646 
       
   647 	
       
   648 \end{lemma}
       
   649 \begin{proof}
       
   650 	By \ref{good1}.
       
   651 \end{proof}
       
   652 \noindent
       
   653 
       
   654 
       
   655 
       
   656 
       
   657 
       
   658 We are also 
   598 \subsubsection{$\rsimp$ is Idempotent}
   659 \subsubsection{$\rsimp$ is Idempotent}
   599 The idempotency of $\rsimp$ is very useful in 
   660 The idempotency of $\rsimp$ is very useful in 
   600 manipulating regular expression terms into desired
   661 manipulating regular expression terms into desired
   601 forms so that key steps allowing further rewriting to closed forms
   662 forms so that key steps allowing further rewriting to closed forms
   602 are possible.
   663 are possible.
   615 
   676 
   616 On the other hand, we could repeat the same $\rsimp{}$ applications
   677 On the other hand, we could repeat the same $\rsimp{}$ applications
   617 on regular expressions as many times as we want, if we have at least
   678 on regular expressions as many times as we want, if we have at least
   618 one simplification applied to it, and apply it wherever we would like to:
   679 one simplification applied to it, and apply it wherever we would like to:
   619 \begin{corollary}\label{headOneMoreSimp}
   680 \begin{corollary}\label{headOneMoreSimp}
   620 	$\map \; \rsimp{(r :: rs)} = \map \; \rsimp{} \; (\rsimp{r} :: rs)$
   681 	The following properties hold, directly from \ref{rsimpIdem}:
       
   682 
       
   683 	\begin{itemize}
       
   684 		\item
       
   685 			$\map \; \rsimp{(r :: rs)} = \map \; \rsimp{} \; (\rsimp{r} :: rs)$
       
   686 		\item
       
   687 			$\rsimp{(\RALTS{rs})} = \rsimp{(\RALTS{\map \; \rsimp{} \; rs})}$
       
   688 	\end{itemize}
   621 \end{corollary}
   689 \end{corollary}
   622 \noindent
   690 \noindent
   623 This will be useful in later closed form proof's rewriting steps.
   691 This will be useful in later closed form proof's rewriting steps.
   624 Similarly, we point out the following useful facts below:
   692 Similarly, we point out the following useful facts below:
   625 \begin{lemma}
   693 \begin{lemma}
   643 closed forms.
   711 closed forms.
   644 Now presented are a few equivalent terms under $\rsimp{}$.
   712 Now presented are a few equivalent terms under $\rsimp{}$.
   645 We use $r_1 \sequal r_2 $ here to denote $\rsimp{r_1} = \rsimp{r_2}$.
   713 We use $r_1 \sequal r_2 $ here to denote $\rsimp{r_1} = \rsimp{r_2}$.
   646 \begin{lemma}
   714 \begin{lemma}
   647 \begin{itemize}
   715 \begin{itemize}
       
   716 	The following equivalence hold:
   648 	\item
   717 	\item
   649 		$\rsimpalts \; (\RZERO :: rs) \sequal \rsimpalts\; rs$
   718 		$\rsimpalts \; (\RZERO :: rs) \sequal \rsimpalts\; rs$
   650 	\item
   719 	\item
   651 		$\rsimpalts \; rs \sequal \rsimpalts (\map \; \rsimp{} \; rs)$
   720 		$\rsimpalts \; rs \sequal \rsimpalts (\map \; \rsimp{} \; rs)$
   652 	\item
   721 	\item
   653 		$\RALTS{\RALTS{rs}} \sequal \RALTS{rs}$
   722 		$\RALTS{\RALTS{rs}} \sequal \RALTS{rs}$
       
   723 	\item
       
   724 		$\sum ((\sum rs_a) :: rs_b) \sequal \sum rs_a @ rs_b$
       
   725 	\item
       
   726 		$\RALTS{rs} = \RALTS{\map \; \rsimp{} \; rs}$
   654 \end{itemize}
   727 \end{itemize}
   655 \end{lemma}
   728 \end{lemma}
       
   729 \begin{proof}
       
   730 	By induction on the lists involved.
       
   731 \end{proof}
       
   732 \noindent
       
   733 Similarly,
       
   734 we introduce the equality for $\sum$ when certain child regular expressions
       
   735 are $\sum$ themselves:
       
   736 \begin{lemma}\label{simpFlatten3}
       
   737 	One can flatten the inside $\sum$ of a $\sum$ if it is being 
       
   738 	simplified. Concretely,
       
   739 	\begin{itemize}
       
   740 		\item
       
   741 			If for all $r \in rs, rs', rs''$, we have $\good \; r $
       
   742 			or $r = \RZERO$, then $\sum (rs' @ rs @ rs'') \sequal 
       
   743 			\sum (rs' @ [\sum rs] @ rs'')$ holds. As a corollary,
       
   744 		\item
       
   745 			$\sum (rs' @ [\sum rs] @ rs'') \sequal \sum (rs' @ rs @ rs'')$
       
   746 	\end{itemize}
       
   747 \end{lemma}
       
   748 \begin{proof}
       
   749 	By rewriting steps involving the use of \ref{test} and \ref{rdistinctConcatGeneral}.
       
   750 	The second sub-lemma is a corollary of the previous.
       
   751 \end{proof}
       
   752 %Rewriting steps not put in--too long and complicated-------------------------------
       
   753 \begin{comment}
       
   754 	\begin{center}
       
   755 		$\rsimp{\sum (rs' @ rs @ rs'')}  \stackrel{def of bsimp}{=}$  \\
       
   756 		$\rsimpalts \; (\rdistinct{\rflts \; ((\map \; \rsimp{}\; rs') @ (\map \; \rsimp{} \; rs ) @ (\map \; \rsimp{} \; rs''))}{\varnothing})$ \\
       
   757 		$\stackrel{by \ref{test}}{=} 
       
   758 		\rsimpalts \; (\rdistinct{(\rflts \; rs' @ \rflts \; rs @ \rflts \; rs'')}{
       
   759 		\varnothing})$\\
       
   760 		$\stackrel{by \ref{rdistinctConcatGeneral}}{=}
       
   761 		\rsimpalts \; (\rdistinct{\rflts \; rs'}{\varnothing} @ \rdistinct{(
       
   762 		\rflts\; rs @ \rflts \; rs'')}{\rflts \; rs'})$\\
       
   763 		
       
   764 	\end{center}
       
   765 \end{comment}
       
   766 %Rewriting steps not put in--too long and complicated-------------------------------
   656 \noindent
   767 \noindent
   657 We need more equalities like the above to enable a closed form,
   768 We need more equalities like the above to enable a closed form,
   658 but to proceed we need to introduce two rewrite relations,
   769 but to proceed we need to introduce two rewrite relations,
   659 to make things smoother.
   770 to make things smoother.
   660 \subsubsection{The rewrite relation $\hrewrite$ and $\grewrite$}
   771 \subsubsection{The rewrite relation $\hrewrite$, $\frewrite$ and $\grewrite$}
   661 Insired by the success we had in the correctness proof 
   772 Insired by the success we had in the correctness proof 
   662 in \ref{Bitcoded2}, where we invented
   773 in \ref{Bitcoded2}, where we invented
   663 a term rewriting system to capture the similarity between terms
   774 a term rewriting system to capture the similarity between terms,
   664 and prove equivalence, we follow suit here defining simplification
   775 we follow suit here defining simplification
   665 steps as rewriting steps.
   776 steps as rewriting steps. This allows capturing 
       
   777 similarities between terms that would be otherwise
       
   778 hard to express.
       
   779 
       
   780 We use $\hrewrite$ for one-step atomic rewrite of regular expression simplification, 
       
   781 $\frewrite$ for rewrite of list of regular expressions that 
       
   782 include all operations carried out in $\rflts$, and $\grewrite$ for
       
   783 rewriting a list of regular expressions possible in both $\rflts$ and $\rdistinct{}{}$.
       
   784 Their reflexive transitive closures are used to denote zero or many steps,
       
   785 as was the case in the previous chapter.
   666 The presentation will be more concise than that in \ref{Bitcoded2}.
   786 The presentation will be more concise than that in \ref{Bitcoded2}.
   667 To differentiate between the rewriting steps for annotated regular expressions
   787 To differentiate between the rewriting steps for annotated regular expressions
   668 and $\rrexp$s, we add characters $h$ and $g$ below the squig arrow symbol
   788 and $\rrexp$s, we add characters $h$ and $g$ below the squig arrow symbol
   669 to mean atomic simplification transitions 
   789 to mean atomic simplification transitions 
   670 of $\rrexp$s and $\rrexp$ lists, respectively.
   790 of $\rrexp$s and $\rrexp$ lists, respectively.
   671 
   791 
   672 \begin{center}
   792 
   673 
   793 
   674 List of 1-step rewrite rules for regular expressions simplification without bitcodes:
   794 	List of one-step rewrite rules for $\rrexp$ ($\hrewrite$):
   675 \begin{figure}
   795 
   676 \caption{the "h-rewrite" rules}
   796 
   677 \[
   797 \begin{center}
   678 r_1 \cdot \ZERO \rightarrow_h \ZERO \]
   798 \begin{mathpar}
   679 
   799 	\inferrule[RSEQ0L]{}{\RZERO \cdot r_2 \hrewrite \RZERO\\}
   680 \[
   800 
   681 \ZERO \cdot r_2 \rightarrow \ZERO 
   801 	\inferrule[RSEQ0R]{}{r_1 \cdot \RZERO \hrewrite \RZERO\\}
   682 \]
   802 
   683 \end{figure}
   803 	\inferrule[RSEQ1]{}{(\RONE \cdot r) \hrewrite  r\\}\\	
       
   804 	
       
   805 	\inferrule[RSEQL]{ r_1 \hrewrite r_2}{r_1 \cdot r_3 \hrewrite r_2 \cdot r_3\\}
       
   806 
       
   807 	\inferrule[RSEQR]{ r_3 \hrewrite r_4}{r_1 \cdot r_3 \hrewrite r_1 \cdot r_4\\}\\
       
   808 
       
   809 	\inferrule[RALTSChild]{r \hrewrite r'}{\sum (rs_1 @ [r] @ rs_2) \hrewrite \sum (rs_1 @ [r'] @ rs_2)\\}
       
   810 
       
   811 	\inferrule[RALTS0]{}{\sum (rs_a @ [\RZERO] @ rs_b) \hrewrite \sum (rs_a @ rs_b)}
       
   812 
       
   813 	\inferrule[RALTSNested]{}{\sum (rs_a @ [\sum rs_1] @ rs_b) \hrewrite \sum (rs_a @ rs_1 @ rs_b)}
       
   814 
       
   815 	\inferrule[RALTSNil]{}{ \sum [] \hrewrite \RZERO\\}
       
   816 
       
   817 	\inferrule[RALTSSingle]{}{ \sum [r] \hrewrite  r\\}	
       
   818 
       
   819 	\inferrule[RALTSDelete]{\\ r_1 = r_2}{\sum rs_a @ [r_1] @ rs_b @ [r_2] @ rsc \hrewrite \sum rs_a @ [r_1] @ rs_b @ rs_c}
       
   820 
       
   821 \end{mathpar}
       
   822 \end{center}
       
   823 
       
   824 %frewrite
       
   825 	List of one-step rewrite rules for flattening 
       
   826 	a list of  regular expressions($\frewrite$):
       
   827 \begin{center}
       
   828 \begin{mathpar}
       
   829 	\inferrule{}{\RZERO :: rs \frewrite rs \\}
       
   830 
       
   831 	\inferrule{}{(\sum rs) :: rs_a \frewrite rs @ rs_a \\}
       
   832 
       
   833 	\inferrule{rs_1 \frewrite rs_2}{r :: rs_1 \frewrite r :: rs_2}
       
   834 \end{mathpar}
       
   835 \end{center}
       
   836 
       
   837 	Lists of one-step rewrite rules for flattening and de-duplicating
       
   838 	a list of regular expressions ($\grewrite$):
       
   839 \begin{center}
       
   840 \begin{mathpar}
       
   841 	\inferrule{}{\RZERO :: rs \frewrite rs \\}
       
   842 
       
   843 	\inferrule{}{(\sum rs) :: rs_a \frewrite rs @ rs_a \\}
       
   844 
       
   845 	\inferrule{rs_1 \frewrite rs_2}{r :: rs_1 \frewrite r :: rs_2}
       
   846 
       
   847 	\inferrule[dB]{}{rs_a @ [a] @ rs_b @[a] @ rs_c \grewrite rs_a @ [a] @ rsb @ rsc}
       
   848 \end{mathpar}
       
   849 \end{center}
       
   850 
       
   851 \noindent
       
   852 The reason why we take the trouble of defining 
       
   853 two separate list rewriting definitions $\frewrite$ and $\grewrite$
       
   854 is that sometimes $\grewrites$ is slightly too powerful
       
   855 that it renders certain equivalence to break after derivative:
       
   856 
       
   857 $\rsimp{(\rsimpalts \; (\map \; (\_ \backslash x) \; (\rdistinct{(\rflts \; (\map \; (\rsimp{} \; \circ \; (\lambda r. \rderssimp{r}{xs}))))}{\varnothing})))} \neq 
       
   858 	\rsimp{(\rsimpalts \; (\rdistinct{(\map \; (\_ \backslash x) \; (\rflts \; (\map \; (\rsimp{} \; \circ \; (\lambda r. \rderssimp{r}{xs})))) ) }{\varnothing})} $
       
   859 
       
   860 
       
   861 
   684 And we define an "grewrite" relation that works on lists:
   862 And we define an "grewrite" relation that works on lists:
   685 \begin{center}
   863 \begin{center}
   686 \begin{tabular}{lcl}
   864 \begin{tabular}{lcl}
   687 $ \ZERO :: rs$ & $\rightarrow_g$ & $rs$
   865 $ \ZERO :: rs$ & $\rightarrow_g$ & $rs$
   688 \end{tabular}
   866 \end{tabular}