Algorithm Search⌘K

Techniqueresearch

Witness configuration method

Also called Michelucci-Foufou witness method.

Michelucci and Foufou's test of rigidity and redundant constraints by the Jacobian rank at a random configuration with the same incidences, which avoids the errors of counting.

The witness configuration method analyses a geometric constraint system by linear algebra at one random solution of a similar system. Choose random positions for the geometric elements, keep the incidences that the system requires, and measure the dimension values (distances, angles) from these positions. The result, the witness, solves a system with the same structure as the user's. The rank of the Jacobian at the witness then tells, with a proved small error probability, whether the system is under-constrained, well-constrained or over-constrained, which constraints are redundant, and which subsystems are rigid. Unlike degree of freedom counting, it sees dependencies that come from geometry, as in the double banana, because it does not count at all.

In plain words

To check whether a drawing is fixed by its dimensions, you could count the dimensions and compare with the number of ways the parts can move. Counting is quick, but it is fooled when two dimensions say the same thing in a hidden way. The witness method instead makes up a random drawing of the same kind, with the same kinds of dimensions, and tests that drawing directly with a small calculation. A random drawing has no hidden coincidences, except those that every drawing of this kind must have. So whatever the test finds there is almost surely true for every typical drawing of this kind.

When it applies

  • Polynomial constraints. Each constraint is a polynomial equation in the coordinates and the dimension values: squared distances, incidences, parallelism, tangency, and angles through their cosines or tangents. Then the entries of the Jacobian are polynomials in the coordinates.
  • A structural question. The question is about a typical instance of the system: is it generically rigid, which constraints are generically redundant. The method answers for almost all dimension values, not for the user's specific values.
  • A witness can be built. There must be an easy way to get random points that satisfy the constraints whose values are not free. For distance and angle constraints any random placement works, since the values are read from it. Incidences such as a point on a line must hold at the witness, so the witness is built by a construction: choose the line at random, then the point at random on it.
  • Exact or modular arithmetic. The rank of a matrix is not a continuous function of its entries, so the method should run in exact rational arithmetic or modulo a large prime. In floating point the rank depends on a tolerance.

The template

For distance constraints between nn points in Rd\mathbb{R}^d, the Jacobian of the squared distances is twice the rigidity matrix. Let D=d(d+1)/2D = d(d + 1)/2 be the dimension of the rigid motions when the points span Rd\mathbb{R}^d.

  1. WITNESS-ANALYSIS(n, E, d, N)
  2. 1choose a witness p with independent uniform integer coordinates in 1..N
  3. 2build the Jacobian J of the constraints at p, one row per constraint
  4. 3for each constraint e, in order of priority
  5. 4if the row of e lies in the span of the earlier rows, mark e redundant
  6. 5r ← rank of J (the number of rows not marked redundant)
  7. 6flex ← (dn − D) − r
  8. 7verdict ← well-constrained if flex = 0 and nothing is redundant, else under- or over-constrained
  9. 8return r, the redundant constraints, flex and the verdict

The greedy pass in lines L3 and L4 finds a basis of the row space: the rows not marked redundant are independent, and each marked row depends on the rows before it. The constraints marked redundant are exactly those that a well-constrained system would drop, given the priority order.

Theorem (one-sided error). Let r∗r^* be the generic rank of JJ, the largest rank over all placements. Then for every witness pp, the rank rr in line L5 satisfies r≤r∗r \le r^*. For a witness drawn as in line L1,

Pr⁡[r<r∗]≤r∗N.\Pr[r < r^*] \le \frac{r^*}{N} .

Proof. Every entry of JJ is a polynomial of degree at most 1 in the coordinates, for example pi,k−pj,kp_{i,k} - p_{j,k}. A matrix has rank at least ss exactly when some s×ss \times s minor is nonzero. Upper bound. Every minor of size r∗+1r^* + 1 is a polynomial that vanishes at every placement, since no placement has rank above r∗r^*. So it vanishes at pp, and r≤r∗r \le r^*. Lower bound. Some r∗×r∗r^* \times r^* minor MM is nonzero at some placement, so MM is a nonzero polynomial in the dndn coordinates, of degree at most r∗r^*. By the Schwartz-Zippel lemma, a nonzero polynomial of degree r∗r^* vanishes at a uniform random point of {1,…,N}dn\{1, \ldots, N\}^{dn} with probability at most r∗/Nr^*/N. If M(p)≠0M(p) \ne 0 then r≥r∗r \ge r^*. □\square

Consequences. The rank can only be too small. So the answer "rigid" (flex =0= 0) is always correct: the framework is infinitesimally rigid at pp, hence generically rigid by the Asimow and Roth theorem. A row that is not marked redundant is truly independent at a generic placement. Only the answers "flexible" and "redundant" can be wrong, and only with probability at most r∗/Nr^*/N. With tt independent witnesses and the largest rank kept, the bound becomes (r∗/N)t(r^*/N)^t. For n=1000n = 1000 points in space and N=231N = 2^{31}, one witness errs with probability below 3000⋅2−31<2⋅10−63000 \cdot 2^{-31} < 2 \cdot 10^{-6}.

Rigid subsystems. The kernel of JJ at the witness is the space of infinitesimal motions. A subset SS of the points is rigid inside the system when every motion in the kernel restricts on SS to a rigid motion of SS, which is a rank test on the kernel basis. Michelucci and Foufou use this to find the rigid parts and to guide the decomposition of the system.

Cost. For mm constraints and dndn unknowns, elimination takes O(m(dn)min⁡(m,dn))O(m (dn) \min(m, dn)) field operations. Over the rationals the numbers grow, so a fraction-free elimination or arithmetic modulo a random prime of about 31 bits is used in practice; the probability bound then also accounts for the prime.

Classic examples

The ranks below are computed exactly over the rationals by the implementation, at random witnesses with N=106N = 10^6 unless the points are given.

A triangle, a square and K4K_4 in the plane. The triangle has rank 3=2⋅3−33 = 2 \cdot 3 - 3 and no redundant edge: well-constrained. The 4-cycle has rank 4 against 2⋅4−3=52 \cdot 4 - 3 = 5: one flex, under-constrained. The complete graph K4K_4, with its edges in the order 01,02,03,12,13,2301, 02, 03, 12, 13, 23, has rank 5, and the pass marks 2323 redundant: over-constrained, although the count 6>56 > 5 already shows it.

Agreement with Laman's count. In the plane, the generic rank is the size of the largest edge set in which every k≥2k \ge 2 vertices span at most 2k−32k - 3 edges, by Laman's theorem. On 150 random graphs with up to 7 vertices, the largest rank over two witnesses equals this count, computed by brute force over vertex subsets, every time. On 60 more such graphs, a single witness with N=106N = 10^6 also agreed every time, and the number of edges marked redundant was always mm minus the rank.

The double banana. In space, the double banana has 18=3⋅8−618 = 3 \cdot 8 - 6 edges and passes every subset count. The witness gives rank 17, flex 1 and one redundant edge. A counting method, such as a pebble game for the (3,6)(3, 6) count, would accept it as well-constrained.

A theorem hidden in the incidences. Take two lines, three points on each, and the three points where cross joins meet. Pappus's theorem says that these three points are always collinear. A constraint "these three points are collinear" therefore adds nothing, but a count treats it as one more equation. A witness built by the construction (random lines, random points on them, intersections computed) satisfies the collinearity, and its Jacobian row lies in the span of the others, so the method marks it redundant.

Tiny grids. With N=2N = 2, so that every coordinate is 1 or 2, many witnesses are special. On 150 random graphs the witness rank fell below the Laman count on some of them and never rose above it, as the theorem says.

Variations

  • Several witnesses. Keep the largest rank over tt independent witnesses. The rank never overshoots, so the maximum is safe, and the error probability drops to (r∗/N)t(r^*/N)^t.
  • Modular witnesses. Choose a random prime qq and work in Z/q\mathbb{Z}/q. The Schwartz-Zippel bound holds over any field, and a bad prime adds a small, bounded failure probability.
  • The user's sketch as witness. The approximate drawing that the user made is often near a valid configuration and can serve as a witness after a small correction. It is cheap, but it is the most likely witness to be special; see Pitfalls.
  • Global rigidity. The same idea with a random combination of the self-stresses at the witness decides generic global rigidity by the rank of the stress matrix, as in the Gortler, Healy and Thurston theorem.
  • Other constraint types. Angles, tangencies, parallelism and point-on-curve constraints add Jacobian rows like distances do. The witness must satisfy every constraint whose value is fixed by the type, such as an incidence, and may take the values of the others from its own geometry.

Pitfalls

  • A special witness. Points on a grid, on a circle, with equal lengths or with parallel sides are not random. For example, K3,3K_{3,3} with its six points on the circle x2+y2=25x^2 + y^2 = 25, at (5,0),(0,5),(−5,0)(5, 0), (0, 5), (-5, 0) and (3,4),(−4,−3),(4,−3)(3, 4), (-4, -3), (4, -3), has rank 8, while a random witness gives 9, the generic rank. The rank drop is real for that placement but false for the system. Use random coordinates from a large range, and never only the user's sketch.
  • The wrong component. When incidences define a set with several components, a witness can land on a degenerate one, for example with two points that coincide, which satisfies "point on line" constraints trivially. The rank there need not be the rank at the configurations the user wants. Build the witness so that distinct elements are distinct.
  • Generic is not specific. The method answers for typical dimension values. The user's actual values may be special: three points with lengths 1,1,21, 1, 2 force a collinear triangle, which is flexible to first order although the triangle is generically rigid. It also says nothing about whether the user's values have a real solution at all, which is the hard distance geometry problem.
  • Floating point. A numerical rank needs a threshold on singular values, and near-dependent rows of a badly scaled sketch can fall on either side. Exact rational or modular arithmetic removes the threshold.
  • Order dependence. Which constraint is marked redundant depends on the order in lines L3 and L4. The number of redundant constraints does not. Order the constraints by user priority so that the dropped ones are the least important. Zou and Feng (2019) discuss why the method alone does not settle the CAD tasks of characterizing the constraint state, decomposing the system and prioritizing constraints.

Code

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

witness_configuration_method.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/witness-configuration-method/. The authors are listed in prov/JK8AA5.jsonl.

"""The witness configuration method for distance constraints between points.

A witness is a random placement of the points. The squared distance constraints hold at the witness by
construction, if the dimension values are measured from it. The rank of the Jacobian at the witness, computed
exactly with fractions, gives the rank at a generic placement with high probability. It is never larger."""

import random
from fractions import Fraction
from typing import Optional, Sequence

Edge = tuple[int, int]
Point = Sequence[int]


def jacobian_rows(edges: Sequence[Edge], p: Sequence[Point]) -> list[list[Fraction]]:
    """Half the Jacobian of the squared distances |p_i - p_j|^2: the rigidity matrix, one row per edge."""
    d = len(p[0]) if p else 0
    rows = []
    for i, j in edges:
        row = [Fraction(0)] * (d * len(p))
        for k in range(d):
            row[d * i + k] = Fraction(p[i][k] - p[j][k])
            row[d * j + k] = Fraction(p[j][k] - p[i][k])
        rows.append(row)
    return rows


class RowSpace:
    """An echelon basis of the rows seen so far; add() reports whether a new row is independent of them."""

    def __init__(self) -> None:
        self.basis: list[tuple[int, list[Fraction]]] = []

    def reduce(self, row: list[Fraction]) -> list[Fraction]:
        row = list(row)
        for c, b in self.basis:
            if row[c] != 0:
                f = row[c] / b[c]
                row = [x - f * y for x, y in zip(row, b)]
        return row

    def add(self, row: list[Fraction]) -> bool:
        row = self.reduce(row)
        for c, x in enumerate(row):
            if x != 0:
                self.basis.append((c, row))
                return True
        return False


def rank(rows: Sequence[list[Fraction]]) -> int:
    space = RowSpace()
    return sum(1 for r in rows if space.add(r))


def random_witness(n: int, d: int, rng: random.Random, box: int) -> list[list[int]]:
    """A placement with independent uniform integer coordinates in 1..box."""
    return [[rng.randint(1, box) for _ in range(d)] for _ in range(n)]


def trivial_dimension(d: int, n: int) -> int:
    """The dimension of the infinitesimal rigid motions of n points in general position in R^d.

    The points span an s-flat with s = min(n - 1, d). The rotations that fix the flat pointwise act on the
    (d - s)-dimensional complement and move no point, so they are subtracted."""
    if n == 0:
        return 0
    s = min(n - 1, d)
    return d * (d + 1) // 2 - (d - s) * (d - s - 1) // 2


def analyze(n: int, edges: Sequence[Edge], d: int = 2, rng: Optional[random.Random] = None,
            box: int = 10**6, witness: Optional[Sequence[Point]] = None) -> dict:
    """Witness analysis of a distance constraint system on n points in R^d.

    Returns the witness, the rank, the redundant edges (each depends on the earlier ones), the number of
    internal degrees of freedom, and a verdict. 'well' means rigid and no redundant edge; 'under' means the
    witness shows a flex; 'over' means some edge is redundant. A 'well' verdict and a rigid verdict are always
    correct; 'under' and 'over' can be wrong with probability at most rank / box for a random witness."""
    rng = rng or random.Random(0)
    p = witness if witness is not None else random_witness(n, d, rng, box)  # @line L1
    rows = jacobian_rows(edges, p)  # @line L2
    space = RowSpace()
    redundant = []
    for e, row in zip(edges, rows):  # @line L3
        if not space.add(row):  # @line L4
            redundant.append(e)  # @line L4
    r = len(space.basis)  # @line L5
    full = d * n - trivial_dimension(d, n)  # @line L6
    flex = full - r  # @line L6
    if flex == 0 and not redundant:  # @line L7
        verdict = "well"
    elif flex > 0:
        verdict = "under"
    else:
        verdict = "over"
    return {"witness": p, "rank": r, "redundant": redundant, "flex": flex, "verdict": verdict}  # @line L8


def generic_rank(n: int, edges: Sequence[Edge], d: int = 2, rng: Optional[random.Random] = None,
                 box: int = 10**6, trials: int = 2) -> int:
    """The largest witness rank over independent witnesses. It never exceeds the generic rank."""
    rng = rng or random.Random(0)
    return max(rank(jacobian_rows(edges, random_witness(n, d, rng, box))) for _ in range(trials))
test_witness_configuration_method.py 150 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/witness-configuration-method/. The authors are listed in prov/JK8AA5.jsonl.

import random
from fractions import Fraction
from itertools import combinations

from witness_configuration_method import (analyze, generic_rank, jacobian_rows, rank, random_witness,
                                          trivial_dimension)


def laman_sparse(n, edges):
    """Every set of k >= 2 vertices spans at most 2k - 3 of the edges (brute force over vertex subsets)."""
    for k in range(2, n + 1):
        for X in combinations(range(n), k):
            s = set(X)
            if sum(1 for u, v in edges if u in s and v in s) > 2 * k - 3:
                return False
    return True


def laman_rank(n, edges):
    """The rank of the generic 2D rigidity matroid by the Laman count: a greedy basis of sparse sets."""
    basis = []
    for e in edges:
        if laman_sparse(n, basis + [e]):
            basis.append(e)
    return len(basis)


def laman_rank_by_edge_subsets(n, edges):
    """The same rank as the largest sparse edge subset, by brute force over all edge subsets."""
    for size in range(len(edges), -1, -1):
        for S in combinations(edges, size):
            if laman_sparse(n, list(S)):
                return size
    return 0


def random_graph(rng, n, prob):
    return [e for e in combinations(range(n), 2) if rng.random() < prob]


def test_witness_rank_matches_laman_count():
    rng = random.Random(1)
    for _ in range(150):
        n = rng.randint(2, 7)
        edges = random_graph(rng, n, rng.choice([0.3, 0.5, 0.7, 0.9]))
        assert generic_rank(n, edges, 2, rng) == laman_rank(n, edges)


def test_greedy_laman_rank_is_the_brute_force_rank():
    rng = random.Random(2)
    for _ in range(40):
        n = rng.randint(2, 5)
        edges = random_graph(rng, n, 0.6)
        assert laman_rank(n, edges) == laman_rank_by_edge_subsets(n, edges)


def test_single_witness_with_large_box():
    rng = random.Random(3)
    for _ in range(60):
        n = rng.randint(3, 7)
        edges = random_graph(rng, n, 0.6)
        info = analyze(n, edges, 2, rng)
        assert info["rank"] == laman_rank(n, edges)
        assert len(info["redundant"]) == len(edges) - info["rank"]


def test_witness_rank_never_exceeds_generic_rank():
    """With a tiny box many witnesses are special, but the rank can only drop."""
    rng = random.Random(4)
    drops = 0
    for _ in range(150):
        n = rng.randint(3, 7)
        edges = random_graph(rng, n, 0.7)
        r = rank(jacobian_rows(edges, random_witness(n, 2, rng, 2)))
        lr = laman_rank(n, edges)
        assert r <= lr
        drops += r < lr
    assert drops > 0


def test_verdicts():
    triangle = [(0, 1), (1, 2), (0, 2)]
    assert analyze(3, triangle)["verdict"] == "well"
    square = [(0, 1), (1, 2), (2, 3), (0, 3)]
    info = analyze(4, square)
    assert info["verdict"] == "under" and info["flex"] == 1
    k4 = list(combinations(range(4), 2))
    info = analyze(4, k4)
    assert info["verdict"] == "over" and info["redundant"] == [(2, 3)]


def test_redundant_edges_are_dependent():
    rng = random.Random(5)
    for _ in range(40):
        n = rng.randint(4, 7)
        edges = random_graph(rng, n, 0.8)
        info = analyze(n, edges, 2, rng)
        kept = [e for e in edges if e not in info["redundant"]]
        rows = jacobian_rows(kept, info["witness"])
        assert rank(rows) == len(kept) == info["rank"]


def test_trivial_dimension():
    assert [trivial_dimension(2, n) for n in range(1, 5)] == [2, 3, 3, 3]
    assert [trivial_dimension(3, n) for n in range(1, 6)] == [3, 5, 6, 6, 6]


def test_line_rank_is_n_minus_components():
    rng = random.Random(6)
    for _ in range(40):
        n = rng.randint(2, 7)
        edges = random_graph(rng, n, 0.35)
        parent = list(range(n))

        def find(x):
            while parent[x] != x:
                x = parent[x]
            return x
        for u, v in edges:
            parent[find(u)] = find(v)
        components = len({find(x) for x in range(n)})
        assert generic_rank(n, edges, 1, rng) == n - components


def test_double_banana_in_space():
    def banana(t):
        vs = [0, 1] + list(t)
        return [e for e in combinations(vs, 2) if e != (0, 1)]
    edges = banana((2, 3, 4)) + banana((5, 6, 7))
    assert len(edges) == 3 * 8 - 6
    info = analyze(8, edges, 3, random.Random(7))
    assert info["rank"] == 17 and info["flex"] == 1 and len(info["redundant"]) == 1
    assert info["verdict"] == "under"


def test_special_witness_on_a_circle():
    """K(3,3) with its six points on a circle has a stress and a flex; a random witness does not."""
    k33 = [(i, j) for i in range(3) for j in range(3, 6)]
    on_circle = [(5, 0), (0, 5), (-5, 0), (3, 4), (-4, -3), (4, -3)]
    assert all(x * x + y * y == 25 for x, y in on_circle)
    assert analyze(6, k33, witness=on_circle)["rank"] == 8
    assert analyze(6, k33, 2, random.Random(8))["rank"] == 9


def test_fractions_are_exact():
    rows = jacobian_rows([(0, 1)], [[1, 2], [4, 6]])
    assert rows == [[Fraction(-3), Fraction(-4), Fraction(3), Fraction(4)]]

Exercises

  1. Show that for a 1-dimensional placement, the rank of the rigidity matrix at any placement with distinct coordinates is n−cn - c, where cc is the number of connected components. Why is any injective witness enough here?
  2. The prism graph in the plane has 9 edges and rank 9. Find a placement of it with rank 8 and explain what the drop means geometrically.
  3. Give a constraint system whose generic rank is r∗r^* and a placement in {1,2}dn\{1, 2\}^{dn} where the rank is below r∗r^*. Compare with the bound r∗/Nr^*/N.
  4. Prove that the rank at the witness cannot exceed the generic rank using only the fact that the set of placements of rank at most ss is closed.
  5. Design the witness construction for a sketch with constraints "point on circle", "line tangent to circle" and "distance between points". Which values are taken from the witness, and which are enforced by the construction?

References

  1. Dominique Michelucci and Sebti Foufou, Geometric constraint solving, the witness configuration method, Computer-Aided Design 38(4), 284 to 299, 2006, the definition of a witness, the rank of the Jacobian at the witness, the detection of dependent constraints and of rigid subsystems, and the comparison with degree of freedom counting
  2. J. T. Schwartz, Fast probabilistic algorithms for verification of polynomial identities, Journal of the ACM 27(4), 701 to 717, 1980, the bound on the probability that a nonzero polynomial vanishes at a random point of a grid
  3. L. Asimow and B. Roth, The rigidity of graphs, Transactions of the American Mathematical Society 245, 279 to 289, 1978, generic points are regular points, where the rank of the rigidity matrix is maximal and decides rigidity
  4. Qiang Zou and Hsi-Yung Feng, On limitations of the witness configuration method for geometric constraint solving in CAD modeling, 2019, the limitations of the method for the three tasks of characterizing the constraint state, decomposing the system and prioritizing constraints
  5. Meera Sitharam, Audrey St. John and Jessica Sidman (editors), Handbook of Geometric Constraint Systems Principles, CRC Press, 2018, the chapters on combinatorial rigidity and on the analysis of constraint systems

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • three classic examples