Archive
Decomposing multiplications, Egyptian Style
Ever wanted a function that takes a number and breaks it down? For instance, let’s say someone types in 1924, wouldn’t it be great if you could quickly and easily generate how to sum up that number? Which in this case is 4 + 128 + 256 + 512 + 1024 = 1924. Not the function you use on a daily basis, I know – but still a cool feature to have.
Egyptian mathematics
The Egyptians that built the pyramids were clever people. For instance, they had two alphabets (one religious and one secular) and they also had two multiplication methods. They also had a number for everything in nature, which made it possible for them to calculate resonance even more accurately than we do now (because every sound also had a number, so matching number, material and sound is easy enough). Every single stone in the Amun temple is carved to fit a number and a shape — and the temple itself is built as a duplicate of the human body (with the holy-of-holies where the pineal gland is positioned. Thats where Alexander the great was buried, in Luxor). So these guys knew a lot of cool stuff that we have forgotten or never even investigated.
But back to their way of multiplying numbers. Their most common way to doing this was simply called “summing up”. And it goes a little something like this:
Let’s say you want to find the solution to: “9 * 13”. What the Egyptians did was to first create a table where they double-up to reach the closest match to “9”, like this:
1
2
4
8
Then they created a second row, where they doubled 13, which is our multiplier:
1 .. 13
2 .. 26
4 .. 52
8 .. 104
With these two tables written as above, they then made a checkmark on the numbers which, when you add them together from the left table, makes 9. In this case that is #1 and #8.
1 .. 13 —
2 .. 26
4 .. 52
8 .. 104 —
To get the correct answere to “9 * 13” all you have to do is to add the checked numbers together from the right table. Which means that the correct answer is 13 + 104 = 117. Pretty cool right?
Use the binary force
You may have noticed that the left-side table is actually plain old binary. So yes, the ancient Egyptians actually invented (or discovered) binary. But it also means that we can use ordinary bit testing to figure out how to turn a number into an equation. We simply check the bits in the integer value and then sum up from the generated right-side table.
Here it is, written in Smart Pascal (Smart Mobile Studio):
const QTX_BITS: Array[0..12] of Integer = ( 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096); //..Fill in the rest here, 32 bits in an integer w3button1.OnClick:=Procedure (sender:Tobject) var mValue: Integer; x: integer; mTotal: Integer; begin var mStack:Array of String; mValue:=1924; for x:=0 to 31 do begin if TInteger.getBit(x,mValue) then begin mStack.add(QTX_BITS[x].toString); writeln('Bit #' + x.toString + ' = ' + QTX_BITS[x].toString); end else writeln('Bit #' + x.toString + ' = ' + '------'); if QTX_BITS[x]>=mValue then break; end; writeln(' '); writeln('Adding:'); if mStack.length>0 then Begin mTotal:=0; for x:=mStack.low to mStack.high do begin if x>mStack.low then writeln(' + ' + mStack[x]) else writeln(' ' + mStack[x]); inc(mTotal,TVariant.AsInteger(mStack[x])); end; Writeln('--------------------'); Writeln(' = ' + mTotal.toString); end; end; end;
When you run this, providing the number 1924, it breaks it down and gives you the following output:
Bit #0 = ------ Bit #1 = ------ Bit #2 = 4 Bit #3 = ------ Bit #4 = ------ Bit #5 = ------ Bit #6 = ------ Bit #7 = 128 Bit #8 = 256 Bit #9 = 512 Bit #10 = 1024 Bit #11 = ------ Adding up: 4 + 128 + 256 + 512 + 1024 -------------------- = 1924
Turning this into a neat little function should be easy enough for anyone. And I’m fairly sure that it can be re-factored into something even more impressive, using simple addition and multiplication, like: “4 + (32 * 4) + (128 * 2) + 512 + ( 32 * 32)” making your string output look incredibly smart and clever.
The final product
Having played around with this code, and also fixed two typo’s in this post, I sat down and cleaned the code up. Here is the final function. It returns a string giving you the numbers to add in order to produce the final outcome:
function QTX_GetNumberProducer(aNumber:Integer):String; const QTX_BITS: Array[0..31] of Integer = ( 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648); var x: Integer; mStack: Array of String; Begin result:=""; if aNumber>0 then begin for x:=QTX_BITS.low to QTX_BITS.high do begin if TInteger.getBit(x,aNumber) then mStack.add(QTX_BITS[x].toString); if QTX_BITS[x]>=aNumber then break; end; if mStack.length>0 then begin result:=aNumber.toString + ' = '; for x:=mStack.low to mStack.high do begin if x>mStack.low then result += '+' + mStack[x] else result += mStack[x]; end; end; end else result:="0"; end;
And as a bonus I added this:
Function QTX_GetNumberMultiplier(aFirst,aSecond:Integer):String; var mSum:Integer; Begin mSum:=aFirst*aSecond; result:=aFirst.toString + ' x ' + aSecond.toString +' = ' + QTX_GetNumberProducer(mSum); end;
The last snippet produces an output like this. Which can be handy for children when learning to multiply (or confuse them utterly, whatever works):
Recent
The vatican vault
- January 2022
- October 2021
- March 2021
- November 2020
- September 2020
- July 2020
- June 2020
- April 2020
- March 2020
- February 2020
- January 2020
- November 2019
- October 2019
- September 2019
- August 2019
- July 2019
- June 2019
- May 2019
- April 2019
- March 2019
- February 2019
- January 2019
- December 2018
- November 2018
- October 2018
- September 2018
- August 2018
- July 2018
- June 2018
- May 2018
- April 2018
- March 2018
- February 2018
- January 2018
- December 2017
- November 2017
- October 2017
- August 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- February 2017
- January 2017
- December 2016
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- May 2016
- April 2016
- March 2016
- January 2016
- December 2015
- November 2015
- October 2015
- September 2015
- August 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- November 2014
- October 2014
- September 2014
- August 2014
- July 2014
- June 2014
- May 2014
- April 2014
- March 2014
- February 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
- February 2013
- August 2012
- June 2012
- May 2012
- April 2012
You must be logged in to post a comment.