Lee's Smooth Manifolds Problem 5-22. Proving Theorem 5.48 on the existence of defining function for regular domains I am really struggling and have spent hours proving this theorem so I would greatly appreciate some help. I think I have nearly proved the theorem except for showing that $f^{-1}(-\infty,0]$ is a regular sublevel set of $f$. 
My attempt so far is this : Let $\mathscr{U}= \{(U_p,\phi_p)\}_{p \in D}$ be a collection of interior or boundary slice charts for $D$ in $M$. Then $\mathscr{U} \cap \{M \backslash D\}$ covers $M$. Now take the partition of unity $\{\psi_\alpha\}$ subordinate to this cover and we can construct functions $\{f_p \}_{p \in D} \cup \{f_0\}$ as follows : Given $p \in Int D$, take an interior slice chart $U_p$ and $f_p \equiv -1$, and extend $\psi_p f_p$ to $0$ on $M \backslash supp \psi_p$. Given $p \in \partial D$, take a boundary slice chart $U_p$ and $f_p(x^1,\dots ,x^n ) =-x^n$ on $U_p$. And extend $\psi_p f_p $ to $0$ outside of the support of $\psi_p$. 
Define $f := \sum_\alpha \psi_\alpha f_\alpha$. Then $f$ is smooth and since if $p \in D$, we have $f_\alpha (p) = -1$ or $f_\alpha(p) \le 0$, and $\psi_0(p)=0$, we get $f(p) \le 0$. 
We show that $D = f^{-1}((-\infty, 0])$. 
Finally if $p \notin D$, then $f_0\equiv1$. Note that we can restrict the interior domains $U_p$ to $U_p \cap Int D$. Here, from Proposition 5.46 in the text, the topological interior and manifold interior of a regular domain $D$ are the same so $U_p$ remains open in $M$ and we get $U_p \cap (M \backslash D) = \emptyset$. Hence for all $p \in M \backslash D$, $\psi_\alpha(p)=0$ if $\alpha$ belongs to an interior domain. 
Hence for $p \notin D$, $\psi_\alpha f_\alpha (p)=0$ for $\alpha$ belonging to the interior domain and $f_\alpha (p)>0$ for $\alpha$ belonging to boundary domain since $p \in U_\alpha \cap D^c = \{(x^1, \dots, x^n ) \in U: x^n < 0\}$ by definition of slice boundary chart. 
Therefore, we have $f(p)=\sum_{\alpha \in \text{Boundary} \cup \{0\}} \psi_\alpha f_\alpha(p) \ge 0$, and indeed it is positive since if $f(p)=0$ then we would have $\psi_0(p)=0$ and $\psi_\alpha(p)=0$ for all $\alpha \in \text{Boundary}$, so $\sum_\beta \psi_\beta (p)=1$, for $\beta \in \text{Interior}$. But interior charts were chosen so that $\psi_\beta(p)=0$ if $p \notin D$. Hence we have $D= f^{-1}(-\infty,0]$. 
Finally, we need to conclude the proof by showing that $0$ is a regular value of $f$. This follows from Proposition 5.47 which states that for each regular value $b$ of $f$, $f^{-1}(-\infty , b]$ is a regular domain. 
However, this I cannot show. And how may we extend this to an exhaustion function if $D$ is compact?

 A: The fact that $0$ is a regular value of $f$ follows from the formula given in Lee's Smooth Manifolds, p.119, l.5.
The case when $D$ is compact:
By Lee's Smooth Manifolds, p.46, Proposition 2.28, we may obtain an exhausting function  $f^0\ge 1$ for the open submanifold $M\setminus D$. Then replace $f_0$ with $f^0$. If one checks the proofs of the results for the old $f$ when $D$ is not restricted to the compact case, one will find these proofs remain valid for the new $f$ when $D$ is compact except that trivial changes are required.
A: *

*We choose a cover of N by:  a) Coordinate balls  U  contained in $ \text{Int}D $ or $ N\setminus D $ and denote its coordinate chart is $ \phi $.
b) Coordinate balls  B  centering at some point in $ \partial D $ such that there exists a chart $ \phi: B\to \mathbb{R}^n,\,$
$$ \phi(B\cap D) = \{ (x^{1},...,x^{n-1}, x^{n})\in \phi(B), x^{n}\le 0 \} $$
These open sets compose an open cover $ \mathcal{U} = \{ U_\alpha \} $ of $ N $ and denote $ \{ \psi_\alpha \} $ be the partition of unity subordinate to $ \mathcal{U} $.


*Then we define the coefficient functions $ \chi_\alpha: U_\alpha\to \mathbb{R} $
$$ \chi_\alpha(x) = \begin{cases}
    1 & \text{ if $ U_\alpha $ is contained in $ N\setminus D $}\\
    -1 & \text{ if $ U_\alpha $ is contained in Int$ D $}\\
    \pi_n\circ \phi_\alpha(x) & \text{ if $ U_\alpha $ is a coordinate ball intersecting $ \partial D $}\\
    \end{cases} $$
where $ \phi_\alpha $ is the special (n-1)-slice chart we mensioned before and $ \pi_n(x^{1},...,x^{n-1}, x^{n}) = x^{n} $ is the standard projection. Clearly $ \chi_\alpha $ is smooth on $ B_\alpha $.


*Then we define the defining map of $ D $, $ f:N\to \mathbb{R} $
$$ f(x) = \sum_{\alpha} \chi_\alpha(x)\cdot \psi_\alpha(x) $$
Then $ f $ is smooth for the support of $ \{\psi_\alpha \} $ is locally finite and each term $ \chi_\alpha(x)\cdot \psi_\alpha(x) $ is smooth at $ U_\alpha $.
Also due to being locally finite, for any point $ p\in \text{Int}D $, $ f(p) < 0 $ because its potential coefficient functions $ \chi_\alpha(p) < 0 $ and $ \sum_{\alpha}\psi_\alpha \equiv 1 $. Similar case as $ f(p) > 0 $ happens when $ p\in N\setminus D $.
Moreover, for each point $ p\in \partial D $, if an open set $ U_{\alpha'} $ contains $ p $, $ U_{\alpha'} $ must be an element in B-sets which we mensioned in step 1. Thus the corresponding coefficient $ \chi_{\alpha'}(p) \equiv 0 $ hence
$$ f(p) = \sum_{\alpha} \chi_\alpha(p)\cdot \psi_\alpha(p) = \sum_{\alpha'}\chi_{\alpha'} (p)\cdot \psi_{\alpha'}(p) = 0 $$
Hence $ f|_{D} = 0 $, $ f|_{\text{Int}D} <0 $ and $ f|_{N\setminus D} >0 $.


*If $ p\in \partial D $, $ df(p)\ne 0 $ because $ df(p) = d\left( \sum_{\alpha'}\chi_{\alpha'} \cdot \psi_{\alpha'} \right)(p) $
$$ = \sum_{\alpha'}d\chi_{\alpha'}(p)\cdot \psi_{\alpha'}(p) + \sum_{\alpha'}\chi_{\alpha'}(p)\cdot d\psi_{\alpha'}(p) = \sum_{\alpha'}d\chi_{\alpha'}(p)\cdot \psi_{\alpha'}(p) $$
Notice that there must be some $ \alpha'' $ such that $ \psi_{\alpha''}(p) > 0 $ and given a vector $ v\in T_pM $, each term like $ d\chi_{\alpha'}(p)v\cdot \psi_{\alpha'}(p) $ is nonnegative. For each $ \alpha' $ there exists a coordinate representation of $ d\chi_{\alpha'}(p) $ such that $ D{\chi}_{\alpha'}(*) \equiv (0,0,...,0,1)  $. Thus there must exists a vector $ v\in T_pM $ such that $ d{\chi}_{\alpha}(p)v\cdot \psi_{\alpha}(p) > 0 $. Therefore $ df(p)> 0 $, and $ 0 $ is a regular value of $ f $.


*As for the compact cases, we can find finite coordinate balls $ \{U_k\}_{k=1}^{s} $ covering $ D $ in the preceeding steps and countable open sets $ \{U_k\}_{k=s+1}^{\infty} $ that covers $ N\setminus D $. We define the exaustion function as
$$ f(x) = \sum_{k=1}^{s}\chi_k(x)\cdot \psi_k(x) + \sum_{k=s+1}^{\infty} k\cdot \chi_{k}(x)\cdot \psi_k(x) $$
Similar discussion can be found to proof $ f $ is a desired exaustion function (Details: GTM218: p.46, Proposition 2.28).
