*Note: We define the signum function, $\text{sgn}$ by $\text{sgn}(x) = 1$ if $x \geq 0$, and $-1$ otherwise.*


Suppose $f: [0, \infty) \to \mathbb R$ is continuous and of locally bounded variation, with $f(0) = 0$. Is it true that the integral


$$\int\_0^t f \, d\, \text{sgn(f)} := f(t) \, \text{sgn}(f(t)) - \int\_0^t \text{sgn} (f(s)) \, df(s)$$


$$= \lvert f(t) \rvert - \int\_0^t \text{sgn} (f(s)) \, df(s)$$
vanishes for all $t \geq 0?$


*Remark: Note that the RHS is a definition for the LHS! The integral on the RHS is to be interpreted as a regular Lebesgue Stiltjes integral.*



On a certain deterministic integral related to Tanaka’s formula
$\newcommand\sgn{\operatorname{sgn}}$Yes, this is true. Indeed, fix any real $t>0$. Let
\begin{equation}
 S\_+:=\{s\in(0,t)\colon f(s)\ge0\},\quad S\_-:=\{s\in(0,t)\colon f(s)<0\}. 
\end{equation}
Then
\begin{equation}
 I:=\int\_0^t\sgn(f(s))\,df(s)=I\_+ - I\_-,
\end{equation}
where
\begin{equation}
 I\_-:=\int\_{S\_-}df(s),
\end{equation}
\begin{equation}
 I\_+:=\int\_{S\_+}df(s)=\int\_0^1 df(s)-\int\_{S\_-}df(s)=f(t)-I\_-, 
\end{equation}  

so that
\begin{equation}
 I=f(t) - 2I\_-. 
\end{equation}
Since $f$ is continuous, the set $S\_-$ is open, so that $S\_-$ is the union of at most countably many disjoint nonempty open intervals. If the right endpoint of one of those intervals is $t$, let us write that interval as $(a,t)$, with $a\in[0,t)$. If the right endpoint of none of those intervals is $t$, let us use the empty interval $(a,t)$ with $a=t$.
So,  

\begin{equation}
 S\_-=(a,t)\cup\bigcup\_{j\in J}(a\_j,b\_j),
\end{equation}
where $J$ is an at most countable set, $0\le a\_j<b\_j\le a\le t$ and $b\_j<t$ for all $j\in J$ and the intervals $(a\_j,b\_j)$ are pairwise disjoint.


If $f(t)>0$, then $a=t$ by the continuity of $f$, and hence $\int\_{(a,t)}df(s)=0=f(t)\,1(f(t)\le0)$.


If $f(t)\le0$ and $a=t$, then $f(t)=0$ by the continuity of $f$, and hence $\int\_{(a,t)}df(s)=0=f(t)\,1(f(t)\le0)$.


If $f(t)\le0$ and $a<t$, then $f(a)=0$ by the continuity of $f$,
and hence $\int\_{(a,t)}df(s)=f(t)-f(a)=f(t)=f(t)\,1(f(t)\le0)$.


So, in any case,
\begin{equation}
 \int\_{(a,t)}df(s)=f(t)\,1(f(t)\le0). 
\end{equation}


Also, by the continuity of $f$, we have $\int\_{(a\_j,b\_j)}df(s)=f(b\_j)-f(a\_j)=0-0$ for all $j\in J$.


So,
\begin{equation}
 I\_-=\int\_{(a,t)}df(s)+\sum\_{j\in J}\int\_{(a\_j,b\_j)}df(s)=f(t)\,1(f(t)\le0). 
\end{equation}
Thus,
\begin{equation}
 I=f(t) - 2I\_-=f(t) - 2f(t)\,1(f(t)\le0)=|f(t)|,
\end{equation}
as claimed.


