Is there a standard way to deal with rounding in algebra? For example:
y = x + round(x/2)
Would give 2 when x = [1, 3), 3 when x = [3, 5), etc. This of course ends up creating a step function. EDIT: the function is injective, see the comments.
Is there a standard math-y way to represent the above equation, and is it possible to solve for x in terms of y?
For context, I need to know the value of y
above, as well as round(x/2)
, both as integers. I'm currently using algebra.js to simplify my expressions, so extra bonus points for showing me how I might implement rounding using that library.
Answer
Edit because the OP keeps changing the question.
The answer below applies to the function
$$
y = 1 + \text{round}(x/2)
$$
which the OP says in a comment is what he meant to ask.
The original question asked about
$$
y = x + \text{round}(x/2)
$$
which is indeed injective and can be inverted, as @EeveeTrainer has commented.
You can't solve for integer $x$ in terms of integer $y$ since two values of $x$ give the same value of $y$.
If $x$ must be an integer then in a computer program you can write the function that computes $y$ from $x$ by looking at whether $x$ is even or odd and acting accordingly. You don't need rounding. For arbitrary $x$ you do need the round
function.
No comments:
Post a Comment