Write logical operator all(x<a) in terms of Heavyside functions
I am currently solving a complex optimisation problem, with constraints that take the form: $1 - all(g(x)<a) <= 0$, meaning I require all values $g(x)$ (for some function $g$) to be below some threshold, given a vector $x$.
I have been told that logical operator all() can be re-written in terms of heavy-side functions, and then we can use some approximation of the heavy-side function to attain a differentiable constraint, as well as write down its gradient to help speed up optimisation. My problem comines in that I do not see how one can re-write all() in terms of a heavy-side function. Can anyone provide insight into this?
Let's have $H_0\ :\begin{cases}0 & x<0 \\ 1 & x\ge 0\end{cases}$
Note: it can also be calculated from the floor function as $$H_0(x)=\dfrac 12\left(1+\dfrac{\lfloor\frac{x+1}{|x|+1}\rfloor-\frac 14}{|\lfloor\frac{x+1}{|x|+1}\rfloor-\frac 14|}\right)$$
An alternative definition still using $\sqrt{x^2}=|x|$ but where the discontinuity is involving $0^{|x|}$ (assuming $0^0=1$, pow() function acts like that for instance in many languages) instead of $\lfloor x\rfloor$ could be $$H_0(x)=\dfrac 12\left(1+\dfrac{|x|+0^{|x|}}{x+0^{|x|}}\right)$$
Then you can define the translated functions:
$H_a(x)=H_0(x-a)\ :\begin{cases}0 & x<a \\ 1 & x\ge a\end{cases}\quad$ and $\quad G_a(x)=H_0(a-x)\ :\begin{cases}1 & x\le a \\ 0 & x> a\end{cases}$
And then all the characteristic functions for intervals:
$\begin{align} \delta_a(x) &= H_a(x)G_a(x)\\ 1_{[a,+\infty)}(x) &= H_a(x)\\ 1_{(a,+\infty)}(x) &= 1 - G_a(x)\\ 1_{(-\infty,b]}(x) &= G_b(x)\\ 1_{(-\infty,b)}(x) &= 1 - H_b(x)\\ 1_{[a,b]}(x) &= H_a(x) + G_b(x) - 1\\ 1_{(a,b)}(x) &= 1 - G_a(x) + H_b(x)\\ 1_{[a,b)}(x) &= H_a(x) - H_b(x)\\ 1_{(a,b]}(x) &= G_b(x) - G_a(x)\end{align}$
Regarding your problem, you are interested in $g(x)<a$ which thus involves $1_{(-\infty,a)}(g(x))$.
But this has only $0,1$ values, we need to multiply by $g(x)$ itself to get back the values of $g$ and do the comparison $1-g(x)\le 0$
So we have now $1_{(-\infty,a)}(g(x))\times(1-g(x))\le 0$ and when $g(x)\ge a$ you can notice that the indicator function is $0$ which also respects the condition $0\le 0$.
Rewriting in terms of $H_0$ only you get the condition $$\big(1-H_0(g(x)-a)\big)\big(1-g(x)\big)\le 0$$