<?xml version="1.0" encoding="UTF-8" standalone="yes"?><oembed><version><![CDATA[1.0]]></version><provider_name><![CDATA[The ryg blog]]></provider_name><provider_url><![CDATA[https://fgiesen.wordpress.com]]></provider_url><author_name><![CDATA[fgiesen]]></author_name><author_url><![CDATA[https://fgiesen.wordpress.com/author/fgiesen/]]></author_url><title><![CDATA[Symmetry]]></title><type><![CDATA[link]]></type><html><![CDATA[<p>As a general rule, when trying to understand or prove something, symmetry is a big help. If something has obvious symmetries, or can be brought into a symmetric form, doing so is usually worth trying. One example of this is my old <a href="https://fgiesen.wordpress.com/2009/12/15/dxt5-alpha-block-index-determination/">post on index determination for DXT5/BC3 alpha blocks</a>. But a while ago I ran into something that makes for a really nice example: consider the expression</p>
<p><img src="https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|a + b| + |a - b|" class="latex" /></p>
<p>If these were regular parentheses, this would simply evaluate to <img src="https://s0.wp.com/latex.php?latex=2a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=2a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=2a&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="2a" class="latex" />, but we&#8217;re taking absolute values here, so it&#8217;s a bit more complicated than that. However, the expression does look pretty symmetric, so let&#8217;s see if we can do something with that. Name and conquer, so let&#8217;s define:</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3A%3D+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3A%3D+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3A%3D+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,b) := |a + b| + |a - b|" class="latex" /></p>
<p>This expression looks fairly symmetric in a and b, so what happens if we switch the two?</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28b%2Ca%29+%3D+%7Cb+%2B+a%7C+%2B+%7Cb+-+a%7C+%3D+%7Ca+%2B+b%7C+%2B+%7C-%28a+-+b%29%7C+%3D+%5C%5C+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28b%2Ca%29+%3D+%7Cb+%2B+a%7C+%2B+%7Cb+-+a%7C+%3D+%7Ca+%2B+b%7C+%2B+%7C-%28a+-+b%29%7C+%3D+%5C%5C+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28b%2Ca%29+%3D+%7Cb+%2B+a%7C+%2B+%7Cb+-+a%7C+%3D+%7Ca+%2B+b%7C+%2B+%7C-%28a+-+b%29%7C+%3D+%5C%5C+%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(b,a) = |b + a| + |b - a| = |a + b| + |-(a - b)| = &#92;&#92; |a + b| + |a - b| = f(a,b)" class="latex" /></p>
<p>So it&#8217;s indeed symmetric in the two arguments. Another candidate to check is sign flips &#8211; we&#8217;re taking absolute values here, so we might find something interesting there as well:</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28a%2C-b%29+%3D+%7Ca+%2B+%28-b%29%7C+%2B+%7Ca+-+%28-b%29%7C+%3D+%7Ca+-+b%7C+%2B+%7Ca+%2B+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2C-b%29+%3D+%7Ca+%2B+%28-b%29%7C+%2B+%7Ca+-+%28-b%29%7C+%3D+%7Ca+-+b%7C+%2B+%7Ca+%2B+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2C-b%29+%3D+%7Ca+%2B+%28-b%29%7C+%2B+%7Ca+-+%28-b%29%7C+%3D+%7Ca+-+b%7C+%2B+%7Ca+%2B+b%7C+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,-b) = |a + (-b)| + |a - (-b)| = |a - b| + |a + b| = f(a,b)" class="latex" /></p>
<p>And because we already know that f is symmetric in its arguments, this gives us <img src="https://s0.wp.com/latex.php?latex=f%28-a%2Cb%29+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28-a%2Cb%29+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28-a%2Cb%29+%3D+f%28a%2Cb%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(-a,b) = f(a,b)" class="latex" /> for free &#8211; bonus! Putting all these together, we now know that</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+f%28b%2Ca%29+%3D+f%28%7Ca%7C%2C%7Cb%7C%29+%3D+%7C+%7Ca%7C+%2B+%7Cb%7C+%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+f%28b%2Ca%29+%3D+f%28%7Ca%7C%2C%7Cb%7C%29+%3D+%7C+%7Ca%7C+%2B+%7Cb%7C+%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+f%28b%2Ca%29+%3D+f%28%7Ca%7C%2C%7Cb%7C%29+%3D+%7C+%7Ca%7C+%2B+%7Cb%7C+%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,b) = f(b,a) = f(|a|,|b|) = | |a| + |b| | + | |a| - |b| |" class="latex" /></p>
<p>which isn&#8217;t earth-shattering but not obvious either. You could prove this directly from the original expression, but I like doing it this way (defining a function f and poking at it) because it&#8217;s much easier to see what&#8217;s going on.</p>
<p>But we&#8217;re not quite done yet: One final thing you can do with absolute values is figure out what needs to happen for the expression to be non-negative and see if you can simplify it further. Now, both <img src="https://s0.wp.com/latex.php?latex=%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|a|" class="latex" /> and <img src="https://s0.wp.com/latex.php?latex=%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|b|" class="latex" /> are always non-negative, so in fact we have</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%7C+%7Ca%7C+-+%7Cb%7C+%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,b) = |a| + |b| + | |a| - |b| |" class="latex" />.</p>
<p>Now suppose that <img src="https://s0.wp.com/latex.php?latex=%7Ca%7C+%5Cge+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Ca%7C+%5Cge+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Ca%7C+%5Cge+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|a| &#92;ge |b|" class="latex" />. In that case, we know the sign of the expression on the right and can simplify further:</p>
<p><img src="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%28%7Ca%7C+-+%7Cb%7C%29+%3D+2+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%28%7Ca%7C+-+%7Cb%7C%29+%3D+2+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+%7Ca%7C+%2B+%7Cb%7C+%2B+%28%7Ca%7C+-+%7Cb%7C%29+%3D+2+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,b) = |a| + |b| + (|a| - |b|) = 2 |a|" class="latex" /></p>
<p>and similarly, when <img src="https://s0.wp.com/latex.php?latex=%7Cb%7C+%5Cge+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Cb%7C+%5Cge+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Cb%7C+%5Cge+%7Ca%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|b| &#92;ge |a|" class="latex" />, we get <img src="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+2+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+2+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=f%28a%2Cb%29+%3D+2+%7Cb%7C&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="f(a,b) = 2 |b|" class="latex" />. Putting the two together, we arrive at the conclusion</p>
<p><img src="https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29+%3D+2+%5Cmax%28%7Ca%7C%2C%7Cb%7C%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002" srcset="https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29+%3D+2+%5Cmax%28%7Ca%7C%2C%7Cb%7C%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002 1x, https://s0.wp.com/latex.php?latex=%7Ca+%2B+b%7C+%2B+%7Ca+-+b%7C+%3D+f%28a%2Cb%29+%3D+2+%5Cmax%28%7Ca%7C%2C%7Cb%7C%29&#038;bg=ffffff&#038;fg=000&#038;s=0&#038;c=20201002&#038;zoom=4.5 4x" alt="|a + b| + |a - b| = f(a,b) = 2 &#92;max(|a|,|b|)" class="latex" /></p>
<p>which I think is fairly cute. (This expression comes up in <a href="http://en.wikipedia.org/wiki/Sum_of_absolute_transformed_differences">SATD</a> computations and can be used to save some work in the final step.)</p>
]]></html></oembed>