The exact distance

frechet_c_compute_exact(P, Q) returns the continuous Fréchet distance with no tolerance: the critical value of Alt and Godau that the distance equals, computed in floating point. On the benchmark of Conradi, van der Hoog and Rotenberg (400 pairs of real planar curves), it takes 6.1 s in total on one thread, against 74.3 s and 65.7 s for the two variants of their exact C++ code, and it is faster on all pairs but one. On traffic and video curves in ℝ^963 and ℝ^19200 it is 16 to 18 times faster than Fred on one thread (see High-dimensional curves: comparison with Fred).

using FrechetDist

d = frechet_c_compute_exact(P, Q)                    # a Float64
frechet_c_decide_exact(P, Q, d)                      # true
frechet_c_compute_exact(P, Q; method = :tables)      # the same, by the reference search

Critical values

The distance is one of the values of r at which the free space changes its connectivity (Alt and Godau, 1995):

  • vertex–vertex: the distance between the first vertices, or the last ones;
  • vertex–segment: the distance from a vertex of one curve to a segment of the other (a free interval on a cell edge appears);
  • monotonicity: the distance at which a point of a segment is equally far from two vertices of the other curve (two free intervals on the same row of cell edges line up, so that a monotone path can pass from one to the other).

There are O(n m) of the first two kinds, but O(n m (n + m)) monotonicity values. The distance is the smallest critical value that the decision procedure accepts.

The algorithm

frechet_c_compute_exact implements the randomized algorithm of Har-Peled and Raichel, The Fréchet distance revisited and extended (Section 6), with two ways to narrow the search:

  1. The interval. For long curves in low dimension (N² ≥ 16 (n + m) d), a bisection with the fast decision procedure (see Deciding, and the distance by bisection) narrows the search to an interval of relative width 1e-10. Otherwise a random sample of 4N² critical values (O(1) each from the tables below), binary searched with the decision procedure, leaves an interval with O(N log N) critical values, with high probability.
  2. The critical values in it. A kinetic sweep lists the monotonicity values in the interval, segment by segment (Section 6.2.1 of the paper): the spheres of radius δ around the vertices of the other curve cut the segment in up to two points each, and as δ grows, two points of different spheres swap their order along the segment exactly at a monotonicity value of the two vertices. The points are kept in a balanced search tree (DataStructures' SortedSet) in their order at the current δ, and only neighbors can swap next: O(log N) per event. After a bisection, the values are computed directly from the coordinates, and the sweep runs only on segments where a point can enter, leave, or change order within the interval: on most segments, all of them are quiet.
  3. The search. A binary search over the sorted values, with the decision procedure, finds the smallest accepted one.

There are two ways to make the decisions of the search:

  • Without tables (the default, method = :auto, after a bisection): by the fast decision procedure, in O(n + m) memory. It certifies the ends of the interval, searches the values, and checks minimality: nothing well below the result may be accepted. When a check fails, the search is done again on the tables.
  • On the tables (method = :tables, or when there is no bisection): the distance from every vertex to every segment of the other curve, tabulated once in O(n m d) time and 40 n m bytes (on all of Julia's threads; the result does not depend on their number), and every decision made by the plain cell-by-cell sweep on them, O(n m) each. This search is independent of the filters and the box search of the fast decision procedure: it is the reference the default is checked against.

The two give the same result, bit for bit, on every input tested (below). The random sample affects only the running time: every rng gives the same result.

Rounding. A candidate counts as accepted when the decider accepts it plus 64 ulps (a relative 1.4e-14), which absorbs the different rounding of the decider and of the critical value. Comparisons that decide whether a point can be quiet use squared distances with a margin, and one square root per vertex.

Results

One thread (julia -t 1), AMD Ryzen 7 5700G, Julia 1.13.4, g++ 16.2.

The frog benchmark

The benchmark of Conradi, van der Hoog and Rotenberg, On computing the (exact) Fréchet distance with a frog (SoCG 2026, arXiv 2512.07728): eight sets of real planar curves (GPS traces of people, pigeons, vehicles and ocean drifters, and the pairs of its OV set); the first 50 pairs of each. Their code computes the exact distance on integer coordinates (scaled by 10^5 to 10^7); its two variants are a sweep line and a Dijkstra search, run with a 60 s timeout per pair, built with -O3 -march=native -fno-math-errno -ffp-contract=off (ruby examples/benchmarks/reproduce.rb exact reruns it). Total seconds (FrechetDist: one timed run; frog: one run):

Setpairsfrechet_c_compute_exacton the tablesfrog sweepfrog Dijkstra
geolife501.114.719.519.88
pigeons503.8515.9220.6220.51
athens500.250.906.928.16
ov500.410.4230.3719.98
chicago500.010.050.690.67
drifter500.421.665.705.99
unid500.000.420.450.45
berlin500.000.000.010.01
total4006.0624.0874.2865.66
  • frechet_c_compute_exact is faster than the frog sweep on every pair, and than the frog Dijkstra search on all but one (a Berlin pair, both well under a millisecond). On the largest pair (pigeons, 47,871 × 23,450 vertices) it takes 0.16 s, against 0.42 s and 0.44 s.
  • "On the tables" is method = :tables: the search of the critical values on the tables, without the bisection that narrows the interval first. It gives the same values, bit for bit.
  • On the sets where frog's integer coordinates are exact (pigeons, athens, OV, drifter, unid), the two agree to 7.6e-14 relative.
  • No pair timed out.

Checks

The default (bisection, then the search without tables) and method = :tables give the same value, bit for bit, on the 400 benchmark pairs, on 3000 random small cases (random curves in 1 to 4 dimensions, grids with many equal distances, collinear curves that go back and forth), and on 1500 planar random walks of 20 to 200 vertices; the narrow listing equals the full listing on 3003 narrow intervals (examples/benchmarks/exact_checks.jl; ruby examples/benchmarks/reproduce.rb checks). The test suite also compares the result with an independent oracle, checks that it does not depend on the random sample, and checks exact values such as 1 for curves whose distance is exactly 1.

High dimensions

On high-dimensional curves the tables are the way: the bisection costs a decision on the curves per step, O((n + m) d), against O(1) per sampled value. On the traffic, video curves in ℝ^963 and ℝ^19200 of High-dimensional curves: comparison with Fred, the exact distance is 16 to 18 times faster than Fred on one thread, and Fred returns a value that is too low for 5 of the 55 pairs. In a Hilbert space known through squared distances, the tables are computed from the cached distances (see Curves in Hilbert spaces).