\section{Further discussion on enumeration strategies}
\label{sec:app_enumeration_strategies}

One approach for enumerating Markov equivalent LEGs can be derived from the transformational characterization in \Cref{prop:LEG} by reversal of directed edges. Similarly to how one could enumerate all Markov equivalent DAGs with covered edge reversals as done by \cite{wienobst2023efficient}, the following depth-first-search program could be used for LEGs.
\begin{enumerate}
    \item Let $S$ be an empty list
    \item Append $L$ to $S$
    \item Run \textbf{search}($L,S$)
\end{enumerate}


\begin{algorithm}[t]
%\fontsize{9}{9}\selectfont
    \caption{Depth-first search}
    \label{alg:depth_first_search}
    \begin{algorithmic}[1]
    \STATE {\bfseries Input:} LEG $L$
    \STATE {\bfseries Output:} Set of Markov equivalent LEGs\medskip
    \STATE Initialize $S$ as an empty list and append $L$
    \RETURN \texttt{Search}($L,S$)\medskip
    \STATE \textbf{function} \texttt{Search}($L, S$)\\\smallskip
    \begin{ALC@g}
    \FOR{each $L'$ obtained by performing a legitimate edge reversal}
        \STATE If $L' \notin S$, append $L'$ to $S$\\[4pt]
        \STATE Run \texttt{Search}($L',S$)
    \ENDFOR
    \end{ALC@g}
    \RETURN $S$
\end{algorithmic}
\end{algorithm}

Starting from an LEG $L$, all neighbors of $L$ (graphs with a single reversed edge) are explored and this is continued recursively. Eventually all ME LEGs are reached by \Cref{prop:LEG} above and the algorithm terminates. In order to not visit any LEG twice, it is necessary to store a set of all visited LEGs. An algorithm implementing this procedure is given in \Cref{alg:depth_first_search}.

\begin{proposition}
    \Cref{alg:depth_first_search} enumerates a Markov equivalence class of LEGs and can be implemented with worst-case delay $\mathcal O(m^3)$, where $m$ is the number of edges in any LEG of the equivalence class.
\end{proposition}

\begin{proof}
    The proof of \cite[Theorem 9]{wienobst2023efficient} applies to the case of LEGs as the space of ME LEGs can be traversed by a sequence of edge traversals (starting from any LEG) as shown by \cite{zhang2012transformational}.
    
    %Any LEG is outputted exactly once and storing all visited LEGs ensures not outputting any LEG multiple times. For the delay, it is first useful to analyze when the most steps between two outputs are necessary. This happens when the algorithm traverses back up the recursion tree (from a leaf), potentially up to the root, without outputting any new LEG and then down into another subtree. In principle, the recursion depth might be exponential and this would, in turn, lead to an exponential-time delay. However, it is possible to bound the recursion depth by m(by Theorem 8 every edge is reversed at most once) and one will still find all LEGs in the Markov equivalence class. It remains to estimate the cost at each recursion step. Going up the recursion tree, at each DAG, O(m) neighbors might be checked whether they have been visited before, e. g., if they are in vis, and all of them might indeed are. The check takes time (m) per neighboring DAG D0 as the whole DAG has to be “read” at least once for lookup. If one uses a hash table for storing the DAGs, expected time O(m) can be reached. So, in total, we have O(m) recursion steps between two outputs, with at most O(m) neighboring DAGs being considered, each of which consuming O(m) time for lookup in vis. This leads to a worst-case delay of O(m3).
\end{proof}

%One trivial observation we can make is that a LEG is a MAG (but not the other way around) and therefore the space of LEGs is smaller in general. Moreover, between a MAG and its LEG only one difference is possible, i.e. some bi-directed edges in the MAG are oriented as directed edges in the LEG, so the size of ME MAGs is larger by an amount equal to the size of ME MAGs in which bi-directed edges are not invariant. 


\Cref{alg:causal_graphs_from_LEG} retrieves the set of MBD causal diagrams compatible with a given LEG. It proceeds by adding dashed bi-directed edges $X\dashleftarrow\dashrightarrow Y$ for every invisible edge between $X$ and $Y$. When bi-directed edges for two adjacent invisible edges cannot be added without violating a conditional independence, two diagrams are constructed and the process continues along two separate branches of the tree. For example, $\{X \rightarrow Z \rightarrow Y\}$ creates $\{X \rightarrow Z \rightarrow Y, X\dashleftarrow\dashrightarrow Z\}$ and $\{X \rightarrow Z \rightarrow Y, Z\dashleftarrow\dashrightarrow Y\}$ separately as $\{X \rightarrow Z \rightarrow Y, X\dashleftarrow\dashrightarrow Z, Z\dashleftarrow\dashrightarrow Y\}$ violates the conditional independence between $X$ and $Y$.

\begin{algorithm}[t]
%\fontsize{9}{9}\selectfont
    \caption{Derivation of maximally bi-directed causal graphs}
    \label{alg:causal_graphs_from_LEG}
    \begin{algorithmic}[1]
        \STATE {\bfseries Input:} LEG $L$
        \STATE {\bfseries Output:} The set of maximally bi-directed graphs.
        \STATE For all invisible edges of the form $X\rightarrow Y$ such that $X$ does not have any parents or spouses not adjacent to $Y$, add a bi-directed edge $X\dashleftarrow\dashrightarrow Y$ to $L$, creating a causal diagram $G$\\[4pt]
        \STATE Initialize an empty list $S$ and append $\G$ to it
        \STATE Initialize an empty list $S'$\\[4pt]
        \WHILE{$S$ is not empty}
            \FOR{each $\G$ in $S$}
                \STATE Let $k$ be the number of invisible edges in $\G$\\[4pt]
                \STATE Create graphs $\G_1, \dots, \G_k$ by adding a bi-directed edge for each invisible edge in $L$\\[4pt]
                \STATE Mark visible edges in $\G_1, \dots, \G_k$\\[4pt]
                \STATE Append $S'$ with the subset of $\{\G_1, \dots, \G_k\}$ in which invisible edges do not exist\\[4pt]
                \STATE Append $S$ with the subset of $\{\G_1, \dots, \G_k\}$ in which invisible edges do exist and remove $\G$
            \ENDFOR
        \ENDWHILE
        \RETURN $S'$
    \end{algorithmic}
\end{algorithm}

\begin{proposition}
    \Cref{alg:causal_graphs_from_LEG} enumerates all MBD causal diagrams compatible with a given LEG.
\end{proposition}

\begin{proof}
    In line (11), \Cref{alg:causal_graphs_from_LEG} appends and returns causal diagrams that can be constructed from a given LEG by adding the maximum number of bi-directed edges, \textit{i.e.} diagrams without invisible edges and that therefore exclude any further unobserved confounding. Lines (9) and (12) ensure that all possible diagrams to which a bi-directed edge could be added are considered and ensures that all intermediate diagrams with invisible edges are maintained for analysis. At termination therefore \Cref{alg:causal_graphs_from_LEG} will have enumerated all MBD causal diagrams compatible with a given LEG.
\end{proof}
