diff --git "a/data_all_eng_slimpj/shuffled/split2/finalzzofdq" "b/data_all_eng_slimpj/shuffled/split2/finalzzofdq" new file mode 100644--- /dev/null +++ "b/data_all_eng_slimpj/shuffled/split2/finalzzofdq" @@ -0,0 +1,5 @@ +{"text":"\\section{Introduction} \\label{sec:introduction}\n\nLet $\\mathcal{B}$ be a $\\sigma$-algebra of subsets of a general sample space\n$\\Omega$. Let $\\mathcal{P}$ be a convex class of probability measures on\n$(\\Omega, \\mathcal{B})$. A {\\em scoring rule}\\\/ is any extended real-valued\nfunction ${\\rm S}$ on $\\mathcal{P} \\times \\Omega$ such that \n\\[\n{\\rm S}(P,Q) = \\int {\\rm S}(P,\\omega) \\,{\\rm d} Q(\\omega) \n\\]\nis well-defined for $P, Q \\in \\mathcal{P}$. The scoring rule ${\\rm S}$ is {\\em\n proper}\\\/ relative to $\\mathcal{P}$ if\n\\begin{equation} \\label{eq:proper} \n{\\rm S}(Q,Q) \\leq {\\rm S}(P,Q) \\quad \\mbox{for all} \\quad P, Q \\in \\mathcal{P}. \n\\end{equation}\nIn words, we take scoring rules to be negatively oriented penalties\nthat a forecaster wishes to minimize. If she believes that a future\nquantity or event has distribution $Q$, and the penalty for quoting\nthe predictive distribution $P$ when $\\omega$ realizes is\n${\\rm S}(P,\\omega)$, then~\\eqref{eq:proper} implies that quoting $P = Q$\nis an optimal strategy in expectation. The scoring rule is {\\em\n strictly proper} if~\\eqref{eq:proper} holds with equality only if $P\n= Q$. For recent reviews of the theory and application of proper\nscoring rules see \\citet{Dawid2007}, \\citet{GneitRaft2007}, \n\\citet{DawidMusio2014}, and \\citet{GneitKatz2014}.\n\nThe intent of this note is to draw attention to the simple fact that,\nsubject to customary regularity conditions, any scoring rule can be\n{\\em properized}, in the sense that it can be modified in a\nstraightforward way to yield a proper scoring rule, so that truth\ntelling becomes an optimal strategy. Implicitly, this construction\nhas recently been used by various authors in various types of\napplications; see, e.g., \\citet{Diks2011}, \\citet{Christetal2014} and\n\\citet{HolzKlar2018}.\n\n\\begin{theorem}[properization] \\label{th:properization} \nLet\\\/ ${\\rm S}$ be a scoring rule. Suppose that for every\\\/ $P \\in \\mathcal{P}$\nthere is a probability distribution\\\/ $P^* \\in \\mathcal{P}$ such that \n\\begin{equation} \\label{eq:Bayes} \n{\\rm S}(P^*,P) \\leq {\\rm S}(Q,P) \\quad \\mbox{for all} \\quad Q \\in \\mathcal{P}. \n\\end{equation} \nThen the function\n\\begin{equation} \\label{eq:S*} \n{\\rm S}^* : \\mathcal{P} \\times \\Omega \\to \\bar{\\mathbb{R}}, \\quad \n(P,\\omega) \\mapsto {\\rm S}^*(P,\\omega) = {\\rm S}(P^*,\\omega), \n\\end{equation} \nis a proper scoring rule. \n\\end{theorem} \n\nHere and in what follows we denote the real line by $\\mathbb{R}$ and the\nextended real line by $\\bar{\\mathbb{R}} := \\mathbb{R} \\cup \\{ - \\infty, \\infty \\}$.\nAny probability measure $P^*$ with the property~\\eqref{eq:Bayes} is\ncommonly called {\\em Bayes act}; for the existence of Bayes acts,\nsee Section~\\ref{sec:existence}. In case there are multiple\nminimizers of the expected score $Q \\mapsto {\\rm S}(Q, P)$, the function\n${\\rm S}^*$ is well-defined by using a mapping $P \\mapsto P^*$ that\nchooses a $P^*$ out of the set of minimizers. If ${\\rm S}$ is proper and\n$P^* = P$, then ${\\rm S}^* = {\\rm S}$, so the proper scoring rules are fixed\npoints under the properization operator.\n\nImportantly, Theorem~\\ref{th:properization} is a special case of a\ngeneral and powerful construction studied in detail by\n\\citet{GruenDawid2004} and \\citet{Dawid2007}. Specifically, given\nsome action space $\\mathcal{A}$ and a loss function ${\\rm L} : \\mathcal{A} \\times \\Omega\n\\to \\bar{\\mathbb{R}}$, suppose that for each $P \\in \\mathcal{P}$ there is a Bayes act\n$a_P \\in \\mathcal{A}$, such that\n\\[\n\\int {\\rm L}(a_P,\\omega) \\,{\\rm d} P(\\omega) \\leq \\int {\\rm L}(a, \\omega) \\,{\\rm d} P(\\omega) \n\\quad \\mbox{for all} \\quad a \\in \\mathcal{A}. \n\\]\nThen the function\n\\[\n{\\rm S}^* : \\mathcal{P} \\times \\Omega \\to \\bar{\\mathbb{R}}, \\quad \n(P,\\omega) \\mapsto {\\rm S}^*(P,\\omega) = {\\rm L}(a_P,\\omega), \n\\]\nis a proper scoring rule. Note the natural connection to decision-\nand utility-based scoring approaches, where the quality of a forecast\nis judged by the monetary utility of the induced acts and decisions\n\\citep{GranPesa2000, GranMach2006, Ehmetal2016}.\n\nIn the remainder of the paper we focus on the above special case in\nwhich the action domain $\\mathcal{A}$ is the class $\\mathcal{P}$. In\nSection~\\ref{sec:examples} we identify scattered results in the\nliterature as prominent special cases of properization\n(Examples~\\ref{ex:binary}--\\ref{ex:PMC}), and we use\nTheorem~\\ref{th:properization} to construct new proper scoring rules\nfrom improper ones (Examples~\\ref{ex:CRPS}--\\ref{ex:probScore}).\nSection~\\ref{sec:existence} gives sufficient conditions for the\nexistence of Bayes acts and Section~\\ref{sec:discussion} contains a\nbrief discussion. All proofs and technical details are moved to the\n\\hyperref[sec:appendix]{Appendix}.\n\n\n\\section{Examples} \\label{sec:examples}\n\nThis section starts with an example in which we review the ubiquitous\nmisclassification error from the perspective of properization. We go\non to demonstrate how Theorem~\\ref{th:properization} has been used\nimplicitly to construct proper scoring rules in econometric,\nmeteorological, and statistical strands of literature. The notion of\nproperization simplifies and shortens the respective proofs of\npropriety, makes them much more transparent, and puts the scattered\nexamples into a unifying and principled joint framework. Further\nexamples show other facets of properization: The scoring rules\nconstructed in Example~\\ref{ex:CRPS} are original, and the discussion\nin Example~\\ref{ex:CRPS2} illustrates a connection to the practical\nproblem of the treatment of observational uncertainty in forecast\nevaluation. Finally, Example~\\ref{ex:probScore} includes an instance\nof a situation in which properization fails.\n\n\n\\begin{example} \\label{ex:binary}\nConsider probability forecasts of a binary event, where $\\Omega =\n\\lbrace 0,1 \\rbrace$ and $\\mathcal{P}$ is the class of the Bernoulli measures.\nWe identify any $P \\in \\mathcal{P}$ with the probability $p = P(\\lbrace 1\n\\rbrace) \\in [0,1]$ and consider the scoring rules\n\\[\n{\\rm S}_1(P,\\omega) := 1 - p \\omega - (1-p)(1-\\omega) \n\\quad \\text{ and } \\quad \n{\\rm S}_2(P,\\omega) := |p-\\omega|.\n\\]\nThe scoring rule ${\\rm S}_1$ corresponds to the mean probability rate\n(MPR) in machine learning \\citep[p.~30]{Ferrietal2009}. The scoring\nrule ${\\rm S}_2$ was first considered by \\citet{Dawid1986}. It agrees\nwith the special case $c_1 = c_2$ in Section~4.2 of\n\\citet{Parry2016} and corresponds to the mean absolute error (MAE)\nas discussed by \\citet[p.~30]{Ferrietal2009}.\\footnote{As noted by\n \\citet{Parry2016}, the improper score ${\\rm S}_2$ shares its (concave)\n expected score function $P \\mapsto {\\rm S}_2(P,P)$ with the proper\n Brier score. This illustrates the importance of the second\n condition in Theorem 1 of \\citet{GneitRaft2007}: For a scoring rule\n ${\\rm S}$ the (strict) concavity of the expected score function $ G(P)\n := {\\rm S}(P,P)$ is equivalent to the (strict) propriety of ${\\rm S}$ only\n if, furthermore, $- {\\rm S}(P,\\cdot)$ is a subtangent of $- G$ at $P$.}\nBoth ${\\rm S}_1$ and ${\\rm S}_2$ are improper with common Bayes act\n\\[\n\\textstyle\np^* = \\one{p \\geq \\frac{1}{2}} \\in \\lbrace 0,1 \\rbrace, \n\\]\nand with the same properized score given by the zero-one rule \n\\[\n{\\rm S}^*(P,\\omega) = \\left\\lbrace \n\\begin{array}{cl}\n0, & p^* = \\omega, \\\\\n1, & \\text{otherwise.}\n\\end{array}\n\\right.\n\\]\nA case-averaged zero-one score is typically referred to as {\\em\n misclassification rate}\\\/ or {\\em misclassification error};\nundoubtedly, this is the most popular and most frequently used\nperformance measure in binary classification. While the scoring rule\n${\\rm S}^*$ is proper it fails to be strictly proper\n(\\citealp[Example 4]{GneitRaft2007};\n\\citealp[Section 4.3]{Parry2016}). Consequently, misclassification\nerror has serious limitations as\na performance measure, as persuasively argued by \n\\citet[p.~258]{Harrell2015}, among others. Nevertheless, the scoring\nrule ${\\rm S}^*$ is proper, contrary to recent claims of impropriety in\nthe blogosphere.\\footnote{See, e.g., \n \\url{http:\/\/www.fharrell.com\/post\/class-damage\/} and\n \\url{http:\/\/www.fharrell.com\/post\/classification\/}.}\n\\end{example}\n\nFor the remainder of the section, let $\\Omega = \\mathbb{R}$ and let $\\mathcal{B}$\nbe the Borel $\\sigma$-algebra. We let $\\mathcal{L}$ be the class of Borel\nmeasures $P$ with a Lebesgue density, $p$. Furthermore, we write\n$\\mathcal{P}_k$ for the measures with finite $k$-th moment and $\\mathcal{P}_k^+$ for\nthe subclasses when Dirac measures are excluded. Whenever it\nsimplifies notation, we identify $P$ with its cumulative distribution\nfunction $x \\mapsto P((-\\infty, x])$.\n\n\\begin{example} \\label{ex:weighted} \nLet ${\\rm S}_0$ be a proper scoring rule on some subclass $\\mathcal{P}$ of $\\mathcal{L}$\nand let\\\/ $w$ be a nonnegative weight function such that\\\/ $0 < \\int\nw(z) \\, p(z) \\,{\\rm d} z < \\infty$ for $p \\in \\mathcal{P}$. Let\n\\[ \n{\\rm S} : \\mathcal{P} \\times \\mathbb{R} \\to \\mathbb{R}, \\quad (P,y) \\mapsto {\\rm S}(P,y) = w(y) \\, {\\rm S}_0(P,y); \n\\] \nthis score is improper unless the weight function is constant.\nIndeed, by Theorem~1 of \\citet{GneitRanjan2011}, the Bayes act $P^*$\nunder ${\\rm S}$ has density\n\\[\np^*(y) = \\frac{w(y) \\, p(y)}{\\int w(z) \\, p(z) \\,{\\rm d} z}.\n\\]\nFrom this we see that the key statement in Theorem~1 of\n\\citet{HolzKlar2018} constitutes a special case of Theorem\n\\ref{th:properization}. In the further special case in which ${\\rm S}_0$\nis the logarithmic score, the properized score~\\eqref{eq:S*} recovers\nthe conditional likelihood score of \\cite{Diks2011} up to equivalence,\nas noted in Example 1 of \\citet{HolzKlar2018}. For analogous results\nfor consistent scoring functions see Theorem~5 of \\citet{Gneit2011}\nand Example~2 of \\citet{HolzKlar2018}.\n\\end{example} \n\n\\begin{example} \\label{ex:error.spread} \nFor a probability measure $P \\in \\mathcal{P}_4$, let $\\mu_P$, $\\sigma^2_P$,\nand $\\gamma_P$ denote its mean, variance, and centered third moment.\nLet\n\\[\n{\\rm S}(P,y) = \\left( \\sigma_P^2 - (y - \\mu_P)^2 \\right)^2 \n\\]\nbe the `trial score' in equation~(16) of \\citet{Christetal2014}. As\n\\citet{Christetal2014} show in their Appendix A, any Bayes act\n$P^*$ under ${\\rm S}$ has mean $ \\mu_P + \\tfrac{1}{2}\n\\tfrac{\\gamma_P}{\\sigma_P^2}$ and variance \n\\[\n\\sigma_P^2 \\left( 1 + \\frac{1}{4} \\frac{\\gamma_P^2}{\\sigma_P^6} \\right), \n\\]\nso properization yields the spread-error score,\n\\[\n{\\rm S}^*(P,y) = \\left( \\sigma_P^2 - \\left( y - \\mu_P \\right)^2\n+ \\left( y - \\mu_P \\right) \\frac{\\gamma_P}{\\sigma_P^2} \\right)^2 ,\n\\]\nwhich is proper relative to the class $\\mathcal{P}_4^+$. Hence the\nconstruction of the spread-error score in \\citet{Christetal2014}\nconstitutes another special case of Theorem~\\ref{th:properization}.\n\\end{example} \n\n\\begin{example} \\label{ex:PMC} \nThe predictive model choice criterion of \\citet{LaudIbra1995} and\n\\citet{GelfGhosh1998} uses the scoring rule ${\\rm S}(P,y) = \\left( y -\n\\mu_P \\right)^2 + \\sigma_P^2$, where $\\mu_P$ and $\\sigma_P^2$ denote\nthe mean and the variance of a distribution $P \\in \\mathcal{P}_2$,\nrespectively. As pointed out by \\citet{GneitRaft2007}, this score\nfails to be proper. Specifically, any Bayes act $P^*$ under ${\\rm S}$\nhas mean $ \\mu_P$ and vanishing variance, so properization yields the\nubiquitous squared error, ${\\rm S}^*(P,y) = \\left( y - \\mu_P \\right)^2$.\n\\end{example} \n\nThe original scoring rules of Examples~\\ref{ex:error.spread}\nand~\\ref{ex:PMC} can be interpreted as functions $ {\\rm S} : \\mathcal{A} \\times\n\\Omega \\rightarrow \\mathbb{R}$ in the Bayes act setting of\n\\citet{GruenDawid2004} and \\citet{Dawid2007}, where the action space\n$\\mathcal{A}$ is given by $\\mathbb{R} \\times [0, \\infty)$. Hence, the\n properization method can be interpreted as an application of\n Theorem~3 of \\citet{Gneit2011} to consistent scoring functions for\n elicitable two-dimensional functionals, as discussed by\n \\citet{FissZieg2016}.\n\nDetailed arguments and calculations for the subsequent examples are\ndeferred to the \\hyperref[sec:appendix]{Appendix}.\n\n\\begin{example} \\label{ex:CRPS} \nFor $\\alpha > 0$ consider the scoring rule \n\\[\n{\\rm S}_\\alpha (P,y) = \\int \\left| P(x) - \\one{y \\le x} \\right|^\\alpha \\,{\\rm d} x,\n\\]\nwhere $P$ is identified with its cumulative distribution function\n(CDF). For $\\alpha = 2$ this is the well known proper continuous\nranked probability score (CRPS), as reviewed in Section 4.2 of\n\\citet{GneitRaft2007}. For $\\alpha = 1$ the score ${\\rm S}_\\alpha$ was\nproposed by \\citet{Muelleretal2005}, and \\citet{ZamoNaveau2018} show\nin their Appendix A that for discrete distributions every Dirac\nmeasure in a median of $P$ is a Bayes act. The same holds true for\ngeneral distributions and for all $\\alpha \\in (0,1]$. If $\\alpha >\n1$, the Bayes act $P^*$ under ${\\rm S}_\\alpha$ is given by\n\\begin{equation} \\label{eq:CRPS_alpha_P*}\nP^* (x) = \\left( \n1 + \\left( \\frac{1 - P(x)}{P(x)} \\right)^{1\/(\\alpha - 1)} \\right)^{-1} \\one{P(x) > 0},\n\\end{equation}\nand all in all we see that properization of ${\\rm S}_\\alpha$ works for\nany $\\alpha > 0$.\n\nMoreover, in the case $\\alpha >1$ the mapping $P \\mapsto P^*$ is even\ninjective. Consequently, if the class $\\mathcal{P}$ is such that $P^* \\in \\mathcal{P}$\nand ${\\rm S}_\\alpha(P^*,P)$ is finite for $P \\in \\mathcal{P}$, the properized\nscore~\\eqref{eq:S*} is even strictly proper relative to $\\mathcal{P}$. If\n$\\alpha \\in (1,2]$, this can be ensured by restricting ${\\rm S}_\\alpha$\nto the class $\\mathcal{P}_1$. For $\\alpha > 2$ the class $\\mathcal{P}_{\\mathrm c}$ of\nthe Borel measures with compact support is a suitable choice.\n\\end{example} \n\n\\begin{example} \\label{ex:CRPS2}\n\\citet[p.~58]{FriedThor2012} propose a modification of the CRPS that\naims to account for observational error in forecast evaluation.\nSpecifically, they consider the scoring rule\n\\[\n{\\rm S}_\\Phi (P, y) = \\int \\left| P(x) - \\Phi(x-y) \\right|^2 \\,{\\rm d} x,\n\\]\nwhere $\\Phi \\in \\mathcal{P}_1^+$ represents additive observation error. This\nscoring rule fails to be proper, as for probability measures $P, Q \\in\n\\mathcal{P}_1$ we have\n\\begin{equation} \\label{eq:NoisyCRPS}\n{\\rm S}_\\Phi (P, Q) = \\mathrm{CRPS} (P, Q * \\Phi) - \\mathrm{CRPS} (\\Phi, \\Phi),\n\\end{equation}\nwhere $*$ denotes the convolution operator. Due to the strict\npropriety of the CRPS relative to the class $\\mathcal{P}_1$, the unique Bayes\nact under ${\\rm S}_\\Phi$ is given by $P^* = P * \\Phi$.\nTheorem~\\ref{th:properization} now gives the scoring rule\n${\\rm S}(P,y) := {\\rm S}_\\Phi (P^*, y)$, which is proper relative to\n$\\mathcal{P}_1$.\n\nIn order to account for noisy observational data in forecast\nevaluation, equation~\\eqref{eq:NoisyCRPS} suggests using the scoring\nrule ${\\rm S} (P,y) := \\mathrm{CRPS} (P^*, y)$ if the noise is independent,\nadditive, and has distribution $\\Phi$. This corresponds to predicting\nhypothetical true values, to which noise is added before they are\ncompared to observations. The drawbacks of this approach and\nalternative techniques are discussed by~\\citet{Ferro2017}. The\nassociated issues in forecast evaluation remain challenges to the\nscientific community at large; see, e.g., \\cite{Ebertetal2013}\nand \\cite{Ferro2017}.\n\n\\end{example}\n\n\n\\begin{example} \\label{ex:probScore}\nLet ${\\rm S}$ be a scoring rule, and let $\\Phi \\in \\mathcal{L}$ be a distribution\nwith Lebesgue density $\\varphi$. Suppose $\\mathcal{P}$ is a class of\ndistributions such that $P * \\Phi \\in \\mathcal{P}$ for $P \\in \\mathcal{P}$. For $P\n\\in \\mathcal{P}$ define\n\\[\n{\\rm S}^\\varphi (P, y) := \\int \\varphi (x-y) \\, {\\rm S} (P, x) \\,{\\rm d} x,\n\\]\nwhich is again a scoring rule. If ${\\rm S}$ is proper, a Bayes act\nunder ${\\rm S}^\\varphi$ is given by $P^* = P * \\Phi$, since ${\\rm S}^\\varphi\n(P, Q) = {\\rm S}(P, Q * \\Phi )$ for $Q \\in \\mathcal{P}$, and if ${\\rm S}$ is\nstrictly proper, the Bayes act is unique. Properization now gives the\nproper scoring rule ${\\rm S}(P,y) := {\\rm S}^\\varphi (P^*, y)$. An\ninteresting special case emerges when substituting the CRPS for\n${\\rm S}$. This leads to\n\\begin{equation} \\label{eq:NoisyCRPS2}\n\\mathrm{CRPS}^\\varphi (P,y) = {\\rm S}_\\Phi (P,y ) + \\mathrm{CRPS} (\\Phi, \\Phi), \n\\end{equation}\nwhere ${\\rm S}_\\Phi$ is the scoring rule in the previous example. For\nanother special case, let $c > 0$ and $P \\in \\mathcal{L}$, to yield\n\\[\n\\mathrm{PS}_c(P, y) := - \\int_{y-c}^{y+c} p(x) \\,{\\rm d} x, \n\\]\nwhich recovers the {\\em probability score}\\\/ of\n\\citet{Wilsonetal1999}. We have that $\\mathrm{PS}_c = 2c \\,\n\\mathrm{LinS}^{\\varphi_c}$, where $ \\mathrm{LinS}(P,y) := - p(y)$ is\nthe improper linear score and $\\varphi_c$ is a uniform density on\n$[-c,c]$. Properization is not feasible relative to sufficiently rich\nclasses $\\mathcal{P}$, as Bayes acts fail to exist under both the linear\nscore and the probability score. For details, see the\n\\hyperref[sec:appendix]{Appendix}.\n\\end{example}\n\n\n\\section{Existence of Bayes acts} \\label{sec:existence}\n\nIn Example~\\ref{ex:probScore} we presented a scoring rule that cannot\nbe properized, due to the non-existence of Bayes acts. This section\naddresses the question under which conditions on ${\\rm S}$ and $\\mathcal{P}$ a\nminimum of the expected score function exists. To illustrate the\nideas, we start with a further example.\n\n\\begin{example} \\label{ex:normalized}\nUsing the notation of Example~\\ref{ex:error.spread}, consider the\nnormalized squared error,\n\\begin{equation*}\n{\\rm S}(P,y) = \\frac{(y - \\mu_P)^2}{\\sigma_P^2}, \n\\end{equation*}\nas a scoring rule on the classes $\\mathcal{P}_{2,m}$ of the Borel measures\nwith variance at most $m$, and $\\mathcal{P}_2 = \\cup_{m > 0} \\mathcal{P}_{2,m}$,\nrespectively. Relative to $\\mathcal{P}_{2,m}$ any Bayes act $P^*$ under\n${\\rm S}$ has mean $\\mu_P$ and variance $m$, so properization yields\n(non-normalized) squared error up to equivalence. Relative to $\\mathcal{P}_2$\nhowever, there is no Bayes act, since increasing the variance will\nalways lead to a smaller expected score.\n\\end{example}\n\nWe now turn to a general perspective and discuss sufficient\nconditions for the existence of Bayes acts. At first, consider a\nfinite probability space $\\Omega = \\lbrace \\omega_1, \\ldots, \\omega_k\n\\rbrace$. In this situation, geometrical arguments yield sufficient\nconditions. In particular, a Bayes act under ${\\rm S}$ exists if the\n\\textit{risk set}\n\\[\n\\mathcal{S} := \\lbrace (x_1, \\ldots, x_k) \\mid \\exists \\, P \\in\n\\mathcal{P} : x_j = {\\rm S} (P, \\omega_j) , \\, j=1,\\ldots, k \\rbrace\n\\subset \\mathbb{R}^k\n\\]\nis closed from below and bounded from below; see Theorem~1 in\nChapter~2.5 of \\citet{Ferguson1967}. Extending this result to a general\nsample space $\\Omega$ is non-trivial since in this case $\\mathcal{S}$\ncan be a subset of an infinite-dimensional vector space. In the\nfollowing we employ well-known concepts of functional analysis in order\nto discuss two possible extensions. All proofs are deferred to the\n\\hyperref[sec:appendix]{Appendix}.\n\n\nLet $\\mathcal{P}$ be a set of probability measures on a general probability\nspace $\\Omega$ and let $\\mathcal{A}$ be a topological space. We return to the\nsetting of Section~\\ref{sec:introduction} and consider functions\n${\\rm S}: \\mathcal{A} \\times \\Omega \\rightarrow \\mathbb{R}$. This makes the results\nmore general and easier to apply in situations where the scoring rule\ndepends on $P$ only via some finite number of parameters. Concerning\nthe latter point, note that the normalized squared error of\nExample~\\ref{ex:normalized} can be written as a composition of the\nmapping $P \\mapsto (\\mu_P, \\sigma^2_P)$ and the function $s(x_1,x_2,y)\n:= (y -x_1)^2 \/ x_2$, with $s$ being defined on $\\mathbb{R} \\times (0,\n\\infty) \\times \\mathbb{R}$. Consequently, the expected normalized squared\nerror attains its minimum if the expected score of $s$ attains its\nminimum. Note that such a decomposition of the scoring rule is\npossible for Examples~\\ref{ex:error.spread} and~\\ref{ex:PMC} as well,\nas alluded to in the comments that succeed these examples. \n\nWe impose the following integrability assumption on ${\\rm S}$.\n\n\\begin{definition}\nThe mapping ${\\rm S}: \\mathcal{A} \\times \\Omega \\rightarrow \\mathbb{R}$ is\n\\textit{uniformly bounded from below} if there exists a function\n$g: \\Omega \\rightarrow \\mathbb{R}$ which is integrable with respect to any\n$P \\in \\mathcal{P}$ and such that ${\\rm S} (a,\\cdot) \\geq g$ holds for all\n$a \\in \\mathcal{A}$.\n\\end{definition}\n\nOur first result is similar to Theorem~2 in Chapter~2.9 of\n\\citet{Ferguson1967}, which proves the existence of minimax decision\nrules. \n\n\\begin{theorem} \\label{th:existence1}\nSuppose ${\\rm S}$ is lower semicontinuous in its first component and\nuniformly bounded from below. If\\\/ $\\mathcal{A}$ is compact, then the function\n$a \\mapsto {\\rm S}(a,P)$ attains its minimum for any $P \\in \\mathcal{P}$.\n\\end{theorem}\n\nThis theorem can be used to prove the existence of a Bayes act\nfor a given scoring rule. However, it is not applicable to\nExample~\\ref{ex:normalized}. To see this, recall the decomposition of\n${\\rm S}$ mentioned above and note that restricting ${\\rm S}$ to $\\mathcal{P}_{2,m}$\ncorresponds to restricting $s$ to $\\mathbb{R} \\times (0,m]$. The latter set\nis not a compact space and neither is its closure. Consequently, we aim\nto dispense with the compactness assumption used in\nTheorem~\\ref{th:existence1}.\n\nTo do so, we need additional concepts from functional analysis. Let\n$\\mathcal{X}$ be a real normed vector space. Recall that a function $h : \\mathcal{X}\n\\rightarrow \\mathbb{R}$ is called \\textit{coercive} if for any sequence\n$(x_n)_{n \\in \\mathbb{N}} \\subset \\mathcal{X}$ the implication\n\\begin{equation*}\n\\lim_{n \\rightarrow \\infty} \\Vert x_n \\Vert = \\infty \\quad \\Rightarrow \\quad \\lim_{n \\rightarrow \\infty} h(x_n) = \\infty\n\\end{equation*}\nholds true, see, e.g.~Definition~III.5.7 in~\\citet{Werner2018}. By\n\\textit{weak topology} on $\\mathcal{X}$, we mean the weakest topology such\nthat all real-valued linear mappings on $\\mathcal{X}$ are continuous; see,\ne.g.~Chapters~2.13 and~6.5 in~\\citet{AlipBord2006}. The space $\\mathcal{X}$ is\ncalled a \\textit{reflexive Banach space} if it is complete and the\ncanonical embedding of $\\mathcal{X}$ into its bidual space is surjective; see,\ne.g.~Chapter~III.3 in~\\citet{Werner2018} or Chapter~6.3\nin~\\citet{AlipBord2006}. Combining these concepts, we obtain a\ncomplement to Theorem~\\ref{th:existence1}.\n\n\\begin{theorem} \\label{th:existence2}\nLet $\\mathcal{A}$ be a weakly closed subset of a reflexive Banach space.\nMoreover, suppose ${\\rm S}$ is weakly lower semicontinuous in its first\ncomponent and uniformly bounded from below. If the function $a \\mapsto\n{\\rm S}(a,P)$ is coercive, then it attains its minimum.\n\\end{theorem}\n\nThis result yields the existence of Bayes acts as long as the\nintegrated scoring rule is coercive for any $P \\in \\mathcal{P}$, where $\\mathcal{P}$\nis a reflexive Banach space. To conclude this section, we connect\nTheorem~\\ref{th:existence2} to Example~\\ref{ex:normalized}: The\nfunction $s(\\cdot, \\cdot, y)$ from the decomposition of ${\\rm S}$\nmentioned above is defined on $\\mathbb{R} \\times (0, \\infty)$, which is a\nsubset of the reflexive Banach space $\\mathbb{R}^2$. Moreover, $s$ is\nbounded from below by zero and continuous in its first component. As\nmentioned above, restricting the class $\\mathcal{P}_2$ to $\\mathcal{P}_{2,m}$\ncorresponds to restricting the domain of $s$ to $\\mathbb{R} \\times (0, m]$\nand in this situation, integrating $s$ with respect to $y$ gives a\ncoercive function. Consequently, Theorem~\\ref{th:existence2} can be\nused to show that ${\\rm S}$ can be properized if restricted to\n$\\mathcal{P}_{2,m}$.\n\n\n\\section{Discussion} \\label{sec:discussion}\n\nIn this article we have introduced the concept of properization, which\nis rooted in the Bayes act construction of \\citet{GruenDawid2004} and\n\\citet{Dawid2007}, and we have drawn attention to its widespread\nimplicit use in the transdisciplinary literature on proper scoring\nrules, where our unified approach yields simplified, shorter, and\nconsiderably more instructive and transparent proofs than extant\nmethods. Moreover, using new examples, we have demonstrated the power\nof the properization approach in the creation of new proper scoring\nrules from existing improper ones. \n\nSince the central element in the construction of a properized score is\na Bayes act, we have discussed conditions on the scoring rule ${\\rm S}$\nand the class $\\mathcal{P}$ that guarantee its existence. Undoubtedly, there\nare alternative paths to existence results in the spirit of\nTheorems~\\ref{th:existence1} and~\\ref{th:existence2}, and the\nderivation of sufficient conditions in alternative situations is an\ninteresting open problem. Furthermore, we have not explored necessary\nconditions for the existence of Bayes acts in this work. Their\nderivation and the refinement of sufficient conditions on ${\\rm S}$ and\n$\\mathcal{P}$ remain challenges that we leave for future work.\n\n\n\\section*{Appendix: Proofs} \\label{sec:appendix}\n\\addcontentsline{toc}{section}{Appendix: Proofs}\n\nHere we present detailed arguments for the technical claims in\nExamples~\\ref{ex:CRPS}, \\ref{ex:CRPS2}, and~\\ref{ex:probScore}\nas well as the proofs of Theorems~\\ref{th:existence1}\nand~\\ref{th:existence2}.\n\n\\subsection*{Details for Example~\\ref{ex:CRPS}}\n\\addcontentsline{toc}{subsection}{Details for Example~\\ref{ex:CRPS}}\n\nWe fix some distribution $P$ and start with the case $\\alpha > 1$. An\napplication of Fubini's theorem gives\n\\begin{equation} \\label{eq:Ex4SQP}\n{\\rm S}_\\alpha (Q,P) = \\int \\int \\vert Q(x) - \\one{y \\leq x} \\vert^\\alpha \\,{\\rm d} P(y) \\,{\\rm d} x .\n\\end{equation}\nGiven $x \\in \\mathbb{R}$ we seek the value $Q(x) \\in [0,1]$ that minimizes\nthe inner integral in~\\eqref{eq:Ex4SQP}. If $x$ is such that $P(x)\n\\in \\lbrace 0, 1 \\rbrace$, the equality $\\one{y \\leq x} = P(x)$ holds\nfor $P$-almost all $y$, hence $Q(x)= P(x)$ is the unique minimizer.\nIf $x$ satisfies $P(x) \\in (0,1)$, define the function\n\\[\ng_{x,P}(q) := \\int \\vert q - \\one{y \\leq x} \\vert^\\alpha \\,{\\rm d} P(y) \n= (1-P(x)) q^\\alpha + P(x) (1-q)^\\alpha,\n\\]\nwhich is strictly convex in $q \\in (0,1)$ with derivative\n\\[\ng_{x,P}'(q) = \\alpha (1- P(x)) q^{\\alpha - 1} - \\alpha P(x) (1- q)^{\\alpha - 1}\n\\]\nand a unique minimum at $q = q_{x,P}^* \\in (0,1)$. As a consequence,\nthe minimizing value $Q(x)$ is given by\n\\begin{equation*}\nQ(x) = q_{x,P}^* = \\left( 1 + \\left( \\frac{1-P(x)}{P(x)} \\right)^{1\/(\\alpha - 1)} \\right)^{-1}.\n\\end{equation*}\nThe function $Q$ defined by the minimizers $Q(x)$, $x \\in \\mathbb{R}$ is a\nminimizer of ${\\rm S}_\\alpha ( \\cdot ,P)$ and if ${\\rm S}_\\alpha (Q, P)$ is\nfinite, it is unique Lebesgue almost surely. Since $\\alpha >1$ the\nfunction $Q$ has the properties of a distribution function and hence\n$P^*$ defined by~\\eqref{eq:CRPS_alpha_P*} is a Bayes act for\n$P$. Moreover, equation~\\eqref{eq:CRPS_alpha_P*} shows that the\nrelation between $P$ and $P^*$ is one-to-one.\n\nIt remains to be checked under which conditions the properization of\n${\\rm S}_\\alpha$ is not only proper but strictly proper. The\nrepresentation~\\eqref{eq:CRPS_alpha_P*} along with two Taylor\nexpansions implies that $P^*$ behaves like $P^{1\/(\\alpha -1)}$ in the\ntails. This has two consequences. At first, the above arguments show\nthat for ${\\rm S}_\\alpha (P^*, P)$ to be finite $x \\mapsto g_{x,P}\n(P^*(x))$ has to be integrable with respect to Lebesgue measure.\nHence, the tail behavior of $P^*$ and the inequality $\\alpha\/(\\alpha\n- 1) > 1$ for $\\alpha > 1$ show that ${\\rm S}_\\alpha (P^*, P)$ is finite\nfor $P \\in \\mathcal{P}_1$. Second, $P^*$ has a lighter tail than $P$ for\n$\\alpha \\in (1,2)$ and a heavier tail for $\\alpha > 2$. In the latter\ncase $P \\in \\mathcal{P}_1$ does not necessarily imply $P^* \\in \\mathcal{P}_1$. Hence,\nwithout additional assumptions, strict propriety of the properized\nscore~\\eqref{eq:S*} can only be ensured relative to $\\mathcal{P}_\\mathrm{c}$\nfor $\\alpha > 2$ and relative to the class $\\mathcal{P}_1$ for $\\alpha \\in (1,\n2]$.\n \nWe now turn to $\\alpha \\in (0,1)$. In this case, the function\n$g_{x,P}$ is strictly concave, and its unique minimum is at $q = 0$\nfor $P(x) < \\frac{1}{2}$ and at $q = 1$ for $P(x) > \\frac{1}{2}$. If\n$P(x) = \\frac{1}{2}$, then both $0$ and $1$ are minima. Arguing as\nabove, every Bayes act $P^*$ is a Dirac measure in a median of $P$.\n\nFinally, $\\alpha = 1$ implies that $g_{x,P}$ is linear, thus, as for\n$\\alpha \\in (0,1)$, every Dirac measure in a median of $P$ is a Bayes\nrule. The only difference to the case $\\alpha \\in (0,1)$ is that if\nthere is more than one median, there are Bayes acts other than Dirac\nmeasures, since $g_{x,P}$ is constant for all $x$ satisfying $P(x) =\n\\frac{1}{2}$.\n\n\\subsection*{Details for Example~\\ref{ex:CRPS2}}\n\\addcontentsline{toc}{subsection}{Details for Example~\\ref{ex:CRPS2}}\n\nLet $P, Q$ and $\\Phi$ be distribution functions. By the\ndefinition of the convolution operator\n\\begin{equation*}\n\\int \\one{y \\leq x} \\,{\\rm d} (Q * \\Phi) (y) = \\int \\Phi (x-y) \\,{\\rm d} Q(y) \n\\end{equation*}\nholds for $x \\in \\mathbb{R}$. Using this identity and Fubini's theorem\nleads to\n\\begin{align*}\n{\\rm S}_\\Phi (P,Q) \n& = \\int \\! \\int \\left( P(x)^2 - 2 P(x) \\Phi(x-y) + \\Phi(x-y)^2 \\right) \\,{\\rm d} Q(y) \\,{\\rm d} x \\\\\n& = \\int \\! \\int \\left( P(x)^2 - 2 P(x) \\one{y \\leq x} + \\one{y \\leq x} \\right) \\,{\\rm d} (Q * \\Phi)(y) \\,{\\rm d} x \\\\\n& \\quad + \\int \\! \\int \\Phi(x-y) (\\Phi(x-y) - 1) \\,{\\rm d} Q(y) \\,{\\rm d} x \\\\\n& = \\int \\! \\int (P(x) - \\one{y \\leq x})^2 \\,{\\rm d} x \\,{\\rm d} (Q * \\Phi)(y) \n - \\int \\Phi (x) (1- \\Phi (x)) \\,{\\rm d} x,\n\\end{align*}\nwhich verifies equality in~\\eqref{eq:NoisyCRPS}. Moreover, the strict\npropriety of the CRPS relative to the class $\\mathcal{P}_1$ gives ${\\rm S}_\\Phi\n(P, Q) < \\infty$ for $P, Q, \\Phi \\in \\mathcal{P}_1$, thereby demonstrating\nthat the Bayes act is unique in this situation.\n\n\\subsection*{Details for Example~\\ref{ex:probScore}}\n\\addcontentsline{toc}{subsection}{Details for Example~\\ref{ex:probScore}}\n\nFor distributions $P, Q \\in \\mathcal{P}$ and $c > 0$, the Fubini-Tonelli\ntheorem and the definition of the convolution operator give\n\\begin{align*}\n{\\rm S}^\\varphi (P,Q) &= - \\int \\int \\varphi (x-y) {\\rm S}(P,x) \\,{\\rm d} Q(y) \\,{\\rm d} x \\\\\n&= \\int \\int \\varphi (x-y) \\,{\\rm d} Q(y) \\, {\\rm S}(P,x) \\,{\\rm d} x = {\\rm S} (P, Q * \\Phi),\n\\end{align*}\nso the stated (unique) Bayes act under ${\\rm S}^\\varphi$ follows from\nthe (strict) propriety of ${\\rm S}$. Proceeding as in the details for\nExample~\\ref{ex:CRPS2} we verify identity~\\eqref{eq:NoisyCRPS2}.\n\nFor $P \\in \\mathcal{L}$ the same calculations as above show that the\nprobability score satisfies\n\\[\n\\mathrm{PS}_c(P,Q) = \n2c \\int \\frac{Q(x + c) - Q(x - c)}{2c} \\: \\mathrm{LinS}(P,x) \\,{\\rm d} x,\n\\]\nwhere $\\mathrm{LinS}(P,y) = - p(y)$ is the linear score.\nConsequently, to demonstrate that Theorem~\\ref{th:properization} is\nneither applicable to $\\mathrm{PS}_c$ nor to $\\mathrm{LinS}$, it\nsuffices to show that there is a distribution $Q$ such that $P \\mapsto\n\\mathrm{LinS}(P,Q)$ does not have a minimizer. We use an argument\nthat generalizes the construction in Section 4.1 of\n\\citet{GneitRaft2007} who show that $\\mathrm{LinS}$ is improper. Let\n$q$ be a density, symmetric around zero and strictly increasing on\n$(-\\infty, 0)$. Let $\\epsilon > 0$ and define the interval $I_k :=\n((2k - 1) \\epsilon, (2k + 1) \\epsilon]$ for $k \\in \\mathbb{Z}$.\n Suppose $p$ is a density with positive mass on some interval $I_k$\n for $k \\neq 0$. Due to the properties of $q$, the score\n $\\mathrm{LinS}(P,Q)$ can be reduced by substituting the density\ndefined by \n\\[\n\\tilde{p}(x) := p(x) - \\one{x \\in I_k} \\, p(x) + \\one{x + 2k \\epsilon\n \\in I_k} \\, p(x + 2k \\epsilon)\n\\]\nfor $p$, i.e., by shifting all probability mass from $I_k$ to the\nmodal interval $I_0$. Repeating this argument for any $\\epsilon > 0$\nshows that no density $p$ can be a minimizer of the expected score\n$\\mathrm{LinS}(P,Q)$. Note that the assumptions on $q$ are stronger\nthan necessary in order to facilitate the argument. They can be\nrelaxed at the cost of a more elaborate proof.\n\n\\subsection*{Proof of Theorem~\\ref{th:existence1}}\n\\addcontentsline{toc}{subsection}{Proof of Theorem~\\ref{th:existence1}}\n\nLet $(a_n)_{n \\in \\mathbb{N}} \\subset \\mathcal{A}$ be a sequence with $ a :=\n\\lim_{n \\rightarrow \\infty} a_n$. Since ${\\rm S}$ is lower semicontinuous\nin its first component and uniformly bounded from below by $g$, Fatou's\nlemma gives\n\\begin{equation*}\n\\liminf_{n \\rightarrow \\infty} \\int {\\rm S} (a_n, \\omega) \\,{\\rm d} P(\\omega)\n\\geq \\int \\liminf_{n \\rightarrow \\infty} {\\rm S} (a_n,\\omega) \\,{\\rm d}\nP(\\omega) \\geq {\\rm S}(a,P)\n\\end{equation*} \nfor any $P \\in \\mathcal{P}$. Hence, $a \\mapsto {\\rm S}(a, P)$ is a lower\nsemicontinuous function for any $P \\in \\mathcal{P}$ and due to the assumed\ncompactness of $\\mathcal{A}$, the result now follows from Theorem~2.43\nin~\\citet{AlipBord2006}.\n\n\\subsection*{Proof of Theorem~\\ref{th:existence2}}\n\\addcontentsline{toc}{subsection}{Proof of Theorem~\\ref{th:existence2}}\n\nThe same arguments as in the proof of Theorem~\\ref{th:existence1}\nshow that $a \\mapsto {\\rm S}(a, P)$ is a weakly lower semicontinuous\nfunction for any $P \\in \\mathcal{P}$. If $P \\in \\mathcal{P}$ is such that this function\nis also coercive, then proceeding as in the proof of Satz~III.5.8\nin~\\citet{Werner2018} gives a weakly convergent sequence\n$(a_n)_{n \\in \\mathbb{N}} \\subset \\mathcal{A}$ with $\\lim_{n \\rightarrow\n\\infty} {\\rm S}( a_n, P) = \\inf_{a \\in \\mathcal{A}} {\\rm S}(a, P)$. Since $\\mathcal{A}$ is\nweakly closed by assumption, it contains the weak limit $a^*$ of the\nsequence $(a_n)_{n \\in \\mathbb{N}}$ and hence weak lower semicontinuity\nimplies that $a \\mapsto {\\rm S}(a, P)$ attains its minimum at $a^* \\in\n\\mathcal{A}$.\n\n\\section*{Acknowledgments}\n\\addcontentsline{toc}{section}{Acknowledgments}\n\nTilmann Gneiting is grateful for funding by the Klaus Tschira\nFoundation and by the European Union Seventh Framework Programme under\ngrant agreement 290976. Part of his research leading to these results\nhas been done within subproject C7 ``Statistical postprocessing and\nstochastic physics for ensemble predictions'' of the Transregional\nCollaborative Research Center SFB \/ TRR 165 ``Waves to Weather''\n(\\url{www.wavestoweather.de}) funded by the German Research Foundation\n(DFG). Jonas Brehmer gratefully acknowledges support by DFG through\nResearch Training Group RTG 1953. We thank Tobias Fissler and Matthew\nParry for instructive discussions.\n\n\n\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} +{"text":"\\section{Supplementary Material for ``Phase-fluctuation Induced Time-Reversal Symmetry Breaking Normal State\"}\nThis supplementary material contains,\n\\begin{itemize}\n\t\\item[I.] A review of the 2D classical $XY$-model\n\t\\item[II.] Monte-Carlo simulations for coupled $XY$-model\n\t\\item[III.] Spontaneous time-reversal symmetry breaking states in FeSe$_{1-x}$Te$_x$\n\\end{itemize}\n\n\\section{I. A review of the 2D classical $XY$-model}\nIn this section, we review the duality transformation from the $XY$-model to the sine-Gordon model, the operator product expansions, scaling dimensions, \nand the one-loop calculation in the renormalization group (RG) analysis.\n\n\n\\subsection{A. Map the $XY$-model to the sine-Gordon model}\nWe follow Ref. [\\onlinecite{herbut2007}] to review the duality between the \n$XY$-model and the sine-Gordon model. \nThe Hamiltonian of a single-component $XY$-model with the coupling \nconstant $J$ is given by,\n\\begin{align}\\label{sm-eq-xy-ham}\nH_{XY} = -J\\sum_{\\langle i,j\\rangle}\\cos(\\theta_i-\\theta_j).\n\\end{align}\nTo map the $XY$-model to the sine-Gordon model, we \nstart with the Villain approximation,\n\\begin{equation}\\label{sm-eq-vallain}\ne^{-K(1-\\cos\\theta)}\\approx \\sum_{n=-\\infty}^{\\infty}e^{-\\frac{K}{2}(\\theta-2n\\pi)^2},\n\\end{equation}\nwhich is valid when $K$ is large. \nIn this case, the dominant contribution comes from the regime\nthat $\\cos\\theta\\approx 1$, i.e. $\\theta \\approx 2n\\pi$.\nPerforming Taylor expansion around each of these values, we have $ e^{-K(1-\\cos\\theta)}\\approx \\sum_n e^{-\\frac{K}{2}(\\theta-2n\\pi)^2}$.\n\nUsing the Villain approximation, the Partition function of the $XY$-model in Eq.~\\eqref{sm-eq-xy-ham} is given by\n\\begin{align}\nZ_{XY} = \\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} e^{-\\beta H_{XY}}\n=\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} e^{\\beta J \\sum_{\\langle i,j\\rangle}\\cos(\\theta_i-\\theta_j)}\n=\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} \\prod_{\\langle i,j\\rangle}\\sum_{m_{ij}}e^{-K\/2(\\theta_i-\\theta_j-2m_{ij}\\pi)^2},\n\\end{align}\nwhere $K=\\beta J=J\/T$ and the Boltzmann constant is set to be 1 \nfor simplicity; $m_{ij}$ are integers defined on each link of the 2D lattice.\nNow we perform the Hubbard-Stratonovich transformation by introducing the continuous variables $x_{ij}$ defined on each link of the lattice.\nThe Partition function becomes,\n\\begin{align}\nZ_{XY}=\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} \\int_{-\\infty}^{\\infty}\\prod_{}\\sqrt{\\frac{2K}{\\pi}}dx_{ij}\\prod_{\\langle i,j\\rangle}\\sum_{m_{ij}}e^{-\\frac{1}{2K}x_{ij}^2-ix_{ij}(\\theta_i-\\theta_j-2m_{ij}\\pi)}.\n\\end{align}\nWith the help of the Poisson resummation formula,\n\\begin{align}\n\\sum_n\\delta(x-nT)=\\sum_m \\frac{1}{T}e^{i\\frac{2m\\pi}{T}x},\n\\end{align}\nwhere $n$ is an integer, the partition function $Z_{XY}$ becomes,\n\\begin{align}\nZ_{XY}&=\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} \\int_{-\\infty}^{\\infty}\\prod_{}\\sqrt{\\frac{2K}{\\pi}}dx_{ij}\\prod_{\\langle i,j\\rangle}e^{-\\frac{1}{2K}x_{ij}^2-ix_{ij}(\\theta_i-\\theta_j)}\\sum_n\\delta(x_{ij}-n), \\\\\n&\\sim\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} \\sum_{\\{m_{ij}\\}}\\prod_{\\langle i,j\\rangle}e^{-\\frac{1}{2K}m_{ij}^2-im_{ij}(\\theta_i-\\theta_j)}.\n\\end{align}\nTo perform the above integrals, each $\\theta_i$ is extracted from its neighbors,\n\\begin{align}\nZ_{XY}\\sim\\int_0^{2\\pi} \\prod_i\\frac{d\\theta_i}{2\\pi} \\sum_{\\{m_{ij}\\}}e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}m_{i,\\hat{\\mu}}^2-i\n\t\\sum_{i,\\hat{\\mu}}(m_{i,\\hat{\\mu}}-m_{i,-\\hat{\\mu}})\\theta_i},\n\\end{align}\nwhere $\\hat{\\mu}=\\hat x, \\hat y$ denotes the lattice unit vectors along\nthe bond directions. \nNow the angles $\\theta_i$ can be integrated out,\n\\begin{align}\nZ_{XY}\\sim \\sum_{\\{m_{ij}\\}}e^{-\\frac{1}{2K}\n\t\\sum_{i,\\hat{\\mu}}m_{i,\\hat{\\mu}}^2} \n\\prod_i\\delta \\left(\\sum_{\\hat{\\mu}} (m_{i,\\hat{\\mu}}-m_{i,-\\hat{\\mu}})\\right),\n\\end{align}\nwhere the $\\delta$-function here is the the Kronecker $\\delta$. \n\nEach integer $m_{ij}$ defined on the link can be treated as a current flown into and out of the connected lattice sites, and the $\\delta$-function here basically says the current through each site is conserved. This conservation constraint is naturally satisfied if we define another set of integers $\\{n_i\\}$ at the sites of the dual lattice, i.e. the centers of the plaquettes of the original lattice,\n\\begin{equation}\n\\begin{split}\n&m_{i,\\hat{x}}=n_{i+\\hat{x}+\\hat{y}}-n_{i+\\hat{x}},\\\\\n&m_{i,\\hat{y}}=n_{i+\\hat{y}}-n_{i+\\hat{x}+\\hat{y}},\\\\\n&m_{i-\\hat{x},\\hat{x}}=n_{i+\\hat{y}}-n_{i},\\\\\n&m_{i-\\hat{y},\\hat{y}}=n_{i}-n_{i+\\hat{x}}.\n\\end{split}\n\\end{equation}\nWith the new set of integers, the partition function now becomes,\n\\begin{align}\nZ_{XY}\\sim \\sum_{\\{n_i\\}}e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}(n_{i+\\hat{\\mu}}-n_i)^2}.\n\\end{align}\nComparing with the original partition function, we notice that the temperature has been inverted because $K\\to 1\/K$, and continuous variables has been replaced by integer variables. However, we can use Poisson summation to go back to continuous variables. Therefore,\n\\begin{align}\nZ_{XY}\\sim \\int \\prod_i d\\phi_i \\sum_{\\{n_i\\}}e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}(\\phi_{i,\\hat{\\mu}}-\\phi_i)^2}\\prod_i\\delta(\\phi_i-n_i)\n=\\int \\prod_i d\\phi_i \\sum_{\\{n_i\\}}e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}(\\phi_{i,\\hat{\\mu}}-\\phi_i)^2-i2\\pi\\sum_in_i\\phi_i},\n\\end{align}\nAfter adding the chemical potential term, the Partition function becomes,\n\\begin{align}\nZ_{XY}\\sim\\int \\prod_i d\\phi_i \\sum_{\\{n_i\\}}e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}(\\phi_{i,\\hat{\\mu}}-\\phi_i)^2-i2\\pi\\sum_in_i\\phi_i+\\mathrm{ln}y\\sum_in_i^2}.\n\\end{align}\nNext we perform the summation over $\\{n_i\\}$ by using the following identity,\n\\begin{eqnarray}\n\\sum_{\\{n_i\\}}e^{-i2\\pi\\sum_in_i\\phi_i+\\mathrm{ln}y\\sum_in_i^2}\n&=&\\prod_i\\sum_{n_i=0,\\pm 1,...}y^{n_i^2}e^{-i2\\pi n_i\\phi_i}\n=\\prod_i(1+2y\\cos2\\pi\\phi_i+O(y^2))\\nonumber \\\\\n=e^{2y\\sum_i\\cos2\\pi \\phi_i}.\n\\end{eqnarray}\nThe partition function eventually becomes the form of the sine-Gordon model,\n\\begin{align}\nZ_{XY}\\sim \\int \\prod_i d\\phi_i e^{-\\frac{1}{2K}\\sum_{i,\\hat{\\mu}}(\\phi_{i,\\hat{\\mu}}-\\phi_i)^2+2y\\sum_icos2\\pi \\phi_i}.\n\\end{align}\n\n\n\n\\subsection{B. Operator Product Expansion and Scaling Dimensions}\n\\label{append:scaling dimension}\nIn this part we use the operator product expansion (OPE) to calculate the scaling dimensions of the coupling terms consisting of vertex operators of the form $\\cos\\beta\\phi$ in the free bosonic field $\\phi$ and the vertex operators $\\cos\\beta\\theta$ in the dual field $\\theta$, based on the free Lagrangian $\\mathcal{L}_0=\\frac{1}{2K}(\\partial_{\\mu}\\phi)^2$. \n\n\nWe start with the correlation functions of the following vertex operators.\nFollowing the notation in Ref. [\\onlinecite{shankar2017}], the \ncorrelation function is given by,\n\\begin{align}\nG_{\\beta}(x-y)\\equiv\\langle \\mathrm{e}^{i\\beta \\phi(x)}\\mathrm{e}^{-i\\beta \\phi(y)} \\rangle.\n\\end{align}\nBy using the operator identity: $\\mathrm{e}^A\\mathrm{e}^B:=:\\mathrm{e}^{A+B}:\\mathrm{e}^{\\langle AB+\\frac{A^2+B^2}{2} \\rangle}$, where $:\\hat{O}:$ means normal ordering, we have\n\\begin{equation}\n\\begin{split}\nG_{\\beta}(x-y)&=\\langle :\\mathrm{e}^{i\\beta(\\phi(x)-\\phi(y))}: \\rangle \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle}\n=\\mathrm{e}^{\\beta\\langle \\phi(x)\\phi(y)-\\phi^2(x)\\rangle}\n=\\lim_{a \\to 0}\\left( \\frac{a^2}{a^2+(x-y)^2}\\right)^{\\frac{\\beta^2K}{4\\pi}},\n\\end{split}\n\\end{equation}\nwhere $a$ here is the short distance cutoff.\nThe following fact is used to derive the above equation,\n\\begin{align}\n\\langle \\phi(x)\\phi(y)-\\phi^2(x)\\rangle=-\\frac{K}{2\\pi}\\mathrm{ln}\\frac{a^2}{a^2+(x-y)^2}.\n\\end{align}\nSimilarly, we have for the dual field $\\theta$:\n\\begin{align}\n\\langle \\theta(x)\\theta(y)-\\theta^2(x)\\rangle=-\\frac{1}{2\\pi K}\\mathrm{ln}\\frac{a^2}{a^2+(x-y)^2}.\n\\end{align}\nTherefore, we are able to obtain the following correlation functions for \ntwo different types of vertex operators:\n\\begin{equation}\n\\begin{split}\n&\\langle \\mathrm{e}^{i\\beta \\phi(x)}\\mathrm{e}^{-i\\beta \\phi(y)} \\rangle\\sim |x-y|^{-\\frac{\\beta^2K}{2\\pi}},\\\\\n&\\langle \\mathrm{e}^{i\\beta \\theta(x)}\\mathrm{e}^{-i\\beta \\theta(y)} \\rangle\\sim |x-y|^{-\\frac{\\beta^2}{2\\pi K}},\n\\end{split}\n\\end{equation}\nbased on which the scaling dimensions of the vertex operators can \nbe calculated.\n\nBy taking\n$\\cos\\beta\\phi=\\frac{1}{2}(\\mathrm{e}^{i\\beta\\phi}+\\mathrm{e}^{-i\\beta\\phi})$, then\n\\begin{equation}\n\\begin{split}\n\\langle \\mathrm{cos}\\beta \\phi(x)\\mathrm{cos}\\beta\\phi(y)\\rangle\n&=\\frac{1}{4}\\left(\\langle \\mathrm{e}^{i\\beta\\phi(x)}\\mathrm{e}^{i\\beta\\phi(y)} \\rangle+\\langle \\mathrm{e}^{i\\beta\\phi(x)}\\mathrm{e}^{-i\\beta\\phi(y)} \\rangle+\\langle \\mathrm{e}^{-i\\beta\\phi(x)}\\mathrm{e}^{i\\beta\\phi(y)} \\rangle+\\langle \\mathrm{e}^{-i\\beta\\phi(x)}\\mathrm{e}^{-i\\beta\\phi(y)} \\rangle \\right)\n\\nonumber \\\\\n&\\sim |x-y|^{-\\frac{\\beta^2K}{2\\pi}}\n\\end{split}\n\\end{equation}\nwhere we have used the fact that $\\langle \\mathrm{e}^{i\\beta_1\\phi(x_1)}...\\mathrm{e}^{i\\beta_N\\phi(x_N)}\\rangle=0$ in the thermodynamic limit when $\\sum_{n=1}^N\\beta_n\\neq 0$ [\\onlinecite{tsvelik2007}]. From this we conclude that the scaling dimension of the $\\cos\\beta\\phi$ term is $\\frac{\\beta^2K}{4\\pi}$. Similarly the $\\cos\\beta\\theta$ term has scaling dimension $\\frac{\\beta^2}{4\\pi K}$. Using these results, the composite operators consisting of this two types of basic vertex operators, like the ones in the main text, can be readily calculated.\n\n\\subsection{C. The One-loop Correction\t}\nWe consider the Lagrangian in terms of $\\theta_{\\pm}$ and $\\phi_{\\pm}$\nwith $\\theta_{\\pm}\\equiv \\frac{1}{\\sqrt{2}}(\\theta_1\\pm\\theta_2)$\nand $\\phi_{\\pm} \\equiv \\frac{1}{\\sqrt{2}}(\\phi_1\\pm\\phi_2)$.\nA few cosine terms are also included as\n\\begin{equation}\\label{sm-eq-langrangian-two-LL}\n\\begin{split}\n\\mathcal{L}(x)&=\\frac{1}{2K}(\\partial_{\\mu}\\phi_+)^2+\\frac{1}{2K}\n(\\partial_{\\mu}\\phi_-)^2\n+\\frac{g_{\\theta}}{l^{D-\\Delta_{\\theta}}}\\cos(2\\sqrt{2}\\theta_-)\n- \\frac{2g_{\\phi}}{l^{D-\\Delta_{\\phi}}}\\mathrm{cos}\\sqrt{2}\\pi\\phi_\n+\\mathrm{cos}\\sqrt{2}\\pi\\phi_-\\\\\n& -\\frac{g_{\\phi_+}}{2l^{D-\\Delta_{\\phi_+}}} \\mathrm{cos}2\\sqrt{2}\\pi\\phi_+\n-\\frac{g_{\\phi_-}}{2l^{D-\\Delta_{\\phi_-}}} \\mathrm{cos}2\\sqrt{2}\\pi\\phi_-,\n\\end{split}\n\\end{equation}\nwhere the short-distance cutoff $l$ is restored to make the \ncouplings dimensionless [\\onlinecite{fradkin2013}].\n\nFor the one-loop corrections for the RG equations, we consider first the \nsimple case where the free bosonic Lagrangian $\\mathcal{L}_0=\\frac{1}{2K}(\\partial_{\\mu}\\phi)^2$ is perturbed \nby a generic vortex term $\\mathcal{L}'=\\frac{g_{\\phi}}{l^{D-\\Delta_{\\phi}}}\\mathrm{cos}\\beta \\phi+\\frac{g_{\\theta}}{l^{D-\\Delta_{\\theta}}}\\mathrm{cos}\\alpha\\theta$, \nthen the partition function can be expanded as the following:\n\\begin{equation}\\label{sm-eq-partition-phi-theta}\n\\begin{split}\nZ=\\int D[\\phi]e^{-S}\n&=Z^*\\Big(1+\\int dx\\frac{g_{\\phi}}{l^{D-\\Delta_{\\phi}}}\\langle\\mathrm{cos}\\beta\\phi\\rangle+\\int dx\\frac{g_{\\theta}}{l^{D-\\Delta_{\\theta}}}\\langle\\mathrm{cos}\\alpha\\theta\\rangle\n+\\frac{1}{2}\\int dxdy\\frac{g_{\\phi}g_{\\theta}}{l^{2D-\\Delta_{\\phi}-\\Delta_{\\theta}}}\\langle\\mathrm{cos}\\beta\\phi(x)\\mathrm{cos}\\alpha\\theta(y)\\rangle\\\\\n&+\\frac{1}{2}\\int dxdy\\frac{g_{\\phi}^2}{l^{2D-2\\Delta_{\\phi}}}\\langle\\mathrm{cos}\\beta\\phi(x)\\mathrm{cos}\\beta\\phi(y)\\rangle\n+\\frac{1}{2}\\int dxdy\\frac{g_{\\theta}^2}{l^{2D-2\\Delta_{\\theta}}}\\langle\\mathrm{cos}\\alpha\\theta(x)\\mathrm{cos}\\alpha\\theta(y)\\rangle+O(g^3)\\Big),\n\\end{split}\n\\end{equation}\nwhere $Z^*$ represents the free theory partition function. \nAs we know, the conformal invariance of the free theory requires that the cross term corresponding to $g_{\\phi}g_{\\theta}$ vanishes at the one-loop level because the $g_{\\phi}$ and the $g_{\\theta}$ terms in general have different scaling dimensions.\nSo we only need to consider the $g_\\phi^2$ and $g_\\theta^2$ terms.\n\n\nFirstly, consider the $g_\\phi^2$ term.\nThe OPE in terms of $e^{i\\beta\\phi}$ is given by,\n\\begin{equation}\n\\begin{split}\n:\\mathrm{e}^{i\\beta \\phi(x)}::\\mathrm{e}^{-i\\beta \\phi(y)}:&=:\\mathrm{e}^{i\\beta(\\phi(x)-\\phi(y))}: \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle}\\\\\n&=:\\mathrm{e}^{i\\beta(-\\phi'(x)(y-x)-1\/2\\phi''(y-x)^2)+O((y-x)^3)}: \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle}\\\\\n&=:1-i\\beta \\phi'(x)(y-x)-i\/2\\beta\\phi''(x)(y-x)^2-\\beta^2\/2\\left(\\phi'(x)(y-x)\\right)^2+O((y-x)^3: \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle},\n\\end{split}\n\\end{equation}\nwhere the Taylor expansion is done based on the fact that $|y-x|\\to 0$. \nTherefore,\n\\begin{equation}\n\\begin{split}\n:\\mathrm{cos}\\beta\\phi(x)::\\mathrm{cos}\\beta\\phi(y):&=\\frac{1}{2}\\mathrm{Re}\\left(:\\mathrm{e}^{i\\beta \\phi(x)}::\\mathrm{e}^{-i\\beta \\phi(y)}:+:\\mathrm{e}^{-i\\beta \\phi(x)}::\\mathrm{e}^{i\\beta \\phi(y)}:\\right),\\\\\n&=:1-\\frac{\\beta^2}{2}\\left(\\phi'(x)(y-x)\\right)^2+O(y-x)^3: \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle},\\\\\n&\\approx :1-\\beta^2\/2(\\partial_{\\mu}\\phi)^2(y-x)^2: \\mathrm{e}^{-\\frac{\\beta^2}{2}\\langle (\\phi(x)-\\phi(y))^2\\rangle},\\\\\n&\\approx |x-y|^{-\\frac{\\beta^2K}{2\\pi}}-\\beta^2\/2:(\\partial_{\\mu}\\phi)^2:|x-y|^{-\\frac{\\beta^2K}{2\\pi}+2}.\n\\end{split}\n\\end{equation}\nSimilarly, the correlation function for $\\cos \\theta$ operator is given by,\n\\begin{align}\n:\\mathrm{cos}\\alpha\\theta(x)::\\mathrm{cos}\\alpha\\theta(y):\\approx |x-y|^{-\\frac{\\alpha^2}{2\\pi K}}-\\frac{\\alpha^2}{2}:(\\partial_{\\mu}\\theta)^2:|x-y|^{-\\frac{\\alpha^2}{2\\pi K}+2}.\n\\end{align}\nFor the $g_{\\phi}^2$ term in Eq.~\\eqref{sm-eq-partition-phi-theta},\n$\\frac{1}{2}\\int dxdy\\frac{g_{\\phi}^2}{l^{2D-2\\Delta_{\\phi}}}\\langle\\mathrm{cos}\\beta\\phi(x)\\mathrm{cos}\\beta\\phi(y)\\rangle$, which gives rise to the one-loop correction to the $:(\\partial_{\\mu}\\phi)^2:$ term, becomes\n\\begin{align}\n-\\beta^2\/2\\int dxdy\\frac{g_{\\phi}^2}{l^{2D-2\\Delta_{\\phi}}}|x-y|^{-\\frac{\\beta^2K}{2\\pi}+2} \\langle :(\\partial_{\\mu}\\phi)^2:\\rangle\n=-\\beta^2\/2\\int dx\\frac{g_{\\phi}^2}{l^{2D-2\\Delta_{\\phi}}}\\langle :(\\partial_{\\mu}\\phi)^2:\\rangle\\int dy|x-y|^{-\\frac{\\beta^2K}{2\\pi}+2}.\n\\end{align}\nNow we do a change of scale by changing the cutoff $l\\to l+\\delta l=(1+\\delta \\ln l)l$. This means the domain of the above integration is changed from $|x-y|>l$ to $|x-y|>(1+\\delta \\ln l)l$. Therefore, the corresponding change in the above integration becomes,\n\\begin{align}\n\\beta^2\/2\\int dx\\frac{g_{\\phi}^2}{l^{2D-2\\Delta_{\\phi}}}\\langle :(\\partial_{\\mu}\\phi)^2:\\rangle\\int_{l<|x-y|<(1+\\delta \\ln l)l} dy|x-y|^{-\\frac{\\beta^2K}{2\\pi}+2},\n\\end{align}\nwhich in the case of $D=2$ is,\n\\begin{align}\n\\frac{1}{2}2\\pi \\beta^2g_{\\phi}^2\\delta \\ln l \\int dx\\langle :(\\partial_{\\mu}\\phi)^2:\\rangle.\n\\end{align}\nComparing with the kinetic term $\\frac{1}{2K}\\int dx (\\partial_{\\mu}\\phi)^2$, we obtain the correction of $K$ due to the $g_{\\phi}$ term,\n\\begin{align}\n\\frac{d(1\/K)}{d\\ln l}=2\\pi \\beta^2g_{\\phi}^2.\n\\end{align}\nSimilarly, the contribution from the $g_{\\theta}$ term is given by,\n\\begin{align}\n\\frac{dK}{d \\ln l}=2\\pi \\alpha^2g_{\\theta}^2,\n\\end{align}\nbecause the corresponding kinetic term for $\\theta$ is $\\frac{K}{2}\\int dx (\\partial_{\\mu}\\theta)^2$. In total we have the following one-loop flow equation for Luttinger parameter $K$,\n\\begin{equation}\n\\frac{dK}{d\\ln l}=2\\pi\\left(-\\beta^2g_{\\phi}^2K^2+\\alpha^2g_{\\theta}^2\\right).\n\\label{eq:one-loop}\n\\end{equation}\nWith this result, the RG equations can be readily obtained. We summarize here the loop-level flow equations for the coupled Luttinger theory defined in Eq.~\\eqref{sm-eq-langrangian-two-LL}\n\\begin{align}\n\\begin{split}\n\\frac{dK_+}{d\\ln l} &=-16\\pi^3\\left(g_{\\phi}^2+g_{\\phi_+}^2\\right)K_+^2 ,\\\\\n\\frac{dK_-}{d\\ln l} &= -16\\pi\\left(\\pi^2(g_{\\phi}^2+g_{\\phi_-}^2)K_-^2-g_{\\theta}^2\\right),\n\\end{split}\n\\end{align}\nwhich have been presented in the main text.\n\n\\section{II. Monte-Carlo simulations for coupled $XY$-model}\nIn this section, we perform the classical Monte-Caro simulation and discuss the derivation of the spin stiffness $\\gamma$ and the scaling of KT transition temperature.\n\n\\subsection{A. Derivation of the spin stiffness $\\gamma$}\n\\label{append:helicity modulus}\nThe Hamiltonian of the coupled $XY$-model is given by\n\\begin{equation}\nH = -J\\sum_{}\\cos(\\theta_{1i}-\\theta_{1j})-J\\sum_{}\\cos(\\theta_{2i}-\\theta_{2j})+g\\sum_{i}\\cos2(\\theta_{1i}-\\theta_{2i}).\n\\end{equation}\nTo calculate the stiffness $\\gamma$ associated with the $U(1)$ symmetry of $\\theta_{c}=\\theta_{1}+\\theta_{2}$, we insert $U(1)$ flux to cause the twisted boundary condition. To simplify the derivation, we only consider twisted boundary condition in $x$-direction, and it is the same to twist $y$-direction boundary condition. After inserting the $U(1)$ flux $\\Phi$, the new Hamiltonian is,\n\\begin{equation}\n\\begin{split}\nH(\\Phi) &= -J\\sum_{_{x},\\alpha}\\cos(\\theta_{\\alpha,i}-\\theta_{\\alpha,j}+\\Phi)-J\\sum_{_{y},\\alpha}\\cos(\\theta_{\\alpha,i}-\\theta_{\\alpha,j})+g\\sum_{i}\\cos(2\\theta_{1i}-2\\theta_{2i})\\\\\n&=H(0)+\\dfrac{1}{2}J\\Phi^{2}\\sum_{_{x},\\alpha}\\cos(\\theta_{\\alpha,i}-\\theta_{\\alpha,j})+J\\Phi\\sum_{_{x},\\alpha}\\sin(\\theta_{\\alpha,i}-\\theta_{\\alpha,j})\\\\\n&=H(0)+\\dfrac{1}{2}\\Phi^{2}\\sum_{\\alpha}H_{\\alpha,x}+\\sum_{\\alpha}\\Phi I_{\\alpha,x},\n\\end{split}\n\\end{equation}\nwith\n\\begin{equation}\n\\begin{split}\n&H_{\\alpha,\\mu}=J\\sum_{}\\cos(\\theta_{\\alpha,j}-\\theta_{\\alpha,i})\\hat{e}_{ij}\\cdot \\hat{\\mu},\\\\\n&I_{\\alpha,\\mu}=J\\sum_{}\\sin(\\theta_{\\alpha,j}-\\theta_{\\alpha,i})\\hat{e}_{ij}\\cdot \\hat{\\mu}.\\\\\n\\end{split}\n\\label{Eq:helicity}\n\\end{equation}\nwhere $\\hat{\\mu}$ is either $\\hat{x}$ or $\\hat{y}$ corresponding twisted x or y boundary condition, $\\alpha$ is the layer index, and $N=2\\times L_{x}\\times L_{y}$ is the total number of sites in the system. Because of the symmetry of the system, we have $\\gamma_{x}=\\gamma_{y}=\\gamma$.\n\\begin{equation}\n\\begin{split}\n&Z(\\Phi)=\\int D[\\theta] e^{-\\beta H[\\Phi]}=\\int D[\\theta]e^{-\\beta H(0)-\\dfrac{1}{2}\\beta\\Phi^{2}(H_{1,x}+H_{2,x})-\\beta \\Phi (I_{1,x}+I_{2,x})}\\\\\n&\\approx Z(0)\\left(1-\\dfrac{1}{2}\\beta \\Phi^{2}\\langle H_{1,x}\\rangle -\\dfrac{1}{2}\\beta \\Phi^{2}\\langle H_{2,x}\\rangle-\\beta \\Phi\\langle I_{1,x}\\rangle +\\dfrac{1}{2}\\beta^{2}\\Phi^{2}\\langle I_{1,x}^{2}\\rangle-\\beta\\Phi \\langle I_{2,x}\\rangle+\\dfrac{1}{2}\\beta^{2}\\Phi^{2}\\langle I_{2,x}^{2}\\rangle \\right).\n\\end{split}\n\\end{equation}Then the spin stiffness is given by\n\\begin{equation}\n\\begin{split}\n\\gamma=\\gamma_{x}=\\dfrac{1}{N}\\dfrac{\\partial^{2}F(\\Phi)}{\\partial \\Phi^{2}}=-\\dfrac{1}{N \\beta}\\dfrac{\\partial^{2}\\ln Z(\\Phi)}{\\partial \\Phi^{2}}=\n\\dfrac{1}{N}\\left(\\langle H_{1,x}\\rangle+\\langle H_{2,x}\\rangle-\\beta\\langle I_{1,x}^{2}\\rangle -\\beta\\langle I_{2,x}^{2}\\rangle \\right).\n\\end{split}\n\\end{equation}\n\n\n\n\\subsection{B. Scaling of the KT transition temperature}\nFig.\\ref{fig:spin_stiffness} shows one typical behavior (at $g=1$) of the spin stiffness $\\gamma$ as a function of temperature $T$. The KT transition temperature for each system size is determined by intersecting the $2T\/\\pi$ line with the stiffness curves. We can clearly see that as system size goes large, the stiffness jump shows up. The temperatures at the crossings for different system sizes can then be used to extrapolate the critical temperature at $L\\rightarrow \\infty$.\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{sm-fig1.pdf}\n\t\\caption{Spin stiffness $\\gamma$ as a function of temperature $T$ for different system sizes at $g=1$. The purple line is $2T$\/$\\pi$. The intersection point between $\\gamma(T)$ and $2T$\/$\\pi$ indicates the KT transition temperature $T_{c}$.}\n\t\\label{fig:spin_stiffness}\n\\end{figure}\n\nFig.\\ref{fig:extrapolation_U1} shows the extrapolation of the KT transition temperature in the thermodynamic limit at different coupling strengths $g$ between the two $XY$-models. The extrapolated critical temperatures determine the phase boundary between the $Z_2$-breaking normal state and the $Z_2$-breaking SC phase in the main text.\n\\begin{figure}[htbp]\n\t\\centering\n\t\\includegraphics[width=0.5\\linewidth]{sm-fig2.pdf}\n\t\\caption{Extrapolation of the KT transition temperatures in the thermodynamic limit for different coupling strengths between the two $XY$-models.}\n\t\\label{fig:extrapolation_U1}\n\\end{figure}\n\n\n\n\\section{III. Spontaneous time-reversal symmetry breaking normal states \n\tin the FeSe$_{1-x}$Te$_x$ superconductor}\nIn this section, we briefly discuss the application of our theory to the FeSe$_{1-x}$Te$_x$ superconductor, in which strong evidence to spontaneously time-reversal-symmetry breaking states has been observed by \nusing the high-resolution laser-based photoemission method \nboth in the superconducting and the normal states [\\onlinecite{zaki2019}].\n\nFollowing Ref. [\\onlinecite{hu2019b}], we consider two superconducting gap \nfunctions $\\Delta_1$ and $\\Delta_2$, which possess different pairing \nsymmetries and each of them maintains time-reversal symmetry.\nThe Ginzburg-Landau free energy is given by,\n\\begin{align}\n\\mathcal{F} = \\alpha_1 \\vert \\Delta_1\\vert^2 + \\beta_1\\vert \\Delta_1\\vert^4 + \\alpha_2\\vert\\Delta_2\\vert^2 + \\beta_2\\vert \\Delta_2\\vert^4 + \\kappa\\vert \\Delta_1\\vert^2\\vert\\Delta_2\\vert^2 + \n\\lambda \\left( (\\Delta_1^\\ast\\Delta_2)^2 + c.c. \\right),\n\\end{align}\nwhere we assume $\\alpha_1\\approx\\alpha_2$ so that the two pairing \nchannels are nearly degenerate, discussed in the main text.\nAnd we focus on $\\lambda>0$ case, where the relative phase between $\\Delta_1$ and $\\Delta_2$ as $\\Delta\\theta_{12}=\\pm \\frac{\\pi}{2}$.\nHence, the complex gap function $\\Delta_1\\pm i\\Delta_2$ spontaneously breaks \ntime-reversal symmetry.\n\nSince the FeSe$_{1-x}$Te$_x$ superconductor has strong atomic spin-orbital \ncoupling, as allowed by symmetry, the complex gap function can directly couple to \nthe spin magnetization $m_z$ via a cubic coupling term as,\n\\begin{align}\n\\mathcal{F}_M = \\alpha_m \\vert m_z\\vert^2 + i\\gamma m_z (\\Delta_1\\Delta_2^\\ast - \\Delta_1^\\ast\\Delta_2),\n\\end{align}\nwhere $\\alpha_m>0$ and $\\gamma$ is proportional to the spin-orbit coupling strength [\\onlinecite{hu2019b}].\nThis term satisfies both the $U(1)$ symmetry and time-reversal symmetry.\nBecause of $\\alpha_m>0$, the spin magnetization can only be induced by \nthe complex gap function via $m_z=\\frac{\\gamma}{\\alpha_m}\\vert \\Delta_1^\\ast\\Delta_2\\vert\\sin(\\Delta\\phi)\\neq0$ when $\\Delta\\theta_{12}=\\pm \\frac{\\pi}{2}$.\nThe development of $m_z$ can gap out the surface Dirac cone as observed in \nthe experiment [\\onlinecite{zaki2019}].\nAs detailed in Ref. [\\onlinecite{hu2019b}], this spontaneous breaking\nof TR symmetry can impose a strong constraint on the gap function\nsymmetry in FeSe$_{1-x}$Te$_x$ system. \n\nOn the other hand, the experiment [\\onlinecite{zaki2019}] also shows that the spin-magnetization develops nonzero values even at $T>T_c$,\nindicating that TRS breaking already occurs above $T_c$.\nIt can be understood from the analysis in the main text, where we propose the $Z_2$-breaking normal state.\nThere are no long-range superconducting orderings, i.e., the $\\langle \\Delta_1\\rangle =\\langle \\Delta_2\\rangle=0 $.\nHowever, the expectation value of the 4-fermion order parameter is nonzero $\\langle \\Delta_1^\\ast\\Delta_2\\rangle\\neq0$ due to the pinning of $\\Delta\\theta_{12}\n=\\pm\\frac{\\pi}{2}$.\nOur theory is consistent with the experimental observations.\n\n\n\\end{widetext}\n\n\\end{appendix}\n\n\n\\bibliographystyle{apsrev4-1}\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} +{"text":"\\section{Introduction} \n\nEarly searches for molecular\nhydrogen in DLAs, though not systematic, have lead to either small values of or\nupper limits on the molecular fraction of the gas.\nFor a long time, only the DLA at $z_{\\rm abs}=2.811$ toward Q\\,0528$-$250 was\nknown to contain H$_2$ molecules (Levshakov \\& Varshalovich 1985, \nFoltz et al. 1988). Ge \\& Bechtold (1999)\nsearched for H$_2$ in a sample of eight DLAs using the\nMMT moderate-resolution spectrograph (${\\rm FWHM}=1$ \\AA ). Apart from the\ndetection of molecular hydrogen at $z_{\\rm abs}=1.973$ and 2.338\ntoward, respectively, Q\\,0013$-$004 and Q\\,1232$+$082, they measured in\nthe other systems upper limits on $f$ in the range $10^{-6}-10^{-4}$.\n\nA major step forward in understanding the nature of DLAs through their\nmolecular hydrogen content has recently been made possible by the\nunique high-resolution and blue-sensitivity capabilities of UVES at the VLT. \nIn the course of the\nfirst large and systematic survey for H$_2$ at high redshift, we have searched\nfor H$_2$ in DLAs down to a detection limit of typically\n$N($H$_2)=2\\times 10^{14}$ cm$^{-2}$ (Petitjean et al. 2000,\nLedoux et al. 2003). Out of the 33 surveyed systems, eight had firm detections of \nassociated H$_2$ absorption lines. Considering that three detections were already known from\npast searches, H$_2$ was detected in $\\sim 15$\\% of\nthe surveyed systems. The existence of a correlation between metallicity\nand depletion factor, measured as [X\/Fe] (with X~=~Zn, S or Si) was demonstrated \n(see also Ledoux et al. 2002a) and \nthe DLA and sub-DLA systems where H$_2$ was detected were usually among \nthose having the highest metallicities.\n\nHowever, the high metallicity end of the Ledoux's sample was biased\nby the presence of already known detections.\nTherefore, to investigate further this possible dependence with metallicity,\nand derive what is the actual molecular content of the high-redshift\ngas with highest metallicity, we have searched a representative \nsample of high metallicity DLAs for H$_2$. \nThe number of H$_2$ measurements in systems with [X\/H]~$>$~$-$1.3 is\ntwice larger in our sample compared to previous surveys.\nWe describe the sample and the observations in Section~2,\npresent two new detections of H$_2$ in Section~3 and the results of the survey\nand our conclusions in Section~4. \n\n\\section{Sample and Observations}\n\nWe have selected from the literature all $z>1.8$ DLAs and sub-DLAs systems ($\\log N($H\\,{\\sc i}$)\\ge 19.5$) with \npreviously measured elemental abundances (e.g. Prochaska \\& Wolfe 2001, Kulkarni \\& Fall 2002) \nlarger than [X\/H]~$>$~$-$1.3 and accessible to UVES. The inclusion of sub-DLAs is \njustified by the fact that for $\\log N($H\\,{\\sc i}$) > 19.5$ most of the hydrogen\nis neutral (Viegas 1995). In addition, Ledoux et al. (2003) \nhave shown that for log~$N$(H~{\\sc i})~$>$~19.5, there is no correlation between the \npresence of H$_2$ and the H~{\\sc i} column density. \nThe fact that we include ALL known systems with these criteria\nguarantees that the sample is representative of the population of DLA-subDLA.\n\nWe ended up with a sample of 15 DLAs and 3 sub-DLAs (with log~$N$(H~{\\sc i})~=~19.7,\n20.10 and 20.25) presented in Table~1. The H$_2$\ncontent of ten of these systems had already been published (Srianand \\& Petitjean 2001, \nPetitjean et al. 2002, Ledoux et al. 2002b, 2003, 2006b, Srianand et al. 2005 \nand Heinm\\\"uller et al. 2006). Five of the eight remaining systems had \ndata in the UVES archive (Q\\,1209$+$093: Prog. 67.A-0146 P.I. Vladilo; Q\\,2116$-$358: \nProg. 65.O-0158 P.I. Pettini; Q\\,2230$+$025: Prog. 70.B-0258, P.I. Dessauges-Zavadsky;\nQ\\,2243$-$605: Prog. 65.O-0411 P.I. Lopez; Q\\,2343$+$125: Prog. 69.A-0204 and 67.A-0022,\nP.I. D'Odorico). \nNew observations of Q\\,0216$+$080, Q\\,2206$-$199, Q\\,2343$+$125 and Q\\,2348$-$011\nhave been performed with the Ultraviolet and Visible Echelle Spectrograph \n(UVES, Dekker et al. 2000) \nmounted on the ESO Kueyen VLT-UT2 8.2 m telescope on Cerro Paranal in Chile.\nThese new observations resulted in two new detections described in the next Section.\n\\\\\nThe data for each of the eight QSOs \nwere reduced using the UVES\npipeline \nwhich is available as a context of the ESO\nMIDAS data reduction system (see e.g. Ledoux et al. 2003 for details). \nStandard Voigt-profile fitting methods were used for the analysis of metal lines\nand molecular lines, when detected,\nto determine column densities using the oscillator strengths compiled in \nLedoux et al. (2003) for metal species and the oscillator strengths given \nby Morton \\& Dinerstein (1976) for H$_2$. We adopted the Solar abundances \nfrom Morton (2003) based on meteoritic data from Grevesse \\& Sauval (2002).\n\nThe characteristics of the sample are summarized in Table~\\ref{summarytab}. The \nH~{\\sc i} column densities and most of metallicities are from the compilation \nby Ledoux et al. (2006a). Slight differences with previously published\nvalues, e.g. Ledoux et al. (2003), are due to the use of different damping\ncoefficients for H~{\\sc i}. The only known $z>1.8$ H$_2$ bearing DLA system \nout of this sample is the system at $z_{\\rm abs}$~=~2.337 toward Q~1232+082\n(Srianand et al. 2000).\n\n\n\\input summarytab.tex\n\n\\begin{figure}[!ht]\n \\begin{center}\n\\includegraphics[width=10.0cm,bb=68 710 399 766,clip=]{q2343_vel_metals.eps}\\\\\n\\includegraphics[width=10.0cm,bb=68 483 399 766,clip=]{q2343_vel_H2.eps}\\\\\n \\caption{Velocity plots of observed H$_2$ absorption lines from\nthe J~=~0 and J~=~1 rotational levels \nat $z_{\\rm abs}$~=~2.43127 toward Q\\,2343$+$125. Profiles of associated Si~{\\sc ii} and\nFe~{\\sc ii} absorptions are shown in the upper panels. The best-fitting model\nto the system is overplotted; the location of Voigt-profile sub-components are \nshown as vertical dashed lines. }\n\\label{q2343h2}\n \\end{center}\n\\end{figure}\n\n\\section{Two new detections}\n\nWe report two new detections of H$_2$ in DLAs from our new observations.\nDetail analysis and interpretation of the physical conditions in these two\nDLAs are out of the scope of the present work and will be described in a subsequent \npaper.\n\n\\subsection{Q\\,2343$+$125, $z_{\\rm abs} = 2.431$}\n\n\n\n\n\nThis DLA system has first been studied by Sargent et al. (1988). High resolution data\nhave been described by Lu et al. (1996), D'Odorico et al. (2002) and Dessauges-Zavadsky\net al. (2004). The profile of the metal lines is spread over more than 250~km~s$^{-1}$\nfrom $z_{\\rm abs}$~=~2.4283 to 2.4313 but the strongest component is centered \nat $z_{\\rm abs} = 2.43127$ corresponding to the red edge of the above redshift range.\nFrom Voigt--profile fitting to the H~{\\sc i} Lyman--$\\alpha$, $\\beta$ and $\\gamma$ lines, \nwe find that the damped Lyman-$\\alpha$ line is centered at $z_{\\rm abs} = 2.431$ and the\ncolumn density is log $N$(H~{\\sc i}) = $20.40 \\pm 0.07$, consistent with previous measurement by \nD'Odorico et al. (2002; log $N$(H~{\\sc i}) = $20.35 \\pm 0.05$). \nWe use Zn as the reference species for metallicity measurement and find\n[Zn\/H]~=~$-$0.89$\\pm$0.08. This is consistent with previous findings.\nAbsorption from the J~=~1 and probably from the J~=~0 rotational levels \nof H$_2$ is detected in this system at $z_{\\rm abs} = 2.43127$ (see Fig.~\\ref{q2343h2}).\nThe optically thin H$_2$ absorption lines are very weak, i.e. close to but above the \n3$\\sigma$ detection limit.\nA very careful normalization of the spectrum has been performed, \nadjusting the continuum while fitting the lines.\nThe best-fitting consistent model for H$_2$ is shown in Fig.~\\ref{q2343h2}.\nThe total H$_2$ column density, integrated over the J~=~0 and 1 levels, is \nestimated to be log $N$(H$_2$) = $13.69 \\pm 0.09$ (12.97$\\pm$0.04 and 13.60$\\pm$0.10\nfor J~=~0 and 1 respectively). This leads to the smallest molecular fraction observed\nup to now, \nlog~$f$~=~$-6.41_{-0.16}^{+0.16}$.\nWe also derive an upper limit on the detection of absorption from the J~=~2 level,\nlog $N$(H$_2$-J=2) $<$ $13.1$ at the 3$\\sigma$ level.\n\n\n\\subsection{Q\\,2348$-$011, $z_{\\rm abs} = 2.426$}\n\n\\begin{figure}[!ht]\n \\begin{center}\n\\includegraphics[width=10.0cm,bb=68 659 392 766,clip=]{q2348_vel_metals.eps}\\\\\n\\includegraphics[width=10.0cm,bb=68 688 392 767,clip=]{q2348_vel_H2.eps}\\\\\n\\caption{Absorption profiles at $z_{\\rm abs}$~=~2.4263 (taken as\nzero of the velocity scale) toward Q\\,2348$-$011. The positions of the seven\n(respectively 13) components needed to fit the H$_2$ (respectively metal line)\nprofiles are indicated by vertical dashed lines. The resulting best-fitting model\nto the system is overplotted. }\n \\label{q2348}\n \\end{center}\n\\end{figure}\n\nThere are two DLA systems at $z_{\\rm abs}=2.426$ and $z_{\\rm abs} = 2.615$ toward \nQ\\,2348$-$011, with total neutral hydrogen column densities of respectively \nlog $N$(H~{\\sc i}) = $20.50 \\pm 0.10$ and log $N$(H~{\\sc i}) = $21.30 \\pm 0.08$. Conspicuous \nH$_2$ absorptions are detected in the $z_{\\rm abs}\\simeq 2.426$ DLA system, the only system \nto be considered here as displaying a high metallicity (see Fig.~\\ref{q2348}).\nThe molecular lines are very numerous and strong but the spectral resolution of our data is \nhigh enough to allow unambiguous detection and accurate determination of the line parameters.\nSeven H$_2$ components spread over about 300~km~s$^{-1}$ were used for the H$_2$ fit. \nIt is interesting to note that the strongest metal component (at $V$~=~0~km~s$^{-1}$\nin Fig.~\\ref{q2348}) has no \nassociated H$_2$ absorption. Strong H$_2$ absorption is seen at $V$~$\\sim$~$-$150~ and +50~km~s$^{-1}$.\nAll seven molecular components have associated C~{\\sc i} absorption. However, additional components\nare needed to fit the metal absorption lines: 9 components for C~{\\sc i} and 13 components\nfor the singly ionized species.\nH$_2$ absorption from the rotational levels J~=~0 to 5 are unambiguously detected. \nThe total H$_2$ column density integrated \nover all rotational levels is log~$N$(H$_2$)~=~18.45$^{+0.27}_{-0.26}$, \ncorresponding to a molecular fraction log~$f$~=~$-1.76_{-0.36}^{+0.37}$. We also derive an upper limit \non the column density of HD molecules, leading to log~$N$(HD)\/$N$(H$_2$) $<$ -3.3. \n\n\n\\section{Metallicity as a criterion for the presence of molecular hydrogen}\n\n\\begin{figure}[!ht]\n \\includegraphics[width=8.2cm,height=9.5cm,bb=0 0 574 726, clip,angle=90]{f_x_h2.eps}\n \\caption{Logarithm of the molecular fraction, $f$~=~2$N$(H$_2$)\/(2$N$(H$_2$)~+~$N$(H~{\\sc i})),\nversus metallicities, [X\/H] = log~$N$(X)\/$N$(H)$-$log(X\/H)$_{\\odot}$ and X either Zn, S or Si, \nin DLAs from the sample described in this paper ([X\/H]~$>$~$-1.3$, see Table~1) and\nthe sample of Ledoux et al. (2003, [X\/H]~$<$~$-1.3$). Filled squares indicate\nsystems in which H$_2$ is detected. Dashed lines indicate the limits used in the text\n(log~$f$~=~$-$4; [X\/H]~=~$-$1.3). The dotted line indicate the median of the\nhigh-metallicity sample ([X\/H]~=~$-$0.7).}\n\\label{sample}\n\\end{figure}\n\nFrom Table 1, it can be seen that H$_2$ is detected in nine high-metallicity \nsystems out of 18. However, for two of the detections, the corresponding \nvalue of log~$f$ is smaller than most of the upper limits derived for\nother systems. All upper limits are smaller than $-$4.5 and all detections\nlarger than these upper limits are larger than $-$3. We therefore define a system\nwith large (respectively small) H$_2$ content if log~$f$ is larger (respectively smaller) than \n$-$4.\n\nIn Fig.~\\ref{sample} we plot the molecular fraction, log~$f$, versus metallicity, [X\/H],\nfor our representative sample of DLAs with [X\/H]~$>$~$-1.3$ (18 measurements summarized \nin Table~1) and measurements by Ledoux et al. (2003) for [X\/H]~$<$~$-1.3$ (23 measurements).\nThe log~$f$ distribution is bimodal with an apparent gap\nin the range $-5$~$<$~log~$f$~$<$~$-3.5$ justifying the above classification\nof systems.\nNote that this jump in log~$f$ has already been noticed before by Ledoux et al. (2003) and \nis similar to what is seen in our Galaxy (Savage et al. 1977; see also Srianand et al. 2005).\nIt is apparent that the fraction of systems with \nmolecular fraction log~$f$~$>$~$-4$ increases with increasing metallicity. It \nis only $\\sim$5\\% for [X\/H]~$<$~$-1.3$\nwhen it is $\\sim$39\\% for [X\/H]~$>$~$-1.3$. This fraction is even larger, \n50\\%, for [X\/H]~$>$~$-0.7$ which is the median metallicity for systems\nwith [X\/H]~$>$~$-1.3$. In addition, all systems with [X\/H]~$<$~$-1.5$\nhave log~$f$~$<$~$-4.5$.\n\nWe conclude that metallicity is an important criterion for the presence of molecular \nhydrogen in DLAs. This may not be surprizing as the correlation \nbetween metallicity and depletion of metals onto dust grains (Ledoux et al. 2003)\nimplies that larger metallicity means larger dust content and therefore\nlarger H$_2$ formation rate. In addition, the presence of dust implies a\nlarger \nabsorption of UV photons that usually dissociate the molecule. More generally, \nLedoux et al. (2006a) have\nshown that a correlation exists between metallicity and velocity width in DLAs.\nIf the latter kinematic parameter is interpreted as reflecting the mass\nof the DM halo associated with the absorbing object, then DLAs with higher\nmetallicity are associated with objects of larger mass in which star formation\ncould be enhanced.\nAll this makes it arguable that, in DLAs, star-formation activity is probably correlated with \nthe molecular fraction (Hirashita \\& Ferrara 2005). \nIt is therefore of first importance to survey a large number of DLA systems \nto define better their molecular content and use this information \nto derive the physical properties of the gas and the amount of star-formation\noccuring in the associated objects.\n\n\n\n\n\\begin{acknowledgements}\nPPJ thanks ESO for an invitation to stay at the ESO headquarters in Chile where part of\nthis work was completed. RS\nand PPJ gratefully acknowledge support from the Indo-French Centre for\nthe Promotion of Advanced Research (Centre Franco-Indien pour la Promotion\nde la Recherche Avanc\\'ee) under contract 3004-3. PN is supported by an\nESO student fellowship.\n\\end{acknowledgements}\n\n\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} +{"text":"\\section{Introduction}\\label{sec:intro}\n\n\\noindent\nProbabilistic programming languages (PPLs), such as Stan~\\citep{carpenter2017stan}, Pyro~\\citep{bingham2019pyro}, Gen~\\citep{towner2019gen}, Birch~\\citep{murray2018automated}, Anglican~\\citep{wood2014new}, and WebPPL~\\citep{goodman2014design}, make it possible to encode and solve statistical inference problems.\nSuch inference problems are of significant interest in many research fields, including phylogenetics~\\citep{ronquist2021universal}, computer vision~\\citep{kulkarni2015picture}, topic modeling~\\citep{blei2003latent}, inverse graphics~\\citep{gothoskar20213dp3}, and cognitive science~\\citep{goodman2016probabilistic}.\nA particularly appealing feature of PPLs is the separation between the inference problem specification (the language) and the inference algorithm used to solve the problem (the language implementation).\nThis separation allows PPL users to focus solely on encoding their inference problems while inference algorithm experts deal with the intricacies of inference implementation.\n\nImplementations of PPLs apply many different inference algorithms.\nMonte Carlo inference algorithms---such as Markov chain Monte Carlo (MCMC)~\\citep{gilks1995markov} and sequential Monte Carlo (SMC)~\\citep{doucet2001sequential}---are especially popular due to their asymptotic correctness and relative ease of implementation for \\emph{universal}\\footnote{%\n A term that first appeared in \\citet{goodman2008church}, indicating expressive PPLs where the number and types of random variables are not always known statically.%\n} PPLs.\nThe central idea behind all Monte Carlo methods in PPLs is to execute probabilistic programs multiple times to generate \\emph{samples} that approximate the target distribution for the encoded inference problem.\nHowever, repeated execution is expensive, and PPL implementations must take care not to introduce unnecessary overhead.\n\n\nIn particular, Monte Carlo algorithms often need to \\emph{suspend} executions as part of inference.\nFor example, MCMC algorithms can suspend at \\emph{random draws} in the program to avoid unnecessary re-execution when proposing new executions, and SMC algorithms can suspend at \\emph{likelihood updates} to \\emph{resample} executions.\nLanguages such as WebPPL~\\citep{goodman2014design} and Anglican~\\citep{wood2014new}, and the approach described by \\citet{ritchie2016c3}, apply \\emph{continuation-passing style (CPS)} transformations~\\citep{appel1991compiling} to enable arbitrary suspension during execution.\nThe main benefit with CPS transformations is that they are relatively easy to implement using higher-order functions in functional programming languages.\nHowever, a major drawback with CPS transformations is that high-performance low-level languages, without higher-order functions, do not support them.\nFor this reason, there are also closely related low-level alternatives to CPS, including non-preemptive multitasking (e.g., coroutines~\\citep{ge2018turing}) and PPL control-flow graphs~\\citep{lunden2022compiling}.\nBesides not requiring higher-order functions, these alternatives can avoid much of the overhead resulting from CPS\\footnote{%\n Note that CPS only results in overhead if programs reify the continuations at runtime to, e.g., suspend computations.\n Traditional CPS-based compilers often only use CPS as an intermediate form during compilation, which does not result in runtime overhead.\n}.\nThe alternatives are, however, more difficult to implement, and high-level functional languages can often not apply them as they require low-level features unavailable in high-level languages.\n\nIn this paper, we consider how to bridge the performance gap between higher-order CPS-based functional PPLs and lower-level PPLs that rely on, e.g., coroutines.\nSpecifically, the overhead in CPS is a direct result of closure allocations for continuations.\nWe make the important observation that PPLs do not strictly require the arbitrary suspensions provided by full CPS transformations.\nIn fact, most Monte Carlo inference algorithms require suspension only in very specific parts of programs.\nFor example, MCMC algorithms require suspension only at random draws, and SMC only at likelihood updates.\nCurrent CPS-based PPLs do not consider inference-specific suspension requirements to reduce CPS runtime overhead.\n\nIn this paper, we design a new static suspension analysis for PPLs that enables selectively CPS transforming programs to significantly reduce runtime overhead compared to using full CPS.\nThe suspension analysis identifies all parts of programs that may require suspension as a result of applying a particular inference algorithm.\nWe formalize the suspension analysis algorithm using a core PPL calculus equipped with a big-step operational semantics.\nSpecifically, the challenge lies in capturing how suspension requirements propagate through the program in the presence of higher-order functions.\nOverall, we (i) prove that the suspension analysis is correct, (ii) show that the resulting selective CPS transformation gives significant performance gains compared to using a full CPS transformation, and (iii) show that the overall approach is directly applicable to a large set of inference algorithms.\nSpecifically, we evaluate the approach for the inference algorithms: likelihood weighting, the SMC bootstrap particle filter, the SMC alive particle filter~\\citep{kudlicka2019probabilistic}, aligned lightweight MCMC~\\citep{lunden2023automatic,wingate2011lightweight}, and particle-independent Metropolis--Hastings~\\citep{paige2014compilation}.\nWe consider each inference algorithm for four real-world models from phylogenetics, epidemiology, and topic modeling.\nConsidering the performance benefits, it is surprising that previous work does not consider selective CPS for PPLs.\nWhile non-trivial, the suspension analysis is relatively simple to implement.\n\nWe implement the suspension analysis and a selective CPS transformation in Miking CorePPL~\\citep{lunden2022compiling,broman2019vision}.\nSimilarly to WebPPL and Anglican, the implementation supports the co-existence of many inference problems and applications of inference algorithms to these problems within the same program.\nHowever, compared to full CPS, such programs are more challenging to handle with selective CPS, as the CPS transformation of an inference problem also depends on the applied inference algorithm---different inference algorithms generally require different suspensions.\nTo complicate things further, different inference problems may share some code, or the PPL user may apply two different inference algorithms to the same inference problem.\nThe compiler must then apply different CPS transformations to different parts of the program, and sometimes even many different CPS transformations to separate copies of the \\emph{same} part of the program.\nTo solve this, we develop an approach that, for any given Miking CorePPL program, \\emph{extracts} all possible inference problems and corresponding inference algorithm applications.\nThis extraction procedure allows the correct application of selective CPS throughout the program.\n\nIn summary, we make the following contributions.\n\\begin{itemize}\n \\item\n We design, formalize, and prove the correctness of a suspension analysis for PPLs, where the suspension requirements come from a given inference algorithm (Section~\\ref{sec:sus}).\n \\item\n We apply the suspension analysis to selectively CPS transform PPLs.\n Compared to full CPS, the approach significantly reduces runtime overhead resulting from unnecessary closure allocations (Section~\\ref{sec:cps}).\n \\item\n We implement the suspension analysis and a selective CPS transformation in the Miking CorePPL compiler.\n Unlike full CPS, selective CPS introduces challenges for probabilistic programs containing many inference problems and inference algorithm applications.\n We implement an approach that correctly applies selective CPS to such programs by extracting individual inference problems (Section~\\ref{sec:implementation}).\n\\end{itemize}\nSection~\\ref{sec:evaluation} presents the evaluation and its results for the implementations in Miking CorePPL, Section~\\ref{sec:related} discusses related work in more detail, and Section~\\ref{sec:conclusion} concludes.\nWe first consider a motivating example in Section~\\ref{sec:motivating} and introduce the underlying PPL calculus in Section~\\ref{sec:ppl}.\n\n\\pgfplotsset{%\n probplot\/.style={%\n ytick=\\empty,\n width=50mm,\n height=40mm,\n tick style={draw=none},\n tick label style={font=\\scriptsize},\n label style={font=\\scriptsize},\n x label style={at={(axis description cs:0.5,-0.3)},anchor=north},\n axis line style={draw=none},\n }\n}\n\\begin{figure}\n \\lstset{%\n basicstyle=\\ttfamily\\scriptsize,\n showlines=true,\n framexleftmargin=-2pt,\n xleftmargin=2em,\n }%\n \\centering\n \\begin{subfigure}{0.5\\textwidth}\n \\centering\n \\begin{lstlisting}[style=ppl]\nlet $a_1$ = assume ($\\textrm{Beta}$ $2$ $2$) in$\\label{line:base:assume}$\nlet rec $\\mathit{iter}$ = $\\lambda \\mathit{obs}.$$\\label{line:base:recbegin}$\n if $\\mathit{null}$ $\\mathit{obs}$ then $()$ else$\\label{line:base:ret}$\n weight ($f_{\\textrm{Bernoulli}}$ $a_1$ ($\\mathit{head} \\, \\mathit{obs})$);$\\label{line:base:weight}$\n $\\mathit{iter}$ ($\\mathit{tail}$ $\\mathit{obs}$)\nin\n$\\mathit{iter}$ $[\\textrm{true}{}$,$\\textrm{true}{}$,$\\textrm{false}{}$,$\\textrm{true}{}]$;$\\label{line:base:recend}$\n$a_1$$\\label{line:base:return}$\n \\end{lstlisting}\n \\caption{Program $\\texample$.}\n \\label{fig:running:base}\n \\end{subfigure}\n \\begin{minipage}{0.49\\textwidth}\n \\begin{subfigure}{\\textwidth}\n \\centering\n \\begin{tikzpicture}\n \\begin{axis}[%\n axis x line*=bottom,\n y axis line style={draw=none},\n width=0.8\\textwidth,\n height=2.7cm,\n ymin=0, ymax=2.5,\n xmin=0, xmax=1,\n \n tick style={draw=none},\n xtick={0,0.5,1},\n ytick=\\empty,\n ]\n \\newcommand{2}{2}\n \\newcommand{2}{2}\n \\addplot [\n domain=0:1\n ] {%\n x^(2-1) * (1-x)^(2-1) \/\n ((2-1)!*(2-1)!\/(2+2-1)!)\n };\n \\end{axis}\n \\end{tikzpicture}\n \\caption{Beta(2,2).}\n \\label{fig:running:beta}\n \\end{subfigure} \\\\[2mm]\n \\begin{subfigure}{\\textwidth}\n \\centering\n \\begin{tikzpicture}\n \\begin{axis}[%\n axis x line*=bottom,\n y axis line style={draw=none},\n width=0.8\\textwidth,\n height=2.7cm,\n ymin=0, ymax=2.5,\n xmin=0, xmax=1,\n \n tick style={draw=none},\n xtick={0,0.5,1},\n ytick=\\empty,\n ]\n \\newcommand{5}{5}\n \\newcommand{3}{3}\n \\addplot [\n fill=gray!70,\n domain=0:1\n ] {%\n x^(5-1) * (1-x)^(3-1) \/\n ((5-1)!*(3-1)!\/(5+3-1)!)\n };\n \\end{axis}\n \\end{tikzpicture}\n \\caption{Distribution of $\\texample$.}\n \\label{fig:running:posterior}\n \\end{subfigure}\n \\end{minipage} \\\\[2mm]\n \\begin{minipage}{0.44\\textwidth}\n \\begin{subfigure}{\\textwidth}\n \\begin{lstlisting}[style=ppl]\n$\\Susassume(\\textrm{Beta}$ $2$ $2$, $\\lambda a_1$.\n let rec $\\mathit{iter}$ = $\\lambda \\mathit{obs}.$\n if $\\mathit{null}$ $\\mathit{obs}$ then $()$ else\n weight ($f_{\\textrm{Bernoulli}(a_1)}$\n ($\\mathit{head} \\, \\mathit{obs}$));\n $\\mathit{iter}$ ($\\mathit{tail}$ $\\mathit{obs}$)\n in\n $\\mathit{iter}$ $[\\textrm{true}{}$,$\\textrm{true}{}$,$\\textrm{false}{}$,$\\textrm{true}{}]$;\n $a_1)$\n \\end{lstlisting}\n \\caption{Suspension at \\texttt{assume}.}\n \\label{fig:running:assume}\n \\end{subfigure}\\\\\n \\begin{subfigure}{\\textwidth}\n \\begin{lstlisting}[style=ppl]\nlet $a_1$ = assume ($\\textrm{Beta}$ $\\!2$ $\\!2$) in\nlet rec $\\mathit{iter}$ = $\\lambda k.$ $\\lambda \\mathit{obs}.$\n if $\\mathit{null}$ $\\mathit{obs}$ then $k$ $()$$\\label{line:weight:ret}$\n else\n $\\Susweight($$\\label{line:weight:sus}$\n $f_{\\textrm{Bernoulli}(a_1)}$ ($\\mathit{head} \\, \\mathit{obs}$),\n ($\\lambda \\_.$ $\\mathit{iter}$ $k$ ($\\mathit{tail}$ $\\mathit{obs}$))$)$$\\label{line:weight:k}$\nin\n$\\mathit{iter}$ ($\\lambda \\_.$ $a_1$)\n $[\\textrm{true}{}$,$\\textrm{true}{}$,$\\textrm{false}{}$,$\\textrm{true}{}]$;\n \\end{lstlisting}\n \\caption{Suspension at \\texttt{weight}.}\n \\label{fig:running:weight}\n \\end{subfigure}\n \\end{minipage}\n \\begin{subfigure}{0.55\\textwidth}\n \\centering\n \\begin{tabular}{c}\n \\begin{lstlisting}[style=ppl]\nlet $k_7$ = $\\lambda t_6.$\n let $k_8$ = $\\lambda t_7.$\n $\\Susassume($$t_7$, $\\lambda a_1.$$\\label{line:full:susassume}$\n let rec $\\mathit{iter}$ = $\\lambda k_1.$ $\\lambda \\mathit{obs}.$\n let $k_2$ = $\\lambda t_1.$\n if $t_1$ then $k_1$ $()$ else\n let $k_3$ = $\\lambda t_2.$\n let $k_4$ = $\\lambda t_3.$\n let $k_5$ = $\\lambda t_4.$\n $\\Susweight($$t_4$, $\\lambda \\_.$$\\label{line:full:susweight}$\n let $\\!k_6\\!$ = $\\!\\lambda t_5.\\!$ $\\!\\mathit{iter}$ $\\!k_1\\!$ $t_5$ in\n $\\mathit{tail}_\\textrm{CPS}$ $k_6$ $\\mathit{obs})$\n in $t_2$ $k_5$ $t_3$\n in $\\mathit{head}_\\textrm{CPS}$ $k_4$ $\\mathit{obs}$\n in ${f_\\textrm{Bernoulli}}_\\textrm{CPS}$ $k_3$ $a_1$\n in $\\mathit{null}_\\textrm{CPS}$ $k_2$ $\\mathit{obs}$\n in $\\mathit{iter}$ ($\\lambda \\_.$ $a_1$)\n $[\\textrm{true}{}$,$\\textrm{true}{}$,$\\textrm{false}{}$,$\\textrm{true}{}])$\n in $t_6$ $k_8$ $2$\nin $\\textrm{Beta}_\\textrm{CPS}$ $k_7$ $2$\n \\end{lstlisting}\n \\end{tabular}\n \\caption{Full CPS.}\n \\label{fig:running:full}\n \\end{subfigure}\n \\caption{%\n A simple probabilistic program $\\texample$ modeling the bias of a coin.\n Figure~(a) gives the program.\n The function $f_\\textrm{Bernoulli}$ is the probability mass function of the Bernoulli distribution.\n Figure~(b) illustrates the distribution used for $a_1$ at line~\\ref{line:base:assume} in (a).\n Figure~(c) shows the set of (weighted) samples resulting from conceptually running $\\texample$ infinitely many times.\n Figure~(d) and Figure~(e) show the selective CPS transformations required for suspension at \\texttt{assume} and \\texttt{weight}, respectively.\n Figure~(f) gives $\\texample$ in full CPS, with suspensions at \\texttt{assume} and \\texttt{weight}.\n The $_\\textrm{CPS}$ subscript indicates CPS-versions of intrinsic functions such as $\\mathit{head}$ and $\\mathit{tail}$.\n }\n \\label{fig:running}\n\\end{figure}\n\\section{A Motivating Example}\\label{sec:motivating}\nThis section introduces the running example in Figure~\\ref{fig:running} and uses it to present the basic idea behind PPLs and how inference algorithms such as SMC and MCMC make use of CPS to suspend executions.\nMost importantly, we illustrate the motivation and key ideas behind selective CPS for PPLs.\n\nConsider the probabilistic program in Figure~\\ref{fig:running:base}, written in a functional-style PPL.\nThe program encodes an inference problem for estimating the probability distribution over the bias of a coin, \\emph{conditioned} on the outcome of four experimental coin flips: \\textrm{true}{}, \\textrm{true}{}, \\textrm{false}{}, and \\textrm{true}{} ($\\textrm{true}{} = \\text{heads}$ and $\\textrm{false}{} = \\text{tails}$).\nAt line~\\ref{line:base:assume}, we use the PPL-specific \\texttt{assume} construct to define our \\emph{prior} belief in the bias $a_1$ of the coin.\nWe set this prior belief to a Beta$(2,2)$ probability distribution, illustrated in Figure~\\ref{fig:running:beta}.\nIn the illustration, 0 indicates a coin that always results in \\textrm{false}{}, 1 a coin that always results in \\textrm{true}{}, and 0.5 a fair coin.\nWe see that our prior belief is quite evenly spread out, but with more probability mass towards a fair coin.\nTo condition this prior distribution on the observed coin flips, we conceptually execute the program in Fig~\\ref{fig:running:base} infinitely many times, \\emph{sampling} values from the prior Beta distribution at \\texttt{assume} (line~\\ref{line:base:assume}) and, as a side effect, \\emph{accumulating the product of weights} given as argument to the PPL-specific \\texttt{weight} construct (line~\\ref{line:base:weight}).\nWe make the four consecutive calls \\texttt{weight ($f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{true}{}$)}, \\texttt{weight ($f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{true}{}$)}, \\texttt{weight ($f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{false}{}$)}, and \\texttt{weight ($f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{true}{}$)}\\footnote{%\n PPLs also commonly use a similar built-in function \\texttt{observe} to update the weight. For example, \\texttt{observe ($\\textrm{Bernoulli}$ $a_1$) \\textrm{true}{}} is equivalent to \\texttt{weight ($f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{true}{}$)}.\n}, using the recursive function $\\mathit{iter}$.\nThe function application \\texttt{$f_\\textrm{Bernoulli}$ $a_1$ $o$} gives the probability of the outcome $o$ given a bias $a_1$ for the coin.\nI.e., $\\texttt{$f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{true}{}$} = a_1$ and $\\texttt{$f_\\textrm{Bernoulli}$ $a_1$ $\\textrm{false}{}$} = 1 - a_1$.\nSo, for example, a sample $a_1 = 0.4$ gets the accumulated weight $0.4\\cdot0.4\\cdot0.6\\cdot0.4$ and $a_1 = 0.7$ the accumulated weight $0.7\\cdot0.7\\cdot0.3\\cdot0.7$.\nThe end result is an infinite set of \\emph{weighted} samples of $a_1$ (the program returns $a_1$ at line~\\ref{line:base:return}) that approximate the \\emph{posterior} or \\emph{target} distribution of Figure~\\ref{fig:running:base}, illustrated in Fig~\\ref{fig:running:posterior}.\nNote that, because we observed three \\textrm{true}{} outcomes and only one \\textrm{false}{}, the weights shift the probability mass towards 1 and narrows it slightly as we are now more sure about the bias of the coin.\nIncreasing the number of experimental coin flips would make Figure~\\ref{fig:running:posterior} more and more narrow.\n\nWe can approximate the infinite number of samples by running the program a large (but finite) number of times.\nThis basic inference algorithm is known as \\emph{likelihood weighting}.\nThe problem with likelihood weighting is that it is only accurate enough for simple models.\nFor complex models, it is common that only a few likelihood weighting samples (often only one) get much larger weights relative to the other samples, greatly reducing inference accuracy.\nReal-world models require more powerful inference algorithms based on, e.g., SMC or MCMC.\nA key requirement in both SMC and MCMC is the ability to \\emph{suspend} executions of probabilistic programs at calls to \\texttt{weight} and\/or \\texttt{assume}.\nOne way to enable suspensions is by writing programs in CPS.\nWe first illustrate a simple use of CPS to suspend at \\texttt{assume} in Figure~\\ref{fig:running:assume}.\nHere, the program immediately returns an object $\\Susassume(\\textrm{Beta}$~$2$~$2$,~$k)$, indicating that execution stopped at an \\texttt{assume} with the argument \\textrm{Beta}~$2$~$2$ and a continuation $k$ (i.e., the abstraction binding $a_1$) that executes the remainder of the program.\nWith likelihood weighting, we would simply sample a value $a_1$ from the \\textrm{Beta}~$2$~$2$ distribution and resume execution by calling $k$~$a_1$.\nThis call then runs the program until termination and results in the actual return value of the program, which is $a_1$.\nMany MCMC inference algorithms often reuse samples from previous executions at $\\Susassume$, and the suspensions are thus useful to avoid unnecessary re-execution~\\citep{ritchie2016c3}.\n\nAs a second example, we illustrate suspension at \\texttt{weight} for, e.g., SMC inference algorithms in Figure~\\ref{fig:running:weight}.\nHere, we require multiple suspensions in the middle of the recursive call to $\\mathit{iter}$, and writing the program in CPS is more challenging.\nNote that we rewrite the $\\mathit{iter}$ function to take a continuation $k$ as argument, and call the continuation with the return value $()$ at line~\\ref{line:weight:ret} instead of directly returning $()$ as in Figure~\\ref{fig:running:base} at line~\\ref{line:base:ret}.\nThis continuation argument $k$ is precisely what allows use to construct and return $\\Susweight$ objects at line~\\ref{line:weight:sus}.\nTo illustrate the suspensions, consider executing the program with likelihood weighting inference.\nFirst, the program returns the object $\\Susweight(f_{\\textrm{Bernoulli}(a_1)}~\\textrm{true}{}, k')$, where $k'$ is the continuation that line~\\ref{line:weight:k} constructs.\nLikelihood weighting now updates the weight for the execution with the value $f_{\\textrm{Bernoulli}(a_1)}~\\textrm{true}{}$ and resumes execution by calling $k'~()$.\nSimilarly, this next execution returns $\\Susweight(f_{\\textrm{Bernoulli}(a_1)}~\\textrm{true}{}, k'')$ for the second recursive call to $\\mathit{iter}$, and we again update the weight and resume by calling $k''~()$.\nWe similarly encounter $\\Susweight(f_{\\textrm{Bernoulli}(a_1)}~\\textrm{false}{}, k''')$ and $\\Susweight(f_{\\textrm{Bernoulli}(a_1)}~\\textrm{true}{}, k'''')$ before the final call $k''''~()$ runs the program until termination and produces the actual return value $a_1$ of the program.\nIn SMC inference, we run many executions concurrently and wait until they all have returned a $\\Susweight$ object.\nAt this point, we resample the executions according to their weights (the first value in $\\Susweight$), which discards executions with low weight and replicates executions with high weight.\nAfter resampling, we continue to the next suspension and corresponding resampling by calling the continuations.\n\nPPL implementations enable suspensions at \\texttt{assume} and\/or \\texttt{weight} through automatic and full CPS transformations.\nFigure~\\ref{fig:running:full} illustrates such a transformation for Figure~\\ref{fig:running:base}.\nWe indicate CPS versions of intrinsic functions with the $_\\textrm{CPS}$ subscript.\nNote that the full CPS transformation results in many additional closure allocations compared to Figure~\\ref{fig:running:assume} and Figure~\\ref{fig:running:weight}.\nAs a result, runtime overhead increases significantly.\nThe contribution in this paper is a static analysis that allows us to automatically and selectively CPS transform programs, as in Figure~\\ref{fig:running:assume} and Figure~\\ref{fig:running:weight}.\nWith a selective transformation, we avoid many unnecessary closure allocations, and can significantly reduce runtime overhead while still allowing suspensions as required for a given inference algorithm.\n\n\\section{Syntax and Semantics}\\label{sec:ppl}\nThis section introduces the PPL calculus used to formalize the suspension analysis in Section~\\ref{sec:sus} and selective CPS transformation in Section~\\ref{sec:cps}.\nSection~\\ref{sec:syntax} gives the abstract syntax and Section~\\ref{sec:semantics} a big-step operational semantics.\nSection~\\ref{sec:anf} introduces A-normal form---a prerequisite for both the suspension analysis and the selective CPS transformation.\n\n\\subsection{Syntax}\\label{sec:syntax}\nWe build upon the standard untyped lambda calculus, representative of functional universal PPLs such as Anglican, WebPPL, and Miking CorePPL.\nWe define the abstract syntax below.\n\\begin{definition}[Terms, values, and environments]\\label{def:terms}\n We define terms $\\textbf{\\upshape\\tsf{t}} \\in T$ and values $\\textbf{\\upshape\\tsf{v}} \\in V$ as\n {\\upshape\n \\begin{equation}\\label{eq:ast}\n \\begin{gathered}\n \\begin{aligned}\n \\textbf{\\upshape\\tsf{t}} \\Coloneqq& \\enspace\n %\n x\n \\enspace | \\enspace\n %\n c\n \\enspace | \\enspace\n %\n \\lambda x. \\enspace \\textbf{\\upshape\\tsf{t}}\n \\enspace | \\enspace\n %\n \\textbf{\\upshape\\tsf{t}} \\enspace \\textbf{\\upshape\\tsf{t}}\n \\enspace | \\enspace\n %\n \\texttt{let } x = \\textbf{\\upshape\\tsf{t}} \\texttt{ in } \\textbf{\\upshape\\tsf{t}}\n %\n & \\textbf{\\upshape\\tsf{v}} \\Coloneqq& \\enspace\n c\n \\enspace | \\enspace\n %\n \\langle\\lambda x. \\enspace \\textbf{\\upshape\\tsf{t}},\\rho\\rangle\n %\n \\\\ |& \\enspace\n %\n \\texttt{if } \\textbf{\\upshape\\tsf{t}} \\texttt{ then } \\textbf{\\upshape\\tsf{t}} \\texttt{ else } \\textbf{\\upshape\\tsf{t}}\n \\enspace | \\enspace\n %\n \\texttt{assume } \\textbf{\\upshape\\tsf{t}}\n \\enspace | \\enspace\n %\n \\texttt{weight } \\textbf{\\upshape\\tsf{t}}\n &&\\\\\n \\end{aligned} \\\\\n x,y \\in X \\quad\n \\rho \\in P \\quad\n c \\in C \\quad\n \\{ \\textrm{false}{}, \\textrm{true}{}, () \\} \\cup \\mathbb{R} \\cup D \\subseteq C.\n \\end{gathered}\n \\end{equation}\n }%\n The countable set $X$ contains variable names, $C$ intrinsic values and operations, and $D \\subset C$ intrinsic probability distributions.\n The set $P$ contains \\emph{evaluation environments}, i.e., maps from variables in $X$ to values in $V$.\n\\end{definition}\n\\begin{definition}[Target language terms]\n As a target language for the selective CPS transformation in Section~\\ref{sec:cps},\n we additionally extend Definition~\\ref{def:terms} to target language terms $\\textbf{\\upshape\\tsf{t}} \\in T^+$ by\n {\\upshape\n \\begin{equation}\n \\textbf{\\upshape\\tsf{t}} \\mathrel{+}=\n \\Susassume(\\textbf{\\upshape\\tsf{t}},\\textbf{\\upshape\\tsf{t}})\n \\enspace | \\enspace\n %\n \\Susweight(\\textbf{\\upshape\\tsf{t}},\\textbf{\\upshape\\tsf{t}}).\n \\end{equation}\n }\n\\end{definition}\n\\noindent\nFigure~\\ref{fig:running:base} gives an example of a term in $T$, and Figure~\\ref{fig:running:assume} and Figure~\\ref{fig:running:weight} of terms in $T^+$.\nHowever, note that the programs in Figure~\\ref{fig:running} also use the list constructor \\texttt{[$\\ldots$]} (not part of the above definitions) to make the example more interesting.\n\nIn addition to the standard variable, abstraction, and application terms in the untyped lambda calculus, we include explicit \\texttt{let} expressions in the language for convenience.\nFurthermore, we use the syntactic sugar \\texttt{let rec $f$ = $\\lambda x.\\textbf{\\upshape\\tsf{t}}_1$ in $\\textbf{\\upshape\\tsf{t}}_2$} to define recursive functions (translating to an application of a call-by-value fixed-point combinator).\nWe also use \\texttt{$\\textbf{\\upshape\\tsf{t}}_1$; $\\textbf{\\upshape\\tsf{t}}_2$} as a shorthand for \\texttt{($\\lambda \\_. \\textbf{\\upshape\\tsf{t}}_2$) $\\textbf{\\upshape\\tsf{t}}_1$}, where $\\_$ is the do-not-care symbol.\n\n\nWe include a set $C$ of intrinsic operations and constants essential to most inference problems encoded in PPLs.\nIn particular, the set of intrinsics includes, but is not limited to, boolean truth values, the unit value, real numbers, and probability distributions.\nWe can also add further operations and constants to $C$.\nFor example, we can let $+ \\in C$ to support addition of real numbers.\nTo allow control flow to depend on intrinsic values, we include \\texttt{if} expressions that use intrinsic booleans as condition.\n\nWe saw examples of the \\texttt{assume} and \\texttt{weight} constructs in Section~\\ref{sec:motivating}.\nThe \\texttt{assume} construct takes distributions $D \\subset C$ as argument, and produces random variables distributed according to these distributions.\nFor example, we can let $\\mathcal N \\in C$ be a function that constructs normal distributions.\nThen, \\texttt{assume ($\\mathcal N$ $0$ $1$)}, where $\\mathcal N$ $0$ $1 \\in D$, defines a random variable distributed according to a standard normal distribution.\nAs we saw in Section~\\ref{sec:motivating}, the \\texttt{weight} construct updates the likelihood of executions with the real number given as argument, and allows conditioning executions on data (e.g., the four coin flips in Figure~\\ref{fig:running}).\n\n\\subsection{Semantics}\\label{sec:semantics}\nWe construct a call-by-value big-step operational semantics, inspired by \\citet{lunden2023automatic}, describing how to evaluate terms $\\textbf{\\upshape\\tsf{t}} \\in T$.\nSuch a semantics is a key component when formally defining the probability distributions corresponding to terms $\\textbf{\\upshape\\tsf{t}} \\in T$ (e.g., the distribution in Figure~\\ref{fig:running:posterior} corresponding to the program in Figure~\\ref{fig:running:base}) and also when proving various properties of PPLs and their inference algorithms (e.g., inference correctness).\nSee, e.g., the work by \\citet{borgstrom2016lambda} and \\citet{lunden2021correctness} for full formal treatments and correctness proofs of PPL MCMC and SMC algorithms.\n\n\\begin{figure}[tb]\n \\[\\footnotesize\n \\begin{gathered}\n \\frac{}\n { \\rho \\vdash x \\sem{\\textrm{false}{}}{[]}{1} \\rho(x) }\n (\\textsc{Var}) \\quad\n %\n \\frac{}\n { \\rho \\vdash c \\sem{\\textrm{false}{}}{[]}{1} c }\n (\\textsc{Const}) \\quad\n %\n \\frac{}\n { \\rho \\vdash \\lambda x. \\textbf{\\upshape\\tsf{t}} \\sem{\\textrm{false}{}}{[]}{1} \\langle\\lambda x. \\textbf{\\upshape\\tsf{t}},\\rho\\rangle }\n (\\textsc{Lam}) \\\\[0.5em]\n %\n \\frac{ \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\sem{u_1}{s_1}{w_1} \\langle\\lambda x. \\textbf{\\upshape\\tsf{t}},\\rho'\\rangle \\quad \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_2}{s_2}{w_2} \\textbf{\\upshape\\tsf{v}}_2 \\quad \\rho' ,x \\mapsto \\textbf{\\upshape\\tsf{v}}_2 \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u_3}{s_3}{w_3} \\textbf{\\upshape\\tsf{v}}}\n { \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_1 \\lor u_2 \\lor u_3}{s_1 \\concat s_2 \\concat s_3}{w_1 \\cdot w_2 \\cdot w_3} \\textbf{\\upshape\\tsf{v}} }\n (\\textsc{App}) \\\\[0.5em]\n %\n \\frac{ \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\sem{u_1}{s_1}{w_1} c_1 \\quad \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_2}{s_2}{w_2} c_2}\n { \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_1 \\lor u_2}{s_1 \\concat s_2}{w_1 \\cdot w_2} \\delta(c_1,c_2) }\n (\\textsc{Const-App}) \\\\[0.5em]\n %\n \\frac{ \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\sem{u_1}{s_1}{w_1} \\textbf{\\upshape\\tsf{v}}_1 \\quad \\rho, x \\mapsto \\textbf{\\upshape\\tsf{v}}_1 \\vdash \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_2}{s_2}{w_2} \\textbf{\\upshape\\tsf{v}}}\n { \\rho \\vdash \\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\texttt{ in } \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_1 \\lor u_2}{s_1 \\concat s_2}{w_1 \\cdot w_2} \\textbf{\\upshape\\tsf{v}} }\n (\\textsc{Let}) \\\\[0.5em]\n %\n \\frac{ \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\sem{u_1}{s_1}{w_1} \\textrm{true}{} \\quad \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_2}{s_2}{w_2} \\textbf{\\upshape\\tsf{v}}_2 }\n {\\rho \\vdash \\texttt{if } \\textbf{\\upshape\\tsf{t}}_1 \\texttt{ then } \\textbf{\\upshape\\tsf{t}}_2 \\texttt{ else } \\textbf{\\upshape\\tsf{t}}_3 \\sem{u_1 \\lor u_2}{s_1 \\concat s_2}{w_1 \\cdot w_2} \\textbf{\\upshape\\tsf{v}}_2}\n (\\textsc{If-True}) \\\\[0.5em]\n %\n \\frac{ \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_1 \\sem{u_1}{s_1}{w_1} \\textrm{false}{} \\quad \\rho \\vdash \\textbf{\\upshape\\tsf{t}}_3 \\sem{u_3}{s_3}{w_3} \\textbf{\\upshape\\tsf{v}}_3 }\n {\\rho \\vdash \\texttt{if } \\textbf{\\upshape\\tsf{t}}_1 \\texttt{ then } \\textbf{\\upshape\\tsf{t}}_2 \\texttt{ else } \\textbf{\\upshape\\tsf{t}}_3 \\sem{u_1 \\lor u_3}{s_1 \\concat s_3}{w_1 \\cdot w_3} \\textbf{\\upshape\\tsf{v}}_3}\n (\\textsc{If-False}) \\\\[0.5em]\n %\n \\frac{\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} d \\quad w' = f_d(c) }\n {\\rho \\vdash \\texttt{assume } \\textbf{\\upshape\\tsf{t}} \\sem{\\mi{suspend}_\\texttt{assume} \\lor u}{s \\concat [c]}{w \\cdot w'} c}\n (\\textsc{Assume}) \\quad\n %\n \\frac{\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} w'}\n {\\rho \\vdash \\texttt{weight } \\textbf{\\upshape\\tsf{t}} \\sem{\\mi{suspend}_\\texttt{weight} \\lor u}{s}{w \\cdot w'} ()}\n (\\textsc{Weight}) \\\\[0.5em]\n \\end{gathered}\n \\]\n \\caption{%\n A big-step operational semantics for $\\textbf{\\upshape\\tsf{t}} \\in T$.\n The environment $\\rho, x \\mapsto \\textbf{\\upshape\\tsf{v}}$ is the same as $\\rho$, but extended with a binding $\\textbf{\\upshape\\tsf{v}}$ for $x$.\n For each $d \\in D$, the function $f_d$ is its probability density or probability mass function.\n For example, $f_{\\mathcal N(0,1)}(x) = e^{x^2\/2}\/\\sqrt{2\\pi}$, the density function of the standard normal distribution.\n We use the following notation: $\\concat$ for sequence concatenation, $\\cdot$ for multiplication, and $\\lor$ for logical disjunction.\n }\n \\label{fig:semantics}\n\\end{figure}\n\nFor the purpose of this paper, we use the semantics to formally define what it means for an evaluation to suspend.\nWe use this definition to state the soundness of the suspension analysis in Section~\\ref{sec:sus} (Theorem~\\ref{thm:main}).\nWe use a big-step semantics, as we do not require the additional control provided by a small-step semantics.\nFigure~\\ref{fig:semantics} presents the full semantics as a relation $\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}$ over tuples $(P, T, S, \\{\\textrm{false}{},\\textrm{true}{}\\}, \\mathbb{R}, V)$.\nHere, $S$ is a set of \\emph{traces} capturing the random draws at \\texttt{assume} during evaluation.\nIntuitively, $\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}$ holds iff $\\textbf{\\upshape\\tsf{t}}$ evaluates to $\\textbf{\\upshape\\tsf{v}}$ in the environment $\\rho$ with the trace $s$ and the total probability density (i.e., the accumulated weight) $w$.\nWe describe the suspension flag $u$ later in this section.\n\nMost of the rules are standard and we focus on explaining key properties related to PPLs and suspension.\nWe first consider the rule (\\textsc{Const-App}), which uses a $\\delta$-function for intrinsic operations.\n\\noindent\n\\begin{definition}[Intrinsic arities and the $\\delta$-function]\\label{def:const}\n For each $c \\in C$, we let $|c| \\in \\mathbb N$ denote its \\emph{arity}.\n We also assume the existence of a partial function $\\delta: C \\times C \\rightarrow C$ such that if $\\delta(c, c_1) = c_2$, then $|c| > 0$ and $|c_2| = |c| - 1$.\n\\end{definition}\n\\noindent\nFor example, $\\delta((\\delta(+,1)), 2) = 3$.\nWe use the arity property of intrinsics to formally define traces.\n\\begin{definition}[Traces]\\label{def:trace}\n For all $s \\in S$, $s$ is a sequence of intrinsics with arity 0, called a \\emph{trace}.\n We write $s = [c_1,c_2,\\ldots,c_n]$ to denote a trace $s$ with $n$ elements.\n\\end{definition}\n\\noindent\nThe rule (\\textsc{Assume}) formalizes random draws and consumes elements of the trace.\nSpecifically, (\\textsc{Assume}) updates the evaluation's total probability density $w \\in \\mathbb R$ with the density $w'$ of the first trace element with respect to the distribution given as argument to \\texttt{assume}.\nThe rule (\\textsc{Weight}) furthermore directly modifies the total probability density according to the \\texttt{weight} argument.\n\nWe now consider the special suspension flag $u$ in the derivation $\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}$.\n\\begin{definition}[Suspension requirement]\\label{def:sus}\n We say that a derivation $\\rho \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}$ \\emph{requires suspension} if the suspension flag $u$ is $\\textrm{true}{}$.\n\\end{definition}\nFor example, the rule (\\textsc{App}) requires suspension if $u_1 \\lor u_2 \\lor u_3$---i.e., if any subderivation requires suspension.\nTo reflect the particular suspension requirements in SMC and MCMC inference, we limit the source of suspension requirements to \\texttt{assume} and \\texttt{weight}.\nWe turn the individual sources on and off through the boolean variables $\\mi{suspend}_\\texttt{assume}$ and $\\mi{suspend}_\\texttt{weight}$ in Figure~\\ref{fig:semantics}.\nFor the examples in the remainder of this paper, we let $\\mi{suspend}_\\texttt{weight} = \\textrm{true}{}$ and $\\mi{suspend}_\\texttt{assume} = \\textrm{false}{}$ (i.e., only \\texttt{weight} requires suspension, as in SMC inference).\n\nTo illustrate the semantics, consider $\\texample$ of Figure~\\ref{fig:running:base} again.\nBecause $\\texample$ evaluates precisely one \\texttt{assume}, the only valid traces for $\\texample$ are singleton traces $[a_1]$, where $a_1 \\in \\mathbb R_{[0,1]}$ due to the Beta prior for $a_1$.\nBy initially setting $\\rho$ to the empty environment $\\varnothing$ and following the rules of Figure~\\ref{fig:semantics}, we derive\n$\n \\varnothing \\vdash \\texample \\sem{\\textrm{true}{}}{[a_1]}{f_{\\textrm{Beta}(2,2)}(a_1)\\cdot a_1^3(1-a_1)} a_1.\n$\nNote that every evaluation of $\\texample$ has $u = \\textrm{true}{}$, as there are always four calls to \\texttt{weight} during evaluation.\nThat is, the derivation requires suspension.\nHowever, many subderivations of $\\texample$ do \\emph{not} require suspension.\nFor example, the subderivations \\texttt{assume (\\textrm{Beta} $2$ $2$)} and \\texttt{$\\mathit{null}$ $\\mathit{obs}$} do not require suspension (i.e., have $u = \\textrm{false}$).\nSection~\\ref{sec:sus} presents a suspension analysis that conservatively approximates which subderivations require suspension.\nThe analysis enables, e.g., the selective CPS transformation in Figure~\\ref{fig:running:weight}.\n\n\\begin{figure}[tb]\n \\centering\n \\lstset{%\n basicstyle=\\ttfamily\\scriptsize,\n showlines=true,\n framexleftmargin=-2pt,\n xleftmargin=2em,\n }%\n \\begin{multicols}{2}\n \\begin{lstlisting}[style=ppl]\nlet $t_1$ = $2$ in\nlet $t_2$ = $2$ in\nlet $t_3$ = $\\textrm{Beta}$ in\nlet $t_4$ = $t_3$ $t_1$ in\nlet $t_5$ = $t_4$ $t_2$ in\nlet $a_1$ = assume $t_5$ in\nlet rec $\\mathit{iter}$ = $\\lambda \\mathit{obs}.$$\\label{line:anflam}$\n let $t_6$ = $\\mathit{null}$ in\n let $t_7$ = $t_6$ $\\mathit{obs}$ in\n let $t_8$ = $\\label{line:if}$\n if $t_7$ then\n let $t_9$ = $()$ in\n $t_9$\n else\n let $t_{10}$ = $f_\\textrm{Bernoulli}$ in\n let $t_{11}$ = $t_{10}$ $a_1$ in\n let $t_{12}$ = $\\mathit{head}$ in\n let $t_{13}$ = $t_{12}$ $\\mathit{obs}$ in\n let $t_{14}$ = $t_{11}$ $t_{13}$ in\n let $w_1$ = weight $t_{14}$ in$\\label{line:weight}$\n let $t_{15}$ = $\\mathit{tail}$ in\n let $t_{16}$ = $t_{15}$ $\\mathit{obs}$ in\n let $t_{17}$ = $\\mathit{iter}$ $t_{16}$ in$\\label{line:iter1}$\n $t_{17}$\n in\n $t_8$$\\label{line:obsreturn}$\nin\nlet $t_{18}$ = $\\textrm{true}{}$ in\nlet $t_{19}$ = $\\textrm{false}{}$ in\nlet $t_{20}$ = $\\textrm{true}{}$ in\nlet $t_{21}$ = $\\textrm{true}{}$ in\nlet $t_{22}$ = $[t_{21}$,$t_{20}$,$t_{19}$,$t_{18}]$ in\nlet $t_{23}$ = $\\mathit{iter}$ $t_{22}$ in$\\label{line:iter2}$\n$a_1$$\\label{line:a1}$\n \\end{lstlisting}\n \\end{multicols}\n\n \\caption{\n The running example $\\texample$ from Figure~\\ref{fig:running:base} transformed to ANF.\n }\n \\label{fig:runninganf}\n\\end{figure}\n\\subsection{A-Normal Form}\\label{sec:anf}\nWe significantly simplify the suspension analysis in Section~\\ref{sec:sus} and the selective CPS transformation in Section~\\ref{sec:cps} by requiring that terms are in \\emph{A-normal form} (ANF)~\\citep{flanagan1993essence}.\n\\begin{definition}[A-normal form]\n We define the A-normal form terms $\\term_\\textrm{ANF} \\in T_\\textrm{ANF}$ as follows.\n {\\upshape\n \\begin{equation}\\label{eq:anf}\n \\begin{aligned}\n &\\begin{aligned}\n \\term_\\textrm{ANF} \\Coloneqq& \\enspace\n %\n x\n \\enspace | \\enspace\n %\n \\texttt{let } x = \\term_\\textrm{ANF}' \\texttt{ in } \\term_\\textrm{ANF}\n %\n \\\\\n \\term_\\textrm{ANF}' \\Coloneqq& \\enspace\n x\n \\enspace | \\enspace\n %\n c\n \\enspace | \\enspace\n %\n \\lambda x. \\enspace \\term_\\textrm{ANF}\n \\enspace | \\enspace\n %\n x \\enspace y\n \\\\ |& \\enspace\n %\n \\texttt{if } x \\texttt{ then } \\term_\\textrm{ANF} \\texttt{ else } \\term_\\textrm{ANF}\n \\enspace | \\enspace\n %\n \\texttt{assume } x\n \\enspace | \\enspace\n %\n \\texttt{weight } x\n \\end{aligned}\n \\end{aligned}\n \\end{equation}\n }\n\\end{definition}\n\\noindent\nIt holds that $T_\\textrm{ANF} \\subset T$.\nFurthermore, there exist standard transformations to convert terms in $T$ to $T_\\textrm{ANF}$.\nFigure~\\ref{fig:runninganf} illustrates Figure~\\ref{fig:running:base} transformed to ANF.\nWe will use Figure~\\ref{fig:running:base} as a running example in Section~\\ref{sec:sus} and Section~\\ref{sec:cps}.\n\nThe predictable structure of programs in ANF significantly simplifies the suspension analysis and selective CPS transformation.\nFurthermore, from now on we require that all variable bindings in programs are unique, and together with ANF, the result is that every expression in a program $\\textbf{\\upshape\\tsf{t}} \\in T_\\textrm{ANF}$ is \\emph{uniquely labeled} by a variable name from a \\texttt{let} expression.\nThis property is critical for the suspension analysis in Section~\\ref{sec:sus}.\n\n\\section{Suspension Analysis}\\label{sec:sus}\nThis section presents the first technical contribution: the suspension analysis.\nThe goal of the suspension analysis is to determine which expressions in programs may require suspension in the sense of Definition~\\ref{def:sus}.\nIdentifying such expressions leads to the selective CPS transformation in Section~\\ref{sec:cps}, enabling transformations such as in Fig~\\ref{fig:running:weight}.\n\nThe suspension analysis builds upon the 0-CFA algorithm~\\citep{shivers1991control,nielson1999principles}, and we formalize our algorithms in the style of~\\citet{lunden2023automatic}.\nThe main challenge we solve is how to model the propagation of suspension in the presence of higher-order functions in the untyped lambda calculus.\nThe 0 in 0-CFA stands for \\emph{context insensitivity}---the analysis considers every part of the program in one global context.\nContext insensitivity makes the analysis more conservative compared to context-sensitive approaches such as $k$-CFA, where $k \\in \\mathbb N$ indicates the level of context sensitivity~\\citep{midtgaard2021control}.\nWe use 0-CFA for two reasons: (i) the worst-case time complexity for the analysis is polynomial, while it is exponential for $k$-CFA already at $k = 1$, and (ii) the limitations of 0-CFA rarely matter in practical PPL applications.\nFor example, $k$-CFA provides no benefits over 0-CFA for the programs in the evaluation in Section~\\ref{sec:evaluation}.\n\nBefore moving on to the technical details, we assume\n$\\langle\\lambda x. \\enspace \\textbf{\\upshape\\tsf{t}}, \\rho \\rangle \\not\\in C$ (recall that $C$ is the set of intrinsics).\nThat is, we assume that closures are not part of the intrinsics.\nIn particular, this disallows intrinsic operations (including the use of \\texttt{assume $d$}, $d \\in D \\subset C$) to produce closures, which would needlessly complicate the analysis without any benefit.\n\nConsider the program in Figure~\\ref{fig:runninganf}, and assume that \\texttt{weight} requires suspension.\nClearly, the expression labeled by $w_1$ at line~\\ref{line:weight} then requires suspension.\nFurthermore, $w_1$ evaluates as part of the larger expression labeled by $t_8$ at line~\\ref{line:if}.\nConsequently, the evaluation of $t_8$ also requires suspension.\nAlso, $t_8$ evaluates as part of an application of the abstraction $\\mathit{obs}$ at line~\\ref{line:anflam}.\nIn particular, the abstraction $\\mathit{obs}$ binds to $\\mathit{iter}$, and we apply $\\mathit{iter}$ at lines~\\ref{line:iter1} and~\\ref{line:iter2}.\nThus, the expressions named by $t_{17}$ and $t_{22}$ require suspension.\nIn summary, we have that $w_1$, $t_8$, $t_{17}$, and $t_{22}$ require suspension, and we also note that all applications of the abstraction $\\mathit{obs}$ require suspension.\n\nWe now proceed to the analysis formalization.\nFirst, we introduce standard \\emph{abstract values}.\n\\begin{definition}[Abstract values]\\label{def:absval}\n We define the abstract values {\\upshape$\\textbf{\\tsf{a}} \\in A$} as\n {\\upshape$\n \\textbf{\\tsf{a}} \\Coloneqq\n %\n \\lambda x. y\n \\enspace | \\enspace\n %\n \\texttt{const}_x \\, n\n $} \\hspace{2mm}for $x,y \\in X$ and $n \\in \\mathbb{N}$.\n\\end{definition}\n\\noindent\nFor example, the abstract value $\\lambda x. y$ represents all closures originating at, e.g., a term \\texttt{$\\lambda x.$ let $y$ = $1$ in $y$} in the program at runtime (recall that we assume that the variables $x$ and $y$ are unique).\nNote that the $y$ in the abstract value indicates the name returned by the body (formalized by the function \\textsc{name} in Algorithm~\\ref{alg:gencstr}).\nThe abstract value $\\texttt{const}_x \\, n$ represents all intrinsic functions of arity $n$ originating at $x$.\nFor example, $\\texttt{const}_x \\enspace 2$ originates at, e.g., a term \\texttt{let $x$ = $+$ in \\textbf{\\upshape\\tsf{t}}}.\n\nThe central objects in the analysis are sets $S_x \\in \\mathcal P (A)$ and boolean values $\\mi{suspend}_x$ for all $x \\in X$.\nThe set $S_x$ contains all abstract values that may flow to the expression labeled by $x$, and $\\mi{suspend}_x$ indicates whether or not the expression requires suspension.\nA trivial but useless solution is $S_x = A$ and $\\mi{suspend}_x = \\textrm{true}{}$ for all variables $x$ in the program.\nTo get more precise information regarding suspension, we wish to find smaller solutions to the $S_x$ and $\\mi{suspend}_x$.\n\n\\begin{algorithm}[tb]\n \\renewcommand{\\enspace}{\\hphantom{|}}\n \\caption{%\n Constraint generation for the suspension analysis.\n We write the functional-style pseudocode for the algorithm itself in sans serif font to distinguish it from terms in $T$.\n }\\label{alg:gencstr}\n \\raggedright\n \\lstinline[style=alg]!function $\\textsc{generateConstraints}$($\\textbf{\\upshape\\tsf{t}}$): $T_\\textrm{ANF} \\rightarrow \\mathcal P(R)$ =!\\\\\n \\hspace{3mm}\n \\begin{minipage}{0.96\\textwidth}\n \\begin{multicols}{2}\n \\begin{lstlisting}[\n style=alg,\n showlines=true,\n basicstyle=\\sffamily\\scriptsize,\n ]\nmatch $\\textbf{\\upshape\\tsf{t}}$ with$\\label{line:topmatch}$\n| $x \\rightarrow$ $\\varnothing$\n| $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\rightarrow$$\\label{line:beginlet}$\n$\\enspace$ $\\textsc{generateConstraints}(\\textbf{\\upshape\\tsf{t}}_2) \\enspace \\cup$\n $\\enspace$ match $\\textbf{\\upshape\\tsf{t}}_1$ with\n $\\enspace$ | $y \\rightarrow \\{S_y \\subseteq S_x\\}$$\\label{line:genvar}$\n $\\enspace$ | $c \\rightarrow$ if $|c| > 0$ then $\\{\\texttt{const}_x \\enspace |c|\\in S_x\\}$\n $\\enspace$ $\\enspace$ $\\hspace{5mm}$ else $\\varnothing$\n $\\enspace$ | $\\lambda y. \\enspace \\textbf{\\upshape\\tsf{t}}_b \\rightarrow$ $\\textsc{generateConstraints}(\\textbf{\\upshape\\tsf{t}}_b)$$\\label{line:genabsb}$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\cup \\enspace \\{\\lambda y. \\enspace \\textsc{name} \\enspace \\textbf{\\upshape\\tsf{t}}_b \\in S_x \\}$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\cup \\enspace \\{ \\mi{suspend}_n \\Rightarrow \\mi{suspend}_y$\n $\\hspace{12mm} \\mid n \\in \\textsc{suspendNames}(t_b)\\}$$\\label{line:genabse}$\n $\\enspace$ | $\\mathit{lhs} \\enspace \\mathit{rhs} \\rightarrow$ $\\{$$\\label{line:genappb}$\n $\\enspace$ $\\enspace$ $\\forall z \\forall y \\enspace \\lambda z. y \\in S_{\\mathit{lhs}}$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\Rightarrow (S_\\mathit{rhs} \\subseteq S_z) \\land (S_y \\subseteq S_x)$,\n $\\enspace$ $\\enspace$ $\\forall y \\forall n \\enspace \\texttt{const}_y \\, n \\in S_\\mathit{lhs} \\land n > 1 $\n $\\enspace$ $\\enspace$ $\\enspace$ $\\Rightarrow \\texttt{const}_y \\, n-1 \\in S_x$,\n $\\enspace$ $\\enspace$ $\\forall y \\enspace \\lambda y. \\_ \\in S_{\\mathit{lhs}}$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\Rightarrow (\\mi{suspend}_y \\Rightarrow \\mi{suspend}_x)$,\n $\\enspace$ $\\enspace$ $\\forall y \\enspace \\texttt{const}_y \\enspace \\_ \\in S_{\\mathit{lhs}}$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\Rightarrow (\\mi{suspend}_y \\Rightarrow \\mi{suspend}_x)$,\n $\\enspace$ $\\enspace$ $\\mi{suspend}_x \\Rightarrow$\n $\\enspace$ $\\enspace$ $\\enspace$ $(\\forall y \\enspace \\lambda y. \\_ \\in S_{\\mathit{lhs}} \\Rightarrow \\mi{suspend}_y)$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\land \\enspace (\\forall y \\enspace \\texttt{const}_y \\enspace \\_ \\in S_{\\mathit{lhs}} \\Rightarrow \\mi{suspend}_y)$\n $\\enspace$ $\\enspace$ $\\}$$\\label{line:genappe}$\n $\\enspace$ | $\\texttt{assume } \\textrm{\\_} \\rightarrow$\n $\\enspace$ $\\enspace$ if $\\mi{suspend}_\\texttt{assume}$ then $\\{ \\mi{suspend}_x \\}$ else $\\varnothing$\n (*@ \\columnbreak @*)\n $\\enspace$ | $\\texttt{weight } \\textrm{\\_} \\rightarrow$\n $\\enspace$ $\\enspace$ if $\\mi{suspend}_\\texttt{weight}$ then $\\{ \\mi{suspend}_x \\}$ else $\\varnothing$ $\\label{line:genweight}$\n $\\enspace$ | $\\texttt{if } y \\texttt{ then } \\textbf{\\upshape\\tsf{t}}_t \\texttt{ else } \\textbf{\\upshape\\tsf{t}}_e \\rightarrow$$\\label{line:genifb}$\n $\\enspace$ $\\enspace$ $\\textsc{generateConstraints}(\\textbf{\\upshape\\tsf{t}}_t)$\n $\\enspace$ $\\enspace$ $\\cup \\enspace \\textsc{generateConstraints}(\\textbf{\\upshape\\tsf{t}}_e)$\n $\\enspace$ $\\enspace$ $\\cup \\enspace \\{S_{\\textsc{name} \\enspace \\textbf{\\upshape\\tsf{t}}_t} \\subseteq S_x, S_{\\textsc{name} \\enspace \\textbf{\\upshape\\tsf{t}}_e} \\subseteq S_x\\}$\n $\\enspace$ $\\enspace$ $\\cup \\enspace \\{\\mi{suspend}_n \\Rightarrow \\mi{suspend}_x $\n $\\mid n \\in \\textsc{suspendNames}(\\textbf{\\upshape\\tsf{t}}_t)$\n $\\cup \\enspace \\textsc{suspendNames}(\\textbf{\\upshape\\tsf{t}}_e)\\}$$\\label{line:genife}$\n\nfunction $\\textsc{name}$($\\textbf{\\upshape\\tsf{t}}$): $T_\\textrm{ANF} \\rightarrow X$ =$\\label{line:func_name}$\n match $\\textbf{\\upshape\\tsf{t}}$ with\n | $x \\rightarrow x$\n | $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\rightarrow$ $\\textsc{name}$($\\textbf{\\upshape\\tsf{t}}_2$)\n\nfunction $\\textsc{suspendNames}$($\\textbf{\\upshape\\tsf{t}}$): $T_\\textrm{ANF} \\rightarrow \\mathcal P(X)$ = $\\label{line:func_suspendNames}$\n match $\\textbf{\\upshape\\tsf{t}}$ with\n | $x \\rightarrow \\varnothing$\n | $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\rightarrow$\n $\\enspace$ $\\textsc{suspendNames}(\\textbf{\\upshape\\tsf{t}}_2) \\enspace \\cup$\n $\\enspace$ match $\\textbf{\\upshape\\tsf{t}}_1$ with\n $\\enspace$ | $\\mathit{lhs} \\enspace \\mathit{rhs} \\rightarrow \\{ x \\}$\n $\\enspace$ | $\\texttt{if } y \\texttt{ then } \\textbf{\\upshape\\tsf{t}}_t \\texttt{ else } \\textbf{\\upshape\\tsf{t}}_e \\rightarrow \\{ x \\}$\n $\\enspace$ | $\\texttt{assume}$ $\\_$ $\\rightarrow$\n $\\enspace$ $\\enspace$ if $\\mi{suspend}_\\texttt{assume}$ then $\\{ x \\}$ else $\\varnothing$\n $\\enspace$ | $\\texttt{weight}$ $\\_$ $\\rightarrow$\n $\\enspace$ $\\enspace$ if $\\mi{suspend}_\\texttt{weight}$ then $\\{ x \\}$ else $\\varnothing$\n $\\enspace$ | $\\_ \\rightarrow$ $\\varnothing$\n \\end{lstlisting}\n \\end{multicols}\n \\end{minipage}\n\\end{algorithm}%\nTo formalize the set of sound solutions for the $S_x$ and $\\mi{suspend}_x$, we generate \\emph{constraints} $\\textbf{\\tsf{c}} \\in R$ for programs (for a formal definition of constraints, see Appendix~\\ref{sec:cfaalg}).\nAlgorithm~\\ref{alg:gencstr} formalizes the necessary constraints for programs $\\textbf{\\upshape\\tsf{t}} \\in T_\\textrm{ANF}$ with a function \\textsc{generateConstraints} that recursively traverses the program $\\textbf{\\upshape\\tsf{t}}$ to generate a set of constraints.\nDue to ANF, there are only two cases in the top match (line~\\ref{line:topmatch}).\nVariables generate no constraints, and the important case is for \\texttt{let} expressions at lines~\\ref{line:beginlet}--\\ref{line:genweight}.\nThe algorithm makes use of an auxiliary function \\textsc{name} (line~\\ref{line:func_name}) that determines the name of an ANF expression, and a function \\textsc{suspendNames} (line~\\ref{line:func_suspendNames}) that determines the names of all top-level expressions within an expression that may suspend (namely, applications, \\texttt{if} expressions, and \\texttt{assume} and\/or \\texttt{weight}).\n\nWe next illustrate and motivate the generated constraints by considering the set of constraints $\\textsc{generateConstraints}(\\texample)$, where $\\texample$ is the program in Figure~\\ref{fig:runninganf}.\nMany constraints are standard, and we therefore focus on the new suspension constraints introduced as part of this paper.\nIn particular, the challenge is to correctly capture the flow of suspension requirements across function applications and higher-order functions.\nFirst, we see that defining aliases (line~\\ref{line:genvar}) generates constraints of the form $S_y \\subseteq S_x$, that constants introduce \\texttt{const} abstract values (e.g., $\\texttt{const}_{t_6} 1 \\in S_{t_6}$), and that \\texttt{assume} and \\texttt{weight} introduce suspension requirements, e.g. $\\mi{suspend}_{w_1}$ (shorthand for $\\mi{suspend}_{w_1} = \\textrm{true}{}$).\n\nFirst, we consider the constraints generated for $\\lambda \\mathit{obs}.$ (line~\\ref{line:anflam} in Figure~\\ref{fig:runninganf}) through the case at lines~\\ref{line:genabsb}-\\ref{line:genabse} in Algorithm~\\ref{alg:gencstr}.\nFor the sake of the example, we treat the unexpanded \\texttt{let rec} as an ordinary \\texttt{let} (the analysis result is unaffected).\nOmitting the recursively generated constraints for the abstraction body, the generated constraints are\n\\begin{equation}\n \\{ \\lambda \\mathit{obs}. \\, t_8 \\in S_\\mathit{iter}\\} \\cup \\{ \\mi{suspend}_n \\Rightarrow \\mi{suspend}_\\mathit{obs} \\mid n \\in \\{ t_7, t_8\\}\n \\}.\n\\end{equation}\nThe first constraint is standard and states that the abstract value $\\lambda \\mathit{obs}. \\, t_8$ flows to $S_\\mathit{iter}$ as the variable naming the $\\lambda \\mathit{obs}$ expression is $t_8$ at line~\\ref{line:obsreturn} in Figure~\\ref{fig:runninganf} (difficult to notice due to the column breaks).\nThe remaining constraints are new and sets up the flow of suspension requirements.\nSpecifically, the abstraction $\\mathit{obs}$ itself requires suspension if any expression bound by a top-level \\texttt{let} in its body requires suspension.\nFor efficiency, we only set up dependencies for expressions that may suspend (formalized by \\textsc{suspendNames} in Algorithm~\\ref{alg:gencstr}).\nNote here that we do not add the constraint $\\mi{suspend}_{w_1} \\Rightarrow \\mi{suspend}_\\mathit{obs}$, as $w_1$ is not at top-level in the body of $\\mathit{obs}$.\nInstead, we later add the constraint $\\mi{suspend}_{w_1} \\Rightarrow \\mi{suspend}_{t_8}$, and $\\mi{suspend}_{w_1} \\Rightarrow \\mi{suspend}_\\mathit{obs}$ follows by transitivity.\n\nThe constraints generated for the \\texttt{if} bound to $t_8$ at line~\\ref{line:if} through the case at lines~\\ref{line:genifb}-\\ref{line:genife} in Algorithm~\\ref{alg:gencstr} are (again, omitting recursively generated constraints)\n\\begin{equation}\n \\begin{aligned}\n &\\{ S_{t_9} \\subseteq S_{t_8}, S_{t_{17}} \\subseteq S_{t_8}\\} \\\\\n &\\hspace{10mm}\\cup \\{ \\mi{suspend}_n \\Rightarrow \\mi{suspend}_{t_8} \\mid n \\in \\{ t_{11}, t_{13}, t_{14}, w_1, t_{16}, t_{17}\\} \\}.\n \\end{aligned}\n\\end{equation}\nThe first two constraints are standard, and state that abstract values in the results of both branches flow to the result $S_{t_8}$.\nThe last set of constraints is new and very similar to the suspension constraints for abstractions.\nThe constraints capture that all expressions at top-level in both branches that require suspension also cause $t_8$ to require suspension.\n\nThe constraints for applications are, naturally, the most complex.\nConsider the application at line~\\ref{line:iter1} in Figure~\\ref{fig:runninganf}.\nThe generated constraints through the case at lines~\\ref{line:genappb}-\\ref{line:genappe} in Algorithm~\\ref{alg:gencstr} are\n\\begin{equation}\\label{eq:appcstrs}\n \\begin{aligned}\n \\{ \\enspace &\\forall z \\forall y \\enspace \\lambda z. y \\in S_{\\mathit{iter}} \\Rightarrow (S_{t_{16}} \\subseteq S_z) \\land (S_y \\subseteq S_{t_{17}}),\\\\\n &\\forall y \\forall n \\enspace \\texttt{const}_y \\, n \\in S_\\mathit{iter} \\land n > 1 \\Rightarrow \\texttt{const}_y \\, n-1 \\in S_{t_{17}},\\\\\n &\\forall y \\enspace \\lambda y. \\_ \\in S_{\\mathit{iter}} \\Rightarrow (\\mi{suspend}_y \\Rightarrow \\mi{suspend}_{t_{17}}),\\\\\n &\\forall y \\enspace \\texttt{const}_y \\enspace \\_ \\in S_{\\mathit{iter}} \\Rightarrow (\\mi{suspend}_y \\Rightarrow \\mi{suspend}_{t_{17}}),\\\\\n &\\mi{suspend}_{t_{17}} \\Rightarrow (\\forall y \\enspace \\lambda y. \\_ \\in S_{\\mathit{iter}} \\Rightarrow \\mi{suspend}_y) \\\\\n & \\hspace{25mm}\\land (\\forall y \\enspace \\texttt{const}_y \\enspace \\_ \\in S_{\\mathit{iter}} \\Rightarrow \\mi{suspend}_y) \\enspace \\}.\n \\end{aligned}\n\\end{equation}\nThe first two constraints are standard and state how abstract values flow as a result of applications.\nThe last three constraints are new and relate to suspension.\nThe third and fourth constraints state that if an abstraction or intrinsic requiring suspension flows to $\\mathit{iter}$, the result $t_{17}$ of the application also requires suspension.\nThe fifth constraint states that if the result $t_{17}$ requires suspension, then \\emph{all} abstractions and constants flowing to $\\mathit{iter}$ require suspension.\nThis last constraint is not strictly required to later prove the soundness of the analysis in Theorem~\\ref{thm:main}, but, as we will see in Section~\\ref{sec:cps}, it is required for the selective CPS transformation.\n\nWe find a solution to the constraints through Algorithm~\\ref{alg:flow} in Appendix~\\ref{sec:cfaalg}.\nThe algorithm propagates abstract values according the constraints until fixpoint, and is fairly standard.\nHowever, we extend the algorithm to support the new suspension constraints.\nSpecifically, Algorithm~\\ref{alg:flow} defines a function \\lstinline[style=alg,basicstyle=\\sffamily]!$\\textsc{analyzeSuspend}$: $T_\\textrm{ANF} \\rightarrow ((X \\rightarrow \\mathcal P (A)) \\times \\mathcal P(X))$!.\nThe function returns a \\linebreak map $\\textsf{data}: X \\rightarrow \\mathcal P (A)$ that assigns sets of abstract values to all $S_x$ and a set $\\textsf{suspend}: \\mathcal P(X)$ that assigns $\\mi{suspend}_x = \\textrm{true}$ iff $x \\in \\textsf{suspend}$.\nImportantly, the assignments to $S_x$ and $\\textsf{suspend}_x$ satisfy all generated constraints.\nTo illustrate the algorithm, here are the analysis results $\\textsc{analyzeSuspend}(\\texample)$:\n\\begin{equation}\\label{eq:analyzerunning}\n \\begin{gathered}\n \\begin{gathered}\n S_\\mathit{iter} = \\{ \\lambda \\mathit{obs}. t_8 \\} \\quad\n S_{t_6} = \\{ \\texttt{const}_{t_6} 1 \\} \\quad\n S_{t_{10}} = \\{ \\texttt{const}_{t_{10}} 2 \\} \\\\\n S_{t_{11}} = \\{ \\texttt{const}_{t_{10}} 1 \\} \\quad\n S_{t_{12}} = \\{ \\texttt{const}_{t_{12}} 1 \\} \\quad\n S_{t_{15}} = \\{ \\texttt{const}_{t_{15}} 1 \\} \\\\\n S_n = \\varnothing \\mid \\text{all other $n \\in X$}\n \\end{gathered} \\\\\n \\begin{aligned}\n \\mi{suspend}_n &= \\textrm{true}{} \\mid n \\in \\{ \\mathit{obs}, w_1, t_8, t_{17}, t_{22} \\} \\\\\n \\mi{suspend}_n &= \\textrm{false}{} \\mid \\text{all other $n \\in X$}.\n \\end{aligned}\n \\end{gathered}\n\\end{equation}\nThe above results confirm our earlier reasoning: the expressions labeled by $\\mathit{obs}$, $w_1$, $t_8$, $t_{17}$, and $t_{22}$ may require suspension.\n\nWe now consider the soundness of the analysis.\nFirst, the soundness of 0-CFA is well established (see, e.g., \\citet{nielson1999principles}) and extends to our new constraints, and we take the following lemma to hold without proof.\n\\begin{lemma}[0-CFA soundness]\\label{lemma:cfa}\n For every $\\textbf{\\upshape\\tsf{t}} \\in T_\\textrm{ANF}$, the solution given by\n $\n \\textsc{analyzeSuspend}(\\textbf{\\upshape\\tsf{t}})\n $\n for $S_x$ and $\\mi{suspend}_x$, $x \\in X$, satisfies the constraints $ \\textsc{generateConstraints}(\\textbf{\\upshape\\tsf{t}})$.\n\\end{lemma}\n\\noindent\nTheorem~\\ref{thm:main} now captures the soundness of the constraints themselves.\n\\begin{theorem}[Suspension analysis soundness]\\label{thm:main}\n Let $\\textbf{\\upshape\\tsf{t}} \\in T_\\textrm{ANF}$, $s \\in S$, $u \\in \\{\\textrm{false}{},\\textrm{true}{}\\}$,\n $w \\in \\mathbb{R}$, and $\\textbf{\\upshape\\tsf{v}} \\in V$ such that\n $\n \\varnothing \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}.\n $\n Now, let $S_x$ and $\\mi{suspend}_x$ for $x \\in X$ according to $\\textsc{analyzeSuspend}(\\textbf{\\upshape\\tsf{t}})$.\n For every subderivation $(\\rho \\vdash \\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\texttt{ in } \\textbf{\\upshape\\tsf{t}}_2 \\sem{u_1 \\lor u_2}{s_1 \\concat s_2}{w_1 \\cdot w_2} \\textbf{\\upshape\\tsf{v}}')$ of $(\\varnothing \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}})$, $u_1 = \\textrm{true}{}$ implies $\\mi{suspend}_x = \\textrm{true}{}$.\n\\end{theorem}\n\\begin{proof}\n Follows directly by Lemma~\\ref{lemma:suslemma} in Appendix~\\ref{sec:proof} with $\\rho = \\varnothing$.\n The proof uses Lemma~\\ref{lemma:cfa} and structural induction over the derivation $\\varnothing \\vdash \\textbf{\\upshape\\tsf{t}} \\sem{u}{s}{w} \\textbf{\\upshape\\tsf{v}}$.\n\\end{proof}\n\\noindent\nThat is, if a subderivation of $\\textbf{\\upshape\\tsf{t}}$ labeled by a name $x$ requires suspension, then $\\mi{suspend}_x = \\textrm{true}$ and the analysis correctly identifies the possibility of suspension.\nNote that the analysis is sound but conservative (i.e. incomplete), as the reverse does not hold: if $\\mi{suspend}_x = true$, then the subderivation of the expression labeled by $x$ does not necessarily require suspension.\n\nNext, we use the suspension analysis results to selectively CPS transform programs.\n\n\\section{Selective CPS Transformation}\\label{sec:cps}\n\\begin{algorithm}[tb]\n \\renewcommand{\\enspace}{\\hphantom{|}}\n \\caption{%\n Selective continuation-passing style transformation.\n The type $T^?$ is the option type over terms. We use the notation $\\varnothing$ for the empty option value.\n We write the functional-style pseudocode for the algorithm itself in sans serif font to distinguish it from terms in $T$.\n }\\label{alg:cps}\n \\raggedright\n \\lstinline[style=alg]!function $\\textsc{cps}$(vars, $\\textbf{\\upshape\\tsf{t}}$): $\\mathcal P(X) \\times T_\\textrm{ANF} \\rightarrow T^+$ =!\\\\\n \\hspace{3mm}\n \\begin{minipage}{0.96\\textwidth}\n \\begin{multicols}{2}\n \\begin{lstlisting}[\n style=alg,\n showlines=true,\n basicstyle=\\sffamily\\scriptsize,\n ]\nreturn $\\textsc{cps}'$($\\varnothing$, $\\textbf{\\upshape\\tsf{t}}$)$\\label{line:cps:init}$\n\nfunction $\\textsc{cps}'$(cont,$\\textbf{\\upshape\\tsf{t}}$): $T^? \\times T_\\textrm{ANF} \\rightarrow T^+$ =\n match $\\textbf{\\upshape\\tsf{t}}$ with$\\label{line:cps:topmatch}$\n | $x \\rightarrow$ if cont $= \\varnothing$ then $\\textbf{\\upshape\\tsf{t}}$ else cont $\\textbf{\\upshape\\tsf{t}}$$\\label{line:cps:casevar}$\n | $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2 \\rightarrow$$\\label{line:cps:beginlet}$\n $\\enspace$ let $\\textbf{\\upshape\\tsf{t}}_2' = \\textsc{cps}'(\\textsf{cont},\\textbf{\\upshape\\tsf{t}}_2)$ in\n $\\enspace$ match $\\textbf{\\upshape\\tsf{t}}_1$ with\n $\\enspace$ | $y \\rightarrow$ $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ | $c \\rightarrow$ $\\texttt{let } x =$\n (if $x \\in \\textsf{vars}$ then $c_\\textrm{cps}$ else $c$) $\\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ | $\\lambda y. \\enspace \\textbf{\\upshape\\tsf{t}}_b \\rightarrow$$\\label{line:cps:abs}$\n $\\enspace$ $\\enspace$ let $\\textbf{\\upshape\\tsf{t}}_1'$ = if $y \\in \\textsf{vars}$\n $\\enspace$ $\\enspace$ $\\enspace$ then $\\lambda k. \\lambda y. \\enspace \\textsc{cps}'(k,\\textbf{\\upshape\\tsf{t}}_b)$\n $\\enspace$ $\\enspace$ $\\enspace$ else $\\lambda y. \\enspace \\textsc{cps}'(\\varnothing,\\textbf{\\upshape\\tsf{t}}_b)$\n $\\enspace$ $\\enspace$ in\n $\\enspace$ $\\enspace$ $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1' \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ | $\\mathit{lhs} \\enspace \\mathit{rhs} \\rightarrow$$\\label{line:cps:app}$\n $\\enspace$ $\\enspace$ if $x \\in \\textsf{vars}$ then\n $\\enspace$ $\\enspace$ $\\enspace$ if $\\textsc{tailCall}(\\textbf{\\upshape\\tsf{t}}) \\land \\textsf{cont} \\neq \\varnothing$\n $\\enspace$ $\\enspace$ $\\enspace$ then $\\mathit{lhs}$ cont $\\mathit{rhs}$\n $\\enspace$ $\\enspace$ $\\enspace$ else $\\mathit{lhs}$ $(\\lambda x. \\textbf{\\upshape\\tsf{t}}_2')$ $\\mathit{rhs}$\n $\\enspace$ $\\enspace$ else $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n\n\n\n (*@ \\columnbreak @*)\n $\\enspace$ | $\\texttt{if } y \\texttt{ then } \\textbf{\\upshape\\tsf{t}}_t \\texttt{ else } \\textbf{\\upshape\\tsf{t}}_e \\rightarrow$$\\label{line:cps:if}$\n $\\enspace$ $\\enspace$ if $x \\in \\textsf{vars}$ then\n $\\enspace$ $\\enspace$ $\\enspace$ if $\\textsc{tailCall}(\\textbf{\\upshape\\tsf{t}}) \\land \\textsf{cont} \\neq \\varnothing$ then\n $\\enspace$ $\\enspace$ $\\enspace$ $\\enspace$ $\\texttt{if } y \\texttt{ then } \\textsc{cps}'(\\textsf{cont},\\textbf{\\upshape\\tsf{t}}_t)$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\enspace$ $\\texttt{else } \\textsc{cps}'(\\textsf{cont},\\textbf{\\upshape\\tsf{t}}_e)$\n $\\enspace$ $\\enspace$ $\\enspace$ else\n $\\enspace$ $\\enspace$ $\\enspace$ $\\enspace$ $\\texttt{let } k = \\lambda x. \\textbf{\\upshape\\tsf{t}}_2' \\enspace \\texttt{in} \\enspace$\n $\\enspace$ $\\enspace$ $\\enspace$ $\\enspace$ $\\texttt{if } y \\texttt{ then } \\textsc{cps}'(k,\\textbf{\\upshape\\tsf{t}}_t) \\texttt{ else } \\textsc{cps}'(k,\\textbf{\\upshape\\tsf{t}}_e)$\n $\\enspace$ $\\enspace$ else $\\texttt{let } x = \\texttt{if } y \\texttt{ then } \\textsc{cps}'(\\varnothing,\\textbf{\\upshape\\tsf{t}}_t)$\n $\\enspace$ $\\enspace$ $\\hspace{15.5mm}$ $\\texttt{else } \\textsc{cps}'(\\varnothing,\\textbf{\\upshape\\tsf{t}}_e) \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ | $\\texttt{assume } y \\rightarrow$ $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ $\\enspace$ if $x \\in \\textsf{vars}$ then\n $\\enspace$ $\\enspace$ $\\enspace$ if $\\textsc{tailCall}(\\textbf{\\upshape\\tsf{t}})$\n $\\enspace$ $\\enspace$ $\\enspace$ then $\\Susassume$($y$, cont)\n $\\enspace$ $\\enspace$ $\\enspace$ else $\\Susassume$($y$,$\\lambda x. \\textsc{cps}'(\\textsf{cont},\\textbf{\\upshape\\tsf{t}}_2)$)\n $\\enspace$ $\\enspace$ else $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$\n $\\enspace$ | $\\texttt{weight } y \\rightarrow$ $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$$\\label{line:cps:weight}$\n $\\enspace$ $\\enspace$ if $x \\in \\textsf{vars}$ then\n $\\enspace$ $\\enspace$ $\\enspace$ if $\\textsc{tailCall}(\\textbf{\\upshape\\tsf{t}})$\n $\\enspace$ $\\enspace$ $\\enspace$ then $\\Susweight$($y$, cont)\n $\\enspace$ $\\enspace$ $\\enspace$ else $\\Susweight$($y$,$\\lambda x. \\textsc{cps}'(\\textsf{cont},\\textbf{\\upshape\\tsf{t}}_2)$)\n $\\enspace$ $\\enspace$ else $\\texttt{let } x = \\textbf{\\upshape\\tsf{t}}_1 \\enspace \\texttt{in} \\enspace \\textbf{\\upshape\\tsf{t}}_2'$$\\label{line:cps:endlet}$\n\nfunction $\\textsc{tailCall}$($\\textbf{\\upshape\\tsf{t}}$): $T_\\textrm{ANF} \\rightarrow \\{\\textrm{false}{},\\textrm{true}{}\\}$ =\n match $\\textbf{\\upshape\\tsf{t}}$ with\n | $\\texttt{let } x = \\_ \\enspace \\texttt{in} \\enspace x \\rightarrow \\textrm{true}{}$\n | $\\_ \\rightarrow \\textrm{false}{}$\n \\end{lstlisting}\n \\end{multicols}\n \\end{minipage}\n\\end{algorithm}\n\\begin{figure}[tb]\n \\centering\n \\lstset{%\n basicstyle=\\ttfamily\\scriptsize,\n showlines=true,\n framexleftmargin=-2pt,\n xleftmargin=2em,\n }%\n \\begin{multicols}{2}\n \\begin{lstlisting}[style=ppl]\nlet $t_1$ = $2$ in\nlet $t_2$ = $2$ in\nlet $t_3$ = $\\textrm{Beta}$ in\nlet $t_4$ = $t_3$ $t_1$ in\nlet $t_5$ = $t_4$ $t_2$ in\nlet $a_1$ = assume $t_5$ in\nlet rec $\\mathit{iter}$ = $\\lambda k.$ $\\lambda \\mathit{obs}.$\n let $t_6$ = $\\mathit{null}$ in\n let $t_7$ = $t_6$ $\\mathit{obs}$ in\n if $t_7$ then\n let $t_9$ = $()$ in\n $t_9$\n else\n let $t_{10}$ = $f_\\textrm{Bernoulli}$ in\n let $t_{11}$ = $t_{10}$ $a_1$ in\n let $t_{12}$ = $\\mathit{head}$ in\n let $t_{13}$ = $t_{12}$ $\\mathit{obs}$ in\n let $t_{14}$ = $t_{11}$ $t_{13}$ in\n $\\Susweight($$t_{14}$,\n $\\lambda \\_$.\n let $t_{15}$ = $\\mathit{tail}$ in\n let $t_{16}$ = $t_{15}$ $\\mathit{obs}$ in\n $\\mathit{iter}$ $k$ $t_{16}$$)$\nin\nlet $t_{18}$ = $\\textrm{true}{}$ in\nlet $t_{19}$ = $\\textrm{false}{}$ in\nlet $t_{20}$ = $\\textrm{true}{}$ in\nlet $t_{21}$ = $\\textrm{true}{}$ in\nlet $t_{22}$ = $[t_{21}$,$t_{20}$,$t_{19}$,$t_{18}]$ in\nlet $k'$ = $\\lambda \\_.$ $a_1$ in\n$\\mathit{iter}$ $k'$ $t_{22}$\n \\end{lstlisting}\n \\end{multicols}\n\n \\caption{\n The running example from Figure~\\ref{fig:runninganf} after selective CPS transformation.\n The program is semantically equivalent to Figure~\\ref{fig:running:weight}.\n }\n \\label{fig:runningcps}\n\\end{figure}\n\\noindent\nThis section presents the second technical contribution: the selective CPS transformation.\nThe transformations themselves are standard, and the challenge with selective CPS is instead to correctly use the suspension analysis results for a selective transformation.\n\nAlgorithm~\\ref{alg:cps} presents the full algorithm.\nUsing terms in ANF as input significantly helps reduce the algorithm's complexity.\nThe main function \\textsc{cps} takes as input a set $\\textsf{vars}: \\mathcal P(X)$, indicating which expressions to CPS transform, and a program $\\textbf{\\upshape\\tsf{t}} \\in T_\\textrm{ANF}$ to transform.\nIt is the new $\\textsf{vars}$ argument that separates the transformation from a standard CPS transformation.\nFor the purposes of this paper, we always use $\\textsf{vars} = \\{ x \\mid \\mi{suspend}_x = \\textrm{true}{} \\}$, where the $\\mi{suspend}_x$ come from $\\textsc{analyzeSuspend}(\\textbf{\\upshape\\tsf{t}})$.\nOne could also use $\\textsf{vars} = X$ for a standard full CPS transformation (e.g., Fig~\\ref{fig:running:full}), or some other set $\\textsf{vars}$ for other application domains.\nThe value returned from the \\textsc{cps} function is a (non-ANF) term of the type $T^+$.\nThe helper function $\\textsc{cps}'$, initially called at line~\\ref{line:cps:init}, takes as input an optional continuation term $\\textsf{cont}$, indicating the continuation to apply in tail position.\nInitially, this continuation term is empty (denoted $\\varnothing$), which indicates that there is no continuation.\nUsing an \\emph{optional} continuation is new, and specific to the selective CPS transformation.\nSimilarly to Algorithm~\\ref{alg:gencstr}, the top-level match at line~\\ref{line:cps:topmatch} has two cases: a simple case for variables (line~\\ref{line:cps:casevar}) and a complex case for \\texttt{let} expressions (lines \\ref{line:cps:beginlet}--\\ref{line:cps:endlet}).\nTo enable optimization of tail calls, the auxiliary function \\textsc{tailCall} indicates whether or not an ANF expression is a tail call (i.e., of the form \\texttt{let $x$ = \\textbf{\\upshape\\tsf{t}}' in $x$}).\n\nWe now illustrate Algorithm~\\ref{alg:cps} by computing $\\textsc{cps}(\\varsexample, \\texample)$, where $\\varsexample = \\{ \\mathit{obs}, w_1, t_8, t_{17}, t_{22} \\}$ is from~\\eqref{eq:analyzerunning}, and $\\texample$ is from Figure~\\ref{fig:runninganf}.\nFigure~\\ref{fig:runningcps} presents the final transformed result.\nFirst, we note that the transformation does not change expressions not labeled by a name in $\\varsexample$, as they do not require suspension.\nIn the following, we therefore focus only on the transformed expressions.\n\nFirst, consider the abstraction $\\mathit{obs}$ defined at line~\\ref{line:anflam} in Figure~\\ref{fig:runninganf}, handled by the case at line~\\ref{line:cps:abs} in Algorithm~\\ref{alg:cps}.\nAs $\\mathit{obs} \\in \\varsexample$, we apply the standard CPS transformation for abstractions: add a continuation parameter to the abstraction and recursively transform the body with this continuation.\nNext, consider the transformation of the \\texttt{weight} expression $w_1$ at line~\\ref{line:weight} in Figure~\\ref{fig:runninganf}, handled by the case at line~\\ref{line:cps:weight} in Algorithm~\\ref{alg:cps}.\nThe expression is not at tail position, so we build a new continuation containing the subsequent \\texttt{let} expressions, recursively transform the body of the continuation, and then wrap the end result in a Suspension object.\nThe \\texttt{if} expression $t_8$ at line~\\ref{line:if} in Figure~\\ref{fig:runninganf}, handled by the case at line~\\ref{line:cps:if} in Algorithm~\\ref{alg:cps}, is in tail position (it is directly followed by returning $t_8$).\nConsequently, we transform both branches recursively.\nFinally, we have the applications $t_{17}$ and $t_{22}$ at lines~\\ref{line:iter1} and~\\ref{line:iter2} in Figure~\\ref{fig:runninganf}, handled by the case at line~\\ref{line:cps:app} in Algorithm~\\ref{alg:cps}.\nThe application $t_{17}$ is at tail position, and we transform it by adding the current continuation as an argument.\nThe application at $t_{22}$ is not at tail position, so we construct a continuation $k'$ that returns the final value $a_1$ (line~\\ref{line:a1} in Figure~\\ref{fig:runninganf}), and then add it as an argument to the application.\n\nIt is not automatically guaranteed that Algorithm~\\ref{alg:cps} produces a correct result.\nSpecifically, for all applications $\\mathit{lhs}$ $\\mathit{rhs}$, we must ensure that (i) if we CPS transform the application, we must also CPS transform \\emph{all} possible abstractions that can occur at $\\mathit{lhs}$, and (ii) if we do \\emph{not} CPS transform the application, we must \\emph{not} CPS transform any abstraction that can occur at $\\mathit{lhs}$.\nWe control this through the argument \\textsf{vars}.\nIn particular, assigning \\textsf{vars} according to the suspension analysis produces a correct result.\nTo see this, consider the application constraints at lines~\\ref{line:genappb}--\\ref{line:genappe} in Algorithm~\\ref{alg:gencstr} again, and note that if any abstraction or intrinsic operation that requires suspension occur at $\\mathit{lhs}$, $\\mi{suspend}_x = \\textrm{true}{}$.\nFurthermore, the last application constraint ensures that if $\\mi{suspend}_x = \\textrm{true}{}$, then \\emph{all} abstractions and intrinsic operations that occur at $\\mathit{lhs}$ require suspension.\nConsequently, for all $\\lambda y. \\, \\_$ and $const_y \\, \\_$, either all $\\mi{suspend}_y = \\textrm{true}{}$ or all $\\mi{suspend}_y = \\textrm{false}{}$.\n\n\\section{Implementation}\\label{sec:implementation}\n\\begin{figure}[tb]\n \\centering\n \\includegraphics[width=0.9\\textwidth]{figs\/cppl-overview.pdf}\n \\caption{Overview of the Miking CorePPL compiler implementation. We divide the overall compiler into two parts, (i) \\emph{suspension analysis and selective CPS} (Section~\\ref{sec:susimpl}), and (ii) \\emph{inference problem extraction} (Section~\\ref{sec:extractimpl}). The figure depicts artifacts as gray rectangular boxes and transformation units and libraries as blue rounded boxes. Note how the \\emph{inference extractors} transformation separates the program into two different paths that are combined again after the inference-specific compilation. The white inheritance arrows (pointing to \\emph{suspension analysis} and \\emph{selective CPS transformations}) mean that these libraries are used within the inference-specific compiler transformation. }\n \\label{fig:cppl-overview}\n\\end{figure}\n\nWe implement the suspension analysis and selective CPS transformation in Miking CorePPL~\\citep{lunden2022compiling}, a core PPL implemented in the domain-specific language construction framework Miking~\\citep{broman2019vision}.\nFigure~\\ref{fig:cppl-overview} presents the organization of the CorePPL compiler.\nThe input is a CorePPL program that may contain many inference problems and applications of inference algorithms, similar to WebPPL and Anglican.\nThe output is an executable produced by one of the Miking backend compilers.\nSection~\\ref{sec:susimpl} gives the details of the suspension analysis and selective CPS implementations, and in particular the differences compared to the core calculus in Section~\\ref{sec:ppl}.\nSection~\\ref{sec:extractimpl} presents the inference extractor and its operation combined with selective CPS.\nThe suspension analysis, selective CPS transformation, and inference extraction implementations consist of roughly 1500 lines of code (a contribution in this paper).\nThe code is available on GitHub~\\citep{mikingdpplgithub}.\n\n\\subsection{Suspension Analysis and Selective CPS}\\label{sec:susimpl}\nMiking CorePPL extends the abstract syntax in Definition~\\ref{def:terms} with standard functional language data structures and features such as algebraic data types (records, tuples, and variants), lists, and pattern matching.\nThe suspension analysis and selective CPS implementations in Miking CorePPL extend Algorithm~\\ref{alg:gencstr} and Algorithm~\\ref{alg:cps} to support these language features.\nFurthermore, compared to $\\mi{suspend}_\\texttt{weight}$ and $\\mi{suspend}_\\texttt{assume}$ in Figure~\\ref{fig:semantics}, the implementation allows arbitrary configuration of suspension sources.\nIn particular, the implementation uses this arbitrary configuration together with the alignment analysis by \\citet{lunden2023automatic}.\nThis combination allows selectively CPS transforming to suspend at a subset of \\texttt{assume}s or \\texttt{weight}s for aligned versions of SMC and MCMC inference algorithms.\n\nMiking CorePPL also includes a framework for inference algorithm implementation.\nSpecifically, to implement new inference algorithms, users implement an \\emph{inference-specific compiler} and \\emph{inference-specific runtime}.\nFigure~\\ref{fig:cppl-overview} illustrates the different compilers and runtimes.\nEach inference-specific compiler applies the suspension analysis and selective CPS transformation to suit the inference algorithm's particular suspension requirements.\n\nNext, we show how Miking CorePPL handles programs containing many inference problems solved with different inference algorithms.\n\n\\subsection{Inference Problem Extraction}\\label{sec:extractimpl}\nFigure~\\ref{fig:cppl-overview} includes the inference extraction compiler procedure.\nFirst, the compiler applies an inference extractor to the input program.\nThe result is a set of inference problems and a main program containing remaining glue code.\nSecond, the compiler applies inference-specific compilers to each inference problem.\nFinally, the compiler combines the main program and the compiled inference problems with inference-specific runtimes and supplies the result to a backend compiler.\n\n\\begin{figure}[tb]\n \\centering\n \\lstset{%\n basicstyle=\\ttfamily\\scriptsize,\n escapeinside={--}{\\^^M},\n showlines=true,\n framexleftmargin=-2pt,\n xleftmargin=2em,\n }%\n \\begin{subfigure}{\\textwidth}\n \\begin{multicols}{2}\n \\lstinputlisting[language=CorePPL]{code\/infer.mc}\n \\end{multicols}\n \\caption{Miking CorePPL program.}\n \\label{fig:extract-ex}\n \\end{subfigure}\\\\[2mm]\n \\begin{subfigure}{.45\\textwidth}\n \\lstinputlisting[language=CorePPL]{code\/infer-ext1.mc}\n \\caption{Extracted inference problem from line~\\ref{fig:extract-ex:infer1} in (a).}\n \\label{fig:extract-ex-infer1}\n \\end{subfigure}\n \\hspace{7mm}\n \\begin{subfigure}{.47\\textwidth}\n \\lstinputlisting[language=CorePPL]{code\/infer-ext2.mc}\n \\caption{Extracted inference problem from line~\\ref{fig:extract-ex:infer2} in (a).}\n \\label{fig:extract-ex-infer2}\n \\end{subfigure}\n \\caption{%\n Example Miking CorePPL program in (a) with two non-trivial uses of \\texttt{infer}.\n Figures (b) and (c) show the extracted and selectively CPS-transformed inference problems at lines~\\ref{fig:extract-ex:infer1} and \\ref{fig:extract-ex:infer2} in (a), respectively.\n The compiler handles the free variables \\texttt{d} and \\texttt{y} in (c) in a later stage.\n }\n \\label{fig:extract}\n\\end{figure}\n\nTo illustrate the extraction approach in more detail, consider the example in Figure~\\ref{fig:extract-ex}.\nWe define a function \\texttt{m} that constructs a minimal inference problem on lines~\\ref{fig:extract-ex:m1}--\\ref{fig:extract-ex:m2}, using a single call to \\texttt{assume} and a single call to \\texttt{observe} (modifying the execution weight similar to \\texttt{weight}).\nThe function takes an initial probability distribution \\texttt{d} and a data point \\texttt{y} as input.\nWe apply aligned lightweight MCMC inference for the inference problem through the \\texttt{infer} construct on lines~\\ref{fig:extract-ex:d1}--\\ref{fig:extract-ex:d1end}.\nThe first argument to \\texttt{infer} gives the inference algorithm configuration, and the second argument the inference problem.\nInference problems are thunks (i.e., functions with a dummy unit argument).\nIn this case, we construct the inference problem thunk by an application of \\texttt{m} with a uniform initial distribution and data point $1.0$.\nThe inference result \\texttt{d0} is another probability distribution, and we use it as the first initial distribution in the recursive \\texttt{repeat} function (lines~\\ref{fig:extract-ex:rep1}--\\ref{fig:extract-ex:rep2}).\nThis function repeatedly performs inference using the SMC bootstrap particle filter (lines~\\ref{fig:extract-ex:d2}--\\ref{fig:extract-ex:d2end}), again using the function \\texttt{m} to construct the sequence of inference problems.\nEach \\texttt{infer} application uses the result distribution from the previous iteration as the initial distribution and consumes data points from the \\texttt{data} sequence.\nWe extract and print the samples from the final result distribution \\texttt{d1} at lines~\\ref{fig:extract-ex:dist-print1}--\\ref{fig:extract-ex:dist-print2}.\nA limitation with the current extraction approach is that we do not (yet) support nested \\texttt{infer}s.\n\nA key challenge in the compiler design concerns how to handle different inference algorithms within one probabilistic program.\nIn particular, the inference algorithms require different selective CPS transformations, applied to different parts of the code.\nTo allow the separate handling of inference algorithms, we apply the extraction approach by~\\citet{hummelgren2022expression} on the \\texttt{infer} applications, producing separate inference problems for each occurrence of \\texttt{infer}. Although the compiler extension mostly concerns rather comprehensive engineering work, special care must be taken to handle the non-trivial problem of name bindings when transforming and combining different code entities together.\nFor instance, note how the compiler must selectively CPS transform Figure~\\ref{fig:extract-ex-infer1} to suspend at \\texttt{assume} (required by MCMC) and selectively CPS transform Figure~\\ref{fig:extract-ex-infer2} to suspend at \\texttt{observe} (required by SMC). We have designed a robust and modular solution, where it is possible to easily add new inference algorithms without worrying about name conflicts.\n\n\\section{Evaluation}\\label{sec:evaluation}\nThis section presents the evaluation of the suspension analysis and selective CPS implementations in Section~\\ref{sec:implementation}.\nOur main claims are that (i) the approach of selective CPS significantly improves performance compared to traditional full CPS, and (ii) that this holds for a significant set of inference algorithms, evaluated on realistic inference problems.\nWe use four PPL models and corresponding data sets from the Miking benchmarks repository, available on GitHub~\\citep{mikingbenchgithub}.\nThe models are: constant rate birth-death (CRBD) in Section~\\ref{sec:expcrbd}, cladogenetic diversification rate shift (ClaDS) in Section~\\ref{sec:expclads}, latent Dirichlet allocation (LDA) in Section~\\ref{sec:explda}, and vector-borne disease (VBD) in Section~\\ref{sec:expvbd}.\nAll models are significant and actively used in different research areas:\nCRBD and ClaDS in evolutionary biology and phylogenetics~\\citep{nee2006birth,ronquist2021universal, maliet2019model}, LDA in topic modeling~\\citep{blei2003latent}, and VBD in epidemiology~\\citep{funk2016comparative, murray2018delayed}.\nIn addition to the Miking CorePPL models from the Miking benchmarks, we also implement CRBD in WebPPL and Anglican.\n\nWe add a number of popular inference algorithms in Miking CorePPL with support for selective CPS.\nThe first is standard likelihood weighting (LW), as introduced in Section~\\ref{sec:motivating}.\nLW does not strictly require CPS, but we implement it with suspensions at \\texttt{weight} to highlight the difference between no CPS, selective CPS, and full CPS.\nIn particular, LW gives a good direct measure of CPS overhead as the algorithm simply executes programs many times.\nSuspending at \\texttt{weight} can also be useful in LW to stop executions with weight 0 (i.e., useless samples) early.\nHowever, we do not use early stopping to isolate the effect CPS has on execution time.\nNext, we add the bootstrap particle filter (BPF) and alive particle filter (APF).\nBoth are SMC algorithms that suspend at \\texttt{weight} in order to \\emph{resample} executions.\nBPF is a standard algorithm often used in PPLs, and APF is a related algorithm introduced in a PPL context by \\citet{kudlicka2019probabilistic}.\nThe final two inference algorithms we add are aligned lightweight MCMC (just MCMC for short) and particle-independent Metropolis--Hastings.\nAligned lightweight MCMC~\\citep{lunden2023automatic} is an extension to the standard PPL Metropolis--Hastings approach introduced by~\\citet{wingate2011lightweight}, and suspends at a subset of calls to \\texttt{assume}.\nParticle-independent Metropolis--Hastings (PIMH) is an MCMC algorithm that repeatedly uses the BPF (suspending at \\texttt{weight}) within a Metropolis--Hastings MCMC algorithm~\\citep{paige2014compilation}.\nWe limit the scope to single-core CPU inference.\n\nIn addition to the inference algorithms in Miking CorePPL, we also use three other PPLs for CRBD: Anglican, WebPPL, and the special high-performance RootPPL compiler for Miking CorePPL~\\citep{lunden2022compiling}.\nFor Anglican, we apply LW, BPF, and PIMH inference.\nFor WebPPL, we use BPF and (non-aligned) lightweight MCMC.\nFor the RootPPL version of Miking CorePPL, we use BPF inference.\n\nWe consider two configurations for each model: $1\\,000$ and $10\\,000$ samples.\nAn exception is for CRBD and ClaDS, where we adjust APF to use $500$ and $5\\,000$ samples to make the inference accuracy comparable to the related BPF.\nWe run each experiment $300$ times (with one warmup run) and measure execution time (excluding compile time).\nTo justify the efficiency of the suspension analysis and selective CPS transformation that are part of the compiler, we note here that they, combined, run in only $1$--$5$ ms for all models.\n\nIn general, the experiments are \\emph{not} intended to compare the performance of different inference algorithms.\nTo do this, one would also need to consider how accurate the inference results are for a given amount of execution time.\nInstead, we evaluate only how selective and full CPS affect individual inference algorithms.\nSelective CPS only reduces execution time compared to full CPS---the algorithms themselves remain unchanged (we verify this in Appendix~\\ref{sec:evalcont} for LW, BPF, and APF).\n\nFor Miking CorePPL, we used OCaml 4.12.0 as backend compiler for the implementation in Section~\\ref{sec:implementation} and GCC 7.5.0 for the separate RootPPL compiler.\nWe used Anglican 1.1.0 and WebPPL 0.9.15.\nWe ran the experiments on an Intel Xeon Gold 6148 CPU with 64 GB of memory using Ubuntu 18.04.6.\n\n\\subsection{Constant Rate Birth-Death}\\label{sec:expcrbd}\n\\begin{figure}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/crbd_small_runtime.pgf}}\n\\end{subfigure}\n\\hspace{5mm}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/crbd_large_runtime.pgf}}\n\\end{subfigure}\n\\caption{%\n Mean execution times for the CRBD model.\n The error bars show 95\\% confidence intervals (using the option \\texttt{('ci', 95)} in Seaborn's \\texttt{barplot}).\n The plots omit the results for Anglican and WebPPL, which are instead available in Appendix~\\ref{sec:expcrbdcont}.\n}\n\\label{fig:crbd:runtime}\n\\end{figure}\nCRBD is a diversification model, used by evolutionary biologists to infer probability distributions over birth and death rates for observed evolutionary trees of groups of species, also called \\emph{phylogenies}.\nFor the CRBD experiment, we use the dated Alcedinidae phylogeny (Kingfisher birds, 54 extant species)~\\citep{ronquist2021universal,jetz2012global} as the observed phylogeny.\nWe implement CRBD in Miking CorePPL (55 lines of code), Anglican (129 lines of code), and WebPPL (66 lines of code).\nThe source code for all implementations is available in Appendix~\\ref{sec:expcrbdcont}.\nThe total experiment execution time was 9 hours.\n\nFigure~\\ref{fig:crbd:runtime} presents the results.\nWe note that selective CPS is faster than full CPS in all cases.\nIn particular, unlike full CPS, the overhead of selective CPS compared to no CPS is marginal for LW.\nThe execution time for early MCMC samples is sensitive to initial conditions, and we therefore see more variance for MCMC compared to the other algorithms.\nWhen we increase the number of samples to $10\\,000$, the variance reduces.\nTo further justify the Miking CorePPL implementation, we also note that WebPPL and Anglican are slower than the equivalent algorithms in Miking CorePPL (see Appendix~\\ref{sec:expcrbdcont} for the results).\nFor example, for $10\\,000$ samples, Anglican LW had a mean execution time of $90.4$ s, Anglican BPF $29.1$ s, WebPPL BPF $53.9$ s, and WebPPL MCMC $3.10$ s.\nExcept for WebPPL MCMC, the execution times are one order of magnitude slower than for Miking CorePPL.\nHowever, note that the comparison is only for reference and not entirely fair, as Anglican and WebPPL use different execution environments compared to Miking CorePPL.\nLastly, we note that the Miking CorePPL BPF implementation with selective CPS is not much slower than when compiling Miking CorePPL to RootPPL BPF---a compiler designed and developed for maximum efficiency (but with other limitations, such as the lack of garbage collection).\n\n\\subsection{Cladogenetic Diversification Rate Shift}\\label{sec:expclads}\n\\begin{figure}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/clads2_small_runtime.pgf}}\n\\end{subfigure}\n\\hspace{5mm}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/clads2_large_runtime.pgf}}\n\\end{subfigure}\n\\caption{%\n Mean execution times for the ClaDS model.\n The error bars show 95\\% confidence intervals (using the option \\texttt{('ci', 95)} in Seaborn's \\texttt{barplot}).\n}\n\\label{fig:clads2:runtime}\n\\end{figure}\nClaDS is another diversification model used in evolutionary biology~\\citep{maliet2019model,ronquist2021universal}.\nUnlike CRBD, it allows birth and death rates to change over time.\nWe again use the Alcedinidae phylogeny as data.\nThe full source code (72 lines of code) is available in Appendix~\\ref{sec:expcladscont}.\nThe total experiment execution time was 3 hours.\nFigure~\\ref{fig:clads2:runtime} presents the results.\nAgain, we note that selective CPS is faster than full CPS in all cases.\n\n\\subsection{Latent Dirichlet Allocation}\\label{sec:explda}\n\\begin{figure}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/lda_small_runtime.pgf}}\n\\end{subfigure}\n\\hspace{5mm}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/lda_large_runtime.pgf}}\n\\end{subfigure}\n\\caption{%\n Mean execution times for the LDA model.\n The error bars show 95\\% confidence intervals (using the option \\texttt{('ci', 95)} in Seaborn's \\texttt{barplot}).\n}\n\\label{fig:lda:runtime}\n\\end{figure}\n\nLDA~\\citep{blei2003latent} is a model frequently applied in natural language processing to categorize documents into \\emph{topics}.\nWe use a synthetic data set with size comparable to the data set in \\citet{ritchie2016c3}.\nSpecifically, we use a vocabulary of 100 words, 10 topics, and 25 observed documents (30 words in each).\nWe do not apply any optimization techniques such as collapsed Gibbs sampling~\\cite{griffiths2004finding}.\nSolving the inference problem using a PPL is therefore challenging already for small data sets.\nThe full source code (26 lines of code) is available in Appendix~\\ref{sec:expldacont}.\nThe total experiment execution time was 12 hours.\n\nFigure~\\ref{fig:lda:runtime} presents the results.\nAgain, we note that selective CPS is faster than full CPS in all cases.\nInterestingly, the reduction in overhead compared to full CPS for LW is not as significant.\nThe reason is that suspension at \\texttt{weight} for the model requires that we CPS transform a larger portion of the model (compared to CRBD and ClaDS).\nIn particular, we must CPS transform the most computationally expensive recursion.\n\n\\subsection{Vector-Borne Disease}\\label{sec:expvbd}\n\\begin{figure}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/vbd_small_runtime.pgf}}\n\\end{subfigure}\n\\hspace{5mm}\n\\begin{subfigure}{0.47\\textwidth}\n\\resizebox{\\textwidth}{!}{\\input{figs\/vbd_large_runtime.pgf}}\n\\end{subfigure}\n\\caption{%\n Mean execution times for the VBD model.\n The error bars show 95\\% confidence intervals (using the option \\texttt{('ci', 95)} in Seaborn's \\texttt{barplot}).\n}\n\\label{fig:vbd:runtime}\n\\end{figure}\n\nWe use the VBD model from \\citet{funk2016comparative} and later \\citet{murray2018delayed}.\nThe background is a dengue outbreak in Micronesia and the spread of disease between mosquitos and humans.\nThe inference problem is to find the true numbers of susceptible, exposed, infectious, and recovered (SEIR) individuals each day, given daily reported number of new cases at health centers.\nThe full source code (140 lines) is available in Appendix~\\ref{sec:expvbdcont}.\nThe total execution time was 8 hours.\n\nFigure~\\ref{fig:vbd:runtime} presents the results.\nAgain, we note that selective CPS is faster than full CPS in all cases, except seemingly for APF and $1\\,000$ samples.\nThis is very likely a statistical anomaly, as the variance for APF is quite severe for the case with $1\\,000$ samples.\nCompared to the BPF, APF uses a resampling approach for which the execution time varies a lot if the number of samples is too low~\\citep{kudlicka2019probabilistic}.\nThe plots clearly show this as, compared to $1\\,000$ samples, the variance is reduced to BPF-comparable levels for $10\\,000$ samples.\nIn summary, the evaluation demonstrates the clear benefits of selective CPS over full CPS for higher-order universal PPLs.\n\n\\section{Related Work}\\label{sec:related}\n\nThere are a number of universal PPLs that require non-trivial suspension.\nOne such language is Anglican~\\citep{wood2014new}, which solves the suspension problem using CPS.\nAnglican does not perform a full language CPS transformation, as is described in~\\citet{tolpin2016design}.\nSpecifically, certain statically known functions named \\emph{primitive procedures}, that include a subset of the regular Clojure\\footnote{The host language of Anglican.} functions, are guaranteed to not execute non-PPL code, and Anglican does not CPS transform them.\nHowever, higher-order functions in Clojure libraries cannot be primitive procedures, and Anglican must manually reimplement such functions (e.g., \\texttt{map} and \\texttt{fold}) using PPL code.\nMore importantly, Anglican does not consider a selective CPS transformation of PPL code, and always fully CPS transforms the PPL part of Anglican programs.\n\nWebPPL~\\citep{goodman2014design} and the approach by~\\citet{ritchie2016c3} also make use of CPS transformations to implement PPL inference.\nThey do not, however, consider selective CPS transformations.\n\\citet{scibior2018functional} present an architectural design for a probabilistic functional programming library based on monads and monad transformers (and corresponding theory in~\\citet{scibior2017denotational}).\nIn particular, they use a coroutine monad transformer to suspend SMC inference.\nThis approach is similar to ours in that it makes use of high-level functional language features to enable suspension.\nThey do not, however, consider a selective transformation.\n\nThere also exists many other PPLs, such as Pyro~\\citep{bingham2019pyro}, Stan~\\citep{carpenter2017stan}, Gen~\\citep{towner2019gen}, and Edward~\\citep{tran2016edward}.\nThese PPLs either implement inference algorithms that do not require suspension, or restrict the language in such a way that suspension is explicit and trivially handled by the language implementation.\nNewer versions of Birch also fall in the latter category.\n\nThere are also previous and more general-purpose approaches to selective CPS.\nThe early work by \\citet{nielsen2001selective} considers the efficient implementation of \\texttt{call\/cc} through a selective CPS transformation.\nManual user annotations guide the selective transformation, and Nielsen verifies the soundness of annotations for programs using an effect system.\nThe approach to selective CPS in this paper does not require manual annotations.\nA more recent approach is due to~\\citet{asai2017selective}, who consider an efficient implementation of delimited continuations using \\texttt{shift} and \\texttt{reset} through a selective CPS transformation.\nSimilar to our approach, they automatically determine where to selectively CPS transform programs.\nThey use an approach based on type inference in a type system with answer types for delimited continuations, while our approach builds upon 0-CFA.\n\nThere are low-level alternatives to CPS that also enable the suspension of executions in PPLs.\nIn particular, there are various languages and approaches that directly implement support for non-preemptive multitasking (e.g., coroutines).\nTuring~\\citep{ge2018turing} and older versions of Birch~\\citep{murray2018automated,murray2020lazy} implement coroutines to enable arbitrary suspension, but do not discuss the implementations in detail.\n\\citet{lunden2022compiling} introduces and uses the concept of PPL control-flow graphs to compile Miking CorePPL to the low-level C++ framework RootPPL.\nThe compiler explicitly introduces code that maintains special execution call stacks, distinct from the implicit C++ call stacks.\nThe implementation results in excellent performance, but supports neither garbage collection nor higher-order functions.\nAnother interesting low-level approach is due to \\citet{paige2014compilation}, who exploits mutual exclusion locks and the \\texttt{fork} system call to suspend and resample SMC executions.\nIn theory, many of the above low-level alternatives to CPS can, if implemented efficiently, result in the least possible overhead due to more fine-grained low-level control.\nThe approaches do, however, require significantly more implementation effort compared to a CPS transformation.\nComparatively, selective CPS transformation is a surprisingly simple, high-level, and easy-to-implement alternative that significantly reduces full CPS overhead.\n\n\\section{Conclusion}\\label{sec:conclusion}\nThis paper introduces the concept of a selective CPS transformation for the purpose of execution suspension in PPLs.\nTo enable such a transformation, we develop a static suspension analysis that determines parts of programs written in higher-order functional languages that require a CPS transformation as a consequence of inference algorithm suspension requirements.\nWe implement the suspension analysis, selective CPS transformation, and an inference problem extraction procedure (required as a result of the selective CPS transformation) in Miking CorePPL.\nFurthermore, we evaluate the implementation on real-world models from phylogenetics, topic-modeling, and epidemiology.\nThe results demonstrate significant speedups compared to the standard full CPS suspension approach for a large number of Monte Carlo inference algorithms.\n\n\\subsubsection*{Acknowledgments}\nWe thank Gizem \u00c7aylak for her LDA implementation and Viktor Senderov for his ClaDS implementation.\n\nThis project is financially supported by the Swedish Foundation for Strategic Research (FFL15-0032 and RIT15-0012) and Digital Futures.\n\n\\clearpage\n\\bibliographystyle{unsrtnat}\n","meta":{"redpajama_set_name":"RedPajamaArXiv"}} +{"text":"\\section{Introduction}\n\t\n\t\n\t%\n\t%\n\t%\n\tFish swimming has been an attractive research topic for many years due to its interdisciplinary nature, involving hydrodynamics \\citep{Triantafyllou2000,Liao2007}, schooling \\citep{Ashraf2017}, swimming styles \\citep{Webb1984}, muscle anatomy \\citep{Altringham1999}, physiology \\citep{HuntvonHerbing2002} and sensory \\citep{Liu2016}. The research has been driven by the fish farming \\citep{Webb2011} and by biomimetic underwater robotics \\citep{Duraisamy2019,Fish2020}.\n\t\\textit{fish schooling} and \\textit{fish swimming style} are two interesting sub-categories among the fish swimming problems. Multiple factors can influence the evolved schooling behaviour and swimming style, including hydrodynamic effectiveness, predator defence, feeding, etc.\n\tBody-caudal fin is one of the most common swimming styles among fish species \\citep{Webb1984}, with typical examples of its sub-swimming forms shown in \\Cref{fig:4modes}.\n\tIn this study, we focus on the effects of \\textit{fish schooling} and \\textit{BCF swimming styles} on the hydrodynamics characteristics using simplified physical models. This work is inspired by the biological observation that schooling behaviour of BCF swimmers is, to our best knowledge, only found in \\textit{less wavy} swimming forms, e.g.\\ thunniform by tunas \\citep{Dai2020}, whereas schooling behaviour is undiscovered in \\textit{more wavy} swimming forms, e.g.\\ anguilliform by eels.\n\t\n\t\n\t%\n\t\n\t%\n\t\n\t%\n\tFish schooling has been extensively studied in the past decades for its hydrodynamic characteristics \\citep{weihs1973hydromechanics,Weihs1975}.\n\tCross sections of two schooling fish can be represented by two vibrating cylinders immersed in quasi-static fluid; it has been identified by theoretical \\citep{Hlamb1932hydrodynamics,NAIR2007} and numerical \\citep{Gazzola2012,Lin2018c,Lin2018b,Lin2019} methods that non-dimensional parameters such as phase difference can have a distinct impact on the flow-mediated interaction between the two cylinders.\n\t%\n\t\\cite{Shaw1978} estimated that at least 25\\% of all fish species demonstrate schooling behaviour.\n\t%\n\tMany hydrodynamic studies have focused on the minimal school composed of 2 identical BCF swimmers, using robotic fish \\citep{Li2020}, biological fish \\citep{Ashraf2016,Li2020}, hydrofoil experiments \\citep{Dewey2014,Kurt2020} and numerical simulation \\citep{Khalid2016,Li2019}.\n\t\\cite{Ashraf2016} discovered a pair of red nose tetra fish tend to swim either in-phase or anti-phase, with the latter mode being more favourable; lateral and front-back distances are around 0.5 and 0.2 fish body length. For this reason, we place more emphasis on the anti-phase scenarios in a later discussion.\n\t\\cite{Li2020} found that the locomotion efficiency of the followers can be achieved at any relative leader-follower front-back distance by adjusting their tailbeat phase difference.\n\t%\n\tAs for the schooling size larger than 2, \\cite{Ashraf2017} discovered that the phalanx, \\ie side-by-side arrangement of multiple fish, formation is most frequently observed in the schooling of red nose tetra fish, \\textit{Hemigrammus bleheri}, which is contradictory with the previous idea that a diamond pattern is more efficient \\citep{weihs1973hydromechanics}.\n\tIn the present work, we set the front-back and lateral distances in a range similar to the previous works \\citep{Ashraf2016,Ashraf2017,Li2020}.\n\t\n\t\n\t\n\t\n\t%\n\tFish swimming style is a curious topic that has fascinated many researchers \\citep{Sfakiotakis1999,Tytell2010,Cui2018,Thekkethil2017,Thekkethil2018,Thekkethil2020}.\n\t%\n\t\\cite{Sfakiotakis1999} categorised fish swimming styles into several classes, among which the most common one is the body-caudal fin (BCF) swimming style, featuring the body\/tail undulation as the main propulsion generator. BCF styles can be further divided into four types: anguilliform, sub-carangiform, carangiform, and thunniform, as exemplified in \\Cref{fig:4modes}.\n\t\\cite{Thekkethil2017,Thekkethil2018,Thekkethil2020} simplified these BCF swimmers into undulating\/pitching NACA0012 hydrofoils, representing different swimming forms by non-dimensional wavelength $ \\lambda^* = \\lambda \/ C $, where $ \\lambda $ is the swimming undulation wavelength and $ C $ is the fish chord length. For example, anguilliform is typically represented by low wavelength $ \\lambda^* < 1 $, whereas the characteristics of thunniform swimming can be captured by high wavelength $ \\lambda^* \\gg 1 $. \\cite{Thekkethil2018} discovered that low wavelength $ \\lambda^* $ swimmers generate thrust force by the pressure difference between anterior and posterior body parts, whereas high $ \\lambda^* $ transfer streamwise momentum by pendulum-like motion; small $ \\lambda^* $, e.g.\\ anguilliform swimmers, generally causes high locomotion efficiency but low thrust production, and vice versa for large $ \\lambda^* $, e.g.\\ thunniform swimmers. The numerical results obtained by \\cite{Thekkethil2018} are highly coherent with previously reported single fish swimming characteristics. The present study adopts the same simplified geometry and kinematic formula proposed by \\cite{Thekkethil2018}, which will be presented later.\n\t\\cite{Nangia2017a} also discovered that optimal wavelength exists for maximum swimming speed and propulsive thrust.\n\t\n\t\n\t\n\t\n\t%\n\tAs \\textit{schooling} and \\textit{swimming styles} of BCF fish both contain significant hydrodynamic implications, they can have a combined effect on the hydrodynamic characteristics of underwater swimmers. To our best knowledge, the systematic biological discussion does not exist on the behavioural correlation between \\textit{schooling} and \\textit{swimming styles}. However, while the schooling phenomenon is reported for swimmers of sub-carangiform \\citep{Trevorrow1998}, carangiform \\citep{Axelsen2001,Guillard2006,Hemelrijk2010} and thunniform \\citep{Dai2020,Mitsunaga2013,Uranga2019}, anguilliform species seem never found to exhibit schooling behaviour in the wild.\n\tAlthough hydrodynamics may not be the only factor affecting fish's schooling tendency, it is reasonable to hypothesise that sub-carangiform, carangiform, and thunniform styles are more suited for schooling than anguilliform styles from a hydrodynamic perspective.\n\t%\n\t\n\t\n\t%\n\tTo justify our numerical methodology, although robotic fish experiments could be an efficient way \\citep{Li2020} to study fish schooling with a fixed swimming style, it will be time-consuming to design and manufacture robotic fish with variable swimming styles. To our best knowledge, existing robotic fish studies have not yet involved such a comparison between swimming styles\/wavelengths. For this reason, computational fluid dynamics is utilised to simulate various fish swimming styles using a representative problem setup, thanks to its convenience in varying the swimming style by a unified kinematic formula and the capacity to analyse the flow-mediated interaction mechanism in detail \\citep{Thekkethil2018}.\n\t\n\t%\n\t\n\t%\n\t\n\t%\n\tIn summary, for the hydrodynamics of body-caudal fin swimmers, while the mechanism of \\textit{schooling} has been extensively studied \\citep{weihs1973hydromechanics,Weihs1975,Ashraf2016,Li2020}, research on the \\textit{swimming styles} is relatively scarce \\citep{Thekkethil2018}. In nature, swimmers of sub-carangiform \\citep{Trevorrow1998}, carangiform \\citep{Hemelrijk2010} and thunniform \\citep{Dai2020} have been reported to exhibit schooling behaviour, whereas the school of travelling anguilliform swimmers seems never been reported in the wild.\n\tHere, we hypothesise that thunniform swimmers are more adapted for schooling locomotion than anguilliform swimmers.\n\t%\n\tIn this paper, this hypothesis is tested by a representative problem of two wavy foils interacting in free-stream flow.\n\tDespite simplification, the present study will be, to our best knowledge, the first study regarding the combined effects of \\textit{schooling} and \\textit{swimming styles} on the BCF swimmers' locomotion hydrodynamics.\n\tThis work is a continuation of the previous single foil swimmer study conducted by \\cite{Thekkethil2018} and has been directly inspired by the previous robotic \\citep{Li2020} and biological \\citep{Ashraf2017} fish schooling studies.\n\t\n\t%\n\t\n\t%\n\t\n\t\n\t\\newcommand{\\addlabeltrim}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={0cm 2.6cm 0cm 2.4cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcounter{testdd}\n\t\\setcounter{testdd}{0}\n\t\\newcommand\\counterdd{\\stepcounter{testdd}\\alph{testdd}}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\n\t\t\\addlabeltrim{0.24}{Figure\/intro_background_fig\/1_Eels}{(\\counterdd) Anguilliform}\n\t\t\\addlabeltrim{0.24}{Figure\/intro_background_fig\/2_Salomnids}{(\\counterdd) Sub-carangiform}\n\t\t\\addlabeltrim{0.24}{Figure\/intro_background_fig\/3_Makrell}{(\\counterdd) Carangiform}\n\t\t\\addlabeltrim{0.24}{Figure\/intro_background_fig\/4_Tuna}{(\\counterdd) Thunniform}\n\t\t\n\t\t\\caption{Four different swimming modes of Body-Caudal-Fin type locomotion\n\t\t\t(a) Anguilliform (body undulation, e.g.\\ eel)\n\t\t\t(b) Sub-carangiform (body undulation with caudal fin pitching, e.g.\\ salmonid)\n\t\t\t(c) Carangiform (minor body undulation with caudal fin pitching, e.g.\\ makrell)\n\t\t\t(d) Thunniform (mainly caudal fin pitching, e.g.\\ tuna). The shaded area demonstrates the body parts with the significant lateral motion to generate thrust force (redrawn from figures by \\cite{Lindsey1978} and \\cite{Sfakiotakis1999}). }\n\t\t\\label{fig:4modes}\n\t\\end{figure}\n\t\n\t\n\t\\section{Methodology}\n\t\n\tThis section describes the numerical methodology to study the combined effects of fish schooling and swimming styles upon propulsive hydrodynamics.\n\tThis problem is represented by two identical wavy hydrofoils tethered in a free-stream flow, as presented in \\Cref{subsec:physical_problem_setup}.\n\tNumerical simulation is then executed by IBAMR \\citep{griffith2013ibamr}, an extensively-validated immersed boundary software, as discussed in \\Cref{subsec:immersed_boundary_method}.\n\tThe kinematic model of hydrofoil undulation is formulated by the classic travelling wave equation with additional consideration upon the \\textit{wavelengths} as shown in \\Cref{subsec:kinematic_model}. Dimensional analysis is conducted in \\Cref{subsec:dim_analysis} to formalise the investigated problem. Mesh convergence study and validation can be found in \\Cref{subsec:mesh_inde_vali}.\n\t\n\t%\n\t\n\t\n\t\\subsection{Physical problem setup}\n\t\\label{subsec:physical_problem_setup}\n\t\n\tIn this paper, the two undulating rigid NACA0012 hydrofoils are fixed at their initial locations, i.e.\\ the foils are \"tethered\".\n\tThe non-dimensional form of the physical problem investigated in the present paper is demonstrated in \\Cref{fig:problemsetup}. Here, $ C = 1 $ is the chord length of the two NACA0012 hydrofoils. $ G $ and $ D $ are the lateral and front-back distances between the two hydrofoils, respectively. The \\textit{computational domain} is chosen as $ 16C $ in the streamwise direction and $ 8C $ in the transverse direction, which is identical to the domain size chosen by \\cite{Thekkethil2018}. The head tip of the leader fish is placed $ 5C $ to the inlet, and the mid-point between the two hydrofoils is placed $ 4C $ to each of the lateral walls.\n\tAs for \\textit{boundary conditions}, the two identical hydrofoils are both non-slip on their fluid-solid interface. The inlet free-stream velocity is configured as $ U_{inlet} = (U_x,U_y) = (1,0) $. The outlet boundary is set as $ {\\partial u_x}\/{\\partial \\bm{n}} = 0$ and $U_y = 0 $, which is equivalent to the zero pressure outlet boundary condition, i.e.\\ $ P_{outlet} = 0 $; here, $ \\bm{n} $ is the outward unit vector normal to the boundary. Lateral walls on the left and right sides of the swimming direction are both prescribed as slip wall boundary condition $ {\\partial u_x}\/{\\partial \\bm{n}} = 0$ and $U_y = 0 $.\n\t%\n\tWe note that we are not strictly modelling any specific fish species but are instead seeking underlying principles of how swimming style affects schooling.\n\t\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[width=1\\linewidth]{Figure\/problem_setup}\n\t\t\\caption{Problem setup of this two fish case}\n\t\t\\label{fig:problemsetup}\n\t\\end{figure}\n\t\n\t\n\t\n\t\n\t\\newcommand{{C\\nolinebreak[4]\\hspace{-.05em}\\raisebox{.4ex}{\\tiny\\bf ++}}}{C\\nolinebreak\\hspace{-.05em}\\raisebox{.4ex}{\\tiny\\bf +}\\nolinebreak\\hspace{-.10em}\\raisebox{.4ex}{\\tiny\\bf +}}\n\t\\def{C\\nolinebreak[4]\\hspace{-.05em}\\raisebox{.4ex}{\\tiny\\bf ++}}{{C\\nolinebreak[4]\\hspace{-.05em}\\raisebox{.4ex}{\\tiny\\bf ++}}}\n\t\n\t\\subsection{Immersed boundary method}\n\t\\label{subsec:immersed_boundary_method}\n\tIn the present study, the numerical simulation of the fluid-structure interaction process is achieved by a modified version of the constrained method in the \\verb!C++! open-source software IBAMR \\citep{griffith2013ibamr}. IBAMR is constructed on the foundation of several libraries, including\n\tSAMRAI \\citep{Hornung2002,Hornung2006},\n\tPETSc \\citep{Balay1997,Balay2010,balay2001petsc},\n\thypre \\citep{falgout2010hypre,Balay1997},\n\tand\n\tlibmesh \\citep{Kirk2006}.\n\tThe constrained immersed boundary (IB) method of IBAMR has been validated in various scenarios, including fish swimming \\citep{Bhalla2013,Griffith2020}, flow past cylinder\\citep{Nangia2017}, and free-surface piercing \\citep{Nangia2019}. In the present study, the force upon each hydrofoil was obtained by the control volume method \\citep{Nangia2017}.\n\t%\n\t\n\tThe IB method uses Eulerian description for the fluid and Lagrangian description for the deforming structure. One of its advantages is the computational efficiency due to circumventing the costly remeshing process encountered in other methods like the finite element method. The implemented formulation is stated as:\n\t\n\t\\begin{equation}\\label{eq:IB1}\n\t\t\\rho \\left( \\frac{\\partial \\bm{u}(\\bm{x},t) }{\\partial t} + \\bm{u}(\\bm{x},t) \\cdot \\nabla \\bm{u}(\\bm{x},t)\\right) = -\\nabla p (\\bm{x},t) + \\mu \\nabla^2 \\bm{u}(\\bm{x},t) + \\bm{f}(\\bm{x},t) \n\t\\end{equation}\n\t\\begin{equation}\\label{eq:IB2}\n\t\t\\nabla \\cdot \\bm{u}(\\bm{x},t) = 0\n\t\\end{equation}\n\t\\begin{equation}\\label{eq:IB3}\n\t\t\\bm{f}(\\bm{x},t) = \\int_{U} \\bm{F}(\\bm{X},t) \\delta(\\bm{x} - \\bm{\\chi}(\\bm{X},t)) \\diff \\bm{X}\n\t\\end{equation}\n\t%\n\t%\n\t%\n\t\\begin{equation}\\label{eq:IB4}\n\t\t\\frac{\\partial \\bm{\\chi} (\\bm{X},t)}{\\partial t} = \\int_{\\Omega} \\bm{u}(\\bm{x},t) \\delta(\\bm{x} - \\bm{\\chi}(\\bm{X},t)) \\diff \\bm{x}\n\t\\end{equation}\n\t\n\tHere $ \\bm{x} = (x,y) \\in \\Omega $ represents fixed physical Cartesian coordinates, where $ \\Omega $ is the physical domain occupied the fluid and the immersed structure. $ \\bm{X} = (X,Y) \\in U $ means Lagrangian solid structure coordinates, and $ U $ is the Lagrangian coordinate domain. The mapping from Lagrangian structure coordinates to the physical domain position of point $ \\bm{X} $ for all time $ t $ can be expressed as $ \\bm{\\chi}(\\bm{X},t) = ( \\chi_x(\\bm{X},t), \\chi_y(\\bm{X},t) ) \\in \\Omega $. In other words, $ \\chi(U,t) \\subset \\Omega $ represents the physical region occupied by the solid structure at time $ t $. $ \\bm{u}(\\bm{x},t) $ is the Eulerian fluid velocity field and $ p(\\bm{b},t) $ is the Eulerian pressure field. $ \\rho $ is the fluid density. $ \\mu $ is the incompressible fluid dynamic viscosity. $ \\bm{f}(\\bm{x},t) $ and $ \\bm{F}(\\bm{X},t) $ is Eulerian and Lagrangian force densities, respectively. $ \\delta (\\bm{x}) $ is the Dirac delta function. More details regarding the constrained IB formulation and discretisation process can be found in previous literature \\citep{Bhalla2013,Griffith2020}.\n\t\n\t\n\t\\subsection{Kinematic model for fish-like wavy propulsion}\n\t\\label{subsec:kinematic_model}\n\tThe non-dimensional kinematic equations for the centrelines of the two tethered NACA0012 hydrofoils \\citep{LangleyResearchCenter2021} are prescribed as \\Cref{equ:fish_wave_leader,equ:fish_wave_follower}\n\t\\citep{Thekkethil2018,VIDELER1984}:\n\t\\begin{equation}\\label{equ:fish_wave_leader}\n\t\t\\Delta Y^*_{1} = A_{max} X^*_{1} \\sin \\left[ 2\\pi \\left( \\frac{X^*_1}{\\lambda^*} - \\frac{St }{2 A_{max}} t^* \\right) \\right]\n\t\\end{equation}\n\t\\begin{equation}\\label{equ:fish_wave_follower}\n\t\t\\Delta Y^*_{2} = A_{max} X^*_{2} \\sin \\left[ 2\\pi \\left( \\frac{X^*_2}{\\lambda^*} - \\frac{St }{2 A_{max}} t^* \\right) + \\phi \\right]\n\t\\end{equation}\n\twhere $ \\Delta Y^*_i = \\Delta Y_i\/C $ is the lateral displacement of each NACA0012 hydrofoil centreline that varies with streamwise direction $ X^*_i=X_i\/C $ and time $ t^* = tu_{\\infty}\/C $. The wavy undulation period $ T $ is equal to $ St\/2A_{max} $, so $ t^*\/T = 2t^*A_{max}\/St $. $ i = 1 $ and $ i = 2 $ denotes the leader foil and the follower foil, respectively. %\n\t%\n\t%\n\t%\n\t\n\t\n\t\n\t\\subsection{Dimensional analysis}\n\t\\label{subsec:dim_analysis}\n\tIn this paper, we investigate the flow-mediated interaction between two swimming fish with various swimming modes, which can be simplified into two rigid NACA0012 hydrofoils with wavy lateral movement subject to free stream flow. The problem setup can be determined by 7 non-dimensional groups as shown in \\Cref{tablecasegroups}, where $ \\rho $ is the fluid density, $ u_{\\infty} = 1 $ is the free stream velocity, $ C = 1 $ is the hydrofoil chord length, $ \\mu $ is the fluid viscosity, $ f $ is the undulation frequency, $ a_{max} $ is the maximum undulation amplitude at tail tip, $ \\lambda,\\ g,\\ d $ are the wavelength, lateral distance and front-back distance to be non-dimensionalised by chord length $ C $.\n\t%\n\tReynolds number $ Re $ and Strouhal number $ St $ are fixed at $ 5000 $ and $ 0.4 $, respectively, since the slowly swimming fish generally swim with moderate $ Re $ and $ St \\approx 0.4,\\ A_{max} \\approx 0.1 $ \\citep{Lindsey1978,Thekkethil2018}. The Reynolds number at the order of $ 10^3 $ allows a more economical mesh resolution and computational cost, whereas predominant vortex dynamics still remain understandable \\citep{Liu2017}. The chosen Reynolds number is more convenient for comparison with the previous work of single wavy foil by \\cite{Thekkethil2018}, which also fixed $ Re $ at $ 5000 $. The lateral and front-back distances vary in the range of $ G = 0.25 - 0.35 $ and $ D = 0 - 0.75 $, respectively, which corresponds to the value range chosen by \\cite{Ashraf2017} and \\cite{Li2020}.\n\t\n\t\n\t%\n\t\n\t\\bgroup\n\t\\def\\arraystretch{2.2}%\n\t\\begin{table}[thb]\n\t\t\\caption{Non-dimensional input parameters and the involved range of value}\n\t\t\\centering\n\t\t\\label{tablecasegroups}\n\t\t\\begin{tabular}{l c c c}\n\t\t\t\\toprule\n\t\t\tReynolds number & $ Re $ &{ $ { \\rho u_{\\infty} C}\/{\\mu} $} & $ 5000 $ \\\\\n\t\t\t\n\t\t\tStrouhal number & $ St $ &{ $ {2 f a_{max}}\/{u_{\\infty}} $} & $ 0.4 $ \\\\\n\t\t\t\n\t\t\tMaximum amplitude & $ A_{max} $ &{ $ a_{max}\/C $ } & $ 0.1 $ \\\\\n\t\t\t\n\t\t\tWavelength & $ \\lambda^* $ &{ $ {\\lambda}\/{C} $} & $0.8 - 8 $ \\\\\n\t\t\t\n\t\t\tLateral gap distance & $ G $ & { $ {g}\/{C} $} & $ 0.25,\\ 0.3,\\ 0.35 $ \\\\ \n\t\t\t\n\t\t\tFront-back distance & $ D $ & { $ {d}\/{C} $} & $ 0,\\ 0.25,\\ 0.5,\\ 0.75 $ \\\\ \n\t\t\t\n\t\t\tPhase difference & $ \\phi $ &{ $ \\phi_{2}-\\phi_{1} $} & $ 0,\\ 0.5\\pi,\\ \\pi,\\ 1.5\\pi $ \\\\\n\t\t\t\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\egroup\n\t\n\t\n\t%\n\t\n\t%\n\tTo examine the schooling performance of two fish-like hydrofoils, we chose the output parameters as listed in \\Cref{tab:output_para}. Here, $ F_{T,i} $ is the net thrust force along streamwise direction and $ F_{L,i} $ is the lateral force on the transverse direction. $ i = 1,\\ 2 $ denotes the No.\\ $ i $ hydrofoil structure; $ i = 1 $ and $ i = 2 $ represent the leader foil and follower foil respectively. $ V_{body,i} = {\\diff \\Delta Y^*_i}\/{ \\diff t^*} $ is the lateral motion velocity of the hydrofoils. $ c_{L,i} $ is the force coefficient density distributed on the surface of the hydrofoil. $ \\bm{u}(\\bm{x},t) $ is the velocity field of the fluid. %\n\t\n\t\n\t\\bgroup\n\t\\def\\arraystretch{2.2}%\n\t\\begin{table}%\n\t\t\\caption{Non-dimensional output parameters}\n\t\t\\centering\n\t\t\\label{tab:output_para}\n\t\t\\begin{tabular}{l c c c}\n\t\t\t\\toprule\n\t\t\tCycle-averaged thrust coefficient & $ C_{Tm,i} $ &{\\Large $\\left( \\frac{2F_{T,i}}{\\rho u_{\\infty}^2 C} \\right)_{avg} $} \\\\\n\t\t\t\n\t\t\tRoot mean square lateral force coefficient & $ C_{Lrms,i} $ &{\\Large $\\left( \\frac{2F_{L,i}}{\\rho u_{\\infty}^2 C} \\right)_{rms} $} \\\\\n\t\t\t\n\t\t\tFroude efficiency \\citep{Liu1996} & $ \\eta_i $ &{\\Large $ \\frac{P_{out,i}}{P_{in,i}} = \\frac{C_{Tm,i}}{\\overline{\\int c_{L,i} V_{body,i} dS}} $ } \\\\\n\t\t\t\n\t\t\tGroup Froude efficiency & $ \\eta_{group} $ &{\\Large $ \\frac{\\sum P_{out,i}}{\\sum P_{in,i}} $ } \\\\\n\t\t\t\n\t\t\tFluid velocity & $ \\bm{u^*} $ &{ $ \\bm{u}\/u_{\\infty} $ } \\\\\n\t\t\t\n\t\t\tFluid vorticity & $ \\bm{\\omega^*} $ &{ $ \\nabla \\times \\bm{u^*} $ } \\\\\n\t\t\t\n\t\t\t\\bottomrule\n\t\t\\end{tabular}\n\t\\end{table}\n\t\\egroup\n\t\n\t\n\t\n\t\n\t\n\t\n\t\\subsection{Mesh independence and validation}\n\t\\label{subsec:mesh_inde_vali}\n\tIBAMR utilises two sets of \"immersed\" meshes for numerical simulations, \\ie Eulerian mesh for the flow field and Lagrangian mesh for the structure (swimmer), where the Eulerian mesh can be adaptively refined considering the local vorticity strength and adjacency to the Lagrangian described structure.\n\tIn the present study, the Eulerian mesh consists of 3 levels of refinement divided by local vorticity thresholds, with each level being 4 times finer than the coarser level.\n\tThe mesh density of the Lagrangian mesh for the hydrofoil structure is equivalent to that of the finest level Eulerian mesh for the fluid.\n\t\n\tMesh independence study was conducted using 4 meshes with different levels of refinement, as listed in \\cref{tab:mesh_val}.\n\tAt $ D = 0.5,\\ G = 0.3, \\lambda^* = 2.0, \\phi\/\\pi = 1 $, the time history of lateral force coefficient is examined to check mesh convergence, as seen in \\Cref{fig:mesh_validation}a. While a large difference can be observed from $ C_L $ yielded by the \"Coarsest\" mesh and \"Coarse\" mesh, the time history of $ C_L $ almost overlaps for the output produced by \"Normal\" and \"Refined\" meshes. To be conservative, the \"Refined\" mesh setting is chosen for all the cases in this study. Based on \"Refined\" mesh, the current result is further validated against results from \\cite[pp. 10]{Thekkethil2018} with single fish case of $ Re = 5000,\\ St = 0.3 - 0.7,\\ A_{max} = 0.1,\\ \\lambda^* = 1.5$, as seen in \\Cref{fig:mesh_validation}b. Excellent coherence can be seen between the results produced by the present IBAMR model and the in-house model by \\cite{Thekkethil2018}.\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t\\newcommand{\\addlabel}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node at (0.2,0.23) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\addlabel{0.49}{Figure\/Mesh_Indp_fish_paper_1}{(a)}\n\t\t\\addlabel{0.49}{Figure\/2018_TH_Validation_CLrms}{(b)}\n\t\t%\n\t\t%\n\t\t\\caption{\n\t\t\t(a) Mesh independence study for meshes listed in \\Cref{tab:mesh_val} with $ Re = 5000 $, $ St = 0.4 $, $ A_{max} = 0.1 $, $ \\lambda^* = 2 $, $ \\phi\/\\pi = 1 $, $ G = 0.3 $, $ D = 0.5 $.\n\t\t\t(b) Validation by comparing present results with that from \\cite[pp. 10]{Thekkethil2018} with $ Re = 5000,\\ St = 0.3 - 0.7,\\ A_{max} = 0.1,\\ \\lambda^* = 1.5$.\n\t\t}\n\t\t\\label{fig:mesh_validation}\n\t\\end{figure}\n\t\n\t\n\t\\begin{table}\n\t\t\\caption{Mesh configuration for independence study}\n\t\t\\centering\n\t\t\\label{tab:mesh_val}\n\t\t\\begin{tabular}{ccccc}\n\t\t\t\\hline\n\t\t\t{Mesh} \t\t& Refined & Normal & Coarse & Coarsest \\\\\n\t\t\t{$ \\Delta x^*_{min} $} \t& $2\\sci{-3}$ & $4\\sci{-3}$ & $8\\sci{-3}$ & $16\\sci{-3}$ \\\\\n\t\t\t{$ \\Delta t^* $} \t& $2.5\\sci{-5}$ & $5\\sci{-5}$ & $10\\sci{-5}$ & $20\\sci{-5}$ \\\\\n\t\t\t{$ \\Delta x^*_{min} \/ \\Delta t^* $} \t& $80$ & $80$ & $80$ & $80$ \\\\\n\t\t\t%\n\t\t\t\\hline\n\t\t\\end{tabular}\n\t\t\\centering\n\t\\end{table}\n\t\n\t\n\t\n\t\n\t%\n\t\n\t\n\t\\section{Results and Discussion}\n\t\n\t%\n\tThe present paper includes a parametric space of more than 300 combinations with a focus on the variation of wavelengths $ \\lambda^* = 0.8 - 8.0 $. The lateral gap distance $ G $ ranges from $ 0.25 $ to $ 0.35 $, the front-back distance $ D = 0 - 0.75 $, leader-follower phase difference $ \\phi\/\\pi = 0, 0.5, 1, 1.5 $. The Reynolds number, Strouhal number and maximum amplitude is fixed at $ Re = 5000 $, $ St = 0.4 $ and $ A_{max} = 0.1 $ throughout this study.\n\t%\n\tThe following discussion is divided into 2 parts: side-by-side arrangement in \\Cref{sec:phalanx_D0} and staggered configuration in \\Cref{sec:Staggered_Dg0}.\n\tThe separated discussion of side-by-side arrangement $ D = 0 $ is justified by the rich physics due to its distinguished symmetrical flow structure and potential occurrence of symmetry breaking \\citep{Gungor2020} and by the observation of fish's tendency to form a phalanx formation in a free-stream flow \\cite{Ashraf2017}. It is also a curious question of how the variation of wavelength affects the flow symmetry and locomotion properties.\n\tThe investigation of staggered arrangement $ D > 0 $ is to understand the effects of swimming style, \\ie wavelengths, upon the vortex phase matching mechanism proposed by \\cite{Li2020}.\n\t\n\t%\n\t\n\tSeveral output parameters will be discussed to understand the schooling effect with various swimming styles, as listed in \\Cref{tab:output_para}: the thrust force $ C_{Tm} $ is directly relevant to the acceleration of the swimming foils; the lateral force $ C_{Lrms} $ is linked to the work done from the undulating foil to the incompressible fluid; Froude efficiency $ \\eta_{i} $ and $ \\eta_{group} $ are the propulsion efficiency converting the input energy to the output locomotion performance as an individual foil and as a grouped system, respectively; vorticity distribution $ \\omega^* $ demonstrates the vortex interaction between the two hydrofoils and the vortex shedding pattern in the wake flow, in which the vortex interaction is significant to understand the mechanism resulting the force and efficiency distribution, and vortex wake pattern is important for stealth capacity for fish schooling behaviour.\n\t\n\t\n\t%\n\t\n\t\n\t\n\t\n\t\\subsection{Overview}\n\t\n\t\n\tIn this subsection, we offer an overview of the present paper with an example case at $ G = 0.25 $, $ D = 0.75 $, $ \\phi = 0 $ and $ \\lambda^* = 0.8 - 8.0 $, demonstrating its key results of vorticity distribution $ \\bm{\\omega^*} $, thrust force $ C_{Tm} $ and the propeller efficiency $ \\eta $ at $ t^*\/T = 5 $, as seen in \\Cref{fig:vorticity_lambda}.\n\tThe irregularity of wake flow generally increases with wavelength $ \\lambda^* $, as seen in the vorticity contours in \\Cref{fig:vorticity_lambda}a-\\ref{fig:vorticity_lambda}f.\n\tThe flow structure near the two foils is relatively regular. In this paper, the output parameters are calculated using the last 3 stable periods.\n\tThe thrust force generally increases with $ \\lambda^* $, whereas the propeller efficiency is peaked at $ \\lambda^* = 2 $ in most cases, as seen in \\Cref{fig:vorticity_lambda}g-\\ref{fig:vorticity_lambda}h. The following sections further discuss the inter-relationship between wavelengths $ \\lambda^* $ and other parameters.\n\t%\n\tCompared with \\textit{single} swimmer cases with similar configurations \\citep{Thekkethil2018}, the interaction between \\textit{two} wavy foils leads to a more complicated flow structure. However, the general trend of thrust force and Froude efficiency is consistent with the single foil cases \\citep{Thekkethil2018}.\n\t%\n\tFor the sake of convenience and conciseness, the vorticity scale in all other figures is identical to the one shown in \\Cref{fig:vorticity_lambda}.\n\t\n\t\n\t%\n\t\n\t\\newcommand{\\addlabela}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={2cm 0cm 0cm 15.1cm},clip]{#2}};\t%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node at (0.125,0.75) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\includegraphics[width=1.0\\linewidth]{Figure\/vorticity_and_lambda}\n\t\t\\addlabela{0.7}{Figure\/legend}{$\\bm{\\omega}^*$:}\n\t\t\\includegraphics[width=0.9\\linewidth]{Figure\/CT_neta}\n\t\t\\caption{Variation of hydrofoil geometry and vorticity contours at time $ t^*\/T = 5 $ with $ G = 0.25 $, $ D = 0.75 $, $ \\phi = 0 $, and (a) $ \\lambda^* = 0.8 $ (b) $ \\lambda^* = 2.0 $ (c) $ \\lambda^* = 3.2 $ (d) $ \\lambda^* = 4.4 $ (e) $ \\lambda^* = 5.6 $ (f) $ \\lambda^* = 8.0 $. Variation of (g) thrust force $ C_{Tm} $ and (h) Froude propeller efficiency $ \\eta $ corresponding to (a-f).\n\t\t\tThe wake structure irregularity increases with $ \\lambda^* $. The propeller efficiency $ \\eta $ of the \\textit{follower} is, in general, higher than the \\textit{leader}, corresponding to higher thrust force $ C_{Tm} $. At large $ \\lambda^* > 7 $, the \\textit{leader} becomes slightly more efficient than the \\textit{follower}.\n\t\t}\n\t\t\\label{fig:vorticity_lambda}\n\t\\end{figure}\n\t\n\t%\n\t\n\t\\subsection{Side-by-side arrangement $ D = 0 $}\n\t\\label{sec:phalanx_D0}\n\t\n\tThis section discusses the scenarios with two foils swimming side-by-side $ D = 0 $.\n\t\\Cref{subsec:F_eta_Dis0} examines the variation of swimmers' mean thrust force $ C_{Tm} $, RMS lateral force $ C_{Lrms} $, propeller efficiency $ \\eta $, and group efficiency $ \\eta_{group} $ with a series of wavelength, phase difference and lateral gap distance.\n\t\\Cref{subsec:FSI_Dis0} investigates the variation of flow structure with wavelength $ \\lambda^* $, phase difference $ \\phi $, front-back distance $ D $ and their inter-relationships with additional discussion regarding the symmetrical anti-phase condition.\n\t\\Cref{subsec:vor_Dis0} discusses the mechanism of flow-mediated interaction between the two swimmers by examining vorticity distribution and hydrodynamic force within one typical cycle of undulation.\n\t\n\t\\subsubsection{Hydrodynamic force and propulsive efficiency at $ D = 0 $}\n\t\\label{subsec:F_eta_Dis0}\n\tAt side-by-side arrangement with $ D = 0 $, the mean thrust force and RMS lateral force generally increase with $ \\lambda^* $ \\Cref{fig:lines_D_0_CT_CL}, but the propeller efficiency only slightly changes with wavelength at $ \\lambda^* > 2 $, as seen in \\Cref{fig:lines_D_0_eta}.\n\tAs the two foils swim in-phase $ \\phi = 0 $ and anti-phase $ \\phi = \\pi $, due to the symmetrical nature of the side-by-side setting, the results of the leader overlap that of the follower. By comparison, results of the leader at $ \\phi = 0.5\\pi $ tend to coincide with that of the follower at $ \\phi = 1.5\\pi $.\n\tThese results regarding the undulation phase difference $ \\phi $ are in coherence with the observed fish schooling behaviour: when the multiple fish swim side-by-side, they tend to undulate either in-phase $ \\phi = 0 $ or in anti-phase $ \\phi = \\pi $ \\citep{Ashraf2017}. While the previous work by \\cite{Ashraf2017} is limited to only one species, \\ie \\textit{Hemigrammus bleheri}, the present results further indicate that the conclusion can be further extended to a wide range of wavelength $ \\lambda = 0.8 - 8.0 $.\n\t\n\t%\n\tThe \\textit{thrust force} $ C_{Tm} $ generally increases with wavelength $ \\lambda^* $ reaching maximum at $ \\lambda^* = 4.4 $ while swimming in-phase $ \\phi = 0 $ or anti-phase $ \\phi = \\pi $, as seen in \\Cref{fig:lines_D_0_CT_CL}a, \\ref{fig:lines_D_0_CT_CL}c and \\ref{fig:lines_D_0_CT_CL}e. Thrust force $ C_{Tm} $ in general increases with gap distance $ G $ while swimming in-phase $ \\phi = 0 $, but decreases with $ G $ while swimming anti-phase $ \\phi = \\pi $.\n\tThe flow is less regular at small gap distance $ G < 0.3 $ and anti-phase $ \\phi = \\pi $ condition, causing the less smooth curves in \\Cref{fig:lines_D_0_CT_CL}a and \\Cref{fig:lines_D_0_CT_CL}c.\n\t%\n\tThe \\textit{lateral force} $ C_{Lrms} $ on the whole increases monotonically with $ \\lambda^* $, as demonstrated in \\Cref{fig:lines_D_0_CT_CL}b, \\ref{fig:lines_D_0_CT_CL}d and \\ref{fig:lines_D_0_CT_CL}f.\n\t%\n\tAs shown in \\Cref{fig:lines_D_0_eta}a, \\ref{fig:lines_D_0_eta}c and \\ref{fig:lines_D_0_eta}e, the \\textit{propeller Froude efficiency} $ \\eta $ reaches maximum at $ \\lambda^* = 2 $ and then only slightly decreases with wavelength $ \\lambda^* $ at $ \\lambda^* > 2 $ and remains almost constant at $ \\lambda^* > 5.6 $.\n\tOne foil can achieve very high propeller efficiency $ \\eta $ at the cost of $ \\eta $ another foil at phase difference $ \\phi = 0.5 \\pi $ or $ 1.5 \\pi $. This effect is strengthened by stronger flow-mediated interaction through smaller gap distance $ G $. The difference in efficiency can reach $ 50\\% $ at $ G = 0.25 $.\n\t$ \\eta $ can be negative at $ \\lambda^* = 0.8 $, meaning the leader or the follower foils are not propelling forward.\n\t\n\tWhen the two foils swim side-by-side, their \\textit{group efficiency} reaches a maximum of $ \\eta_{group} = 31.2\\% $ at wavelength $ \\lambda^* = 2 $ and phase lag $ \\phi = 0.5 \\pi $, as seen in \\Cref{fig:lines_D_0_eta}b, \\ref{fig:lines_D_0_eta}d and \\ref{fig:lines_D_0_eta}f. Anguilliform swimming with low wavelength $ \\lambda^* < 1 $ can lead to negative group efficiency $ \\eta_{group} < 0 $, indicating that the foils tend to drift along the inlet flow direction; this tendency is strengthened by a narrow gap $ G = 0.25 $ and in-phase undulation $ \\phi = 0 $. For Carangiform swimming at high $ \\lambda^* $, the group efficiency slightly increases with the gap distance, especially the in-phase $ \\phi = 0 $ scenarios. The group efficiency is highly consistent for phase lag $ \\phi = 0,\\ \\pi $ and $ \\phi = 0.5\\pi,\\ 1.5\\pi $, at $ G = 0.30,\\ 0.35 $ and high wavelength $ \\lambda^* > 5 $.\n\t\n\t\n\t%\n\t%\n\t\n\t\n\t\\newcommand{\\addlabelb}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node [anchor=west] at (0.16,0.9) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcommand{\\addlabelbtop}[4]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node [anchor=west] at (0.16,0.9) {#3};\t%\n\t\t\t\t\\node [anchor=west] at (0.16,1.05) {#4};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcounter{testb}\n\t\\setcounter{testb}{0}\n\t\\newcommand\\counterb{\\stepcounter{testb}\\alph{testb}}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\addlabelbtop{0.49}{Figure\/matlab_print\/C_Tm_G=0.25__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.25 $}{$ D = 0 $}\n\t\t\\addlabelb{0.49}{Figure\/matlab_print\/C_Lrms_G=0.25__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.25 $}\n\t\t%\n\t\t\n\t\t\\addlabelb{0.49}{Figure\/matlab_print\/C_Tm_G=0.30__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.30 $}\n\t\t\\addlabelb{0.49}{Figure\/matlab_print\/C_Lrms_G=0.30__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.30 $}\n\t\t%\n\t\t\n\t\t\\addlabelb{0.49}{Figure\/matlab_print\/C_Tm_G=0.35__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.35 $}\n\t\t\\addlabelb{0.49}{Figure\/matlab_print\/C_Lrms_G=0.35__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.35 $}\n\t\t%\n\t\t\n\t\t\\includegraphics[width=0.9\\linewidth]{Figure\/matlab_print\/legend_phi_leader_follower}\n\t\t\n\t\t\\caption{Variation of (a \\& c \\& e) mean thrust force $ C_{Tm} $, (b \\& d \\& f) RMS lateral force $ C_{Lrms} $ with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, while side-by-side distance $ D = 0 $, phase difference $ \\phi = 0 - 1.5 \\pi $, and gap distance (a-b) $ G = 0.25 $, (c-e) $ G = 0.30 $, and (e-f) $ G = 0.35 $. Each row of sub-figures demonstrates the results from the same gap distance $ G $ between the two foils. }\n\t\t\\label{fig:lines_D_0_CT_CL}\n\t\\end{figure}\n\t\n\t\\setcounter{testb}{0}\n\t\\newcommand{\\addlabelbb}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node at (0.60,0.25) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcommand{\\addlabelbbtop}[4]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node at (0.60,0.25) {#3};\t%\n\t\t\t\t\\node [anchor=west] at (0.16,1.05) {#4};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\addlabelbbtop{0.49}{Figure\/matlab_print\/Froude_Coefficient_G=0.25__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.25 $}{$ D = 0 $}\n\t\t\\addlabelbb{0.49}{Figure\/matlab_print\/group_effi_G=0.25__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.25 $}\n\t\t\n\t\t\\addlabelbb{0.49}{Figure\/matlab_print\/Froude_Coefficient_G=0.30__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.30 $}\n\t\t\\addlabelbb{0.49}{Figure\/matlab_print\/group_effi_G=0.30__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.30 $}\n\t\t\n\t\t\\addlabelbb{0.49}{Figure\/matlab_print\/Froude_Coefficient_G=0.35__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.35 $}\n\t\t\\addlabelbb{0.49}{Figure\/matlab_print\/group_effi_G=0.35__D=0.00_all_phi_lamda}{(\\counterb) $ G = 0.35 $}\n\t\t\n\t\t\n\t\t\\includegraphics[width=1.0\\linewidth]{Figure\/matlab_print\/legend_phi_leader_follower_group}\n\t\t\n\t\t\n\t\t\\caption{Variation of (a \\& c \\& e) propeller efficiency $ \\eta $ and (b \\& d \\& f) group efficiency $ \\eta_{group} $ with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, while side-by-side distance $ D = 0 $, phase difference $ \\phi = 0 - 1.5 \\pi $, and gap distance (a-b) $ G = 0.25 $, (c-d) $ G = 0.30 $, and (e-f) $ G = 0.35 $.}\n\t\t\\label{fig:lines_D_0_eta}\n\t\\end{figure}\n\t\n\t%\n\t\n\t\\subsubsection{Vorticity distribution at $ D = 0 $}\n\t\\label{subsec:vor_Dis0}\n\t%\n\t%\n\tIn this section, the distribution of vorticity $ \\omega^* $ is observed to reveal the fluid-structure interaction mechanism underlying the aforementioned patterns regarding the thrust force and swimming economy of the schooling hydrofoils.\n\t%\n\t\n\t%\n\tWavelength $ \\lambda^* $ is positively correlated with shed vortices' intensity and scattering area, as seen in \\Cref{fig:vort_overview_lam_var}.\n\tAt low wavelength $ \\lambda^* = 0.8 $ in \\Cref{fig:vort_overview_lam_var}a, the vortex shedding is distributed in a narrow band at the downstream side of the schooling foils, indicating better stealth performance for low-wave-length swimmers.\n\tWith a longer wavelength $ \\lambda^* $, the wake vortices can disturb a larger area, with the flow structure becoming increasingly complicated.\n\tOne vortex dipole, \\ie a pair of opposite-sign vortices, is generated in each undulation cycle. The interaction between the shed dipoles becomes more unsteady with a larger wavelength $ \\lambda^* $ (see \\Cref{fig:vort_overview_lam_var}) and a smaller gap distance $ G $ (see \\Cref{fig:vor_wake_G_phi}).\n\t\n\t%\n\tAt phalanx arrangement $ D = 0 $ and anti-phase $ \\phi\/\\pi = 1 $, vorticity distribution is examined in \\Cref{fig:vor_inst_phalanx_anti_phase} to seek the underlying mechanism of the irregular force output, aforementioned in \\Cref{sec:phalanx_D0}. Here, the two swimmers form a mirror symmetry geometry at any moment during the undulation process.\n\tHowever, the consequent flow pattern does not always remain symmetrical through the development of time; this symmetry breaking phenomenon tends to occur with a higher wavelength.\n\tAt low undulation wavelength $ \\lambda^* = 0.8 $, the flow pattern is symmetrical in the initial periods, and the symmetry breaking only gradually becomes observed after the 6th period of undulation $ t^*\/T = 6 $.\n\tAt high wavelength $ \\lambda^* \\geq 2.0 $, the wake flow becomes highly irregular within merely 1 or 2 initial periods of undulation; the chaotic flow structure occurs very close to the tails of the undulating fish, thus causing the fluctuation in the output thrust and lateral force (further discussed in \\Cref{subsec:FSI_Dis0}). Across various $ \\lambda^* $, the propulsive performance measurements such as thrust force are highly consistent with the symmetric features of the near field wake structure.\n\t\\cite{Gungor2020} also discovered similar symmetry breaking phenomenon of two hydrofoils pitching in anti-phase, though only with infinite wavelength $ \\lambda^* = + \\infty $ at $ Re = 4000 $ and $ St = 0.25 - 0.5 $.\n\tIn summary, the irregularity of the flow structure tends to increase with undulation wavelength $ \\lambda^* $.\n\t\n\t\n\t%\n\t\n\tAt low wavelength $ \\lambda^* $, the gap distance $ G $ and phase difference $ \\phi $ can affect the skewness, symmetry and regularity of the wake pattern, as demonstrated in \\cref{fig:vor_wake_G_phi}.\n\tIt is interesting to observe that at $ \\phi\/\\pi = 0.5 $ and $ \\phi\/\\pi = 1.5 $, the vortex shedding direction is slightly skewed towards the right and left sides of the swimming direction, respectively.\n\tAt $ \\phi\/\\pi = 1.0 $, the flow structure is symmetrical due to the anti-phase undulation of the hydrofoils. The intensity of the vortices decreases with a larger gap distance $ G $. With a small gap distance $ G = 0.25 $, the vortices are distributed in a narrower band of wake flow, i.e. the dynamic energy is more concentrated at $ G = 0.25 $; in contrast, the decrease in gap distance $ G $ is relatively less effective in cases with other phase differences $ \\phi $.\n\tAt $ \\phi\/\\pi = 0 $, mixture of vortices is observed at $ G = 0.25 $, whereas at $ G \\geq 0.30 $, the mixture does not occur.\n\tIn summary, at low wavelength $ \\lambda^* = 0.8 $, the distribution of vortices is subtly affected by the gap distance and phase difference; concentration of dynamic energy is discovered at low gap distance and when the two hydrofoils swim in anti-phase.\n\t\n\t\n\t%\n\t\n\t%\n\t\\newcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4cm 1cm 0.5cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.8) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcounter{testaa}\n\t\\setcounter{testaa}{0}\n\t\\newcommand\\counteraa{\\stepcounter{testaa}\\alph{testaa}}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8 $}\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0 $}\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam03.200_Num_0000}{(\\counteraa) $ \\lambda^* = 3.2 $}\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam04.400_Num_0000}{(\\counteraa) $ \\lambda^* = 4.4 $}\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam05.600_Num_0000}{(\\counteraa) $ \\lambda^* = 5.6 $}\n\t\t\\addlabelvor{0.49}{Figure\/ps_format\/g0.25d0.00p0.00e5000.0s0.4r101_Lam06.800_Num_0000}{(\\counteraa) $ \\lambda^* = 6.8 $}\n\t\t\\caption{\n\t\t\tVariation of hydrofoil geometry and vorticity contours at time $ t^*\/T = 5 $ with $ G = 0.25 $, $ D = 0 $, $ \\phi = 0 $, and (a) $ \\lambda^* = 0.8 $ (b) $ \\lambda^* = 2.0 $ (c) $ \\lambda^* = 3.2 $ (d) $ \\lambda^* = 4.4 $ (e) $ \\lambda^* = 5.6 $ (f) $ \\lambda^* = 6.8 $. In general, intensity and scattering angle of wake vorticity distribution increase with wavelength $ \\lambda^* $, indicating better stealth performance for low-wave-length swimmers.\n\t\t\t%\n\t\t}\n\t\t\\label{fig:vort_overview_lam_var}\n\t\\end{figure}\n\t\n\t\n\t%\n\t\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_TimePeriod_1.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 0.8,\\ t^*\/T = 1 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam02.000_TimePeriod_1.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 2.0,\\ t^*\/T = 1 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam08.000_TimePeriod_1.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 8.0,\\ t^*\/T = 1 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_TimePeriod_2.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 0.8,\\ t^*\/T = 2 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam02.000_TimePeriod_2.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 2.0,\\ t^*\/T = 2 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam08.000_TimePeriod_2.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 8.0,\\ t^*\/T = 2 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_TimePeriod_3.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 0.8,\\ t^*\/T = 3 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam02.000_TimePeriod_3.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 2.0,\\ t^*\/T = 3 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam08.000_TimePeriod_3.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 8.0,\\ t^*\/T = 3 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_TimePeriod_4.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 0.8,\\ t^*\/T = 4 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam02.000_TimePeriod_4.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 2.0,\\ t^*\/T = 4 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam08.000_TimePeriod_4.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 8.0,\\ t^*\/T = 4 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_TimePeriod_5.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 0.8,\\ t^*\/T = 5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam02.000_TimePeriod_5.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 2.0,\\ t^*\/T = 5 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_fig_check_instants\/g0.25d0.00p1.00e5000.0s0.4r107_Lam08.000_TimePeriod_5.0_CopyNum_0000}{(\\counteraa) $ \\lambda^* = 8.0,\\ t^*\/T = 5 $}\n\t\t\n\t\t\\setcounter{testaa}{0}\n\t\t\\caption{\n\t\t\tVorticity contours and hydrofoil deformation at phalanx arrangement $ D = 0 $, lateral gap $ G = 0.25 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants (a-c) $ t^*\/T = 1 $ (d-f) $ t^*\/T = 2 $ (g-i) $ t^*\/T = 3 $ (j-l) $ t^*\/T = 4 $ (m-o) $ t^*\/T = 5 $ with various wavelengths (a \\& d \\& g \\& j \\& m) $ \\lambda^* = 0.8 $ (b \\& e \\& h \\& k \\& n) $ \\lambda^* = 2.0 $ (c \\& f \\& i \\& l \\& o) $ \\lambda^* = 8.0 $.\n\t\t\t%\n\t\t}\n\t\t\\label{fig:vor_inst_phalanx_anti_phase}\n\t\\end{figure}\n\t\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.25d0.00p0.00e5000.0s0.4r101_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.25 $, $ \\phi\/\\pi = 0 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.30d0.00p0.00e5000.0s0.4r102_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.30 $, $ \\phi\/\\pi = 0 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.35d0.00p0.00e5000.0s0.4r103_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.35 $, $ \\phi\/\\pi = 0 $}\n\t\t\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.25d0.00p0.50e5000.0s0.4r104_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.25 $, $ \\phi\/\\pi = 0.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.30d0.00p0.50e5000.0s0.4r105_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.30 $, $ \\phi\/\\pi = 0.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.35d0.00p0.50e5000.0s0.4r106_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.35 $, $ \\phi\/\\pi = 0.5 $}\n\t\t\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.25d0.00p1.00e5000.0s0.4r107_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.25 $, $ \\phi\/\\pi = 1.0 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.30d0.00p1.00e5000.0s0.4r108_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.30 $, $ \\phi\/\\pi = 1.0 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.35 $, $ \\phi\/\\pi = 1.0 $}\n\t\t\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.25d0.00p1.50e5000.0s0.4r110_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.25 $, $ \\phi\/\\pi = 1.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.30d0.00p1.50e5000.0s0.4r111_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.30 $, $ \\phi\/\\pi = 1.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/d0_00_check\/g0.35d0.00p1.50e5000.0s0.4r112_Lam00.800_Num_0000}{(\\counteraa) $ G = 0.35 $, $ \\phi\/\\pi = 1.5 $}\n\t\t\n\t\t\\setcounter{testaa}{0}\n\t\t\\caption{\n\t\t\tVorticity contours and hydrofoil deformation at instant $ t^*\/T = 5 $ with $ G = 0.35 $, $ D = 0 $, (a-c) $ \\phi\/\\pi = 0 $ (d-f) $ \\phi\/\\pi = 0.5 $ (g-i) $ \\phi\/\\pi = 1.0 $ (j-l) $ \\phi\/\\pi = 1.5 $. (a \\& d \\& g \\& j) $ G = 0.25 $ (b \\& e \\& h \\& k) $ G = 0.30 $ (c \\& f \\& i \\& l) $ G = 0.35 $.\n\t\t\tAt low wavelength $ \\lambda^* = 0.8 $, the distribution of vortices is subtly affected by the gap distance and phase difference; concentration of dynamic energy is discovered at low gap distance for anti-phase cases.\n\t\t}\n\t\t\\label{fig:vor_wake_G_phi}\n\t\\end{figure}\n\t\n\t\n\t\n\t\\subsubsection{Flow-mediated interaction between two swimmers at $ D = 0 $}\n\t\\label{subsec:FSI_Dis0}\n\t%\n\t%\n\tFor the anti-phase $ \\phi\/\\pi = 1 $ scenarios, the results are analysed in detail for wavelengths $ \\lambda^* = 0.8,\\ 2.0,\\ 8.0 $ with the help of \\Cref{fig:vor_1T_D0_lam0d8,fig:vor_1T_D0_lam2d0,fig:vor_1T_D0_lam8d0}, where the time history of thrust $ C_T $ and the lateral force $ C_L $ upon the foils are examined together with vorticity distribution at corresponding instants within 1 period of deformation. This configuration of $ D = 0 $ and $ \\phi\/\\pi = 1 $ is justified by the observation from \\cite{Ashraf2017} that schooling fish tend to form a simple side-by-side pattern with the characteristics of synchronised tail-beating with either in-phase or anti-phase swimming modes. \\cite{Ashraf2017} previously observed the fish schooling of a single wavelength of red nose tetra \\textit{Hemigrammus Rhodostomus}. Strong vortex interaction has been identified at low gap distance $ G = 0.25 $ and anti-phase cases $ \\phi\/\\pi = 1 $ in \\Cref{subsec:vor_Dis0}.\n\tWe thus further investigate the effects of wavelengths across 3 typical values $ \\lambda^* = 0.8,\\ 2,\\ 8 $.\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\newcommand{\\addlabelnotrim}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={0cm 0cm 0cm 0cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.1,-0.03) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam00.800_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.00_Lam=0.80_anti_phi}{(i) Bottom}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.00_Lam=0.80_anti_phi}{(j) Top}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 0.8 $, side-by-side arrangement $ D = 0 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Bottom and (j) Top swimmers.}\n\t\t\\label{fig:vor_1T_D0_lam0d8}\n\t\\end{figure}\n\t\n\t%\n\t\n\t%\n\tThe swimming deformation of the foils is an overlap of both lateral pitching motion and travelling sinusoidal wave. At low wavelength $ \\lambda^* = 0.8 $, the component of the travelling wave becomes more significant with a wavy appearance shown in \\Cref{fig:vor_1T_D0_lam0d8}.\n\tFor the single foil swimming cases \\citep{Thekkethil2018}, two vortices of opposite signs are shed in each cycle of undulation. In the present case of two side-by-side foils undulating in anti-phase, strong but symmetrical interference is discovered between the vortices generated by each foil, as seen in \\Cref{fig:vor_1T_D0_lam0d8}.\n\tIn the \\textit{outward} movement of the swimmers' tail tips, as demonstrated in \\Cref{fig:vor_1T_D0_lam0d8}a-\\ref{fig:vor_1T_D0_lam0d8}d, each of the two foils produces a vortex of opposite signs, temporarily forming a vortex pair. Meanwhile, the travelling wave deforming the foils propels the fluid between the two foils, pushing these two vortices downstream.\n\tDuring the \\textit{inward} phase of the tail tip movement, \\ie \\Cref{fig:vor_1T_D0_lam0d8}e-\\ref{fig:vor_1T_D0_lam0d8}h, each foil sheds one more vortex, which, in the next cycle, gradually forms a vortex dipole by pairing with the previous vortex from the same foil, \\ie \\Cref{fig:vor_1T_D0_lam0d8}a-\\ref{fig:vor_1T_D0_lam0d8}d. Eventually, the vortex dipoles from each of the two foils repel their counterparts and travel laterally away from each other, forming a highly symmetrical pattern of vortex dipoles in the downstream area.\n\t%\n\tCorresponding to the high level of symmetry in flow structure, the thrust of two foils are identical through the variation of time $ C_{T,1} = C_{T,2} $, indicating the two foils reach a stable formation and propel in a synchronised manner, as seen in \\Cref{fig:vor_1T_D0_lam0d8}i and \\ref{fig:vor_1T_D0_lam0d8}j. The lift force of the two foils are opposite to each other as $ C_{L,1} = -C_{L,2} $, which also periodically switches direction; so the two foils repel each other at instants \\Cref{fig:vor_1T_D0_lam0d8}a-\\ref{fig:vor_1T_D0_lam0d8}d while attracting each other at instants \\Cref{fig:vor_1T_D0_lam0d8}e-\\ref{fig:vor_1T_D0_lam0d8}h.\n\t\n\t\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam02.000_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.00_Lam=2.00_anti_phi}{(i) Bottom}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.00_Lam=2.00_anti_phi}{(j) Top}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 2.0 $, side-by-side arrangement $ D = 0 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Bottom and (j) Top swimmers.}\n\t\t\n\t\t\\label{fig:vor_1T_D0_lam2d0}\n\t\\end{figure}\n\t\n\tAt intermediate wavelength $ \\lambda^* = 2 $, the highest energy efficiency can be obtained as previously discussed. Here, we further analyse its vorticity contour in order to study its flow structure and fluid mediated interaction.\n\tSimilar to low wavelength cases, generation of vortices is governed by the tail tip movement. When the tail tip moves \\textit{outward} in \\Cref{fig:vor_1T_D0_lam2d0}c-\\ref{fig:vor_1T_D0_lam2d0}f, each foil generates a vortex in the near-tail region. During the \\textit{inward} phase shown in \\Cref{fig:vor_1T_D0_lam2d0}g-\\ref{fig:vor_1T_D0_lam2d0}h and \\Cref{fig:vor_1T_D0_lam2d0}a-\\ref{fig:vor_1T_D0_lam2d0}b, the vortices on the outer side of each foil are generated as well. The vortex dipoles eventually form a streaming direction that points downstream, enhancing the propulsion of the swimmers.\n\tIt is also interesting to notice that at $ \\lambda^* = 2 $, the velocity of shed vortex dipoles is almost 2 times of that at $ \\lambda^* = 0.8 $. \n\tThe thrust and lateral force generally follows the same pattern as the low wavelength scenario at $ \\lambda^* = 0.8 $.\n\t\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.00p1.00e5000.0s0.4r109_Lam08.000_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.00_Lam=8.00_anti_phi}{(i) Bottom}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.00_Lam=8.00_anti_phi}{(j) Top}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 8.0 $, side-by-side arrangement $ D = 0 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Bottom and (j) Top swimmers.}\n\t\t\\label{fig:vor_1T_D0_lam8d0}\n\t\\end{figure}\n\t\n\t%\n\tAt large wavelength $ \\lambda^* = 8.0 $, the swimming motion of the foils consists mainly of pitching rather than undulation, as seen in \\Cref{fig:vor_1T_D0_lam8d0}.\n\tDue to the anti-phase setting $ \\phi\/\\pi = 1 $, the pitching of two swimmers periodically switches between \\textit{outward} and \\textit{inward} movement.\n\t%\n\tThe \\textit{outward} motion creates a vortex dipole between the tails of the two swimmers, as shown in \\Cref{fig:vor_1T_D0_lam8d0}a-\\ref{fig:vor_1T_D0_lam8d0}d. During the outward movement, the dipole stays near the tail region despite the streaming flow. \n\t%\n\tThe \\textit{inward} motion, \\ie \\Cref{fig:vor_1T_D0_lam8d0}e-\\ref{fig:vor_1T_D0_lam8d0}h, then pushes out the vortex dipole while creating two vortices at each outer side of the two foils. A strong jet flow is also produced.\n\t%\n\tIn this period of motion, the flow symmetry gradually breaks, causing an increasingly complicated flow structure, which corresponds to the unsteady thrust $ C_{Tm} $ and lateral $ C_{Lrms} $ force as seen in \\Cref{fig:vor_1T_D0_lam8d0}i and \\ref{fig:vor_1T_D0_lam8d0}j. The symmetry breaking typically occurs at the instant $ t^*\/T = 2.25 $ in \\Cref{fig:vor_1T_D0_lam8d0}c, where the large vortex dipole is broken into multiple small vortices.\n\t%\n\tIn addition to the near-tail vortex dipole, two relatively small vortices emerge from the outer sides of the each foil, and then travels along the surface of the foils. The generation of these outer minor vortices starts to generate at the later phase of the inward pitching movement at instant $ t^*\/T = 2.75 $ \\Cref{fig:vor_1T_D0_lam8d0}g and instant $ t^*\/T = 2.875 $ \\ref{fig:vor_1T_D0_lam8d0}h, and then remains almost static in the outward pitching motion at \\Cref{fig:vor_1T_D0_lam8d0}a-\\ref{fig:vor_1T_D0_lam8d0}d; the displacement of these minor vortices takes place during the inward motion at \\Cref{fig:vor_1T_D0_lam8d0}e-\\ref{fig:vor_1T_D0_lam8d0}h.\n\tThis phenomenon is only observed in the anti-phase cases with high wavelength in the tested parametric space.\n\tIn addition, the broken symmetry corresponds to the irregular thrust force at anti-phase condition, as depicted in \\Cref{fig:lines_D_0_CT_CL}.\n\t\n\t\n\t\n\t\n\t\n\t%\n\t%\n\t%\n\t%\n\t\\newcommand{\\addlabelc}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=west] at (0.16,0.9) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\n\t\\newcommand{\\addlabelctop}[4]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=west] at (0.16,0.9) {#3};\t%\n\t\t\t\t\\node[anchor=west] at (0.14,1.05) {#4};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\n\t\\newcounter{testa}\n\t\\setcounter{testa}{0}\n\t\\newcommand\\countera{\\stepcounter{testa}\\alph{testa}}\n\t\n\t\n\t\n\t\\newcommand{\\addlabeld}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node at (0.60,0.25) {#3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\n\t\\setcounter{testa}{0}\n\t\n\t\n\t\\subsubsection{Summary for side-by-side $ D = 0 $ cases}\n\t\n\t\n\t%\n\tIn this section, we summarise the hydrodynamic characteristics of side-by-side cases, \\ie $ D = 0 $. The discussed content includes the thrust and lateral force, propeller and group efficiency, vorticity distribution and corresponding force time histories.\n\t%\n\t\n\t%\n\t%\n\t\\textit{Thrust and lateral force} is identical for the two foils, \\ie $ C_{Tm,1} = C_{Tm,2} $ and $ C_{Lrms,1} = C_{Lrms,2} $, at in-phase or anti-phase conditions $ \\phi\/\\pi = 0,\\ 1 $. However, such consistency is disrupted at high wavelengths $ \\lambda^* > 4 $, due to the high irregularity in flow structure.\n\tThrust and lateral force of both foils generally increase with wavelength $ \\lambda^* $.\n\tAt $ \\lambda^* > 1 $, the hydrodynamic force $ C_{Tm} $ and $ C_{Lrms} $ is highly sensitive to phase difference $ \\phi\/\\pi $. Hydrodynamic force at anti-phase $ \\phi\/\\pi = 1 $ can reach 6 times of that at in-phase $ \\phi\/\\pi = 0 $. When the two swimmers school at a relatively large lateral distance $ G = 0.35 $, the impact of phase difference $ \\phi $ is reduced, whereas the flow stability is increased.\n\t%\n\t\\textit{Propeller efficiency} for each individual foil $ \\eta_{1,2} $ or two foils as a group $ \\eta_{group} $ generally reaches maximum at $ \\lambda^* = 2 $.\n\tHighest group efficiency is obtained at intermediate wavelength $ \\lambda^* = 2 $, phase difference $ \\phi\/\\pi = 0.5,\\ 1.5 $ and relatively high lateral distance $ G = 0.35 $.\n\tThe influence of phase difference $ \\phi\/\\pi $ can be more significant than wavelength $ \\lambda^* $.\n\t\n\t%\n\t%\n\t%\n\t\n\t\\textit{Vorticity distribution} $ \\omega^* $ is reviewed to understand the flow structure around the two wavy foils.\n\tWavelength $ \\lambda^* $ is positively correlated with shed vortices' intensity and the disturbed area. Vortex dipoles are generated during foil undulation\/pitching.\n\tAt anti-phase $ \\phi\/\\pi = 1 $, vorticity distribution can be symmetrical, since the two swimmers form a mirror symmetry geometry at any moment during the undulation process.\n\tHowever, symmetry breaking can occur after a number of initial periods; higher wavelength leads to broken symmetry in fewer starting periods.\n\tThe irregularity of the flow structure tends to increase with undulation wavelength $ \\lambda^* $.\n\tAt low wavelength $ \\lambda^* $, the gap distance $ G $ and phase difference $ \\phi $ can affect the skewness, symmetry and regularity of the wake pattern.\n\tAt $ \\phi\/\\pi = 0.5 $ and $ \\phi\/\\pi = 1.5 $, the vortex shedding direction is slightly skewed towards the right and left sides of the swimming direction, respectively.\n\tThe intensity of the vortices decreases with a larger gap distance $ G $.\n\tConcentration of dynamic energy is discovered at low gap distance and when the two hydrofoils swim in anti-phase.\n\t\n\t\n\t\n\t%\n\t\n\t\n\t\n\t\n\t%\n\t%\n\t%\n\t%\n\t\n\tAt side-by-side arrangement $ D = 0 $, anti-phase $ \\phi\/\\pi = 1 $ and wavelengths $ \\lambda^* = 0.8,\\ 2.0,\\ 8.0 $, within one cycle of undulation, flow structure at 8 instants is examined with corresponding time histories of thrust $ C_T $ and lateral $ C_L $ force upon the foils.\n\t%\n\tAt \\textit{low wavelength} $ \\lambda^* = 0.8 $, strong symmetrical interference exists between the vortices shed by each foil.\n\tThe vortex dipoles from each foil repel their counterparts from another foil and travel laterally away from each other, forming a highly symmetrical pattern of vortex dipoles in the downstream area.\n\t%\n\tAt \\textit{intermediate wavelength} $ \\lambda^* = 2 $, vortex dipoles causes a streaming direction that directly points downstream, enhancing the propulsion of the swimmers.\n\tThe velocity of shed vortex dipoles is about 2 times of that at $ \\lambda^* = 0.8 $.\n\t%\n\tAt \\textit{large wavelength} $ \\lambda^* = 8.0 $, the flow symmetry breaks at $ t^*\/T = 2.25 $, causing a complicated flow structure.\n\t%\n\tTwo additional small vortices emerge from the outer sides of each foil and then travels along the foil surface.\n\t%\n\tThe \\textit{thrust} force of two foils is generally identical through the time histories as $ C_{T,1} = C_{T,2} $ with the \\textit{lift} force being opposite as $ C_{L,1} = -C_{L,2} $, which also periodically switches direction. The force time histories are smooth at low and intermediate wavelengths $ \\lambda^* = 0.8 - 2 $, but fluctuates at high wavelength $ \\lambda^* = 8 $ due to irregularity in flow field.\n\t\n\t\n\t%\n\t%\n\t%\n\t%\n\t\n\t\n\t%\n\t\\subsection{Staggered arrangement $ D > 0 $}\n\t\\label{sec:Staggered_Dg0}\n\t\n\t\n\tThis section discusses the situation when the two swimmers are placed in a staggered arrangement $ D > 0 $.\n\t\\Cref{subsec:F_eta_Dg0} studies how the non-dimensional parameters affect the leader\/follower's mean thrust force $ C_{Tm} $, RMS lateral force $ C_{Lrms} $, propeller efficiency $ \\eta $, and group efficiency $ \\eta_{group} $.\n\t\\Cref{subsec:FSI_Dg0} examines the variation of flow structure with wavelength $ \\lambda^* $, phase difference $ \\phi $, front-back distance $ D $ and their inter-relationships.\n\t\\Cref{subsec:vor_Dis0} investigates the flow-mediated interaction between the two swimmers with the help of vorticity contours and hydrodynamic force time histories.\n\t\n\t\\subsubsection{Hydrodynamic force and propulsive efficiency at $ D > 0 $}\n\t\\label{subsec:F_eta_Dg0}\n\t\n\t%\n\t%\n\t\n\t%\n\t%\n\tFor both the leader and the follower, mean \\textit{thrust force} $ C_{Tm} $ generally increases with the wavelength $ \\lambda^* $ in the tested parametric space of $ G = 0.25 - 0.35 $ and $ D = 0.25 - 0.75 $, as demonstrated in \\Cref{fig:matrix_CTm}.\n\t%\n\t%\n\t%\n\t%\n\tThe follower can take great advantages of the schooling interaction through various wavelengths, especially at $ \\lambda^* \\geq 5.6 $.\n\tThis enhancement of the follower's thrust force $ C_{Tm} $ with $ \\lambda^* $ is most significant when the two foils undulate\/pitch in anti-phase $ \\phi\/\\pi = 1.0 $. For example, as seen in \\Cref{fig:matrix_CTm}a, great difference is observed between the thrust force of the follower and that of the leader at the anti-phase $ \\phi\/\\pi = 1.0 $ cases with close distance $ G = 0.25,\\ D = 0.25 $. At high wavelength $ \\lambda^* $, follower's thrust force reach 4.5 times as large as the leader's. Generally speaking, this enhancement effect is activated by phase difference of $ \\phi\/\\pi = 1.0,\\ 1.5 $ across various lateral $ G $ and front-back $ D $ distances, as shown in \\Cref{fig:matrix_CTm}. The leader-follower thrust force difference decreases when the two swimmers are arranged at a further lateral $ G $ and front-back $ D $ distance.\n\t%\n\t%\n\t%\n\t%\n\tAlthough the follower's thrust force is generally larger than the leader's, exceptions are observed in a few cases.\n\t%\n\tAt $ D = 0.25 $ with relatively high wavelength $ \\lambda^* > 3 $, the thrust force upon the leader can become greater than the follower when the two swimmers undulates in-phase $ \\phi\/\\pi = 0 $.\n\tAt $ D = 0.50 $ with $ \\lambda^* > 5 $, leader's thrust is higher than the follower at $ \\phi\/\\pi = 0 $ and $ 0.5 $.\n\tAt $ D = 0.75 $ with $ \\lambda^* > 5 $, leader's thrust is higher than the follower only at $ \\phi\/\\pi = 0.5 $. \n\tLateral distance $ G $ does not significantly affects this trend. \n\tOn the contrary, at low wavelength $ \\lambda^* \\leq 2.0 $, the follower always take a greater advantage upon the thrust force compared with the leader.\n\t%\n\t%\n\t%\n\tHere, we offer a more general overview regarding the effects of phase difference with the help of \\Cref{fig:matrix_CTm}. \n\tPhase difference $ \\phi $ can significantly affect the follower's net thrust force while its effects on the leader is less prominent. The effect of the phase difference becomes less significant with the enlargement of the lateral gap $ G $ and the front-back distance $ D $, as demonstrated by the converging values of $ C_{Tm} $ from \\Cref{fig:matrix_CTm}a to \\ref{fig:matrix_CTm}i. The variation of $ \\phi $ is more influential at high wavelength $ \\lambda^* > 3 $ while being less effective at low wavelength $ \\lambda^* \\leq 2 $.\n\t\n\t%\n\t\\newcommand{\\addlabele}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.15,0.80) {\\footnotesize #3};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\setcounter{testa}{0}\n\t\t\\centering\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.25__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.30__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.35__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.25$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.25__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.30__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.35__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.50$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.25__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.30__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Tm_G=0.35__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.75$}\n\t\t\n\t\t\\includegraphics[width=1.0\\linewidth]{Figure\/matlab_print\/legend_phi_leader_follower}\n\t\t\n\t\t\\caption{\n\t\t\tVariation of \\textit{mean thrust force} $ C_{Tm} $ for both leading swimmer (solid lines) and following swimmer (dashed lines) with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, leader-follower phase difference $ \\phi \/ \\pi = 0, 0.5, 1.0, 1.5 $ (denoted by marker types), front-back distance (a-c) $ D = 0.25 $, (d-f) $ D = 0.50 $, and (g-i) $ D = 0.75 $; lateral gap distance at (a \\& d \\& g) $ G = 0.25 $, (b \\& e \\& h) $ G = 0.30 $, (c \\& f \\& i) $ G = 0.35 $.\n\t\t\t%\n\t\t}\n\t\t\\label{fig:matrix_CTm}\n\t\t\n\t\\end{figure}\n\t\n\t\n\t\n\t\n\t\n\t\n\t\n\t%\n\t%\n\tThe RMS of \\textit{lateral force} $ C_{Lrms} $ increases monotonically with wavelength $ \\lambda^* $ despite the variation of other parameters, as seen in \\Cref{fig:matrix_CLrms}.\n\tThe lateral force greatly increases with the wavelength $ \\lambda^* $, reaching as high as $ C_{Lrms} = 18 $ for both swimmers, at short distance $ G = 0.25 $, $ D = 0.25 $ and anti-phase $ \\phi\/\\pi = 1 $, as shown in \\Cref{fig:matrix_CLrms}a.\n\t%\n\t%\n\tRegarding the effects of the phase difference $ \\phi $, the lateral force $ C_{Lrms} $ reaches {minimum} when the two hydrofoils swim {in-phase} $ \\phi\/\\pi = 0 $ while reaching {maximum} at {anti-phase} $ \\phi\/\\pi = 1 $ condition with front-back distance $ D \\leq 0.50 $, as seen in \\Cref{fig:lines_D_0_CT_CL}b and \\ref{fig:matrix_CLrms}. However, at $ D = 0.75 $, this relationship is reversed that the minimal $ C_{Lrms} $ is found at anti-phase condition whereas the maximal $ C_{Lrms} $ is discovered at in-phase scenarios. This observation can be postulated to be related with vortex shedding and its impingement upon the follower.\n\tAs the distances $ G $ and $ D $ increase, the phase difference $ \\phi $ becomes less influential upon the lateral force $ C_{Lrms} $ for both the leader and the follower, as shown in \\Cref{fig:matrix_CLrms}.\n\t%\n\t%\n\tWith the increase of lateral gap $ G $ and front-back distance $ D $, the difference of lateral force $ C_{Lrms} $ between the leader and the follower becomes smaller; as the lateral gap increases from $ G = 0.25 $ to $ 0.35 $ and the front-back distance rises from $ D = 0.25 $ to $ 0.75 $, the leader-follower lateral force difference decreases from $ 2.5 $ to $ 0.5 $, as seen in \\Cref{fig:matrix_CLrms}a to \\ref{fig:matrix_CLrms}i.\n\t%\n\tCompared with the large leader-follower difference for the thrust force $ C_{Tm} $ previously discussed, the leader-follower discrepancy in lateral force $ C_{Lrms} $ is relatively small, especially at short distances $ G = 0.25,\\ D = 0.25 $ indicating the thrust force is more sensitive to the schooling effect than the lateral force, across the tested wavelengths.\n\t\n\t\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testa}{0}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.25__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.30__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.35__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.25$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.25__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.30__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.35__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.50$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.25__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.30__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/C_Lrms_G=0.35__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.75$}\n\t\t\n\t\t\n\t\t\\includegraphics[width=1.0\\linewidth]{Figure\/matlab_print\/legend_phi_leader_follower}\n\t\t\n\t\t\\caption{Variation of \\textit{root mean square of lateral force} $ C_{Lrms} $ for both leader (solid lines) and follower (dashed lines) hydrofoils with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, leader-follower phase difference $ \\phi \/ \\pi = 0, 0.5, 1.0, 1.5 $ (denoted by marker types), front-back distance (a-c) $ D = 0.25 $, (d-f) $ D = 0.50 $, and (g-i) $ D = 0.75 $; lateral gap distance at (a \\& d \\& g) $ G = 0.25 $, (b \\& e \\& h) $ G = 0.30 $, (c \\& f \\& i) $ G = 0.35 $.}\n\t\t\\label{fig:matrix_CLrms}\n\t\\end{figure}\n\t\n\t\n\t\n\t\n\t\n\t%\n\t%\n\tThe individual \\textit{propeller efficiency} $ \\eta $ for each swimmer generally reaches minimum at wavelength $ \\lambda^* = 0.8 $ while peaking at $ \\lambda^* = 2.0 $, as seen in \\Cref{fig:matrix_LF_effi}. With a relatively high wavelength $ \\lambda^* > 2.0 $, phase lag $ \\phi $ affects how $ \\lambda^* $ influences the follower's propeller efficiency $ \\eta_{follower} $: at in-phase $ \\phi\/\\pi = 0 $ condition, $ \\eta_{follower} $ greatly decreases with wavelength $ \\lambda^* $; at $ \\phi\/\\pi = 0.5 $, the negative relationship between $ \\lambda^* $ and $ \\eta_{follower} $ is less significant than that at $ \\phi\/\\pi = 0 $; at $ \\phi\/\\pi = 1.0 $ and $ 1.5 $, the result generally remains constant regardless of the variation in $ \\lambda^* $.\n\t%\n\t%\n\t%\n\tThe increase in front-back distance $ D $ significantly reduces the propeller efficiency of the follower while slightly increasing the leader's efficiency. In the tested range of values, lateral gap $ G $ barely influences the propeller efficiency, being consistent with the conclusion by \\cite{Li2020}.\n\t%\n\tThe follower's efficiency $ \\eta_{follower} $ is generally higher than the leader's $ \\eta_{leader} $, most significantly at front-back distance $ D = 0.25 $ and phase lag $ \\phi\/\\pi = 1.5 $, as demonstrated in \\Cref{fig:matrix_LF_effi}a to \\ref{fig:matrix_LF_effi}c; the leader's propeller efficiency can only be slightly higher than the follower's at in-phase condition $ \\phi\/\\pi = 0 $ and high wavelength $ \\lambda^* > 7 $.\n\t%\n\tIn the present combinations of input parameters, the leader efficiency can be negative at $ \\lambda^* = 0.8 $ when the front-back distance is small $ D \\leq 0.50 $, meaning the leader is moving backwards along the flow direction. At $ D =0.75 $, the swimmers' efficiency is all positive except at $ \\phi\/\\pi = 1.0,\\ 1.5 $ with low wavelength $ \\lambda^* = 0.8 $.\n\t\n\t\\renewcommand{\\addlabele}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\textwidth]{#2}};\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.16,0.15) {\\footnotesize #3};\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\setcounter{testa}{0}\n\t\t\\centering\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.25__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.30__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.35__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.25$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.25__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.30__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.35__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.50$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.25__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.30__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/Froude_Coefficient_G=0.35__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.75$}\n\t\t\n\t\t\n\t\t\\includegraphics[width=1.0\\linewidth]{Figure\/matlab_print\/legend_phi_leader_follower}\n\t\t\\caption{Variation of {propeller efficiency} $ \\eta $ for leader (solid lines) and follower (dashed lines) hydrofoils with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, leader-follower phase difference $ \\phi \/ \\pi = 0, 0.5, 1.0, 1.5 $ (denoted by marker types), front-back distance (a-c) $ D = 0.25 $, (d-f) $ D = 0.50 $, and (g-i) $ D = 0.75 $; lateral gap distance at (a \\& d \\& g) $ G = 0.25 $, (b \\& e \\& h) $ G = 0.30 $, (c \\& f \\& i) $ G = 0.35 $.}\n\t\t\\label{fig:matrix_LF_effi}\n\t\\end{figure}\n\t\n\t\n\t\n\t\n\t\n\t%\n\t%\n\tThe \\textit{group efficiency} $ \\eta_{group} $ represents the effectiveness of energy conversion from lateral undulation to the thrust propulsion for the two interacting swimmers as a minimal school.\n\t%\n\tThe group efficiency $ \\eta_{group} $ reaches minimum at $ \\lambda^* = 0.8 $, peaks at $ \\lambda^* = 2.0 $, and then gradually approach a certain value at large wavelength $ \\lambda^* = 8.0 $; this pattern can be observed across all simulated cases.\n\tThe {group efficiency} $ \\eta_{group} $ reaches maximum at 33.3\\% with front-back distance $ D = 0.75 $ and wavelength $ \\lambda^* = 2.0 $.\n\t%\n\tIn the explored parametric space, $ \\eta_{group} $ generally increases with lateral gap $ G $ and front-back distance $ D $ across various wavelengths $ \\lambda^* $, as seen in \\Cref{fig:matrix_group_eta}. At low wavelength $ \\lambda^* = 0.8 $, the group efficiency is especially sensitive to front-back distance $ D $ but less sensitive to lateral distance $ G $, being consistent with the conclusions by \\cite{Li2020}.\n\t%\n\tThe increase of front-back distance $ D $ and lateral gap $ G $ leads to reduced sensitivity regarding phase lag $ \\phi $ across various wavelengths $ \\lambda^* = 0.8 - 8 $, as seen in \\Cref{fig:matrix_group_eta}i for the almost overlapped lines; this trend corresponds to the reduced difference in propeller efficiency $ \\eta $ between the leader and the follower, as seen in \\Cref{fig:matrix_group_eta}, implying reduced flow mediated interference between the two swimming foils.\n\t%\n\tAt low wavelength $ \\lambda^* = 0.8 $, the negative group efficiency is observed at front-back distance $ D \\leq 0.50 $ but not found in cases with $ D = 0.75 $.\n\t%\n\tIt is an indication that, for schooling Anguilliform swimmers, it can be critical to keep an appropriate front-back distance $ D $, which may even reverse the collective propulsive direction of the swimmer group; in contrast, the schooling performance for Carangiform or Thunniform swimmers with high wavelength $ \\lambda^* > 6 $ is more stable; its group efficiency does not vary significantly with phase lag $ \\phi $ and front-back distance. This is in support of the hypothesis that the Carangiform and Thunniform swimmers are more suitable for schooling in contrast with Anguilliform swimmers.\n\t\n\t\n\t\\begin{figure}\n\t\t\\setcounter{testa}{0}\n\t\t\\centering\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.25__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.30__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.25$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.35__D=0.25_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.25$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.25__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.30__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.50$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.35__D=0.50_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.50$}\n\t\t\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.25__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.25, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.30__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.30, D = 0.75$}\n\t\t\\addlabele{0.32}{Figure\/matlab_print\/group_effi_G=0.35__D=0.75_all_phi_lamda}{(\\countera) $ G = 0.35, D = 0.75$}\n\t\t\n\t\t\\includegraphics[width=0.9\\linewidth]{Figure\/matlab_print\/legend_phi_only_group}\n\t\t\\caption{Variation of {group efficiency} $ \\eta_{group} $ for the swimming group with a series of wavelength $ \\lambda^* = 0.8 - 8.0 $, leader-follower phase difference $ \\phi \/ \\pi = 0, 0.5, 1.0, 1.5 $ (denoted by marker types), front-back distance (a-c) $ D = 0.25 $, (d-f) $ D = 0.50 $, and (g-i) $ D = 0.75 $; lateral gap distance at (a \\& d \\& g) $ G = 0.25 $, (b \\& e \\& h) $ G = 0.30 $, (c \\& f \\& i) $ G = 0.35 $.}\n\t\t\\label{fig:matrix_group_eta}\n\t\\end{figure}\n\t\n\t\n\t\n\t\n\t\n\t%\n\t\\subsubsection{Vorticity distribution at $ D > 0 $}\n\t\\label{subsec:vor_Dg0}\n\t\n\t\n\tThe wavelength $ \\lambda^* $ and the phase lag $ \\phi $ influence the vortex strength and shedding pattern in different ways, as seen in \\Cref{fig:vor_lam_phi}.\n\t%\n\tAt $ \\lambda^* = 0.8 $, the general vortex shedding pattern is barely affected by the variation in phase difference $ \\phi $. The dipoles shed by the two foils hardly interact with each other, especially when the two foils swim in-phase $ \\phi = 0 $, as seen in \\Cref{fig:vor_lam_phi}a. The dipoles steadily drift downstream, meaning the streaming direction is stable as well.\n\tAt $ \\lambda^* = 2.0 $, significant interference between the dipoles leads to irregular flow structure in the downstream area of the two foils. However, in the area between the two foils, the flow structure is regular and predictable, indicating the interaction between the two foils should largely be periodical despite the complex pattern in the downstream. Phase lag $ \\phi $ can significantly affect the flow structure in the area immediately downstream the follower foil.\n\tAt $ \\lambda^* = 8.0 $, the flow pattern is similar to that at $ \\lambda^* = 2.0 $.\n\t%\n\t%\n\t%\n\tIn summary, despite subtle differences observed, the general wake flow pattern is not significantly affected by the phase difference $ \\phi $; this also corresponds to the results in \\Cref{fig:matrix_group_eta}.\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.69) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, \\phi\/\\pi = 0 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, \\phi\/\\pi = 0 $}\n\t\t%\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam06.800_Num_0000}{(\\counteraa) $ \\lambda^* = 8.0, \\phi\/\\pi = 0 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.50e5000.0s0.4r142_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, \\phi\/\\pi = 0.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.50e5000.0s0.4r142_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, \\phi\/\\pi = 0.5 $}\n\t\t%\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.50e5000.0s0.4r142_Lam06.800_Num_0000}{(\\counteraa) $ \\lambda^* = 8.0, \\phi\/\\pi = 0.5 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, \\phi\/\\pi = 1 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, \\phi\/\\pi = 1 $}\n\t\t%\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.00e5000.0s0.4r145_Lam06.800_Num_0000}{(\\counteraa) $ \\lambda^* = 8.0, \\phi\/\\pi = 1 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.50e5000.0s0.4r148_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, \\phi\/\\pi = 1.5 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.50e5000.0s0.4r148_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, \\phi\/\\pi = 1.5 $}\n\t\t%\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p1.50e5000.0s0.4r148_Lam06.800_Num_0000}{(\\counteraa) $ \\lambda^* = 8.0, \\phi\/\\pi = 1.5 $}\n\t\t\n\t\t\\setcounter{testaa}{0}\n\t\t\\caption{\n\t\t\tVorticity contours and hydrofoil deformation at instant $ t^*\/T = 5 $ with fixed relative distances $ G = 0.35 $, $ D = 0.75 $ and a variety of phase difference (a-c) $ \\phi\/\\pi = 0 $ (d-f) $ \\phi\/\\pi = 0.5 $ (g-i) $ \\phi\/\\pi = 1.0 $ (j-l) $ \\phi\/\\pi = 1.5 $ and various wavelengths (a \\& d \\& g \\& j) $ \\lambda^* = 0.8 $ (b \\& e \\& h \\& k) $ \\lambda^* = 2.0 $ (c \\& f \\& i \\& l) $ \\lambda^* = 6.8 $.\n\t\t}\n\t\t\\label{fig:vor_lam_phi}\n\t\\end{figure}\n\t\n\t\n\t\n\tIn order to examine the inter-relationship between wavelength $ \\lambda^* $, front-back distance $ D $, and wake flow structure, we draw the vorticity contours across various wavelengths $ \\lambda^* $ and front-back distances $ D $, as seen in \\Cref{fig:D0.25_0.75_wake_mixing}.\n\t%\n\t%\n\t%\n\tAt front-back distance $ D = 0.25 $, as seen in \\Cref{fig:D0.25_0.75_wake_mixing}a-\\ref{fig:D0.25_0.75_wake_mixing}c, the vortex dipoles shed by each hydrofoil do not mix in the wake flow, but bifurcating towards two distinct directions, forming an angle with a near-perfect mirror symmetry about the centreline. This symmetrically stable flow structure persists despite the variation of wavelengths $ \\lambda^* $. Such near-symmetrical patterns were only observed in cases with \\textit{phalanx} arrangement $ D = 0 $ and \\textit{anti-phase} $ \\phi\/\\pi = 1 $ condition, e.g.\\ cases discussed in \\Cref{subsec:vor_Dis0} and results from another paper focusing on wake symmetry by \\cite{Gungor2020}. It is therefore interesting to observe a very similar pattern at a \\textit{staggered} placement $ D = 0.25 $ with \\textit{in-phase} $ \\phi\/\\pi = 0 $ undulation.\n\t%\n\tTo explain this phenomenon, we further examine the underlying hydrodynamic mechanism. The front-back distance of $ D = 0.25 $ causes positive vortex from the present half-cycle of the follower to collide with the negative vortex from the previous half-cycle of the leader. These two vortices collide with each other but cannot merge together due to their opposite rotating direction, thus pushing each other away while drifting downstream, eventually leading to a steady flow structure with a certain angle. This periodic flow pattern does not lead to an outstanding thrust force or locomotion efficiency as previously discussed, yet it may contain implications for stealth capacity of the swimmers.\n\tAs for cases at $ D \\geq 0.50 $, the wake flow structure is more irregular due to unsteady interaction among dipoles, e.g.\\ some vortices merge together to form a larger one. The overall vorticity strength and the degree of irregularity both increase with the wavelengths $ \\lambda^* $. Although the wake flow is irregular for the cases at $ D \\geq 0.50 $, the flow structure near the two foils is largely predictable, especially in the area between the two foils.\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.25p0.00e5000.0s0.4r115_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, D = 0.25 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.25p0.00e5000.0s0.4r115_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, D = 0.25 $ }\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.25p0.00e5000.0s0.4r115_Lam03.200_Num_0000}{(\\counteraa) $ \\lambda^* = 3.2, D = 0.25 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.50p0.00e5000.0s0.4r127_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, D = 0.50 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.50p0.00e5000.0s0.4r127_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, D = 0.50 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.50p0.00e5000.0s0.4r127_Lam03.200_Num_0000}{(\\counteraa) $ \\lambda^* = 3.2, D = 0.50 $}\n\t\t\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam00.800_Num_0000}{(\\counteraa) $ \\lambda^* = 0.8, D = 0.75 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam02.000_Num_0000}{(\\counteraa) $ \\lambda^* = 2.0, D = 0.75 $}\n\t\t\\addlabelvor{0.32}{Figure\/ps_format\/g0.35d0.75p0.00e5000.0s0.4r139_Lam03.200_Num_0000}{(\\counteraa) $ \\lambda^* = 3.2, D = 0.75 $}\n\t\t\n\t\t\\setcounter{testaa}{0}\n\t\t\\caption{\n\t\t\tVorticity contours and hydrofoil deformation at instant $ t^*\/T = 5 $ with $ G = 0.35 $, $ \\phi = 0 $, (a-c) $ D = 0.25 $ (d-f) $ D = 0.50 $ (g-i) $ D = 0.75 $ (a \\& d \\& g) $ \\lambda^* = 0.8 $ (b \\& e \\& h) $ \\lambda^* = 2.0 $ (c \\& f \\& i) $ \\lambda^* = 3.2 $. \n\t\t}\n\t\t\\label{fig:D0.25_0.75_wake_mixing}\n\t\\end{figure}\n\t\n\t%\n\t\\subsubsection{Flow-mediated interaction between two swimmers at $ D > 0 $}\n\t\\label{subsec:FSI_Dg0}\n\t\n\t\n\t\n\t%\n\t%\n\t%\n\t%\n\t\n\t\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\renewcommand{\\addlabelnotrim}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={0cm 0cm 0cm 0cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.1,-0.03) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam00.800_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 0.8 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.75_Lam=0.80_anti_phi}{(i) Leader}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.75_Lam=0.80_anti_phi}{(j) Follower}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 0.8 $, side-by-side arrangement $ D = 0.75 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Leader and (j) Follower swimmers.}\n\t\t\\label{fig:vor_1T_D0d75_lam0d8}\n\t\\end{figure}\n\t\n\tAt $ D =0.75,\\ \\lambda^* = 0.8 $, the wake vorticity pattern looks as if each of the two foils swims as a single foil, \\ie interference between the wake flows by two foils are visibly insignificant, as viewed in \\Cref{fig:vor_1T_D0d75_lam0d8}a-\\ref{fig:vor_1T_D0d75_lam0d8}h.\n\t%\n\tHowever, large discrepancy of thrust force $ C_T $ is discovered between the two swimmers; the leader's thrust force is generally negative, whereas the follower's is on the whole positive, as seen in \\Cref{fig:vor_1T_D0d75_lam0d8}i and \\ref{fig:vor_1T_D0d75_lam0d8}j, indicating that the two foils are attracted towards each other due to the flow-mediated interaction.\n\tThe lateral force $ C_L $ of the two foils is dissimilar from each other, which is different from the almost symmetrical lateral force time history at higher wavelength $ \\lambda^* = 2,\\ 8 $. In other words, the lateral force is more sensitive to the flow-mediated interaction between the two swimmers. \n\tThis thrust and lateral force discrepancy may be further relevant to the pressure suction mechanism \\citep{Blickhan1992} that is most typical in low wavelength swimmers.\n\t\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam02.000_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 2.0 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.75_Lam=2.00_anti_phi}{(i) Leader}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.75_Lam=2.00_anti_phi}{(j) Follower}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 2.0 $, side-by-side arrangement $ D = 0.75 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Leader and (j) Follower swimmers.}\n\t\t\\label{fig:vor_1T_D0d75_lam2d0}\n\t\\end{figure}\n\t\n\t\n\tAt $ D =0.75,\\ \\lambda^* = 2 $, the leader's upward vortices collides with the the follower's vortex street, causing great disturbance in the wake flow of the follower, as seen in \\Cref{fig:vor_1T_D0d75_lam2d0}.\n\t\"Vortex swapping\" periodically takes place between the two foils, which is the swapping of positive vortices between the two swimmers: the leader's positive vortex from previous undulating cycle is entrained by the upward motion the follower's tail tip; eventually the leader's positive vortex pairs up with the follower's negative one, whereas the follower's positive vortex moves downward to pair with the leader's negative one.\n\t%\n\tThe thrust force $ C_{T} $ of the two swimmers demonstrates a phase difference of about $ T\/2 $, although the lateral force amplitude upon the follower is about 40\\% larger than the that upon the leader. Similar pattern is also observed in the case at $ \\lambda^* = 8 $, which will be discussed later.\n\t\n\t%\n\t%\n\t\n\t\n\t%\n\t\\renewcommand{\\addlabelvor}[3]{%\n\t\t\\begin{tikzpicture}\n\t\t\t\\node[anchor=south west,inner sep=0] (image) at (0,0) \n\t\t\t{\\includegraphics[width=#1\\linewidth, trim={4.05cm 1cm 1cm 1.25cm},clip]{#2}};%\n\t\t\t\\begin{scope}[x={(image.south east)},y={(image.north west)}]\n\t\t\t\t%\n\t\t\t\t\\node[anchor=south west] at (0.00,0.75) {\\footnotesize #3};\t%\n\t\t\t\\end{scope}\n\t\t\\end{tikzpicture}%\n\t}\n\t\\begin{figure}\n\t\t\\centering\n\t\t\\setcounter{testaa}{0}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.0_CopyNum_0000}{(a) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.00 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.5_CopyNum_0000}{(e) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.50 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.125_CopyNum_0000}{(b) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.125 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.625_CopyNum_0000}{(f) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.625 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.25_CopyNum_0000}{(c) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.25 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.75_CopyNum_0000}{(g) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.75 $}\n\t\t\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.375_CopyNum_0000}{(d) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.375 $}\n\t\t\\addlabelvor{0.49}{Figure\/Time_history_check\/g0.35d0.75p1.00e5000.0s0.4r145_Lam08.000_TimePeriod_2.875_CopyNum_0000}{(h) $ \\lambda^* = 8.0 $, $ t^*\/T = 2.875 $}\n\t\t\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Leader_G=0.35_D=0.75_Lam=8.00_anti_phi}{(i) Leader}\n\t\t\\addlabelnotrim{0.49}{Figure\/Time_history_check\/Time_History_of_Follower_G=0.35_D=0.75_Lam=8.00_anti_phi}{(j) Follower}\n\t\t\n\t\t\\caption{Vorticity contours and hydrofoil deformation with wavelength $ \\lambda^* = 8.0 $, side-by-side arrangement $ D = 0.75 $, lateral gap $ G = 0.35 $, anti-phase $ \\phi\/\\pi = 1.0 $ at instants of a typical period\n\t\t\t(a-h) $ t^*\/T = 2.00-2.875 $. Time histories of thrust and lift coefficient for the (i) Leader and (j) Follower swimmers.}\n\t\t\\label{fig:vor_1T_D0d75_lam8d0}\n\t\\end{figure}\n\t\n\t%\n\tAt $ D =0.75,\\ \\lambda^* = 8 $, the general flow structure is composed of several large vortices, as shown in \\Cref{fig:vor_1T_D0d75_lam8d0}, rather than being broken into numerous small ones, as previously seen in \\Cref{fig:vor_1T_D0_lam8d0}. Periodical interaction occurs in the region between the two foils, whereas in the wake flow, the vortex interaction is irregular and unpredictable.\n\t%\n\tIn the region between the two foils, the vortex pattern near the tail tip of the leader is very similar to that of a single pitching foil \\citep{Thekkethil2018}, whereas a small vortex is generated from the left side of the follower's head, as seen in \\Cref{fig:vor_1T_D0d75_lam8d0}a-\\ref{fig:vor_1T_D0d75_lam8d0}h and then in the next cycle, this small vortex merges with the large vortex produced by the tail pitching of the leader. The merging of small and large vortices is stably repeated in every cycle of pitching in spite of the irregular wake flow.\n\t%\n\tIn the wake flow region, with the strong disturbance produced by $ \\lambda^* = 8 $, the front-back distance $ D =0.75 $ allows the interaction of vortices generated from different cycles and different swimmers. The vortex dipoles may swap their partners if collision between the dipoles occurs; the consequent new pair may draw a unique trajectory that further disturbs the wake flow.\n\t%\n\tThe thrust and lateral force upon the two foils is smooth in general, as seen in \\Cref{fig:vor_1T_D0d75_lam8d0}i and \\ref{fig:vor_1T_D0d75_lam8d0}j, corresponding to the relatively regular flow structure near the tail regions of the two foils. The lift force of the two foils are just opposite to each other $ C_{L,1} = -C_{L,2} $, \\ie the amplitude of lift force is almost identical, yet the thrust force of the follower is generally larger than that of the leader. It is also interesting to note a half period phase difference between the leader and the follower's thrust force, which can only be caused by the interaction of vortex.\n\t\n\t\n\t\n\t%\n\t\n\t\\subsubsection{Summary for staggered $ D > 0 $ cases}\n\t\n\tThis section provides a summary of the hydrodynamic characteristics for two foils swimming in staggered arrangement $ D > 0 $. The upstream swimmer is identified as the leader, while the downstream one as the follower.\n\t\n\t\n\t%\n\tThrust force $ C_{Tm} $ for either swimmer generally increases with wavelengths $ \\lambda^* $.\n\tThe follower's thrust force can be much larger than the leader's, \\ie $ C_{Tm,follower} > C_{Tm,leader} $, especially at high $ \\lambda^* $ and $ \\phi\/\\pi = 1,\\ 1.5 $.\n\t%\n\tFor the follower, the maximum achievable thrust force by tuning phase lag $ \\phi $ decreases with both lateral $ G $ and front-back distances $ D $.\n\t%\n\tThe RMS of {lateral force} $ C_{Lrms} $ increases monotonically with wavelength $ \\lambda^* $, reaching as high as $ C_{Lrms} = 18 $ for both swimmers at short distances $ G = 0.25 $, $ D = 0.25 $ and anti-phase $ \\phi\/\\pi = 1 $.\n\t\n\t%\n\tPropeller efficiency of either foil $ \\eta_{1,2} $ or two foils as a group $ \\eta_{group} $ reaches minimum and maximum at $ \\lambda^* = 0.8 $ and $ \\lambda^* = 2 $, respectively, and then gradually decreases at $ \\lambda^* > 2 $.\n\tThe follower's efficiency $ \\eta_{follower} $ is generally higher than the leader's $ \\eta_{leader} $.\n\tPhase lag $ \\phi $ is more influential to the follower's efficiency than the leader's, especially at high wavelength $ \\lambda^* > 2 $ and close front-back distance $ D \\leq 0.5 $.\n\t%\n\t%\n\tThe follower's propeller efficiency significantly decreases with a further front-back distance $ D $, while slightly increasing the leader's.\n\t\n\t\n\t%\n\t%\n\tGroup efficiency $ \\eta_{group} $ reaches a maximum of $ 33.3\\% $ at $ D = 0.75 $ and $ \\lambda^* = 2.0 $.\n\t%\n\tGroup efficiency $ \\eta_{group} $ generally increases with lateral gap $ G $ and front-back distance $ D $ across various wavelengths $ \\lambda^* $.\n\tAt low wavelength $ \\lambda^* = 0.8 $, the group efficiency is especially sensitive to front-back distance $ D $, whereas effects of lateral gap $ G $ is less prominent.\n\t%\n\tPhase lag $ \\phi $ is more influential to group efficiency $ \\eta_{group} $ at close distances across tested wavelengths $ \\lambda^* = 0.8 - 8 $.\n\t\n\t\n\tVorticity distribution is examined to understand how various non-dimensional parameters affect the flow structure surrounding the two foils.\n\tThe overall vorticity strength and the degree of irregularity both increase with the wavelengths $ \\lambda^* $ with various front-back distance $ D $, whereas the general wake flow pattern is only slightly affected by the phase difference $ \\phi $.\n\tAt $ \\lambda^* = 0.8 - 3.2 $, $ D = 0.25 $, the vortex dipoles shed by each hydrofoil do not mix in the wake flow, but bifurcating towards 2 distinct directions, forming a mirror symmetry pattern.\n\t%\n\tAt $ D \\geq 0.50 $, the wake flow structure is more irregular due to unsteady interaction among dipoles that vortices can merge together to form a larger one.\n\t%\n\t\n\t\n\tFlow-mediated interaction mechanism is examined in 8 instants within 1 period at $ D = 0.75 $ with low, intermediate, and high wavelengths $ \\lambda^* = 0.8,\\ 2,\\ 8 $.\n\tThe staggered arrangement $ D > 0 $ allows vortices generated from different cycles of undulation\/pitching to interact with each other, leading to a phase lag in the thrust force history. Distinct flow structure and force variation emerges with the change of wavelengths $ \\lambda^* $.\n\tAt $ D =0.75,\\ \\lambda^* = 0.8 $, the wake vorticity pattern looks as if each of the two foils swims as a single foil.\n\t%\n\tAt $ D =0.75,\\ \\lambda^* = 2 $, the leader's upward vortices collides with the the follower's vortex street, causing great disturbance in the wake flow of the follower.\n\t\\textit{Vortex swapping} periodically takes place between the two foils.\n\tThe thrust force $ C_{T} $ of the two swimmers demonstrates a phase difference of about $ T\/2 $.\n\tAt $ D =0.75,\\ \\lambda^* = 8 $, the general flow structure is composed of several large vortices. Periodical interaction occurs in the region between the two foils, whereas in the wake flow, the vortex interaction is irregular and unpredictable.\n\t%\n\tIn the region between the two foils, the vortex pattern near the tail tip of the leader is very similar to that of a single pitching foil, whereas a small vortex is generated from the left side of the follower's head that eventually merges with the large vortex at tail. \n\t%\n\tIn the wake flow region, with the strong disturbance produced by $ \\lambda^* = 8 $, the front-back distance $ D =0.75 $ allows the interaction of vortices generated from different cycles and different swimmers. Vortex dipoles may swap their paired partners if collision occurs, further disturbing the wake flow.\n\t%\n\tThe thrust and lateral force upon the two foils is smooth in general, corresponding to the relatively regular flow structure near the tail regions of the two foils. The lift force of the two foils are just opposite to each other $ C_{L,1} = -C_{L,2} $. It is also interesting to note a half period phase difference between the leader and the follower's thrust force, which can only be caused by the interaction of vortex.\n\t\n\t\n\t\n\t%\n\t%\n\t%\n\t\n\t\\section{Conclusion}\n\t\n\tFish swimming is a classic topic that involves rich physics \\citep{Webb1984,Triantafyllou2000,Liao2007,Ashraf2017} with applications in biomimetics \\citep{Duraisamy2019,Fish2020} and fish farming \\citep{Webb2011}.\n\tAmong the problems of fish swimming, abundant research exists for both fish schooling \\citep{weihs1973hydromechanics,Weihs1975,Ashraf2016,Li2020} and swimming styles \\citep{Sfakiotakis1999,Tytell2010,Cui2018,Thekkethil2017,Thekkethil2018,Thekkethil2020}.\n\tHowever, the combined effect of swimming style and schooling upon hydrodynamics of BCF swimmers has never been systematically examined in details.\n\tIn the present paper, we investigate how swimming style affects fish schooling by a representative problem setup consisting of two NACA0012 hydrofoils undulating at various wavelengths $ \\lambda^* = 0.8 - 8 $, front-back distance $ D = 0,\\ 0.25,\\ 0.5,\\ 0.75 $, phase difference $ \\phi\/\\pi = 0,\\ 0.5,\\ 1,\\ 1.5 $, and lateral gap distance $ G = 0.25,\\ 0.3,\\ 0.35 $ with fixed Reynolds number $ Re = 5000 $, Strouhal number $ St = 0.4 $, and maximum amplitude $ A_{max} = 0.1 $. In total, 336 combinations were simulated by ConstraintIB module of IBAMR. Here, we classify the results by the relative front-back distance between the two foils as side-by-side $ D = 0 $ and staggered $ D > 0 $ conditions.\n\t\n\t\n\t%\n\t\n\t%\n\tThe swimming style of BCF swimmers is represented by wavelengths $ \\lambda^* $. Low wavelength $ \\lambda^* < 1 $ corresponds to anguilliform swimmers, whereas high wavelength $ \\lambda^* \\gg 1 $ for the thunniform ones.\n\tIn the tested parametric space,\n\tthe increase in wavelength $ \\lambda^* $ results in larger thrust $ C_{Tm} $ and monotonic increase of lateral $ C_{Lrms} $ force.\n\t%\n\tPropeller efficiency of either foil $ \\eta_{1,2} $ or two foils as a group $ \\eta_{group} $ reaches minimum and maximum at $ \\lambda^* = 0.8 $ and $ \\lambda^* = 2 $, respectively, and then gradually decreases or remains constant at $ \\lambda^* > 2 $.\n\t%\n\tIt indicates high efficiency but low acceleration for swimmers of intermediate wavelength $ \\lambda^* = 2 $ and vice versa for high wavelength swimmers $ \\lambda^* > 2 $. Low wavelength $ \\lambda^* = 0.8 $ causes both low efficiency and low acceleration due to the fixed Strouhal number $ St = 0.4 $.\n\tThe increase in wavelength also results in strong vortex and irregular flow structure.\n\tThese effects of wavelength for schooling foils is consistent with that for the single foil cases by \\cite{Thekkethil2018}.\n\t\n\t\n\t\n\t\n\t\n\t%\n\tPhase difference $ \\phi $ and front-back distance $ D $ can affect the interaction between vortex shed by the leader and undulating body of the follower \\citep{Li2020}, thus greatly impact the consequent thrust force and propeller efficiency.\n\t%\n\tThe undulation phase difference $ \\phi $ between the two schooling hydrofoils $ \\phi $ can significantly affect the thrust\/lateral force and the individual\/group propeller efficiency, especially at close distances.\n\tThe follower's force and efficiency is most sensitive to phase difference at intermediate or high wavelength $ \\lambda^* > 1 $,\n\twhereas group efficiency is most influenced by phase difference at low wavelength $ \\lambda^* < 1 $.\n\t%\n\tIn other words, by tuning the phase difference, low wavelength swimmers can school with significantly higher group efficiency. For the follower swimming at a high wavelength and close distances, phase tuning can effectively improve its acceleration and efficiency.\n\tThe influence of phase difference $ \\phi\/\\pi $ can be more significant than wavelength $ \\lambda^* $ in some cases.\n\t\n\t\n\t%\n\tFront-back distance $ D $ can greatly affect the follower's thrust force and propeller efficiency while exerting considerable impact on group efficiency at low wavelength $ \\lambda^* < 1 $ as well.\n\t%\n\tA closer front-back distance generally results in advantageous acceleration and high efficiency for the follower, especially at high wavelength $ \\lambda^* \\gg 1 $, \\ie thunniform swimming style; however, a further distance is more beneficial to the group efficiency, especially at low wavelength $ \\lambda^* < 1 $, \\ie anguilliform swimming style.\n\tAt close front-back distances, phase lag $ \\phi $ becomes more influential to group efficiency $ \\eta_{group} $ across $ \\lambda^* = 0.8 - 8 $.\n\tIt is an indication that, for schooling anguilliform swimmers, it can be critical to keep an appropriate front-back distance $ D $, which may even reverse the collective propulsive direction of the swimmer group; in contrast, the schooling performance for thunniform swimmers with high wavelength $ \\lambda^* > 6 $ is more stable; its group efficiency does not vary significantly with phase lag $ \\phi $, especially at further front-back distance $ D \\geq 0.75 $. This point is in support of the hypothesis that thunniform swimmers are more suitable for schooling in contrast with anguilliform swimmers.\n\t\n\t%\n\tLateral gap distance $ G $ can only slightly influence the leader-follower interaction in the tested range of $ G = 0.25 - 0.35 $.\n\tFor the follower, the maximum achievable thrust force by tuning $ \\phi $ and $ \\lambda^* $ slightly decreases with lateral gap $ G $.\n\tGroup efficiency $ \\eta_{group} $ generally increases with lateral gap $ G $ across various wavelengths $ \\lambda^* $.\n\t\n\t%\n\tThe leader and the follower are affected by these parameters in different ways.\n\tThe follower's propulsive efficiency $ \\eta_{follower} $ is generally higher than the leader's $ \\eta_{leader} $.\n\t%\n\tPhase difference $ \\phi $ is more influential to the follower's efficiency than the leader's, especially at high wavelength $ \\lambda^* > 2 $ and close front-back distance $ D \\leq 0.5 $.\n\tAt high $ \\lambda^* \\gg 1 $ and $ \\phi\/\\pi = 1,\\ 1.5 $, the follower's thrust force can be much larger than the leader's.\n\t%\n\t\n\t\n\t%\n\t%\n\t%\n\tVorticity distribution $ \\omega^* $ is reviewed to understand how various non-dimensional parameters affect the flow structure surrounding two foils.\n\t%\n\tThe overall vorticity strength and the flow irregularity both increase with the wavelengths $ \\lambda^* $ regardless of front-back distance $ D $, whereas the general wake flow pattern is only slightly affected by the phase difference $ \\phi $.\n\tVortex dipoles are generated during foil undulation\/pitching.\n\tAt side-by-side $ D = 0 $ and anti-phase $ \\phi\/\\pi = 1 $, vorticity distribution can be symmetrical, since the two swimmers form a mirror symmetry geometry at any moment during the undulation process.\n\tHowever, symmetry breaking can occur after a number of initial periods, especially at high wavelength.\n\tAt $ D = 0.25 $, $ \\lambda^* = 0.8 - 3.2 $, the shed vortex dipoles bifurcates towards 2 distinct directions, forming a mirror symmetry pattern.\n\tAt $ D \\geq 0.50 $, $ \\lambda^* = 0.8 - 3.2 $, the wake flow structure becomes irregular due to unsteady interaction among vortex dipoles.\n\t%\n\tAt low wavelength $ \\lambda^* < 1 $, the gap distance $ G $ and phase difference $ \\phi $ can affect the skewness, symmetry and regularity of the wake pattern.\n\tAt $ \\phi\/\\pi = 0.5 $ and $ \\phi\/\\pi = 1.5 $, the vortex shedding direction is slightly skewed towards the right and left sides of the swimming direction, respectively.\n\tThe intensity of the vortices decreases with gap distance $ G $.\n\tConcentration of dynamic energy is discovered at low gap distance and when the two hydrofoils swim in anti-phase.\n\t%\n\t%\n\t\n\t\n\t%\n\t%\n\tFlow structure surrounding the two foils is examined at 8 consecutive instants within the 3rd cycle of undulation\/pitching, \\ie $ t^*\/T = 2-3 $, together with time histories of thrust $ C_T $ and lateral $ C_L $ force within that cycle. Side-by-side $ D = 0 $ and staggered $ D = 0.75 $ cases are studied at low $ \\lambda^* = 0.8 $, intermediate $ \\lambda^* = 2 $ and high $ \\lambda^* = 8 $ wavelengths, whereas the foil-to-foil phase difference remains constant at anti-phase $ \\phi\/\\pi = 1 $.\n\t\n\tAt side-by-side $ D = 0 $ arrangement and anti-phase $ \\phi\/\\pi = 1 $, the most distinct flow characteristics is the \\textit{symmetrical} flow pattern, which breaks easily at high wavelength. At {low wavelength} $ \\lambda^* = 0.8 $, the flow structure is highly symmetrical.\n\tAt {intermediate wavelength} $ \\lambda^* = 2 $, where the highest energy efficiency is obtained, vortex dipoles form a streaming direction that directly points downstream.\n\tAt {large wavelength} $ \\lambda^* = 8.0 $, the flow symmetry is broken, causing a complicated flow structure, whereas two additional small vortices emerge from the outer sides of two foils.\n\t\n\tAt staggered arrangement $ D = 0.75 $ and anti-phase $ \\phi\/\\pi = 1 $, vortices shed from the leader can interact with those from the follower by from different cycles due to the front-back distance, leading to a delayed impact upon the foil body, thus a phase lag in the eventual thrust force history.\n\tAt low wavelength $ \\lambda^* = 0.8 $, the vorticity pattern looks as if the each foil swims as a single foil.\n\tAt intermediate wavelength $ \\lambda^* = 2 $, \\textit{Vortex swapping} periodically takes place between the two foils.\n\t%\n\tAt high wavelength $ \\lambda^* = 8 $, the general flow structure consists of several large vortices. Periodical interaction occurs near the two foils despite the irregular wake flow.\n\t\n\t%\n\t%\n\tThe hydrodynamic thrust and lateral force upon the two foils is smooth in general, except for the cases with side-by-side $ D = 0 $ arrangement and high wavelength $ \\lambda^* = 8 $, where the flow structure near the foils are highly fractured.\n\tAt either side-by-side $ D = 0 $ or staggered $ D = 0.75 $ arrangement, the lift force of the two foils are generally opposite to each other $ C_{L,1} = -C_{L,2} $, especially at $ \\lambda^* > 2 $.\n\tAt side-by-side $ D = 0 $ arrangement, thrust force upon the two foils is generally identical through the time histories as $ C_{T,1} = C_{T,2} $. In contrast, at staggered arrangement $ D = 0.75 $, a half period phase difference is discovered between the leader and the follower's thrust force, caused by the delayed vortex interaction due to front-back distance; the thrust force of the follower is generally higher than that of the leader.\n\t\n\t%\n\t%\n\t%\n\t\n\tThe low and high wavelength in this paper corresponds to anguilliform and thunniform swimmers, respectively.\n\tOne attempt of the present paper is to test the hypothesis that thunniform swimmers are more adapted for schooling locomotion than anguilliform swimmers.\n\tSeveral biological implications can be derived from the above analysis.\n\t%\n\tThe group energy efficiency of anguilliform swimmers is more sensitive to relative distance and undulation phase difference, implying a less stable collective efficiency than the thunniform swimmers.\n\t%\n\tWhile schooling together, the anguilliform swimmers tend to produce a more stable wake flow than the thunniform swimmers, disturbing less area of the fluid. This implies a better stealth performance for the anguilliform swimmers.\n\t%\n\tAt side-by-side arrangement, the thrust force produced by various swimming styles is roughly equivalent, given the in-phase or anti-phase coordination. This implies the side-by-side arrangement can be a stable formation regardless of swimming styles, given the maintenance of appropriate lateral distance. However, at such stable formation, anguilliform swimmers do not produce a beneficial propeller efficiency. This means that the anguilliform swimmers can be locked in a stable formation with undesirable efficiency, making it less suitable for schooling locomotion.\n\t%\n\tThunniform swimmers produce better thrust force, although not obtaining the best locomotion efficiency, which is coherent with single swimming foil as studied in \\cite{Thekkethil2018}.\n\t%\n\tFor the above implications, the current results are in support of the hypothesis that thunniform swimmers are more hydrodynamically adapted to schooling locomotion than the anguilliform swimmers. These conclusions can also be useful for the schooling locomotion of fish-like robots.\n\t%\n\tIn the future, we intend to continue the present study by three-dimensional and self-propelled simulations.\n\t\n\t%\n\t%\n\t%\n\t%\n\t%\n\t%\n\t%\n\t%\n\t%\n\t%\n\t\n\t\\section{Acknowledgement}\n\tWe acknowledge the help from Yu Jiang for data processing. This work was funded by\n\tChina Postdoctoral Science Foundation under Grant Number 2021M691865\n\tand\n\tScience and Technology Major Project of Fujian Province under Grant Number 2021NZ033016.\n\tA.P.S.B acknowledges support from US National Science Foundation award OAC 1931368.\n\t%\n\t\n\t%\n\t\n\t\\FloatBarrier\n\t\\clearpage\n\t\n\t\\bibliographystyle{elsarticle-harv} \n\t","meta":{"redpajama_set_name":"RedPajamaArXiv"}}