<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[12pt,reqno]{article}

\usepackage[usenames]{color}

\usepackage[colorlinks=true,
linkcolor=webgreen,
filecolor=webbrown,
citecolor=webgreen]{hyperref}

\definecolor{webgreen}{rgb}{0,.5,0}
\definecolor{webbrown}{rgb}{.6,0,0}

\usepackage{color}
\usepackage{fullpage}
\usepackage{float}

\usepackage{psfig}
\usepackage{graphics,amsmath,amssymb}
\usepackage{amsthm}
\usepackage{amsfonts}
\usepackage{latexsym}
\usepackage{epsf}
\usepackage{graphicx}

\usepackage{bm}
\usepackage{amscd}
\usepackage{xcolor}
\usepackage{array}
\usepackage{enumerate}
\usepackage{fullpage}
\usepackage{float}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{multicol}
\usepackage{verbatim}

\setlength{\textwidth}{6.5in}
\setlength{\oddsidemargin}{.1in}
\setlength{\evensidemargin}{.1in}
\setlength{\topmargin}{-.5in}
\setlength{\textheight}{8.9in}

\newcommand{\seqnum}[1]{\href{http://oeis.org/#1}{\underline{#1}}}



% Macros
\renewcommand{\div}{/}
\renewcommand{\bar}{\overline}
\DeclareMathOperator{\sign}{sgn}
\newcommand{\R}{{\mathbb R}}
\newcommand{\N}{{\mathbb N}}
\newcommand{\Q}{{\mathbb Q}}
\newcommand{\Alphabet}{\mathcal{A}}
\newcommand{\Pref}{{\rm Pref}}
\newcommand{\Suff}{{\rm Suff}}
\newcommand{\Card}{{\rm Card}}
\newcommand{\pal}{{\rm Pal}}
\newcommand{\ipal}{{\psi}}
\newcommand{\pref}{{\rm Pref}}
\newcommand{\bw}{\mathbf{w}}
\newcommand{\bx}{\mathbf{x}}
\newcommand{\by}{\mathbf{y}}
\newcommand{\br}{\mathbf{r}}
\newcommand{\bfi}{\mathbf{f}}
\newcommand{\bd}{\mathbf{d}}
\newcommand{\bTheta}{{\bm \Theta}}
\newcommand{\bu}{\mathbf{u}}
\newcommand{\bs}{\mathbf{s}}
\newcommand{\bv}{\mathbf{v}}
\newcommand{\A}{{\mathcal A}}
\newcommand{\V}{{\vartheta}}
\newcommand{\bV}{{\bm \vartheta}}
\newcommand{\id}{\rm Id}
\newcommand{\h}{\mathcal H}
\renewcommand{\a}{{\textsc a}}
\newcommand{\e}{{\textsc e}}
\renewcommand{\o}{{\textsc o}}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}
\newcommand{\alp}[1]{{\rm alph}(#1)}
\newcommand{\Type}{\theta}
\newcommand{\Transducer}{{\mathcal T}}
\newcommand{\underdot}{\d}
\newcommand{\ord}{\mathrm{ord}}
\newsavebox{\gauche}
\sbox{\gauche}{\setlength{\unitlength}{1mm}
                  \begin{picture}(1.5,3)(0,0)
                  \thicklines
                  {\put(0,-.5){\line(1,0){1}}}%
                  {\put(0.15,-.64){\line(0,3){3.48}}}%
                  {\put(0,2.7){\line(1,0){1}}}%
                  \end{picture}}
\newcommand{\lbr}{\usebox{\gauche}}
\newsavebox{\droite}
\sbox{\droite}{\setlength{\unitlength}{1mm}
                  \begin{picture}(1,3)(0,0)
                  \thicklines
                  {\put(0,-.5){\line(-1,0){1}}}%
                  {\put(-0.16,-.64){\line(0,3){3.48}}}%
                  {\put(0,2.7){\line(-1,0){1}}}%
                  \end{picture}}
\newcommand{\rbr}{\usebox{\droite}}
\newcommand\Class[1]{\hspace{-1pt}\lbr#1\rbr\hspace{-1pt}}
\renewcommand{\bf}{\textbf}



\begin{document}

\begin{center}
\epsfxsize=4in
\leavevmode\epsffile{logo129.eps}
\end{center}

\theoremstyle{plain}
\newtheorem{theorem}{Theorem}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{conjecture}[theorem]{Conjecture}

\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}


\begin{center}
\vskip 1cm{\LARGE\bf{On Generalized Pseudostandard Words \\
\vskip .13in
Over Binary Alphabets
}} \vskip 1cm
Alexandre Blondin Mass\'e\\
Laboratoire d'informatique formelle\\
Universit\'e du Qu\'ebec \`a Chicoutimi\\
Chicoutimi, QC, G7H 2B1  \\
Canada\\
\href{mailto:ablondin@uqac.ca}{\tt ablondin@uqac.ca}\\
\ \\
Genevi\`eve Paquin\\
D\'epartement de math\'ematiques\\
C\'egep de Saint-J\'er\^ome\\
Saint-J\'er\^ome, QC J7Z 4V2\\
Canada \\
\href{mailto:gpaquin@cstj.qc.ca}{\tt gpaquin@cstj.qc.ca}\\
\ \\
Hugo Tremblay\\
Laboratoire de combinatoire et d'informatique math\'ematique\\
Universit\'e du Qu\'ebec \`a Montr\'eal\\
Montr\'eal, QC H3C 3P8\\
Canada \\
\href{mailto:tremblay.hugo.5@courrier.uqam.ca}{\tt tremblay.hugo.5@courrier.uqam.ca}\\
\ \\
Laurent Vuillon\\
Laboratoire de math\'ematiques\\
Universit\'e de Savoie\\
Le-Bourget-du-Lac 73376\\
France \\
\href{mailto:laurent.vuillon@univ-savoie.fr}{\tt laurent.vuillon@univ-savoie.fr}\\
\end{center}

\vskip .2 in

\begin{abstract}
In this paper, we study generalized pseudostandard words over a two-letter alphabet, which extend the classes of standard Sturmian, standard episturmian and pseudostandard words, allowing different involutory antimorphisms instead of the usual palindromic closure or a fixed involutory antimorphism. We first discuss about \emph{pseudoperiods}, a useful tool for describing words obtained by iterated pseudopalindromic closure. Then, we introduce the concept of {\it normalized} directive bi-sequence $(\Theta, w)$ of a generalized 
pseudostandard word, that is the one that exactly describes all the pseudopalindromic prefixes of it. We show that a directive bi-sequence is normalized if and only if its set of factors does not intersect a finite set of forbidden ones. Moreover, we provide a construction to normalize any directive bi-sequence. Next, we present an explicit formula, generalizing the one for the standard episturmian words introduced by Justin, that computes recursively the next prefix of a generalized pseudostandard word in term of the previous one. Finally, we focus on generalized pseudostandard words having complexity $2n$, also called \emph{Rote words}. More precisely, we prove that the normalized bi-sequences describing Rote words are completely characterized by their factors of length $2$.
\end{abstract}

\section{Introduction}

The \emph{Sturmian words} form a well-known class of infinite words over a two-letter alphabet that occurs in many different fields, for instance in astronomy,  symbolic dynamics, number theory, discrete geometry, crystallography, and of course, in combinatorics on words (see \cite[Chapter 2]{Lothaire2002}).  
{These words have many equivalent characterizations whose usefulness depends on the context.}
In discrete geometry, 
they are exactly the words that code the discrete approximations of lines with irrational slopes, using horizontal and diagonal moves. In symbolic dynamics, Sturmian words are obtained from two-intervals exchange transformations. They are also known as the balanced aperiodic infinite words over a two-letter alphabet. A remarkable subclass of the Sturmian words is the class of the so-called \emph{standard Sturmian words}. To each Sturmian word corresponds a standard Sturmian one having the same language, i.e., the same set of factors. Thus, standard Sturmian words are, in a sense, representatives of all Sturmian words having the same language. Geometrically, they correspond to discrete lines starting at the origin. All the words in this subclass can be obtained by a construction called iterated palindromic closure \cite{deLuca1997}. This operation establishes a bijection between standard Sturmian words and {non-eventually} constant infinite words over a binary alphabet. It can also be generalized for an alphabet with more than two letters and yields the standard episturmian words. 

Another generalization of the standard episturmian words was introduced by de Luca and De Luca in \cite{deLucaDeLuca2006}, where the authors considered pseudopalindromes instead of palindromes. In the paper, they first define the notion of $\V$-palindrome 
(called \emph{pseudopalindrome} when $\V$ is not mentioned), which is a word fixed by an involutory antimorphism $\V$. Moreover, they introduce the pseudopalindromic closure, which extends the usual palindromic closure to pseudopalindromes.
These ideas lead one to naturally define words obtained by \emph{iterated pseudopalindromic closure}. In particular, they consider a generalization of Sturmian and episturmian words: the \emph{pseudostandard words}. Finally, toward the end of their paper, they define an even more general class of infinite words, called \emph{generalized pseudostandard words}, these words being obtained by a directive bi-sequence $(\Theta, w)$, where $\Theta$ is a sequence of involutory antimorphisms and $w$ is an infinite 
word. In that case, the type of pseudopalindromic closure changes at each step, applying the $n$th involutory antimorphism for the $n$th pseudopalindromic closure, after having added the $n$th letter of the word $w$. Different generalizations of standard episturmian words have been introduced and studied (see for instance \cite{BuccideLucaDeLucaZamboni20082,BuccideLucaDeLucaZamboni2008,deLucaDeLuca2006}), but not much is known about generalized pseudostandard words except for the remarkable fact that the famous Thue-Morse word falls within this class of words (see \cite{deLucaDeLuca2006}).

In order to study generalized pseudostandard words, it is natural to search for an efficient way to construct it from its directive bi-sequence.  In \cite{Justin2005}, Justin gives a formula that 
allows one to compute in linear time a prefix of a standard Sturmian (resp., episturmian) word, using its directive sequence, that is the sequence on which the iterated palindromic closure is performed, in order to construct the standard Sturmian (resp., episturmian) word. 
The main aim of this paper is to extend Justin's formula to generalized pseudostandard words on binary alphabets. In particular, this formula might be useful in the study of generalized pseudostandard word by mean of computer exploration.

The next sections are organized as follows. As usual, we first introduce the definitions and notation used in the next sections. We recall iterated palindromic and pseudopalindromic closure operators as well as the main topic of this paper: the generalized pseudostandard words. Section \ref{S:pseudoperiodicity} is devoted to the structure of words having pseudoperiods (i.e. words such that $w\Class{i} = \sigma(w\Class{i + p})$ for some permutation $\sigma$ and some positive integer $p$). These results turn out to be very useful for studying generalized pseudostandard words. Next, we introduce in Section \ref{S:normalized} the notion of normalized directive bi-sequence. 
Those normalized bi-sequences are representatives of all directive bi-sequences describing the same word, but having the special additional property that the successive prefixes obtained by 
pseudopalindromic closure coincide with all pseudopalindromic prefixes of the corresponding generalized pseudostandard word. We first prove the existence of such a normalized bi-sequence and we describe exactly the forbidden factors for a bi-sequence not to be normalized. Then we provide a simple way of constructing a normalized bi-sequence from any directive bi-sequence. In Section \ref{S:justin}, we present a generalization of Justin's formula for generalized pseudostandard words whose proof depends strongly on the normalized form. Section \ref{S:rote} is devoted to the particular case of Rote words.

Notice that this paper is an complete and improved version of two conference communications. The content of Sections \ref{S:normalized} and \ref{S:justin} was presented in Amiens (France) during the 13th Mons Theoretical Computer Science Days \cite{BlondinMassePaquinVuillon2010} (JM 2010), while the content of Section \ref{S:rote} was the main subject of a communication during the conference in honor of the 20th Anniversary of the Laboratoire de combinatoire et d'informatique mathÃ©matique \cite{lacim2010} (LaCIM 2010).

\section{Preliminaries}

We introduce the definitions and notation in the next sections.

\subsection{Words}

We first recall notions on words (for more details, see for instance \cite{Lothaire2002}).

An {\it alphabet} $\A$ is a finite set of symbols called {\it letters}. A {\it word over $\A$} is a sequence of letters from $\A$. The {\it empty word}  $\varepsilon$ is the empty sequence. Equipped with the concatenation operation, the set $\A^*$ of {\it finite words} over $\A$ is a free monoid with neutral element $\varepsilon$ and set of generators $\A$, and $\A^+=\A^* \setminus \varepsilon$. We denote by $\A^\omega$ the set of {\it (right-) infinite words} over $\A$.  The set $\A^\infty$ is defined as the set of finite and infinite words: $\A^\infty= \A^* \cup \A^\omega$. Note that depending on the context, an infinite word is sometimes also called a {\it sequence}. For sake of clarity, variables denoting infinite words appear in bold.

If, for some words $u, s \in \A^\infty$, $v, p \in \A^*$, $u=pvs$, then $v$ is a {\it factor} of $u$, $p$ is a {\it prefix} of $u$ and $s$ is a {\it suffix} of $u$. %If $v\neq u$ (resp. $p\neq u$ and $s \neq u$), $v$ is called a {\it proper factor} (resp. {\it proper prefix} and {\it proper suffix}).
The {\it set of factors} of the word $u$ is denoted by $F(u)$. For $u=vw$, with $v\in \A^*$ and $w \in \A^\infty$, $v^{-1}u$ denotes the word $w$ and $uw^{-1}$ denotes the word $v$. Negative powers are naturally extended by $v^{-n}u = (v^n)^{-1}u$ and $u(w^n)^{-1}$.

As usual, for a finite word $u$ and a positive integer $n$, the \emph{$n$th power of $u$}, denoted by $u^n$, is the word $\varepsilon$ if $n=0$; otherwise $u^n=u^{n-1}u$.
If $u\neq \varepsilon$, $u^\omega$ denotes the infinite word obtained by infinitely repeating $u$. {Given a finite or an infinite word $u$, we denote by $u\Class{i}$ the $i$th letter of $u$ and by $u\Class{i\ldots j}$ the word $u\Class{i}u\Class{i+1}\cdots u\Class{j}$.}
Given a nonempty finite word $u=u\Class{1}u\Class{2}\cdots u\Class{n}$, the {\it length} $|u|$ of $u$ is the integer $n$. One has $|\varepsilon|=0$. The number of occurrences of the letter $a$ in the word $u$ is denoted by $|u|_a$.  If $|u|_a=0$, then $u$ is called an {\it $a$-free word}.  

The {\it reversal} of the finite word $u=u\Class{1}u\Class{2}\cdots u\Class{n}$, also called the {\it mirror image}, is {$R(u)$}$= u\Class{n}u\Class{n-1}\cdots u\Class{1}$ and if $u=$ {$R(u)$}, then $u$ is called a {\it palindrome}. The {\it right-palindromic closure} ({\it palindromic closure}, for short) of the finite word $u$, denoted by $u^{(+)}$, is defined by $u^{(+)}=u\cdot${$R(p)$}, with $u=ps$ and $s$ is the longest palindromic suffix of $u$.  In other words, it is the shortest palindromic word having $u$ as prefix.

Over a two-letter alphabet $\{0,1\}$, there is a usual length preserving morphism, the {\it complementation}, defined by $\overline 0 =1$ and $\overline 1= 0$, which extends to words (finite or infinite). For instance, the complement of $u=u\Class{1}u\Class{2}\cdots u\Class{n}$ is the word $\overline u=\overline{u\Class{1}} \, \overline{u\Class{2}}\cdots \overline{u\Class{n}}$. 

Sturmian words may be defined in many equivalent ways (see Chapter 2 in \cite{Lothaire2002} for more details). For instance, they are the non-ultimately periodic infinite words over a two-letter alphabet  that have minimal complexity, that is the number of distinct factors of  length $n$  is $(n+1)${, for each positive integer $n$}. They are also the set of non-ultimately periodic binary balanced words. Recall that a {word $w$ over $\A$} is {\it balanced} if for all factors $f, f'$ having same length, and for all letters $a \in \A$, one has $\left | |f|_a-|f'|_a\right | \leq 1$.

The Sturmian words are {also infinite words that describe discrete approximations of irrational slopes} (see \cite{Lothaire2002}).  {More precisely, an infinite word is \emph{Sturmian} if and only if it is equal to one of the two infinite words ${ s}_{\alpha, \rho}, { s'}_{\alpha, \rho} \in \{a,b\}^\omega$, defined by}
$${ s}_{\alpha, \rho}\Class{n}= \begin{cases}
  a, &amp; \mbox{if $\lfloor \alpha(n+1) +\rho  \rfloor = \lfloor \alpha n +\rho \rfloor$;} \\
  b, &amp; \mbox{otherwise}.
\end{cases}$$
and
$${ s'}_{\alpha, \rho}\Class{n}= \begin{cases}
  a, &amp; \mbox{if $\lceil \alpha(n+1) +\rho  \rceil = \lceil \alpha n +\rho \rceil$;} \\
  b, &amp; \mbox{otherwise},
\end{cases}$$
where $\alpha, \rho \in \R$, $0\leq \alpha &lt;1$ and $\alpha$ irrational.

The parameters $\rho$ and $\alpha$ correspond respectively to the \emph{intercept} and the \emph{slope} of the line approximated by the word $s$. A Sturmian word is called {\it standard} (or {\it characteristic}) if {$\rho=\alpha$}.

%%%%%
\subsection{Pseudopalindromic closure}

Given a finite word $w$, let us denote by $\ipal(w)$ the word obtained by iterating palindromic closure over $w$: $\ipal(\varepsilon) = \varepsilon$ and $\ipal(wa) = (\ipal(w)a)^{(+)}$, for all letters $a$.

Note that the $\ipal$ operator is sometimes denoted by $\pal$ in the works of Justin and Jamet et al (see for instance \cite{JametPaquinRichommeVuillon2010, Justin2005}). By definition of iterated palindromic closure $\ipal$, for any finite word $w$ and letter $a$, $\ipal(w)$ is a prefix of $\ipal(wa)$. 
Thus, one can extend the iterated palindromic closure to any infinite word $\bw = (a\Class{n})_{n \geq 1}$ as follows:  $$\ipal(\bw) = \lim_{n \to \infty} \ipal(a\Class{1 \ldots n}).$$
We say that the word $w$ {\it directs} the word $\ipal( w)$. Also, we know from \cite{deLuca1997} that 
$\ipal$ {gives} a bijection between the set {of infinite words over $\{a,b\}$ not of the form $ua^\omega$ or $ub^\omega$, for some $u\in \{a,b\}^*$, and the set of standard Sturmian words over $\{a,b\}$.} The word $\bw$ is then  called the {\it directive sequence}  of the standard Sturmian word $\ipal(\bw)$. Note that words of the form $\ipal(ua^\omega)$ are periodic (see \cite{DroubayJustinPirillo2001}).

The $\ipal$ operator is also well-defined over a $k$-letter alphabet, with $k\geq 3$. In this case, it is known \cite{DroubayJustinPirillo2001} that $\ipal(\A^\omega)$ is exactly the set of {\it standard episturmian words}, a generalization over a $k$-letter alphabet, $k\geq 3$, of the family of standard Sturmian words (for more details, see \cite{GlenJustin2009}). 

\begin{example}\label{e:fibo} The {\it infinite Fibonacci word} 
$${ f}=\ipal((01)^\omega)=\underline 0 \, \underline 10 \underline 010 \underline 10010\underline 01010010\underline 1\cdots$$
is a standard Sturmian word directed by the word $(01)^\omega$.  Indeed:
\begin{center}\begin{tabular}{*{2}{&gt;{$}r&lt;{$}&gt;{$}c&lt;{$}&gt;{$}l&lt;{$}}}
\ipal(0)&amp;=&amp;\underline 0&amp;\ipal(010)&amp;=&amp;(\ipal(01)0)^{(+)}=010\underline 010\\
\ipal(01)&amp;=&amp;(\ipal(0)1)^{(+)}=0\underline 10&amp;\ipal(0101)&amp;=&amp;(\ipal(010)1)^{(+)}=010010\underline 10010\\
&amp;\ldots&amp;&amp;&amp;\ldots&amp;\\
\end{tabular}\end{center}
\end{example}

Notice that in the previous example, all the images are palindromes. 

\begin{example} The infinite word $01201002\cdots$ directs the standard episturmian word 
$$\bw=\ipal(01201002\cdots)=\underline 0 \, \underline 10 \underline 2010 \underline 0102010 \underline 1 020100102010 \underline 0\cdots .$$
\end{example}

As usual, we have underlined in the previous examples the letters of $w$ corresponding to the directive words, for sake of clarity. 

When generating words by iterated palindromic closure, it is useful to have an efficient way to compute the successive prefixes. In that perspective, it is too costly to compute the longest palindromic suffix every time a letter is added in the directive sequence. The key of this problem is found in a formula introduced by Justin \cite{Justin2005}.

\begin{proposition}  {\rm \cite{Justin2005} }\label{P:justin}  Let $w \in \A^*,  a \in \A$. If $w$ is not $a$-free, then we write $w=v_1av_2$ with $v_2$ $a$-free and we have
$$\ipal (wa)= \begin{cases}
  \ipal(w)a\ipal(w),               &amp; \mbox{if $w$ is $a$-free;} \\
  \ipal(w)\ipal(v_1)^{-1}\ipal(w), &amp; \mbox{otherwise.}
\end{cases}
$$
\end{proposition}

\begin{algorithm}
\caption{Computation of a word by iterated palindromic closure.} \label{A:ipc}
\centering
\begin{algorithmic}[1] 
\Function{IteratedPalindromicClosure}{$w$}
  \State \emph{Input:} Any word $w$
  \State \emph{Output:} The iterated palindromic closure $\psi(w)$ of $w$
  \State $n \leftarrow |w|$, $u \leftarrow \varepsilon$
  \State $\Call{HasOccurred}{$a$} \leftarrow \mbox{\emph{false}}$ for every letter $a$
  \For{$i \in \{1,2,\ldots,n\}$}
    \State $\ell \leftarrow \Call{LastLength}{w\Class{i}}$
    \State $\Call{LastLength}{w\Class{i}} = |u|$
    \If{\textbf{not} $\Call{HasOccurred}{w\Class{i}}$}
      \State $\Call{HasOccurred}{w\Class{i}} \leftarrow \mbox{\emph{true}}$
      \State $u \leftarrow u \cdot w\Class{i} \cdot u$
    \Else
      \State $s \leftarrow |u| - \ell$
      \State $u \leftarrow u \cdot \Suff_s(u)$
    \EndIf
  \EndFor
\EndFunction 
\end{algorithmic} 
\end{algorithm}

Proposition \ref{P:justin} yields directly Algorithm \ref{A:ipc}.
In the next sections, we generalize it to the so-called \emph{pseudopalindromes} over binary alphabets, where the situation is more complicated, since there are two possible kinds of closure.  A few years ago, de Luca and De Luca \cite{deLucaDeLuca2006} {extended} the notion of palindrome to what they call {\it pseudopalindrome}, using involutory antimorphisms.  In order to define it, let us first recall that a map $\V:\A^* \rightarrow \A^*$ is called an {\it antimorphism} of $\A^*$ if for all $u,v \in \A^*$ one has $\V(uv)=\V(v)\V(u)$. Moreover, an antimorphism is {\it involutory} if $\V^2=\id$. Any antimorphism $\V$ of $\A^*$ can be constructed as $\V=\sigma \circ R= R\circ \sigma$, with $\sigma$ a permutation of the alphabet $\A$. We denote by $\sigma_\V$ the permutation associated with the antimorphism $\V$. Over a two-letter alphabet $\{a, b\}$, there are only two involutory permutations of letters
$\sigma_R=(a)(b)$ and $\sigma_E= (ab)$, yielding the two antimorphisms $R$, the reversal antimorphism, and $E$, defined as $E = \sigma_E \cdot R$.
The antimorphism $E$ will be called, as {usual}, the \textit{exchange antimorphism}.

We can now define the generalization of palindromes given in \cite{deLucaDeLuca2006}:  a word $w \in \A^*$ is called a {\it $\V$-palindrome} if it is the fixed point of the involutory antimorphism $\V$ of the free monoid $\A^*$: $\V(w)=w$. When the antimorphism $\V$ is not mentioned, {$w$} is called a {\it pseudopalindrome}. Notice that the $R$-palindromes are exactly the usual palindromes.

By analogy to the palindromic closure $^{(+)}$, the {\it $\V$-palindromic closure} of the finite word $u$, also called the   {\it pseudopalindromic closure} when the antimorphism is not specified,  is defined by $u^{\oplus_\V}=sq\V(s)$, where $u=sq$, with $q$ the longest $\V$-palindromic suffix of $u$. The $\V$-palindromic closure of $u$ is the shortest $\V$-palindrome having $u$ as prefix. 
\begin{example}Over the alphabet $\{0,1\}$, since the longest $E$-palindromic suffix of $w = 0010$ is $10$, $w^{\oplus_E}=0010\cdot E(00)=001011$. 
\end{example}

Notice that in the previous example, we have that $001011$ is an $E$-palindrome, also called an {\it antipalindrome}, since $E(001011)=R(\overline{001011})=R(110100)=001011$.

Extending the $\ipal$ operator to $\V$-palindromes, the $\ipal_ \V$ operator is naturally defined by $\ipal_ \V(\varepsilon)=\varepsilon$ and $\ipal_\V(wa)=(\ipal_\V(w)a)^{\oplus_\V}$, for $w\in \A^*$ and $a \in \A$. Then, for $\bw\in \A^\omega$, $\ipal_\V(\bw)=\lim_{n \rightarrow \infty} \ipal_\V(w\Class{1 \ldots n})$. This limit exists since by the definition of $\ipal_\V$, for any involutory antimorphism $\V$, $w \in \A^*$ and $a\in \A$, $\ipal_\V(w)$ is a  prefix of $\ipal_\V(wa)$.
 The infinite word obtained by the $\ipal_\V$ operator is a {\it $\V$-standard word}, also called a {\it pseudostandard word} when the antimorphism is not specified. This new class of words  is a general one that includes the standard Sturmian and the standard episturmian ones and was first introduced in \cite{deLucaDeLuca2006}. 


\begin{example} Over $\A=\{0,1\}$:
$$\ipal_\e(001)=((\ipal_\e(0)0)^{\oplus_E} 1)^{\oplus_E} = ((01\cdot 0)^{\oplus_E} 1)^{\oplus_E}=(0101\cdot 1)^{\oplus_E}=0101100101.$$
\end{example}

%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Generalized pseudostandard words}

In \cite{deLucaDeLuca2006}, the authors introduce the pseudostandard words as well as a new class of words, extending the pseudostandard words to a larger class of words: the {\it generalized pseudostandard words}. It consists mainly in allowing different types of pseudopalindromic closure while constructing the word from its directive sequence. 

More formally, let $\mathcal I$ be the set of all involutory antimorphisms of $\A^*$, and $\mathcal I^\omega$ be the set of infinite sequences over $\mathcal I$. Let $\Theta=\V_1\V_2\V_3\ldots \in \mathcal I ^\omega$ and let $^{\oplus_i}$ be the $\V_i$-palindromic closure operator, for all $i\geq 1$. We define inductively an operator $\psi_\Theta$ by setting $\psi_\Theta(\varepsilon)=\varepsilon$, and
$$\psi_\Theta(w\Class{1 \ldots n+1})=(\psi_\Theta(w\Class{1 \ldots n})w\Class{n+1})^{\oplus_{n+1}}$$
whenever $w\Class{i} \in \A$ for $i\geq 1$. 

If $\bw=\bw\Class{1}\bw\Class{2}\cdots \bw\Class{n}\cdots \in \A^\omega$, $\bw\Class{i} \in \A$ for $i \geq 1$, then $\psi_\Theta(\bw\Class{1 \ldots i})$ is a prefix of $\psi_\Theta(\bw\Class{1 \ldots i+1})$ for any $i$, so that the infinite word
$$\psi_\Theta(\bw)=\lim_{n \rightarrow \infty} \psi_\Theta(\bw\Class{1 \ldots  n})$$
is well-defined. We call $\psi_\Theta(\bw)$ a {\it generalized pseudostandard word} and the pair $(\Theta,w)$ is called the {\it directive bi-sequence} of $\psi_\Theta(w)$. 
 
When we consider a finite word $w$ and a finite sequence of involutory antimorphisms $\Theta$, both of length $|w|$, we call the word $\psi_\Theta(w)$ a {\it prefix of a generalized pseudostandard word} and the {\it length} of its directive bi-sequence is $|w|$. 

Notice that one can set $\Theta=R^\omega$ (resp., $\Theta=\V^\omega$) in order to obtain standard episturmian (resp., $\V$-standard) words.


For the remainder of that paper, we fix $\A = \{0,1\}$ so that the only two involutory antimorphisms are the reversal $R$ and the exchange antimorphism $E$.

Moreover, we write $\overline R=E$ and $\overline{E} = R$.

\begin{example}
Let $w = 0100$ and $\Theta = RERR$. Then $\ipal_\Theta(w) = \underline 0 \d {\rm 1}\underline 0\, \underline 010$.
\end{example}


Note that in the previous example, we have underlined (resp., under-dotted) the letter in the generalized pseudostandard word $\ipal_\Theta (w)$ where a $R$-closure (resp., $E$-closure) is performed.

A remarkable property of this class of words is that it contains the well-known Thue-Morse word $T$ as shown in \cite{deLucaDeLuca2006}, whose construction by iterated pseudopalindromic closure coincides with the one consisting of concatenating the successive prefixes with their complement. More precisely:

\begin{theorem}{\rm\cite{deLucaDeLuca2006}} \label{T:TM}The Thue-Morse word is described by $\psi_{(ER)^\omega}(01^\omega).$
\end{theorem}

\begin{example} \label{E:TM}As an example, let us construct the first prefixes of the Thue-Morse word.
$$\begin{tabular}{&gt;{$}r&lt;{$}&gt;{$}c&lt;{$}&gt;{$}l&lt;{$}&gt;{$}r&lt;{$}&gt;{$}c&lt;{$}&gt;{$}l&lt;{$}}
\psi_{E}(0)&amp;=&amp; \d {\rm 0}1 &amp; \psi_{ERE}(011)&amp;=&amp;\d {\rm 0}1 \underline 10 \d {\rm 1}001\\
\psi_{ER}(01)&amp;=&amp;\d {\rm  0}1 \underline 10 &amp; \psi_{ERER}(0111)&amp;=&amp;\d {\rm 0}1 \underline 10 \d {\rm 1}001 \underline 10010110.
\end{tabular}$$
\end{example}


%%%%%%%%%%%%%%
\section{Pseudoperiodicity} \label{S:pseudoperiodicity}

In the conference version of this extended article \cite{BlondinMassePaquinVuillon2010}, we introduced the notion of \emph{pseudoperiod}. We also provided a theorem in the spirit of Fine and Wilf for binary alphabets that was generalized to arbitrary alphabets in \cite{dlt2012}. We briefly discuss here this concept and provide lemmas (\ref{L:fperiod}, \ref{L:perdiv1} and \ref{L:perdiv2}) that turn out to be essential in the next section to describe the structure of words obtained by iterated pseudopalindromic closure.

First, we recall the definition of pseudoperiod from \cite{BlondinMassePaquinVuillon2010}.

\begin{definition} \label{D:pseudoperiod} {\rm \cite{BlondinMassePaquinVuillon2010}}
Let $w$ be a finite word and $\sigma$ be a permutation of the alphabet. We say that the positive integer $p$ is a {\rm $\sigma$-period of $w$} if for each integer $i$ such that $1 \leq i \leq |w| - p$, we have $w\Class{i} = \sigma(w\Class{i + p})$.
\end{definition}

\begin{example} Let $\sigma_R = (0)(1)$ and $\sigma_E = (01)$. Then the word $011011$ has the $\sigma_R$-period $3$ and the $\sigma_E$-period $5$, since $011011=011\cdot \sigma_R(011)$ and $011011=01101\cdot \sigma_E(0)$.
\end{example} 
As we can see in the previous example, the $\sigma_R$-periods are the usual periods on words. Finally, the reader verifies easily that if $p$ is a $\sigma$-period of a word $w$, then $\ord(\sigma)p$ is a period of $w$, where $\ord(\sigma)$ is the order of the permutation $\sigma$, i.e. the smallest number $k$ such that $\sigma^k$ is the identity.

It shall be mentioned that the word \emph{pseudoperiod} is also used in \cite{Czeizler2009,manea}, but its meaning is not equivalent to Definition \ref{D:pseudoperiod}. More precisely, the authors say from a positive integer $p$ that it is a $\sigma$-period of a word $w$ if $w$ may be written as an arbitrary product of elements in $\{u, \sigma(u)\}$, where $u$ is a word of length $p$. For instance, the number $2$ is a $\sigma$-period of the word $w = 12323212$ for $\sigma : 1 \mapsto 3, 2 \mapsto 2, 3 \mapsto 1$, since $w = u\sigma(u)\sigma(u)u$, for $u = 12$. On the other hand, Definition \ref{D:pseudoperiod} imposes an alternance of the word with its complement and applies even if $p$ does not divide $|w|$. Moreover, in the case of a binary alphabet, for every word $w$, $1$ is trivially a $\sigma_E$-period of $w$ when considering the definition of pseudoperiod of \cite{Czeizler2009}.

It is known that overlapping palindromes yield periodicity (see for instance \cite{deLuca1997}). These periodic properties may be generalized naturally to overlapping pseudopalindromes. The following lemma shows that pseudoperiodic pseudopalindromes may be extended into longer ones or broken into smaller ones.

\begin{lemma}\label{L:pal and antipal}
Let $w$ be a $\V$-palindrome and $p$ be a $\sigma$-period of $w$, where $\sigma$ is an involutory permutation and $p &lt; |w|$, $u$ is the suffix of $w$ of length $p$. Moreover, let $i = \lfloor |w| / p \rfloor$. Then
\begin{enumerate}[\rm(i)]
  \item $w(\sigma(u)u)^j$ is a $\V$-palindrome for all integers $j \geq -\lfloor i/2 \rfloor$; 
  \item $w\sigma(u)(u\sigma(u))^j$ is a $(\V \circ \sigma)$-palindrome for all integers $j \geq -\lfloor i/2 \rfloor$.
\end{enumerate}
\end{lemma}

\begin{proof}
(i) Since $p$ is a $\sigma$-period of $w$, there exist a word $x$, a nonempty word $y$ and a positive integer $k$ such that $|xy| = p$ and $w \in \{(xy\sigma(xy))^kx, (xy\sigma(xy))^kxy\sigma(x)\}$. We first consider the case $w = (xy\sigma(xy))^kx$. In particular, $k = \lfloor i / 2 \rfloor$ and $u = \sigma(y)x$. Moreover, since $w$ is a $\V$-palindrome, we deduce that $x = \V(x)$ and $y = (\V \circ \sigma)(y)$. Let $j \geq -\lfloor i/2 \rfloor$ be an integer. Then $w(\sigma(u)u)^j = (xy\sigma(xy))^{k+j}x$, which is indeed a $\V$-palindrome, since $x = \V(x)$ and $y = (\V \circ \sigma)(y)$. The case $w = (xy\sigma(xy))^kxy\sigma(x)$ is verified similarly, as well as (ii).
\end{proof}

Roughly speaking, Lemma \ref{L:pal and antipal} states that if a given $\V$-palindrome is $\sigma$-periodic and sufficiently long, then one can construct a sequence of alternating $\V$-palindromes and $(\V \circ \sigma)$-palindromes by erasing the repetitions or by extending the period.

\begin{example}
Let $\sigma = \sigma_E$, $\V = R$ and $w = 001011101000101110100$. Then $5$ is an $\sigma_E$-period of $w$ and $w$ is an $R$-palindrome. Also, Lemma \ref{L:pal and antipal} applies, so that $w(10100)^{-1} = 0010111010001011$ and $w(0101110100)^{-1}(10100)^{-1} = 001011$ are $E$-palindromes. On the other hand, the words $w(0101110100)^{-1} = 00101110100$ and $w(0101110100)^{-2} = 0$ are $R$-palindromes. 
\end{example}

In \cite{dlt2012}, the authors generalized Fine and Wilf's Theorem for pseudoperiodic words.

\begin{theorem} \label{T:fineandwilfgen} {\rm\cite{dlt2012}}
Let $p$, $q$ be two positive integers and $\sigma_1$, $\sigma_2$ two permutations such that $\sigma_1$ and $\sigma_2^{-1}$ commute. Then any word $w$ of length at least $p + q$ admitting $p$ as a $\sigma_1$-period and $q$ as a $\sigma_2$-period also admits $\gcd(p, q)$ as a $\sigma$-period, where $\sigma = \sigma_1^x\sigma_2^{-y}$ and $x, y$ are any integers such that $\gcd(p, q) = xp - yq$.
\end{theorem}

It is worth mentioning that Theorem \ref{T:fineandwilfgen} holds even if $\sigma_1$ and $\sigma_2$ are not involutory. The binary case is proved in \cite{BlondinMassePaquinVuillon2010}. It also directly follows from Theorem \ref{T:fineandwilfgen}:
\begin{theorem} \label{T:fineandwilf} {\rm\cite{BlondinMassePaquinVuillon2010}}
Let $p$, $q$ be two positive integers and $\sigma_1$, $\sigma_2$ two permutations on a binary alphabet $\A$. Then any word $w$ of length at least $p + q$ admitting $p$ as a $\sigma_1$-period and $q$ as a $\sigma_2$-period also admits $\gcd(p, q)$ as a $\sigma$-period, where
$$\sigma = \begin{cases}
  \sigma_R, &amp; \mbox{if $\sigma_1 = \sigma_2 = \sigma_R$;} \\
  \sigma_E, &amp; \mbox{otherwise.}
\end{cases}$$
\end{theorem}

\begin{proof}
On binary alphabet, the permutations $\sigma_R$ and $\sigma_E^{-1} = \sigma_E$ commute. Moreover, any pair of integers verifying $\gcd(p, q) = xp - yq$, also called Bezout coefficients, may be chosen so that one is even and the other is odd. If $\sigma_1 = \sigma_2 = \sigma_R$, then $\sigma = \sigma_R$ and the theorem follows. Otherwise, since $x$ and $y$ have different parity, then $\sigma_1^x\sigma_2^{-y} = \sigma_E = \sigma$, which concludes the proof.
\end{proof}

\begin{example}
The word $w = 01010101$ admits the $\sigma_R$-period $4$ and the $\sigma_E$-period $3$. By Theorem \ref{T:fineandwilf}, $\gcd(4,3) = 1$ is also an $\sigma_E$-period of $w$.
\end{example}

\begin{remark}
The bound $|w| \geq p + q$ in Theorem \ref{T:fineandwilf} is tight, as illustrated by the following example. Let $p$ be any positive integer and $q = p + 1$. Moreover, let $w = 0^p1^p$. Then $w$ has the $\sigma_E$-periods $p$ and $q$. On the other hand, $1 = \gcd(p,q)$ is not an $\sigma_E$-period of $w$ and $|w| = 2p &lt; 2p + 1 = p + q$. Actually, one may show that there is no word of length $2p + 1$ admitting the $\sigma_E$-periods $p$ and $q$.
\end{remark}

We conclude this section with three lemmas about local periodicity in words. The first lemma holds for any alphabet.

\begin{lemma} \label{L:fperiod}
Let $u$ be a finite word over an arbitrary alphabet, $p$ be a $\V_1$-palindrome and $q$ be a $\V_2$-palindrome for some involutory antimorphisms $\V_1$,$\V_2$, such that $pu = q$. Then $q$ has the $(\sigma_{\V_2} \circ \sigma_{\V_1})$-period $|u|$.
\end{lemma}

\begin{proof}
Let $i$ be an integer satisfying $1 \leq i \leq |p|$. Since $p$ is a prefix of $q$ and since $p$ is a $\V_1$-palindrome, one has $q\Class{i} = \sigma_{\V_1}(q\Class{|p| + 1 - i})$. But $q$ is a $\V_2$-palindrome, which implies that
\begin{eqnarray*}
  q\Class{i}
    &amp; = &amp; \sigma_{\V_1}(q\Class{|p| + 1 - i}) \\
    &amp; = &amp; (\sigma_{\V_2} \circ \sigma_{\V_1})(q\Class{|q| + 1 - |p| - 1 + i}) \\
    &amp; = &amp; (\sigma_{\V_2} \circ \sigma_{\V_1})(q\Class{|q| - |p| + i})\\
    &amp; = &amp; (\sigma_{\V_2} \circ \sigma_{\V_1})(q\Class{i + |u|}),
\end{eqnarray*}
and the result follows.
\end{proof}

Not any pseudoperiod may exist in a given word.

\begin{lemma} \label{L:perdiv1}
Let $w$ be a finite binary word, $p$ a $\sigma_1$-period of $w$ and $q$ a $\sigma_2$-period of $w$, where $\sigma_1, \sigma_2 \in \{\sigma_R, \sigma_E\}$. Assume that $|w| &gt; p &gt; q$ and $p = mq$ for some integer $m \geq 2$. Then one of the two following conditions holds:
\begin{enumerate}[\rm(i)]
  \item $\sigma_1$ is the identity and $m$ is even;
  \item $\sigma_1 = \sigma_2$ and $m$ is odd. 
\end{enumerate}
\end{lemma}

\begin{proof}
Let $i$ be an integer such that $1 \leq i \leq |w| - p$. Note that $\sigma_1$ and $\sigma_2$ commute since the alphabet is binary. Therefore,
$$\sigma_R(w\Class{i}) = w\Class{i} = \sigma_1(w\Class{i+p}) = \sigma_1(w\Class{i+mq}) = (\sigma_2^m \circ \sigma_1)(w\Class{i}),$$
so that $\sigma_R = \sigma_2^m \circ \sigma_1$. As a consequence, if $m$ is even, then $\sigma_1 = \sigma_R$, and if $m$ is odd, then $\sigma_R = \sigma_1 \circ \sigma_2$, which implies $\sigma_1 = \sigma_2$.
\end{proof}

It is worth mentioning that Lemma \ref{L:perdiv1} holds for arbitrary alphabets whenever all letters occur in the prefix of length $|w| - p$ of $w$, i.e. whenever we have $\sigma_R(a) = (\sigma_{\V_2}^m \circ \sigma_{\V_1})(a)$ for all letters $a$.

The last lemma is a simple extension of Lemma 8.1.3 of \cite{Lothaire2002} giving condition for a local period to propagate to the whole word. As for Lemma \ref{L:perdiv1}, it could be extended to arbitrary alphabets provided that all letters occur in some prefix of $w$, but since this paper is devoted to binary alphabets, for sake of simplicity, we only present this case.

\begin{lemma} \label{L:perdiv2}
Let $w$ be a finite binary word and $v$ be a factor of $w$. Assume that $p$ is a $\sigma_1$-period of $w$ such that $|v| &gt; p$ and $q$ is a $\sigma_2$-period of $v$ such that $q$ divides $p$, where $\sigma_1, \sigma_2 \in \{\sigma_R, \sigma_E\}$. Then $q$ is a $\sigma_2$-period of $w$. 
\end{lemma}

\begin{proof}
First consider the case $q = p$. Then $p = q$ is both a $\sigma_1$-period and a $\sigma_2$-period of $v$ and $|v| &gt; p$. This means that $\sigma_1 = \sigma_2$ and the lemma follows. For the rest of the proof, we may suppose $q &lt; p$ and $p = qm$ for some positive integer $m \geq 2$.

Let $k$ be an integer, $1 \leq k \leq |w|$, such that $v = w\Class{k}w\Class{k+1}\cdots w\Class{k+|v|-1}$. Let $V = \{k,k+1,\ldots,k+|v|-1\}$ be the set of indices of $v$ in $w$. Moreover, let $i$ be an integer such that $1 \leq i \leq |w| - q$. Since $|v| &gt; p$, there exists an integer $i' \in V$ such that $i' \equiv i \bmod p$. 
Therefore, since $p$ is a $\sigma_1$-period of $w$, we have $w\Class{i'} = \sigma_1^{|\ell|}(w\Class{i})$, where $\ell$ is the integer satisfying $i' - i = p\ell$. Since $\sigma_1$ is involutory, we have $w\Class{i} = \sigma_1^{|\ell|}(w\Class{i'})$ as well.

Let $j = i + q$. Using a similar argument as above, we find that there exists at least one integer $j' \in V$ such that $j' \equiv j \bmod p$. In particular, we may choose $j'$ so that $j' \in \{i' + q, i' + q - p\}$. Indeed, we have $i' + q \equiv i' + q - p \equiv i + q \bmod p$ and at least one value among $i' + q$ and $i' + q - p$ must fall in $V$ (since $|v| &gt; p$ and $i' \in V$). Thus, we may write $j' - j = p\ell'$, for some integer $\ell' \in \{\ell - 1, \ell\}$, so that $w\Class{j'} = \sigma_1^{|\ell'|}(w\Class{j})$.
We distinguish two cases. Assume first that $\ell' = \ell$ so that $j' = i' + q$. Since $q$ is a $\sigma_2$-period of $v$, we have $w\Class{i'} = \sigma_2(w\Class{j'})$. Then $w\Class{j} = (\sigma_1^{|2\ell|} \circ \sigma_2)(w\Class{i}) = \sigma_2(w\Class{i})$. On the other hand, suppose that $\ell' = \ell - 1$ so that $j' = i' + q - p$. Recall that $p = qm$. Then $j' = i' + (1 - m)q$ so that $w\Class{i'} = \sigma_2^{|1-m|}(w\Class{j'})$. This implies $w\Class{j} = (\sigma_1^{|2\ell-1|} \circ \sigma_2^{|1-m|})(w\Class{i}) = (\sigma_1 \circ \sigma_2^{|1-m|})(w\Class{i})$. We know from Lemma \ref{L:perdiv1} that either $\sigma_1 = R$ and $m$ is even or $\sigma_1 = \sigma_2$ and $m$ is odd. Both cases imply $w\Class{j} = \sigma_2(w\Class{i})$. Hence, we have shown that $w\Class{i + q} = \sigma_2(w\Class{i})$ for any integer $i$ such that $1 \leq i \leq |v| - q$, i.e. $q$ is a $\sigma_2$-period of $w$.
\end{proof}

%%%%%%%%%%%%%%
\section{Normalized form} \label{S:normalized}

Words obtained by iterated palindromic closure are the limit of a sequence of palindromes that are prefixes of each other. The idea is the same when considering iterated pseudopalindromic closure. A first trivial and useful observation is the following.
\begin{lemma} \label{L:nomiss}
  Let $\bu = \ipal(\bw)=\ipal_{R^\omega}(\bw)$ be a word on an arbitrary alphabet. The word $v$ is a palindromic prefix of $\bu$ if and only if there exists a nonnegative integer $n$ such that $v = \ipal_{R^n}(\bw\Class{1\ldots n})$.
\end{lemma}

\begin{proof}
$(\Rightarrow)$ By contradiction, assume that such a word $v$ exists. Let $n$ be the integer such that $|\ipal_{R^{n-1}}(\bw\Class{1\ldots n - 1})| &lt; |v| &lt; |\ipal_{R^n}(\bw\Class{1\ldots n})|$. Then $\ipal_{R^n}(\bw\Class{1\ldots n})$ is not the shortest palindromic suffix having $\ipal_{R^{n-1}}(\bw\Class{1\ldots n-1})\bw\Class{n}$ as a prefix, contradicting the definition of the palindromic closure. $(\Leftrightarrow)$ By definition of palindromic closure, $\ipal_{R^n}(\bw\Class{1\ldots n})$ is a palindrome for any integer $n \geq 0$.
\end{proof}

Roughly speaking, Lemma \ref{L:nomiss} states that no palindromic prefix is missed by the iterated palindromic closure. In the following, Lemma \ref{L:nomiss} is used several times without being referenced. This fact also holds for any $\V$-standard word (see Proposition 4.1, \cite{deLucaDeLuca2006}), i.e. no $\V$-palindromic prefix is missed by the iterated $\V$-palindromic closure. However, this is not the case if different pseudopalindromic closures are allowed. For instance, the word $w = \ipal_{RERE}(0011) = \underline 0 \d {\rm 0}11 \underline 100 \d {\rm 1}100011$ misses the palindrome $00$ while the word $u=\ipal_{RRE}(011)=\underline 0\, \underline 10\d {\rm 1}$ misses the $E$-palindrome $01$. On the other hand, $w = \ipal_{RRERE}(00111)$ and $u=\ipal_{RERE}(0101)$, i.e. it is possible to rewrite the directive bi-sequences of $w$ and $u$ so that they do not miss any pseudopalindromic prefixes. As we will see (and prove) in the sequel, it is always possible to rewrite any directive bi-sequence of a generalized pseudostandard word in a ``normalized'' form. 

\begin{definition} A finite or infinite directive bi-sequence $(\Theta, w)$ is called \emph{normalized} if it verifies the following condition: $v$ is a pseudopalindromic prefix of $\psi_\Theta(w)$ if and only if there exists a non negative integer $n$ such that $v = \psi_{\Theta\Class{1..n}}(w\Class{1..n})$. A pseudopalindromic prefix $v$ that does not satisfy the previous condition is called a \emph{missed pseudopalindrome} and the we say that $(\Theta, w)$ \emph{misses} $v$.
\end{definition}

The length of any missed pseudopalindrome is constrained.

\begin{lemma}\label{L:longueurMissed} Let $(\Theta, w)$ be a finite directive bi-sequence describing a prefix of a generalized pseudostandard word on any alphabet. If $(\Theta, w)$ is normalized and $(\Theta \tau, wx)$ is not, with $x \in \A$ and $\tau \in \{E, R\}$, any missed $\V$-palindromic prefix $p$ is such that $|\ipal_\Theta(w)| &lt; |p| &lt; |\ipal_{\Theta \tau}(wx)|$.
\end{lemma}

\begin{proof} It is obvious that $|p| &lt; |\ipal_{\Theta \tau}(wx)|$. If $|p|\leq |\ipal_\Theta(w)|$, then a contradiction occurs, since $(w, \Theta)$ is supposed normalized.
\end{proof}

The next results only apply to binary alphabets. First, the following fact is easily observed.

\begin{lemma}\label{L:prefNorm} The shortest prefixes of a normalized directive bi-sequence containing exactly two different letters are of the form:
$$(R^{i+1},a^i\overline a) {\rm \, \, \,  for \, \, \, } i\geq 2, {\rm\, \, \,  or \, \, \, } (R^i E, a^i {\overline a}) {\rm \, \, \,  for \, \, \,  } i\geq 1 {\rm \, \, \, and \, \, \, } a \in \{0,1\}.$$
\end{lemma}

\begin{proof}
By direct inspection. One notices in particular that no normalized bi-sequence starts with the antimorphism $E$.
\end{proof}

Generalized pseudostandard words have periods to different scale. In particular, if a bi-sequence is not normalized, we can extract useful information about the antimorphisms and the letters involved.

\begin{lemma} \label{L:not normalized}
Let $(\Theta,w)$ be a finite normalized directive bi-sequence of length $n \geq 1$ of a prefix of a generalized pseudostandard binary word. Suppose that $(\Theta\tau,wa)$ is not normalized, where $\tau \in \{R,E\}$ and $a \in \A$. Let $u = \ipal_\Theta(w)$, $v = \ipal_{\Theta\tau}(wa)$ and $t$ be a pseudopalindromic prefix missed by $(\Theta\tau,wa)$. Finally, let $p = |v| - |u|$, $q = |v| - |t|$ and $g = \gcd(p,q)$. Then exactly one of the following conditions hold.
\begin{enumerate}[\rm(i)]
  \item $g$ is an $\sigma_E$-period of $v$, $p = 2g$, $q = g$ and $\V_n = \tau$, where $\V_n$ is the last antimorphism of $\Theta$;
  \item $(\Theta\tau, wa) = (R^nE,a^{n+1})$;
\end{enumerate}
\end{lemma}

\begin{proof}
\begin{figure}
  \centering
  \includegraphics{tikz-demo-non-normalise}
  \caption{Illustration of the proof of Lemma \ref{L:not normalized}.}
  \label{F:not normalized}
\end{figure}
The situation is depicted in Figure \ref{F:not normalized}. Notice that $t$ is a $\overline{\tau}$-palindrome, otherwise $v$ would not be the shortest $\tau$-palindrome having $ua$ as a prefix. Moreover, it follows from Lemma \ref{L:fperiod} that $p$ is a $(\sigma_{\V_n} \circ \sigma_\tau)$-period of $v$, since $v$ is a $\tau$-palindrome and $u$ is a $\V_n$-palindrome, where, $\V_n$ is the last antimorphism of $\Theta$. Similarly, $q$ is a $(\sigma_\tau \circ \sigma_{\overline{\tau}})$-period (i.e. an $\sigma_E$-period) of $v$.

First, suppose that $|v| \geq p + q$. Then Theorem \ref{T:fineandwilf} applies so that $v$ has the $\sigma_E$-period $g = \gcd(p,q)$. By Lemma \ref{L:pal and antipal}, we conclude that the prefix $y$ of $v$ of length $|v| - 2g$ is a $\tau$-palindrome. Since no $\tau$-palindrome occurs between $u$ and $v$ (otherwise $v$ would not be the shortest $\tau$-palindrome having $ua$ as a prefix), we must have $|y| \leq |u|$, i.e. $p = |v| - |u| \leq 2g$. 
Since $0 &lt; q &lt; p \leq 2g$ and $g$ divides both $p$ and $q$, we have $p, q \in \{g,2g\}$. But $q &lt; p$, so that $q = g$ and $p = 2g$. In particular, $u = y$ is a $\tau$-palindrome and we are in case (i).

It remains to consider the case $|v| &lt; p + q$. Notice that, by definition of pseudopalindromic closure, one has $|v| \leq 2|u| + 2$, with $|v| = 2|u| + 2$ only if $v$ is an $E$-palindrome. We first show that $|v| = 2|u| + 2$. Arguing by contradiction, suppose that $|v| \leq 2|u| + 1$. Then
\begin{align}
  |v|
    &amp; &lt; p + q \notag \\
    &amp; = |v| - |u| + |v| - |t| \notag \\
    &amp; \leq 2|u| + 1 - |t| + |v| - |u| \notag \\
    &amp; = |u| + 1 - |t| + |v| \notag \\
    &amp; \leq |u| + 1 - |u| - 1 + |v| \label{E:cons} \\
    &amp; = |v|, \notag
\end{align}
which is absurd. Note that Inequality \eqref{E:cons} follows from the inequality $|t| \geq |u| + 1$. Hence, $|v| = 2|u| + 2$. This implies that $\tau = E$ and $t$ is a $R$-palindrome (since $\overline{\tau} = R$).

Next, suppose that $|t| \geq |u| + 2$. Then $q \leq |u|$. Since $u$ is a $\V_n$-palindrome and $q$ is a $\sigma_E$-period of $u$, Lemma \ref{L:pal and antipal} implies that the prefix of $v$ of length $|u| + q$ is a $\overline{\sigma_{\V_n}}$-palindrome. Therefore, $\overline{\sigma_{\V_n}} \neq \tau$, otherwise, $v$ would not be of minimum length, which implies $\V_n \neq \tau$ and then $\V_n = R$. As a consequence, $p - q$ is a $\sigma_E$-period of $t$. Moreover, we know that $q$ is a $\sigma_E$-period of $t$ as well since it is a period of $v$. We can apply Theorem \ref{T:fineandwilf} to $t$ since $q + (p - q) = p = |u| + 2 \leq |t|$, so that $\gcd(q, p - q) = \gcd(q,p) = g$ is a $\sigma_E$-period of $t$ which propagates to $v$, by Lemma \ref{L:perdiv2}. Once again by Lemma \ref{L:pal and antipal}, we conclude that the prefix of $v$ of length $|u| + 2g$ is a $\V_n$-palindrome, i.e. a $\tau$-palindrome. This implies $|u| + 2g \geq |v| = 2|u| + 2$, so that $2g \geq |u| + 2 = p$. Since $g$ divides both $p$ and $q$ and since $q &lt; p$, this means that $q = g$ and $p = 2g$, which corresponds also to case (i).

Finally, assume that $|t| = |u| + 1$. There are two cases to consider. If $\V_n = R$, then Lemma \ref{L:fperiod} implies that $1$ is a $\sigma_R$-period of $t$, so that $t = a^{n+1}$, $u = a^n$, $v = a^{n+1}\overline{a^{n+1}}$ and $(\Theta\tau,wa) = (R^nE,a^{n+1})$, which yields case (ii). Otherwise, again by Lemma \ref{L:fperiod}, $\V_n = E$ and $1$ is a $\sigma_E$-period of $t$. Since $t$ is an $R$-palindrome, we must have $t = (a\bar{a})^ka$ for some positive integer $k$. But every prefix of $t$ is either an $R$-palindrome or an $E$-palindrome and $(\Theta,w)$ is normalized: Therefore, $|u| = n$ which implies $u = (a\overline{a})^{n/2}$, $t = (a\overline{a})^{n/2}a$ and $v = (a\overline{a})^{n/2+1}$. But $n + 2 = |v| = 2|u| + 2 = 2n + 2$, so that $n = 0$, a contradiction.
\end{proof}

There are forbidden patterns that necessarily lead to non normalized bi-sequences.

\begin{lemma}\label{L:not normalized alternate}
Let $\Theta$ be a sequence of involutory antimorphisms, $\V \in \{R, E\}$, $w \in \A^*$ and $a, b \in \A$, where $\A$ is a binary alphabet. Suppose that $(\Theta\V\bar{\V}, wab)$ is normalized. Also, let $u = \ipal_{\Theta\V}(wa)$, $v = \ipal_{\Theta\V\bar{\V}}(wab)$, $p = |v| - |u|$ and $s$ be the suffix of length $p$ of $v$. Then
\begin{enumerate}[\rm(i)]
  \item $p$ is the minimum $\sigma_E$-period of $v$;
  \item $\ipal_{\Theta\V\bar{\V}\V}(uab\bar{b}) = v\bar{s}$;
  \item $\ipal_{\Theta\V\bar{\V\V}}(uab\bar{b}) = v\bar{s}s$;
  \item $(\Theta\V\bar{\V\V}, uab\bar{b})$ is not normalized, $(\Theta\V\bar{\V}\V\bar{\V}, uab\bar{b}b)$ is normalized and both bi-sequences generate the same word.
\end{enumerate}
\end{lemma}

\begin{proof}
(i) It follows from Lemma \ref{L:fperiod} that $p$ is a $\sigma_E$-period of $v$ since $\sigma_{\V} \circ \sigma_{\bar{\V}} = \sigma_E$. It remains to show that $p$ is minimal. By contradiction, assume that there exists a $\sigma_E$-period $p' &lt; p$. Let $s'$ be the word of length $p'$ such that $us'$ is a prefix of $v$. By Lemma \ref{L:pal and antipal}, $us'$ is a $\bar{\V}$-palindrome and, by construction of $v$, $b$ is the first letter of $s'$, contradicting the fact that $v$ is the shortest $\bar{\V}$-palindrome having $ub$ as a prefix.

(ii) Since $v$ is a $\bar{\V}$-palindrome having $p$ as a $\sigma_E$-period, it follows from Lemma \ref{L:pal and antipal} that $v\overline{s}$ is a $\V$-palindrome. Now, assume that $v\overline{s}$ is not the shortest $\V$-palindrome having $v\bar{b}$ as a prefix. Let $x$ be the longest $\V$-palindrome suffix of $v$. Then $|x| &gt; |v| - p$ and, by Lemma \ref{L:fperiod}, $v$ has the $\sigma_E$-period $|v| - |x| &lt; p$, contradicting the minimality of $p$.

(iii) It suffices to apply the same reasoning as in part (ii).

(iv) Parts (ii) and (iii) implies that $(\Theta\V\bar{\V\V}, uab\bar{b})$ is not normalized since it misses the pseudopalindrome $v\bar{s}$. Moreover, $(\Theta\V\bar{\V}\V\bar{\V}, uab\bar{b}b)$ is normalized since it does not verify any of the conditions of Lemma \ref{L:not normalized}. Finally, applying twice part (ii) and once part (iii) shows that both bi-sequence generate the same word.
\end{proof}

Let $(\Theta, w)$ be an infinite (resp., a finite) directive bi-sequence of a (resp., prefix of a) generalized pseudostandard word. The concept of factor is naturally extended to bi-sequences. More precisely, $(\V_i\cdots \V_{i+k}, w\Class{i \ldots i+k})$ is called a {\it factor} of $(\Theta, w)$ for any integers $i, k \geq 1$.

We are now ready to describe the forbidden factors and prefixes of normalized bi-sequences.

\begin{proposition}\label{L:motifInt} A finite directive bi-sequence $s$ on a binary alphabet is normalized if and only if it does not have a prefix of one of the following forms:
\begin{multicols}{2} \begin{enumerate}[\rm (i)]
  \item $(RR, a\overline{a})$,
  \item $(R^{i-1}E, a^i)$,
  \item $( R^iEE, a^i\overline{a}\,\overline{a})$,
  \item $(\Theta REE, wab\overline{b})$ or $(\Theta ERR, wab\overline{b})$,
\end{enumerate} \end{multicols}
\noindent where $a,b \in \{0,1\}$, $i \geq 1$ is an integer and $(\Theta,w)$ is a finite directive bi-sequence.
\end{proposition}

\begin{proof} 
$(\Rightarrow)$ We prove the contrapositive, i.e. we suppose that the prefix of the directive bi-sequence is of one of these four forms and prove that it is not normalized. Clearly, (i) $\ipal_{RR}(a\overline{a}) = a\overline{a}a$ misses the $E$-palindromic prefix $a\overline{a}$, (ii) $\ipal_{R^{i-1}E}(a^i) = a^{i}\overline{a}^{i}$ misses the palindromic prefix $a^i$ and (iii) $\ipal_{R^iEE}(a^i\overline{a}\, \overline {a}) = a^i\overline{a}^{i+1}a^{i+1}\overline{a}^i$ misses the palindromic prefix  $a^i\overline{a}^{i+1}a^i$. Case (iv) follows directly from Lemma \ref{L:not normalized alternate}.

\begin{figure}
  \centering
  \includegraphics{tikz-forbidden}
  \caption{Illustration of Part $(\Leftarrow)$ in the proof of Proposition \ref{L:motifInt}. It follows from Lemma \ref{L:not normalized} that $p = 2g$ and $q = g$, where $g = \gcd(p,q)$. Also, $\V_{n-1} = \V_n$.}
  \label{F:forbidden}
\end{figure}
$(\Leftarrow)$ We prove the contrapositive, i.e. we suppose that $s$ is not normalized. If $|s| \leq 2$, then inspection shows that the only possible non-normalized directive bi-sequences fall in case (i) or (ii). Now, assume that $|s| \geq 3$.
Let $(\Theta,w)$ be the shortest non-normalized prefix of $s$ and $n = |w|$. Let
\begin{eqnarray*}
  u &amp; = &amp; \ipal_{\V_1\V_2\cdots\V_{n-1}}(w\Class{1}w\Class{2}\cdots w\Class{n-1}),\\
  v &amp; = &amp; \ipal_{\Theta}(w)
\end{eqnarray*}
and $t$ be a $\overline{\V_n}$-palindrome missed by $(\Theta,w)$ (see Figure \ref{F:forbidden}). Moreover, let $p = |v| - |u|$, $q = |v| - |t|$ and $g = \gcd(p,q)$. By Lemma \ref{L:not normalized}, either we are in case (ii) or (iv), or $(\Theta,w)$ ends with a factor in $\{(RRR, abc), (EEE, abc), (ERR,abc), (REE, abc)\}$, where $a,b,c$ are letters. On the other hand, Lemma \ref{L:not normalized} implies that $|v| \geq p + q$, $g$ is an $\sigma_E$-period of $v$, $p = 2g$, $q = g$ and $u$ is a $\V_n$-palindrome, i.e. $\V_{n-1}=\V_n$. Let $y$ be the prefix of lenght $n - 2$ of $\ipal_\Theta(w)$, that is $y = \ipal_{\V_1\V_2\cdots\V_{n-2}}(w\Class{1}w\Class{2}\cdots w\Class{n-2})$.

Notice that $|u| - |y| \leq g$. Otherwise, there would exist a $\overline{\V_n}$-palindromic prefix between $y$ and $u$, namely the suffix of $v$ of length $|v| - 3g$ by Lemma \ref{L:pal and antipal}, contradicting the fact that $(\V_1\V_2\cdots \V_{n-1}, w\Class{1}w\Class{2}\cdots w\Class{n-1})$ is normalized. Let $g' = |u| - |y|$. If $g' = g$, then $\V_{n-2} = \overline{\V_n}$ and $c = \overline{b}$, i.e. $s$ ends with $(ERR,ab\overline b)$ or $(REE, ab\overline b)$. By Lemma \ref{L:not normalized alternate}, we know that $s$ is not normalized, and this corresponds to case (iv). It remains to consider the case $g' &lt; g$. We show in the next paragraphs that this implies case (iii).

First, we show that $|y| &lt; g$. Proceeding by contradiction, assume that $|y| \geq g$. This implies $|u| \geq g + g'$. Since $g$ is an $\sigma_E$-period of $v$ and in particular an $\sigma_E$-period of $u$ and, by Lemma \ref{L:fperiod}, $g'$ is a $(\sigma_{\V_{n-2}} \circ \sigma_{\V_n})$-period of $u$, it follows from Theorem \ref{T:fineandwilf} that $g'' = \gcd(g,g')$ is an $\sigma_E$-period of $u$. Moreover, that $\sigma_E$-period $g''$ propagates to the whole word $v$ in virtue of Lemma \ref{L:perdiv2} applies, yielding a contradiction: this would imply that there is a $\V_n$-palindrome between the $\V_n$-palindromes $u$ and $v$, namely the prefix of $v$ of length $|v| - 2g''$ (by Lemma \ref{L:pal and antipal}). But $g'' &lt; g$ (since $g' &lt; g$). Hence, the claim $|y| &lt; g$ is proved.

Now, we prove that $|v| = 4g - 2$. Recall that by definition of pseudopalindromic closure, $|v| \leq 2|u| + 2$. Moreover, $|v| = |u| + 2g$, $|y| \leq g - 1$ and $g' = |u| - |y| \leq g - 1$. On the first hand, we have $|v| \leq 2|u| + 2 = 2|v| - 4g + 2$ which implies $|v| \geq 4g - 2$. On the other hand, $|v| = |u| + 2g \leq |y| + g - 1 + 2g \leq g - 1 + g - 1 + 2g = 4g - 2$, thus $|v| = 4g - 2$. In particular, in virtue of the equalities and inequalities $|v| = 4g - 2$, $|v| - |u| = 2g$, $|u| - |y| \leq g - 1$ and $|y| \leq g - 1$, we have $|y| = g - 1$, $|u| = 2g - 2$ and $|v| = 2|u| + 2$. Hence, $\V_n = E$ and $g' = |u| - |y| = g - 1$.

Finally, notice that, since $|v| \geq p + q = 3g$, the prefix $z$ of $v$ of length $|v| - 3g$ is a $\overline{\V_n}$-palindrome, i.e. an $R$-palindrome, by Lemma \ref{L:pal and antipal}. But Lemma \ref{L:fperiod} implies that $|y| - |z| = g - g' = 1$ is an $(\sigma_{\V_{n-2}} \circ \sigma_R)$-period of $y$, i.e. an $\sigma_{\V_{n-2}}$-period of $y$. If $\V_{n-2} = R$ and since $y$ has length $g - 1$, contains the letter $\overline{b}$ and $\V_1 = R$, we find $y = \overline{b}^{g-1}$, so that $u = \overline{b}^{g-1}b^{g-1}$ and $v = \overline{b}^{g-1}b^g\overline{b}^gb^{g-1}$, which corresponds to case (iii). It only remains to consider the case $\V_{n-2} = E$. Then $y = (d\bar{d})^{(g - 1)/2}$ for some letter $d$, since $1$ is a $\sigma_E$-period of $y$ and $|y| = g - 1$. But $\V_n = \V_{n-1} = E$ and $(\V_1\V_2\cdots\V_{n-1},w\Class{1}w\Class{2}\cdots w\Class{n-1})$ is normalized, which implies that $w\Class{n-1} \neq d$ (otherwise the palindrome $(d\bar{d})^{(g-1)/2}d$ would be missed). Therefore, $u = (d\bar{d})^{(g-1)/2}(\bar{d}d)^{(g-1)/2}$. Finally, notice that the condition $|v| = 2|u| + 2$ implies that the longest $\sigma_E$-palindromic suffix of $uw\Class{n} = \varepsilon$. This is impossible since $d\bar{d}$ is a $\sigma_E$-palindromic suffix of $u\bar{d}$ and $\bar{d}\bar{d} (d\bar{d})^{(g-1)/2 - 1}dd$ is a $\sigma_E$-palindromic suffix of $ud$.
%Hence, $w\Class{n} \neq \bar{d}$, i.e. $w\Class{n} = d$ and
%$$v = (d\bar{d})^{(g-1)/2}(\bar{d}d)^{(g-1)/2}(d\bar{d})^{(g-1)/2}(d\bar{d})^{(g-1)/2}.$$
%But $(\V_1\V_2\cdots\V_{n-2},w\Class{1}w\Class{2}\cdots w\Class{n-2})$ is normalized and all prefixes of $y$ are pseudopalindromes, which implies that $y$ ends with $a$. Hence, $y = (\bar{a}a)^{(g - 1)/2}$. Similarly, since $(\V_1\V_2\cdots\V_{n-1},w\Class{1}w\Class{2}\cdots w\Class{n-1})$ is normalized and $|u| = 2g - 2$, one finds that $u = (\bar{a}a)^{(g-1)/2}(a\bar{a})^{(g-1)/2}$.
%assume that $\V_{n-2} = E$. Since $\V_n = \V_{n-1} = R$ and ...., we conclude that $(\Theta,w)$ ends with $(ERR, a\overline bb)$, with $a \in \A$ and we fall back in case (iv), which concludes the proof.
\end{proof}

The following theorem explains how to replace the forbidden factors in order to normalize a directive bi-sequence.

\begin{theorem}\label{T:reecriture}
  Let $(\Theta, w)$ be a directive bi-sequence, with $\Theta$ a finite or infinite sequence of involutory antimorphisms and $w$ a binary word having same length as $\Theta$. Then there exists a normalized directive bi-sequence  $(\Theta', w')$ such that $\psi_\Theta(w)=\psi_{\Theta'}(w')$. Moreover,  in order to get the normalized directive bi-sequence $(\Theta', w')$ from $(\Theta, w)$, it is sufficient to replace the prefix (if it is of one of the following forms):
  \begin{enumerate}[\rm (i)]
    \item $(RR, a\overline{a})$ by $(RER, a\overline a a)$;
  \item  $(R^{i-1}E, a^i)$ by $(R^iE, a^i \overline a)$;
  \item  $(R^iEE, a^i\overline{a}\,\overline{a})$ by $(R^iERE,a^i\overline a\,  \overline a a)$;
  \end{enumerate}
for $i\geq 1$  and then, to replace from left to right any factor 
\begin{enumerate}[\rm(i)]
  \setcounter{enumi}{3}
  \item $(\V \bar{\V} \bar{\V}, ab\overline b)$ by  $(\V \bar{\V} \V \bar{\V}, ab\overline b b)$,
\end{enumerate}
where $\V \in \{R,E\}$ and $a, b \in \{0,1\}$. 
 \end{theorem}

\begin{proof}
Proposition \ref{L:motifInt} indicates precisely which prefixes and factors cannot occur in a normalized directive bi-sequence, while Lemma \ref{L:not normalized alternate} tells us how to replace  any factor of the form $(\V \bar{\V} \bar{\V}, ab\overline b)$ in order to normalize the directive bi-sequence. It remains to prove how to correct the non-normalized prefixes of the form (i), (ii) and (iii). By Proposition \ref{L:motifInt}, we know that the prefixes $(RER,a\overline a a)$, $(R^iE, a^i \overline a)$ and $(R^iERE, a^i \overline a \, \overline a a)$ are normalized, since they are not in the set of forbidden prefixes and factors.  In order to conclude the proof, we let the reader verify that $\ipal_{RR}(a\overline a)=\ipal_{RER}(a\overline aa)$, $\ipal_{R^{i-1}E}(a^i)=\ipal_{R^iE}(a^i \overline a)$ and $\ipal_{R^iEE}(a^i\overline{a}\,\overline{a})=\ipal_{R^iERE}(a^i\overline a\,  \overline a a)$.
\end{proof}

\begin{example} Let us normalize the directive bi-sequence $d=(RRR,011).$ Since it has a prefix of the form (i) in Theorem \ref{T:reecriture}, we rewrite $d$ as $d'=(RER\cdot R, 010\cdot 1)$, with $(RER, 010)$ normalized. The second step is to replace all the factors of the form $(\V \bar{\V} \bar{\V}, ab\overline b)$ by  $(\V \bar{\V} \V \bar{\V}, ab\overline b b)$. There is only one factor of this form: $(ERR, 101)$. We then obtain the new directive bi-sequence $d''=(RERER, 01010)$, which is normalized. Indeed, one can verify that $d''$ does not contain any forbidden prefix or factor. Finally, $d$ and $d''$ direct the same generalized pseudostandard word:
$$\psi_{RRR}(011)=\underline 0 \, \underline 1 0 \underline 1 0 \quad \text{and} \quad \psi_{RERER}(01010)=\underline 0 \d {\rm 1} \underline 0 \d {\rm 1}  \underline 0.$$ 
\end{example}


%%%%%%%%%%%%%%%%%
\section{A generalization of Justin's formula} \label{S:justin}

The previous section gives us the main tool to prove Theorem \ref{T:main}, that is the existence of the normalization of a directive bi-sequence: Given a generalized pseudostandard word, it is always possible to find a directive bi-sequence that describes all its pseudopalindromic prefixes. 

As pointed out in previous sections, the naive way to compute $\ipal_{\Theta R}(wa)$ (resp., $\ipal_{\Theta E}(wa)$) when $\ipal_\Theta (w)$ is known, is to find the longest palindromic (resp., $E$-palindromic) suffix $p$ of $\ipal_\Theta(w)$ preceded by $a$. Then $\ipal_{\Theta R}(wa) = \ipal_\Theta(w) p^{-1}\ipal_\Theta(w)$ (resp., $\ipal_{\Theta E}(wa) = \ipal_\Theta(w) p^{-1}\overline{\ipal_\Theta(w)}$). However, this turns out to be very costly since at each step, one must find the longest pseudopalindromic suffix of words that grow more and more in size. We are now ready to state and prove one of the main theorem of this paper, thus providing an efficient way to compute binary generalized pseudostandard words.

\begin{theorem}\label{T:main}
Let $(\Theta,w)$ be a normalized finite directive bi-sequence of length $n$ on a binary alphabet and, for $i=1,2,\ldots,n$, let $\ipal_i = \ipal_{\V_1\V_2\cdots\V_i}(w\Class{1 \ldots i})$, $\ipal_0 = \varepsilon$ and $\alpha_i$ be the last letter of $\psi_i$ for $1\leq i \leq n$.
\begin{enumerate}[\rm(i)]
  \item If $|w\Class{1}w\Class{2}\cdots w\Class{n-1}|_{w\Class{n}} = 0$ or $|\V_1\V_2\cdots \V_{n-1}|_{\V_n} = 0$, then 
  $$\ipal_{n} = \begin{cases} \ipal_{n-1} w\Class{n} \ipal_{n-1}, &amp; \mbox{if $\V_n = R$;} \\ \ipal_{n-1}\overline{\ipal_{n-1}}, &amp; \mbox{if $\V_n = E$ and $\alpha_{n-1} \neq w\Class{n}$;} \\ \ipal_{n-1}w\Class{n}\overline{w\Class{n}}\, \overline{\ipal_{n-1}}, &amp; \mbox{if $\V_n = E$ and $\alpha_{n-1} = w\Class{n}$.} \end{cases}$$

    \item If one can write $(\Theta,w) = (\Theta' \V_n \Theta'', w' (\V_{n-1} \circ \V_n)(w\Class{n}) w'')$ such that $i := |w'| = |\Theta'| + 1$ with $|\Theta'|$ maximum, then $$\ipal_n = \ipal_{n-1} (\V_{n-1} \circ \V_n)\left(\ipal_i^{-1} \ipal_{n-1}\right).$$
    \item Otherwise, $$\ipal_{n} = \begin{cases} \ipal_{n-1} \V_n(\ipal_{n-1}), &amp; \mbox{if $\V_n = R$ or $\alpha_{n-1} \neq w\Class{n}$;} \\ \ipal_{n-1}w\Class{n}\bar{w\Class{n}}\,\bar{\ipal_{n-1}}, &amp; \mbox{if $\V_n = E$ and $\alpha_{n-1} = w\Class{n}$.} \end{cases}$$

\end{enumerate}
\end{theorem}

\begin{proof}

(i) Assume first that $w = a^{n-1}\overline{a}$ for some $a \in \A$. Then $\Theta \in \{R^n, R^{n-1}E\}$, otherwise $(\Theta, w)$ would not be normalized by Lemma \ref{L:prefNorm}. The result follows according to the value of $\Theta_n$, $w_n$ and $\alpha_n$. If $|\V_1\V_2\cdots\V_{n-1}|_{\V_n} = 0$ and $|w\Class{1}w\Class{2}\cdots w\Class{n-1}|_{w\Class{n}} \neq 0$, again by Lemma \ref{L:prefNorm},  since $(\Theta, w)$ is normalized, we know that $\V_1 = R$ so that $\V_n = E$, except if $n = 1$. But since no $E$-palindrome occurs as a prefix, and then as a suffix of $\psi_{n-1}$, we deduce that the longest $E$-palindromic suffix of $\ipal_{\V_1\V_2\cdots \V_{n-1}}(w\Class{1}w\Class{2}\cdots w\Class{{n-1}})w\Class{n}$ is either $\varepsilon$ or $\alpha_{n-1}\overline{\alpha_{n-1}}$ and the result follows.

(ii) By hypothesis, there exists a $\V_n$-palindromic prefix $\psi_i$ of $\psi_{n-1}$ followed by the letter $(\V_{n-1} \circ \V_n)(w\Class{n})$. Moreover, since $(\Theta, w)$ is normalized, $|\Theta'|$ is maximum and by its construction, $\psi_i$ is exactly the longest $\V_n$-palindromic prefix of $\psi_{n-1}$ followed by the letter $(\V_{n-1} \circ \V_n)(w\Class{n})$. But $\psi_{n-1}$ is a $\V_{n-1}$-palindrome, so that $\V_{n-1}(\psi_i)$ is the longest $(\V_{n-1} \circ \V_n)$-palindromic suffix of $\psi_{n-1}$ preceded by $\V_n(w\Class{n})$. Then $s = \V_n(w\Class{n})\V_{n-1}(\psi_i)w\Class{n}$ is the longest $\V_n$-palindromic suffix of $\psi_{n-1}w\Class{n}$. Therefore,
\begin{eqnarray}
  \psi_n &amp; = &amp; \psi_{n-1}w\Class{n}(s^{-1})\V_n(w\Class{n})\V_n(\psi_{n-1}) \nonumber \\
&amp; = &amp; \psi_{n-1}w\Class{n} (\V_n(w\Class{n})\V_{n-1}(\psi_i)w\Class{n})^{-1}\V_n(w\Class{n})\V_n(\psi_{n-1}) \label{lgn2} \\
&amp; = &amp; \psi_{n-1}w\Class{n} w\Class{n}^{-1}\V_{n-1}(\psi_i)^{-1}\V_n(w\Class{n})^{-1}\V_n(w\Class{n})\V_n(\psi_{n-1}) \label{lgn3}\\
         &amp; = &amp; \psi_{n-1}\V_{n-1}(\psi_i)^{-1}\V_n(\psi_{n-1}) \label{lgn4} \\
         &amp; = &amp; \psi_{n-1}(\V_{n-1} \circ \V_n)(\psi_i^{-1}\psi_{n-1}), \label{lgn5}
\end{eqnarray}
which concludes this part. Notice that Equation (\ref{lgn3}) is obtained from Equation (\ref{lgn2}), using the fact that for any word $u, v \in \A^*$, $(uv)^{-1}= v^{-1}u^{-1}$, and that Equation (\ref{lgn5}) follows from Equation (\ref{lgn4}), since $\psi_i$ is a $\V_n$-palindrome and $\psi_{n-1}$ is a $\V_{n-1}$-palindrome.

(iii) Since the hypothesis of cases (i) and (ii) are not satisfied, we can assume here that $\psi_{n-1}$ does not have a nonempty $\V_n$-palindromic suffix that is preceded by the letter $\V_n(w\Class{n})$ and that $|w\Class{1}w\Class{2}\cdots w\Class{n-1}|_{w\Class{n}}\geq 1$. Let us first suppose that $\V_n=R$.  Then $w\Class{n}=\alpha_{n-1}$, otherwise we contradict the hypothesis, since it implies that $\psi_{n-1}$ necessarily has a palindromic suffix that is preceded by the letter $\V_n(w\Class{n})=w\Class{n}$, namely a suffix of the form $w\Class{n}\overline {w\Class{n}} ^i$. Thus, $\V_n=R$ implies $w\Class{n}=\alpha_{n-1}$ and consequently, $\psi_{n}=\psi_{n-1}R(\psi_{n-1})$.
Let us now suppose that $\V_n=E$. If $w\Class{n}=\alpha_{n-1}$, one deduces that $\psi_n=\psi_{n-1}w\Class{n} \overline{w\Class{n}}\, \overline {\psi_{n-1}}$, while if $w\Class{n}\neq \alpha_{n-1}$, one obtains $\psi_n=\psi_{n-1}\overline {\psi_{n-1}}$. Combining all those cases yields the statement.
\end{proof}

It is worth mentioning that Proposition \ref{P:justin} is a special case of Theorem \ref{T:main}. Indeed, if $\Theta=R^n$, then $(\Theta, w)$ directs a standard Sturmian sequence and we retrieve case (i) if $w=a^{n-1}\overline a$, for $a \in \{0,1\}$ and then, $\psi_n=\psi_{n-1}w\Class{n}\psi_{n-1}$. Otherwise, case (ii) applies and we get $\psi_n=\psi_{n-1}\psi_i^{-1}\psi_{n-1}$.

On the other hand, if $\Theta=E^n$, the directive bi-sequence $(E^n, w)$ cannot be a normalized one, by  Lemma \ref{L:prefNorm}. In this case, we can use the same idea as in the proof of Theorem \ref{T:main} in order to get the following generalization of Justin's formula for $E$-standard words.

\begin{proposition} Let $(E^{n+1}, wa)$ be a directive bi-sequence of a $E$-standard word, with $w \in \{0,1\}^n$. If $w$ is not $a$-free, then we write $w=v_1 a v_2$ with $v_2$ $a$-free and we have
$$\ipal (wa) =
\begin{cases}
  \ipal(w)a \bar{a} E(\ipal(w)), &amp; \mbox{if $w$ is $a$-free;}\\
  \ipal(w)\ipal(v_1)^{-1}E(\ipal(w)),      &amp; \mbox{otherwise.}
\end{cases}
$$
\end{proposition}

Notice that the algorithms of normalization and of computation of generalized pseudostandard words have been implemented in Python by the first author and should be included soon in the Sage words library \cite{sage}.

To conclude this section, let us see how Theorem \ref{T:main} may be used in order to construct the Thue-Morse word.

\begin{example} Theorem \ref{T:TM} tells us that the Thue-Morse word is a generalized pseudostandard word $T=\psi_{(ER)^\omega}(01^\omega)$. In order to apply Theorem \ref{T:main} to the construction of $T$, we have to normalize the directive bi-sequence $d=((ER)^\omega, 01^\omega)$. Using Theorem \ref{T:reecriture}, we get $d'=((RE)^\omega, 01^\omega)$, which is normalized.  Theorem \ref{T:main} yields the successive prefixes $t_i$ of $T$, with $t_0=\varepsilon$:
\begin{eqnarray*}
  t_1 &amp; = &amp; 0;\\
  t_2 &amp; = &amp; t_1\overline{t_1} = 01, \mbox{by Theorem \ref{T:main} (i), second case;}\\
  t_3 &amp; = &amp; t_2 E(t_0 ^{-1}t_2) = 01 E(01) = 0110, \mbox{by Theorem \ref{T:main} (ii);}\\
  t_4 &amp; = &amp; t_3E(t_3)=01101001, \mbox{by Theorem \ref{T:main} (iii), first case;} \\
  t_5 &amp; = &amp; t_4E(t_4)=0110100101101001, \mbox{by Theorem \ref{T:main} (iii), first case}
\end{eqnarray*}
and so on, which corresponds to the usual construction of the Thue-Morse word.
\end{example}

\section{Rote words} \label{S:rote}

This section is devoted to the study of Rote words obtained by iterated pseudopalindromic closure. They deserve some attention since they provide a natural characterization of the palindromic prefixes in standard Sturmian words. Moreover, their corresponding normalized bi-sequences are easy to characterize. The so-called \emph{Rote words} or \emph{complementary-symmetric words} are sequences of letters having complexity $2n$ and such that their language is closed under the complementation operator. Let $w$ be a binary word on $\{0,1\}$. The \emph{difference of $w$}, denoted by $\Delta(w)$, is the word $v = v_1v_2\cdots v_{|w| - 1}$ defined by
\[v_i = (w_{i+1} - w_i) \bmod 2, \quad \mbox{for $i = 1,2,\ldots,|w| - 2$}.\]
Complementary-symmetric words are connected to Sturmian words by a structural theorem.

\begin{theorem}[Rote~\rm\cite{Rote}] \label{T:rote}
An infinite word $\bw$ is a complementary-symmetric Rote word if and only if the infinite word $\Delta(\bw)$ is a Sturmian word.
\end{theorem}

We say that a complementary-symmetric words $\br$ is a \emph{standard Rote word} if both $0\br$ and $1\br$ are complementary-symmetric words. Equivalently, a word $\br$ is standard Rote if and only if $\Delta(\br)$ is standard Sturmian.

The aim of this section is to provide an explicit construction of standard Rote words by iterated pseudopalindromic closure. The key idea is to exploit the link with Sturmian words by looking at the palindrome and antipalindrome prefixes of the Rote word. First, we state without proof some elementary properties of the operator $\Delta$.

\begin{lemma} \label{L:delta}
  Let $u,v \in \varSigma^*$, where $|u|,|v| \geq 2$. Then
  \begin{enumerate}[\rm(i)]
    \item \label{SL:equal} $\Delta(u) = \Delta(v)$ if and only if $v = u$ or $v = \overline{u}$,
    \item \label{SL:pal or antipal} $u$ is either a palindrome or an antipalindrome if and only if $\Delta(u)$ is a palindrome and 
    \item $u$ is an antipalindrome if and only if $\Delta(u)$ is an odd palindrome with central letter $1$.
\end{enumerate}
\end{lemma}

Now, we study the palindrome prefixes of standard Sturmian words.

For instance, consider the Fibonacci word:
$$\bfi = 010010100100101001010\cdots$$
Its palindrome prefixes are:
$$\varepsilon, 0, 010, 010010, 01001010010, \ldots$$

We may divide them into three categories
\begin{enumerate}[(i)]
  \item palindromes of even length,
  \item palindromes of odd length with central letter $0$ and
  \item palindromes of odd length with central letter $1$.
\end{enumerate}
Thus, we consider a three-letters alphabet $T = \{\a,\e,\o\}$ and we define a map $\Type : \A^* \rightarrow T^*$ by $\Type(\varepsilon) = \e$ and, for $w \in \A^*$ and $\alpha \in \A$,
$$\Type(w\alpha) = \Type(w) \cdot \begin{cases}
  \e, &amp; \mbox{if $\ipal(w\alpha)$ is an even palindrome and;} \\
  \a, &amp; \mbox{if $\ipal(w\alpha)$ is a palindrome with central letter $1$;} \\
  \o, &amp; \mbox{if $\ipal(w\alpha)$ is a palindrome with central letter $0$.}
\end{cases}$$
We call $\Type(w)$ the \emph{palindrome type word} of $w$.

\begin{example}
One may verify that the Fibonacci word $\bfi$ satisfies $\Type(\bfi) = (\e\o\a)^\omega$.
\end{example}

The next proposition establishes an important link between $w$ and $\Type(w)$.

\begin{proposition} \label{P:pal type}
We have $\Type(0) = \e\o$ and $\Type(1) = \e\a$. Let $c, d \in \A$, $u \in \A^*$ and $\Type(uc) = x\alpha\beta$ for $x \in T^*$, $\alpha,\beta \in T$. Then the two last letters of $\Type(ucd)$ are distinct and
\begin{equation} \label{E:type}
\Type(ucd) = \begin{cases}
  x\alpha\beta\alpha, &amp; \mbox{if $c = d$;} \\
  x\alpha\beta\gamma, &amp; \mbox{if $c \neq d$.}
\end{cases}
\end{equation}
where $\gamma$ is the unique letter distinct from $\alpha$ and $\beta$. 
\end{proposition}

\begin{proof}
The proof is done by induction on $|u|$. Clearly, the two palindrome prefixes of $\ipal(0) = 0$ are $\varepsilon, 0$, so that $\Type(0) = \e\o$. Similarly, one notices that $\Type(1) = \e\a$. Now, there are three cases to consider:
\begin{enumerate}[(i)]
  \item Suppose that $c = d$. Then $\ipal(ucd) = \ipal(uc)\ipal(u)^{-1}\ipal(uc)$ by Proposition \ref{P:justin}. Therefore, $|\ipal(ucd)|$ and $|\ipal(u)|$ have same parity. If they are even, then $\Type(ucd)$ ends with $\e\beta\e$. If they are odd, they share the same central letter, so that $\Type(ucd)$ ends with $\alpha\beta\alpha$, where $\alpha \in \{\o,\a\}$. In both cases, by the induction hypothesis, the two last letters of $\Type(uc)$ are distinct, and so are the two last letters of $\Type(ucd)$.
  \item Suppose that $c \neq d$ and $|uc|_d = 0$. Then $\ipal(ucd) = \ipal(uc)d\ipal(uc)$ by Proposition \ref{P:justin}. In particular $|\ipal(ucd)|$ is odd. Moreover, $uc$ is the power of a letter, which means that the previous palindrome prefixes are all powers of the same letter. Hence, one of the two previous palindrome prefixes is of odd length while the other is of even length, so that $\alpha \neq \beta$. Finally, $|\ipal(ucd)|$ is of odd length and has central letter different from all shorter odd palindrome prefixes. Hence, $\gamma \neq \alpha,\beta$, as desired.
  \item Suppose that $c \neq d$ and $|uc|_d &gt; 0$. Write $u = u_1dc^k$ with $u_1 \in \A^*$ and $k$ a non negative integer, so that $ucd = u_1dc^{k+1}d$. Again by Proposition \ref{P:justin}, one deduces $\ipal(ucd) = \ipal(uc)\ipal(u_1)^{-1}\ipal(uc)$, which means that $\ipal(ucd)$ and $\ipal(u_1)$ share the same parity and, if odd, the same central letter. Hence, it suffices to show that $\Type(u_1)$ ends with $\gamma$.

It follows from (i) that $\Type(uc)$ ends with $(\alpha\beta)^{k/2}$ if $k$ is even and with $\beta(\alpha\beta)^{k/2}$ otherwise. Moreover, by the induction hypothesis $\Type(uc)$ ends with $\gamma(\alpha\beta)^{k/2}$ if $k$ is even, or with $\gamma\beta(\alpha\beta)^{k/2}$ otherwise. In both cases, this implies that $\Type(u_1)$ ends with $\gamma$. But $\ipal(u_1)$ and $\ipal(ucd)$ are of the same type, so that $\Type(u_1)$ ends with $\gamma$, as desired. In particular, $\beta$ and $\gamma$ are distinct.
\end{enumerate}
The values of $\Type(uc)$ are represented in Figure \ref{F:pal type tree} for short words.
\end{proof}

\begin{figure}
  \centering
  \includegraphics{tikz-palindrome-type-tree}
  \caption{Representation of Proposition \ref{P:pal type} by a tree, describing the possible palindrome type sequences for any finite binary word. Each node is a couple $(\ipal(w),\Type(w))$, where $w$ is a binary word. For instance, if $w = 010$, then its corresponding node is $(\underline{0}\,\underline{1}\,0\,\underline{0}\,1\,0, \e\o\a\e)$ and one verifies that the palindrome prefixes $\varepsilon$, $0$, $010$ and $010010$ of $\ipal(w)$ are indeed of types $\e$, $\o$, $\a$ and $\e$.}
  \label{F:pal type tree}
\end{figure}

\begin{example} \label{E:prefixes}
Consider once again the Fibonacci word on $\{0,1\}$
$$\bfi = 0100101001001010010\cdots$$
and the Rote word $\br$ starting with $0$ such that $\Delta(\br) = \bfi$
$$\br = 00111001110001100011\cdots$$
By inspection, we may enumerate the palindromic prefixes of $\bfi$, which are in bijections with the palindromic and antipalindromic prefixes of $\br$, except for the empty word prefix of $\br$
\begin{center} \begin{tabular}{&gt;{$}l&lt;{$}|&gt;{$}l&lt;{$}}
  \bfi        &amp; \br \\
  \hline
              &amp; \varepsilon \\
  \varepsilon &amp; 0 \\
  0           &amp; 00 \\
  010         &amp; 0011 \\
  010010      &amp; 0011100 \\
  01001010010 &amp; 001110011100 \\
  \ldots      &amp; \ldots \\
\end{tabular} \end{center}
One may verify that $\br$ is indeed a generalized pseudostandard word:
$$\br = \underline{0} \, \underline{0}\underdot{$1$}1\underline{1}00\underline{1}1100\underdot{$0$}1100011\cdots$$
\end{example}

From now on, we consider only standard Rote word starting with $0$. Since the complement of a Rote word is also a Rote word, it is easy to extend the results to standard Rote words starting with $1$, but for sake of simplicity, we restrict our study by fixing the first letter as $0$. Observations found in Example \ref{E:prefixes} lead naturally to the following statement:

\begin{lemma} \label{L:pal antipal}
Let $\bs$ be a standard Sturmian word and $\br$ be the standard Rote word starting with $0$ such that $\Delta(\br) = \bs$. Let $p_0 = \varepsilon$, $p_1$, $p_2$, $\ldots$ be the palindrome prefixes of $\bs$, enumerated with increasing length, and $q_0 = \varepsilon$, $q_1$, $q_2$, $\ldots$ be the pseudopalindrome prefixes of $\br$, enumerated with increasing length as well. Then $\Delta(q_{i+1}) = p_i$ for all integers $i \geq 0$.
\end{lemma}

\begin{proof}
First, notice that since $\bs$ has infinitely many palindrome prefixes, then $\br$ has infinitely many pseudopalindrome prefixes, in virtue of Lemma \ref{L:delta}(ii).
We proceed by contradiction. Let $i \geq 0$ be the smallest integer such that $\Delta(q_{i+1}) \neq p_i$. We know from Lemma \ref{L:delta}(ii) that $\Delta(q_{i+1})$ is a palindrome. Hence, it means that $\Delta(q_{i+1}) = p_j$ for some integer $j &gt; i$. This is impossible since the prefix $q$ of $\br$ such that $\Delta(q) = p_i$ is a pseudopalindrome, again by Lemma \ref{L:delta}(ii), i.e. there would exist a pseudopalindrome $q$ having length between $|q_i|$ and $|q_{i+1}|$.
\end{proof}

Therefore, standard complementary-symmetric words are generalized pseudostandard words.

\begin{lemma} \label{L:piqi}
Let $\bs$ be a standard Sturmian word directed by some infinite binary sequence $\bx$ and $\br$ be the standard Rote words starting with $0$ such that $\Delta(\br) = \bs$. Then there exists an infinite bi-sequence $(\bTheta,\bw)$ such that $\br = \ipal_\bTheta(\bw)$, i.e. $\br$ is a generalized pseudostandard word.
\end{lemma}

\begin{proof}
As in Lemma \ref{L:pal antipal}, let $p_0 = \varepsilon$, $p_1$, $p_2$, $p_3$, $\ldots$ be the palindrome prefixes of $\bs$ and $q_0 = \varepsilon$, $q_1$, $q_2$, $q_3$, $\ldots$, be the list of pseudopalindrome prefixes of $\br$ enumerated with increasing length. For $i = 0,1,2,\ldots$, let $w_{i+1} = \br\Class{|q_i|+1}$ , i.e. $w_{i+1}$ is the letter following the pseudopalindrome prefix $q_i$. Finally, let
$$\V_i = \begin{cases}
  R, &amp; \mbox{if $q_i$ is an $R$-palindrome;} \\
  E, &amp; \mbox{if $q_i$ is an $E$-palindrome.}
\end{cases}$$
We show that $(\bTheta,\bw) = (\V_1\V_2\V_3\cdots, w_1w_2w_3\cdots)$ is a directive bi-sequence of $\br$. Let $\psi_i = \psi_{\V_1\V_2\cdots\V_i}(w_1w_2\cdots w_i)$ for $i = 1,2,\ldots$.

It suffices to prove that $q_{i+1} = \psi_{i+1}$ for $i = 1,2,\ldots$. Arguing by contradiction, suppose that $i$ is the smallest integer such that $q_i = \ipal_i$ but $q_{i+1} \neq \ipal_{i+1}$. Clearly, $q_{i+1}$ and $\psi_{i+1}$ are both $\V_{i+1}$-palindromes and share the prefix $q_iw_{i+1}$. Therefore, $|\ipal_{i+1}| &lt; |q_{i+1}|$, otherwise $\psi_{i+1}$ would not be the shortest $\V_{i+1}$-palindrome having $q_iw_{i+1} = \psi_iw_{i+1}$. By Lemma \ref{L:piqi}, we have $\Delta(q_{i+1}) = p_i$ which implies that $\Delta(q_iw_{i+1}) = p_{i-1}a$, with $a \in \A$, is a prefix of both $p_i$ and $\Delta(\psi_{i+1})$. But $\Delta(\psi_{i+1})$ is a palindrome and $|\Delta(\psi_{i+1})| &lt; |p_i|$, contradicting the fact that $p_i$ is the shortest palindrome having prefix $p_{i-1}a$.
\end{proof}

\begin{figure}[ht]
  \centering
  \includegraphics{tikz-transducer}
  \caption{Transducer computing the directive bi-sequence of a Rote standard word $\br$ starting with $0$ from the directive sequence of a Sturmian standard word $\bs$ such that $\Delta(\br) = \bs$.}
  \label{F:transducer}
\end{figure}

Consider the transducer $\Transducer$ on $\{0,1\} \times (\{R,E\} \times \{0,1\})$ represented in Figure \ref{F:transducer}. The next lemma states some observations about $\Transducer$.

\begin{lemma} \label{L:transducer}
Let $x = x_1x_2\cdots x_n$ be an input word of length $n \geq 1$ of $\Transducer$ and
$$(\V_1\V_2\cdots\V_n,y_1y_2\cdots y_n)$$
be its associated output word. Let $q=ab\alpha\neq i,q'=cd\beta$ be the two last states visited when reading $x$. Then $c = b$, $\beta = x_n$ and $\Type(x)$ ends with $cd$.
\end{lemma}

\begin{proof}
The proof is done by induction on $n$. For $n = 1$, we have $q = \o\e 0$. There are two cases to consider according to the value of $x_1$. If $x_1 = 0$, then $q' = \e\o0$ so that $c = b = \e$, $\beta = x_1 = 0$ and $\Type(x) = \Type(0) = \e\o$. On the other hand, if $x_1 = 1$, then $q' = \e\a 1$ so that $c = b = \e$, $\beta = x_1 = 1$ and $\Type(x) = \Type(1) = \e\a$.

Consider now the general case. By inspection of $\Transducer$, one observes that $c = b$ and $\beta = x_i$ for any transition, except the one starting with the initial state $i$. The fact that $\Type(x)$ ends with $cd$ follows from inspection of $\Transducer$ and Proposition \ref{P:pal type}.
\end{proof}

We are now ready to show the main theorem of this section. The key idea is to observe that one may derive the directive bi-sequence from the directive sequence of the Sturmian word by looking at the palindrome types ($\a$, $\e$ or $\o$) at each step.

\begin{theorem}
Let $\bx$ be an infinite binary sequence directing some Sturmian word $\bs$ and let $\br$ be the Rote word starting with $0$ and such that $\Delta(\br) = \bs$. Then the output word $(\Theta,\by)$ obtained from $\bx$ in the transducer $\Transducer$ is a directive bi-sequence of $\br$.
\end{theorem}

\begin{proof}
We know from Lemma \ref{L:pal antipal} that the palindrome prefixes of $\bs$ and the pseudopalindromic prefixes of $\br$ are in 1-to-1 correspondence. It only remains to describe the letters and type of pseudopalindromes involved in the iterated pseudopalindromic closure.

For every positive integer $n$, let $x = x_1x_2\cdots x_n$ and $(\Theta,\by) = (\V_1\V_2\cdots \V_n,y_1y_2\cdots y_n)$. Moreover, let $q = ab\alpha$ and $q' = cd\beta$ be the two last states visited when reading $x$. We prove by induction on $n$ that $(\Theta,\by)$ is the output word obtained from $\Transducer$ by reading $x$. This is clear for $n = 1$.

For the general case, we know from Lemma \ref{L:transducer} that $q'$ remembers the two last palindrome type encountered in $\ipal(x)$, i.e. $\Type(x)$ ends with $ab$. Moreover, $c = b$ and $\beta = x_n$. Next, observe that since $\ipal(x)$ is a palindrome of type $c = b$, we deduce by inspection of $\Transducer$ that $\ipal_{\V_1\V_2\cdots\V_n}(y_1y_2\cdots y_n)$ is a $R$-palindrome if $c = b \in \{\o,\e\}$ and is a $E$-palindrome if $c = b = \a$. Finally, one verifies in $\Transducer$ that $y_{n+1} = x_n$ if $c = b \in \{\o,\e\}$ and $y_{n+1} = (x_n + 1) \bmod 2$ if $c = b = \a$.

%Combining these observations, Proposition \ref{P:pal type}, Lemma \ref{L:pal antipal} and inspection of the transducer $\Transducer$ together with Lemma \ref{L:transducer} yields the result.

%First, we show by induction on $n \geq 1$ that $\e\Type(x)$ ends with $ab$. If $n = 1$, then
%$$(x,\Type(x),y,q) \in \{(0;\o;(RR,00),\e\o 0),(1;\a;(RE,01),\e\a 1)\},$$
%as desired. Now assume that this holds for any input word of length less than $n$. Let $q' = cd\beta$, where $c,d \in \{\a,\o,\e\}$ and $\beta \in \{0,1\}$ be the last state visited before $q$ when reading $x$. By the induction hypothesis and in virtue of Proposition \ref{P:pal type}, one concludes that $c = b$, $\beta = x_n$ and $d$ is the last letter of $\Type(x)$ which concludes this part.
% and Lemma \ref{L:pal antipal}
%Let $d_s$ be a finite word of length $n$ on $\{0,1\}$ directing the standard Sturmian prefix $s$. We show by induction on $n$ that the output obtained from $d_s$ in the transducer $\Transducer$ is exactly the prefix $d_r$ of the directive bi-sequence $\bd_\br$ of length $n + 1$. Since the transducer $\Transducer$ is deterministic and the transition function is well-define from every state for both values $0$ and $1$, let $p = (i,d_s,d_r,q)$ be the path of length $n + 1$ obtained by reading $d_s$.
%
%If $n = 0$, then $q = \a\o1$, $d_s = \varepsilon$ and $d_r = (R,0)$, so that $d_r$ is indeed the prefix of length $1$ of $\bd_\br$, since $\br$ starts with $0$ by definition.
%
%Consider now the general case. Let $p' = (i,d'_s,d'_r,q')$ be the path of length $n$ such that $d'_s$ is the prefix of length $n - 1$ of $d_s$, $d'_r$ is the prefix of length $n$ of $d_r$ and $q'$ is the last state visited before $q$ with respect in the path $p$. Finally, let $(\V,\alpha)$ be the last symbol of $d_r$.
%
%It follows from Lemma \ref{L:prefixes} that $\V$ is exactly given by the palindrome type of $\ipal(d_s)$
%Follows from Proposition \ref{P:pal type}. (AJOUTER DES DETAILS)
\end{proof}

\begin{example}
Let $x = 001101$. When reading $x$ in $\Transducer$, one visits states $i$, $\o\e 0 $,  $\e\o 0 $, $\o\e 0$, $\e\a 1$, $\a\e 1$, $\e\o 0$ and $\o\a 1$ and obtains the output word
$$(\V,y) = (RRRERRE,0001001).$$
Moreover,
\begin{eqnarray*}
  \ipal(x) &amp; = &amp; \underline{0}\,\underline{0}\,\underline{1}00\underline{1}00\underline{0}100100\underline{1}000100100 \\
  \ipal_{\V}(y) &amp; = &amp; \underline{0}\,\underline{0}\,\underline{0}\underdot{$1$}11\underline{0}00\underline{0}111000\underdot{$1$}111000111
\end{eqnarray*}
and we indeed have $\Delta(\ipal_\V(y)) = \ipal(x)$.
\end{example}

As a consequence, we have a complete characterization of standard Rote words obtained from iterated pseudopalindromic closure.
\begin{corollary}
Let $(\Theta,w)$ be a directive bi-sequence. Then $\ipal_{\Theta}(w)$ is a standard Rote word if and only if no factor of length $2$ of $(\Theta, w)$ is in the set
$$D = \{(EE,ab) \mid a,b \in \A\} \cup \{(RR,a\bar{a}) \mid a \in \A\} \cup \{(RE,aa) \mid a \in \A\}.$$
Moreover, $(\Theta,w)$ is normalized.
\end{corollary}

\begin{proof}
If $\psi_\Theta(w)$ is a standard Rote word, then it must be obtained from $\Transducer$. But every path of length $2$ in $\Transducer$ yields an output word in
\begin{center} \begin{tabular}{*{3}{&gt;{$}r&lt;{$}}&gt;{$}l&lt;{$}}
\{ (RR,00), &amp; (RR,11), &amp; (RE,01), &amp; (RE,10),\\
   (ER,00), &amp; (ER,01), &amp; (ER,10), &amp; (ER,11)\}. \\
\end{tabular} \end{center}
Conversely, if $(\Theta, w)$ contains a factor in $D$, then it cannot be obtained from $\Transducer$. Hence, the first claim is proved. The fact that $(\Theta,w)$ is normalized follows directly from Proposition \ref{L:motifInt} since all forbidden factors for a bi-sequence do not appear in any output word of $\Transducer$.
\end{proof}


%%%%%%%%%%%%%%%
\section{Concluding remarks}

Theorem \ref{T:main} does not provide the most efficient way of computing the Thue-Morse word. However, it may be very useful for large directive bi-sequences having less regularity. It is also a great tool, combined with the normalization, to compute a generalized pseudostandard word over a two-letter alphabet. 

Algorithm \ref{A:pseudo} takes as input any directive bi-sequence of length $n$ for a two-letter alphabet, normalized or not, and computes, in linear time with respect to the length of the directive bi-sequence, a prefix of the corresponding  generalized pseudostandard word, using both the normalization and the generalization of Justin's formula (Theorem \ref{T:main}) for generalized pseudostandard words. 

\begin{algorithm}[t]
\caption{Computation of a finite generalized pseudostandard word.} \label{A:pseudo}
\centering
\begin{algorithmic}[1] 
{\footnotesize
\Function{IteratedPseudoPalindromicClosure}{$\Theta,w$}
%Le premier if, c'est pour normaliser le prÂŽfixe. Il ne restera qu'Âˆ vÂŽrifier linÂŽairement que la suite directrice ne contient pas le facteur interdit.
\If {$(RR,a\overline a)$ is prefix of $(\Theta, w)$}
\State{ $\Theta \leftarrow RER(RR)^{-1}\Theta, w \leftarrow a\overline a a(a\overline a)^{-1}w$}
\ElsIf{ $(R^{i-1}E, a^i)$ is prefix of $(\Theta, w)$, for some integer $i\geq 1$}
\State{$\Theta \leftarrow R\Theta, w \leftarrow a^i \overline a a^{-i}w$}
\ElsIf{$(R^i EE, a^i \overline a\, \overline a)$ is prefix of $(\Theta, w)$ for some integer $i \geq 1$}
\State {$\Theta \leftarrow R^i ERE (R^i EE)^{-1}\Theta, w \leftarrow a^i \overline a\, \overline a a (a^i \overline a \, \overline a)^{-1}w$}
\EndIf
%on initialise 
\State $\psi_0 \leftarrow \varepsilon$
\For{$i \in \{1,2,\ldots,n\}$}
%On verifie que le facteur $(\V_i \V_{i+1} \V_{i+2}, w[i, i+2])$ n'est pas de la forme interdite Âˆ la position considÂŽrÂŽe
   \If{$i \leq n - 2$ and $(\V_i\V_{i+1}\V_{i+2},w\Class{i \ldots i+2}) \in \{(ERR,ab\overline b), (REE,ab \overline b)\}$, $a,b\in \A$}
\State{$\Theta \leftarrow \V_1\cdots \V_{i+1} \overline \V_{i+1}\V_{i+2}\V_{i+3}\cdots \V_n$, $w \leftarrow w\Class{1 \ldots i+2}\overline{w\Class{i+2}}w\Class{i+3\ldots n}$}
\EndIf
%On calcule la fermeture pseudopal Âˆ la ieme lettre en appliquant le thÂŽorÂme 6.2
\If{$|w\Class{1\ldots i-1}|_{w\Class{i}}=0$ or $|\V_1\cdots \V_{i-1}|_{\V_i}=0$} %cas (i)
\If {$\V_i=R$} $\psi_i \leftarrow \psi_{i-1} w\Class{i} \psi_{i-1}$
\ElsIf{$\V_i=E$ and $\V_{i-1}(w\Class{1})\neq w\Class{i}$} $\psi_i \leftarrow \psi_{i-1} \overline \psi_{i-1}$
\Else ~$\psi_i \leftarrow \psi_{i-1} w\Class{i} \overline{w\Class{i}}\, \overline {\psi_{i-1}}$
\EndIf

\ElsIf{$\exists j$ such that $(\V_1 \cdots \V_i,w\Class{1\ldots i})= (\V_1\cdots \V_j  \V_i \V_{j+2}\V_{j+3}\cdots \V_{i}, w\Class{1\ldots j+1} \V_{i-1} \circ \V_{i}(w\Class{i}) w\Class{j+3\ldots i})$} $\psi_i \leftarrow \psi_{i-1}(\V_{i-1}\circ \V_i)(\psi_j^{-1}\psi_{i-1})$
\Else %cas (iii)
\If{$\V_i=R$ or $\V_{i-1}(w\Class{1}) \neq w\Class{i}$} $\psi_i \leftarrow \psi_{i-1}\V_i(\psi_{i-1})$
\Else ~$\psi_i \leftarrow \psi_{i-1}w\Class{i}(\V_{i-1}\circ \V_i)(w\Class{i} \psi_{i-1})$
\EndIf
\EndIf
\EndFor
\State \Return $\psi_n$
\EndFunction 
}
\end{algorithmic} 
\end{algorithm}


The main results of this paper are the generalization of Justin's formula for generalized pseudostandard words (Theorem \ref{T:main}) over a two-letter alphabet and the characterization of the directive bi-sequences of standard Rote words. They should be of considerable help for future investigations about generalized pseudostandard words. It shall be noted that some stated lemmas could be generalized for words over an alphabet with three or more letters, but it remains an interesting open problem to generalize all of them. 

Another topic of interest would be to compute the maximum complexity of generalized pseudostandard words. Since they include Sturmian words, which have complexity $n + 1$, Rote words of complexity $2n$ and the Thue-Morse word, whose complexity oscillates around $3n$, it seems reasonable to conjecture that it is at most linear. Indeed, empirical observation suggests that, over binary alphabets, no word has a complexity greater than $4n$:
\begin{conjecture} \label{C:4n}
Let $\bw$ be a generalized pseudostandard words over a binary alphabet. Then there exists some integer $n_0$ such that $f_{\bw}(n) \leq 4n$, for all $n \geq n_0$.
\end{conjecture}
Interestingly, the bi-sequence yielding the highest complexity we have been able to provide, so far, is constructed only from forbidden factors as detailed in Proposition \ref{L:motifInt}. For instance, in Sage, we may compute the number of factors of each length between $1$ and $300$ for the prefix of length 5~000 of the word $\ipal_{(REEEEERRRE)^\omega}((0001101011)^\omega)$:

{\scriptsize
\begin{verbatim}
    sage: A = Words([0,1])
    sage: R = WordMorphism({0:0,1:1}, codomain=A)
    sage: E = WordMorphism({0:1,1:0}, codomain=A)
    sage: T = [R,E,E,E,E,E,R,R,R,E] + [R,E,E,E]
    sage: w = A([0,0,0,1,1,0,1,0,1,1] + [0,0,0,1])
    sage: u = iterated_right_palindromic_closure(w,T)
    sage: v = u[:5000]
    sage: [round(float(v.number_of_factors(i)/(4*i)),3) for i in range(1,300)]
    [0.5, 0.5, 0.5, 0.5, 0.5, 0.583, 0.643, 0.688, 0.722, 0.8, 0.864, 0.917, 0.962,
    1.0, 1.033, 1.063, 1.088, 1.111, 1.132, 1.15, 1.167, 1.182, 1.196, 1.208, 1.22,
    1.212, 1.204, 1.196, 1.19, 1.183, 1.177, 1.172, 1.167, 1.162, 1.157, 1.153,
    1.149, 1.145, 1.141, 1.137, 1.134, 1.131, 1.128, 1.125, 1.122, 1.12, 1.117,
    1.115, 1.112, 1.11, 1.108, 1.106, 1.104, 1.102, 1.1, 1.098, 1.096, 1.095,
    1.093, 1.092, 1.09, 1.089, 1.087, 1.086, 1.085, 1.083, 1.082, 1.081, 1.08,
    1.079, 1.077, 1.076, 1.075, 1.074, 1.073, 1.072, 1.071, 1.071, 1.07, 1.069,
    1.068, 1.067, 1.066, 1.065, 1.065, 1.064, 1.063, 1.063, 1.062, 1.061, 1.06,
    1.06, 1.059, 1.059, 1.058, 1.057, 1.057, 1.056, 1.056, 1.055, 1.054, 1.054,
    1.053, 1.053, 1.052, 1.052, 1.051, 1.051, 1.05, 1.05, 1.05, 1.049, 1.049,
    1.048, 1.048, 1.047, 1.047, 1.047, 1.046, 1.046, 1.045, 1.045, 1.045, 1.044,
    1.044, 1.044, 1.043, 1.043, 1.043, 1.042, 1.042, 1.042, 1.041, 1.041, 1.041,
    1.04, 1.04, 1.04, 1.04, 1.039, 1.039, 1.039, 1.038, 1.038, 1.038, 1.038, 1.037,
    1.037, 1.037, 1.037, 1.036, 1.036, 1.036, 1.036, 1.035, 1.035, 1.035, 1.035,
    1.035, 1.034, 1.034, 1.034, 1.034, 1.034, 1.033, 1.033, 1.033, 1.033, 1.033,
    1.032, 1.032, 1.032, 1.032, 1.032, 1.031, 1.031, 1.031, 1.031, 1.031, 1.031,
    1.03, 1.03, 1.03, 1.03, 1.03, 1.03, 1.029, 1.029, 1.029, 1.029, 1.029, 1.029,
    1.028, 1.028, 1.028, 1.028, 1.028, 1.028, 1.028, 1.027, 1.027, 1.027, 1.027,
    1.027, 1.027, 1.027, 1.027, 1.026, 1.026, 1.026, 1.024, 1.021, 1.019, 1.016,
    1.014, 1.012, 1.009, 1.007, 1.005, 1.002, 1.0, 0.998, 0.996, 0.993, 0.991,
    0.989, 0.987, 0.985, 0.983, 0.98, 0.978, 0.976, 0.974, 0.972, 0.97, 0.968,
    0.966, 0.964, 0.962, 0.96, 0.959, 0.957, 0.955, 0.953, 0.951, 0.949, 0.947,
    0.946, 0.944, 0.942, 0.94, 0.938, 0.937, 0.935, 0.933, 0.932, 0.93, 0.928,
    0.927, 0.925, 0.923, 0.922, 0.92, 0.919, 0.917, 0.915, 0.914, 0.912, 0.911,
    0.909, 0.908, 0.906, 0.905, 0.903, 0.902, 0.9, 0.899, 0.897, 0.896, 0.895,
    0.893, 0.892, 0.89, 0.889, 0.888, 0.886, 0.885, 0.884, 0.882, 0.881, 0.88,
    0.878, 0.877, 0.876, 0.875, 0.873, 0.872, 0.871, 0.87]
\end{verbatim}
}
Observe that the $f(n)$ may be greater than $4n$ up to $n = 200$, but it then decreases beyond $4n$, suggesting Conjecture \ref{C:4n}.

\section{Acknowledgement}
The authors wish to thank the referees for a number of comments and suggestions that have led to improvements in this paper.

\begin{thebibliography}{99}

\bibitem{dlt2012} A. Blondin Mass\'e,
S. Gaboury, and S. Hall\'e, Pseudoperiodic words, in \textit{DLT'2012 -
16th International Conference on Developments in Language Theory
(Taipei, Taiwan) August 14--17}, Lect. Notes in Comp. Sci.,
Vol.\ 7410, Springer, 2012, pp.\ 308--331.

\bibitem{BlondinMassePaquinVuillon2010} A. Blondin Mass\'e, G. Paquin
and L. Vuillon, A Fine and Wilf's theorem for pseudoperiods and
Justin's formula for generalized pseudostandard words, in \textit{JM'2010
- 13th Mons Theoretical Computer Science Days}, 2010.  Available
at \url{http://tinyurl.com/bbqxtou}.

\bibitem{lacim2010} A. Blondin Mass\'e, and L. Vuillon, Generalized
pseudostandard words having complexity $2n$, in \textit{LaCIM'2010 - 20th
Anniversary of the Laboratoire de combinatoire et d'informatique
math\'ematique}, 2010.

\bibitem{BuccideLucaDeLucaZamboni20082} M. Bucci, A. de Luca, A. De
Luca, and L. Q. Zamboni, On different generalizations of episturmian
words, \textit{Theor. Comput. Sci.}, \textbf{393} (2008)
23--36.

\bibitem{BuccideLucaDeLucaZamboni2008} M. Bucci, A. de Luca, A. De
Luca, and L. Q. Zamboni, On some problems related to palindromic
closure, \textit{RAIRO-Theor. Inf. and Appl.}, \textbf{42} (2008),
679--700.

\bibitem{Czeizler2009} E. Czeizler, E. Czeizler, L. Kari, and S. Seki,
An extension of the Lyndon Sch\"{u}tzenberger result to pseudoperiodic
words, in \textit{DLT '09: Proceedings of the 13th International
Conference on Developments in Language Theory}, Springer-Verlag, 
2009, pp.\ 183--194.

\bibitem{deLuca1997} A. de Luca, Sturmian words: structure,
combinatorics, and their arithmetics, \textit{Theor. Comput.
Sci.} \textbf{183} (1997),  45--82.

\bibitem{deLucaDeLuca2006} A. de Luca, and A. De Luca, Pseudopalindrome
closure operators in free monoids, {\it Theor. Comput. Sci.}
\textbf{362} (2006), 45--82.

\bibitem{DroubayJustinPirillo2001} X. Droubay, J. Justin, and G.
Pirillo, Episturmian words and some constructions of de Luca and Rauzy,
\textit{Theor. Comput. Sci.}, \textbf{255} (2001), 539--553.

\bibitem{GlenJustin2009} A. Glen, and J. Justin, Episturmian words: a
survey, \textit{RAIRO Theor. Info. Appl.}, \textbf{43}
(2009) 402--433.

\bibitem{JametPaquinRichommeVuillon2010} D. Jamet, G. Paquin, G.
Richomme and L. Vuillon, On the fixed points of the iterated
pseudopalindromic closure, in \textit{WORDS'09 - 7th International
Conference on Words}, 2010, Paper 122.

\bibitem{Justin2005} J. Justin, Episturmian morphisms and a Galois
theorem on continued fractions, \textit{RAIRO Theor. Info. Appl.},
\textbf{39} (2005), 207--215.

\bibitem{Lothaire2002} M. Lothaire, {\it Algebraic Combinatorics on Words},
Vol.\ 90,
Encyclopedia of Mathematics and its Applications, Cambridge
University Press, 2002.

\bibitem{manea} F. Manea, R. Merca\c{s} and D. Nowotka, Fine and Wilf's
theorem and pseudo-repetitions, in B. Rovan, V. Sassone, and P. Widmayer,
eds., \textit{MFCS 2012:  Mathematical Foundations of
Computer Science}, Lecture Notes in Computer Science, Vol.\ 7464,
Springer-Verlag, 2012, pp.\ 
668--680.

\bibitem{Rote} G. Rote, Sequences with subword complexity $2n$,
\textit{J. Number Theory}, \textbf{46} (1994), 196--213.

\bibitem{sage} W. A. Stein et al., Sage Mathematics Software
(Version 4.3.3), The Sage Development Team (2010),
\url{http://www.sagemath.org}.

\end{thebibliography}

\bigskip
\hrule
\bigskip

\noindent 2010 \textit{Mathematics Subject Classification}:  
Primary 68R15; Secondary 05A05, 37E05.

\noindent \textit{Keywords}: palindrome, pseudopalindrome, iterated
pseudopalindromic closure, generalized pseudostandard word,
normalization, directive bi-sequence, Justin's formula, Fine and Wilf
theorem. 

\bigskip
\hrule
\bigskip

\vspace*{+.1in}
\noindent
Received July 4 2012;
revised version received January 1 2013.
Published in {\it Journal of Integer Sequences}, March 2 2013.

\bigskip
\hrule
\bigskip

\noindent
Return to
\htmladdnormallink{Journal of Integer Sequences home page}{http://www.cs.uwaterloo.ca/journals/JIS/}.
\vskip .1in


\end{document}

                                                                                

</pre></body></html>