1 Introduction

Let \(f:({\mathbb {R}}^n,0)\rightarrow ({\mathbb {R}},0)\) be an analytic function germ with an isolated critical point at 0. The Khimshiashvili formula (see Khimshiashvili 1977) states that

$$\begin{aligned} \chi (f^{-1}(\delta )\cap B_{\epsilon }) = 1-{\text {sign}}(-\delta )^n\deg _0\nabla f, \end{aligned}$$

where \(0<|\delta |\ll \epsilon \ll 1\), \(B_\epsilon \) is the closed ball of radius \(\epsilon \) centered at 0, \(\nabla f\) is the gradient of f and \(\deg _0\nabla f\) is the topological degree of the mapping \(\frac{\nabla f}{|\nabla f|}: S_{\epsilon }\rightarrow S^{n-1}.\)

As a corollary of the Khimshiashvili formula, by a result of Arnol’d (1978) and Wall (1983) we have that

$$\begin{aligned} \chi (\{f\le 0\}\cap S_{\epsilon }) = 1 - \deg _0\nabla f, \\ \chi (\{f\ge 0\}\cap S_{\epsilon }) = 1 + (-1)^{n-1}\deg _0\nabla f, \end{aligned}$$

and

$$\begin{aligned} \chi (\{f=0\}\cap S_{\epsilon }) = 2 - 2\deg _0\nabla f, \end{aligned}$$

if n is even.

Szafraniec (1986) generalized the results of Arnol’d and Wall to the case of a function germ f with non-isolated singularities and in Szafraniec (1991) he improved this result for a weighted homogeneous polynomial \(f:{\mathbb {R}}^n\rightarrow {\mathbb {R}}\).

In Dutertre (2020) Lemma 2.5, the first named author proves a new relation between the topology of the positive (resp. negative) real Milnor fibre of an analytic function germ \(f:({\mathbb {R}}^n,0)\rightarrow ({\mathbb {R}},0)\) and the topology of the link of the set \(\{f \le 0\}\) (resp. \(\{f \ge 0 \})\). Using Szafraniec’s results, he deduces a generalization of the Khimshiashvili formula for non-isolated singularities. Namely he proves that if \(0<\delta \ll \epsilon \), then

$$\begin{aligned} \chi (f^{-1}(-\delta )\cap B_{\epsilon })=1-(-1)^n\deg _0\nabla g_{-}, \end{aligned}$$

and

$$\begin{aligned} \chi (f^{-1}(\delta )\cap B_{\epsilon })=1-(-1)^n\deg _0\nabla g_{+}, \end{aligned}$$

with \(g_{-}=-f-\omega ^d\), \(g_{+}=f-\omega ^d\), \(\omega (x)=x_1^2+\cdots +x_n^2\) and d is an integer big enough.

Sekalski (2005) gives a global counterpart of Khimshiasvili’s formula for a polynomial function \(f:{\mathbb {R}}^2\rightarrow {\mathbb {R}}\) with a finite number of critical points. He considers the set \(\Lambda _f = \{\lambda _1,\ldots ,\lambda _k\}\) of critical values of f at infinity, where \(\lambda _1<\lambda _2<\cdots <\lambda _k\), and its complement \({\mathbb {R}}\setminus \Lambda _f=\cup _{i=0}^{k}]\lambda _i,\lambda _{i+1}[\) where \(\lambda _0=-\infty \) and \(\lambda _{k+1}=+\infty .\) Denoting by \(r_{\infty }(g)\) the number of real branches at infinity of a curve \(\{g=0\}\) in \({\mathbb {R}}^2\), he proves that

$$\begin{aligned} \deg _{\infty }\nabla f = 1 + \sum _{i=1}^k r_{\infty }(f-\lambda _i) - \sum _{i=0}^k r_{\infty }(f-\lambda _i^+), \end{aligned}$$

where for \(i=0,\ldots ,k,\) \(\lambda _i^+\) is an element of \(]\lambda _i,\lambda _{i+1}[\) and \(\deg _{\infty }\nabla f\) is the topological degree of the mapping \(\frac{\nabla f}{\Vert \nabla f\Vert }: S_R\rightarrow S^{n-1}\), \(R\gg 1\).

Gwoździewicz (2009) gives a topological proof of Sekalski’s result using Euler integration. He proves that

$$\begin{aligned} \deg _{\infty }\nabla f = 1 + \int _{{\mathbb {R}}}r_{\infty }(f-t)d\chi _c(t), \end{aligned}$$

where \(\chi _c\) denotes the Euler characteristic with compact support that we will define later.

The first named author generalizes Sekalski result in Dutertre (2012) by considering a closed semi-algebraic set \(X\subset {\mathbb {R}}^n\) and a \({\mathcal {C}}^2\) semi-algebraic function \(f:{\mathbb {R}}^n\rightarrow {\mathbb {R}}\) such that \(f_{|X}\) has a finite number of critical points. In Dutertre and Moya Perez (2016) the authors recover the first named author’s results using Euler integration, which clearly simplifies the proofs.

Finally, in Dutertre et al. (2016), Sect. 3, Araujo, Chen, Andrade and the first named author gave a generalization of the results of Dutertre (2012) when \(X={\mathbb {R}}^n\) and f is a semi-tame function with non-isolated critical points, by adapting to the global case the method developed by Szafraniec (1986).

The aim of this paper is to extend these results to the general case, i.e., without any assumption on the set of critical points of the function. We work in the following setting: \(X\subset {\mathbb {R}}^n\) is a closed semi-algebraic set, \(F:{\mathbb {R}}^n\rightarrow {\mathbb {R}}\) is a \({\mathcal {C}}^2\) semi-algebraic function and \(f=F_{|X}:X\rightarrow {\mathbb {R}}^n\) is the restriction of F to X.

In Sect. 3, we define the global index of a critical value \(c_i\) of f,

$$\begin{aligned} {\text {ind}}_g(f,X,f^{-1}(c_i))=\chi (f^{-1}(c_i)) - \chi (f^{-1}(c_i-\alpha )\cap B_{R_{c_i}}), \end{aligned}$$

where \(R_{c_i}\gg 1\) and \(0<\alpha \ll \frac{1}{R_{c_i}}\). Then, we generalize Theorem 3.16 of Dutertre (2012) and Theorem 5.1 of Dutertre and Moya Perez (2016) for the case of a non-compact critical set, that is, we prove that (Theorem 3.2)

$$\begin{aligned} \chi (X) = \sum _{i=1}^l{\text {ind}}_g(f, X, f^{-1}(c_i)) - \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t). \end{aligned}$$

Using the same techniques we generalize the other results of Dutertre (2012) and Dutertre and Moya Perez (2016) for \(\chi (X)\) for the case of a non-compact critical set. As an application, we obtain an index formula for the quotient of two semi-algebraic functions.

In Sect. 4 we define two new indices, the right index at infinity of an asymptotic non-\(\rho \)-regular value \(d_i\) (see Definition 2.15),

$$\begin{aligned} {\text {ind}}_{\infty }^{+}(f,X,f^{-1}(d_i))=\chi (f^{-1}(d_i+\alpha ))-\chi (f^{-1}(d_i+\alpha )\cap B_{R_{d_i}}), \end{aligned}$$

and the left index at infinity of \(d_i\),

$$\begin{aligned} {\text {ind}}_{\infty }^{-}(f,X,f^{-1}(d_i))=\chi (f^{-1}(d_i-\alpha ))-\chi (f^{-1}(d_i-\alpha )\cap B_{R_{d_i}}), \end{aligned}$$

where \(R_{d_i}\gg 1\) and \(0<\alpha \ll \frac{1}{R_{d_i}}\). We compute these indices in particular cases and we finish the section with a formula that relates \(\chi (X)\) with them (Theorem 4.4). This formula can be viewed as a generalization of Corollary 2.3 applied to \(f: X \rightarrow {\mathbb {R}}\).

We end the paper in Sect. 5 with some real and global Lê-Iomdine type formulas. Namely, by adding or substracting to f a big power of an adapted function, we construct two functions \(g_+\) and \(g_-\) that have compact sets of critical points and then we prove that the sum of the global indices of f (respectively \(-f\)) and \(g_-\) (respectively \(g_+\)) coincide (Theorem 5.11). Such results were prevoiusly proved in Dutertre et al. (2016), when \(X={\mathbb {R}}^n\) and f is a semi-tame function.

Let us finish this introduction with a comment. It seems that all these results can be extended to the case of arbitrary real closed fields. Indeed the tools and results that we use (Euler characteristic with compact support, Hardt’s theorem, constructible functions, first Thom–Mather’s isotopy lemma...) have versions in this case. For instance, Coste and Shiota (1995) proved a version of the Thom–Mather isotopy lemma without integrating vector fields. But in order to do this, one needs to check many (hidden) details.

The authors are grateful to the referee for suggesting valuable improvements.

2 Some Preliminary Results

2.1 Euler Integration

Let \(X\subset {\mathbb {R}}^n\) be a semi-algebraic set. We can write it in the following way:

$$\begin{aligned} X = \sqcup _{j=1}^l C_j, \end{aligned}$$

where \(C_j\) is semi-algebraically homeomorphic to \(]-1,1[^{d_j}\) (\(C_j\) is called a cell of dimension \(d_j\)). We set

$$\begin{aligned} \chi _c(X) = \sum _{j=1}^l (-1)^{d_j}, \end{aligned}$$

and we call it the Euler characteristic with compact support of X. Let us remark that if X is compact, then \(\chi _c(X) = \chi (X)\).

A constructible function \(\varphi : X\rightarrow {\mathbb {Z}}\) is a \({\mathbb {Z}}\)-valued function that can be written as a finite sum

$$\begin{aligned} \varphi = \sum _{i\in I}m_i1_{X_i}, \end{aligned}$$

where \(X_i\) is a semi-algebraic subset of X.

If \(\varphi \) is a constructible function, the Euler integral of \(\varphi \) is defined as

$$\begin{aligned} \int _{X}\varphi d\chi _c(x) = \sum _{i\in I}m_i\chi _c(X_i). \end{aligned}$$

Definition 2.1

Let \(f:X\rightarrow Y\) be a continuous semi-algebraic map and let \(\varphi : X\rightarrow {\mathbb {Z}}\) be a constructible function. The push forward \(f_{*}\varphi \) of \(\varphi \) along f is the function \(f_{*}\varphi : Y\rightarrow {\mathbb {Z}}\) defined by

$$\begin{aligned} f_{*}\varphi (y) = \int _{f^{-1}(y)}\varphi d\chi _c(x). \end{aligned}$$

Theorem 2.2

(Fubini type theorem) Let \(f: X\rightarrow Y\) be a continuous semi-algebraic map and let \(\varphi \) be a constructible function on X. Then, we have

$$\begin{aligned} \int _{Y}f_{*}\varphi d\chi _c(y) = \int _{X}\varphi d\chi _c(x). \end{aligned}$$

Proof

See Statement 3.A in Viro (1988). \(\square \)

Corollary 2.3

Let X, Y be semi-algebraic sets and let \(f: X\rightarrow Y\) be a continuous semi-algebraic map. Then

$$\begin{aligned} \chi _c(X) = \int _Y\chi _c(f^{-1}(y))d\chi _c(y). \end{aligned}$$

2.2 Link at Infinity and Adapted Radius

For any closed semi-algebraic set equipped with a Whitney stratification \(X = \sqcup _{\alpha \in A} S_\alpha \), we denote by Lk\(^\infty (X)\) the link at infinity of X. It is defined as follows. Let \(\omega : {\mathbb {R}}^n \rightarrow {\mathbb {R}}\) be a \(C^2\) proper semi-algebraic positive function. Since \(\omega _{\vert X}\) is proper, the set of critical points of \(\omega _{\vert X}\) (in the stratified sense) is compact. Hence for R sufficiently big, the map \(\omega : X \cap \omega ^{-1}([R,+\infty [) \rightarrow {\mathbb {R}}\) is a stratified submersion. The link at infinity of X is the fibre of this submersion. The topological type of Lk\(^\infty (X)\) does not depend on the choice of the function \(\omega \) (for instance, see Dutertre (2012), Sect. 3).

Definition 2.4

We will say that \(R>0\) is an adapted radius for X if \(D: X \cap D^{-1}([R,+\infty [) \rightarrow {\mathbb {R}}\) is a stratified submersion, where D is the euclidean norm.

Remark 2.5

  1. (i)

    We note that if R is an adapted radius for X then \({\text {Lk}}^{\infty }(X)\) is homeomorphic to \(X\cap S_{R'}\), for \(R'\ge R\).

  2. (ii)

    We note that \(\chi _c(X)= \chi (X)-\chi (\textrm{Lk}^\infty (X))\).

2.3 Stratified Critical Points and Values

Let us consider from now on a closed semi-algebraic set \(X\subset {\mathbb {R}}^n\). It is equipped with a finite semi-algebraic Whitney stratification \(X=\sqcup _{a\in A}S_{a}\). Let \(F: {\mathbb {R}}^n\rightarrow {\mathbb {R}}\) be a \({\mathcal {C}}^2\)-semi-algebraic function and let \(f=F_{|X}\).

Definition 2.6

  1. (1)

    A point \(p\in X\) is a critical point of f if it is a critical point of \(F_{|S(p)}\), where S(p) is the stratum that contains p.

  2. (2)

    A point \(c\in {\mathbb {R}}\) is a critical value if there exists \(p\in f^{-1}(c)\) such that p is a critical point of f.

  3. (3)

    If p is an isolated critical point of f, we define the index of f at p by

    $$\begin{aligned} {\text {ind}}(f,X,p) = 1 - \chi (\{f=f(p)-\delta \}\cap B_{\epsilon }(p)), \end{aligned}$$

    where \(0<\delta \ll \epsilon \ll 1.\)

Let us notice that if \(X={\mathbb {R}}^n\), by Khimshiashvili (1977), \({\text {ind}}(f,X,p)=\deg _{p}\nabla f\).

Lemma 2.7

The set of critical points of f, \(\Sigma _f\), is a closed semi-algebraic subset of X and its set of critical values, \(\Delta _f\), is finite.

Proof

To prove that \(\Sigma _f\) is closed we use Whitney’s condition (a) and to prove that \(\Delta _f\) is finite we use the Bertini-Sard Theorem ( Bochnak et al. (1998)). \(\square \)

The following result gives a relation between the Euler characteristic of X and the indices of the \(p_i\)’s, when X is compact.

Theorem 2.8

(Dutertre (2012), Theorem 3.1) If X is compact and f has a finite number of critical points \(p_1, \ldots , p_l\), we have

$$\begin{aligned} \chi (X) = \sum _{i=1}^l{\text {ind}}(f,X,p_i). \end{aligned}$$

Now, we give some lemmas that we will use later on. For the proofs we refer to Dutertre (2012). We assume that f has a finite number of critical points \(p_1,p_2,\ldots ,p_l.\)

Lemma 2.9

If \(\delta <0\) is a small regular value of f and \(R\gg 1\) is such that \(f^{-1}(0) \cap B_R\) is a retract by deformation of \(f^{-1}(0)\), then

$$\begin{aligned} \chi (f^{-1}(\delta )\cap B_R) = \chi (f^{-1}(0)) - \sum _{p_i\in f^{-1}(0)}{\text {ind}}(f,X,p_i). \end{aligned}$$

Lemma 2.10

If f is proper then for any \(\alpha \in {\mathbb {R}}\), we have

$$\begin{aligned} \chi (\{f\ge \alpha \}) - \chi (\{f=\alpha \}) = \sum _{i:f(p_i)>\alpha }{\text {ind}}(f,X,p_i). \end{aligned}$$

We state a Mayer–Vietoris type result that we will apply several times in the paper.

Lemma 2.11

For any \(\alpha \in {\mathbb {R}}\), we have

$$\begin{aligned} \chi (X)= \chi (\{f\ge \alpha \}) + \chi (\{f\le \alpha \}) - \chi (\{f=\alpha \}). \end{aligned}$$

Proof

By the additivity of \(\chi _c\), we know that

$$\begin{aligned} \chi _c(X)= \chi _c(\{f\ge \alpha \}) + \chi _c(\{f\le \alpha \}) - \chi _c(\{f=\alpha \}), \end{aligned}$$

so the result is obvious if X is compact. If X is not compact, we can choose \(R>0\) such that X (resp. \(\{f\ge \alpha \}\), \(\{f\le \alpha \}\), \(\{f=\alpha \}\)) is a deformation retract of \(X \cap B_R\) (resp. \(\{f\ge \alpha \} \cap B_R\), \(\{f\le \alpha \}\cap B_R\), \(\{f=\alpha \}\cap B_R\)). It is enough to apply the compact case and the relation between \(\chi \) and \(\chi _c\). \(\square \)

The following lemma is a consequence of Lemma 2.10 and Lemma 2.11.

Lemma 2.12

If f is proper then for \(\alpha \) and \(\alpha '\) with \(\alpha < \alpha '\), we have

$$\begin{aligned} \chi (\{\alpha \le f\le \alpha '\}) - \chi (\{f=\alpha \}) = \sum _{i: \alpha <f(p_i) \le \alpha '}{\text {ind}}(f,X,p_i). \end{aligned}$$

Let \(g:{\mathbb {R}}^n\rightarrow {\mathbb {R}}\) be a \({\mathcal {C}}^2\)-semi-algebraic function such that \(g^{-1}(0)\) intersects X transversally. Let us suppose that \(f_{|X\cap \{g\le 0\}}\) admits an isolated critical point p in \(X\cap \{g=0\}\) which is not a critical point of f. We say that such a point is a correct critical point. If S denotes the stratum of X that contains p, this implies that

$$\begin{aligned} \nabla (f_{|S})(p) = \lambda (p)\nabla (g_{|S})(p), \end{aligned}$$

with \(\lambda (p)\ne 0\).

Lemma 2.13

For \(0<\delta \ll \epsilon \ll 1\), we have

$$\begin{aligned} \chi (f^{-1}(-\delta )\cap B_{\epsilon }(p)\cap X\cap \{g\le 0\}) = 1, \end{aligned}$$

if \(\lambda (p)>0\) and

$$\begin{aligned} \chi (f^{-1}(-\delta )\cap B_{\epsilon }(p)\cap X\cap \{g\le 0\}) = \chi (f^{-1}(-\delta )\cap B_{\epsilon }(p)\cap X\cap \{g=0\}), \end{aligned}$$

if \(\lambda (p)<0.\)

Remark 2.14

As a consequence of the last lemma and the definition of the index of a critical point p, we get that

$$\begin{aligned} {\text {ind}}(f, X\cap \{g\le 0\}, p) = 0, \end{aligned}$$

if \(\lambda (p)>0\), and

$$\begin{aligned} {\text {ind}}(f, X\cap \{g\le 0\}, p) = {\text {ind}}(f, X\cap \{g=0\},p), \end{aligned}$$

if \(\lambda (p)<0.\)

2.4 Asymptotic Non-\(\rho \)-Regular Values

Let \(\rho (x)= 1 + \frac{1}{2}(x_1^2+\cdots +x_n^2)\). Note that \(\nabla \rho (x)=x\), \(\rho (x) \ge 1\) and the levels of \(\rho \) are the spheres of radius greater than or equal to 1. Let \(\Gamma _{f,\rho }\) be the polar set

$$\begin{aligned} \Gamma _{f,\rho } = \left\{ x \in {\mathbb {R}}^n \ \vert \ \textrm{rank} [\nabla f_{\vert S} (x), \nabla \rho _{\vert S} (x) ] < 2 \right\} , \end{aligned}$$

where S is the stratum that contains x. We have \(\Sigma _f \subset \Gamma _{f,\rho }\).

Definition 2.15

The set of asymptotic non-\(\rho \)-regular values of f is the set defined as follows:

$$\begin{aligned} \Lambda _f = \{ \alpha \in {\mathbb {R}} \ \vert \ \exists \{x_n\}_{n\in {\mathbb {N}}} \in \Gamma _{f,\rho } \hbox { such that } \vert x_n \vert \rightarrow +\infty \hbox { and } f(x_n) \rightarrow \alpha \}. \end{aligned}$$

The set \(\Lambda _f\) was introduced and studied by Tibăr (1999) when \(X={\mathbb {R}}^n\) and \(f:{\mathbb {R}}^n \rightarrow {\mathbb {R}}\) is a polynomial. By Lemma 2.2 in Dutertre (2012), we can assume that \(\Gamma _{f,\rho }\setminus \Sigma (f)\) is a curve and so, that \(\Lambda _f\) is a finite set \(\{d_1,d_2\ldots , d_m\}\), with \(d_1<d_2<\cdots <d_m\).

2.5 Some Others Sets of Special Values

We define four sets of special values. They are values where some changes in the topology of the fibres of f may occur.

Definition 2.16

Let \(*\in \{\le ,=,\ge \}\).

  1. (1)

    We define \(\Lambda ^{*}_f\) by

    $$\begin{aligned} \Lambda ^{*}_f = \{\alpha \in {\mathbb {R}}\ |\ \beta \mapsto \chi ({\text {Lk}}^{\infty }(\{f*\beta \})) \hbox { is not constant } \\ \hbox { in a neighborhood of } \alpha \}. \end{aligned}$$
  2. (2)

    We define \({\widetilde{B}}(f)\) by \({\widetilde{B}}(f) = \Delta _f\cup \Lambda _f^{\le }\cup \Lambda _f^{\ge }.\)

Proposition 2.17

  1. (1)

    The sets \(\Lambda _f^{*}\) and \({\widetilde{B}}(f)\) are finite. Moreover \(\Lambda _f^= \subset \Lambda _f^\le \cup \Lambda _f^\ge \).

  2. (2)

    If \(\alpha \notin {\widetilde{B}}(f)\), the functions

    $$\begin{aligned} \beta \mapsto \chi (\{f*\beta \}), *\in \{\le , =, \ge \}, \end{aligned}$$

    are constant in a neighborhood of \(\alpha \).

Proof

The first point is proved in Dutertre (2012). Let \(\alpha \notin {\widetilde{B}}(f)\) and let \(\alpha ^- < \alpha \) be a value close enough to \(\alpha \). Let \(R_\alpha \) (resp. \(R_{\alpha ^-}\)) be an adapted radius for \(f^{-1}(\alpha )\) (resp. \(f^{-1}(\alpha ^-)\)). We can choose them in such a way that they are also adapted to \(\{f \le \alpha \}\) and \(\{ f \le \alpha ^-\}\) respectively. The critical points of \(f_{\vert \{\alpha ^-< f < \alpha \} \cap B_{R_{\alpha ^-}}}\) can only lie on \( S_{R_{\alpha ^-}}\), and they point outwards. By Lemma 2.12, this implies that

$$\begin{aligned} \chi ( \{f \le \alpha ^-\})=\chi ( \{f \le \alpha \}), \end{aligned}$$

because \(R_{\alpha ^-}\) is also adapted for \(\{f \le \alpha \}\).

Similarly, we can consider the critical points of \(-f_{\vert \{\alpha ^-< f < \alpha \} \cap B_{R_{\alpha ^-}}}.\) Applying Lemma 2.12 twice, we obtain that

$$\begin{aligned} \chi (\{f \ge \alpha ^- \}) -\chi (\{f \ge \alpha \})=\chi ({\text {Lk}}^{\infty }(\{f \ge \alpha ^- \})) -\chi ({\text {Lk}}^{\infty }(\{f \ge \alpha \}))=0, \end{aligned}$$

since \(\alpha \notin \Lambda ^\ge _f\). By Lemma 2.11, we see that

$$\begin{aligned} \chi (\{f = \alpha ^- \}) =\chi (\{f = \alpha \}). \end{aligned}$$

The same proof works for \(\alpha ^+ > \alpha \), a value close enough to \(\alpha \). \(\square \)

Remark 2.18

Taking into account Proposition 2.17 and basic properties of \(\chi _c\), if we have inclusions

$$\begin{aligned} \Lambda _f^{*} \subset \{\nu _1, \nu _2, \ldots , \nu _t\}, \end{aligned}$$

with \(\nu _1< \nu _2< \cdots < \nu _t\) and

$$\begin{aligned} {\widetilde{B}}(f) \subset \{\eta _1, \eta _2, \ldots , \eta _u\}, \end{aligned}$$

with \(\eta _1< \eta _2< \cdots < \eta _u\), we can express the Euler integral \(\int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(X\cap \{f*t\}))d\chi _c(t)\) as

$$\begin{aligned} \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(X\cap \{f*t\}))d\chi _c(t)= & {} \sum _{i=1}^t\chi ({\text {Lk}}^{\infty }(X\cap \{f*\nu _i\}))\\{} & {} - \sum _{i=0}^t\chi ({\text {Lk}}^{\infty }(X\cap \{f*\nu _i^+\})), \end{aligned}$$

the Euler integral \(\int _{{\mathbb {R}}}\chi (X\cap \{f*t\})d\chi _c(t)\) as

$$\begin{aligned} \int _{{\mathbb {R}}}\chi (X\cap \{f*t\})d\chi _c(t) = \sum _{j=1}^u\chi (X\cap \{f*\eta _j\}) - \sum _{j=0}^u\chi (X\cap \{f*\eta _j^+\}), \end{aligned}$$

and the Euler integral \(\int _{{\mathbb {R}}}\chi _c(X\cap \{f*t\})d\chi _c(t)\) as

$$\begin{aligned} \int _{{\mathbb {R}}}\chi _c(X\cap \{f*t\})d\chi _c(t) = \sum _{j=1}^u\chi _c(X\cap \{f*\eta _j\}) - \sum _{j=0}^u\chi _c(X\cap \{f*\eta _j^+\}), \end{aligned}$$

where \(\nu _0, \eta _0 =-\infty \), \(\nu _{t+1}=+\infty \), \(\eta _{u+1}=+\infty \), \(\nu _i^+\in ]\nu _i,\nu _{i+1}[\) and \(\eta _j^+\in ]\eta _j,\eta _{j+1}[\).

3 Formulas for the Euler Characteristic of a Closed Semi-Algebraic Set in the General Case

Let X be a closed semi-algebraic set, equipped with a finite semi-algebraic Whitney stratification \(X=\sqcup _{a\in A}S_{a}\). Let \(F: {\mathbb {R}}^n \rightarrow {\mathbb {R}}\) be a \({\mathcal {C}}^2\) semi-algebraic function. We call \(f = F_{|X}\), the restriction of F to X. Let \(\Delta _f = \{c_1, c_2, \ldots , c_k\}\) be the set of critical values of f.

Let \(c_i\) be a critical value of f. The partition \(f^{-1}(c_i)= \sqcup _{a\in A} f^{-1}(c_i) \cap S_{a}\) may not be a Whitney stratification, but since Whitney conditions are stratifying, we can refine it in order to get a Whitney stratification \(f^{-1}(c_i)= \sqcup _{b\in B}T_{B}\) of \(f^{-1}(c_i)\) such that

$$\begin{aligned} X = \sqcup _{a\in A} (S_{a} \setminus f^{-1}(c_i)) \bigsqcup \sqcup _{b\in B}T_{B} \end{aligned}$$

is still a Whitney stratification of X.

Definition 3.1

We define the index of a critical value \(c_i\) of f as

$$\begin{aligned} {\text {ind}}_g(f,X,f^{-1}(c_i))=\chi (f^{-1}(c_i)) - \chi (f^{-1}(c_i-\alpha )\cap B_{R_{c_i}}) \end{aligned}$$

with \(0<\alpha \ll 1\) and \(R_{c_i}\) is an adapted radius for \(f^{-1}(c_i).\)

Theorem 3.2

We have

$$\begin{aligned} \chi (X) = \sum _{i=1}^k{\text {ind}}_g(f, X, f^{-1}(c_i)) - \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t). \end{aligned}$$

Proof

By Hardt’s theorem Hardt (1975), there exists a finite set \(\widetilde{\Delta }_f \subset {\mathbb {R}}\) such that over each connected component of \({\mathbb {R}} \setminus \widetilde{\Delta }_f\), f is a semi-algebraic trivial fibration. Let us write

$$\begin{aligned} \Lambda _f \cup {\widetilde{B}}_f \cup \widetilde{\Delta }_f = \{b_1,\ldots , b_l\}, \end{aligned}$$

where \(b_1< \cdots < b_l\).

Note that, by Lemma 2.9, \({\text {ind}}_g(f,X,f^{-1}(b_j))= 0\) if \(b_j\notin \Delta _f\).

By Corollary 2.3, we have

$$\begin{aligned} \chi _c(X)=\int _{{\mathbb {R}}}\chi _c(f^{-1}(t))d\chi _c(t) = \sum _{j=1}^l (\chi _c(f^{-1}(b_j)- \chi _c(f^{-1}(b_j^-))- \chi _c(f^{-1}(b_l^+)), \end{aligned}$$

where \(b_j^-=b_j-\alpha \) and \(b_j^+=b_j+\alpha \), with \(0<\alpha \ll 1\).

To compute the right-hand side of the above equality, we work with each difference \(\chi _c(f^{-1}(b_j)- \chi _c(f^{-1}(b_j^-))\) for \(j=1,\ldots ,l\). Let us set \(b_{j}^-=b^-\) and \(b_j = b\) with \(b^{-}=b-\delta \), \(0<\delta \ll \frac{1}{R_{b^{-}}}\), where \(R_{b^{-}}>R_{b}\gg 1\) are adapted radius for \(f^{-1}(b^-)\) and \(f^{-1}(b)\). We have

$$\begin{aligned}{} & {} \chi _c(f^{-1}(b))-\chi _c(f^{-1}(b^-)) \\{} & {} \quad = \chi (f^{-1}(b))-\chi ({\text {Lk}}^{\infty }(f^{-1}(b))-\chi (f^{-1}(b^-)\cap B_{R_b})+\chi (f^{-1}(b^-)\cap S_{R_b}) \\{} & {} \qquad -\chi _c(f^{-1}(b^-)\cap \{|x|\ge R_b\}) \\{} & {} \quad ={\text {ind}}_g(f,X,f^{-1}(b))-\chi ({\text {Lk}}^{\infty }(f^{-1}(b))+\chi (f^{-1}(b^-)\cap S_{R_b})\\{} & {} \qquad -\chi _c(f^{-1}(b^-)\cap \{|x|\ge R_b\}). \end{aligned}$$

As explained above, we can assume that \(f^{-1}(b)\) is a union of strata of our stratification. If \(R_b\) is sufficiently big and \(b^-\) is sufficiently close to b, then the (stratified) critical points of \(-\rho _{\vert \{b^- \le f \le b\}}\) lying in \(\{ R_b \le \rho \le R_{b^-}\}\) appear on \(\{f =b^-\}\). Moreover they are correct and points outwards (Fig. 1).

Fig. 1
figure 1

Critical points on the fiber \(f^{-1}(b^-)\)

Therefore, by Lemmas 2.12 and 2.13, we have

$$\begin{aligned} \chi (\{R_b\le |x|{} & {} \le R_{b^-}\}\cap \{b^-\le f \le b\}) \\{} & {} = \chi (\{b^-\le f \le b\}\cap S_{R_{b^-}}) = \chi (\{f\le b\}\cap S_{R_{b^-}}) - \chi (\{f\le b^-\}\cap S_{R_{b^-}})\\{} & {} \quad + \chi (\{f=b^-\}\cap S_{R_{b^-}}) \\{} & {} = \chi ({\text {Lk}}^{\infty }(\{f\le b\})) - \chi ({\text {Lk}}^{\infty }(\{f\le b^-\})) + \chi ({\text {Lk}}^{\infty }(\{f =b^-\})), \end{aligned}$$

applying Lemma 2.11 and the definition of the link at infinity.

Let us compute \(\chi (\{R_b\le |x| \le R_{b^-}\}\cap \{b^-\le f \le b\})\) in another way. Let \({\tilde{b}}\) be a regular value of f such that \(b^-< {\tilde{b}} < b\) and \(f_{\vert \{ R_b \le \vert x \vert \le R_{b^-}\}}\) has no critical point on \(\{ {\tilde{b}} \le f < b \}\). This implies that \(f^{-1}(b) \cap \{ R_b \le \vert x \vert \le R_{b^-} \}\) is a deformation retract of \(\{R_b\le |x| \le R_{b^-}\}\cap \{{\tilde{b}} \le f \le b\}\). Applying the same argument as above, considering the function \(f_{\vert \{ R_b \le \vert x \vert \le R_{b^-} \}}\) and applying Lemmas 2.12 and 2.13, we obtain that

$$\begin{aligned} \chi ( \{ b^- \le f \le {\tilde{b}} \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \})= \chi ( \{ f=b^- \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}). \end{aligned}$$

By Lemma 2.11 and the deformation retract argument, we get that

$$\begin{aligned} \chi ( \{ b^- \le f \le b \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \})= & {} \chi ( \{ f=b^- \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}) \\{} & {} + \chi ( \{ f =b \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \})\\{} & {} - \chi ( \{ f={\tilde{b}} \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}). \end{aligned}$$

Moreover if we choose \({\tilde{b}}\) close enough to b, then the intersection

$$\begin{aligned} \Gamma _{f,\rho } \setminus \Sigma _f \cap [ f^{-1}([{\tilde{b}},b])\cap \{R_b\le |x| \le R_{b^-}\} ] \end{aligned}$$

is empty (see Fig. 2).

Fig. 2
figure 2

The fiber \(f^{-1}(\tilde{b})\)

This implies that

$$\begin{aligned} \chi ( \{f={\tilde{b}} \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}) = \chi ( \{f={\tilde{b}} \} \cap S_{R_b}). \end{aligned}$$

Finally we obtain that

$$\begin{aligned} \chi ( \{ b^- \le f \le b \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \})= & {} \chi ( \{ f=b^- \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}) \\{} & {} + \chi ( {\text {Lk}}^\infty (f^{-1}(b))) - \chi ( \{f=b' \} \cap S_{R_b}). \end{aligned}$$

Comparing the two expressions for \(\chi (\{R_b\le |x| \le R_{b^-}\}\cap \{b^-\le f \le b\})\) leads to

$$\begin{aligned} \chi ( \{f=b^-\} \cap \{ R_b \le \vert x \vert \le R_{b^-}\})= & {} \chi ({\text {Lk}}^{\infty }(\{f\le b\})) - \chi ({\text {Lk}}^{\infty }(\{f\le b^-\})) \\{} & {} + \chi ({\text {Lk}}^{\infty }(\{f =b^-\})) -\chi ( {\text {Lk}}^\infty (f^{-1}(b)))\\{} & {} + \chi ( \{f=b' \} \cap S_{R_b}). \end{aligned}$$

Then we can write

$$\begin{aligned} \chi _c ( \{f=b^- \} \cap \{ \vert x \vert \ge R_b \})= & {} \chi ( \{f=b^- \} \cap \{ \vert x \vert \ge R_b \}) - \chi ( {\text {Lk}}^\infty (f^{-1}(b^-))) \\= & {} \chi ( \{f=b^- \} \cap \{ R_b \le \vert x \vert \le R_{b^-} \}) - \chi ( {\text {Lk}}^\infty (f^{-1}(b^-))) \\= & {} \chi ({\text {Lk}}^{\infty }(\{f\le b\})) - \chi ({\text {Lk}}^{\infty }(\{f\le b^-\})) \\{} & {} - \chi ( {\text {Lk}}^\infty (f^{-1}(b))) +\chi ( \{f=b' \} \cap S_{R_b}). \end{aligned}$$

Finally we obtain

$$\begin{aligned} \chi _c(f^{-1}(b))-\chi _c(f^{-1}(b^-)){} & {} ={\text {ind}}_g(f,X,f^{-1}(b)) \\{} & {} \quad -\chi ({\text {Lk}}^{\infty }(\{f\le b\})) + \chi ({\text {Lk}}^{\infty }(\{f\le b^-\})), \end{aligned}$$

and so

$$\begin{aligned} \chi _c(X){} & {} = \sum _{j=1}^l{\text {ind}}_g(f, X, f^{-1}(b_j)) - \sum _{j=1}^l\chi ({\text {Lk}}^{\infty }(\{f\le b_j\}))\\{} & {} \quad + \sum _{j =1}^l\chi ({\text {Lk}}^{\infty }(\{f\le b_j^-\})) - \chi _c(f^{-1}(b_l^+)). \end{aligned}$$

Let \(R_{b_l^+}\) be an adapted radius for \(f^{-1}(b_l^+)\). We can write

$$\begin{aligned} \chi _c(f^{-1}(b_l^+))= & {} \chi (f^{-1}(b_l^+)\cap B_{R_{b_l^+}}) - \chi ({\text {Lk}}^{\infty }(f^{-1}(b_l^+)))\\= & {} \chi (\{f\ge b_l^+\}\cap B_{R_{b_l^+}}) - \chi ({\text {Lk}}^{\infty }(f^{-1}(b_l^+))), \end{aligned}$$

because by Lemma 2.10, \(\chi (f^{-1}(b_l^+)\cap B_{R_{b_l^+}})=\chi (\{f\ge b_l^+\}\cap B_{R_{b_l^+}})\). Hence,

$$\begin{aligned} \chi _c(f^{-1}(b_l^+))= & {} \chi (\{f\ge b_l^+\}) - \chi ({\text {Lk}}^{\infty }(f^{-1}(b_l^+))) \\= & {} \chi _c(\{f\ge b_l^+\}) + \chi ({\text {Lk}}^{\infty }(\{f\ge b_l^+\})) - \chi ({\text {Lk}}^{\infty }(f^{-1}(b_l^+))). \end{aligned}$$

But since \(\chi _c ([b_{l^+},+\infty [)=0\) and \(f_{\vert [b_{l^+},+\infty [}\) is a trivial fibration, we get that \(\chi _c(\{f\ge b_l^+\})=0\). We conclude that

$$\begin{aligned} \chi _c(f^{-1}(b_l^+)) = \chi ({\text {Lk}}^{\infty }(X)) - \chi ({\text {Lk}}^{\infty }(\{f\le b_l^+\})), \end{aligned}$$

by Lemma 2.11. Putting \(b_l^+=b_{l+1}^-\), where \(b_{l+1}=+\infty \), we have

$$\begin{aligned} \chi _c(X)= & {} \chi (X) - \chi ({\text {Lk}}^{\infty }(X)) \\= & {} \sum _{j=1}^l{\text {ind}}_g(f, X, f^{-1}(b_j)) - \chi ({\text {Lk}}^{\infty }(X)) + \sum _{j=1}^{l+1}\chi ({\text {Lk}}^{\infty }(\{f\le b_j^-\})) \\{} & {} -\sum _{j=1}^l\chi ({\text {Lk}}^{\infty }(\{f\le b_j\})) = \sum _{j=1}^l{\text {ind}}_g(f, X, f^{-1}(b_j)) \\{} & {} - \chi ({\text {Lk}}^{\infty }(X)) - \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t), \end{aligned}$$

obtaining the desired result. \(\square \)

Corollary 3.3

If f has a finite number of critical points \(p_1, p_2,\ldots , p_l\) then

$$\begin{aligned} \chi (X) = \sum _{i=1}^l{\text {ind}}(f, X, p_i) - \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t). \end{aligned}$$

Proof

Let \(b_i\) be a critical value such that \(f^{-1}(b_i)\) has a finite number of singularities \(p_1,\ldots , p_{r_i}.\) By Lemma 2.9, we know that

$$\begin{aligned} \sum _{i=1}^{r_i}{\text {ind}}(f,X,p_i)=\chi (f^{-1}(b_i))-\chi (f^{-1}(b_i^-)\cap B_{R_{b_i}}) \end{aligned}$$

where \(R_{b_i}\) is an adapted radius for \(f^{-1}(b_i)\). \(\square \)

Corollary 3.4

We have

$$\begin{aligned} \chi (X) = \sum _{i=1}^k{\text {ind}}_g(-f, X, f^{-1}(c_i)) - \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\ge t\}))d\chi _c(t). \end{aligned}$$

Proof

By replacing f by \(-f\) and applying an analogous procedure as in the last theorem, we arrive to the desired result. \(\square \)

Corollary 3.5

We have

$$\begin{aligned} 2\chi (X) - \chi ({\text {Lk}}^{\infty }(X))= & {} \sum _{i=1}^l{\text {ind}}_g(f,X,f^{-1}(c_i))\\{} & {} + \sum _{i=1}^l{\text {ind}}_g(-f,X,f^{-1}(c_i)) \\{} & {} -\int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f=t\}))d\chi _c(t). \end{aligned}$$

Proof

It follows from Theorem 3.2 and Corollary 3.4 by applying Lemma 2.11. \(\square \)

Lemma 3.6

We have \(\int _{{\mathbb {R}}}\chi _c(\{f\le t\})d\chi _c(t) = 0.\)

Proof

Let us take b in \(\Lambda _f \cup {\widetilde{B}}_f \cup \widetilde{\Delta }_f\) and \(b^+=b + \delta \), with \(\delta >0\) small enough, a regular value. Since \(f_{|X\cap ]b, b^+]}\) is trivial and \(\chi _c(]b, b^+])=0\), we conclude that

$$\begin{aligned} \chi _c(\{f\le b^+\}) - \chi _c(\{f\le b\}) = \chi _c(\{\alpha < f\le b^+\}) = 0. \end{aligned}$$

Therefore,

$$\begin{aligned} \int _{{\mathbb {R}}}\chi _c(\{f\le t\})d\chi _c(t)= & {} \sum _{j=1}^l\chi _c(\{f\le b_i\}) - \sum _{j=0}^l\chi _c(\{f\le b_i^+\}) \\= & {} -\chi _c(\{f\le b_0^+\}) = 0. \end{aligned}$$

\(\square \)

Corollary 3.7

We have

$$\begin{aligned} \chi (X) = \sum _{i=1}^k{\text {ind}}_g(f,X,f^{-1}(c_i)) -\int _{{\mathbb {R}}}\chi (\{f\le t\})d\chi _c(t). \end{aligned}$$

Proof

We have

$$\begin{aligned} \chi (X) = \sum _{i=1}^k{\text {ind}}_g(f,X,f^{-1}(c_i)) -\int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t), \end{aligned}$$

and

$$\begin{aligned} \int _{{\mathbb {R}}}\chi _c(\{f\le t\})d\chi _c(t)= & {} \int _{{\mathbb {R}}}\chi _c(\{f\le t\}\cap B_{R_t})d\chi _c(t) \\{} & {} - \int _{{\mathbb {R}}}\chi _c({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t) = 0. \end{aligned}$$

Then,

$$\begin{aligned} \int _{{\mathbb {R}}}\chi (\{f\le t\})d\chi _c(t)= & {} \int _{{\mathbb {R}}}\chi (\{f\le t\}\cap B_{R_t})d\chi _c(t) \\= & {} \int _{{\mathbb {R}}}\chi _c(\{f\le t\}\cap B_{R_t})d\chi _c(t)\\= & {} \int _{{\mathbb {R}}}\chi ({\text {Lk}}^{\infty }(\{f\le t\}))d\chi _c(t), \end{aligned}$$

arriving to the desired result. \(\square \)

Corollary 3.8

We have

$$\begin{aligned} \chi (X) = \sum _{i=1}^k{\text {ind}}_g(-f,X,f^{-1}(c_i)) -\int _{{\mathbb {R}}}\chi (\{f\ge t\})d\chi _c(t). \end{aligned}$$

Proof

By replacing f by \(-f\) and applying an analogous procedure as in the last corollary, we arrive to the desired result. \(\square \)

Corollary 3.9

We have

$$\begin{aligned} \chi (X)= & {} \sum _{i=1}^k{\text {ind}}_g(f,X,f^{-1}(c_i))\\{} & {} \quad + \sum _{i=1}^k{\text {ind}}_g(-f,X,f^{-1}(c_i)) - \int _{{\mathbb {R}}}\chi (\{f=t\})d\chi _c(t). \end{aligned}$$

Proof

It follows from the last two corollaries by applying Lemma 2.11. \(\square \)

Remark 3.10

Since \({\text {ind}}_g(f,X,f^{-1}(t))=0\) if t is not a critical value of f, we can replace \( \sum _{i=1}^k{\text {ind}}_g(\pm f, X, f^{-1}(c_i)) \) with \(\int _{{\mathbb {R}}} {\text {ind}}_g(\pm f, X, f^{-1}(t))d\chi _c(t)\) in all our statements.

Application 3.11

Let us apply these results to the case of a function given as the quotient of two semi-algebraic functions. Let \(f,g: X\rightarrow {\mathbb {R}}\) be two semi-algebraic functions, where X a closed semi-algebraic set and f (resp. g) is the restriction to X of a \({\mathcal {C}}^2\) semi-algebraic function F (resp. G). We consider their quotient \(\phi :=f/g: X\setminus V(g) \rightarrow {\mathbb {R}}\) which is also a semi-algebraic function. Let Y be the following closed semi-algebraic set:

$$\begin{aligned} Y=\{(x,y)\in X\times {\mathbb {R}}\ \vert \ f(x)-yg(x)=0\}. \end{aligned}$$

We cannot apply Corollary 3.9 since \(\phi \) is not defined in X, so we work with Y to obtain a formula for the sum of the global indices of the function \(\phi \).

Let \(\pi :Y\rightarrow {\mathbb {R}}\) be the linear function defined by \(\pi (x,y)=y\). By applying Corollary 3.9, we have that

$$\begin{aligned} \chi (Y)= & {} \int _{{\mathbb {R}}} {\text {ind}}_g(\pi , Y, \pi ^{-1}(t))d\chi _c(t) + \int _{{\mathbb {R}}} {\text {ind}}_g(-\pi , Y, \pi ^{-1}(t))d\chi _c(t) \\{} & {} - \int _{{\mathbb {R}}}\chi (Y\cap \{\pi =t\})d\chi _c(t). \end{aligned}$$

We have that, if \(t\ne 0\),

$$\begin{aligned} Y\cap \{\pi =t\}=\{(x,t)\ \vert \ f(x)-tg(x)=0\}=\{x\ \vert \ \phi (x) =t\}\sqcup \{f=g=0\}, \end{aligned}$$

and so,

$$\begin{aligned} \chi (Y\cap \{\pi =t\})=\chi (\{\phi (x)=t\})+\chi (\{f=g=0\}). \end{aligned}$$

When \(t=0\), we have that

$$\begin{aligned} Y\cap \{\pi =0\}=\{x\ \vert \ f(x)=0\}, \end{aligned}$$

and so,

$$\begin{aligned} \chi (Y\cap \{\pi =0\})=\chi (\{f=0\}). \end{aligned}$$

Let us study the global index of \(\pi \) at the non-zero critical value t. We recall that

$$\begin{aligned} {\text {ind}}_g(\pi ,Y,\pi ^{-1}(t)) = \chi (Y\cap \pi ^{-1}(t)) -\chi (Y\cap \pi ^{-1}(t-\alpha )\cap B_{R_t}), \end{aligned}$$

where \(R_t\) is an adapted radius for \(\pi ^{-1}(t)\) and \(0< \alpha \ll \frac{1}{R_t}\).

We have

$$\begin{aligned} (x,t)\in Y\cap \pi ^{-1}(t)\Leftrightarrow f(x)-tg(x)=0\Leftrightarrow \end{aligned}$$
$$\begin{aligned} {\left\{ \begin{array}{ll} \phi (x)=t &{} \text {if} \ g(x)\ne 0, \\ f(x)=0 &{} \text {if} \ g(x)=0, \end{array}\right. } \end{aligned}$$

then,

$$\begin{aligned} \chi (Y\cap \pi ^{-1}(t))=\chi (\{ \phi =t \})+\chi (\{f=g=0\}). \end{aligned}$$

Let us study \(\chi (Y\cap \pi ^{-1}(t-\alpha )\cap B_{R_t})\). We have

$$\begin{aligned} (x,t-\alpha )\in Y\cap \pi ^{-1}(t-\alpha )\cap B_{R_t}\Leftrightarrow {\left\{ \begin{array}{ll} f(x)-(t-\alpha )g(x) = 0\\ |(x,t-\alpha )|\le R_t\end{array}\right. }\Leftrightarrow \end{aligned}$$
$$\begin{aligned} {\left\{ \begin{array}{ll} \phi (x)=t-\alpha , |x|\le \sqrt{R_t^2-(t-\alpha )^2} &{} \text {if} \ g(x)\ne 0 \\ f(x)=0 &{} \text {if} \ g(x)=0\end{array}\right. }. \end{aligned}$$

If \(R_t\) is big enough and \(\alpha \) small enough, then \({\widetilde{R}}= \sqrt{R_t^2 - (t-\alpha )^2}\) is an adapted radius for \(\{\phi =t\}\) and \(\{f=g=0\}\). Therefore we have

$$\begin{aligned} \chi (Y\cap \pi ^{-1}(t-\alpha )\cap B_{R_t})=\chi (\{\phi =t-\alpha \})\cap B_{{\widetilde{R}}}) + \chi (\{f=g=0\}\cap B_{{\widetilde{R}}}). \end{aligned}$$

Therefore, we get

$$\begin{aligned} \chi (Y)= & {} \int _{{\mathbb {R}}^*} {\text {ind}}_g(\phi , X, \phi ^{-1}(t))d\chi _c(t) + \int _{{\mathbb {R}}^*} {\text {ind}}_g(-\phi , X, \phi ^{-1}(t))d\chi _c(t) \\{} & {} +{\text {ind}}_g(\pi ,Y,\pi ^{-1}(0)) + {\text {ind}}_g(-\pi ,Y,\pi ^{-1}(0)) - \chi (\{f=0\}) \\{} & {} +2\chi (\{f=g=0\}) - \int _{{\mathbb {R}}^{*}}\chi (X\cap \{\phi =t\})dt. \end{aligned}$$

We have that

$$\begin{aligned} Y =\{(x,y)\ \vert \ f(x)-yg(x)=0\}=\{(x,y)\ \vert \ \phi (x) =y\}\sqcup \Big (\{f=g=0\} \times {\mathbb {R}} \Big ), \end{aligned}$$

and so,

$$\begin{aligned} \chi (Y)=\chi (X\setminus V(g))+\chi (\{f=g=0\}). \end{aligned}$$

Finally we obtain that

$$\begin{aligned} \chi (X\setminus V(g))= & {} \int _{{\mathbb {R}}^*} {\text {ind}}_g(\phi , X, \phi ^{-1}(t))d\chi _c(t) + \int _{{\mathbb {R}}^*} {\text {ind}}_g(-\phi , X, \phi ^{-1}(t))d\chi _c(t) \\{} & {} +{\text {ind}}_g(\pi ,Y,\pi ^{-1}(0)) + {\text {ind}}_g(-\pi ,Y,\pi ^{-1}(0)) - \chi (\{f=0\}) \\{} & {} +\chi (\{f=g=0\}) - \int _{{\mathbb {R}}^{*}}\chi (X\cap \{\phi =t\})dt. \end{aligned}$$

If furthermore we assume that 0 is a regular value (in the stratified sense) of f, then 0 is a regular value of \(\pi \) and so

$$\begin{aligned} \chi (X\setminus V(g))= & {} \int _{{\mathbb {R}}^*} {\text {ind}}_g(\phi , X, \phi ^{-1}(t))d\chi _c(t) + \int _{{\mathbb {R}}^*} {\text {ind}}_g(-\phi , X, \phi ^{-1}(t))d\chi _c(t) \\{} & {} - \chi (\{f=0\})+\chi (\{f=g=0\}) - \int _{{\mathbb {R}}^{*}}\chi (X\cap \{\phi =t\})dt. \end{aligned}$$

Taking \(f=1\), we obtain an index formula for the Euler characteristic of the non-closed semi-algebraic set \(X {\setminus } V(g)\). Namely we have

$$\begin{aligned} \chi (X\setminus V(g))= & {} \int _{{\mathbb {R}}^*} {\text {ind}}_g(\phi , X, \phi ^{-1}(t))d\chi _c(t) + \int _{{\mathbb {R}}^*} {\text {ind}}_g(-\phi , X, \phi ^{-1}(t))d\chi _c(t) \\{} & {} - \int _{{\mathbb {R}}^{*}}\chi (X\cap \{\phi =t\})dt. \end{aligned}$$

4 New Indices at Infinity

By Proposition 2.17, there exists a finite set \(\{e_1,e_2,\ldots ,e_s\}\), \(e_1<e_2< \cdots <e_s\), such that the function \(t\mapsto \chi (f^{-1}(t))\) is locally constant on \({\mathbb {R}}\setminus \{e_1,e_2,\ldots ,e_s\}.\) When X is compact, by Corollary 2.3, we have

$$\begin{aligned} \chi (X)= \int _{[e_1,e_s]}\chi (f^{-1}(t))d\chi _c(t), \end{aligned}$$

because \(f^{-1}(t)\) is empty for \(t<e_1\) and \(t>e_s\). The aim of this section is to generalize this equality when X is only closed, by introducing new indices at infinity and applying the results of Sect. 3.

We recall that \(\Lambda _f\) is defined by

$$\begin{aligned} \Lambda _f = \{ \alpha \in {\mathbb {R}} \ \vert \ \exists (x_n)_{n\in {\mathbb {N}}} \in \Gamma _f \hbox { such that } \vert x_n \vert \rightarrow +\infty \hbox { and } f(x_n) \rightarrow \alpha \}, \end{aligned}$$

and that it is a finite set \(\{d_1,d_2\ldots , d_m\}\), with \(d_1<d_2<\cdots <d_m\).

Definition 4.1

We define the right index at infinity of \(d_i\) as

$$\begin{aligned} {\text {ind}}^{+}_{\infty }(f,X,f^{-1}(d_i))=\chi (f^{-1}(d_i^+))-\chi (f^{-1}(d_i^+)\cap B_{R_{d_i}}). \end{aligned}$$

Analogously, we define the left index at infinity of \(d_i\) as

$$\begin{aligned} {\text {ind}}^{-}_{\infty }(f,X,f^{-1}(d_i))=\chi (f^{-1}(d_i^-))-\chi (f^{-1}(d_i^-)\cap B_{R_{d_i}}), \end{aligned}$$

where \(d_i^+=d_i+\alpha \), \(d_i^-=d_i-\alpha \) with \(0<\alpha \ll 1\) and \(R_{d_i}\) is an adapted radius for \(f^{-1}(d_i).\)

Example 4.2

Let us consider the Broughton polynomial \(f(x,y)=y(xy-1)\) defined on \(X={\mathbb {R}}^2\).

We have that \(\Lambda _f=\{0\}\) and

$$\begin{aligned} {\text {ind}}^{+}_{\infty }(f,{\mathbb {R}}^2,f^{-1}(0)) = \chi (f^{-1}(\delta ))-\chi (f^{-1}(\delta )\cap B_{R_0}) = 2-3=-1, \\ {\text {ind}}^{-}_{\infty }(f,{\mathbb {R}}^2,f^{-1}(0)) = \chi (f^{-1}(-\delta ))-\chi (f^{-1}(-\delta )\cap B_{R_0}) = 2-3=-1, \end{aligned}$$

with \(R_0\) an adapted radius for 0 and \(0<\delta \ll 1\) (see Fig. 3).

Fig. 3
figure 3

The Broughton polynomial

Example 4.3

(Tibăr and Zaharia 1999) Let us consider the polynomial \(f(x,y)=x^2y^2+2xy+(y^2-1)^2\) defined on \(X={\mathbb {R}}^2\). We have that \(0\in \Lambda _f\) and

$$\begin{aligned} {\text {ind}}^{+}_{\infty }(f,{\mathbb {R}}^2,f^{-1}(0)) = \chi (f^{-1}(\delta ))-\chi (f^{-1}(\delta )\cap B_{R_0}) = 2-2=0, \\ {\text {ind}}^{-}_{\infty }(f,{\mathbb {R}}^2,f^{-1}(0)) = \chi (f^{-1}(-\delta ))-\chi (f^{-1}(-\delta )\cap B_{R_0}) = 0-0=0, \end{aligned}$$

with \(R_0\) an adapted radius for 0 and \(0<\delta \ll 1\) (see Fig. 4).

Fig. 4
figure 4

\(f(x,y)=x^2y^2+2xy+(y^2-1)^2\)

Theorem 4.4

We have

$$\begin{aligned} \chi (X)= & {} \sum _{i=1}^m({\text {ind}}^{+}_{\infty }(f, X, f^{-1}(d_i)) + {\text {ind}}^{-}_{\infty }(f, X, f^{-1}(d_i))) \\{} & {} + \int _{[e_1,e_s]}\chi (f^{-1}(t))d\chi _c(t). \end{aligned}$$

Proof

We recall that

$$\begin{aligned} \Lambda _f \cup {\widetilde{B}}_f \cup \widetilde{\Delta }_f = \{b_1,\ldots , b_l\}, \end{aligned}$$

with \(b_1<b_2< \cdots < b_l\). First of all, note that, by the definition of the indices at infinity,

$$\begin{aligned} {\text {ind}}^{+}_{\infty }(f,X,f^{-1}(b_i)) = {\text {ind}}^{-}_{\infty }(f,X,f^{-1}(b_i))= 0, \end{aligned}$$

if \(b_i\notin \Lambda (f)\) and that

$$\begin{aligned} {\text {ind}}_g(-f,X,f^{-1}(b_i))= {\text {ind}}_g(f,X,f^{-1}(b_i))=0, \end{aligned}$$

if \(b_i\notin \Delta _f.\)

By Corollary 3.9, we have

$$\begin{aligned} \chi (X)= & {} \sum _{j=1}^l{\text {ind}}_g(f,X,f^{-1}(b_i))\\{} & {} + \sum _{j=1}^l{\text {ind}}_g(-f,X,f^{-1}(b_i)) - \int _{{\mathbb {R}}}\chi (\{f=t\})d\chi _c(t). \end{aligned}$$

By definition,

$$\begin{aligned} {\text {ind}}_g(f,X,f^{-1}(b_i)) = \chi (f^{-1}(b_i)) -\chi (f^{-1}(b_i^-)\cap B_{R_{b_i}}). \end{aligned}$$

Therefore, we have

$$\begin{aligned} \chi (X)= & {} \sum _{i=1}^l \Big (2\chi ((f^{-1}(b_i)) - \chi (f^{-1}(b_i^-)\cap B_{R_{b_i}}) - \chi (f^{-1}(b_i^+)\cap B_{R_{b_i}}) \Big ) \\{} & {} + \sum _{i=1}^l \Big (\chi ((f^{-1}(b_i^-)) + \chi ((f^{-1}(b_i^+))\Big ) - \sum _{i=1}^l \chi ((f^{-1}(b_i)) - \sum _{i=1}^{l-1} \chi ((f^{-1}(b_i^+)) \\= & {} \sum _{i=1}^l \chi ((f^{-1}(b_i)) + \sum _{i=1}^m\Big ({\text {ind}}^{+}_{\infty }(f, X, f^{-1}(d_i)) + {\text {ind}}^{-}_{\infty }(f, X, f^{-1}(d_i))\Big ) \\{} & {} -\sum _{i=1}^{l-1} \chi ((f^{-1}(b_i^+)) = \sum _{i=1}^m\Big ({\text {ind}}^{+}_{\infty }(f, X, f^{-1}(d_i)) + {\text {ind}}^{-}_{\infty }(f, X, f^{-1}(d_i))\Big ) \\{} & {} +\int _{[b_1,b_l]}\chi (f^{-1}(t))d\chi _c(t). \end{aligned}$$

To conclude, we remark that

$$\begin{aligned} \int _{[b_1,e_1[}\chi (f^{-1}(t))d\chi _c(t)=0, \end{aligned}$$

if \(b_1<e_1\) and

$$\begin{aligned} \int _{]e_l,b_l]}\chi (f^{-1}(t))d\chi _c(t)=0, \end{aligned}$$

if \(e_l<b_l.\) \(\square \)

5 Relations with Functions with Compact Critical Set

If \(f: ({\mathbb {C}}^n,0) \rightarrow ({\mathbb {C}},0)\) is an analytic function germ with a one-dimensional singular locus then \(f +l^d \) has an isolated singularity at the origin, where l is a generic linear form and \(d \in {\mathbb {N}}\) is sufficiently big. Moreover the topology of the Milnor fibre of f is closely related to that of the Milnor fibre of \(f+l^d\). This is the well-know Lê-Iomdine formula (Iomdin 1974; Lê 1980).

In the real case, Szafraniec (1986) adapted this method by replacing l with the distance function to the origin. Then, using Szafraniec’s approach, the first author in Dutertre (2020) found generalizations of the Khimshiashvili formula for non-isolated singularities.

The aim of this section is to present similar results in our global and general setting. We note that our results generalize the ones of Dutertre et al. (2016), where the case \(X={\mathbb {R}}^n\) and f semi-tame is considered.

We recall that \(\rho (x)= 1 + \frac{1}{2}(x_1^2+\cdots +x_n^2)\) and that

$$\begin{aligned} \Gamma _{f,\rho } = \left\{ x \in {\mathbb {R}}^n \ \vert \ \textrm{rank} [\nabla f(x), \nabla \rho (x) ] < 2 \right\} . \end{aligned}$$

Note that \(\nabla \rho (x)=x\) and \(\rho (x) \ge 1\). We have \(\Sigma _f \subset \Gamma _{f,\rho }\).

Let \(\Lambda _f = \{d_1,d_2\ldots , d_m\}.\)

Lemma 5.1

There is \(k \in {\mathbb {N}}\) such that for all \(i\in \{1,2,\ldots ,m\}\), for all \(x \in \Gamma _{f,\rho } {\setminus } f^{-1}(d_i)\),

$$\begin{aligned} \vert f(x)-d_i \vert > \frac{1}{\rho (x)^k},\ 1\le i\le m, \end{aligned}$$

for \(\vert x \vert \gg 1\).

Proof

Note that 1 is the greatest critical value of \(\rho \). We set \({\tilde{S}}_r = \rho ^{-1}(r)\). Let \(\beta : ]1,+\infty [ \rightarrow {\mathbb {R}}\) be defined by

$$\begin{aligned} \beta (r) = \textrm{inf} \left\{ \vert f(x)-d_i \vert \ \vert \ x \in {\tilde{S}}_r \cap (\Gamma _{f,\rho } \setminus f^{-1}(d_i)) \right\} . \end{aligned}$$

The function \(\beta \) is semi-algebraic. Furthermore \(\beta >0\) because for \(r > 1\), \(f_{\vert {\tilde{S}}_r}\) has a finite number of critical values. Thus the function \(\frac{1}{\beta }\) is also semi-algebraic. Hence there exist \(r_1 \ge 1\) and \(k_0 \in {\mathbb {N}}\) such that \(\frac{1}{\beta } < r^k\), for \(r \ge r_1\) and \(k \ge k_0\). This implies that \(\beta (r) > \frac{1}{r^k}\) for \(r \ge r_1\) and \(k \ge k_0\). We can conclude that for \(r \ge r_1\) and \(k \ge k_0\),

$$\begin{aligned} \vert f(x) - d_i \vert > \frac{1}{\rho (x)^k}, \end{aligned}$$

for \( x \in {\tilde{S}}_r \cap ( \Gamma _{f,\rho } {\setminus } f^{-1}(d_i) ).\) \(\square \)

Let \(G_-(x) =F(x)-\frac{1}{\rho (x)^k}\) and let \(g_-={G_-}_{|X}.\)

Lemma 5.2

We have \(\Lambda _f = {\Lambda _g}_-\)

Proof

By definition of \(g_-(x)\), we have that \(\Gamma _{f,\rho }=\Gamma _{g_-,\rho }\). So if \(\{x_n\}\) is a sequence of points in \(\Gamma _{f,\rho }\) such that \(\{x_n\}\rightarrow \infty \) then \(\{f(x_n)\}\rightarrow d_i\) if and only if \(\{g_-(x_n)\}\rightarrow d_i\) \(\square \)

Lemma 5.3

For \(R \gg 1\), \(\chi ( \{ g_- \le d_i \} \cap {\tilde{S}}_R ) = \chi ( \{ f \le d_i \} \cap {\tilde{S}}_R )\).

Proof

Let \(R \gg 1\) be such that for all \(x \in (\Gamma _{f,\rho } {\setminus } f^{-1}(d_i) )\cap \{\rho (x) \ge R\}\), \(\vert f(x) - d_i \vert > \frac{1}{\rho (x)^k}\). Set \(N_f^\le = \{ x \in {\tilde{S}}_R \ \vert \ f(x) \le d_i \}\) and \(N_{g_-}^\le = \{ x \in {\tilde{S}}_R \ \vert \ g_-(x) \le d_i \}\). For \(x \in {\tilde{S}}_R\), we have

$$\begin{aligned} g_-(x) \le d_i \Leftrightarrow f(x)-\frac{1}{R^k} \le d_i \Leftrightarrow f(x) \le d_i + \frac{1}{R^k}, \end{aligned}$$

and so \(N_f^\le \subset N_{g_-}^\le \). Furthermore if \(0 < f(x) - d_i \le \frac{1}{R^k}\) then \(x \notin \Gamma _{f,\rho } {\setminus } f^{-1}(d_i)\) and therefore \(\{ f(x) \le d_i + \frac{1}{R^k} \} \cap {\tilde{S}}_R\) retracts by deformation to \(\{ f(x) \le d_i \} \cap {\tilde{S}}_R\). We get the result. \(\square \)

Corollary 5.4

We have \(\chi (\textrm{Lk}^\infty (\{g_- \le d_i \}) ) = \chi (\textrm{Lk}^\infty (\{f \le d_i \}) ) \).

Lemma 5.5

Let \(\alpha \notin \Lambda _f\). We have \(\chi (\textrm{Lk}^\infty (\{g_- \le \alpha \}) ) = \chi (\textrm{Lk}^\infty (\{f \le \alpha \}) ) \).

Proof

Let us study first the case when \(\alpha \) belongs to an interval of \({\mathbb {R}} \setminus \Lambda _f\) bounded from above. We can assume that \(0 \in \Lambda _f\) and that \(b<0\) is the greatest negative element of \(\Lambda _f\) (b can be \(-\infty \)).

Let \(\alpha \) be such that \(b<\alpha < 0\). We can find \(R_b \gg 1\) such that \(b<\frac{1}{2}+ \frac{1}{R_b^k}<0\). If \(\{x_n\}\subseteq \Gamma _{g_-,\rho }\) is a sequence such that \(b <g_-(x_n)\le \frac{1}{2}\alpha \), then \(\{g_-(x_n)\}\rightarrow b\). If \(\rho (x_n)\ge R_b\) then \(f(x_n)=g_-(x_n) + \frac{1}{\rho (x_n)^k}\le g_-(x_n)+\frac{1}{R_b^k}\le \frac{1}{2}\alpha + \frac{1}{R_b^k}<0\). Then, \(\{f(x_n)\}\) tend to b as well. As a consequence, there exists \(R_0\gg 1\) such that for all \(R\ge R_0\) and \(x\in {\widetilde{S}}_R\cap \Gamma _{g_-,\rho }\cap \{g_-\le \frac{1}{2}\alpha \}\), \(f(x)\le \frac{b+\alpha }{2}\) and \(g_-(x)\le \frac{b+\alpha }{2}\).

To conclude, we have that \({\text {Lk}}^{\infty }(\{g_-\le \alpha \})\) is homeomorphic to \(\{g_-\le \alpha \}\cap {\widetilde{S}}_R\), \({\text {Lk}}^{\infty }(\{f\le \alpha \})\) is homeomorphic to \(\{f\le \alpha \}\cap {\widetilde{S}}_R,\) and that

$$\begin{aligned} \{g_-\le \alpha \}\cap {\widetilde{S}}_R = \{f\le \alpha + \frac{1}{R^k}\}\cap {\widetilde{S}}_R \end{aligned}$$

is homeomorphic to \( \{f\le \alpha \}\cap {\widetilde{S}}_R,\) since \({\widetilde{S}}_R\cap \Gamma _{f,\rho }\cap \{\alpha \le f\le \alpha + \frac{1}{R^k}\}=\emptyset .\)

Similarly if \(\alpha \) belongs to the interval of \({\mathbb {R}} {\setminus } \Lambda _f\) not bounded from above, we can suppose that 0 is the biggest bifurcation value and that \(\alpha >0\). The proof is the same, replacing \(\{ g_- \le \frac{b+\alpha }{2}\}\) with \(\{ g_- \ge \frac{\alpha }{2} \}\) and taking R such that \(\alpha + \frac{1}{R^k} < 2 \alpha .\) \(\square \)

Let \(G_+(x) =f(x)+\frac{1}{\rho (x)^k}\) and let \(g_+={G_+}_{|X}\). Note that \(\Lambda _f = {\Lambda }_{g_+}\).

Lemma 5.6

For \(R \gg 1\), \(\chi ( \{ g_+ \ge d_i \} \cap {\tilde{S}}_R ) = \chi ( \{ f \ge d_i \} \cap {\tilde{S}}_R )\).

Corollary 5.7

We have \(\chi (\textrm{Lk}^\infty (\{g_+ \ge d_i \}) ) = \chi (\textrm{Lk}^\infty (\{f \ge d_i \}) ) \).

Lemma 5.8

Let \(\alpha \notin \Lambda _f\). We have \(\chi (\textrm{Lk}^\infty (\{g_+ \ge \alpha \}) ) = \chi (\textrm{Lk}^\infty (\{f \ge \alpha \}) ) \).

Lemma 5.9

The sets \((\nabla g_-)^{-1}(0) \) and \((\nabla g_+)^{-1}(0)\) are compact.

Proof

Let us suppose that \((\nabla {g_-})^{-1}(0)\) is not compact. Therefore, there exists \(\alpha \) a critical value of \(g_-\) such that \((\nabla {g_-})^{-1}(0)\cap g_-^{-1}(\alpha )\) is not compact. Then, there exists \(\{x_n\}\subset (\nabla {g_-})^{-1}(0)\cap g_-^{-1}(\alpha )\) such that \(\{x_n\}\rightarrow \infty \). Then \(\{f(x_n)\}\rightarrow \alpha \) and \(0=\nabla f(x_n) + \frac{k}{\rho ^{k+1}(x_n)}\nabla \rho (x_n)\). This implies that \(x_n\in \Gamma _{f,\rho }\setminus f^{-1}(\alpha ).\) Therefore \(\alpha \) is a bifurcation value of f and \(|f(x_n) - \alpha | = \frac{1}{\rho ^k(x_n)},\) which contradicts Lemma 5.1. \(\square \)

Corollary 5.10

We have

$$\begin{aligned} \int _{{\mathbb {R}}}\chi (\textrm{Lk}^\infty (\{g_- \le t\}) )d\chi _{c}(t) = \int _{{\mathbb {R}}} \chi (\textrm{Lk}^\infty (\{f \le t \}) )d\chi _c(t), \end{aligned}$$

and

$$\begin{aligned} \int _{{\mathbb {R}}}\chi (\textrm{Lk}^\infty (\{g_+ \ge t\}) )d\chi _{c}(t) = \int _{{\mathbb {R}}} \chi (\textrm{Lk}^\infty (\{f \ge t \}) )d\chi _c(t). \end{aligned}$$

We are in position to state the main theorem of this section.

Theorem 5.11

We have

$$\begin{aligned} \int _{{\mathbb {R}}}{\text {ind}}_g(f,X,f^{-1}(t))d\chi _c(t) = \int _{{\mathbb {R}}}{\text {ind}}_g(g_-,X,g_-^{-1}(t))d\chi _c(t), \end{aligned}$$

and

$$\begin{aligned} \int _{{\mathbb {R}}}{\text {ind}}_g(-f,X,f^{-1}(t))d\chi _c(t) = \int _{{\mathbb {R}}}{\text {ind}}_g(g_+,X,g_+^{-1}(t))d\chi _c(t). \end{aligned}$$

If \(X={\mathbb {R}}^n\), we have that

$$\begin{aligned} \int _{{\mathbb {R}}}{\text {ind}}_g(g_-,X,g_-^{-1}(t))d\chi _c(t)=\deg _{\infty }\nabla g_-, \end{aligned}$$

so

$$\begin{aligned} \int _{{\mathbb {R}}}{\text {ind}}_g(f,X,f^{-1}(t))d\chi _c(t)=\deg _{\infty }\nabla g_-. \end{aligned}$$

Moreover, if \(W_-\) is the vector field defined by \(W_-=\rho ^{k+1}\nabla f +\nabla \rho ,\) then \(\deg _{\infty }W_-=\deg _{\infty }\nabla g_-\) and so,

$$\begin{aligned} \int _{{\mathbb {R}}}{\text {ind}}_g(f,X,f^{-1}(t))d\chi _c(t)=\deg _{\infty }W_-. \end{aligned}$$

We can apply the same procedure to \(g_+\) and obtain a vector field \(W_+\). We note if f is a polynomial then \(W_-\) and \(W_+\) are polynomial vector fields.