\section{Introduction}

Symmetry-breaking phase transition is of great interest in various fields, ranging from cosmology to condensed matter \cite{Kibble1976, Zurek1985, Hendry1994, Weiler2008, Monaco2009, DelCampo2010, Ulm2013, Pyka2013, Deutschlander2015, Fowler2017, Bowick1994, Chuang1991, Chuang1991a}. When a system undergoes a phase transition from higher to lower symmetry phases, different regions of broken symmetries appear. If the symmetries of adjacent domains are incompatible, topological defects may form at their boundaries. Kibble \cite{Kibble1976} and Zurek \cite{Zurek1985} proposed a theoretical model to statistically understand the dynamics of defect formation and annihilation, utilizing the examples of cosmic string formation in the universe and superfluid phase transition in helium, respectively. The resulting scaling laws connect the density of defects and phase transition rate. Regardless of a system's nature, various experimental systems have validated the Kibble-Zurek mechanism and scaling laws: superfluids \cite{Hendry1994} and superconductors \cite{Monaco2009} to laser-cooled ion crystals \cite{DelCampo2010, Ulm2013, Pyka2013}, trapped atom gas \cite{Weiler2008}, and two-dimensional colloidal systems \cite{Deutschlander2015}.

Nematic liquid crystals (LCs) have been a popular system for studying the formation of domains and accompanying defects involved in phase transitions. Nematic LC with no long-range positional ordering, but the orientational order is arguably the simplest partially ordered matter and allows a facile observation of topological defects under optical microscopes. Thus, it is one of the earliest experimental systems verifying the Kibble-Zurek mechanism \cite{Chuang1991, Chuang1991a, Bowick1994}. Specifically, the formation and evolution of strings, monopoles, and textures in nematic LC films have been observed, and the Kibble-Zurek scaling laws successfully describe the relation between the defects density and the cooling rate \cite{Chuang1991,Bowick1994, Bradac2002, Fowler2017}. In the same vein, water-based lyotropic chromonic liquid crystals (LCLCs) with a broad isotropic-nematic coexistence regime have been employed to investigate the morphogenesis of nematic tactoids and defects formation by coalescence of the tactoids \cite{Kim2013,Wang2018,Golovaty2020}.

In this work, we introduce a one-dimensional (1D) model system to investigate how domains and defects form, evolve, and annihilate. We utilize a cylindrically confined LCLC exhibiting the double-twist director configuration. A train of right- or left-handed domains is formed with topological defects between two adjacent domains of different handedness. Upon quenching from the isotropic to nematic phase, we observe nematic tactoids' nucleation, growth, and coalescence to form the train of domains with alternating handedness, reminiscing the Kibble-Zurek mechanism\cite{Kim2013} and 1D Ising model. Taking advantage of the 1D system, we investigate how the domains get coarsened by lowering the system's elastic free energy. Lastly, to justify an early-stage domain-size distribution, we propose a statistical distribution best describing our experimentally observed domain-size distribution and a theoretical model considering a stochastic merging of pre-domains.

\section{Results and Discussion}

\begin{figure*}[t]
\centering
\includegraphics{Defect_type.eps}
\caption{\label{fig:formationtype}
Defects formation in cylindrically confined nematic DSCG. (a) and (b) Time-lapse polarized optical microscopy (POM) images of the 14.0\% (wt/wt) DSCG between crossed polarizers with a full-wave plate during the isotropic-to-nematic phase transition at different cooling rates: (a) 2$^{\circ}$C/min, (b) 20$^{\circ}$C/min. Yellow arrows represent pass axes of the polarizers, and a tilted blue arrow corresponds to the slow axis of the full-wave plate of 550-nm retardance, inserted before the analyzer. All scale bars are 100 $\mu$m. White texts correspond to the time elapsed after cooling. (c) POM images of three types of defects after relaxation: point (Top), domain wall (Middle), and disclination ring (Bottom). (d) Schematic diagram of the DT director configuration with the disclination ring. Rods representing the nematic director are color-coded according to the angle between the capillary axis and the director. Here red- and blue-shaded regions correspond to right- and left-handed domains, respectively, according to the right-hand rule. The black circle represents the disclination-ring defect.
}
\end{figure*}

\subsection{Formation of Double-twist Domains and Time Evolution of Their Size Distribution}

Our model system is a cylindrically confined nematic LCLC having the double-twist (DT) director configuration. Nematic LCLCs have unusual elastic properties of LCLC, such as giant elastic anisotropy and large saddle-splay modulus \cite{Zhou2012, Zhou2014, Nayani2015, Davidson2015, long2022violation}, which often give rise to chiral symmetry breaking of the director configurations under confinement despite their achiral building blocks \cite{Tortora2011, Jeong2014, Jeong2015, Davidson2015, Nayani2015, nayani2017using, fu2017spontaneous, Javadi2018, Eun2019, srinivasarao2021spontaneous}. Specifically, the nematic disodium cromoglycate (DSCG)---a representative LCLC---exhibits spontaneous chiral symmetry breaking to form the DT structure when confined in cylindrical capillaries with degenerate planar anchoring \cite{Nayani2015, Eun2019}. The directors of the DT configuration twist along the capillary radius while the directors at the capillary center lie along the capillary axis \cite{Davidson2015, Nayani2015, Eun2019}. The large saddle-splay modulus lowers the total elastic free energy by making the surface directors at the inner capillary wall align along the circumferential direction \cite{koning2014saddle,Selinger2018}. The resultant DT configurations with the right- and left-handed twist have the same energy. Thus, domains of different handednesses coexist in a capillary with the same appearance probability $P$ ($P_{\mathrm{Right}}=P_{\mathrm{Left}}=1/2$). There is a topological defect between two domains of different handedness.

\begin{figure*}[t]
\centering
\includegraphics{defstat.eps}
\caption{\label{fig:defstat}
Comparison of the appearance probability of each defect type according to the cooling rate and the capillary size. We investigate the types and number of defect in capillaries of four different diameters, ranging from 50 to 200 $\mu$m. The numbers above each column indicate the total number of defects investigated; ``n/a'' means that the number is not available because we did not count them. ``Ambient'' data are from the capillaries after injecting room-temperature nematic DSCG without heating and cooling procedure, and these capillaries exhibit only ``wall'' defect. See Fig.~\ref{fig:formationtype}(c) for the types of defects. The fast and slow cooling correspond to 2 and 20$^{\circ}$C/min, respectively.
}
\end{figure*}

\begin{figure*}[t]
\centering
\includegraphics{CDF.eps}
\caption{\label{fig:tevolcdf}
Statistical characterization of the time-evolving distribution of domain sizes. The specimen is 14.0\% (wt/wt) DSCG in 100 $\mu$m-diameter cylindrical capillary after a fast cooling at the rate of 20$^{\circ}$C/min. (a) Time-lapse POM images of the DT configuration with ring defects separating the domains of opposite handedness. The scale bar is 200 $\mu$m, and polarizer axes are represented by double arrows. (b) The experimentally measured cumulative distribution function of non-dimensionalized domain sizes $\tilde{l}=l/D$ (colored solid lines). Each black dashed line corresponds to the best fit to each data with the three-parameter log-normal distribution function. An inset shows the probability distribution function of representative data at 3 hours. The data is taken from five independent experiments, and each experiment investigates six capillaries of approximately 30 mm in length at the designated time interval. (c) The total number of domains in a single experiment with six capillaries as a function of time. The symbols show the average values of the five independent experiments, and the error bar is the standard deviation. (d)-(f) The fitting parameters of the three-parameter log-normal fittings in (b): (d) mean $\tilde{l}_c$, (e) standard deviation $\tilde{l}_w$, and (f) cutoff $\tilde{l}_0$ of the logarithm of non-dimensionalized domain size $\tilde{l}$. See Eq. (\ref{eq:lncdf}) for the distribution function.
}
\end{figure*}

The domain formation process and resulting defect density strongly depend on the rate of isotropic-nematic phase transition before the nematic DT configuration forms. Fig. \ref{fig:formationtype} (a) and (b) compare two experiments of phase transition from the isotropic (45$^{\circ}$C) to nematic (21.5$^{\circ}$C) phase with different cooling rates, 2 and 20$^{\circ}$C/min, respectively. Fig. \ref{fig:formationtype}(a) shows how the nematic DT domains form at the cooling rate of 2$^{\circ}$C/min. Entering the isotropic-nematic coexistence phase upon cooling from the isotropic phase, a nematic shell grows from the capillary wall. However, as shown in Fig. \ref{fig:formationtype}(b) with the cooling rate of 20$^{\circ}$C/min, the nematic shell grows from the capillary wall, and also nematic droplets appear and grow in bulk, simultaneously \cite{Javadi2018}. The nematic texture relaxes over time to form one-dimensional (1D) DT domains eventually, while nematic domains merge and annihilate. In our experimental conditions with the glass capillary of 100-$\mu$m inner diameter, it takes approximately three hours to clearly identify defect-separated 1D domains of different twist-handedness. The linear defect density in the slow-cooling case, \textit{i.e.}, the number of defects per unit capillary length, is over ten times smaller than the density in the fast-cooling case.

This observation that slow cooling leads to larger domains than fast cooling reminisces the scaling laws in the Kibble-Zurek mechanism, but the systematic study of the Kibble-Zurek scaling law under this confinement can be pointless. As shown in Fig. \ref{fig:formationtype} (a) and (b), the nematic droplets formed only in the fast-cooling case make the texture more disordered than in the slow-cooling case, presumably resulting in the shorter domains. On the other hand, during the droplet-free slow cooling, the Rayleigh-Plateau instability of the confinement-induced cylindrical core-shell interface seems to play a major role in the determination of the domain sizes \cite{Javadi2018}. This indicates that the mechanism of the domain formation can differ by the cooling rate, thus making it difficult to expect a single governing scaling. Furthermore, because acquiring a statistically meaningful number of domains by slow cooling is impractical, we mainly study the fast-cooling case.

In DSCG's nematic DT configuration, we identify three different types of defects between neighboring domains. A previous study presents that energetics chooses the type of the defect separating the adjacent domains of opposite handednesses: either a point defect or a domain wall \cite{Davidson2015}. For instance, only point defects have been observed in another representative LCLC, Sunset Yellow (SSY) \cite{Davidson2015}. However, we find that three distinct types can appear in our 14.0\% (wt/wt) DSCG: point, domain wall, and disclination ring as shown in Fig. \ref{fig:formationtype}(c), and their appearance probability depends on factors such as capillary size and cooling rate. Fig.~\ref{fig:defstat} compares the experimentally measured appearance probability of each defect type. In this work which focuses on 100 $\mu$m-diameter capillaries filled with 14.0\% (wt/wt) DSCG quenched at the rate of 20$^{\circ}$C/min, the disclination ring shown at the bottom row of Fig. \ref{fig:formationtype}(c) is the dominant type of defect with the appearance probability greater than 95\% \cite{Eun2019}. This type of defect is not observed in SSY, and Fig. \ref{fig:formationtype}(d) sketches its proposed director configuration. Note that we sometimes observe the domain-wall defect (the middle row of Fig. \ref{fig:formationtype}(c)), which is not observed in SSY, and the DSCG's point defect (the top row of Fig. \ref{fig:formationtype}(c)) is similar but different from the one in SSY because of their broken symmetry. The defect energetics in DSCG requires further investigation in the future.

Utilizing the 1D model domains, we investigate the domain-size distribution of the fast-cooling case and its time evolution during which the domains coarsen by merging of defects as shown in Fig. \ref{fig:tevolcdf}(a). For better statistics, we simultaneously observe six different capillaries after quenching them on the same temperature-controlled slide glass, and domains in all six capillaries are analyzed as one data set. The domains from the six capillaries span $\sim$165 mm in the capillary length, and there are approximately five hundred defects after three hours of relaxation from the quenching. We observe that the domain and defect arrangements before and after the heating-and-cooling process are independent, meaning that we can erase the information via the temperature cycle and conduct independent experiments multiple times with the same specimen. Therefore, repeating the same temperature experiments, we acquire five independent data sets. Note that we study only the fast-cooling data for the size-distribution study. It is because the defect density in the slow-cooling case is too low to analyze the domain-size distribution statistically, \textit{i.e.}, ten times smaller than the fast-cooling case.

We estimate the distribution of the dimensionless domain length $\tilde{l}$ at different times after the quenching. The length $l$ of a single domain is obtained by measuring the distance between two neighboring defects as described in Materials and Methods and is non-dimensionalized in units of the capillary diameter ($D$ = 100 $\mu$m), \textit{i.e.,} $\tilde{l}=l/D$. Fig. \ref{fig:tevolcdf}(b) shows the cumulative distribution function (CDF) of $\tilde{l}$ in all combined five data sets; The inset shows a probability distribution function (PDF) after three hours from the cooling, which is right-skewed. The coarsening shown in Fig. \ref{fig:tevolcdf}(a) is evident in the time evolution of CDF, \textit{i.e.,} the curve shifting toward the longer $\tilde{l}$ as time goes by. Fig. \ref{fig:tevolcdf}(c) shows how the number of defects, $N$, decreases during the coarsening as a function of time. The driving force of this coarsening process is the defects' elastic energy penalty; defects annihilation by merging them can lower the total energy of the system \cite{Jeong2015}. In this work, we focus on understanding the domain-size distribution from the statistical point of view, not the energetics of defect annihilation.

\subsection{Theoretical Understanding of Domain-Size Distribution}

To understand the observed domain-size distribution, we propose a theoretical model based on a stochastic merging of neighboring domains. As shown in Fig. \ref{fig:formationtype} (b), when the system enters the isotropic-nematic coexistence phase from the isotropic phase by quenching, the nematic droplets nucleate, grow, and coalesce to form the train of 1D domains shown in Fig. \ref{fig:tevolcdf}(a). We assume that the droplets have twisted bipolar director configuration, and their probability of having either right or left-handedness is $1/2$ because of the achiral nature of the LCLC \cite{Jeong2014}. If adjacent droplets as `pre-domains' have the same handedness, they merge to form a longer domain. Otherwise, they become two separate domains with a defect between them. Thus, the sizes of the pre-domains and their stochastic merging determine the number and sizes of the domains.

Although the actual merging and relaxation process seems complicated, as shown in Fig. \ref{fig:formationtype}(b), we assume that stochastic merging of 1D pre-domains having a certain length distribution determines the DT domain-size distribution at the early stage shown in the top panel of Fig. \ref{fig:tevolcdf}(a). The 1D pre-domain's non-dimensionalized size $\tilde{x}_{\mathrm{pre}} = x_{\mathrm{pre}}/D$ as a random variable has a probability distribution function (PDF) $f(\tilde{x}_{\mathrm{pre}})$; $x_{\mathrm{pre}}$ and $D$ are the length and diameter of a cylindrical pre-domain, respectively. Since the size $\tilde{x}$ as a dimensionless length is linearly additive, the dimensionless size of a `domain' by the merging of $n$ pre-domains is a random variable $\tilde{l}(n)=\sum_{i=1}^{n} \tilde{x}_{i,\mathrm{pre}}$, where the size of $i$th pre-domain is $\tilde{x}_{i,\mathrm{pre}}$ as an independent random variable. Then, the domain-size PDF $f(\tilde{l})$ is a mixture distribution $f(\tilde{l}) = \sum_{n=1}^{\infty} P(n)~f(\tilde{l}(n))$ with a PDF $f(\tilde{l}(n))$ of the random variable $\tilde{l}(n)$ and the probability $P(n)$ of having a merged domain by $n$ consecutive pre-domains. The probability $P(n)$ as a weighting factor should satisfy $\sum_{n=1}^{\infty} P(n)=1$. Given that the probability of having a left-handed pre-domain is $p$ and $1-p$ for the right-handed one, $P_{\mathrm{Left}}(n)$ is the probability of having $(n-1)$ consecutive left-handed pre-domains that follow a given left-handed pre-domain as a starting point of the domain. Additionally, the $(n-1)$ pre-domains should be followed by a right-handed pre-domain as a starting point of a new right-handed adjacent domain. This gives $P_{\mathrm{Left}}(n)=1 \times p^{n-1} \times (1-p)$, and $P(n)=(\frac{1}{2})^{n}$ for the equally probable left- and right-handedness.

\begin{figure}
\centering
\includegraphics{Model.eps}
\caption{\label{fig:compcdf}
Comparison of experimental (a) CDF and (b) PDF of non-dimensionalized domain sizes (gray solid fill) with the three-parameter log-normal fittings (red dashed line) and our theoretical model based on a  stochastic merging (blue dotted line). The experimental data is the 3-hour data in Fig. \ref{fig:tevolcdf}(b).
}
\end{figure}

We find that pre-domains having the normal size distribution can simulate approximately the experimentally measured domain-size distribution. Inspired by our experimental observation that the nucleated nematic droplets have a quite uniform size with some variation as shown in Fig. \ref{fig:formationtype}(b), we try $\tilde{x}_{\mathrm{pre}}\sim \mathcal{N}(\mu,\,\sigma^{2})$, where $\mu$ and $\sigma$ are mean and standard deviation of the normal distribution $\mathcal{N}$, respectively. Then, we have $\tilde{l}(n)=\sum_{i=1}^{n} \tilde{x}_{i,\mathrm{pre}} \sim \mathcal{N}(n \mu,\,n \sigma^{2})$ and
\begin{equation} \label{eq:sumCDF}
F(\tilde{l})=\sum_{n=1}^{\infty} P(n)~F_{\mathcal{N}} (\tilde{l}(n)) = \sum_{n=1}^{\infty} \frac{\left[1+\textrm{erf}\left(\frac{\tilde{x}-\mu n}{\sigma \sqrt{2n}}\right)\right]}{2^{n+1}},
\end{equation}
where $F_{\mathcal{N}}(\tilde{l}(n))$ is a cumulative distribution function (CDF) of $\mathcal{N}(n \mu,\,n \sigma^{2})$ and $F(\tilde{l})$ is the CDF of the domain-size distribution with $P(n)=(\frac{1}{2})^{n}$. In Fig. \ref{fig:compcdf}, we compare our experimental data and Eq. \ref{eq:sumCDF} to find $\mu$ and $\sigma$ numerically. With the cutoff $n_{\mathrm{max}} = 10$, $\mu = 1.693~\pm~0.004 $ and $\sigma = 0.518~\pm~0.011$ best describe the experimental data in the CDF plot shown in Fig. \ref{fig:compcdf}(a); Fig. \ref{fig:compcdf}(b) shows the fitting in the PDF plot. Instead of $\tilde{x}_{\mathrm{pre}}\sim \mathcal{N}(\mu,\,\sigma^{2})$, one may try other distributions guaranteeing positive domain size, such as Weibull or truncated normal distribution, we still find numerical similarity between the resulting CDF and experimental data (data not shown here). Note also that this comparison is only for the domain-size distribution at the early stage, i.e., the first snapshot after the relaxation into the DT configuration, because the time evolution of the distribution afterwards will be determined by the elasticity-driven interaction between the defects and resultant domain coarsening, not by the merging of pre-domains.

We find that all experimental CDFs can be approximated to the log-normal distribution's CDF (see Statistical Tests section under Materials and Methods). The dashed lines in Fig. \ref{fig:tevolcdf}(b) are the log-normal distribution fits to the time-varying experimental CDFs, and the fitting parameters are shown in in Fig. \ref{fig:tevolcdf}(d-f). The log-normal distribution is a continuous probability distribution of a random variable, whose logarithm follows the normal distribution. This log-normal nature is frequently observed in various systems such as aerosol droplets, bacteria division, avalanche processes in cells \cite{Sangal1970,Hosoda2011,Polizzi2021}. We adopt the CDF of the 3-parameter log-normal distribution

\begin{equation}
\label{eq:lncdf}
F_{\mathrm{log-normal}}(\tilde{l})=\int_{\tilde{l}_0}^{\tilde{l}}\frac{1}{\sqrt{2\pi}\tilde{l}_{\mathrm{w}} t}\exp\left(\frac{(\ln (t-\tilde{l}_0)-\tilde{l}_{\mathrm{c}})^{2}}{2\tilde{l}_{\mathrm{w}}^2}\right)dt,
\end{equation}
where $\tilde{l}_{\mathrm{c}}$ and $\tilde{l}_{\mathrm{w}}$ correspond to the mean and standard deviation of the logarithm of non-dimensionalized domain size $\tilde{l}$ after subtracting the offset $\tilde{l}_0$. As shown in Fig. \ref{fig:tevolcdf} (d-f), both $\tilde{l}_{\mathrm{c}}$ and $\tilde{l}_{\mathrm{w}}$ according to Eq. \ref{eq:lncdf} monotonically increase as time passes. $\tilde{l}_{\mathrm{c}}$ increases because the average domain size gets larger while the number of defects decreases as they annihilate by merging (See Fig. \ref{fig:tevolcdf}(a)). Note that, even at the later stage with the larger $\tilde{l}_{\mathrm{c}}$, there still exist short domains since the coarsening keeps occurring, which results in the large variance in the domain size $\tilde{l}_{\mathrm{w}}$. On the other hand, we see no consistent trend in change of $\tilde{l}_0$. Theoretically, domains shorter than $\tilde{l}_0$ should not exist. The experimental interpretation of $\tilde{l}_0$ is that domains shorter than $\tilde{l}_0$ is hardly observed because the neighboring defects at a short separation quickly annihilate by merging. This cutoff is determined by the energetics, which does not depend on time. Therefore, $\tilde{l}_0$ remains almost constant throughout the experiments.

\begin{figure*}[t]
\centering
\includegraphics{SI.eps}
\caption{\label{fig:COD_KS_QQ}
Two statistical tests to find the best fit to the experimental domain-size distribution shown in Fig. \ref{fig:tevolcdf}(b). Using eight right-skewed trial probability distribution functions, we evaluate (a) Coefficient of determination $R^2$ with (b) the enlarged view of the region around $R^2=1$. (b) Kolmogorov-Smirnov test statistics $KS$ of the eight trial functions. (c) Quantile-Quantile plot of the three-parameter log-normal distribution in the logarithmic scale. LN, LL, and W stand for the log-normal, log-logistic, and Weibull distributions, respectively. The following number, \textit{i.e.}, 2 or 3, indicates the number of parameters. F is for the Fr\'echet distribution with three parameters and, G for the gamma distribution with two parameters.
}
\end{figure*}

\section{Materials and Methods}

\subsection{Sample Preparation}
Disodium cromoglycate (DSCG, purity of 95\%), acquired from Sigma-Aldrich is used without further purification. By dissolving DSCG into deionized water (18.2 M$\Omega~$cm), we prepare the 14.0\% (wt/wt) DSCG solution. We fill this solution into a cylindrical glass capillary (CV1017, Vitrocom) of 100-$\mu$m inner diameter with $\pm$10\% tolerance, at the room temperature of 22$\pm$2$^{\circ}$C with no surface treatment of the capillary. The DSCG-filled capillaries are put on a slide glass and capillaries' both ends are sealed with epoxy to minimize water evaporation during experiments. We place a coverslip on top of the capillaries and fill the space between the slide glass and coverslip with an index-matching oil (n = 1.474 at 589.3 nm, Cargille Labs).

\subsection{Optical Microscopy}
We observe the slide on a temperature controller (T95-PE120, Linkam) using a polarized optical microscope (BX53-P, Olympus). First, the sample is heated to 45.0$^{\circ}$C at the rate of 20$^{\circ}$C/min, and nematic DSCG melts into the complete isotropic phase. After incubating the sample for ten minutes at 45.0$^{\circ}$C, we decrease the sample's temperature to 21.5$^{\circ}$C while controlling the cooling rate: 20$^{\circ}$C/min for the fast cooling process and 2$^{\circ}$C/min for the slow one. Unless specified otherwise, all observations of domains are conducted at the final temperature, 21.5$^{\circ}$C, where the 14.0\% (wt/wt) DSCG solution is in the fully nematic phase.

The polarized optical microscopy (POM) images with crossed linear polarizers are taken using a CCD camera (Infinity3-6UR, Lumenera) under illumination derived from LED lamp (LED4D067, Thorlabs). As shown in the first row of Fig. \ref{fig:tevolcdf}(a), the first set of images is taken three hours after reaching 21.5$^{\circ}$C, and the time evolution is recorded typically at 3-hour intervals for 24 hours. To facilitate the measurement of the domain-size distribution in a wide field of view, we use a 4$\times$ objective lens to take and stitch multiple images covering the whole sample area; See Data Analysis for how to stitch multiple images together. For the observation of domain formation shown in Fig. \ref{fig:formationtype}(a) and \ref{fig:formationtype}(b), we use a 20$\times$ objective lens to take images at the rate of one frame per five seconds.

\subsection{Data Analysis}
To measure the domain-size distribution in a whole capillary, we stitch multiple images using ImageJ's `Grid/Collection Stitching' plugin \cite{Preibisch2009}. Then, from the intensity profile along the stitched capillary images, we identify the positions of defects and measure the distances between all neighboring defects, \textit{i.e.}, domain lengths. Specifically, as shown in the POM images under crossed polarizers such as Fig. \ref{fig:tevolcdf}(a), the defects appear as dark lines between two bright regions. A location where the second derivative of the intensity profile along the capillary is greater than a threshold value, corresponds to the defect position. Collecting these positions and distances between the neighboring defects, we estimate the domain-size distribution of $\sim$500 domains per each experiment, as shown in Fig. \ref{fig:tevolcdf}(b) and (c), and repeat the experiments five times. Note that we present the data as the cumulative distribution function with no need to set the bin size.

\subsection{Statistical Tests}

Testing eight right-skewed probability distributions to fit our experimentally measured distributions, we find that the log-normal distribution with three parameters best describes the experimental data. As shown in Fig. \ref{fig:compcdf}(b), the experimental probability distribution function(PDF) is right-skewed. We choose eight distributions of a similar shape to fit our experimental data from 3 to 24 hours: log-normal, log-logistic, Weibull, Fr\'echet, and gamma distributions. For log-normal, log-logistic, and Weibull distributions, we test both the typical two-parameter distribution and the three-parameter distribution with an additional offset parameter. Avoiding the binning issue, we use CDFs for fitting and test the goodness of the fits by two methods: the coefficient of determination, $R^2$ (Fig. \ref{fig:COD_KS_QQ}(a)), and the Kolmogorov-Smirnov test (Fig. \ref{fig:COD_KS_QQ}(b)) \cite{Young1977,Pobocikova2017}.

Both tests suggest that the three-parameter log-normal distribution (LN3) best describes our experimental data. We calculate the coefficient of determination $R^2 = 1- \frac{\mathrm{SS}_{\mathrm{R}}}{\mathrm{SS}_{\mathrm{T}}}$ where the residual sum of squares $\mathrm{SS}_{\mathrm{R}} = \sum_{i=1}^{N}\left[ F(\tilde{l}_i)-F_\mathcal{D}(\tilde{l}_i) \right]^2$ and total sum of squares $\mathrm{SS}_{\mathrm{T}} = \sum_{i=1}^{N}\left[ F(\tilde{l}_i)-\bar{F}(\tilde{l})\right]^2$. Here, the experimental CDF is $F(\tilde{l}_i)$ when $\tilde{l}_i$ is the $i$th nondimensionalized domain length, with its mean $\bar{F}(\tilde{l})=\frac{1}{N}\sum_{i=1}^{N}F(\tilde{l}_i)$. The CDF of a certain model distribution $\mathcal{D}$ is $F_{\mathcal{D}}(\tilde{l})$. Fig. \ref{fig:COD_KS_QQ}(a) shows $R^2$ of experimental CDFs at different times to eight trial distribution functions. Except for the two-parameter Weibull and gamma distributions, the values of $R^2$ are close to one; $R^2=1$ means the distribution model matches the data. The LN3 gives the highest $R^2$.

The Kolmogorov-Smirnov test determines the distribution best describing the experimental data based on the largest absolute difference between the experimental and model CDFs, \textit{i.e.}, ${KS} = \sup_{\tilde{l}} \left| F_{\mathcal{D}}(\tilde{l})-F(\tilde{l}) \right|$. Here $\sup_{\tilde{l}}$ denotes the supremum of the set of absolute CDF differences; the supremum stands for the value greater or equal to all the other values in a set. If the test statistic ${KS}$ is smaller than a critical value, the null hypothesis that the data comes from the particular distribution is not rejected. In our test, the critical value for the test statistic is not determined conventionally since the parameters of the fitting distributions are estimated from the data itself. Therefore, we consider the distribution with the smallest ${KS}$ to be the best model. Fig. \ref{fig:COD_KS_QQ}(b) shows ${KS}$ for all trial distributions as a function of time, which reconfirms that the LN3 fits our data best. The Quantile-Quantile (Q-Q) plots in Fig. \ref{fig:COD_KS_QQ}(c) compare the experimental and LN3 CDFs. Except for the regions of very short and long domains where the log-normal distribution expects more domains, the experimental data points lie mostly on a 45-degree reference line, indicating a fair agreement between the experimental distribution and LN3.

\section{Conclusion}

We study how nematic DT domains in a cylindrical capillary form and grow by coarsening, focusing on their size distribution. Quenching from the isotropic phase leads to the domains of different handedness separated by a singular defect. The domains get coarsened by the annihilation of defects by merging and exhibit a time-evolving length distribution. We propose a model describing how stochastic merging within a train of nematic droplets as pre-domains with normally distributed sizes and randomly assigned handedness, determines the initial size distribution after the isotropic-nematic phase transition. Our statistical tests propose that the three-parameter log-normal distribution best approximates our experimentally measured size distributions of the initial and coarsened domains. Our results manifest that the proposed 1D system allowing facile optical observation and size characterization, provides a useful model platform to study symmetry-breaking phase transition in condensed matter, accompanying domains and topological defects formation.

Looking to future works, we believe understanding the energetics of DT domains and their defects, would deepen our understanding of how the domain-size distribution is determined and evolve as time goes by. Specifically, the topological defects where the handedness of the ground-state DT domain changes have an energy penalty, thus exhibiting effective attraction with each other to lower the elastic free energy. Investigating the energy landscape may give us hints at why the coarsening dynamics maintains the log-normal size distribution over time evolution. It would also be intriguing to tune the energy landscape by adding chiral dopants or applying external fields and see how the coarsening dynamics would change \cite{Eun2019,Dietrich2017}. Then, this 1D model system with known and tunable energetics may shed light on domain formation and coarsening dynamics in complicated systems of higher dimensions.

\input{main.bbl}

\end{document}


\section*{Ethical Consideration}
During our manual annotation process, we provide timely warning of potential adult topics and ask workers to return the job if they are under age.
For modeling, we utilize T5 throughout our work, which also involves generating rationales.
It is well-known that such pretrained language models---trained on massive online texts---could capture the biases reflecting the training data.
Our released models might be used for malicious purposes because we do not have a filtering mechanism that checks the toxicity, bias, or offensiveness of source sentences from the input.
We suggest interested parties carefully check the generated content before using our trained models in any real world applications.
The datasets in our work are all public.
These do not contain any explicit detail that leaks information about a user's name, health, negative financial status, racial or ethnic origin, religious or philosophical affiliation or beliefs.

\section{Author Annotation Details}
\label{app:author}
The 100 CoS-E instances that are annotated by three authors are the sames ones annotated by workers on Mturk in the additional quality checks.
Workers' annotation agrees with ours on 92 out of 100 instances for both background knowledge and leakage annotation, showing a good agreement between us and workers. We do the rest of annotations by ourselves to ensure the annotation quality. During the annotation, one example of a \emph{\small$C_{\textrm{no-leak-no-bg}}$} rationale is ``\textit{Rivers flow trough valleys.}'', which occurs in 119 / 1221 instances (9.7\% of the entire dev. set), even though it seemed valid for just one dev. instance. We suspect that this rationale was used as a default placeholder. We urge future researchers to closely inspect the annotation quality before releasing a dataset.
\section{Templates to Generate Poor-by-Construction Rationales}
\label{app:intend-incorrect}
 The ten templates we designed that aim to produce rationales that intend to be incorrect are:
 \begin{itemize}[leftmargin=*]
\vspace{-0.1in}
\itemsep-.5em
     \item if you know \emph{\{one\_of\_incorrect\_options\}}, you should know the answer to ``\emph{\{question\}}''
     \item the answer to ``\emph{\{question.lower()\}}'' is obvious based on my experience
     \item one should know \emph{\{one\_of\_incorrect\_options\}}'s relation with ``\emph{\{question.lower()\}}''
     \item the \emph{``\{question.lower()\}''}'s answer is in one of the five options
     \item answering \emph{``\{question.lower()\}''} needs some common sense reasoning
     \item it is unknown if \emph{\{one\_of\_incorrect\_options\}} can answer \emph{``\{question.lower()\}''} or not
     \item we expect \emph{\{one\_of\_incorrect\_options\}} might be able to answer \emph{``\{question.lower()\}''}
     \item answering \emph{``\{question.lower()\}''} is easy
     \item we do not know the answer to \emph{``\{question.lower()\}''}
     \item the options must contain the answer to \emph{``\{question.lower()\}''}
 \end{itemize}
 These rationales are designed to have incorrect qualities. In the ideal case, none of them should be flagged as containing background knowledge to answer a question. Therefore, we use them as a baseline to monitor the crowd-sourcing quality.
\section{\emph{\small$C_{\textrm{no-bg}}$} Example in CoS-E}

\section{Examples of Generated Rationales}
\label{app:generation-example}
\input{tables/7-generate}
Table~\ref{tab:generated-examples} shows an example of generated rationales for CoS-E and ECQA, together with annotated rationales in the original dataset. Based on our human evaluation, the quality of generated rationales are worse than annotated rationales and cannot provide proper supervision signals for model training.
\section{Human Study Annotation}
\label{app:anno-human-study}
 We recruit workers through our maintained list of good workers. These workers have collaboration with us on other projects, who we make sure are not spammers. In addition, we require workers to have completed over 1000 HITs with an approval rate over 99\% and locate in the United States to qualify for our annotation task. As some of the questions contain discussion of adult topics, we warn workers and ask them to terminate the annotation if they are under 18. Our annotation pays for \$1 per HIT.

\section{Implementation Details for Finetuning T5}
\label{app:t5}
We finetune multiple T5 models~\cite{t5} in our work, and we use HuggingFace~\cite{wolf-etal-2020-transformers} throughout our implementation. We use 512 and 256 for the maximum source length and the maximum target length separately.
To optimize, we use AdamW~\cite{adamw} with a learning rate of 0.0001. We train each model on a NVIDIA RTX 2080 with a batch size of 8 for 30 epochs.
During the inference time, we use beam search as the decoding method with a beam size of 2.
The generation of EOS token or reaching the maximum target length will terminate the decoding.

\section{Introduction}
\label{sec:intro}

Interpretable natural language processing benefits from faithful rationales that are accurate representations of a model's decision process~\cite{AlvarezMelis2018TowardsRI}.
These rationales aim to explain decisions by providing additional world knowledge or commonsense reasoning, necessary for most language understanding tasks.\footnote{
We use the terms ``rationale'' and ``explanation'' interchangeably.
Please see \citet{Wiegreffe2021TeachMT} and \citet{jacovi-goldberg-2021-aligning} for more details on terminology.}
Free-form rationales also come with the promise of being easily interpretable by humans, as opposed to other kinds of explanations, such as extractive rationales in the form of textual highlights \cite{ESNLI}, or low-level neuron activations in neural architectures~\cite{Hohman2020SummitSD}.

\begin{figure}[t]
    \centering
    \includegraphics[width=\linewidth]{figures/rationale-v7.pdf}

    \caption{
    Our work studies the benefits of rationales. We conduct \emph{human} studies to understand perceived usability of rationales and study if \emph{models} can benefit from crowd-sourced rationales as extra supervision. Furthermore, we study how much extra supervision models need to boost the performance. Finally, we compare generated rationales with human-annotated rationales.
    Here we use commonsense QA as an example for illustration.
    }

    \label{fig:teaser}
\end{figure}

Indeed, there have been increasing efforts to collect corpora containing free-form rationales for task instances, which provide a supervised setting for teaching models to produce rationales for test-time decisions.
Such corpora include {\fontfamily{cmss}\selectfont{CoS-E}}\xspace~\cite{rajani-etal-2019-explain} and {\fontfamily{cmss}\selectfont{ECQA}}\xspace~\cite{aggarwal-etal-2021-explanations} for commonsense question-answering, e-SNLI \cite{ESNLI} for natural language inference, SBIC \cite{sap-etal-2020-social} for social bias inference, among others; most of these corpora contain crowdworker-written free-form rationales \cite{Wiegreffe2021TeachMT}.
Collecting high-quality free-form rationales is challenging: for instance, \citet{Narang2020WT5TT} find that the rationales in {\fontfamily{cmss}\selectfont{CoS-E}}\xspace are of low quality,
which might defeat the purpose behind collecting such corpora.
Recognizing this, {\fontfamily{cmss}\selectfont{ECQA}}\xspace~\cite{aggarwal-etal-2021-explanations} re-annotates  {\fontfamily{cmss}\selectfont{CoS-E}}\xspace for better quality.

However, the usability of rationales is still unclear.
Do crowdsourced rationales really help human users interpret decisions better, or do they simply provide the right answer without the necessary background knowledge or reasoning?
Our work explores this question through two carefully designed human studies for commonsense question answering.
We find that rationales from different corpora have different capabilities: humans find 93\% {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales provide additional information that can help answer questions, while only 12\% of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales do.

Inspired by this finding, we further ask: analogous to the benefit provided to human users, can crowdsourced rationales benefit \textit{models} by providing additional supervision that results in a performance boost?
In contrast to prior work that uses rationales as supervision to generate model rationales, we focus on using crowdsourced rationales to simply aid a task model's classification capabilities.
Our results indicate that while crowdsourced rationales do indeed boost model performance, they might be doing so trivially, i.e. by simply leaking the correct answer to the model.
In response, we experiment with different strategies for altering {\fontfamily{cmss}\selectfont{ECQA}}\xspace and {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales to prevent such leakage, and set up a fair test benchmark.
Under this setting, we find that including only 5\% of rationales during training can improve model performance by 47.22\% at inference time with good rationales.
This finding generalizes to {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace~\cite{tafjord-etal-2019-quartz}, a dataset for textual relationship inference, in which the provided background knowledge is intentionally designed to contain no leakage.

Finally, we investigate if automatically generated rationales provide similar benefits as crowdsourced rationales.
Our human studies indicate that the perceived usability of generated rationales is much lower than that of human-written ones.
Moreover, we find that generated rationales from T5 \cite{t5} are not yet ready to serve as supervision signals.
These results indicate that the quality of rationales is paramount for both human interpretability and model supervision.

To summarize, our work focuses on understanding the utility of free-form rationales in existing popular datasets, from both the human and modeling perspectives.
To the best of our knowledge, no previous work has quantitatively examined the utility of free-form rationales.\footnote{We will publicly release our annotated data and code.}

\section{Preliminaries}
\label{sec:tasks}

\paragraph{Tasks and Datasets.}
We explore three large datasets containing crowdsourced free-form natural language rationales (App. Table~\ref{tab:statistics} shows the statistics).
The first two address the commonsense-based question answering (\citealp[ComQA]{talmor-etal-2019-commonsenseqa}) task: {\fontfamily{cmss}\selectfont{CoS-E}}\xspace~\cite{rajani-etal-2019-explain}, and {\fontfamily{cmss}\selectfont{ECQA}}\xspace~\cite{aggarwal-etal-2021-explanations}.
The ComQA task is based on answering questions about common situations, from a choice of 3 ({\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.0) or 5 ({\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11) answers, along with providing a free-text explanation for the correct answer.
{\fontfamily{cmss}\selectfont{ECQA}}\xspace builds upon and improves the quality of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11 explanations, in terms of comprehensiveness, refutation completeness and non-redundancy~\cite{aggarwal-etal-2021-explanations}.
In addition, {\fontfamily{cmss}\selectfont{ECQA}}\xspace explanations are contrastive, i.e. they include rationales for choosing the correct option and rejecting other options.

We additionally consider an open-domain reasoning task about textual qualitative relationships, via the {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace~\cite{tafjord-etal-2019-quartz} dataset, for a subset of our experiments.
Each instance contains a triplet: a situated qualitative question, two answer options and a knowledge statement that can help  answer the question.
For example, for \emph{``Compared to a box of bricks a box of feathers would be (A) lighter (B) heavier''}, the annotated knowledge in {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace is \emph{A given volume of a denser substance is heavier than the same volume of a less dense substance}.
In contrast to {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace, the two options for a question in {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace are orthogonal, which means the knowledge provided to support one option will automatically reject the other option.
Furthermore, this general qualitative knowledge statement in {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace is guaranteed to not leak the correct answer.
While not explicitly designed for interpretability, we treat the annotated knowledge in {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace as a rationale that can help understand or derive the correct answer.
The statistics of the three datasets are in Table~\ref{tab:statistics}.\footnote{
{\fontfamily{cmss}\selectfont{CoS-E}}\xspace does not provide explanations for instances in the test set; we report our results on its validation set.
}

\paragraph{Models.}
We use finetuned T5~\cite{t5} models throughout our work following prior efforts for analysing~\cite{wiegreffe-etal-2021-measuring} and generating~\cite{Narang2020WT5TT,lakhotia-etal-2021-fid} free-text explanations.
More specifically, we finetune three T5-base models for each dataset, with ground-truth labels and rationales.\footnote{See App.~\ref{app:t5} for details on our T5 model training.}
\begin{itemize}[leftmargin=*]
\itemsep-.3em
\vspace{-0.2em}
    \item I$\rightarrow$O. We directly finetune a model to predict the correct option, and we format the I/O of this T5 model as \texttt{context:} \emph{\{question\}} \texttt{options:} \emph{\{concatenated option string\}} for input and \emph{\{correct option\}} for output.
    \item IR$\rightarrow$O. Different from the I$\rightarrow$O model, we add rationales into input and have: \texttt{context:} \emph{\{question\}} \texttt{options:} \emph{\{concatenated option string\}} \texttt{explanation:} \emph{\{rationale\}} for input, the output is \emph{\{correct option\}}.
    \item I$\rightarrow$R. We finetune a model with questions and options as input to generate rationales. The format is \texttt{explain question:} \{question\} \texttt{answer:} \emph{\{concatenated option string\}} for input and \texttt{explanation:} \emph{\{rationale\}}  for output.
\end{itemize}
For the IR$\rightarrow$O model, we experiment with different variations based on the source of the rationales R (e.g. R$_{\textrm{{\fontfamily{cmss}\selectfont{CoS-E}}\xspace}}$).
In addition, rationales used in our analysis could be either from crowdsourced human annotation (R$_{crowd}$) or automatic model generations (R$_{generated}$).

\paragraph{Evaluation.}
We use accuracy (\textit{acc}) to evaluate the performance of both I$\rightarrow$O and IR$\rightarrow$O models, and measure the benefit of rationales as extra supervision by using a simulatability score, which reflects the utility of rationales in terms of improving a model's performance:
\vspace{-2mm}
\begin{equation}
\textrm{acc(IR} \rightarrow \textrm{O}) - \textrm{acc(I} \rightarrow \textrm{O}).
\vspace{-2mm}
\label{equation:simulatability}
\end{equation}
We do not report lexical-overlap metrics as our primary evaluation metric because these are not suited for measuring plausibility~\cite{Camburu2018eSNLINL, Kayser2021eViLAD, clinciu-etal-2021-study} or faithfulness of rationales~\cite{jacovi-goldberg-2020-towards}.
In contrast, we follow prior work ~\citet{wiegreffe-etal-2021-measuring} and use the simulatability score (Eq.~\ref{equation:simulatability}) to measure rationale quality from the lens of usability of rationales.
Simulatability score has been serving as a reliable measure of rationale quality from the lens of utility to an end user in prior literature \citep[i.a.]{hase-bansal-2020-evaluating, hase-etal-2020-leakage, rajagopal-etal-2021-selfexplain, PoursabziSangdeh2021ManipulatingAM,wiegreffe-etal-2021-measuring}, which additionally measures the predictive ability a rationale provides over the input, unlike lexical-overlap metrics.

\section{Do crowdsourced rationales aid human interpretability?}
\label{sec:human}

Free-text rationales purportedly improve human user interpretability by explaining a model's decisions in natural language.
We seek to discover which characteristics of the rationales aid users:
\begin{itemize}[leftmargin=*]
\vspace{-0.1in}
\itemsep-.5em
    \item [Q1] Are the rationales providing \textbf{additional background knowledge} for understanding decisions? For example, the rationale: \emph{Air cannot stay in any object that has a hole in it} provides additional knowledge for understanding why the answer to \emph{What would not be true about a basketball if it had a hole in it but it did not lose its general shape?}  should be \emph{full of air}.
    \item [Q2] Are the rationales providing explicit clues to \textbf{leak} the correct answer? For example, given a rationale: \emph{The common watching device at home is a tv set}, one can guess the correct answer should be ``television'', among options \emph{drive in home},  \emph{television}, \emph{video store and show}, without looking at the question.
\end{itemize}
\subsection{Human Studies}
We conduct two studies to investigate Q1 and Q2:

\paragraph{Comparative Study.} We conduct a {pilot study} where
annotators are presented the question, options, correct answer and rationales from {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace for each instance.
Annotators are tasked to answer which rationale provides \textit{additional background knowledge} that can help them answer the question.
Four options are possible: {\fontfamily{cmss}\selectfont{CoS-E}}\xspace, {\fontfamily{cmss}\selectfont{ECQA}}\xspace, \emph{neither}, or \emph{both}.\footnote{While \citet{aggarwal-etal-2021-explanations} provide similar human studies comparing {\fontfamily{cmss}\selectfont{ECQA}}\xspace and {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales, they do not specifically ask for additional background knowledge.} Simultaneously, we ask annotators if any of the two rationales leaks the correct answer.
Concretely, the annotators are required to provide three annotations for each instance: 1) \emph{choose one option for the additional background information} (T1); 2) \emph{judge if} {\fontfamily{cmss}\selectfont{ECQA}}\xspace \emph{rationale leaks the correct answer} (T2); and 3) \emph{judge if} {\fontfamily{cmss}\selectfont{CoS-E}}\xspace \emph{leaks the correct answer} (T3).

We use the first 120 rationales in {\fontfamily{cmss}\selectfont{ECQA}}\xspace and {\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11 and
conduct our study on Amazon Mturk. For each instance, we collect annotations from three independent annotators.\footnote{See more annotation details in Appendix~\ref{app:anno-human-study}.}
Using Fleiss's Kappa~\cite{Fleiss1973TheEO}, the inter annotator agreement (IAA) for T1, T2 and T3 are 0.43, 0.26, and 0.30, respectively, indicating moderate agreement.
We take the majority vote of annotations as the final label.

\begin{table}[t]
\centering
\small
\begin{tabular}{@{}lrr@{}}
\toprule
\textbf{} & \textbf{{\fontfamily{cmss}\selectfont{ECQA}}\xspace} & \textbf{{\fontfamily{cmss}\selectfont{CoS-E}}\xspace} \\ \midrule
has background knowledge & 85.8\% & 30.0\% \\
leaks answer & 83.3\% & 43.3\% \\ \bottomrule
\end{tabular}
\caption{
Comparative study on the perceived usefulness of {\fontfamily{cmss}\selectfont{ECQA}}\xspace/{\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales on 120 ComQA instances.
}
\label{tab:human}
\end{table}

Table~\ref{tab:human} shows the results for human evaluation of the usefulness and quality of annotated rationales.
About 85.8\% {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales can provide additional background knowledge to help answer the question, while only 30\% {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales can achieve the same, confirming the higher quality of {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales for human interpretability \cite{aggarwal-etal-2021-explanations}.
However, both {\fontfamily{cmss}\selectfont{ECQA}}\xspace and {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales leak the correct answers.
Indeed, {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales often \textit{reveal} the correct answer, though providing the background knowledge necessary for humans to understand the decision.

\paragraph{Additional Objective Study.} In the above study, workers are asked to use their personal judgements. To study Q1 and Q2 in a more objective manner, we propose the following two experiments. Every instance in both experiments is annotated by three annotators, and we report the majority vote.

To further measure \emph{leakage} quantitatively, we use a partial information setting, where we hide the question from workers and only provide the rationale, the options for the question and a new option ``cannot tell''.
We then task workers to pick the option that best matches the rationale.
If a worker can pick the correct answer without even seeing the question, we consider the rationale has leaked the answer. As a result, annotators are able to pick the correct answer among options by only looking at rationales for 43.0\% {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales and 78.0\% {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales. The IAA is 0.73.

\begin{table}[]
\centering\small
\resizebox{0.5\textwidth}{!}{
\begin{tabular}{@{}lllll@{}}
\toprule
     & \textbf{crowdsourced rationale} & \textbf{constructed rationale} & \textbf{question} & \textbf{option} \\ \midrule
{\fontfamily{cmss}\selectfont{CoS-E}}\xspace &
  \begin{tabular}[c]{@{}l@{}}unit is a self-contained \\ housing unit that\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}You could find a\\ toilet at apartment \\ that only friends \\ can use.\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Where could \\ you find a toi\\ -let that only \\ friends can \\ use?\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}rest area,\\school,\\stadium,\\\textbf{apartment},\\ hospital\end{tabular} \\
  \cdashlinelr{1-5}
{\fontfamily{cmss}\selectfont{ECQA}}\xspace &
  \begin{tabular}[c]{@{}l@{}}Glue stick is a solid glue \\ used to stick thin paper \\ materials by adults in \\ offices. Adults don't go\\ to classroom and school,\\and other options don't \\ have adults.\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Adults use glue \\ sticks in their \\ offices. They do \\ not use them at \\ classroom, desk \\ drawer, at school \\ or kitchen drawer.\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}Where do\\adults use\\glue sticks?\end{tabular} &
  \begin{tabular}[c]{@{}l@{}}classroom,\\desk drawer,\\at school,\\\textbf{office},\\kitchen-\\ drawer\end{tabular} \\ \midrule\midrule
     & \textbf{crowdsourced rationale} & \textbf{constructed rationale} & \textbf{neither}  & \textbf{either} \\ \midrule
{\fontfamily{cmss}\selectfont{CoS-E}}\xspace & 3\%                & 5\%          & 92\%              & 0\%             \\
{\fontfamily{cmss}\selectfont{ECQA}}\xspace & 73\%               & 9\%          & 14\%              & 4\%             \\ \bottomrule
\end{tabular}
}
\caption{Top: examples of crowdsourced vs. constructed rationales for {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace. Bottom: results from our human study to compare crowdsourced and constructed rationales.}
\label{tab:new-bg}
\end{table}

For \emph{background knowledge}, we manually produce constructed rationales to contrast with crowdsourced rationales.
Our constructed rationales are designed to not provide background knowledge, while being fluent and following the same style as the crowdsourced explanations.
For {\fontfamily{cmss}\selectfont{CoS-E}}\xspace, this rationale simply combines the correct option and the answer.
For {\fontfamily{cmss}\selectfont{ECQA}}\xspace, in addition to combining the correct option with the answer, our constructed rationale simply states that all options are incorrect for the question.
We show two examples of our constructed text in Table~\ref{tab:new-bg}.
We provide human subjects with the question, the correct answer, the crowdsourced rationale (from {\fontfamily{cmss}\selectfont{CoS-E}}\xspace or {\fontfamily{cmss}\selectfont{ECQA}}\xspace) and our constructed rationale.
We instruct workers to choose the explanation that they would prefer if they need to explain the correct answer to someone who might not have the necessary knowledge, perhaps a child or a foreign national.
The IAA is 0.61.
Table~\ref{tab:new-bg} shows that while human raters preferred our constructed rationales over {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales, most preferred neither, indicating that neither provides background knowledge necessary for answering the question.
On the other hand, raters seem to prefer {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales over our constructed ones, indicating the benefits of background knowledge in the carefully collected {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales.
However, surprisingly, raters picked our constructed rationales 9\% of the time, while being ambivalent about either rationale for 4\% of the cases; moreover, they liked neither {\fontfamily{cmss}\selectfont{ECQA}}\xspace or the constructed explanations for 14\% of the cases!
This indicates that while {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales might be of higher quality than {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales, it is likely that human raters might select rationales based on style alone.
Additionally, overspecification of the background knowledge might not always be appealing to human annotators.

\subsection{Categorizing Crowdsourced Rationales}
\label{sec:quality}
\input{tables/2-cose-quality}

\paragraph{{\fontfamily{cmss}\selectfont{CoS-E}}\xspace:}
Although ~\citet{Narang2020WT5TT} criticize the quality of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace annotation, they do not provide a detailed study of the various deficiencies in the rationales.
Nevertheless, {\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11 is still widely used for additional commonsense knowledge \cite{Ye2019AlignMA}, analysis \cite{Majumder2021RationaleInspiredNL, wiegreffe-etal-2021-measuring} and commonsense reasoning~\cite{paranjape-etal-2021-prompting}.
Therefore, it is imperative for the community to understand the quality of the annotated rationales in {\fontfamily{cmss}\selectfont{CoS-E}}\xspace.
Motivated by their usefulness for model supervision, we split rationales into 4 categories in Table~\ref{tab:cose-quality}.

Three co-authors of this paper annotated 100 instances independently. The Fleiss Kappa scores among co-authors are 0.65 for \emph{background knowledge} and 0.84 for \emph{leakage}, which suggests a good agreement. We use the majority vote among three annotators as the final label. Afterwards, one of the authors categorized the rest of the instances in the development set of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11 dataset into four categories.~\footnote{App. \ref{app:author} provides details.}
Table~\ref{tab:cose-quality} shows the distribution of the categories, examples from each category picked at random, together with a description.

Rationales that do not provide additional background knowledge make up 88.45\% of the entire development set of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace v1.11.
Using the development set as a lens, our annotation provides a qualitative and quantitative understanding of the crowdsourced rationales in {\fontfamily{cmss}\selectfont{CoS-E}}\xspace.
Future research should be careful when using rationales from {\fontfamily{cmss}\selectfont{CoS-E}}\xspace as additional knowledge or explanations.

\paragraph{{\fontfamily{cmss}\selectfont{ECQA}}\xspace:}
\citet{aggarwal-etal-2021-explanations} build on {\fontfamily{cmss}\selectfont{CoS-E}}\xspace question-answer pairs and reannotate the rationales.
Table~\ref{tab:comparison} compares {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales, where the former directly combines the correct answer and the question, but the latter contains additional commonsense knowledge that can help answer the question, suggesting a higher quality.
Moreover, {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales are contrastive as they explain, for each option, why it is correct or incorrect.
Regardless, we find that all {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales \textit{start} with the rationale for the correct option, followed by all other incorrect options.
This ordering introduces a spurious correlation which likely provides a shortcut to the model for predicting the correct answer, but for wrong reasons.
To address this issue, we randomly shuffle the rationales for different answer choices within each {\fontfamily{cmss}\selectfont{ECQA}}\xspace instance.\footnote{We use the sentencizer in Spacy (\url{https://spacy.io/}) and random permute their order, with seed 0.}

\input{tables/5-comparison}

\input{tables/7-distant}
\input{tables/6-ecqa}

\section{Can Models Benefit from Crowdsourced Rationales?}
\label{sec:experiments}

In the previous section (\S\ref{sec:human}), we found that crowdsourced rationales from carefully constructed corpora provide additional information to help humans better answer commonsense questions.
Now, we seek to answer if the same information can also benefit machine learning models, by providing them additional supervision, to make better decisions.

\subsection{Revisiting Rationales as Supervision}
\label{sec:noisy}

Taking into account our findings from the detailed analysis above (\S\ref{sec:human}), we conduct experiments to include rationales as supervision for task models, but with a finer-grained understanding of these rationales.
During training, we use varying amounts (5\%, 10\%, 20\%, 30\% and the full 100\%) of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and shuffled-{\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales, to study how the quantity of rationales affects the model performance.
During inference, we provide the T5 models with rationales under each of the four categories of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace, as discussed above, as well as all combined together.
For {\fontfamily{cmss}\selectfont{ECQA}}\xspace, we report performance for inference with and without shuffled rationales.
Finally, we study how supervision from one dataset affects another, in a transfer learning setting.

\paragraph{Takeaways.} Table~\ref{tab:distant} shows that one may find rationales are helping improve model performance at the first glance, {\fontfamily{cmss}\selectfont{CoS-E}}\xspace ($c1$ \& $c2$ for $r2$) with only 5\% training data. However, instances that purely leak the answer may make up a large portion. With a closer look, without background information and leakage, there is no improvement ($c7$). 2) with background knowledge, but no leakage, model performance can still be improved ($c5$); a close inspection of the quality of rationales reveals is necessary to understand when rationales can help the model decision for the right reasons (i.e. providing background information, not leaking the answer).
Our experiment on Quartz, as a benchmark with rationales containing background information but no leakage further validates our hypothesis.

\paragraph{Rationales boost model performance.}
First, comparing $c$1 with the rest of columns ($c$2-$c$8), rationales can help improve model's ability to make the correct prediction. \emph{However, when there is neither leakage of correct answer nor additional background information in the rationale, it cannot help model predict the correct answer.}
After adding 5\% of training data, the model reaches 59.89\% accuracy with $\small{C_{\textrm{no-leak-bg}}}$ rationales, which yields 47.2\% improvement compared to 40.68\% without rationales.
Please note that we exempt $r$1 from comparison because the model does not have any supervision from rationales during training, making it hard to understand the usability of rationales during the inference time.

\paragraph{Rationales help transfer learning.}
Second, adding more rationales to training will help boost model's performance for data from the same distribution. $r$2-$r$6 under $c$2 and $r$7-$r$11 under $c$4 are two examples.
Adding rationales from another type can help model improve performance to an extent.
However, models would perform worse when adding more rationales (20\%$\rightarrow$30\%) from another type of rationale.
We suspect this is because the model overfits to one specific rationale type and raise the distributional shift issue.

\paragraph{Rationale quality matters.}
Last, the quality of rationales affects performance for both cases: 1) adding rationales to training, and 2) use rationales for model inference.
The former is supported by the comparison between $r$2-$r$6 under $c$2 and $r$7-$r$11 under $c$4: using {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales will yield a better performance.
Meanwhile, $r$2 to $r$6 under $c$7 supports the latter argument:
adding poor quality rationales does not help model reasoning.
\input{tables/6-quartz}

To validate the importance of shuffling ECQA rationales, we add randomly-picked 5\% ECQA rationales without shuffling into training and test the model performance on both shuffled and unshuffled ECQA rationales in Table~\ref{tab:ecqa}.
Comparing $c$2 and $c$3 in Table~\ref{tab:ecqa}, we see that with only 5\% unshuffled ($r$2), the accuracy rises from 53.32 to 93.94.
However, when we test the model on shuffled data, the accuracy is 76.66\%.
The experimental result suggests that the model learns the spurious correlation between the rationale and correct answer before shuffling.
Therefore, we shuffle the order of sentences in the {\fontfamily{cmss}\selectfont{ECQA}}\xspace annotation to prevent the model from learning this spurious correlation.

\paragraph{Non-leaky rationales still boost model performance.}

Despite taking care to prevent spurious correlations in {\fontfamily{cmss}\selectfont{ECQA}}\xspace, there is still a chance models benefit from some amount of leakage of the correct answer.
To control for this, we consider the {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace dataset, introduced in \S\ref{sec:tasks}, using knowledge statements as rationales, which are guaranteed to contain no leakage.
We use the same modeling strategy as before and finetune T5 models for both I$\rightarrow$O and IR$\rightarrow$O models on {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace.
Without rationales, T5 model performs comparably to the BERT-PFT (IR) model which scores 73.7, one of the most promising models reported in ~\cite{tafjord-etal-2019-quartz}.
It shows that {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace dataset is hard, and finetuning T5 is a feasible modeling strategy to apply for {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace dataset.

Table~\ref{tab:quartz} shows the experimental results of the distant supervision setting for {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace, which validates our previous finding that rationales help to improve model's ability to predict correct answer, here adding 30\% of rationales can bring about 0.89\% accuracy improvement. Meanwhile, keep adding more rationales further boosts model's performance.
The consistency with our previous findings shows the generalizability of our conclusions.

\section{Benefits of Generated Rationales}
\label{sec:generated}
So far, we have focused on crowdsourced rationales, written by humans.
However, there has been a lot of research on generating free-form rationales using T5~\cite{Narang2020WT5TT, paranjape-etal-2021-prompting}.
Based on this, we ask: 1) can generated rationales provide the additional background information necessary for humans to interpret and answer questions, similar to \S\ref{sec:experiments}, and 2) can generated rationales provide additional supervision to improve model's prediction accuracy?

\input{tables/8-generate-distant}

\paragraph{Human Perception of Generated Rationales.}
\label{app:subjective}

We repeat our comparative human study in \S\ref{sec:human} on: (1) generated- v.s annotated- {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales and (2) generated- v.s. annotated- {\fontfamily{cmss}\selectfont{CoS-E}}\xspace rationales. Table~\ref{tab:human-generate} shows that human perceive fewer generated rationales to provide additional background knowledge than human-annotated rationales.
Meanwhile, {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales have better quality than both the human-annotated and generated rationales from {\fontfamily{cmss}\selectfont{CoS-E}}\xspace. The conclusion is consistent with \S\ref{sec:human}.

\paragraph{Generated Rationales as Model Supervision.}
First, we use annotated rationales to train I$\rightarrow$R models for both {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace following steps from \S\ref{sec:tasks}.
Then, we use the I$\rightarrow$R models to generate rationales and add generated rationales to IR$\rightarrow$O model training with various amount.\footnote{We show an example of annotated and generated rationales for both {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace in Appendix~\ref{app:generation-example}.} During the inference time, we either \RNum{1}: use generated rationales, following the setting from ~\citet{wiegreffe-etal-2021-measuring}, or \RNum{2}: use human annotated rationales.

Table~\ref{tab:generated} shows the experimental result of the distant supervision setting with generated rationales. For setting \RNum{1}, we share the same finding with ~\citet{wiegreffe-etal-2021-measuring} that using generated rationales during inference does not help improve model's performance in terms of predicting correct option, leading to negative simulatability scores, which are -13.1 (43.9-57) for {\fontfamily{cmss}\selectfont{CoS-E}}\xspace generated rationales and -12.36 (44.64-57) for {\fontfamily{cmss}\selectfont{ECQA}}\xspace generated rationales. For setting \RNum{2}, using generated rationales for training but human-annotated rationales at the inference time, model's prediction accuracy improves. However, the accuracy is lower than the setting where we use human-written rationales for training in Table~\ref{tab:distant}.
These findings address the importance of having good quality rationales for the I$\rightarrow$R model training, as we have concluded that {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales are of better quality than {\fontfamily{cmss}\selectfont{CoS-E}}\xspace.
Under the distant supervision setting, however, using more generated rationales in training keeps boosting the model performance to an extent (from 5\% to 30\%), which is consistent with our previous conclusion using human annotated rationales.
However, using 100\% generated rationales leads to a performance drop compared to only using 30\% for R$_\textrm{{\fontfamily{cmss}\selectfont{CoS-E}}\xspace}$, we suspect that this is because the generated rationales introduce too much noise and the model fails to learn a clear pattern.
These conclusions are consistent with our human studies.

\section{Related Work}
\label{sec:related}

\paragraph{Types of Explanations.}
Rationales can be roughly categorized into two broad categories: extractive rationales and free-form rationales.
Extractive rationales serve interpretability in that they can reveal the ``reasoning'' behind model outputs.
Therefore, extractive rationales are usually grounded in a specific context (e.g., such as a paragraph) as supportive evidence.
For example, in information extraction (IE) tasks, a rationale can be extracted as a subset of the input and is sufficient to make a prediction on its own without relying on the rest of the input.
\citet{deyoung-etal-2020-eraser} introduce ERASER that comprises 8 datasets and 9 tasks with human annotation of extractive rationales.
Free-text rationales take the form of free-form natural language to fill in the reasoning or knowledge gap.
There have been fewer datasets focusing on introducing free-form rationales compared to extractive rationales.
In addition to e-SNLI~\cite{ESNLI}, {\fontfamily{cmss}\selectfont{CoS-E}}\xspace~\cite{rajani-etal-2019-explain}, {\fontfamily{cmss}\selectfont{QuaRTz}}\xspace~\cite{tafjord-etal-2019-quartz} and the most recent  {\fontfamily{cmss}\selectfont{ECQA}}\xspace~\cite{aggarwal-etal-2021-explanations} provide necessary knowledge for answering questions.

\paragraph{Rationale Generation.}
From the modeling perspective, rationale generation models can be roughly categorized into supervised and unsupervised models.
For supervised models, \citet{lakhotia-etal-2021-fid} and \citet{Narang2020WT5TT} finetune T5 to generate extractive and free-form rationales separately.
For unsupervised models, \citet{glockner-etal-2020-think} propose a differential training framework to create models that output faithful rationales without supervision.
Instead of directly generating rationales, \citet{paranjape-etal-2021-prompting} propose to utilize T5 to complete contrastive explanation prompts that explicitly contrast different possible answers in its explanation.
Under the line of contrastive explanation generation, \citet{jacovi-etal-2021-contrastive} manipulate the latent space, differentiate two potential decisions and construct explanations to answer for which the given label is useful.
Following prior work, we also finetune T5 models to generate rationales.
\paragraph{Learning From Rationales.}
There has been limited work studying the problem of training models to learn from human-annotated free-form rationales.
\citet{wiegreffe-etal-2021-measuring} investigate how free-form rationales and model predicted labels are associated, and use it as a property to evaluate the faithfulness of rationales; in contrast our work provides a much more detailed study across multiple datasets.
\citet{Carton2021WhatTL} leverage extractive rationales and show a consistent trend that using rationales can improve model performance.
Most similar to our work, \citet{huang-etal-2021-exploring} noticed that the quality of rationales would have a huge impact and explore the utility of extractive rationales in the distant supervision setting.
Our work has a similar motivation to Huang et al.'s and follows a similar setting for free-form rationales.

\section{Conclusion}
\label{sec:conclusion}

We investigated the usability of free-form rationales from both a human and a modeling perspective.
Centering our analysis on commonsense QA datasets,
we find that humans perceive rationales with more background knowledge as more useful than those which simply combine the question and the answer.
We provided a detailed qualitative analysis of {\fontfamily{cmss}\selectfont{CoS-E}}\xspace and {\fontfamily{cmss}\selectfont{ECQA}}\xspace rationales, and found that even small amounts of higher quality rationales are helpful as additional supervision sources for task models.
Our work highlights the importance of inspecting the quality of human-annotated rationales before using them for additional model supervision.
We also found that generated rationales are not as useful for human interpretability or for model supervision, as opposed to crowdsourced rationales.
Our investigations shed light on fundamental assumptions about human interpretability in collecting and generating rationales, and calls for further deeper investigation into the utility of free-form rationales.


\section{Why functional?}

General purpose, numerical programming languages are the right tools for building models in machine learning, probabilistic programming, and differentiable programming ($\partial P$). In general, models may be no less complex than general-purpose programs, and need similar tools to manage that complexity \cite{innes2018machine}.

ML practitioners tend to use imperative languages -- mainly Python, and to a lesser extent R, Matlab, Julia and a smattering of others -- for their work. Yet ML, and particularly deep learning, frameworks often look quite unlike normal libraries, imposing an atypical functional style of programming \cite{colah2015types}.

The term ``functional'' originated with the use of higher-order functions, and is now associated with a number of related ideas. Two that matter for our purposes are:

\begin{enumerate}
\item \textit{Value semantics}, particularly for arrays. Mathematical operations create new arrays, rather than operating in-place.
\item \textit{Referential transparency}, in which a function call can be replaced by its return value. In other words, implicit dependencies (such as model configuration objects) can be assumed fixed.
\end{enumerate}

JAX, a Python library for numerics and code transforms \cite{frostig2018compiling}, is a clean example of these issues at play. It turns the Python interpreter into a compiler, using objects that abstractly represent arrays to run a partial evaluation of user code. In effect the result of dictionary lookups and dynamic dispatch is cached on first run, which avoids overhead during model training. But strictly speaking this is in violation of Python's semantics: the result of a dictionary lookup, or almost any other Python operation, might well change at run time. So JAX simply asks users to provide a pure function and assumes that they have done so, with undefined behaviour if the rule is violated. This has some limitations and sharp edges that would be ameliorated with better language-level support.

Julia, a numerical programming language \cite{bezanson2017julia}, is revealing in a different way. Julia's abstract interpretation is analogous to JAX's partial evaluation (a proof-of-concept hybrid, \citealt{innes2020mjolnir}, showed that they are two sides of the same coin). But Julia's compiler must respect the language's semantics, without making additional assumptions. Mutable objects, such as \texttt{Dict}s, stymie inference and must be given explicit type parameters to allow inference of downstream code. Limited constant propagation is supported on immutable objects, like \texttt{Tuple}s, but not arrays or dictionaries. Julia's source-transform based autodiff library, Zygote, disables array mutation in user functions due to the complexity of managing their derivatives. Deep learning with Flux, a Julia-based ML stack \cite{innes2018fashionable}, therefore looks functional: but in this case the core language's use of mutation impedes, rather than enabling, high performance code.

The trend towards functional-style, relatively declarative programming with compilers like XLA \cite{sabne2020xla} is a significant shift from the conventional style of scientific and numerical computing,\footnote{And indeed the style Julia was designed to cater for, albeit with more modern language affordances.} in which arrays are explicitly allocated and modified in loops, with a close correspondence between program and machine instructions. The change is partly driven by increasingly diverse hardware, as well as the relatively fixed set of core numerical kernels used in ML. Kernels individually benefit from hand optimisation, but compositions of them have less room for improvement, even for hardware experts. Low-level control is therefore less valuable for users, and general optimisations like simple loop fusion, memory placement and model-level distribution and parallelism are best done by compilers, on representations far more abstract than machine code \cite{li2020deep}.

\section{Why imperative?}

The discussion above seems to suggest that Haskell, OCaml or Scala would be better frontends for numerical compilers. Yet researchers have voted with their feet (or at least with their keyboards): Python is by far the most popular language for ML,\footnote{Google Trends supports ``python machine learning'' being about 10$\times$ more popular than ``matlab machine learning'', which in turn is about 5$\times$ more searched than ``julia machine learning''.} despite being poorly suited to the task on paper. Why are dynamic, imperative languages so popular? Partly this is to do with conventional (though not inherent) differences between static and dynamic languages -- things like interactivity, ease of use for beginners and the flexibility of dictionary-oriented programming \cite{dubois1996numerical}. We don't delve into those topics, except to point out that there are perfectly serviceable dynamic, functional languages like Clojure and Mathematica, so it can't be a complete explanation.\footnote{There are also some historical accidents that favour Python specifically. For example, its unusual choice to use reference counting happens to be ideal for managing large GPU arrays, where Julia's tracing GC struggles.}

Given that ML frameworks eschew shared mutable state, the last difference of note between functional and imperative is their conventional syntax choices. Clearly, nested, structured control flow (as in the loop, \texttt{if}/\texttt{else} statements and \texttt{break}, \texttt{return} and \texttt{continue}) is a helpful way to express algorithms, especially the iterative algorithms common in numerical programming. Just as importantly, the imperative style allows for a notion of \textit{change} that is easier to think with, compared with having to decompose and reconstruct everything: ``change column $i$ of matrix $A$'' is a more natural description than ``take all columns but the $i^{th}$ from $A$, and concatenate them together with this new one in the right position to create $B$'', and more so as updates get more complex.

Syntax like \texttt{A[i] = x} typically does three things: it provides a syntactic notion of change as above; it efficiently modifies memory in-place; and it may alter the behaviour of seventeen other threads of execution that reference $A$. But the last of these is most often an anti-feature, and the second is the job of the compiler. It really is only the syntax that we want.

Despite being superficial in a sense, syntax is an important part of the user experience, and a perfectly good reason for users to prefer imperative over functional languages. But now we are surely asking to have our cake and eat it too: we don't like mutable state, yet we want to write programs with explicit change. In fact, there is no contradiction. To explain why we'll have to challenge some misconceptions about ``imperative'' syntax.

\section{The procedural is pure}

When discussing imperative programming, it's common to conflate mutable \textit{local variables} with mutable \textit{data structures}. In fact they are hardly related. Here's an example with the former, but not the latter:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
fn pow(x, n) {
  r = 1
  while n > 0 {
    r *= x
    n -= 1
  }
  return r
}
\end{Verbatim}
\vspace{-0.16cm}

LLVM, a compiler for those most imperative of languages \cite{lattner2004llvm}, lowers such functions to an intermediate representation (IR) similar to the following:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
fn pow(x, n) {
  fn block1() {
    r = 1
    block2(n, r)
  }
  fn block2(n, r) {
    if n > 0 {
      block3(n, r)
    else {
      block4(r)
    }
  }
  fn block3(n, r) {
    n_ = n - 1
    r_ = r * x
    block2(n_, r_)
  }
  fn block4(r) {
    return r
  }
  block1()
}
\end{Verbatim}
\vspace{-0.16cm}

LLVM and similar compilers call this form ``static single assignment'', or SSA, because variables are syntactically immutable -- in other words, they behave like bindings in functional languages. We could equally call this a set of mutually tail-recursive pure functions \cite{appel1998ssa}. This form is excellent for a wide variety of analysis, optimisation and transformation (eg autodiff on SSA, \citealt{innes2020sense}). All local control flow, however complex, can be lowered to SSA \cite{cytron1989efficient}.

The main point is that ``mutable'' locals are a corollary of control flow structures, rather than of other kinds of mutation. And control flow is just syntax sugar for simple functions. If syntax sugar does not fundamentally change our programming paradigm, and the latter example is a functional program, the former must be too. At the least, we can agree that mutable locals need not violate referential transparency, because there's no external way to tell they are being used.\footnote{Shared mutable state can also be emulated in a functional language. But a more invasive, global transformation would be needed to capture all of its ``features'', like race conditions and nondeterminism, so it represents a more fundamental difference.}

It is right to say that variables like $r$ are changing. But we use the word \textit{change} in the sense of changing clothes, without assuming any physical alteration.\footnote{\textit{change} derives from words meaning ``barter'' or ``substitute''; ``cause to turn or pass from one state to another''.} A change might compile down to a real modification (of registers, memory or whatever) but this is only coincidence. Change and mutation are distinct; C just happens to conflate them.

\section{The more things change...}

The exploration above suggests that clearer notions of change may help us get the benefits of imperative-style programming, without losing those of the functional style. But simply adding control flow and locals to a functional language is not enough. For one thing, it is clunky to write

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
xs = append(xs, x)
\end{Verbatim}
\vspace{-0.16cm}

every time we want to change $xs$ (in this case, by appending a new element to the list). It has the benefit of being explicit about what is changing, but at the cost of some verbosity, especially when multiple inputs are affected.

We propose a design that takes inspiration from the C-like address operator \texttt{\&}, writing this as

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
append(&xs, x)
\end{Verbatim}
\vspace{-0.16cm}

which is still explicit, but less verbose. We refer to \texttt{\&} as the ``swap operator''. All function calls have a hidden return value, a list of swapped arguments, so that for example

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
result = foo(&a, b, &c)
\end{Verbatim}
\vspace{-0.16cm}

is roughly equivalent to

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
[result, rs] = foo(a, b, c)
a = rs[1]
c = rs[3]
\end{Verbatim}
\vspace{-0.16cm}

We can write a function to swap two variables as follows:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
fn switch(&x, &y) {
  [x, y] = [y, x]
  return
}

a = 1
b = 2
switch(&a, &b) # now a = 2, b = 1
\end{Verbatim}
\vspace{-0.16cm}

where the \texttt{\&a} in the function signature indicates that the final value of \texttt{a} should be returned to the caller.

The use of \texttt{\&} is like the address operator in C, C++, Rust and Swift \cite{ritchie1988c}. But whereas the \textit{change} implied is similar, those languages conflate that change with \textit{mutation} of the stack, with all the knock-on effects that implies. In our implementation no references, pointers or mutable state are created; the \texttt{\&} is syntax sugar for a functional program, which means that program transformations and analyses are not impeded.

A last sprinkle help us recover full convenience. Syntax like \texttt{A[i] = x} and \texttt{foo.bar = baz} can lower to function calls (eg \texttt{set(\&A, x, i})). We can update nested structures like \texttt{append(\&foo.xs, x)}, which roughly becomes:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
xs = foo.xs
append(&xs, x)
foo.xs = xs
\end{Verbatim}
\vspace{-0.16cm}

This looks imperative. But only variables are changing -- not values.

Note that in most languages with mutable locals, closures capture variables by reference. In this more functional setting they should of course capture by value instead. This is more intuitive in many cases anyway (eg a closure that captures a loop counter by reference can lead to confusing bugs).

A side effect of this approach is to avoid a leaky abstraction most imperative language have: types that happen to be implemented as heap-allocated references, like dictionaries or objects, are mutable, whereas basic types like numbers or strings are not. More generally, possible modifications are dictated by the underlying representation in memory, and the choice to make an interface in-place or not may be dictated by implementation concerns. When change and mutation are distinct, any value is just as changeable as any other.

With these relatively minor tweaks -- structured control flow, mutable locals and a bit of syntax sugar -- we can write numerical programs almost exactly as we would in Python or Julia. But because our data structures are values, we have the guarantees needed for aggressive compilation and transformation by default. Such optimisation can be done robustly by the main compiler, without special cases or sharp edges, and while playing nicely with existing language tooling: error messages, debuggers and profilers.

\section{Turning change into mutation}

One reason that change, in the sense we have discussed, and mutation are conflated is that doing things in-place is a good optimisation. Where performance matters, it is crucial that this optimisation be predictable to the programmer. If it isn't, algorithms may not only have unnecessary overheads but also higher computational complexity (because mutations are usually constant time, whereas copies are linear). Having to make copies is therefore a significant downside of the functional style.

It is not fatal, however. Reference counting (and its compile-time analogues, as in Rust or Lobster, \citealt{matsakis2014rust,lobster}) provides a solution: any time the count is $1$, no-one else can see our mutations, so it is safe to update the old data in place.

Koka \cite{leijen2016algebraic} has an implementation of this idea, and it turns out to benefit from the functional pattern of deconstructing and rebuilding data. For example, say we have a type \texttt{Foo} with named fields \texttt{xs}, \texttt{ys} and \texttt{zs}. We want to append a new item, \texttt{x}, to the \texttt{xs} array. In a functional style we might write the update something like this, using pattern matching to destructure \texttt{foo}:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
Foo(xs, ys, zs) = foo
xs2 = append(xs, x)
foo2 = Foo(xs2, ys, zs)
\end{Verbatim}
\vspace{-0.16cm}

After the first line has executed, \texttt{foo} is not used, and can therefore be released. Assuming \texttt{foo} is unique, releasing it will in turn release its hold on \texttt{xs}. \texttt{xs} is now only referenced from one place (the current stack frame) and can safely be updated by mutation.

Consider in contrast the version we wrote above, using an imperative-style update syntax to change \texttt{foo}:

\vspace{-0.16cm}
\begin{Verbatim}[fontsize=\footnotesize]
xs = foo.xs
append(&xs, x)
foo.xs = xs
\end{Verbatim}
\vspace{-0.16cm}

Unlike the last example, \texttt{foo} is live after the first line, because we need it to run the last line. That in turns means \texttt{xs} is referenced in two places (the current stack frame, and \texttt{foo}) and can't be modified in place.

Fortunately, the swap syntax we introduced for nested updates, \texttt{append(\&foo.xs, x)}, can also account for this case. Rather than expanding directly to the above, it expands to code that decomposes and rebuilds \texttt{foo} more like the functional-style example. This can work recursively, meaning that updates to deeply-nested structures will still reliably happen in place where possible.

\section{Related work}

There are many interesting efforts to bridge the gap between functional and imperative, including within numerical and differentiable programming.

Dex \cite{maclaurin2019dex} aims to do numerical programming and code transformation in a Haskell-like setting, notably using constructs for structured mutation inspired by algebraic effects.

Koka \cite{leijen2016algebraic} is a recent functional language with support for side effects based on algebraic effect handlers. Notably, effects imply that order matters, so Koka uses a C-like syntax for sequences of statements.

Clojure \cite{hickey2008clojure} is related for somewhat tangential reasons. A key benefit of languages like Python is the ease of ``dictionary-oriented programming'', where the built-in data types are flexible enough that users typically don't have to build their own. Clojure showed that this was practical in a functional setting with its persistent data structures, which will be an important component of any system resembling a ``functional Python''.

Rust \cite{matsakis2014rust} takes a different tack to eliminating shared mutable state, not by avoiding mutation but by restricting sharing through static analysis. This approach is probably inappropriate for our use case, but Rust libraries have thought carefully about how to express more advanced techniques, such as multiple threads working on an output array, in a structured and safe way. Those APIs could inspire functional approaches that can reliably compile to efficient code.

\section{Conclusion}

The functional and imperative styles are less at odds than they may first appear. At least in machine learning, the functional approach is valuable for its semantic benefits, while imperative style brings syntactic and expressive convenience. And though the benefits of FP are real, there is no need to make users do SSA transformation by hand. Perhaps surprisingly, it is possible to construct a very imperative \textit{looking} language that nonetheless retains the most important functional properties. Such designs are promising for probabilistic and differentiable programming, offering high flexibility to users expressing models, without sacrificing the ability to do advanced analysis, optimisation and transformation of the resulting code.

\textit{Thanks to Zenna Tavares for encouraging this paper, and to Maximilian Schleich for reviewing a draft.}