# How to create this algebraic equation encoding basic choice?

Given 2 non negative, ordered real variables $$x, y$$ such that we know:

1. $$x\geqslant y$$
2. $$x - y = d$$
3. $$x+y=1$$

Given another variable $$k$$ such that either:

1. $$k=0$$ or
2. $$k=d^2-d$$

The objective is to construct a single algebraic equation such that:

1. The equation outputs $$d$$ when value of $$k$$ is non zero i.e. $$k=d^2-d$$.
2. It outputs 0 when $$k$$ is 0.

Essentially we are trying to encode a logical constraint in a simple mathematical equation. The simple approach is to take $$d^2-d$$ or 0 as the constant and solve the quadratic equation $$x^2-x=k$$ but it will give 2 results in each case:

1. $$d$$ and $$1-d$$
2. 0 and 1

How do we enforce the logic/selection using basic mathematical operations [+, - , *, /, abs()]. We are not allowed to use any logical operations or operations that internally use logic or require if/else kind of tests at any level as that defeats the original purpose and makes the problem trivial.

• Are $x$ and $y$ the inputs of the expression you seek? Jul 17, 2021 at 16:32
• The operations you want to restrict yourself to are all continuous (in their various domains), and therefore it is impossible to use them to build the discontinuous function you have defined (namely, when $k=d^2-d$ you want $0$ for $y=0$ but $1-2y$ when $y>0$. If you're willing to divulge more about the "original purposes" that would "defeated" by other mechanisms is, it might be possible to point you in a useful direction, though. Jul 17, 2021 at 16:38