Difference between revisions of "TADM2E 1.7"

From Algorithm Wiki
Jump to: navigation, search
(Recovering wiki)
Line 1: Line 1:
<h2>Base Case</h2>
+
Eat bulaga!!!!!!
 
+
Eat bulaga!!!!!!
The base case <math>(z = 0)</math> is true since it returns zero<br>
+
Eat bulaga!!!!!!
:<code>if <math>z = 0</math> then return(0)</code>
+
Eat bulaga!!!!!!
 
+
Eat bulaga!!!!!!
<h2>Assumptions</h2><br/>
+
Eat bulaga!!!!!!
multiply(y,z) gives the correct answer where:
+
Eat bulaga!!!!!!
* z <= n
+
Eat bulaga!!!!!!
* c >= 2
+
Eat bulaga!!!!!!
* y >= 0<br />
+
Eat bulaga!!!!!!
<br />
+
Eat bulaga!!!!!!
We will also assume the following. A brief proof will follow:
+
Eat bulaga!!!!!!
* <math>\left \lfloor z / c \right \rfloor c + (z\,\bmod\,c) = z</math>
+
Eat bulaga!!!!!!
<br/>
+
Eat bulaga!!!!!!
 
+
Eat bulaga!!!!!!
<h2>Proof</h2><br />
+
Eat bulaga!!!!!!
Where z = n+1, c >= 2, y >= 0<br/>
+
Eat bulaga!!!!!!
<br />
+
Eat bulaga!!!!!!
First we break the result of multiply into two parts:<br />
+
Eat bulaga!!!!!!
<br/>
+
Eat bulaga!!!!!!
&nbsp;&nbsp;&nbsp;&nbsp;A = <math>multiply(cy, \left \lfloor [n+1]/c  \right \rfloor)</math><br/>
+
Eat bulaga!!!!!!
&nbsp;&nbsp;&nbsp;&nbsp;B = <math>y([n+1]\,\bmod\,c)</math><br/>
+
Eat bulaga!!!!!!
<br/>
+
Eat bulaga!!!!!!
&nbsp;&nbsp;&nbsp;&nbsp;<math>multiply(y,z) = A + B</math><br/>
+
Eat bulaga!!!!!!
<br/>
+
Eat bulaga!!!!!!
<br/>
+
Eat bulaga!!!!!!
Now, because c >= 2 we know that <math>\left \lfloor (n+1) / c \right \rfloor < (n+1)</math>.<br />
+
Eat bulaga!!!!!!
Based on that, we know that the call to multiply in "A" returns the correct result.<br />
+
Eat bulaga!!!!!!
<br />
+
Eat bulaga!!!!!!
&nbsp;&nbsp;&nbsp;&nbsp;<math>A = multiply(cy, \left \lfloor [n+1]/c \right \rfloor) = cy * \left \lfloor [n+1] / c \right \rfloor</math><br />
+
Eat bulaga!!!!!!
<br />
 
So now let's transform A into something more useful:<br />
 
<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;<math>A = cy * \left \lfloor [n+1] / c \right \rfloor = y * \left \lfloor z / c \right \rfloor c</math> <br/>
 
&nbsp;&nbsp;&nbsp;&nbsp;(Note: We transformed n+1 back into z for simplicity)<br />
 
<br />
 
Based on our earlier assumption, we can transform this further:<br />
 
<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;<math> \left \lfloor z / c \right \rfloor c + (z \,\bmod\, c) = z</math><br />
 
&nbsp;&nbsp;&nbsp;&nbsp;<math> \left \lfloor z / c \right \rfloor c = z - (z \,\bmod\, c)</math><br/>
 
<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;<math>A = y *  \left \lfloor z / c \right \rfloor c = y (z - z \,\bmod\, c) = yz - y(z \,\bmod\, c)</math><br />
 
<br />
 
And now we add B back into the mix:<br />
 
<br />
 
&nbsp;&nbsp;&nbsp;&nbsp;<math>A + B = yz - y(z \,\bmod\, c) + y(z \,\bmod\, c) = yz</math><br />
 
<br />
 
<br/>
 
<h2>Subproof</h2>
 
<b>Show that <math>\left \lfloor z/c \right \rfloor c + z\,\bmod\,c = z</math> where c >= 2</b><br/>
 
<br/>
 
We can prove this statement using a general example.<br/>
 
<br/>
 
First, assume that <math>z\,\bmod\,c = a.</math><br/>
 
<br/>
 
Now, due to the definition of floor, we know the following:<br/>
 
<br/>
 
&nbsp;&nbsp;&nbsp;&nbsp;<math>(z-a) / c = \left \lfloor z / c \right \rfloor</math><br/>
 
<br/>
 
This is because the remainder can't possibly be taken into account during a "floor" operation.<br/>
 
<br/>
 
Based on that, we can restate the equation as:<br/>
 
<br/>
 
&nbsp;&nbsp;&nbsp;&nbsp;<math>(z-a) / c * c + a  = (z - a) + a = z</math><br/>
 
<br/>
 
 
 
[[introduction-TADM2E|Back to ''Introduction ...'']]
 

Revision as of 07:27, 18 July 2020

Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!! Eat bulaga!!!!!!