In a metric space , let the nonempty compact set lie in the open set . If is nonempty, the distance to a set is a continuous function of : the triangle inequality gives . Since is a closed set, this distance is strictly positive on . The extreme value theorem attains its minimum on , so
If is empty, the extended-real convention gives . This result provides a single positive neighbourhood radius that stays inside at every point of . Compactness is essential: in the real line has zero distance between two sets from , although each point of has positive distance to a set from that complement.
Put . This is a closed set. First assume is nonempty. The Heine-Borel theorem makes the nonempty bounded closed set a compact set. By the preceding parts, is a continuous function and is strictly positive at every , because .
The extreme value theorem gives attaining its minimum. Therefore
The equality with the distance between two sets follows by taking the two infima successively. Crucially, compactness supplies a point attaining the minimum; positivity at each point alone would not make an arbitrary infimum positive. This is the principle that a compact subset of an open set has positive distance from its complement.
If , its complement is empty. With the usual extended-real convention , the stated inequality holds in that case too.