{'fraction_non_alphanumeric': 0.060593849950890274, 'fraction_numerical': 0.01861132797743471, 'mean_word_length': 3.9314456035767513, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 1, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 18, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
The Euclidean distance degree of smooth complex projective varieties

We obtain several formulas for the Euclidean distance degree (ED degree) of an arbitrary nonsingular variety in projective space: in terms of Chern and Segre classes, Milnor classes, Chern-Schwartz-MacPherson classes, and an extremely simple formula equating the Euclidean distance degree of X with the Euler characteristic of an open subset of X.


Introduction
The Euclidean distance degree (ED degree) of a variety X is the number of critical points of the distance function from a general point outside of X. This definition, tailored to real algebraic varieties, may be adapted for complex projective varieties, and this is the context in which we will work in this paper. The ED degree is studied thoroughly in [DHO + 16], which provides a wealth of examples, results, and applications. In particular, [DHO + 16, Theorem 5.4] states that the ED degree of a complex projective variety X ⊆ P n−1 equals the sum of its 'polar degrees', provided that the variety satisfies a technical condition related to its intersection with the isotropic quadric, i.e., the quadric Q with equation x 2 1 +· · ·+x 2 n = 0. As a consequence, a formula is obtained ([DHO + 16, Theorem 5.8]) computing the Euclidean distance degree of a nonsingular variety X, assuming that X intersects Q transversally, i.e., under the assumption that Q ∩ X is a nonsingular hypersurface of X. This number is a certain combination of the degrees of the components of the Chern class of X (see (3.1)); we call this number the 'generic Euclidean distance degree' of X, gEDdeg(X), since it equals the Euclidean distance degree of a general translate of X.
There are several directions in which this formula could be generalized. For example, the hypothesis of nonsingularity on X could be relaxed; it is then understood that the role of the Chern class of X is taken by the so-called Chern-Mather class of X, one of several generalizations of the notion of Chern class to possibly singular X. The resulting formula (see e.g., [Alu,Proposition 2.9]) gives the generic ED degree of an arbitrarily singular variety X. In a different direction, one could maintain the nonsingularity hypothesis, but attempt to dispose of any requirement regarding the relative position of Q and X, and aim at computing the 'actual' ED degree of X.
The main result of this note is of this second type. It consists of formulas for the Euclidean distance degree of an arbitrary nonsingular subvariety of projective space; different versions are presented, in terms of different types of information that may be available on X. The simplest form of the result is the following: Theorem. Let X be a smooth subvariety of P n−1 , and assume X ⊆ Q. Then where H is a general hyperplane.
Here χ is the ordinary topological Euler characteristic. This statement will be proven in §8; in each of § §5-7 we obtain an equivalent formulation of the same result. These serve 1 as stepping stones in the proof of (1.1), and seem of independent interest. Theorems 5.1 and 6.1 will express EDdeg(X) as a 'correction' γ(X) of the generic Euclidean distance degree due to the singularities of Q ∩ X. For example, it will be a consequence of Theorem 6.1 that when Q ∩ X has isolated singularities, then this correction equals the sum of the Milnor numbers of the singularities. (If X is a smooth hypersurface of degree = 2, the singularities of Q ∩ X are necessarily isolated, cf. §9.3.) Theorem 5.1 expresses γ(X) in terms of the Segre class of the singularity subscheme of Q ∩ X; this version of the result is especially amenable to effective implementation, using available algorithms for the computation of Segre classes ( [Har17]). Theorem 7.1 relates the Euclidean distance degree to Chern-Schwartz-MacPherson classes, an important notion in the theory of characteristic classes for singular or noncompact varieties. In fact, EDdeg(X) admits a particularly simple expression, given in (7.3), in terms of the Chern-Schwartz-MacPherson class of the nonsingular, but noncompact, variety X Q. Theorem 8.1, reproduced above, follows from this expression.
The progression of results in § §5-8 is preceded by a general formula, Theorem 4.3, giving the correction term γ(X) for essentially arbitrary varieties X. Coupled with [Alu, Proposition 2.9], this yields a general formula for EDdeg(X). This master formula is our main tool for the applications to nonsingular varieties obtained in the sections that follow; in principle it could be used in more general situations, but at this stage we do not know how to extract a simple statement such as formula 1.1 from Theorem 4.3 without posing some nonsingularity hypothesis on X.
Refining the techniques used in this paper may yield more general results, but this is likely to be challenging. Ultimately, the reason why we can obtain simple statements such as (1.1) is that Segre classes of singularity subschemes of hypersurfaces of a nonsingular variety X are well understood. In general, singularities of X will themselves contribute to the singularity subscheme of Q ∩ X, even if the intersection of Q and X is (in some suitable sense) 'transversal'. In fact, for several of our formulas to hold it is only necessary that X be nonsingular along Q ∩ X (cf. Remarks 5.2 and 6.2).
The raw form of our result is a standard application of Fulton-MacPherson intersection theory, modulo one technical difficulty, which we will attempt to explain here. Techniques developed in [DHO + 16] express the ED degree as the degree of a projection map from a certain correspondence in P n−1 × P n−1 . Applying Fulton-MacPherson's intersection theory, one obtains a formula for the ED degree involving the Segre class of an associated subscheme Z ∆ u in the conormal space of X (Theorem 4.3); this formula holds for arbitrary X ⊆ Q. In the nonsingular case, the formula may be recast in terms of the Segre class in X of a scheme supported on the singular locus of Q ∩ X. A somewhat surprising complication arises here, since this scheme does not coincide with the singularity subscheme of Q ∩ X. However, we can prove (Lemma 5.4) that the ideal sheaves of the two subschemes have the same integral closure, and deduce from this that their Segre classes coincide. This is key to our explicit formulas.
This technical difficulty is likely one of the main obstacles in extending the results of this paper to the case of more general subvarieties of projective space, by analogous techniques. We may venture the guess that a different approach, aiming at 'understanding' (1.1) more directly, without reference to the theory of characteristic classes of singular varieties, may be more amenable to generalization. Finding such an approach would appear to be a natural project.
Preliminaries on the Euclidean distance degree are given in §2. In §3 we point out that (1.1), in its equivalent formulation (8.2), agrees with gEDdeg(X) when X is nonsingular and meets the isotropic quadric transversally. We find that this observation clarifies why a formula such as (1.1) may be expected to hold without transversality hypotheses. It is perhaps natural to conjecture that an analogue replacing ordinary Euler characteristics in (1.1) with the degree χ Ma of the Chern-Mather class may hold for arbitrary varieties. Under the transversality hypothesis, an analogue of (8.2) does hold for possibly singular varieties, as we show in Proposition 3.1. The main body of the paper consists of § §4-8 Examples of applications of the results obtained here are given in §9.
As recalled in the introduction, the Euclidean distance degree of a variety in R n is the number of critical nonsingular points of the (squared) distance function from a general point outside of the variety. We consider the complex projective version of this notion: for a subvariety X ⊆ P n−1 := P(C n ), we let EDdeg(X) be the Euclidean distance degree of the affine cone over X in C n , that is, the number of critical points of the function which occur at nonsingular points of the cone over X, where (u 1 , . . . , u n ) is a general point.
Remark 2.1. If X is a subset of the isotropic quadric Q (with equation x 2 1 + · · · + x 2 n = 0), then the quadratic term in (2.1) vanishes, and (2.1) has no critical points. Therefore, EDdeg(X) = 0 in this case, and we can adopt the blanket convention that X ⊆ Q. With suitable positions, our results will hold without this assumption (cf. e.g., Remark 5.8).
The definition of EDdeg(X) may be interpreted in terms of a projective ED correspondence, and this will be needed for our results. Our reference here is [DHO + 16, §5] (but we use slightly different notation). Consider the projective space P n−1 and its dualP n−1 , parametrizing hyperplanes in P n−1 . It is well-known that the projective cotangent space T * P n := P(T * P n−1 ) of P n−1 may be realized as the incidence correspondence I ⊆ P n−1 × P n−1 consisting of pairs (p, H) with p ∈ H. Every subvariety X P n−1 has a (projective) conormal space T * X P n−1 , defined as the closure of the projective conormal variety to X; this may be realized as T * X P n−1 := {(p, H) | p ∈ X ns and T p X ⊆ H} ⊆ I = T * P n−1 . Consider the subvariety Z ⊆ P n−1 ×P n−1 × C n obtained as the image of .) The projection PE → C n is in fact dominant, and we have the following result.
Lemma 2.2. The Euclidean distance degree EDdeg(X) equals the degree of the projection PE → C n .
Proof. This is implied by the argument in the proof of [DHO + 16, Proposition 5.4].
Lemma 2.2 suggests that one should be able to express EDdeg(X) in terms of an intersection with the fiber Z u of Z over a general point u ∈ C n . We may view Z u as a subvariety of P n−1 ×P n−1 : where u is now fixed (and general). It is easy to verify that Z u is an n-dimensional irreducible variety, and that in the Chow group A * (P n−1 ×P n−1 ). Here, h, resp.,ȟ denote the pull-back of the hyperplane class from P n−1 , resp. ,P n−1 . (For example, one may verify (2.2) by intersecting Z u with suitably chosen P i ×P j within P n−1 ×P n−1 .) This implies the following statement, cf.
Lemma 2.3. For all u ∈ C n−1 and all subvarieties X ⊆ P n−1 , where the numbers δ i (X) are the polar degrees of X.
Indeed, the polar degrees are (by definition) the coefficients of the monomials h n−1−iȟi+1 in the class [T * X P n−1 ]. In view of Lemma 2.3, we define the 'generic Euclidean distance degree' of X. By Lemma 2.2, EDdeg(X) is the contribution of the projective ED correspondence to the intersection number gEDdeg(X) = Z u · T * X P n−1 calculated in Lemma 2.3. It is a consequence of [DHO + 16, Proposition 5.4] that if X is in sufficiently general position, then this contribution in fact equals the whole intersection number, i.e., EDdeg(X) = gEDdeg(X). Our goal is to determine a precise 'correction term' evaluating the discrepancy between EDdeg(X) and gEDdeg(X) without any a priori hypothesis on X. In §4 we will formalize this goal and deduce a general formula for EDdeg(X) for an arbitrary variety X. In § §4-8 we will use this result to obtain more explicit formulas for EDdeg(X) under the assumption that X is nonsingular.

The generic Euclidean distance degree, revisited
This section is not used in the sections that follow, but should help motivating formula (1.1), which will be proven in §8. We also propose a possible conjectural generalization of this formula to arbitrary projective varieties.
We have defined the 'generic' Euclidean distance degree of a subvariety X ⊆ P n−1 as the sum of its polar degrees. In [DHO + 16, Theorem 5.8] it is shown that if X is nonsingular, then this number may be interpreted as the Euclidean distance degree of a general translation of X, which will meet Q transversally by Bertini's theorem. Here c(X) j is the degree of the component of dimension j of the Chern class c(T X) ∩ [X] of X. Formula (3.1) holds for arbitrarily singular varieties X, if one replaces c(X) with the Chern-Mather class c Ma (X) of X ([Alu, Proposition 2.9]). Assume first that X is nonsingular. As a preliminary observation, the reader is invited to perform the following calculus exercise: With this understood, we have the following computation: Assuming further that X is transversal to Q and that H is a general hyperplane, the last expression may be rewritten as (by transversality, all of the loci appearing in this expression are nonsingular). The degree of the zero-dimensional component of the Chern class of a compact complex nonsingular variety is its topological Euler characteristic, so this computation shows that if X is nonsingular and meets Q transversally (and where H is a general hyperplane). Theorem 8.1 will amount to the assertion that (3.2) holds as soon as X is nonsingular, without any hypothesis on the intersection of Q and X. By the good inclusion-exclusion properties of the Euler characteristic, (3.2) is equivalent to (1.1).
While the computation deriving (3.2) from [DHO + 16, Theorem 5.8] is trivial under the transversality hypothesis, we do not know of any simple way to obtain this formula in the general case. The next several sections ( §4-8) will lead to a proof of (3.2) for arbitrary nonsingular varieties.
The above computation can be extended to singular projective subvarieties. Just as the topological Euler characteristic of a nonsingular variety is the degree of its top Chern class, we can define an 'Euler-Mather characteristic' of a possibly singular variety V by setting the degree of the Chern-Mather class of V . This number is a linear combination of Euler characteristics of strata of V , with coefficients determined by the local Euler obstruction Eu, a well-studied numerical invariant of singularities.
Proposition 3.1. For any subvariety X ⊆ P n−1 intersecting Q transversally, where H is a general hyperplane.
Proof. Argue precisely as in the discussion leading to (3.2), using [Alu, Proposition 2.9] in place of [DHO + 16, Theorem 5.8]. The only additional ingredient needed for the computation is the fact that if W is a nonsingular hypersurface intersecting a variety V transversally, then For a much stronger result, and a discussion of the precise meaning of 'transversality', we address the reader to [Sch], particularly Theorem 1.2.
Of course (3.3) specializes to (3.2) when X is nonsingular, under the transversality hypothesis; but it does not do so in general, because Q ∩ X may be singular even if X is nonsingular, and χ Ma (Q ∩ X) does not necessarily agree with χ(Q ∩ X) in that case. Therefore, the transversality hypothesis in Proposition 3.1 is necessary. The Euler-Mather characteristic of the complement, (where c * denotes MacPherson's natural transformation) may be the most natural candidate as an expression for EDdeg(X) for arbitrary subvarieties X ⊆ P n−1 , without smoothness or transversality hypotheses.

Intersection formula
In §2 we have defined the projective ED correspondence to be one component of the intersection (T * X P n−1 × C n ) ∩ Z. We next determine the union of the other irreducible components. We denote by ∆ the diagonal in P n−1 ×P n−1 . In this section X ⊆ P n−1 is a subvariety (not necessarily smooth), and X ⊆ Q (cf. Remark 2.1).
where the support of Z ∆ equals the support of (∆ ∩ T * X P n−1 ) × C n . Proof. Consider the projection (T * X P n−1 ×C n )∩Z → P n−1 ×P n−1 . We have already observed in §2 that the fiber over ) consists of the whole space C n−1 ; the statement follows immediately from this assertion.
The fact that Z contains ∆ × C n (used in the proof) may also be verified by observing that equations for Z in P n−1 ×P n−1 × C n are given by the 3 × 3 minors of the matrix (4.1)   x 1 x 2 · · · x n y 1 y 2 · · · y n u 1 u 2 · · · u n   associated with a point ([x], [y], u) ∈ P n−1 ×P n−1 × C n ; the diagonal ∆ × C n obviously satisfies these equations. Now we fix a general u ∈ C n . By Lemma 2.2, the fiber PE u consists of EDdeg(X) simple points, which will be disjoint from the diagonal for general u. On the other hand, for all u, the fiber Z u (when viewed as a subvariety of P n−1 ×P n−1 ) contains ∆. We deduce the following consequence of Lemma 4.1.
, where the support of Z ∆ u agrees with the support of ∆ ∩ T * X P n−1 . Taking into account Lemma 2.3 we obtain that where γ(X) is the contribution of Z ∆ u to the intersection product Z u · T * X P n−1 . This 'correction term' γ(X) does not depend on the chosen (general) u, and vanishes if ∆∩T * X P n−1 = ∅, since in this case Z ∆ u = ∅ by Corollary 4.2. This special case recovers the statement of [DHO + 16, Proposition 5.4], and indeed (4.2) is essentially implicit in loc. cit.. We are interested in computable expressions for the correction term γ(X).
We will first obtain the following master formula, through a direct application of Fulton-MacPherson intersection theory. The diagonal ∆ is isomorphic to P n−1 , and we denote by H its hyperplane class, as well as its restrictions. (Thus, H agrees with the restriction of both h andȟ.) Theorem 4.3. With notation as above, Here, denotes degree, and s(−, −) is the Segre class, in the sense of [Ful84, Chapter 4]. Segre classes are effectively computable by available implementations of algorithms (see e.g., [Har17]). However, the need to obtain explicit equations for the scheme Z ∆ u , and conditions guaranteeing that a given u is general enough, limit the direct applicability of Theorem 4.3. Our task in the next several sections of this paper will be to obtain from 4.3 concrete computational tools, at the price of requiring X to be of a more specific type-we will assume in the following sections that X ⊆ Q is nonsingular, but otherwise arbitrary.
The proof of Theorem 4.3 requires some additional information on Z u , which we gather next. As noted in §2, Z u is an irreducible n-dimensional subvariety of P n−1 ×P n−1 . Equations for Z u in P n−1 ×P n−1 are given by the 3 × 3 minors of the matrix (4.1), where now Proof. This statement is clearly invariant under a change of coordinates, so we may assume u = (1, 0, . . . , 0). If either [x] or [y] is not [u], we may without loss of generality assume that x n = 0, and hence x n = 1. The ideal of Z u at this point ([x], [y]) is generated by the 3 × 3 minors of   x 1 x 2 · · · x n−1 1 y 1 y 2 · · · y n−1 y n 1 0 · · · 0 0   and among these we find the n − 2 minors Near ([x], [y]), these generate the ideal of an irreducible smooth complete intersection of dimension n = dim Z u , which must then coincide with Z u in a neighborhood of ([x], [y]), giving the statement.
u is a local complete intersection in (P n−1 ×P n−1 ) • , and we let N be its normal bundle.
Lemma 4.5. With notation as above, Proof. Consider the rational map where H ′ is the hyperplane class. The statement follows by observing that the pull-back of H ′ to ∆ • agrees with the pull-back of H. This is the case, since the restriction π| ∆ • : With these preliminaries out of the way, we can prove Theorem 4.3.
Proof of Theorem 4.3. Since [u] is general, it may be assumed not to be a point of X. This ensures that ([u], [u]) ∈ T * X P n−1 ; in particular Z • u ∩ T * X P n−1 = Z u ∩ T * X P n−1 . It follows that, as a class in A * (Z u ∩T * X P n−1 ), the (Fulton-MacPherson) intersection product of T * X P n−1 by Z u on P n−1 ×P n−1 equals the intersection product of T * X P n−1 by Z • u on (P n−1 ×P n−1 ) • . Therefore, we can view γ(X) as the contribution of Z ∆ u to Z • u · T * X P n−1 . Consider the fiber diagram .1] (especially Proposition 6.1(a), Example 6.1.1), this contribution equals where N = N Z • u (P n−1 ×P n−1 ) • as above. Since Z ∆ u is supported on a subscheme of ∆ • , c(g| * Z ∆ u N ) equals (the restriction of) (1 + H) n−1 by Lemma 4.5, and the stated formula follows.
Summarizing, we have proven that for all subvarieties X ⊆ Q of P n−1 . (If X ⊆ Q, then EDdeg(X) = 0, cf. Remark 2.1.) The quantity gEDdeg(X) is invariant under projective translations, and may be computed in terms of the Chern-Mather class of X. The other term records subtle information concerning the intersection of X and Q, by means of the Segre class s(Z ∆ u , T * X P n−1 ). We will focus on obtaining alternative expressions for this class.

Euclidean distance degree and Segre classes
Now we assume that X ⊆ P n−1 is a smooth closed subvariety. As recalled in §3, in this case gEDdeg(X) is given by a certain combination of the Chern classes of X: An application of Theorem 4.3, obtained in this section, will yield an explicit formula for the correction term γ(X) (and hence for EDdeg(X)). This result has two advantages over Theorem 4.3: first, the formula will not depend on the choice of a general u; second, its ingredients will allow us to draw a connection with established results in the theory of characteristic classes for singular varieties, leading to the results presented in § §6-8.
The main result of this section is the following. Recall that we are denoting by Q the isotropic quadric, i.e. the hypersurface of P n−1 with equation n i=1 x 2 i = 0. By our blanket assumption that X should not be contained in Q, we have that Q∩X is a (possibly singular) hypersurface of X. We let J(Q ∩ X) denote its singularity subscheme, defined locally by the partial derivatives of its equation in X (or equivalently by the appropriate Fitting ideal of the sheaf of differentials of Q ∩ X). Also, recall that h denotes the hyperplane class in P n−1 .
Theorem 5.1. Let X be a smooth subvariety of P n−1 , and assume X ⊆ Q. Then The key ingredient in (5.1) is the Segre class s(J(Q ∩ X), X). This may be effectively computed by using the algorithm for Segre classes described in [Har17].
Remark 5.2. It will be clear from the argument that it is only necessary to require X to be nonsingular in a neighborhood of Q ∩ X. (Of course X must only have isolated singularities in this case.) Formula (5.1) holds as stated in this more general case; gEDdeg(X) may be computed using the same formula as in the smooth case (that is, (3.1)), but using the degrees of the component of the Chern-Mather class of X ([Alu, Proposition 2.9]). The hypothesis X ⊆ Q is also not essential, cf. Remark 5.8.
The proof of Theorem 5.1 will rely on a more careful study of the schemes ∆ ∩ T * X P n−1 and Z ∆ u encountered in §4. In Corollary 4.2 we have shown that these two schemes have the same support; here we will prove the much stronger statement that they have the same Segre class in T * X P n−1 . Since ∆ ∩ T * X P n−1 is closely related with J(Q ∩ X) (Lemma 5.3), this will allow us to recast Theorem 4.3 in terms of the Segre class appearing in (5.1), by means of a result of W. Fulton.
Recall that ∆ ⊆ Z u (in fact, ∆ is a divisor in Z u ); it follows that These two schemes have the same support (Corollary 4.2); but they are in general different. It is straightforward to identify ∆ ∩ T * X P n−1 with a subscheme of X. Lemma 5.3. Let δ : P n−1 → P n−1 × P n−1 be the diagonal embedding, and let X be a smooth subvariety of P n−1 . Then J(Q ∩ X) = δ −1 (T * X P n−1 ), i.e., δ maps J(Q ∩ X) isomorphically to ∆ ∩ T * X P n−1 . Proof. Since T * X P n−1 ⊆ P(T * P n−1 ), we have The diagonal δ restricts to an isomorphism q : Q ∼ → T * Q P n−1 . By (5.2), we have that δ −1 (T * X P n−1 ) agrees with q −1 (T * X P n−1 ), viewed as a subscheme of P n−1 .
X, and these conditions define J(Q ∩ X) scheme-theoretically. The statement follows.
Setting λ j = ϕ j we obtain from (5.6) generators (5.7) s k + j ϕ j ϕ jk , k = 2, . . . , d for the ideal of Z ∆ u in σ(X); the same generators, together with give the ideal of ∆ ∩ T * X P n−1 in σ(X). It suffices then to verify that (5.8) is integral over the ideal generated by (5.7).
Remark 5.6. The smoothness of X is needed in our argument, since it gives us direct access to the conormal space T * X P n−1 . However, it is reasonable to expect that (5.3) holds without this assumption, and it would be interesting to establish this equality for more general varieties.
Remark 5.7. The very definition of the Euclidean distance degree relies on the squaredistance function, i (x i − u i ) 2 , which is not a projective invariant. Therefore, EDdeg(X) does depend on the choice of coordinates in the ambient projective space P n−1 . Formula (4.2), EDdeg(X) = gEDdeg(X) − γ(X) , expresses the Euclidean distance degree of a variety in terms of a quantity that is projectively invariant, i.e., gEDdeg(X), and a correction term γ(X) which is not. In fact, the coordinate choice determines the isotropic quadric Q: i x 2 i = 0 is a specific nonsingular quadric in P n−1 . Theorem 5.1 prompts us to define a transparent 'projective invariant version' of the Euclidean distance degree, for smooth X: EDdeg(Q, X) could be defined by the right-hand side of (5.1), where now Q is any nonsingular quadric in P n−1 not containing X.
(If X is not necessarily smooth, (4.3) could likewise be used to define such a notion.) This number is clearly independent of the choice of coordinates. What Theorem 5.1 shows is that EDdeg(Q, X) equals the Euclidean distance degree of the variety X once homogeneous coordinates x 1 , . . . , x n are chosen so that the equation of Q is n i=1 x 2 i . Remark 5.8. As pointed out in Remark 2.1, EDdeg(X) = 0 if X ⊆ Q. Theorem 5.1 is compatible with this fact, in the following sense. if Q ∩ X = X, it is natural to set J(Q ∩ X) = X, and hence s(J(Q ∩ X), X) = s(X, X) = [X]. The reader can verify (using (3.1)) that Therefore (5.1) reduces to EDdeg(X) = 0 in this case, as expected.

Euclidean distance degree and Milnor classes
While the formula in Theorem 5.1 is essentially straightforward to implement, given the algorithm for the computation of Segre classes in [Har17], it is fair to say that its 'geometric meaning' is not too transparent. In this section and the following two we use results from the theory of characteristic classes of singular varieties to provide versions of the formula in terms of notions with a more (and more) direct geometric interpretation.
Our first aim is the following result. The Milnor class of a variety V is the signed difference between its Chern-Fulton class c F (V ) (which we have already encountered in §5) and its CSM ('Chern-Schwartz-MacPherson') class. We will denote by M(V ) j the component of M(V ) of dimension j. The Milnor class owes its name to the fact that if V is a hypersurface with at worst isolated singularities in a compact nonsingular variety, then the degree of its Milnor class is the sum of the Milnor numbers of its singularities ([PP01, Example 0.1]).
The CSM class of a variety V is a 'homology' class which agrees with the total Chern class of the tangent bundle of V when V is nonsingular, and satisfies a functorial requirement formalized by Deligne and Grothendieck. See [Mac74] for MacPherson's definition (inspired by this functorial requirement), and [Sch65a,Sch65b] for an earlier equivalent definition by Marie-Hélène Schwartz (motivated by the problem of extending theorems of Poincaré-Hopf type). An efficient summary of MacPherson's definition (upgraded to the Chow group) may be found in [Ful84, Example 19.1.7]. With notation as in this reference (or as in [Mac74]), our c SM (V ) is c * (1 1 V ).
As an easy consequence of functoriality, the degree of c SM (V ) equals χ(V ), the topological Euler characteristic of V . In fact the degrees of all the terms in c SM (V ) may be interpreted in terms of Euler characteristics ([Alu13, Theorem 1.1]), and this will be key for the version of the result we will present in §8.
If V is a hypersurface, then c F (V ) equals the class of the virtual tangent bundle of V ; it may be interpreted as the limit of the Chern class of a smoothing of V in the same linear equivalence class. The terms in c F (V ) may therefore also be interpreted in terms of Euler characteristics (of smoothings of V ). Roughly, the Milnor class measures the changes in the Euler characteristics of general hyperplane sections of V as we smooth it within its linear equivalence class.
Theorem 6.1. Let X be a smooth subvariety of P n−1 , and assume X ⊆ Q. Then Milnor classes are also accessible computationally, cf. [Alu03, Example 4.7].
Remark 6.2. It suffices to require X to be nonsingular in a neighborhood of Q ∩ X, cf. Remark 5.2.
a i c(L ) i (note that the codimension is computed in the ambient variety M , even if the class may be defined in the Chow group of the subscheme V ).
This notation satisfies several properties, for example a basic compatibility with respect to Chern classes of tensors of vector bundles. One convenient property is given in [Alu17, Lemma 3.1]: with notation as above, the term of codimension c in M in is independent of L . In particular, is independent of L , and this implies (using [Alu94, Proposition 2]) Apply this fact to γ(X) (from (5.13)), viewed as where the equality ! = follows by applying [Alu94, Proposition 1]. Since the degree of a class in X is the degree of its component of dimension 0, i.e., codimension dim X, this gives Finally, by (6.2) (with M = X, and this implies (6.1).
Corollary 6.3. If Q ∩ X only has isolated singularities x i , then where µ(−) denotes the Milnor number.
We will see that this is in fact the case for most smooth hypersurfaces ( §9.3).

Euclidean distance degree and Chern-Schwartz-MacPherson classes
Our next aim is to express the Euclidean distance degree of a nonsingular projective variety directly, rather than in terms of a correction from a 'generic' situation. CSM classes provide a convenient means to do so. The formula presented in §8 may look more appealing, but the alternative (7.1) presented here, besides being a necessary intermediate result, is in a sense algorithmically more direct.
Theorem 7.1. Let X be a smooth subvariety of P n−1 . Then Here, c SM (Q ∩ X) j denotes the degree of the j-dimensional component of Q ∩ X. Again, (7.1) is straightforward to implement given available algorithms for characteristic classes (for example [Alu03,Jos15,Har17]).
Remark 7.2. If X ⊆ Q, then c SM (Q ∩ X) = c SM (X) = c(X) by the basic normalization property of CSM classes, as X is nonsingular. In this case (7.1) gives EDdeg(X) = 0, as it should (cf. Remark 2.1). Therefore, we will assume X ⊆ Q in the proof.
Remark 7.3. In the proof we will use the fact that c(X) = c F (X) if X is nonsingular. This prevents a straightforward generalization of the argument to the case in which X is only required to be nonsingular in a neighborhood of Q ∩ X.
Proof. According to Theorem 6.1, By (3.1), therefore, EDdeg(X) equals By definition, (after push-forward to X) since Q ∩ X is a hypersurface in X and O(Q) = O(2h) as Q is a quadric. Therefore The coefficient of c(X) j in this expression equals the coefficient of h j in the expansion of
CSM classes may be associated with locally closed sets: if V is a locally closed set of a variety M , then c SM (V ) = c * (1 1 V ) is a well-defined class in A * M . (If V = V W , with W closed, then c SM (V ) = c SM (V ) − c SM (W ).) This notation allows us to express (7.1) in (even) more concise terms: if X is a smooth subvariety of P n−1 , and X ⊆ Q, then Indeed, c(X) = c SM (X) since X is nonsingular. If Q ∩ X is (supported on) a simple normal crossing divisor, (7.3) admits a particularly simple expression, given in the corollary that follows. An illustration of this case will be presented in §9.6.
Corollary 7.4. Let X ⊆ P n−1 be a smooth subvariety, and assume the support of Q ∩ X is a divisor D with normal crossings and nonsingular components D i , i = 1, . . . , r. Then Proof. If D is a simple normal crossing divisor in X, then (see [Alu99b], or [GP02] (Proposition 15.3)). Using this fact in (7.3), the stated formulas follow from simple manipulations and the well-known expression for c(T * X(log D)) when D is a simple normal crossing divisor.
Liao has shown that (7.4) holds as soon as D is a free divisor that is locally quasi homogeneous ( [Liab]) or more generally with Jacobian of linear type ( [Liaa]). Therefore, EDdeg(X) = c(T * X(log D)) 1−H ∩[X] as in Corollary 7.4 as soon as the support of Q∩X satisfies these less restrictive conditions.

Euclidean distance degree and Euler characteristics
Finally, we present a version of the main result which makes no use (in its formulation) of characteristic classes for singular varieties. This is the version given in the introduction.
Theorem 8.1. Let X be a smooth subvariety of P n−1 . Then where H is a general hyperplane.
By the inclusion-exclusion property of the topological Euler characteristic, (8.1) is equivalent to which has the advantage of only involving closed subsets of P n−1 . Any of the aforementioned implementations of algorithms for characteristic classes of singular varieties includes explicit functions to compute Euler characteristics of projective schemes from defining homogenous ideals, so (8.2) is also essentially trivial to implement. However, despite its conceptual simplicity, this expression is computationally expensive.
Remark 8.2. As in §7, we have to insist that X be smooth; only requiring it to be nonsingular in a neighborhood of Q ∩ X is not enough for the result to hold.
Proof. The statement is a consequence of Theorem 7.1 and of a result from [Alu13]. Collect the degrees of the components of the CSM class of a locally closed set V ⊆ P N into a polynomial: and collect the signed Euler characteristics of generic linear sections of V into another polynomial: where the H i 's are general hyperplanes. Then according to [Alu13, Theorem 1.1] we have where I is an explicit involution. It follows from the specific expression of I that 0) (see the paragraph preceding the statement of Theorem 1.1 in [Alu13]). Therefore for every locally closed set V in projective space.
The statement of the theorem, in the form given in (8.2), follows by applying (8.3) to (7.1). 9. Examples 9.1. Computations. The ingredients needed to implement the main theorems of this text on computer algebra systems such as Sage [Dev] or Macaulay2 [GS] are all available. One can compute Segre classes and Chern-Mather classes via [Har17] and Chern-Schwartz-MacPherson classes via (for example) any of [Alu03,MB12,Jos,Jos15,Hel16,Har17]. One issue in concrete examples is that computer algebra systems prefer to work with Qcoefficients, and it is often difficult to write the defining equations of a variety which is tangent to the isotropic quadric without extending the field of coefficients. This difficulty can sometimes be circumvented by a suitable choice of coordinates; see Remark 5.7. Also see §9.5 below for a discussion of a template situation.
In many cases, the 'standard' algorithm of [DHO + 16, Example 2.11] appears to be at least as fast as the alternatives obtained by implementing the results presented here. In some examples these alternatives are faster, particularly if they take advantage of the refinements which will be presented below. As an illustration, we can apply Proposition 9.2 ( §9.4) to compute the ED degrees of plane curves in terms of a generator of their homogeneous ideal. A (non-optimal) implementation of this method in Macaulay2 can be coded as follows: For example, trial runs of computations of the ED degrees of Fermat curves x d +y d +z d = 0 for all degrees d = 3, . . . , 40 took an average of 4.5 seconds using this method (in a more efficient implementation), and 260 seconds by using the standard algorithm. However, direct implementations of the general formulas presented in this paper do not fare as well.
The interested reader can find the actual code used here, as well as implementations of the more general formulas at http://github.com/coreysharris/EDD-M2 . At this stage, the value of the formulas obtained in Theorems 5.1-8.1 appears to rest more on their theoretical applications (in examples such as the ones discussed below in §9.6) than in the speed of their computer algebra implementations.
If the variety is known to be transversal to the isotropic quadric, then its Euclidean distance degree equals the generic Euclidean distance degree. This may be computed by using the algorithm for Chern(-Mather) classes in [Har17], often faster than the standard algorithm. For example, let S be a general hyperplane section of the second Veronese embedding of P 3 in P 9 . Then S is transversal to the isotropic quadric, and the implementation of the algorithm in [Har17] computes its Euclidean distance degree (i.e., 36) in about 2 seconds. The standard algorithm appears to take impractically long on this example; one can improve its performance by first projecting S to a general P 3 (this does not affect the Euclidean distance degree, by [DHO + 16, Corollary 6.1]), and the computation then takes about a minute. 9.2. Quadrics and Spheres. Let X ⊆ P n−1 be a nonsingular quadric hypersurface. We say that X is a sphere if it is given by the equation with c > 0 a real number. It is clear from the definition in terms of critical points of the distance function that EDdeg(X) = 2 if X is a sphere in P n−1 , n ≥ 2. We use this example to illustrate some of the formulas obtained in this paper. First, since X is a degree 2 hypersurface in P n−1 , c(T X) = c(T P n−1 | X ) 1 + 2h = (1 + h) n 1 + 2h (where h denotes the hyperplane class and its pull-backs, as in previous setions). Applying (3.1), one easily sees that For a sphere X ⊆ P n−1 , the intersection Q ∩ X consists of a double quadric in P n−2 , supported on the transversal intersection X ∩ H of X with a hyperplane. It follows that J(Q ∩ X) = X ∩ H, and therefore According to Theorem 5.1, the correction term in this case is given by = 2(n − 2) .
From the point of view of Theorem 8.1, we should deal with the topological Euler characteristics of X, X ∩ Q, X ∩ H, X ∩ Q ∩ H, where H is a general hyperplane (see (8.2)). If X is a sphere, then X ∩ Q is (supported on) a nonsingular quadric in P n−2 ; so is X ∩ H, and X ∩ Q ∩ H is a nonsingular quadric in P n−3 . The Euler characteristic of a nonsingular quadric in P N is N + 1 if N is odd, N if N is even; therefore χ(X)−χ(X ∩Q)−χ(X ∩H)+χ(X ∩Q∩H) = (n − 1) − 2(n − 1) + (n − 3) = −2 n odd n − 2(n − 2) + (n − 2) = 2 n even and by Theorem 8.1 EDdeg(X) = (−1) dim X χ(X (Q ∪ H)) = 2 for all n, as expected.
9.3. Hypersurfaces. The case of smooth hypersurfaces of degree ≥ 3 is more constrained than it may look at first. (This is [Alu00, Claim 3.2].) It follows that if X ⊂ P n−1 is a smooth hypersurface of degree d = 2, then the intersection Q ∩ X necessarily has isolated singularities. We are then within the scope of Corollary 6.3, and we can conclude where the sum is over all singularities x i of Q ∩ X, and µ(−) denotes the Milnor number. 9.4. Curves. Let C ⊆ P n−1 be a nonsingular curve. Then has EDdeg equal to 3: indeed, it meets the isotropic quadric at the images of the solutions of s 6 + 3s 4 t 2 + 3s 2 t 4 + t 6 = (s 2 + t 2 ) 3 = 0, that is, at two points. More generally, the Euclidean distance degree of the rational normal curve of degree n − 1 in P n−1 parametrized by For plane curves, (9.1) admits a particularly explicit formulation.
Proposition 9.2. Let C be a nonsingular plane curve, defined by an irreducible homogeneous polynomial F (x, y, z). Then where R is the number of distinct factors of the polynomial F (s 2 − t 2 , 2st, i(s 2 + t 2 )) ∈ C[t] and d = deg F .
If S is a plane in P 3 , tangent to the isotropic quadric Q, then C = Q ∩ S is a pair of lines, and (9.2) gives EDdeg(S) = 0. But note that the coefficients of the equation of this plane are necessarily not all real, so the enumerative interpretation of EDdeg(S) as the number of critical points of a 'distance' function should be taken cum grano salis.