2

I'm trying to construct a function that contains two parts: one, $g(a,b)$, coming into effect when $a\lt b$, and the other, $h(a,b)$, when $b \lt a$.

The problem is that $a=b$ is a valid possibility which I do not know how to handle, even though

if $a=b$, then $g(a,b)=h(a,b)$ and $g'(a,b)=h'(a,b)$.

So there is a real result at $a=b$, but I don't know how to get it out of the equation. there must be a mathematical way to properly express this.

currently I have

f(a,b) = $$\frac{(a-b)-\sqrt{(a-b)^2}}{2(a-b)}g(a,b) + \frac{\sqrt{(a-b)^2}+(a-b)}{2(a-b)}h(a,b).$$ which clearly doesn't cut it, because at $a=b$ the result is some weird specie of infinity.

And I am still working on figuring out $g(a,b)$ and $h(a,b)$, so I can't provide you with an example at this point.

So to recap: How do you join parts of functions into one continuous arithmetic function? (without input logic)

"you can'd do that" is a valid answer, but I'd like to know why.

user64742
  • 2,207
guest
  • 193
  • And you don't want to use a piecewise function? You want just a single expression? What kind of functions are you allowed to use? Any problem with $\max$ and $\min$? – Arturo Magidin Jul 24 '12 at 02:38
  • You are essentially looking for a formula such so that $$i(a,b)=\left{\begin{array}{ll}1 &\text{if }a\leq b\0&\text{if }a\gt b\end{array}\right.$$Then you can define your function as $i(a,b)g(a,b) + (1-i(a,b))h(a,b)$. But $i$ will not be continuous. – Arturo Magidin Jul 24 '12 at 02:43
  • @arturo (sqrt(pow((a-b),2))+(a-b))/(2*(a-b)) basically is a is greater b, but the inverse, or 1 - that isn't a greater than or equal b. but yes, i would be looking for something like that.

    and I mean I can use conditional statements, but i would 'like' a form that is universally portable, something you 'could' punch into a calculator, something that you could just copy from c++ and paste into haskell or calc.exe. I know plenty of ways to do it, but I'm asking the crowd for a universal solution, should one exist. If anyone (heh), you would know.

    – guest Jul 24 '12 at 04:37
  • @arturo in short, yea. – guest Jul 24 '12 at 04:41
  • also, what do you call these functional condition elements? (for googling) – guest Jul 24 '12 at 04:43
  • 1
    Functions defined that way are called "piecewise defined functions" (or "piece-wise") – Arturo Magidin Jul 24 '12 at 05:43
  • 2
    See http://math.stackexchange.com/questions/41444 and http://math.stackexchange.com/questions/58792. – joriki Jul 24 '12 at 06:43
  • so i have to accept the consensus that a discontinuity cannot be plugged. :( – guest Jul 24 '12 at 06:48
  • 2
    BTW: what @Arturo was doing in his second comment is in fact an instance of the so-called Iverson bracket, but in slightly different notation. Raymond, in his answer, tells you how you can express your Iverson bracket in terms of the unit step or sign functions. – J. M. ain't a mathematician Jul 24 '12 at 10:34

2 Answers2

7

Consider the Heaviside step function defined this way (other variants for $H(0)$ exist) :

$$ H(x)=\begin{cases} x<0&\ 0\\[8pt] x=0&\frac 12\\[8pt] x>0&\ 1\\[8pt] \end{cases} $$

(you may too write $H$ as a $\rm{sign}$ function : $\ H(x)=\dfrac {1+\rm{sign}(x)}2$) then :

$$\boxed{\displaystyle f(a,b)= g(a,b)\cdot H(b-a)+ h(a,b)\cdot H(a-b)}$$

(with value $\dfrac{g(a,a)+h(a,a)}2$ for $a=b$ of course)

To get a 'smoothed' result you may replace $H$ by a Sigmoid function : $\ \displaystyle S(x)=\frac 1{1+e^{-x}}\ $ or other variants.

Since $\ H(x)=\lim_{n->\infty} S(n\cdot x)\ $ you may replace $H(x)$ by something like $S(n\cdot x)$ with any $n \gg 1$ to get a smooth transition!

Let's illustrate this with an example : $x\mapsto x^2$ for negative $x$ and $x\mapsto \cos(10 x)$ for positive $x$ illustrated with $n=1000$ and $n=100$ :

f(t)=t^2/(1+exp(1000*t))+cos(10*t)/(1+exp(-1000*t)

n=1000

f(t)=t^2/(1+exp(100*t))+cos(10*t)/(1+exp(-100*t)

n=100

Hoping it helped,

Raymond Manzoni
  • 43,021
  • 5
  • 86
  • 140
  • 2
    that's pretty darn badass dude. it's not perfect but i can adapt. many thanks. – guest Jul 24 '12 at 19:52
  • @user35945: glad it helped! One of the possible problems is exponential overflow or underflow (i.e. the resulting function should be tested for the minimal an maximal value allowed). – Raymond Manzoni Jul 24 '12 at 20:40
1

If it is acceptable for you to write $$g(a,b)=u\left(\frac{a+b}{2}\right)+(b-a)\cdot g_*(a,b)\\ h(a,b)=u\left(\frac{a+b}{2}\right)+(b-a)\cdot h_*(a,b)$$ then you can write $$f(a,b)=u\left(\frac{a+b}{2}\right)+\frac{(b-a)-|b-a|}{2}\cdot g_*(a,b)+\frac{(b-a)+|b-a|}{2}\cdot h_*(a,b)$$


On the other hand, if you have to consider $g,h$ as opaque functions, it is impossible to find continuous $\varphi,\psi$ such that $$f(a,b)=\varphi(a,b)g(a,b)+\psi(a,b)h(a,b)$$ (this is because necessarily $\varphi(a,b)=1$ when $a<b$ and $0$ when $a>b$, creating a discontinuity).

In particular, if $\varphi,\psi$ are constructed from constants, the variables $a,b$, operators like $+,-,\times,/$ and continuous functions like $\exp,\log,\sin,\cos,\tan,\sqrt{\cdot},|\cdot|$ (paying attention to their domain of definition), then they are necessarily continuous.