0
$\begingroup$

Is there a way to rewrite these two equations into one equation that would work in both scenarios?

If $x > y$, then the equation is: $$z = \frac{x - y}{1 - y}.$$

If $x < y$, then the equation is: $$z = 1 - \frac{y - x}{y}.$$

$\endgroup$
  • 1
    $\begingroup$ The second is just z=x/y $\endgroup$ – Ross Millikan Jun 18 '11 at 2:31
  • $\begingroup$ Why do you want to? In any case, $z$ is not continuous in $x$ and $y$, so the combined expression would be not be very nice (no offence to Yuval). $\endgroup$ – Rahul Jun 18 '11 at 4:44
7
$\begingroup$

There are at least two ways to do that. One way is to use an "if" construct: $$ z = \begin{cases} (x-y)/(1-y) & x > y, \\ x/y & x < y. \end{cases} $$ But that's like cheating.

The second way is using absolute values to implement the conditional "honestly": $$\frac{|x-y|+x-y}{2|x-y|} \cdot \frac{x-y}{1-y} + \frac{|x-y|+y-x}{2|x-y|} \cdot \frac{x}{y}. $$ You can simplify that if you want by taking common factors, to get $$ \frac{1}{2} \left( \frac{x-y}{1-y} + \frac{x}{y} \right) + \frac{x-y}{2|x-y|} \left( \frac{x-y}{1-y} - \frac{x}{y} \right). $$

$\endgroup$
  • 1
    $\begingroup$ Haha, +1 for not cheating, @Yuval. $\endgroup$ – Jack Henahan Jun 18 '11 at 2:47
2
$\begingroup$

This is to expand Yuval's answer so you may understand the idea and tackle it in general.

You need to express the cases in a single equation, in other words you need to find $$z = f(x,y)\; \frac{x - y}{1 - y} + g(x,y)\; \frac{x}{y}$$

Where the properties of $f$ and $g$ are

$$ f(x,y)= \begin{cases} 1 & x > y \\\\ 0 & x < y \end{cases} \quad \mbox{and} \quad g(x,y)= \begin{cases} 0 & x > y \\\\ 1 & x < y \end{cases} $$

It is pretty easy to find $f$ and $g$ out for yourself. For example, if $x\neq y$ then

$$f(x,y) = \theta(x-y)$$ $$g(x,y) = \theta(y-x)$$

Where $\theta(x)$ is the Heaviside theta function. To express it completely algebraically, $\theta(x)$ can be expressed in terms of $sgn(x)$ which can be expressed as $\frac{x}{|x|}$ for $x\neq 0$. So the theta function can be written as ($x\neq y$)$$\theta(z) = \frac{z+|z|}{2|z|}$$

$\endgroup$
0
$\begingroup$

I suppose the easiest way would be a piecewise function:

$$ z= \begin{cases} \frac{x-y}{1-y} & x > y \\\\ \frac{x}{y} & x < y \end{cases} $$

Unless you mean you'd like a single function which would satisfy both conditions, in which case Yuval's got you covered.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.