  Let $(\mathcal{X}, \rho, \mu)$ be a metric measure space of homogeneous type
which supports a certain Poincar\'e inequality. Denote by the symbol
$\mathcal{C}_{\mathrm{c}}^\ast(\mathcal{X})$ the space of all continuous
functions $f$ with compact support satisfying that $\operatorname{Lip}
f:=\limsup _{r \rightarrow 0} \sup_{y\in B(\cdot, r)} |f(\cdot)-f(y)|/r$ is
also a continuous function with compact support and $\operatorname{Lip} f=\lim
_{r \rightarrow 0} \sup_{y\in B(\cdot, r)} |f(\cdot)-f(y)|/r$ converges
uniformly. Let $p \in[1,\infty)$. In this article, the authors prove that, for
any $f\in\mathcal{C}_{\mathrm{c}}^\ast(\mathcal{X})$, \begin{align*}
&\sup_{\lambda\in(0,\infty)}\lambda^p\int_{\mathcal{X}} \mu\left(\left\{y\in
\mathcal{X}:\ |f(x)-f(y)|>\lambda \rho(x,y) [V(x,y)]^{\frac
1p}\right\}\right)\, d\mu(x)\\ &\quad\sim \int_{{\mathcal{X}}}
[\operatorname{Lip}f(x)]^p \,d\mu(x) \end{align*} with the positive equivalence
constants independent of $f$, where $V(x,y):=\mu(B(x,\rho(x,y)))$. This
generalizes a recent surprising formula of H. Brezis, J. Van Schaftingen, and
P.-L. Yung from the $n$-dimensional Euclidean space ${\mathbb R}^n$ to
$\mathcal{X}$. Applying this generalization, the authors establish new
fractional Sobolev and Gagliardo--Nirenberg inequalities in $\mathcal{X}$. All
these results have a wide range of applications. Particularly, when applied to
two concrete examples, namely, ${\mathbb R}^n$ with weighted Lebesgue measure
and the complete $n$-dimensional Riemannian manifold with non-negative Ricci
curvature, all these results are new. The proofs of these results strongly
depend on the geometrical relation of differences and derivatives in the metric
measure space and the Poincar\'e inequality.
