# Smooth function that vanishes only on unit cube

I am having hard time defining a smooth function $$f:\Bbb R^3 \to \Bbb R$$ such that :

$$f(x,y,z) = 0$$ if and only if $$(x,y,z)$$ belongs to the unit cube $$[0,1]^3$$.

I tried generalizing the case of $$f:\Bbb R\to \Bbb R$$, such that $$f$$ vanishes only on $$[0,1]$$ but failed in the process.

I would really appreciate any help, Thanks in advance!

If $$f:\Bbb R\to \Bbb R$$ is a smooth function such that $$f(x)=0\iff x\in[0,1]$$ then the map $$g:\Bbb R^3\to \Bbb R$$ defined by $$g(x,y,z)=f(x)^2+f(y)^2+f(z)^2$$ is smooth and has the property that $$g(x,y,z)=0\iff f(x)=f(y)=f(z)=0\iff 0\leq x,y,z\leq 1,$$ so you just have to do the case $$f:\Bbb R\to \Bbb R$$.