urn:lsid:ibm.com:blogs:entries-84a1e68f-fa2b-4d83-a240-5f565e7d6248Mainframe Performance Topics with Martin Packer - Tags - algebra I'm a well-known mainframe performance guy, with almost 30 years of experience helping customers manage systems. I also dabble in lots of other technology. I've sought to widen the Performance role, incorporating aspects of infrastructural architecture.03032017-09-06T04:15:14-04:00IBM Connections - Blogsurn:lsid:ibm.com:blogs:entry-8947f2e3-c126-4198-8405-a162cc961493Factorise - For Your EyesMartinPacker11000094DHactivefalseComment Entriesapplication/atom+xml;type=entryLikestrue2014-02-23T10:51:16-05:002014-02-23T10:51:16-05:00<p>As you might know I like maths, particularly algebra.
(If you’ve read
<a href="https://www.ibm.com/developerworks/community/blogs/MartinPacker/entry/another_neat_piece_of_algebra_series_summation15?lang=en">Another Neat Piece Of Algebra - Series Summation</a>
and
<a href="https://www.ibm.com/developerworks/community/blogs/MartinPacker/entry/hello_i_m_martin_and_i_m_an_algebraic47?lang=en">Hello, I’m Martin And I’m An Algebraic <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /></a>
you do.)</p>
<p>If there’s one thing I would be doing if I weren’t doing this<a href="#fn:1" id="fnref:1" title="see footnote" class="footnote">[1]</a> it might be teaching maths - but it would have to be at a level where algebra and calculus were substantial topics.
But I don’t think I’ll really be doing that - at least not for the foreseeable future. <a href="#fn:2" id="fnref:2" title="see footnote" class="footnote">[2]</a></p>
<p>So it occurred to me that I need not be alone in treating some algebraic techniques as puzzles<a href="#fn:3" id="fnref:3" title="see footnote" class="footnote">[3]</a> - and with automatic generation of problems people could really get quite good at it.
That <em>might</em> be useful - though utility is not my prime motivator in liking algebra:
I almost never get to use it.</p>
<p>I won’t claim I was looking for a programming project:
The day job gives me enough of those and anyway I have other ideas for fun stuff to <strong>create</strong>.<a href="#fn:4" id="fnref:4" title="see footnote" class="footnote">[4]</a>
But anyway, this weekend I created a basic polynomial factorisation page.
It’s a single file, containing javascript, HTML and CSS - which makes it quite portable.</p>
<p>After a brief preamble about factorisation and some hints it presents you with a machine-generated second-order<a href="#fn:5" id="fnref:5" title="see footnote" class="footnote">[5]</a> polynomial in x to factorise.
You type in the factors and press the “Check” button.</p>
<p>The code multiplies the factors together and tells you what the resulting polynomial is.
It also compares it to the original and tells you if you’ve got it right.</p>
<p>There’s a “Try another” button or you can just manually reload the page.</p>
<p>Try the code
<a href="https://www.ibm.com/developerworks/community/blogs/MartinPacker/resource/factorise.html?lang=en">here</a>.</p>
<p>It’s a little rough and ready. In particular you have to be little careful in how you type the factors in.</p>
<p>I’ve thought of some ways I could improve it already:</p>
<ul>
<li>I can think of difficulty levels.</li>
<li>I could extend it to third- or fourth-order polynomials.</li>
<li>I could extend it to polynomials in x and y.</li>
<li>I could give tutorial hints.</li>
<li>I could graph the resulting polynomial - probably on an HTML5 canvas.</li>
<li>I could work on the text some more.</li>
<li>I could use the HTML5 <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html">Offline Web Applications</a> function to enable you to download it and run it on, let’s say, your smartphone.</li>
</ul>
<p>But for now I’m enjoying testing it.
And I hope you enjoy <strong>playing</strong> with it too.</p>
<p>And, in case you’re wondering, I have a memory-related “day job” post beginning to take shape in my brain.</p>
<div class="footnotes">
<hr />
<ol>
<li id="fn:1">
<p>The term “this” is, of course, loosely defined. Whether you think I’m a System z advocate, as Principal Systems Investigator (as I seem to be allowed to style myself) <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /> or as Performance Guy is a matter of personal opinion. <a href="#fnref:1" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
<li id="fn:2">
<p>OK, how far can you foresee the future? Really, <strong>that</strong> far? <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /> <a href="#fnref:2" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
<li id="fn:3">
<p>As indeed I confess to in
<a href="https://www.ibm.com/developerworks/community/blogs/MartinPacker/entry/hello_i_m_martin_and_i_m_an_algebraic47?lang=en">Hello, I’m Martin And I’m An Algebraic <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /></a> <a href="#fnref:3" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
<li id="fn:4">
<p>My creative metier is code. Oh, and true stories. <a href="#fnref:4" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
<li id="fn:5">
<p>A second-order polynomial is one of the form ax<sup>2</sup>+bx+c. <a href="#fnref:5" title="return to article" class="reversefootnote"> ↩</a></p>
</li>
</ol>
</div>
As you might know I like maths, particularly algebra.
(If you’ve read
Another Neat Piece Of Algebra - Series Summation and
Hello, I’m Martin And I’m An Algebraic you do.) If there’s one thing I would be doing if I weren’t...002807urn:lsid:ibm.com:blogs:entry-143e9dde-a292-4114-925d-643a2e626046Another Neat Piece Of Algebra - Series SummationMartinPacker11000094DHactivefalseComment Entriesapplication/atom+xml;type=entryLikestrue2011-07-19T13:00:56-04:002011-07-19T13:00:56-04:00<p>Here's another neat piece of algebra: A technique for summing series.</p>
<p>You know what b - a + c - b + d - c is. Right?</p><p>
</p><p>Suppose I were to write the same sum as:</p>
<p>(b - a) +</p>
<p>(c - b) +</p>
<p>(d - c)</p>
<p>The answer is still d - a. Right?</p>
<p>Now, suppose I re-label with s<sub style=" vertical-align:-50%;">0</sub> = a, s<sub style=" vertical-align:-50%;">1</sub> = b, s<sub style=" vertical-align:-50%;">2</sub> = c and s<sub style=" vertical-align:-50%;">3</sub> = d. We end up with:</p>
<p>(s<sub style=" vertical-align:-50%;">1</sub> - s<sub style=" vertical-align:-50%;">0</sub>) +</p>
<p>(s<sub style=" vertical-align:-50%;">2</sub> - s<sub style=" vertical-align:-50%;">1</sub>) +</p>
<p>(s<sub style=" vertical-align:-50%;">3</sub> - s<sub style=" vertical-align:-50%;">2</sub>)</p>
<p>This is actually pretty scalable terminology as you can write s<sub style=" vertical-align:-50%;">r</sub> for any arbitrary value of r. And that's one of the strengths of algebra: generalisation.</p>
<p> So let's do that up to n:</p>
<p>(s<sub style=" vertical-align:-50%;">1</sub> - s<sub style=" vertical-align:-50%;">0</sub>) +</p>
<p>(s<sub style=" vertical-align:-50%;">2</sub> - s<sub style=" vertical-align:-50%;">1</sub>) +</p>
<p>...</p>
<p>(s<sub style=" vertical-align:-50%;">n</sub> - s<sub style=" vertical-align:-50%;">n-1</sub>)</p>
<p>which is, of course, s<sub style=" vertical-align:-50%;">n</sub> - s<sub style=" vertical-align:-50%;">0</sub>.</p>
<p>But what has that got to do with summing series?</p>
<p>If we can replace each (s<sub style=" vertical-align:-50%;">r</sub> - s<sub style=" vertical-align:-50%;">r-1</sub>) by a single term u<sub style=" vertical-align:-50%;">r</sub> you may see the relevance...</p>
<p>u<sub style=" vertical-align:-50%;">1</sub> + u<sub style=" vertical-align:-50%;">2</sub> + ... + u<sub style=" vertical-align:-50%;">n</sub> = s<sub style=" vertical-align:-50%;">n</sub> - s<sub style=" vertical-align:-50%;">0</sub>.</p>
<p>The series summation boils down to a "simple" subtraction. The trick is to find these s terms, given the u terms. Let's try it with an example.</p><p> <br /></p>
<hr><br /></hr>
<h3> <br /></h3><h3>Summing The Integers</h3>
<p> <br /></p><p>This is the series 1, 2, 3, ... , n.</p>
<p>The r'th u term is just r. u<sub style=" vertical-align:-50%;">r</sub> = r. So we now have to find the s<sub style=" vertical-align:-50%;">r</sub> term. Remember s<sub style=" vertical-align:-50%;">r</sub> - s<sub style=" vertical-align:-50%;">r-1</sub> has to equal r.</p>
<p>Try s<sub style=" vertical-align:-50%;">r</sub> = r (r + 1).</p>
<p>Then s<sub style=" vertical-align:-50%;">r-1</sub> = (r - 1) r or r (r - 1).</p>
<p>So s<sub style=" vertical-align:-50%;">r</sub> - s<sub style=" vertical-align:-50%;">r-1</sub> = [(r + 1) - (r - 1)] r or 2r. Not quite what we wanted. But we know - dividing by the factor of 2 - we should've guessed s<sub style=" vertical-align:-50%;">r</sub> = ½ r (r + 1).</p>
<p>So s<sub style=" vertical-align:-50%;">n</sub> - s<sub style=" vertical-align:-50%;">0</sub> = ½ n (n + 1) - ½ 0 (0 + 1) = ½ n (n + 1) - 0 = ½ n (n + 1).</p><p>
</p><p>The sum of the first n integers being ½ n (n + 1) is a well-known result. Admittedly it could've been done another way. But it's simple enough to show the method.</p><p> <br /></p>
<hr />
<h3> <br /></h3><h3>Another Example - Summing The Squares Of The Integers</h3>
<p> <br /></p><p>This is the series 1, 4, 9, ... , n² .</p>
<p>In this case we need to do something that will appear slightly perverse:</p>
<p>Rewrite r² as r ( r + 1) - r.</p>
<p>If you can split each of the terms in a series into two terms you can sum these sub terms. I just did the split. We already know how to sum the "r" portion. It's ½ n (n + 1). So we need to sum the r (r+1) portion and subtract ½ n (n+1) from the result.</p>
<p>Try s<sub style=" vertical-align:-50%;">r</sub> = r (r + 1) (r + 2).</p><p>
</p><p>Again we need to find s<sub style=" vertical-align:-50%;">r-1</sub>.</p>
<p>It's:</p>
<p> (r - 1) r (r + 1)</p>
<p>or, rearranging,</p>
<p>r (r+1) (r-1)</p>
<p>So</p>
s<sub style=" vertical-align:-50%;">r</sub> - s<sub style=" vertical-align:-50%;">r-1</sub> = [(r + 2) - (r - 1)] r (r + 1) or 3r (r + 1).<p />
<p>This is 3 times what we want so we should've guessed s<sub style=" vertical-align:-50%;">r</sub> = 1/3 r (r + 1) (r + 2).</p>
<p>So this portion of the sum is 1/3 n (n + 1) (n + 2) - 1/3 0 (0 + 1)(0 + 2) or 1/3 n (n + 1) (n + 2).</p>
<p>But we need to subtract ½ n (n + 1) from this:</p>
<p>1/3 n (n + 1) (n +2) - ½ n (n + 1) = 2/6 n (n + 1) (n +2) - 3/6 n (n + 1)</p><p>
</p><p>or</p>
<p>1/6 n (n + 1) [ 2 (n + 2) - 3] = 1/6 n (n + 1)( 2 n + 1) .</p>
<p>If you try it for a few values you'll see it's right. This <b>isn't</b> such a well known result as for the sum of the integers.</p><p> <br /></p>
<hr />
<p> </p><p>I'm conscious there's been some fiddliness here - which is where <b>I</b> normally fall down. <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/sad.gif" class="smiley" alt=":-(" title=":-(" /></p>
<p>But I think the "sum a series by converting it to a single subtraction" trick is a neat one - which is why I share it with you.</p>Here's another neat piece of algebra: A technique for summing series. You know what b - a + c - b + d - c is. Right? Suppose I were to write the same sum as: (b - a) + (c - b) + (d - c) The answer is still d - a. Right? Now, suppose I re-label with s 0 = a, s...104134urn:lsid:ibm.com:blogs:entry-76ce0af7-bf94-46e5-8727-b396e8398cf5Hello, I'm Martin And I'm An Algebraic :-)MartinPacker11000094DHactivefalseComment Entriesapplication/atom+xml;type=entryLikestrue2011-07-09T16:13:16-04:002011-07-09T16:13:16-04:00<p>If you're sat next to me on a plane you'll probably notice at take off and landing I do algebra puzzles. You may not have heard of the term "algebra puzzles" before and perhaps think the juxtaposition of the two words to be odd, but I think it apt...</p>
<p>(You may also think this whole post to be showing off, but that's a risk I take in sharing a passion I have.) <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /> </p>
<p>A classic problem with take offs and landings is what to do given you're not allowed to use electronic equipment. I'll readily agree that staring out the window is a good one - which is why I prefer a window seat. I <b>love</b> staring out the window. I love maps - and to me looking out of an airplane window brings maps to life. And figuring out what I'm seeing is another <b>great</b> puzzle. But sometimes there's nothing to see. So what do you do?</p>
<p>I started by taking puzzle books with me. I've done <a href="http://en.wikipedia.org/wiki/Sudoku">Sudoku</a> (but not recently), <a href="http://en.wikipedia.org/wiki/Kakuro">Kakuro</a>, <a href="http://en.wikipedia.org/wiki/Futoshiki">Futoshiki</a>, <a href="http://en.wikipedia.org/wiki/Hashiwokakero">Hashi</a>, <a href="http://en.wikipedia.org/wiki/KenKen">Kenken</a> and any number of others. I enjoy them but each one lacks variety. (And I'm disappointed that by far and away the most common puzzle books are Sudoku.)<br /></p>
<p>But I find the best puzzles of all are algebra problems. I still have a copy of my "high school" Further Mathematics textbook. I don't know why, I just do. <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /></p>
<p>I actually think it's the elegance of expression and the neatness of the right shortcut that appeal to me. As I've said many times I'm a sucker for ingenuity. Below is an example of a neat shortcut that I'd like to share with you. I hope you'll see what I mean.
</p>
<p>One of the nice things about mathematics in general is that you're perpetually "standing on the shoulders of giants". Some of them well known (Newton, Leibnitz, Euclid, Gauss, etc) but many are anonymous. In the example below I've no idea who thought of the shortcut first. (I'm just pleased I understand it and can see its applicability.)</p>
<hr style="width: 100%; height: 2px;" />
<hr\>
<h4>A Simple Example Of Elegance</h4>
<p><b>Problem:</b> Solve (x - 3)² - (x + 2)² = 0</p>
<p>It looks like a difficult puzzle to solve. Of course if it were I wouldn't be offering it here. <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /> You could multiply everything out and gather terms but that's horrid. Thankfully, there is a more elegant way:</p>
<p>Observe x² - y² = (x - y) (x + y) . (Check it if you don't believe me!)</p>
<p>If you substitute a for (x - 3) and b for (x + 2) you get:</p>
<p>a² - b² which, of course, can be rewritten as (a - b) (a + b) .</p>
<p>I think you'll agree working out what (a - b) and (a + b) are is easy:</p>
<p>a - b = (x - 3) - (x + 2) or -5</p>
<p>a + b = (x - 3) + (x + 2) or 2x - 1</p>
<p>Multiply them together and you get:</p>
<p>-5 × (2x - 1) = 5 - 10x </p>
<p>So (x - 3)² - (x + 2)² = 5 - 10x which = 0, as the original problem stated.</p>
<p>If 5 - 10x = 0 then 10x = 5 and so x = ½.</p>
<hr style="width: 100%; height: 2px;" />
<hr\>
<p>See, that wasn't so hard, was it? I think people think mathematics is hard. I don't think algebra is hard. I <b>do</b> thing topology is hard - because of the abstractness of the concepts. I <b>do</b> think proving things is hard - because of the need to not miss any loose ends and to know whether you've actually <span style="font-weight: bold;">proved</span> anything. But algebra is, to me, pure puzzle solving. And elegance is important: In the above example I could quite easily have made a mistake if I'd not known the trick. With the trick I'm much less likely to.</p>
<p>Now someone will probably come along and point out a few things about the example, including a further trick. If they do I'll be <span style="font-weight: bold;">delighted</span>. This "old dog" <b>loves</b> learning new tricks. <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /> And if I <b>am</b> sat next to you on the plane at least I won't be muttering to myself as I manipulate those symbols. <img src="https://www.ibm.com/developerworks/community/blogs/images/smileys/smile.gif" class="smiley" alt=":-)" title=":-)" /></p></hr\></hr\>If you're sat next to me on a plane you'll probably notice at take off and landing I do algebra puzzles. You may not have heard of the term "algebra puzzles" before and perhaps think the juxtaposition of the two words to be odd, but I think it apt......366769