How this calculation works
Reconstruct an additive weighted unrooted tree from exact rational leaf distances and verify every reconstructed path length.
d(i,j) = sum of edge lengths on the unique tree path from leaf i to leaf j.A worked example
For distances d01=d23=4 and all cross-pair distances 6, attach leaves 0 and 1 by length-2 limbs to one internal vertex, leaves 2 and 3 by length-2 limbs to another, and join the internal vertices by length 2. Total length is 10.
Good to know
3–12 labeled leaves; square symmetric rational distances with zero diagonal and positive off-diagonal entries. Exact four-point and reconstructed-path checks. Nonnegative edge lengths, including contracted zero limbs where needed. Nonadditive matrices are rejected; no approximate neighbor joining or evolutionary interpretation.
Reference: Primary method or official documentation (opens in a new tab) ↗
Reconstruct paths rather than clusters
An additive distance matrix records path lengths between labeled leaves of a weighted unrooted tree. The task is to recover a tree that reproduces every supplied distance exactly. The internal branching points are not input observations, and the root is not specified or inferred by this construction.
Hierarchical clustering can produce a dendrogram for many arbitrary dissimilarities, including ones that no additive tree realizes. This page instead rejects a matrix that fails the tree-distance conditions. A successful reconstruction is therefore an exact representation of the entered numbers, not a best approximate hierarchy or a statistical claim about a hidden evolutionary history.
Compare this with the Hierarchical clustering dendrogram calculator from pairwise distances. Recover a weighted unrooted tree whose leaf-path distances exactly match the input, rather than produce linkage clusters for an arbitrary distance matrix.
Enter exact distances consistently
Rows and columns refer to the same leaf labels in the same order. The diagonal must be zero, off-diagonal distances positive, and symmetry exact. Rational entries such as 3/2 preserve intended arithmetic; decimal measurements should be interpreted as the exact decimal values entered, with no hidden noise model.
Units can be any consistent length or dissimilarity unit appropriate to an additive model. Mixing units between rows destroys the interpretation. If empirical measurements are slightly nonadditive, silently rounding them into a tree is inappropriate: use an explicitly approximate fitting method and inspect its residuals separately.
The four-point condition
For any four labels i,j,k,l, form the three sums d(i,j)+d(k,l), d(i,k)+d(j,l), and d(i,l)+d(j,k). Tree distances require that the two largest sums agree. Together with the metric conditions, this identifies the branch split or its unresolved zero-length degeneration.
The comparison is exact for rational inputs. A tiny mismatch therefore remains a mismatch rather than being absorbed into an arbitrary epsilon. This protects the meaning of exact additivity, though it also means noisy measured data may be rejected. The condition is a property of the full matrix, so checking only adjacent rows or one favorite quartet is insufficient.
Insert limbs and internal vertices
A leaf’s limb length is obtained from half of d(i,j)+d(j,k)−d(i,k), minimized over suitable other leaves. Removing that limb locates an attachment point on an already reconstructed path. If the point falls strictly inside an edge, the edge is split and a new internal vertex is introduced.
Nonnegative zero-length cases need careful treatment. An input label may attach at an existing vertex or share a location through a zero limb, so a degree-two or zero-edge representation is not automatically an error. The returned edge list and path replay define the result more reliably than assuming every input label must appear as a strictly positive pendant edge.
Read the four-leaf example
Leaves 0 and 1 are distance four apart, as are leaves 2 and 3. Every cross-pair distance is six. Two length-two limbs meet on each side, and a length-two central edge connects the two branch points. A within-pair path uses two limbs and has length four.
A cross-pair path uses two limbs plus the central edge, for total six. The five recovered edges have total length ten. For quartet (0,1,2,3), the three sums are eight, twelve and twelve, so the two largest agree and the shorter sum identifies the split {0,1}|{2,3}. None of this assigns a temporal direction or a root.
Certificates and alternative representations
The decisive certificate recomputes every pairwise leaf distance from the reconstructed tree and compares it with the input. It also verifies connectivity, nonnegative lengths and absence of cycles. The sum of edge lengths is useful as a summary, but agreement of that sum alone would not establish a correct reconstruction.
A tree may be represented with redundant degree-two vertices or contracted zero edges. These presentations can reproduce the same leaf metric, so do not compare internal IDs as if they were canonical biological objects. Compare the edge-length structure after appropriate contractions and, above all, the complete leaf-distance replay.
Limits of an exact additive model
The result explains exactly the supplied leaf metric within the bounded rational model. It does not quantify uncertainty, test a molecular clock, select a substitution model, or establish that observed similarities arose through a tree process. Networks, recombination and measurement error may require very different models.
For a rejection, inspect the reported violated quartet or distance condition before changing the data. Deliberately choosing an approximate neighbor-joining or least-squares method is a defensible next step; treating a rejected matrix as approximately accepted without a residual criterion is not. Preserve the original measurements so that any later approximation remains auditable.
A few questions, answered
Is the recovered tree rooted?
No. Leaf distances determine an unrooted weighted structure; a root requires extra information.
What if measured distances nearly satisfy the condition?
This page uses exact rational additivity and rejects a mismatch. Use a separate approximate fitting method for noisy data.
Can an edge have length zero?
Yes. Zero edges or limbs can represent contracted or coincident attachment structures, and the full path replay remains decisive.
Do internal vertex numbers identify real ancestors?
No. They are implementation labels for the recovered metric structure, not independently inferred entities.