Find Formulas of Absolute and "Ray" Functions $$y = \begin{cases} 0, & \text{if } x < 0, \\ 2x, & \text{if } x \geq 0. \end{cases}$$
How can we represent the above function in one formula?
I'm not exactly sure how to tackle this sort of question. (This is not homework.) It comes from Functions and Graphs by I. M. Gelfand on page 32. On the face of it, it's an easy question that should have an easy answer. Yet my math intuition skills need a lot of work. (Hopefully this book will help!) 
To solve this, is there a general method to work backwards from these two "rays" to an absolute value function?
Likewise, turning to page 33 to investigate another problem:
$$y = \begin{cases} 2x + 1, & \text{if } x \geq 0, \\ \frac{1}{2}x + 1, & \text{if } x \leq 0. \end{cases}$$
For example, $|2x+1|-|\frac{1}{2}x+1|$ clearly can't work as the formula. Besides guessing and attempting all sorts of possible formulas to the end of time, how can we look at this systematically?
Thank you so much for your time and patients!

$y = max(0,2x) = \frac{1}{2}(|2x| + 2x) = |x| + x$
More generally, suppose you had $y = ax, x > 0$, and $y = bx$, $x<0$.  Consider the generic function $y = c|x| - dx$.  Then for $x > 0$, $y = cx - dx$, and for $x < 0$, $y = -cx - dx$.  So you want to choose $c$ and $d$ to solve $c - d = a$, and $-c - d = b$.  From this you can work out the general form of $c$ and $d$.
