Abstract 1 Introduction 2 Language Similarity Notions in the Literature 3 Asymptotic Hausdorff 4 Formal Languages and Distances 5 On the Computation of 𝔸ned 6 Discussion References

Asymptotic Hausdorff and Language Similarity

Dana Fisman ORCID Institute for the Theory of Computing, Stein Faculty of Computer and Information Science, Ben Gurion University, Beer Sheva, Israel    Gal Meirom ORCID Institute for the Theory of Computing, Stein Faculty of Computer and Information Science, Ben Gurion University, Beer Sheva, Israel
Abstract

We introduce the Asymptotic Hausdorff lifting, denoted 𝔸d, a general method for lifting an element-level metric d to a (pseudo-) metric on sets, that captures asymptotic similarity in infinite domains equipped with a notion of size. The construction is designed to be insensitive to finite deviations and to avoid the limitations of classical Hausdorff-based approaches, which are often overly sensitive to outliers and fail to reflect asymptotic behavior.

Formal languages provide a central motivating instance of this framework, where elements are words and sets are languages. When applied to normalized edit distances, the Asymptotic Hausdorff lifting yields metric-valued distances between languages that reflect asymptotic edit behavior while preserving metric structure. We study the equivalence classes of regular languages induced by 𝔸d for normalized edit distances d, and characterize their asymptotic essence. Focusing in particular on the normalized edit distance of Marzal and Vidal, ned, we investigate the computation of 𝔸ned for regular languages and for bounded context-free languages.

Keywords and phrases:
Automata theory, formal Languages, Metric Spaces, Language similarity, Edit Distance, asymptotic Analysis
Category:
Track B: Automata, Logic, Semantics, and Theory of Programming
Funding:
Gal Meirom: Supported by ISF grant 2507/21 and Frankel Center for Computer Science, BGU.
Copyright and License:
[Uncaptioned image] © Dana Fisman and Gal Meirom; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Formal languages and automata theory
; Theory of computation Design and analysis of algorithms
Acknowledgements:
We thank Dror Fried, Guy Ofek, Omer Shachar and Gera Weiss for helpful comments on an early draft of this paper.
Related Version:
Full Version: https://arxiv.org/abs/2605.09668
Editors:
Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis

1 Introduction

Various applications in formal methods call for a notion of similarity between languages. Such a need arises, for example, in applications of program repair, robustness quantification, and grammatical inference. In all these settings, similarity between two languages X and Y is grounded in a notion of edit operations required to transform words xX into words yY. More generally, edit distance itself has been extensively studied in areas such as error-correcting codes, parsing theory, speech recognition, and molecular biology, highlighting its broad relevance.

In the context of robustness, Filliot et al. [9] study the computation of infxXinfyYd(x,y), where d(x,y) is a cost function for editing x into y, implemented by a given weighted transducer. Similarity functions of this form are also studied by Mohri [19], Samanta et al. [23], and Henzinger et al. [14]. The latter also considers the dual quantity supxXsupyYd(x,y).

In repair applications, Benedikt et al. [2, 4] consider the standard edit operations of insertion, substitution, and deletion (with uniform costs) required to transform a string in X into a string in Y. In [2], they ask whether one can transform any word in X into a word in Y using a bounded number of edits. For example, if X=ac and Y=abc, then at most one edit operation (inserting a b) is required to transform any string in X into a string in Y. In contrast, if X=a and Y=(ab), then there is no bound on the number of edits required to transform a word in X into a word in Y. They note that requiring a uniform bound on the number of edits is a strong restriction, and in subsequent work [4] they therefore study the percentage of letters that need to be edited. In the latter example, the expected value is 12, since words in X are of the form an and such a word requires n2 edit operations to transform into a closest word in Y.

In general, one expects such similarity notions to induce a metric or a pseudo-metric. Some applications, such as repair, are inherently asymmetric; in such cases, one may only require adherence to the triangle inequality 𝒟(X,Z)𝒟(X,Y)+𝒟(Y,Z). The triangle inequality is nevertheless central, as it ensures alignment with user intuitions, enables compositional reasoning (inferring distances between X and Z from distances between X,Y and Y,Z), and is computationally beneficial in optimization and learning tasks by enabling pruning, efficient indexing, and incremental updates.

It turns out that none of the similarity notions used in the works mentioned above constitute a metric. In this work, we ask whether it is possible to obtain a metric or a pseudo-metric between languages when the underlying similarity between words is based on the rationale of [4] and captures the percentage of edit operations required to transform words in X to words in Y in the limit. Since we are interested in percentages, we restrict attention to functions returning values in [0,1]. That is, we seek a function 𝒟:P(Σ)×P(Σ)[0,1] that is a metric (or pseudo-metric) and captures the intuitions underlying [4].

We next present several examples that formalize the desired intuitions and requirements emerging from [4].

Requirement 1 (Percentage).

As discussed above, one may expect 𝒟(a,(ab)) to be 12. Rather than insisting on a specific numerical value, we require a monotonicity property:

𝒟(a,(ajb))<𝒟(a,(aib))for all j>i.

Intuitively, this reflects that as the percentage of symbols requiring editing increases, so does the induced distance.

Requirement 2 (Outlier-insensitive, finite-subset indifferent).

Consider repairing X=b to Y=a. Since any word xX is of the form bn and such a word requires at least n edits (i.e. one edit per character), we expect 𝒟(b,a)=1. Consider now repairing X=ab to Y. The percentage of edit operations for words of the form an is zero, while the percentage for the word b is 1. Consequently, the supremum of the edit-percentage from words in X to Y is 1. This is undesired as it gives the impression that ab is as farthest as possible from a, while we expect a value reflecting they are quite similar. Similarly, we expect repairing abbb to (acc) to return 23 and not 1, since for all but finitely many words, the percentage is 23. That is, we expect 𝒟 to be outlier-insensitive, which we formulate as follows: 𝒟(X,Y)=𝒟(XF,Y) for all infinite languages X,Y and finite languages F. Note that this requirement necessarily violates identity of indiscernibles on the full powerset, as it entails 𝒟(XF,X)=𝒟(X,X)=0. Thus, we seek for a pseudo-metric rather than a metric.111The identity of indiscernibles prescribes that d(x,y)=0 iff x=y and a pseudo-metric relaxes this condition to require only d(x,x)=0.

Requirement 3 (Bounded-edits insensitivity).

Consider now repairing X′′=aba to Y=a. In contrast to the previous example, every word xX′′ requires at least one edit operation to reach a closest word in Y (in fact, exactly one). However, to capture the percentage nature, we note that the percentage of the number of edits required to transform anba to an+ diminishes as n or grows. Note that this is true also if we consider repairing abka to a. While now every word requires k edits, still as n or grows to infinity, the k edits required are negligible compared to the length of the word. Thus, the following formal requirement emerges from [4]: If there exists a bound k such that every xX can be transformed into a word in Y with at most k edits and vice versa, then 𝒟(X,Y)=0.

 Remark 1.1.

One may argue that it is desirable to distinguish the language a from ab or from aba. Indeed, there exist language similarity measures that make such distinctions, in particular [1]. In applications where such sensitivity is required, one may combine such a measure with the distance developed here (for example, via a product construction). In this work, however, we deliberately impose invariance under finite subsets of words and a finite number of edits, as these capture the asymptotic notion of similarity that we and [4] aim to capture.

To summarize, we seek a language similarity function with a bounded codomain, specifically 𝒟:P(Σ)×P(Σ)[0,1], that is a pseudo-metric and satisfies the following requirements:

  1. 1.

    Percentage nature: 𝒟(a,(ajb))<𝒟(a,(aib)) for all j>i.

  2. 2.

    Outlier insensitivity: 𝒟(X,Y)=𝒟(XF,Y) for all infinite X,Y and finite F.

  3. 3.

    Bounded-edits insensitivity: If there exists a bound k such that every xX can be transformed into a word in Y with at most k edits and vice versa, then 𝒟(X,Y)=0.

Since languages are sets of words, and we seek a similarity notion induced by edit distance between words, a natural question is whether there exists a general method to lift a metric d on a universe M to a metric 𝒟 on subsets of M that meets these requirements. A classical lifting scheme is given by the Hausdorff distance. Let us first recall the common way to define a distance between an element x and a set Y. This measure, d:M×P(M)0 is defined as d(x,Y)=infyYd(x,y), i.e. it measures the distance of x to the closest element y in Y.222Its use in the context of formal languages goes back to [25] where d is the Levenshtein Edit Distance [17]. Next, the directional (asymmetric) distance from set X to set Y is defined as d(X,Y)=supxXd(x,Y), namely it is the distance of the farthest element in X to Y. Finally, given d:M×M0, the Hausdorff distance with respect to d is the function d:P(M)×P(M)0 defined by d(X,Y)=max{d(X,Y),d(Y,X)}

i.e. it takes the maximum of the directional distance from X to Y and in the other direction.

While the Hausdorff lifting yields a metric and can be used to lift edit distances between words to distances between languages, applying it to the standard Levenshtein edit distance ed [17] fails to produce a similarity measure with a percentage nature, and the resulting values are unbounded. For example, ed(a,abb)=2 and ed(a,(ab))=.

Replacing ed by a normalized edit distance such as ned [18], ged [26], or ced [8] restores the percentage nature, but does not address a more fundamental limitation: the Hausdorff distance is inherently sensitive to outliers.333Formal definitions of ed, ned, ged, and ced appear in Subsection 4.1. At a high level, ed denotes the minimum number of edit operations, whereas ned, ged, and ced correspond to different normalized variants. Indeed, while ned(a,(ab))=12, we have ned(a,abb)=1. This shortcoming is not specific to edit distance, but arises from the supremum-based definition of the Hausdorff construction itself.

The Hausdorff distance is well suited to lifting distances on finite universes or universes where elements are conceived as having the same size. In contrast, it is size-oblivious and ill suited to infinite universes whose elements admit an unbounded notion of size, as is the case in formal languages, where languages of interest are necessarily infinite and contain words of unbounded length. Similar limitations of Hausdorff-type constructions have been observed in prior work on language similarity measures, leading to the proposal of various alternative notions of language similarity; we review these in Section 2.

Our main contribution is a new lifting scheme 𝔸d:P(M)×P(M)0, which we term Asymptotic Hausdorff. This construction lifts an element-level (pseudo) metric d to a set-level pseudo-metric while remaining insensitive to finite outliers and respecting unbounded growth in element size. Unlike the classical Hausdorff distance, it is specifically suited to infinite universes equipped with a natural size notion and yields metric-valued distances whose behavior is asymptotically aligned with the underlying element-level distance.

The lifting is defined for element-level metrics satisfying a property we call the asymptotic separation property. We show that normalized edit distances such as ned, ged, and ced satisfy this property, and that the resulting language distance meets all of our stated requirements. We further show that this property is satisfied by other common distance functions such as the Euclidean distance, the Lp metric, and in fact every norm-induced metric. This generality suggests applications beyond the formal-languages setting, particularly in domains that employ finite representations or generators of infinitely many objects, equipped with a natural notion of size.

One such application arises in the study of graph spanner constructions. A spanner is a subgraph of a given weighted graph and thus shares its vertex set with the input. Spanner constructions are thus naturally viewed as set of objects indexed by graph size. Any metric dist comparing spanners over the same graph – for example, based on stretch, distortion, or sparsity – can be lifted via 𝔸dist to obtain an asymptotic comparison between spanner constructions, focusing on large-scale behavior while abstracting away finite-size effects.

Another example comes from procedural texture generators in computer graphics. Such generators are commonly modeled as functions f:k[0,1], for k{2,3}, producing a continuous scalar field that is mapped to concrete values such as colors, materials, or block types. Well-known instances include Perlin noise, simplex noise, Worley noise, and their fractal variants. Similarity between generators is typically assessed by comparing the finite structures they induce over bounded spatial regions (often called patches), independently of spatial location. By equipping such patches with an appropriate distance measure that captures their similarity, and using their spatial extent as the size parameter, the lifting 𝔸 naturally captures asymptotic similarity between texture generators.

After presenting the abstract framework of the Asymptotic Hausdorff lifting, we return to edit-operation-based language similarity measures, study their properties, and establish complexity results for computing our primary instance, 𝔸ned. For regular languages, we prove Pspace-hardness and give an approximation algorithm in coNExp. For bounded context-free languages (BCFLs), we present an exact algorithm running in Exp.

Missing proofs are available in the full version.

2 Language Similarity Notions in the Literature

A variety of notions for measuring similarity between formal languages have been explored in the literature, arising from different motivations. In the following, we survey these measures through the lens of the requirements identified in the introduction, and highlight limitations that motivate our Asymptotic Hausdorff metric.

Complexity-based similarity measures

Since our focus is on formal languages, where (possibly infinite) languages are finitely represented by some computational model, one natural approach is to define a distance measure between languages via a distance between their representations. To ensure that such a measure is insensitive to the particular choice of representation, one may appeal to a canonical representation, when one exists for the class of languages under consideration.

Kolmogorov and automata-size based measures.

In this spirit, [15] proposes using Kolmogorov complexity and defines the Kolmogorov distance between languages X and Y as 𝒦(X,Y)=|K(X)K(Y)|, where K(L) denotes the Kolmogorov complexity of the language L. For regular languages, the minimal DFA can serve as a canonical representation, allowing K to be replaced by the number of DFA states. Alternatively, [15] suggests using the size of a minimal NFA, defined as the sum of its states, initial and final states, and transitions.

It is straightforward to see that these notions induce a pseudo-metric. (Indeed, any function of the form 𝒮(X,Y)=|S(X)S(Y)|, where S(L) maps languages to 0, induces a pseudo-metric on the space of languages.) However, 𝒦 and its variants measure differences in the complexity of languages rather than differences between the languages themselves. For example, 𝒦(a,b)=0, since the two languages are equally simple, even though every word in a needs a complete rewrite to transform into a word in b. In contrast, our goal is to define a pseudo-metric under which a and b are as far apart as possible.

Set-theoretic similarity measures

As mentioned in the introduction, since languages are sets, any metric on sets can be used to induce a metric on languages.

Jaccard.

One of the earliest notions of set similarity, dating back to the 19th century, is the Jaccard index, 𝒥¯, along with its dual notion, the Jaccard distance 𝒥, which serves as a dissimilarity measure. These are defined as follows:

𝒥¯(X,Y)=|XY||XY|𝒥(X,Y)=|XY||XY| (1)

where denotes symmetric set difference. The Jaccard index and distance are undefined when |XY| is 0 or , and thus are inapplicable for infinite languages.

Cesáro-Jaccard.

For infinite languages, one approach is to consider one of the limits

limn𝒥(X(n),Y(n))  or limn𝒥(X(n),Y(n)) (2)

where L(n) (resp. L(n)) denotes the set of words in L of length n (resp. at most n). However, as shown in [22], these limits need not exist. For example, considering the left limit, if X=a and Y=(aa), then the fraction evaluates to 0 for even n and to 1 for odd n.

To address this issue, [22] propose smoothing the sequence using the Cesàro average, yielding the following distance measure between languages:

𝒥𝒞(X,Y)=limn1ni=1n𝒥(X(i),Y(i))=limn1ni=1n|(XY)(i)||(XY)(i)|

They show that 𝒥𝒞 is a pseudo-metric.

However, while the Cesàro-Jaccard distance successfully addresses the fact that formal-language theory is primarily concerned with infinite languages, and is finite-subset indifferent, it does not incorporate any notion of similarity between individual words. As a result, both 𝒥𝒞(ca,ba)=1 and 𝒥𝒞(c,b)=1, despite the fact that in the former pair the edit cost per word is uniformly bounded (one edit per word), while in the latter it grows unboundedly with word length. Our goal, by contrast, is a metric that reflects this asymptotic discrepancy, identifying the first pair as close and the second as far.

Discounted-sum Jaccard.

Another approach to addressing the potential non-convergence of the limits in Equation 2 is to employ a discounted-sum construction. This idea was recently proposed in [5]. In particular, they show that

𝒥𝒟𝒮λ(X,Y)=(1λ)n=0λn𝒥(X(n),Y(n))=(1λ)n=0λn|(XY)(n)||(XY)(n)|

is a pseudo-metric for every λ(0,1).

However, this construction places greater weight on discrepancies at smaller word lengths, which limits its ability to capture asymptotic percentage behavior. In particular, differences among short words dominate the value of the distance, even when they become negligible relative to word length. For example, for λ=12 we obtain 𝒥𝒟𝒮λ(a>2,a)=78 and 𝒥𝒟𝒮λ(a2b>2,a)=18, despite the fact that the former pair differs only on finitely many short words, while the latter exhibits a persistent asymptotic discrepancy.

Shortlex vector approach.

Another approach explored in [15] begins by ordering all words over the alphabet using the shortlex order (first by length and then lexicographically). A language L is then represented by an infinite binary vector vL{0,1}ω, where vL(i)=1 if and only if the i-th word belongs to L. The distance between two languages X and Y is defined by applying a chosen distance measure between binary vectors to vX and vY.

Since vX(i)=vY(i) precisely when the i-th word either belongs to both X and Y or to neither, this construction effectively accounts for words in the symmetric difference (and intersection) of the two languages. The precise behavior of the resulting language distance depends on the specific choice of vector distance. Nevertheless, this approach does not incorporate any notion of similarity between words themselves, making it difficult to see how it could determine ba and ca as being closer than b and c.

Word-level lifted similarity measures
Predicate-lifted Jaccard.

In [7], it is observed that language similarity notions can benefit from enriching set-based similarity measures, such as the Jaccard distance, with an explicit notion of distance between individual words. Rather than using the strict symmetric difference the approach of [7] introduces a predicate φ that captures when two words are considered sufficiently close. The comparison between X and Y considers only pairs of words deemed sufficiently close according to φ. For example, the predicate φ(x,y) may be defined as hamming(x,y)c0, where hamming denotes the Hamming distance between words and c0 is a fixed constant. Another example from [7] is φ(x,y)=lcs(x,y)c0, where lcs denotes the length of the longest common subsequence.

Given such a predicate φ, they define 𝒥¯φ(X,Y)=|φ(X,Y)||XY| where φ(X,Y)={xXyY,φ(x,y)}{yYxX,φ(x,y)}. This construction essentially replaces the strict intersection in the standard Jaccard index with the set of all words that are sufficiently close according to the predicate φ.

Predicate-lifted information-rate.

The focus in [7] is on extending the notion of information rate introduced by Shannon and Weaver [24] and applied to formal languages by Chomsky and Miller [6]. The information rate of a language L is defined as (L)=limnlog|L(n)|n. This notion pertains to a single language rather than a pair of languages and is intended to capture the density of a language. In [7], an extension for two languages, which additionally incorporates a predicate, is suggested: φ(X,Y)=(φ(X,Y))(XY).

Since the information rate is not a (pseudo-)metric, it does not serve as a candidate for our purposes.

Predicate-lifted Cesàro-Jaccard.

While not suggested in the literature, we note that the use of a predicate can also be applied to the Cesàro–Jaccard distance. For example, one can define 𝒥𝒞φ(X,Y) analogously to 𝒥𝒞(X,Y), by replacing (XY)(n) with (φ¯(X,Y))(n) where φ¯(X,Y)={(x,y)(x,y)φ(X,Y)}. Taking the predicate φ to be ed(x,y)1, we obtain 𝒥𝒞φ(ca,ba)=0, which is desirable and resolves the issue that 𝒥𝒞(ca,ba)=1. Similarly, defining φ as ned(x,y)12 gives 𝒥𝒞φ(a,(ba))=0 while 𝒥𝒞φ(a,(bba))=1.444The formal definition of ed and ned are deferred to Subsection 4.1. Intuitively, ed counts minimal number of edit operations, and ned minimal percentage of edits. In particular, for every k we have ed(cak,bak)=1, ned(a2k,(ab)k)=12 and ned(a3k,(bba)k)=23.

However, the use of a predicate necessitates choosing a fixed threshold, which prevents distances from degrading gradually and makes it impossible to satisfy the monotonicity property described in Requirement 1.

We now turn to language similarity notions that lift a similarity measure between words.

Infinitum and Supremum based.

As mentioned in the introduction, the measure 𝕀d(X,Y)=infxXinfyYd(x,y), where d assigns a cost to string transformations, has been used in the literature [19, 23, 9]. However, this measure is not a metric. For example, taking d to be the normalized edit distance ned, we have 𝕀ned(a+,b)=1>0+0=𝕀ned(a+,a)+𝕀ned(a,b). Moreover, 𝕀ned(a,b)=0, illustrating the outlier sensitivity of 𝕀d (the outlier being ε). By similar reasoning, the dual notion 𝕊d(X,Y)=supxXsupyYd(x,y) is also not a metric and suffers from outlier sensitivity; for instance, 𝕊ned(abb,a)=1.

Prefix-distance based.

Considering variations in word-level similarity, several works examine the prefix distance between words. The prefix distance between two strings x and y, denoted prf(x,y), is defined as the number of characters in x and y that do not belong to their longest common prefix. The Hausdorff lifting of prf, denoted prf, has been studied in various works [20]. We note that prf, being a Hausdorff lifting, is sensitive to outliers. In addition, it is unbounded: for example, prf(b,a)=, and it is also sensitive to bounded edits, as seen from prf(ba,a)=.

𝓐𝓒, Benedikt et al.’s measure.

As mentioned in the introduction, Benedikt et al. [3] studied the number of edits required to repair a word in X into a word in Y. Since this quantity is often unbounded, their subsequent work [4] focused on capturing the percentage of edits required in the limit. Their work forms the basis for our approach. The exact formula they use is 𝒜𝒞(X,Y)=limnsupxX|x|ninfyYed(x,y)|x|.
It is straightforward to see that 𝒜𝒞(X,Y)[0,1] for any pair of languages X,Y. We note that 𝒜𝒞 is asymmetric by nature. For applications requiring symmetry, one can define 𝒜𝒞(X,Y)=max(𝒜𝒞(X,Y),𝒜𝒞(Y,X)). However, the critical issue is that 𝒜𝒞 (and thus 𝒜𝒞) violates the triangle inequality.

Claim 2.1.

𝒜𝒞 does not satisfy the triangle inequality.

In summary, while a variety of language similarity measures have been proposed, existing approaches face key limitations. Complexity-based measures capture overall representation size but ignore word-level structure; set- and vector-based measures fail to account for word similarity or are sensitive to infinite languages; and word-level or edit-distance–based liftings can be outlier-sensitive or fail to satisfy fundamental metric properties such as the triangle inequality. These observations motivate the need for a pseudo-metric that simultaneously accounts for word-level similarity, is robust to outliers, and preserves essential metric properties. In the next section, we introduce such a construction: the Asymptotic Hausdorff metric, 𝔸d, which generalizes the Hausdorff lifting to capture asymptotic behavior at the language level. We first present it at an abstract level, and later specialize to 𝔸ned, the lifting of the normalized edit distance ned [18].

3 Asymptotic Hausdorff

We turn to define the central notion of the paper, the Asymptotic Hausdorff lifting. In what follows we assume M is a domain (set) and d:M×M0 is a metric or a pseudo-metric. That is, we assume d satisfies the three pseudo-metric requirements:

  1. 1.

    Reflexivity: d(x,x)=0 for all xM.

  2. 2.

    Symmetry: d(x,y)=d(y,x) for all x,yM.

  3. 3.

    Triangle inequality: d(x,z)d(x,y)+d(y,z) for all x,y,zM.

3.1 Defining the Asymptotic Hausdorff Lifting

As discussed in the introduction, we are interested in domains whose elements are equipped with a natural notion of size. This allows us to distinguish between bounded and unbounded behavior and to focus on asymptotic phenomena.

Definition 3.1 (Size notion).

A size notion for M is a map s:M0.

Henceforth, we assume M is equipped with such a size notion s. We are interested in sets with increasing size of elements. To capture this we introduce the following definition, which considers infinite sequences of elements (rather than sets).

Definition 3.2 (s-bounded sequence).

A sequence (xi)i=1 is called s-bounded if there exists some N such that lim supis(xi)N. Otherwise we say it is s-unbounded.

We are interested in element-level distances d that separate s-bounded sequences from s-unbounded sequences, in the sense that the asymptotic distance is as large as possible.

Definition 3.3 (Asymptotic separation property).

We say d has the asymptotic separation property if for every s-unbounded sequence (xk)k=1, and s-bounded sequence (yk)k=1, d satisfies limkd(xk,yk)=supd where supd is the supremum of the image of d.

We now have all the ingredients needed to define the Asymptotic Hausdorff lifting. As in the Hausdorff lifting, we first define a directional distance, and then take the maximum of going from X to Y and in the other direction.

Definition 3.4 (Asymptotic Hausdorff lifting).

Given a pseudo-metric d on M, the two functions 𝔸d and 𝔸d of type 𝒫(M)×𝒫(M)0 are defined as follows
𝔸d(X,Y)=deflimksupxXs(x)kinfyYd(x,y) 𝔸d(X,Y)=max{𝔸d(X,Y),𝔸d(Y,X)}

We refer to 𝔸d(X,Y) as the asymptotic directional distance from X to Y and to 𝔸d as the asymptotic Hausdorff lifting of d.

3.2 Properties of the Asymptotic Hausdorff Lifting

We first establish that the asymptotic directional distance is well defined.

Claim 3.5.

𝔸d(X,Y) is well defined for all X,YM.

Equivalently, the asymptotic directional distance 𝔸d(X,Y) can be defined as the supremum over all sequences (xn)n1X with s(xn), of the limit lim supninfyYd(xn,y). That is, as the worst-case asymptotic distance to Y attained along sequences of elements of X whose size grows unboundedly.

Claim 3.6 (Equivalent definition to asymptotic directional distance).

Let X and Y be sets. Then 𝔸d(X,Y)=sup(xn)n=1Xs(xn)n,nlim supninfyYd(xn,y)

We next show that the asymptotic separation property is sufficient to lift the triangle inequality to the asymptotic setting.

Theorem 3.7 (𝔸d satisfies the triangle inequality).

Let d be a pseudo-metric that has the asymptotic separation property. Then 𝔸d satisfies the triangle inequality.

The proof makes use of the following claim.

Claim 3.8 (Point-wise triangle inequality).

Let M be a set, d a pseudo-metric on M and Z a subset of M. Then for every x,yM infzZd(x,z)d(x,y)+infzZd(y,z)

Proof.

Let ZM and x,yM. As d is a pseudo-metric d(x,z)d(x,y)+d(y,z) for every zZ. Thus infzZd(x,z)infzZ{d(x,y)+d(y,z)}=d(x,y)+infzZd(y,z).

Proof of Theorem 3.7.

Let X,Y,Z be subsets of M and let ε>0. Let N such that

supyYs(y)NinfzZd(y,z)𝔸d(Y,Z)+ε2. (3)

If all infinite sequences (xk)k=1X are s-bounded, then X is an s-bounded set and thus
𝔸d(X,Z)=limksupxXs(x)kinfzZd(x,z)=limksupxinfzZd(x,z)=0𝔸d(X,Y)+𝔸d(Y,Z).

Otherwise, let (xk)k=1X be some arbitrary sequence that has an infinite subsequence (xki)i=1 such that (s(xki))i=1 is a non decreasing sequence that tends to . We consider two cases:

Case 1.

There exists a subsequence (kj)j=1 such that for every yY that satisfies s(y)N, we have that d(xkj,y)>infyYd(xkj,y)+ε2.

Let Yxkj be the set of elements that satisfy d(xkj,y)infyYd(xkj,y)+ε2. We get that YxkjYN where YN={yY:s(y)N}. Therefore as d has the asymptotic separation property

𝔸d(X,Y) =limksupxXs(x)kinfyYd(x,y)limjinfyYd(xkj,y)
=limjinfyYNd(xkj,y)=(Definition 3.3)supd.

Since supd bounds 𝔸d(A,B) for any A,B, together we get that 𝔸d(X,Y)=supd and

𝔸d(X,Z)supd=𝔸d(X,Y)𝔸d(X,Y)+𝔸d(Y,Z).
Case 2.

There exists k such that for every kk there exists ykY that satisfies s(yk)N and also satisfies

d(xk,yk)infyYd(xk,y)+ε2 (4)

As d is a pseudo-metric by Claim 3.8 we know that

infzZd(xk,z)d(xk,yk)+infzZd(yk,z) (5)

And because s(yk)N and asupA for any A{a} we get

infzZd(yk,z)supyYs(y)NinfzZd(y,z)(3)𝔸d(Y,Z)+ε2 (6)

Putting it all together we get

infzZd(xk,z) (5)d(xk,yk)+infzZd(yk,z) (7)
(4)infyYd(xk,y)+ε2+infzZd(yk,z)
(6)infyYd(xk,y)+𝔸d(Y,Z)+ε.

Note that this inequality is satisfied for an arbitrary sequence in X with size that tends to . Using Claim 3.6 there exists (pk)k=1 a sequence that satisfies

ε+lim supkinfzZd(pk,z)𝔸d(X,Z). (8)

Thus, we finally get

𝔸d(X,Z) (8)lim supkinfzZd(pk,z)+ε
(7)lim supk{infyYd(pk,y)+𝔸d(Y,Z)+2ε}
=lim supk{infyYd(pk,y)}+𝔸d(Y,Z)+2ε
sup(xk)k=1Xs(xk)k,klim supk{infyYd(xk,y)}+𝔸d(Y,Z)+2ε
=3.6𝔸ned(X,Y)+𝔸d(Y,Z)+2ε.

As ε is arbitrary small we get that 𝔸d(X,Z)𝔸d(X,Y)+𝔸d(Y,Z).

Since 𝔸d obviously satisfies reflexivity and symmetry, an immediate corollary of Theorem 3.7 is that 𝔸d is a pseudo-metric.

Theorem 3.9 (Asymptotic Hausdorff is a pseudo-metric).

𝔸d is a pseudo-metric when d has the asymptotic separation property.

Returning to our primary motivating setting of words and language, in the next section, we show that many word similarity measures satisfy the asymptotic separation property, and therefore can be lifted to pseudo-metrics between languages. We expect that similar results hold for metrics on trees and graphs, but we do not pursue this direction here.

More broadly, this naturally raises a stronger question: how restrictive is the asymptotic separation property in general? We therefore turn to identifying broad classes of distance functions for which this property holds. The following theorem shows that the asymptotic separation property is in fact quite common: every metric induced by a norm satisfies it.

Theorem 3.10 (Norm-induced metrics satisfy asymptotic separation).

Let (M,) be a normed space with d(x,y)=xy and s(x)=x. Then d has the asymptotic separation property.

Corollary 3.11.

Let (M,) be a normed space and d(x,y)=xy. Then 𝔸d is a pseudo-metric on 𝒫(M).

As an immediate consequence of the corollary, the Asymptotic Hausdorff lifting applies to all metrics induced by norms. This includes, in particular, the Euclidean distance and, more generally, Lp distances for any p1. Hence, 𝔸d can be meaningfully applied in continuous settings alongside the discrete ones considered earlier.

While we arrived at this notion from the perspective of formal languages, as discussed in the introduction, we believe that it is applicable in a much broader range of settings. In particular, it is well suited to contexts in which infinite sets arise from finite representations or generators, are equipped with a natural notion of size, and contain elements whose size is unbounded. This situation commonly occurs, for example, when considering functions defined over infinite domains, where each input x induces an element f(x) in the set generated by the function.

4 Formal Languages and Distances

We now focus on language similarity notions obtained via the Asymptotic Hausdorff lifting. This construction applies to a variety of word-level metrics, including both classical and normalized edit distances. While all are suitable for lifting, only normalized metrics are compatible with the percentage-based requirements discussed in the introduction. Among these, the normalized edit distance ned will play a central role and serve as our main point of reference. We begin by briefly reviewing standard distances between words.

4.1 Metrics on words (Preliminaries)

Let Σ be a finite alphabet. For a word xΣ, we write |x| for its length and x[i] for its i-th letter. The empty word is denoted by ε.

One of the oldest metrics on words is the Hamming distance. It measures the distance between x and y as the number of letters on which they differ plus the difference between their lengths. Formally, if x=|x| and y=|y| then hamming(x,y)=|{i:x[i]y[i],imin(x,y)}|+|xy|. Another common simple metric between words is the prefix distance [20]. It measures the number of letters in x and y that are not in the longest common prefix of x and y. Formally, prf(x,y)=|x|+|y|2max{|z|:x,yzΣ}. Beyond these position-based notions, many widely used distances between words are defined in terms of edit operations, which we review next.

Edit operations and edit paths.

We work with the standard edit operations: insertion, deletion, substitution, and no-op. Let Γ^=(Σ{ε})2, and write [ab] for the pair (a,b). The set of edit operations is Γ=Γ^{[εε]}, where [ab] denotes substitution of a by b, [aa] a no-op, [aε] deletion of a, and [εa] insertion of a.

An edit path from x to y is a finite sequence p over Γ such that, writing p=[a1b1][a2b2][anbn], we have a1an=x and b1bn=y. We denote by |p|=n the length of p. Let d:Γ[0,1] assign weights to edit operations. The weight of an edit path p is wgt(p)=i=1nd(ai,bi). Its cost is defined as cost(p)=wgt(p)/|p|. We write p:xy to denote that p is an edit path from x to y.

Edit-distance notions.

Several notions of edit distance have been proposed in the literature, differing mainly in how edit operations are aggregated and normalized. The most basic notion is the Levenshtein (edit) distance [17], denoted ed, which returns the minimum total weight of an edit path transforming x into y.

For applications involving words of substantially different lengths, normalization becomes essential. When words have equal length, normalizing by the word length is straightforward; however, for unequal lengths, naïve normalizations – such as dividing by the maximum, minimum, or sum of the lengths – generally fail to preserve the metric properties (cf. [26]). To address this issue, several normalized variants of edit distance have been proposed, including the normalized edit distance ned [18], the generalized edit distance ged [26], and the contextual edit distance ced [8]. Despite differing in their normalization schemes, all these notions yield bounded distances that satisfy the metric axioms, and are therefore well suited for comparing words of varying lengths.

A common choice of weights is the uniform weight, in which no-op operations have cost 0 and all other edit operations have weight 1. All notions but ced allow non-uniform weights. When non-uniform weights are considered, they must satisfy additional conditions to ensure that the induced distances edd, nedd, and gedd are metrics [26, 10, 11]. Unless stated otherwise, we henceforth assume the uniform weight.

Definition 4.1 (Edit-distance notions).

Let x,yΣ.

  • Levenshtein (edit) distance [17]: edd minimizes the weight of an edit path:

    edd(x,y)=min{wgt(p)p is an edit path from x to y}.
  • Normalized edit distance [18, 10, 11]: nedd minimizes the average cost per operation, by dividing by the edit path length:

    nedd(x,y)=min{cost(p)p is an edit path from x to y}.
  • Generalized edit distance [26]: ged is another way to obtain an averaged cost:

    gedd(x,y)=2edd(x,y)|x|+|y|+edd(x,y).
  • Contextual edit distance [8]: Last, ced provides an averaged cost by considering the context of the edits. Formally, for strings s,s for which ed(s,s)=1, one defines ced(s,s)=1/max(|s|,|s|). For a sequence ρ=(s0,,sk) satisfying ed(si,si+1)=1 for every i<k, let ced(ρ)=i=1kced(si1,si). Then

    ced(x,y)=min{ced(ρ)ρ=(s0,,sk),s0=x,sk=y}.
Example 4.2.

Consider x=aab and y=abac. One edit path from x to y is p1=[aa][ab][ba][εc]. Another edit path is p2=[aε][aa][bb][εa][εc]. We have wgt(p1)=wgt(p2)=3. Since no edit path has smaller weight, it follows that ed(x,y)=3. Applying this value in the definition of ged, we obtain ged(x,y)=233+4+3=35. Since |p1|=4 and |p2|=5, we have cost(p1)=34 and cost(p2)=35. As no edit path has smaller cost, we conclude that ned(x,y)=35. For ced, consider the sequence of strings s0=aab, s1=abb, s2=aba, and s3=abac. Note that ed(si1,si)=1 for all 1i3. Therefore, ced(s0,s1,s2,s3)=13+13+14=1112. However, a different sequence yields a smaller value. In particular, ced(aab,aabc,abbc,abac)=14+14+14=34. Thus, ced(x,y)34.

The values of ed are clearly unbounded. In contrast, the values of ned and ged are bounded by 1 and may attain this bound. The values of ced are unbounded; however, they can be made bounded by considering the variant ced(x,y)=max{1,ced(x,y)} [10, 8]. Finally, we note that ged(x,y)ned(x,y) for all x,y; see the full version.

We establish that each of these notions satisfies the asymptotic separation property, and thus is amenable to lifting via the Asymptotic Hausdorff construction.

Claim 4.3.

The asymptotic separation property holds for ed, ned, ged, ced, and prf.

Corollary 4.4.

𝔸ed, 𝔸ned, 𝔸ged, 𝔸ced, and 𝔸prf, are all pseudo-metrics on the set of languages.

4.2 𝔸 for Normalized Edit Distances

Recall the three requirements given in the introduction. We claim that the three notions of normalized edit distance ned, ged and ced, all satisfy these properties.

Claim 4.5 (𝔸ned,𝔸ged,𝔸ced are finite-subset indifferent).

Let X,Y be infinite language and F a finite languages. Then 𝒟(X,Y)=𝒟(XF,Y) for every 𝒟{𝔸ned,𝔸ged,𝔸ced}.

Claim 4.6 (𝔸ned,𝔸ged,𝔸ced are bounded-edits insensitive).

Let X,YΣ. If k such that for every xX there exists yY such that ed(x,y)<k and vice versa then 𝒟(X,Y)=0 for every 𝒟{𝔸ned,𝔸ged,𝔸ced}.

Claim 4.7 (𝔸ned,𝔸ged,𝔸ced have a percentage nature).

For every 𝒟{𝔸ned,𝔸ged,𝔸ced} we have that 𝒟(a,(ajb))<𝒟(a,(aib)) for all j>i.

Corollary 4.8.

𝔸ned,𝔸ged,𝔸ced satisfy all of our requirements.

Recall (cf. Requirement 1) that one may expect 𝒟(a,(ab))=12 and, more generally, 𝒟(a,(akb))=1k+1. We deliberately adopted a more relaxed requirement, as enforcing these equalities exactly would be overly restrictive. Nevertheless, we show that 𝔸ned does satisfy this stricter behavior, whereas 𝔸ged and 𝔸ced do not.

Requirement 4 (Strict percentage property).

We say that a language metric 𝒟 satisfies the strict percentage property if the following hold:

  • 𝒟(a,(akbl))=lk+l for all k,l0 with k+l1;

  • 𝒟((aib),(akb))=kik+1 for all i<k.

Claim 4.9 (Satisfaction of the strict percentage property).

The strict percentage property is satisfied by 𝔸ned, but not by 𝔸ged or 𝔸ced.

For this reason, we prefer 𝔸ned over 𝔸ged and 𝔸ced.

 Remark 4.10 (Relations).

The following relations between the metrics hold for every pair of languages X,Y: 𝔸ged(X,Y)𝔸ned(X,Y)ned(X,Y)ed(X,Y)

While 𝔸ned satisfies all of our stated requirements, its insensitivity to finite outliers and bounded local edits implies that it is a pseudo-metric rather than a metric. In scenarios where one wishes to additionally distinguish, for example, ab from a (i.e., to forgo outlier insensitivity), or ab from a (i.e., to forgo bounded-edit insensitivity), this can be achieved by combining 𝔸ned with an additional language metric 𝒟 (e.g. ed, prf, etc.). Specifically, one may consider the refined generalized metric 𝔻×(X,Y)=(𝔸ned(X,Y),𝒟(X,Y)), ordered lexicographically so that the 𝔸ned component is dominant.555Here we use the term generalized metric to refer to a distance function whose codomain is a totally ordered set (rather than 0), and which satisfies the triangle inequality with respect to that order; see, e.g., [16, 12]. If 𝒟 takes values in a domain that is bounded above by a constant C (as is the case, for example, for ned), then this generalized metric can be collapsed into a genuine metric by defining 𝔻(X,Y)=(C+1)𝔸ned(X,Y)+𝒟(X,Y), which preserves the dominance of the asymptotic distance.

4.3 Asymptotic Essence of Regular Languages

A pseudo-metric 𝒟 naturally induces an equivalence relation 𝒟, where X𝒟Y if and only if 𝒟(X,Y)=0. In our context, two languages are considered equivalent with respect to language-metric 𝒟 if their 𝒟-distance is zero.

Recalling the discussion in the introduction, which was illustrated using regular expressions, it appears that removing all parts of a regular expression that are not under a Kleene star yields a language that is equivalent to the original one under the desired pseudo-metric 𝒟. Intuitively, the asymptotic essence of a regular expression is captured by the subexpressions occurring under Kleene closure, whereas all other subexpressions are asymptotically negligible. Accordingly, we denote by Ereg(r) the regular expression obtained by retaining only these Kleene-starred subexpressions.

Note that applying this procedure to different regular expressions defining the same language may result in different languages. For example, consider r1=a(aa)(aa) and r2=a. Although r1=r2, we have Ereg(r1)Ereg(r2), since Ereg(r1)=(aa)(aa) whereas Ereg(r2)=a.

Since regular languages do not admit a canonical regular expression, we seek to define asymptotic essence at the level of automata, so that it can later be applied to the minimal DFA, which is canonical up to isomorphism. Given a DFA or an NFA A recognizing a language L, we seek an intuitively simpler language L that is equivalent to L under 𝒟. To this end, we decompose A into its strongly connected components (SCCs) and replace all transitions that are not contained in some SCC by ε-transitions. The resulting automaton is a simpler NFA A that recognizes a language L which, intuitively, preserves exactly the asymptotically significant behavior of A.666Here, we use the strict notion of SCC: a singleton state forms an SCC only if it has a self-loop.

We denote by Efa(A) the NFA obtained by this construction. The asymptotic essence of a regular language L, denoted E(L), is then defined as Efa(AL), where AL is the minimal DFA recognizing L.

The following claim shows that these constructions – whether applied to regular expressions or to automata – yield languages that are equivalent under 𝒟 when 𝒟 is instantiated as one of the Asymptotic Hausdorff distances using a normalized word metric.

Claim 4.11 (Asymptotic Essence Equivalences).

Let L be a regular language, and r and A a regular expression and a NFA recognizing L, resp. Then, for every 𝒟{𝔸ned,𝔸ged,𝔸ced}

L𝒟E(L)𝒟Ereg(r)𝒟Efa(A)
Sketch proof.

The proof follows from 4.5 since Ereg and Efa (and thus E) yield languages that differ from the original language by finitely many words and require finitely many edits.

We note that this claim does not hold in general for 𝔸d. For example, it fails for 𝔸ed, since Ereg(abb)=a while 𝔸ed(abb,a)=2 implying abb𝔸eda.

5 On the Computation of 𝔸ned

We now turn to the computation of 𝔸ned, our primary notion of interest (cf. Corollary 4.8 and Claim 4.9). We begin, in Subsection 5.1, by considering regular languages, where we establish a Pspace-hardness result and present an approximation algorithm in coNExp. We then move to Subsection 5.2, where we develop a detailed algorithm for bounded context-free languages.

5.1 𝔸ned for Regular Languages

For regular languages, we establish both a hardness result and an approximation bound for computing 𝔸ned.

Hardness.

We begin by showing that, as in the case of 𝒜𝒞, which serves as our starting point, the problem is already Pspace-hard when languages are regular and X=Σ.

Theorem 5.1 (Pspace-hardness).

Let Σ be an alphabet, T an NFA over Σ and ν a rational number. The problem of deciding whether 𝔸ned(Σ,T)ν is Pspace-hard.

Sketch proof.

The proof proceeds by a reduction from the universality problem for NFAs, adapting ideas from the Pspace-hardness construction for 𝒜𝒞 [4] to account for normalization by edit-path length rather than word length. Given an NFA A over Σ, we construct an NFA T over the extended alphabet Γ=Σ{#} that recognizes the language (#A). We then show that if A is universal, i.e. A=Σ, then 𝔸ned(Γ,T)=0, whereas if A is not universal, then 𝔸ned(Γ,T)>0.

To establish the latter case, we consider the sequence (xk)k1 defined by xk=(#x)k for some xΣA. We first analyze the cost of an optimal edit path for xk and then study the limit behavior arising in the computation of 𝔸ned.

The complete proof makes use of the following claim which we also use for the approximation result.

Claim 5.2.

Let x be a word and let Y be a language recognized by an NFA with n states. Then there exists a word yxY attaining the value infyYned(x,y). Moreover, there exists an optimal edit path from x to yx of length at most n(|x|+1).

Approximation.

Next, we establish bounds relating 𝔸ned and 𝒜𝒞. In particular, 𝔸ned(X,Y) is sandwiched between 𝒜𝒞(X,Y) and 1d𝒜𝒞(X,Y), where d is the number of states in the minimal DFA for Y.

Claim 5.3.

Let X and Y be regular languages. Then 𝔸ned(X,Y)𝒜𝒞(X,Y).

Claim 5.4.

Let X and Y be regular languages. Then 𝔸ned(X,Y)1d𝒜𝒞(X,Y) where d is the number of states in the minimal DFA of Y.

Using these bounds and the coNExp-time algorithm for 𝒜𝒞 developed in [4], which relies on substantial technical machinery, we obtain a coNExp-time approximation algorithm for 𝔸ned.

Lemma 5.5.

Let X and Y be regular languages. Then there is a coNExp algorithm finding c such that 𝔸ned(X,Y)[1d,1]c where d is the number of states in the minimal DFA of Y.

5.2 𝔸ned for Bounded Context-Free Languages

We now turn to bounded context-free languages (BCFLs), a well-studied subclass of context-free languages with rich structural properties and strong decidability results. We assume familiarity with standard definitions and basic properties of context-free languages, and provide the necessary definitions for bounded CFLs.

Bounded CFL (Preliminaries).

A language L is said to be bounded if there exist fixed words w1,w2,,wnΣ such that Lw1w2wn. A language is a bounded context-free language if it is both bounded and context-free.

Let Σ={σ1,,σk}. The Parikh vector of a word wΣ is the k-tuple Parikh(w)=(|w|σ1,,|w|σk), where |w|σ is the number of occurrences of σ in w. For bounded languages, it is often convenient to work with a Parikh representation relative to the bounding words. Specifically, given w1,,wn and a word w=w1n1w2n2wnnn, we define the Parikh vector of w with respect to these words to be (n1,n2,,nn).

Parikh’s Theorem states that for every context-free language L, the set of Parikh vectors Parikh(L)={Parikh(w)wL} is a semi-linear set [21]. A set Sn is linear if there exist vectors U={𝐮0,𝐮1,,𝐮m}n such that S={𝐮0+t1𝐮1++tm𝐮mt1,,tm}. The vector 𝐮0 is called the constant vector, and the remaining vectors 𝐮1,,𝐮m are called period vectors. The matrix in n×(m+1) whose columns are the vectors 𝐮0,𝐮1,,𝐮m is called the generator matrix of S. A set is semi-linear if it is a finite union of linear sets.

Example 5.6.

As an example, consider the language L={(aba)n(bcc)3ndkemc2m+1n,k,m0}. This language is bounded, since Lw1w2w3w4w5 for w1=aba, w2=bcc, w3=d, w4=e, and w5=c. For the word w=(aba)(bcc)3d2ec3, the corresponding Parikh vector is (1,3,2,1,3). The Parikh image of L is generated by the constant vector 𝐮0=(0,0,0,0,1) together with the period vectors 𝐮1=(1,3,0,0,0), 𝐮2=(0,0,1,0,0), 𝐮3=(0,0,0,1,2), that correspond to the powers n, k, and m, respectively.

Ginsburg and Spanier [13] characterized bounded context-free languages by showing that a bounded language is context-free if and only if its Parikh image (with respect to the bounding words) is a stratified semi-linear set. A linear set is stratified if (i) each of its period vectors has at most two non-zero coordinates, and (ii) the non-zero coordinates of distinct period vectors do not interleave. Formally, if 𝐮 has non-zero coordinates at indices i1<i2 and 𝐯 has non-zero coordinates at j1<j2, then it is not the case that i1<j1<i2<j2. In the example above, the period vectors satisfy these conditions: each has at most two non-zero entries, and the index sets {1,2}, {3}, and {4,5} are pairwise non-interleaving.

Towards solving 𝔸ned for BCFLs

For simplicity, we focus on BCFLs whose Parikh image is a stratified linear (rather than semi-linear) set. Henceforth, let Xx1xn and Yy1ym be BCFLs with generators Un×(k+1) and Vm×(r+1), respectively. Let X0 be the BCFL with the same generating vector set U as X but where u0=0. Thus with i=1nu0[i]|wi| edit operations we can move between X and X0 and hence by 4.6 𝔸ned(X0,X)=0. From this point onward we thus assume u0=v0=0 and hence Un×k and Vm×r.

Example 5.7.

We use X={(a)n(bba)2nn} and Y={(abbb)k(ab)2m(c)mk,m} as a running example. The generators of X and Y are U2×1 and V3×2 where 𝐮1=(1,2) 𝐯1=(1,0,0) and 𝐯2=(0,2,1).

We compute 𝔸ned for BCFLs using linear programs. This requires several auxiliary notions, which we introduce next.

The edit graph.

Let x=a1a2an and y=b1b2bm. The edit graph Gx,y is the directed graph whose vertices are the grid points {0,,n}×{0,,m}, with edges from (i,j) to (i+1,j), (i,j+1), and (i+1,j+1) whenever the target vertex exists. An edge to (i+1,j) corresponds to deleting ai, and has weight 1; an edge to (i,j+1) corresponds to inserting bj, and has weight 1; and an edge to (i+1,j+1) corresponds either to a no-op (with weight 0) if ai=bj, or to a substitution of ai by bj (with weight 1) otherwise.

Example 5.8.

The edit graph of x=abbabba and y=abbbababc is given in Figure 1 (left). Edges that weigh 0 are dashed whereas edges that weigh 1 are solid. A minimum cost-path is marked on the graph in black. It corresponds to the edit path [aa][bb][bb][εb][aa][bb][bε][aa][εb][εc]. It has 10 edges, out of which 4 weigh 1 so its cost is 410. Accordingly ned(x,y)=410.

Blocks.

Note that words in X (resp. Y) are parameterized by vectors in n (resp. m). Let 𝐧=(n1,,nn)n and 𝐦=(m1,,mm)m. These vectors induce the words w𝐧x=x1n1xnnn and w𝐦y=y1m1ymmm, resp. We denote their lengths by 𝐧x=|w𝐧x| and 𝐦y=|w𝐦y|. Consider now x=w𝐧x and y=w𝐦y. The edit graph of x and y can be partitioned into n×m rectangular subgrids, which we henceforth call blocks. The (i,j)-block corresponds to the edit graph of xini and yjmj.

Example 5.9.

Let X={(a)n(bba)2nn} and Y={(abbb)k(ab)2m(c)mk,m}. Let 𝐧=(1,2) and 𝐦=(1,2,1) Figure 1 (middle) shows the edit graph of w𝐧x=abbabba and w𝐦y=aabbababc partitioned into its six blocks by the bold gray lines.

Interleavings.

Let p be an edit path from x to y. We consider the n×m grid, and say that a cell (i,j) is lit if the edit path p passes through the (i,j)-block. We write π(p) for the set of cells lit by p, and refer to π(p) as the interleaving imposed by p. Observe that π(p) forms a monotone path from (1,1) to (n,m) in the n×m grid. We use Π to denote the set of all interleavings from (1,1) to (n,m).

Example 5.10.

Continuing Ex.5.9, the 2×3 grid below shows that the marked edit path passes through blocks (1,1), (2,1), (2,2), and (2,3); the cells corresponding to these blocks are diagonally hatched.

 Remark 5.11.

Note that |Π|=(n+m2n1), since any such interleaving consists of a total of n1 rightward steps and m1 downward steps, and is therefore determined by the choice of which n1 of the n+m2 steps are rightward.

Figure 1: Left: Gx,y, Middle: the blocks of Gx,y, Right: the sub-blocks of the (2,2)-block.
Sub-blocks and the cyclic-edit graph.

In our linear program, we want to reason simultaneously about many words xX and yY. To this end, we observe that each (i,j)-block is composed of ni×mj identical copies of the edit graph of xi and yj, which we call sub-blocks. Figure 1 (right) illustrates the partition of the (2,2)-block into four identical sub-blocks corresponding to the edit graph of x2 to y2.

To reason uniformly about powers of xi and yj, we introduce the cyclic edit graph of xi and yj, denoted Gi,j. Let xi=a1a|xi| and yj=b1b|yj|. The vertices of Gi,j form a quotient of the set V={(l,k)0l|xi|, 0k|yj|} where (0,k) is identified with (|xi|,k), and (l,0) is identified with (l,|yj|).

These identifications reflect the adjacency of sub-blocks: for instance, the vertex (0,k) of a given sub-block (e.g., the orange block in Figure 1 (right)) coincides with (|xi|,k) of the sub-block to its left (the cyan one), and analogously for the vertical direction.

As a result, there is a bijection between edit paths from xisuffxixipref to yjsuffyjyjpref and walks in Gi,j, where xisuff and yjsuff are suffixes and xipref and yjpref are prefixes of xi and yj, respectively. This bijection preserves both weight and length. Moreover, every walk starting at (0,0) corresponds to an edit path from some word in xixipref to some word in yjyjpref, and similarly for walks ending at (0,0) and words in xisuffxi and yjsuffyj.

Example 5.12.

Consider the edit path in the (2,2)-block of Figure 1 (right). It induces the edit path [aa][bb][bε][aa][εb] which corresponds to the walk (0,2)(1,3)(1,0)(2,1)(2,2)(0,2)(1,3)(2,3) in G2,2. This walk represents the alignment of the words abba and abab, that is, ax2 and y2y2, respectively, where a is indeed a suffix of x2.

Directions.

Another means to simultaneously reason on many xX and yY is the notion of direction. Consider again 𝐧=(n1,,nn)n, w𝐧x=x1n1xnnn, and 𝐧x=|w𝐧x|. Note that 𝐧x=i=1nni|xi|. The direction induced by 𝐧 is the vector dir(𝐧)=(d1,,dn), where di=ni/𝐧x.

Example 5.13.

For instance, for X={(a)n(bba)2nn}, 𝐧=(1,2), we get that w𝐧x=abbabba, 𝐧x=7 and dir(𝐧)=(17,27).

For every 𝐧n, the induced direction dir(𝐧) lies in the set Δx=def{𝐝0n:i=1n𝐝[i]|xi|=1}. Note that each direction 𝐚Δx is induced by infinitely many vectors in n: if 𝐧 induces 𝐚, then so does c𝐧 for any c.

Not every vector 𝐧n induces a word w𝐧x that belongs to X. We therefore restrict attention to directions that are realizable by words in X, at least asymptotically. Let Sxn denote the Parikh image of X with respect to x1,,xn. We define the direction set of X as Dx=def{dir(𝐧)𝐧Sx}¯Δx, where the closure is taken in the standard topology on n. Since Sx is a linear set, Dx is a polytope.

The Linear Program

Fix a direction 𝐚Dx and an interleaving πΠ. Our goal is to describe an optimal edit path from a word in X inducing the direction 𝐚 to a word in Y, under the restriction that the path respects the interleaving π. We use a linear program to solve the infimum for any 𝐛Dy and λ(0,1], where 𝐛 is the “closest” direction to a in Sy and if p is a corresponding edit path then λ represents the fraction |x||p|. To this aim we define a linear program over the following set of variables:

  • fei,j0  for each (i,j)π and eE(Gi,j)

  • τt0  for each 1t

  • λ(0,1]

Intuitively the variable fei,j holds the fraction corresponding to the number of times edge e is used in Gi,j along π divided by the length of the edit path p. Thus, the sum overall these variables should be 1, and this is Constraint 1 below. Working with edit paths whose length is normalized to 1 simplifies the reasoning for ned: under this condition the cost of the path is the same as its weight.

Not every assignment to the variables fei,j corresponds to a valid edit path. In a path, for every vertex (except for the source and target) every visited vertex has a corresponding entry and exit edges. This gives rise to Constraint 2 below.777The discrepancy for the source and target is taken care of in the proof details.

We further require that the resulting edit path corresponds to a word in X with direction 𝐚, and transforms it into an optimal word in Y. We use the indicators 𝟙xi(e) and 𝟙yj(e) where 𝟙xi(e) equals 1 if the edge e consumes a letter of xi – that is, if it corresponds to a substitution, deletion, or no-op – and equals 0 otherwise (and analogously for 𝟙yj(e)). Constraint 3 ensures that the total use of edit operations reading symbols from the source block xi matches the contribution prescribed by the direction 𝐚Dx. Recall that parameter λ corresponds to the ratio |x||p|. It is introduced to account for the fact that the expression  (i,j)Π,eE(Gi,j)fei,j 1xi(e)  naturally yields ni|xi| normalized by |p|, whereas the direction vector 𝐚Dx is defined in terms of normalization by |x|. Multiplication by λ therefore corrects the denominator, aligning the normalization with that of the source direction.

For the target word, we do not fix a direction in advance. Instead, we allow the linear program to choose an optimal target direction. This is achieved using the variables τ1,,τr, which induce a normalized direction vector 𝐛 for Y via   bj=s=1rτsvs[j]for each 1jm. Intuitively, the variables τ1,,τr normalize by |p| a natural combination of the generators 𝐯1,,𝐯r of Y. Accordingly, bj represents the |p|-normalized contribution of the target block yj. Constraint 4 ensures that the edit path consumes symbols from the target blocks in accordance with this induced direction.

Constraints.

The constraints of the linear program LP𝐚,π are as follows:

  1. 1.

    Normalization constraint:

    (i,j)πeE(Gi,j)fei,j=1.
  2. 2.

    Flow conservation in each block: for every (i,j)π and every vertex vV(Gi,j)

    eOut(v)fei,j=eIn(v)fei,j.
  3. 3.

    Source-consumption constraints: for all i{1,,n}

    (i,j)πeE(Gi,j)fei,j𝟙xi(e)=|xi|aiλ.
  4. 4.

    Target-consumption constraints: for all j{1,,m}

    (i,j)πeE(Gi,j)fei,j 1yj(e)=|yj|bj
Objective.

min(i,j)πeE(Gi,j)fei,jc(e).
where c(e) is the weight of e. The objective thus looks for an edit path with minimum cost.

For a fixed direction 𝐚Dx, each interleaving πΠ induces a linear program LP𝐚,π. We denote by OPT𝐚,π the optimal value of LP𝐚,π. We aggregate these by taking the best value over all interleavings, and define F(𝐚)=defminπΠOPT𝐚,π. Continuity of F is used in the proof of the following theorem.

Claim 5.14.

The function F:Dx is continuous.

We can finally state the main theorem for this section.

Theorem 5.15.

Let X and Y be bounded CFLs, and let Π and Dx be the corresponding interleaving and directions set. Then 𝔸ned(X,Y)=sup𝐚DxminπΠOPT𝐚,π=sup𝐚DxF(𝐚).

Putting the above ingredients together, we obtain the following complexity bound for computing 𝔸ned on bounded context-free languages.

Lemma 5.16.

There exists an Exp algorithm that computes 𝔸ned(X,Y) for bounded context-free languages X and Y.

Proof sketch.

By the LP characterization, 𝔸ned(X,Y)=sup𝐚DXF(𝐚), where F(𝐚)=minπΠOPT𝐚,π and OPT𝐚,π is the optimum of a linear program whose constraints are independent of 𝐚 and whose right-hand side depends affinely on it. By LP duality, for each π, OPT𝐚,π is a convex, piecewise-linear function of 𝐚. Hence, F is also piecewise linear.

Since DX is a compact polytope, the supremum of F is attained at a vertex of the arrangement induced by these linear pieces. The number of defining hyperplanes is exponential, as it depends on the number of interleavings and dual vertices. Standard bounds on hyperplane arrangements imply that the number of candidate vertices is exponential.

The algorithm enumerates these candidates, evaluates F at each by solving the corresponding linear programs, and returns the maximum. This yields an exponential algorithm.

6 Discussion

The Asymptotic Hausdorff lifting captures a notion of similarity that is inherently asymptotic, comparing infinite sets by their long-run behavior while deliberately abstracting away from finite deviations. This choice is intentional: in formal verification, two languages are considered similar when similarity is witnessed on increasingly long words. In particular, in applications such as repair, robustness, and automata learning, asymptotic behavior with respect to a normalized edit distance between words reflects the semantic core of the compared languages.

Our results highlight an inherent trade-off between robustness and sensitivity. Classical Hausdorff-style constructions are highly sensitive to outliers, whereas asymptotic notions necessarily collapse certain local distinctions. The Asymptotic Hausdorff lifting makes this trade-off explicit and allows additional sensitivity to be reintroduced in a controlled manner by combining it with complementary distances.

Although formal languages serve as a central motivating domain, the lifting scheme itself is more general and applies to any infinite domain equipped with a meaningful notion of size and an element-level metric.

From an algorithmic perspective, our results indicate that computing 𝔸ned is already challenging for regular and bounded context-free languages, and extending the proposed techniques to richer classes or more efficient exact algorithms is an interesting direction for future work.

References

  • [1] Michael Benedikt, Gabriele Puppis, and Cristian Riveros. The cost of traveling between languages. In Luca Aceto, Monika Henzinger, and Jirí Sgall, editors, Automata, Languages and Programming - 38th International Colloquium, ICALP 2011, Zurich, Switzerland, July 4-8, 2011, Proceedings, Part II, volume 6756 of Lecture Notes in Computer Science, pages 234–245. Springer, 2011. doi:10.1007/978-3-642-22012-8_18.
  • [2] Michael Benedikt, Gabriele Puppis, and Cristian Riveros. Regular repair of specifications. In Proceedings of the 26th Annual IEEE Symposium on Logic in Computer Science, LICS 2011, June 21-24, 2011, Toronto, Ontario, Canada, pages 335–344. IEEE Computer Society, 2011. doi:10.1109/LICS.2011.43.
  • [3] Michael Benedikt, Gabriele Puppis, and Cristian Riveros. Bounded repairability of word languages. J. Comput. Syst. Sci., 79(8):1302–1321, 2013. doi:10.1016/J.JCSS.2013.06.001.
  • [4] Michael Benedikt, Gabriele Puppis, and Cristian Riveros. The per-character cost of repairing word languages. Theoretical Computer Science, 539:38–67, 2014. doi:10.1016/j.tcs.2014.04.021.
  • [5] Florian Bruse, Maurice Herwig, and Martin Lange. A similarity measure for formal languages based on convergent geometric series. In Implementation and Application of Automata: 26th International Conference, CIAA 2022, Rouen, France, June 28 – July 1, 2022, Proceedings, Berlin, Heidelberg, 2022. Springer-Verlag. doi:10.1007/978-3-031-07469-1_6.
  • [6] Noam Chomsky and George A. Miller. Finite state languages. Inf. Control., 1(2):91–112, 1958. doi:10.1016/S0019-9958(58)90082-2.
  • [7] Cewei Cui, Zhe Dang, Thomas R. Fischer, and Oscar H. Ibarra. Similarity in languages and programs. Theoretical Computer Science, 498:58–75, 2013. doi:10.1016/j.tcs.2013.05.040.
  • [8] Colin de la Higuera and Luisa Micó. A contextual normalised edit distance. In Proceedings of the 24th International Conference on Data Engineering Workshops, ICDE 2008, April 7-12, 2008, Cancún, Mexico, pages 354–361. IEEE Computer Society, 2008. doi:10.1109/ICDEW.2008.4498345.
  • [9] Emmanuel Filiot, Nicolas Mazzocchi, Jean-François Raskin, Sriram Sankaranarayanan, and Ashutosh Trivedi. Weighted transducers for robustness verification. In Igor Konnov and Laura Kovács, editors, 31st International Conference on Concurrency Theory, CONCUR 2020, Vienna, Austria (Virtual Conference), September 1-4, 2020, volume 171 of LIPIcs, pages 17:1–17:21. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2020. doi:10.4230/LIPIcs.CONCUR.2020.17.
  • [10] Dana Fisman, Joshua Grogin, Oded Margalit, and Gera Weiss. The normalized edit distance with uniform operation costs is a metric. In 33rd Annual Symposium on Combinatorial Pattern Matching, CPM 2022, June 27-29, 2022, Prague, Czech Republic. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.CPM.2022.17.
  • [11] Dana Fisman and Ilay Tzarfati. When is the normalized edit distance over non-uniform weights a metric? In Shunsuke Inenaga and Simon J. Puglisi, editors, 35th Annual Symposium on Combinatorial Pattern Matching, CPM 2024, Fukuoka, Japan, June 25-27, 2024, volume 296 of LIPIcs, pages 14:1–14:17. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2024. doi:10.4230/LIPIcs.CPM.2024.14.
  • [12] Robert C. Flagg. Quantales and continuity spaces. Algebra Universalis, 37(3):257–276, 1997.
  • [13] Seymour Ginsburg and Edwin H. Spanier. Semigroups, Presburger formulas, and languages. Pacific Journal of Mathematics, 16(2):285–296, 1966.
  • [14] Thomas A. Henzinger, Jan Otop, and Roopsha Samanta. Lipschitz robustness of finite-state transducers. In Venkatesh Raman and S. P. Suresh, editors, 34th International Conference on Foundation of Software Technology and Theoretical Computer Science, FSTTCS 2014, New Delhi, India, December 15-17, 2014, volume 29 of LIPIcs, pages 431–443. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2014. doi:10.4230/LIPIcs.FSTTCS.2014.431.
  • [15] Manfred Kudlek and Benedek Nagy. Distances of formal languages. PU.M.A. Pure Mathematics and Applications, 17, January 2006.
  • [16] F. William Lawvere. Metric spaces, generalized logic, and closed categories. Rendiconti del Seminario Matematico e Fisico di Milano, 43(1):135–166, 1973.
  • [17] Vladimir Iosifovich Levenshtein. Binary codes capable of correcting deletions, insertions and reversals. Soviet Physics Doklady, 10(8):707–710, February 1966. Doklady Akademii Nauk SSSR, V163 No4 845-848 1965.
  • [18] A. Marzal and E. Vidal. Computation of normalized edit distance and applications. IEEE Transactions on Pattern Analysis and Machine Intelligence, 15(9):926–932, 1993. doi:10.1109/34.232078.
  • [19] Mehryar Mohri. Edit-distance of weighted automata. In Proceedings of the 7th International Conference on Implementation and Application of Automata, CIAA’02, pages 1–23, Berlin, Heidelberg, 2002. Springer-Verlag. doi:10.1007/3-540-44977-9_1.
  • [20] Timothy Ng, David Rappaport, and Kai Salomaa. Relative prefix distance between languages. In International Conference on Developments in Language Theory, pages 284–295. Springer, 2017. doi:10.1007/978-3-319-62809-7_21.
  • [21] Rohit J. Parikh. On context-free languages. Journal of the Association for Computing Machinery, 13(4):570–581, 1966. doi:10.1145/321356.321364.
  • [22] Austin J. Parker, Kelly B. Yancey, and Matthew P. Yancey. Regular language distance and entropy, 2016. arXiv:1602.07715.
  • [23] Roopsha Samanta, Jyotirmoy V. Deshmukh, and Swarat Chaudhuri. Robustness analysis of string transducers. In Dang Van Hung and Mizuhito Ogawa, editors, Automated Technology for Verification and Analysis, pages 427–441, Cham, 2013. Springer International Publishing. doi:10.1007/978-3-319-02444-8_30.
  • [24] C. E. Shannon. A mathematical theory of communication. SIGMOBILE Mob. Comput. Commun. Rev., 5(1):3–55, January 2001. doi:10.1145/584091.584093.
  • [25] Robert A. Wagner. Order-n correction for regular languages. Commun. ACM, 17(5):265–268, 1974. doi:10.1145/360980.360995.
  • [26] Li Yujian and Liu Bo. A normalized levenshtein distance metric. IEEE Transactions on Pattern Analysis and Machine Intelligence, 29(6):1091–1095, 2007. doi:10.1109/TPAMI.2007.1078.