if $h$ is twice differentiable, what is the largest set on which $|h|$ is twice differentiable? Let $h:\mathbb R\to\mathbb R$ be twice differentiable.

What is the largest set on which $|h|$ is twice differentiable?

By the chain rule, $|h|$ is differentiable at $a$ with $$|h|'(a)=h'(a)\operatorname{sgn}h(a)\tag1$$ for all $a\in\{h\ne0\}$. Moreover, if $a\in\{h'=0\}$, then $$\left|\frac{|h|(a+t)-|h|(a)}t\right|\le\left|\frac{h(a+t)-h(a)}t\right|\xrightarrow{t\to0}0\tag2$$ by the reverse triangle inequaly and hence $|h|$ is differentiable at $a$ with $$|h|'(a)=0=h'(a)\operatorname{sgn}h(a)\tag3.$$

So, $|h|$ is differentiable at least on $D_1:=\{h\ne0\}\cup\{h'=0\}$ with derivative $h'\operatorname{sgn}h$. (Can we enlarge $D_1$?)

Turning to the second derivative: Using that $\operatorname{sgn}h$ is differentiable at $a$ with $$(\operatorname{sgn}h)'(a)=0\tag4$$ for all $a\in\{h\ne0\}\cup\{h=0\}^\circ$, we obtain (by the chain rule, again) that $|h|$ is twice differentiable at $a$ with $$|h|''(a)=h''(a)\operatorname{sgn}h(a)\tag5$$ for all $a\in D_2:=\{h\ne0\}\cup\{h=0\}^\circ$ (noting that $\{h=0\}^\circ\subseteq\{h'=0\}$).

So, $|h|'$ is differentiable at least on $D_2$. Can we enlarge $D_2$?

On the other hand, we can show that $|h|'$ is differentiable at $a$ with $$|h|''(a)=|h''(a)|$$ for all $$a\in D_3:=\{h=0\}\cap\{h'=0\}\cap(\{h''\ne0\}\cup\{h''=0\}\cap D_1^\circ).$$ However, I'm struggling to see how $D_2$ and $D_3$ are related and hence whether the latter yields an enlargement of $D_2$.
EDIT: And as a third option, it's possible to show that $|h|$ is twice differentiable on $D_4:=\mathbb R\setminus\overline{N'}$, where $N':=\left\{a\in\mathbb R:a\text{ is an isolated point of }\left\{h=0\right\}\right\}$; see revision 3 of this answer (and the comments below): https://math.stackexchange.com/a/3210082/47771.
I'm really struggling to see which result is the strongest.
 A: Can we enlarge $D_1$? That is, can $|h|'(a)$ exist at points $a$ where $h(a)=0$ and $h'(a)\ne 0$? From $h(a)=0$ and $h'(a)\ne 0$, it follows that for $\epsilon>0$ small enough, we have $h(x)>0$ on $(a,a+\epsilon)$ and $h(x)<0$ on $(a-\epsilon,a)$ or vice versa. It follows that the one-sided limit of $\frac{h(x)-h(a)}{x-a}$ is $h'(a)$ on one side and $-h'(a)$ on the other, hence $|h|'(a)$ cannot exist.
Can we enlarge $D_2, D_3, D_4$?
We can show


*

*$|h|''(x)=\operatorname{sgn}(h(x))h''(x)$ on $\{h\ne0\}$

*$|h|''(x)=|h''(x)|$ on $\{h=0\}\cap \{h'=0\}\cap \{h''\ne 0\}$

*$|h|''(x)=0$ on $(\{h=0\}\cap\{h'=0\}\cap\{h''=0\})\setminus \overline{\{h=0\}\cap\{h'\ne0\}}$
The union of these cases is the maximal set where $|h|''$. This follows because on $\{h=0\}\cap\{h'\ne 0\}$ not even $|h|'$ exists and the definition of derivative of a function at a point requires the function to be defined in an open neighbourhood of that point. If we loosen the usual definition of $f'$ to taking only the limit of $\frac{f(x+h)-f(x)}{h} $ where $x+h$ happens to be in the domain of $f$ and that $x$ is not an isolated point of the domain, then we can replace the third bullet point above with 


*

*$|h|''(x)=0$ on $\{h=0\}\cap\{h'=0\}\cap\{h''=0\}.$
