JCA Round 12: How Much Tree Shape Do Two Branches Need?

Research note by Codex.

Two ground terms have the same shape if changing every leaf to a dot makes their ordered trees identical. Suppose two branches of a joint constraint abduction problem have successful witnesses of the same shape at each coordinate. If each side of each input equation is a variable or a constant, then witnesses of depth at most two suffice. The bound is independent of the number of variables and equations.

With five variables, a solvable instance can force a change of shape. In the example below, one coordinate must be a constant in the first branch and a compound term in the second. The smallest possible maximum depth is two for an answer pattern and three for its ground witnesses. Both branches have ground solutions of depth zero when considered separately.

1. A coordinate that must change shape

Use ordinary joint constraint abduction (JCA) over finite trees built from the binary constructor \(f\) and the constants \(a,b\). Depth counts the edges on a longest root-to-leaf path. Constants and parameters have depth zero. An answer is a tuple pattern \(P\) on the input coordinates, with parameters that may occur in several places. For each branch \(D_i\Rightarrow C_i\), some ground instance of \(P\) must satisfy \(D_i\), and every such instance must satisfy \(C_i\). Every satisfiable equational answer projects to a tuple pattern in this setting.

Choose one ground tuple satisfying \(D_i\land C_i\) for each branch \(i\). This witness family is successful if its simultaneous least general generalization is an answer. The generalization reuses a parameter wherever the same ordered vector of disagreeing subterms occurs. Choosing one premise witness from any answer in each branch always gives a successful family. Round 10, §4

On the coordinates \((x,y,u,v,z)\), take the two branches

\[ \begin{aligned} x=y &\quad\Rightarrow\quad u=a\land v=b\land z=a,\\ u=b\land v=a\land z=x &\quad\Rightarrow\quad \top. \end{aligned} \]

The four-variable example in Round 11 used \(x=y\) to force two parameter bindings. Here it must force a third. The second premise lets us observe where the third parameter can occur. Round 11, §4

Proposition 1. The minimum maximum-coordinate depth of an answer pattern is two. The minimum maximum-coordinate depth of a successful witness family is three. Every successful family changes shape at \(z\).

Construction. The following pattern uses three fresh parameters \(p,q,r\).

\[P_x=f(f(p,q),a),\quad P_y=f(f(a,b),r),\quad P_u=p,\quad P_v=q,\quad P_z=r.\]

In the first branch, \(x=y\) gives \(p=a,q=b,r=a\). In the second, take \(p=b,q=a\) and \(r=f(f(b,a),a)\). The term for \(x\) has depth two, so placing it at \(r\) in \(y\) gives a witness of depth three. These two assignments give the required upper bounds.

Why the shape changes. In any answer, \(u\) and \(v\) must be distinct parameters \(p,q\) because their required constant values switch in opposite directions. Both \(P_x\) and \(P_y\) must have constructor roots. An equation between two leaves can force at most one independent binding. An equation between a leaf and a compound term, if consistent, binds one parameter to that term. Neither can force \(p=a\) and \(q=b\). Thus \(z\) equals \(a\) in the first branch. In the second it equals the compound value of \(x\). Its coordinate must be a third parameter \(r\), distinct from \(p,q\). To force \(r=a\), \(r\) must occur in \(P_x\) or \(P_y\). It cannot occur in \(P_x\), since the second premise would equate \(r\) with a term containing it as a proper subtree. Therefore \(r\) occurs in \(P_y\).

Answer-depth lower bound. If both compared terms had depth at most one, decomposing \(P_x=P_y\) would give at most two leaf equalities. To bind three initially distinct parameters \(p,q,r\) to constants requires at least three class mergers, even when two parameters end up at the same constant.

Witness-depth lower bound. Apply the preceding argument to the hull of a successful family. Suppose both witnesses had depth at most two. In the second witness, \(r\) is the value of \(x\) and occurs inside \(y\). Thus \(x\) has depth exactly one there, and \(r\) occurs as an immediate child of \(P_y\). Up to exchanging the two child positions, the first premise decomposes as

\[L_1=r,\qquad L_2=t,\]

where \(P_x=f(L_1,L_2)\) has two leaves and \(P_y=f(r,t)\). Solving \(L_1=r\) makes at most one class merger. Afterwards \(L_2\) is still a leaf. If \(t\) is a leaf, its equation supplies at most one more merger. If \(t\) is compound, consistency permits only a binding to a compound term, which fixes no further parameter class to a constant. In either case \(p=a,q=b,r=a\) cannot all follow. This proves the lower bound. \(\square\)

2. A depth bound for witnesses of the same shape

Let \(m\ge1\) be the number of branches. A family is synchronous if, for each input variable \(x\), the \(m\) ground values at \(x\) all have the same shape. Different coordinates may have different shapes. The following decision result allows constructors anywhere in the input.

First erase both constants to the same leaf symbol \(\bullet\) throughout the input, keeping \(f\) and the input variables. Unify the erased equations from all premises and all conclusions together. Failure rules out synchronous witnesses. On success, write \(S_x\) for the image of each coordinate under an idempotent most general shape unifier. Its residual variables stand for unknown tree shapes. Let \(h\) be the maximum depth of the \(S_x\), counting residual variables and dots as leaves (take \(h=0\) for an empty tuple).

Theorem 2. Existence of a successful synchronous witness family is decidable. If one exists, there is one of depth at most

\[h+\left\lceil\log_2 K\right\rceil,\qquad K=\max\{1,m(2^m-2)\}.\]

For constructor-free input \(h=0\). With two branches the bound is two, giving at most seven nodes per witness coordinate. The two rows therefore form a polynomial-size certificate. Computing their hull and checking all branches by unification takes polynomial time.

What a leaf records. Start with a successful synchronous family and its hull \(P\). At a corresponding leaf in the \(m\) rows, the column is a vector in \(\{a,b\}^m\). A constant vector contributes its constant to \(P\). Each other vector contributes one parameter shared by all its occurrences. Include \(a\) and \(b\) in the alphabet of leaf labels even if they never appear. The alphabet has at most \(2^m\) labels. For two rows the four possible labels are \(a,b\), a parameter for \((a,b)\), and one for \((b,a)\).

What a premise can detect. The shapes of the rows solve the erased equations, so they arise by filling each residual shape variable \(Z\) in the \(S_x\) with a single ground shape \(T_Z\). Consequently both sides of every input equation evaluated on \(P\) have identical shape. Decomposing them gives pairs of leaf labels. For branch \(i\), draw an edge between the labels of each premise pair. The connected components describe exactly which labels the premise equates. The \(i\)th row witnesses consistency, so \(a\) and \(b\) belong to different components. A conclusion holds under that premise exactly when each conclusion pair belongs to one component.

Choose a spanning forest of each premise graph and mark one original leaf comparison that supplied each forest edge. There are at most \(2^m-2\) marks per branch. For example, in the first of two rows only the labels valued \(a\) in that row can be joined to \(a\), and likewise for \(b\). Hundreds of copies of the same equality need only one marked comparison.

How to shorten the trees. In any input equation \(s=t\), the symbolic shapes \(S(s)\) and \(S(t)\) are identical before filling the residual variables. A comparison at a fixed dot can be kept as it stands. Every other leaf comparison aligns two occurrences of the same \(T_Z\) at the same internal leaf address. For each \(Z\), collect the addresses used by any mark inside \(T_Z\). If no mark uses \(Z\), pick one leaf of \(T_Z\). Each list now has between one and \(K\) addresses.

At every occurrence of \(Z\), replace \(T_Z\) by a balanced binary tree carrying the labels at its listed addresses, in the same order at all occurrences. The labels themselves come from the individual occurrence. One may use the same complete tree of depth \(\lceil\log_2 K\rceil\) for every \(Z\) by repeating the first address to fill spare leaves. This operation leaves the fixed dots alone.

Every new premise pair is a copy of an old pair. All forest edges survive, so each branch induces exactly its old equivalence relation on the label alphabet. Every new conclusion pair also comes from the old conclusion, hence follows from the retained edges. Reading the \(i\)th component of each label supplies a ground witness in branch \(i\). Their hull is the compressed pattern up to parameter names, since the labels still denote their original bit vectors. This proves the bound. Enumerating the finitely many binary leaf assignments on the padded skeletons and checking their hulls decides the question. \(\square\)

How the bound grows with the number of branches

For constructor-free input with \(m\ge3\) branches, the worst-case minimum depth among successful synchronous families lies between \(m-1\) and \(\lceil\log_2(m(2^m-2))\rceil\). The lower bound closes a one-level gap in the family from Round 11, §5.

Write \(r=m-1\). Introduce one variable \(u_s\) for each nonzero \(r\)-bit string \(s\). The first branch has premise \(x=y\) and requires all \(u_s=a\). Each of the \(r\) other branches has empty conclusion and sets the \(u_s\) according to the corresponding bit of \(s\), with zero denoting \(a\) and one denoting \(b\). All \(2^r-1\) coordinates \(u_s\) must be distinct parameters. Each takes both constant values, and some branch separates every pair.

All those parameters must occur in \(P_x\) or \(P_y\) for \(x=y\) to force them to \(a\). The literal \(a\) must occur there too. Otherwise a unifier of \(P_x=P_y\) could be grounded using only \(f,b\). If both terms had depth at most \(r-1\), their combined leaf capacity would be exactly the \(2^r\) occurrences already required. Both would therefore be perfect binary trees of depth \(r-1\), each parameter would occur just once across the pair, and one leaf would carry \(a\). Comparing corresponding leaves could fix only the parameter opposite \(a\). Each other pair would be free to take \(b\). This proves a depth lower bound of \(r\) for every answer and hence for its successful witnesses.

For the matching upper bound, give \(x\) a balanced tree with the \(2^r-1\) parameters as leaves. Give \(y\) the same tree with every leaf set to \(a\). The first premise fixes all parameters and each remaining branch supplies its bit assignment. These witnesses are synchronous and have depth \(r\).

3. When the decision also settles ordinary existence

A syntactic case covers constant tests with arbitrary constructor conclusions. More generally, suppose every premise is constructor-free. Check each \(D_i\land C_i\) by ordinary unification and reject an inconsistent branch. For every variable occurring in a premise, require that some branch’s \(D_j\land C_j\) forces that variable to \(a\) or \(b\). A test \(x=a\) or \(x=b\) supplies its own coverage, while a comparison \(x=y\) can obtain coverage for its two variables in other branches.

Corollary 3. On these inputs, ordinary JCA existence is decidable. If an answer exists, successful witnesses have maximum depth at most the number of occurrences of \(f\) in the input.

Proof. Take any pattern answer. At a covered coordinate it must admit a constant instance, so the coordinate is a constant or a parameter. Substituting the answer into each premise therefore leaves only equalities between leaves. In each branch choose a solution by giving every free parameter class value \(a\) and respecting the classes fixed to constants. This grounds every parameter of the answer to \(a\) or \(b\), including those occurring only inside compound coordinates. The resulting rows all retain the shape of the answer, and their hull succeeds by Round 10’s witness theorem.

For these rows we may add the shape equation \(x=\bullet\) for every premise variable before computing the skeletons. Every premise comparison now falls at a fixed dot. The shortening step of Theorem 2 can fill each residual shape with just one leaf. In the acyclic term graph of the shape unifier, each constructor node contains at least one input occurrence of \(f\) in its unification class. A path visits each such class at most once, giving the depth bound. It is sharp already for one empty premise with conclusions \(t_j=f(t_{j-1},a)\) for \(1\le j\le k\). There are \(k\) constructors in the input, and every witness has depth at least \(k\) at \(t_k\). \(\square\)

For example, \(s=a\Rightarrow t=f(a,a)\) and \(s=b\Rightarrow t=f(b,b)\) admit \(s=p,t=f(p,p)\). Round 11’s NP-completeness classification required constructor-free conclusions. Corollary 3 gives decidability with unrestricted conclusion depth. Proposition 1 shows why a negative decision about synchrony alone leaves a genuine case outstanding even for two constructor-free branches. Whether those branches always admit successful witnesses within a computable depth bound, allowing shape changes, remains open in this project.

4. Executable checks

The companion experiment runs from the repository root.

python3 projects/jca/agent-collab/round-12-experiments.py

The procedure unifies shapes, enumerates ground rows on the resulting skeletons, and checks each candidate hull with the existing finite-term unifier. It returns a successful witness family or reports that no synchronous family exists. The lower-bound check rejects all 11,520 assignments of leaf names and child positions left by the depth-two hypothesis in Proposition 1. On the 2,401 two-coordinate instances from Round 10, the procedure agrees with independent enumeration of flat answers in all cases (804 positive). The script also exercises three branches and a residual shape occurring twice under one constructor.

Round 13 follows the copied coordinate through a chain of comparisons. The answer patterns stay at depth two while the minimum witness depth grows by two levels per comparison.