How can $|n_1 - n_2| + |n_3 - n_4|$ be equal two different formulas I have a formula to be calculated such as;
$|n_1 - n_2| + |n_3 - n_4|$. I want to calculate it with two tuples of values such as;
$(n_1,n_2)$ and $(n_3,n_4)$
When I try this method, it is equivalent;
$$|310-111| + |440-342| = (310 + 440) - (111 + 342)$$
When I try this method, it is also equivalent but this method won't work with above equation;
$$|111 - 309| + |342 - 207| = (342 - 111) + (309 - 207)$$
What is the problem here, where am I thinking wrong? Thanks in advance...
 A: $|n_1-n_2|+|n_3-n_4|=(n_1+n_3)-(n_2+n_4)$ is true if $n_1\geq n_2$ and $n_3\geq n_4$. Only then, you can get rid of the absolute value signs (because $|x|=x\iff x\geq 0$).
A: $$|x| = \begin{cases} x & x\geq0\\ -x & x< 0 \end{cases}$$
So if $x\geq 0$ you can think of $|x|$ as $x$ as you did with the first equation.
However you can't do that with the second equation because $111-309$ is negative.
A: The issue, here, is that you're ordering your tuple, and using the given order as if it is important in some way. We can instead see that $$|310-111|+|440-342|=(440-111)+(310-342).$$
As for why this is the case, it is because $|x|=-x$ when $x$ is negative, and $|x|=x$ otherwise. So, we have: $$|310-111|=310-111\\|440-342|=440-342\\|111-309|=-(111-309)=-111+309=309-111\\|342-207|=342-207.$$ From the above, we can regroup (by commutativity, distributivity, and associativity), once we've removed the absolute value bars.
Since you seem to be looking for a general formula, here's one way we can go.
Observe that, regardless of $x,y$ we will necessarily have $|x-y|=\max(x,y)-\min(x,y).$ In the case that $x=y,$ this is easy to prove. In the case that $x>y,$ we know that $x-y>0,$ so that it's again easy to prove. In the case that $x<y,$ the third example above illustrates how we can prove it.
Given that, we have for any $n_1,n_2,n_3,n_4$ that $$|n_1-n_2|+|n_3-n_4|=\bigl(\max(n_1,n_2)-\min(n_1,n_2)\bigr)+\bigl(\max(n_3,n_4)-\min(n_3,n_4)\bigr),$$ or equivalently, $$|n_1-n_2|+|n_3-n_4|=\bigl(\max(n_1,n_2)+-\min(n_1,n_2)\bigr)+\bigl(\max(n_3,n_4)+-\min(n_3,n_4)\bigr).$$
At this point, we could use associativity to drop the parentheses, then use commutativity to obtain $$|n_1-n_2|+|n_3-n_4|=\max(n_1,n_2)+\max(n_3,n_4)+-\min(n_1,n_2)+-\min(n_3,n_4).$$ Now we can use distributivity (together with the identity $-x=-1\cdot x$ to see that
\begin{eqnarray}|n_1-n_2|+|n_3-n_4| &=& \max(n_1,n_2)+\max(n_3,n_4)+-1\cdot\min(n_1,n_2)+-1\cdot\min(n_3,n_4)\\ &=& \max(n_1,n_2)+\max(n_3,n_4)+-1\cdot\bigl(\min(n_1,n_2)+\min(n_3,n_4)\bigr)\\ &=& \max(n_1,n_2)+\max(n_3,n_4)+-\bigl(\min(n_1,n_2)+\min(n_3,n_4)\bigr)\\ &=& \bigl(\max(n_1,n_2)+\max(n_3,n_4)\bigr)-\bigl(\min(n_1,n_2)+\min(n_3,n_4)\bigr)\end{eqnarray}
This certainly isn't the only way we could formulate it, but it gets the job done.
