Professional Documents
Culture Documents
Randomized Algorithms: Matrix Multiplication
Randomized Algorithms: Matrix Multiplication
Matrix Multiplication
Lecturer
Department of Computer Science and Engineering
Islamic University of Technology
Randomized/Probabilistic Algorithms
Given n × n matrices, A, B, C
Given n × n matrices, A, B, C
Verify whether A × B = C or not
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times→ O(kn2 )
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times→ O(kn2 )
I Independent executions
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times→ O(kn2 )
I Independent executions→ Independent randomization
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times→ O(kn2 )
I Independent executions→ Independent randomization
I Probability multiplies in each execution
MBH (CSE, IUT) Randomized Algorithms 3/7
Checking Matrix Multiplication
Given n × n matrices, A, B, C
Verify whether A × B = C or not
With certain probability→ Monte Carlo
How to verify?
• Simple Algorithm: O(n3 ) multiplications
• Strassen’s Algorithm (1969): O(nlog2 (7) ) = O(n2.81 )
• Coppersmith-Winograd (1990): O(n2.375477 )
• Andrew Stothers (2010): O(n2.374 )
• Le Gall (2014): O(n2.3728642 )
Verification should be faster→ O(n2 )
Reduced accuracy
• If A × B = C , then Pr [output = YES] = 1(No False Negative)
• If A × B 6= C , then Pr [output = YES] ≤ 12 (False Positive)
I Run k times→ O(kn2 )
I Independent executions→ Independent randomization
I Probability multiplies in each execution→ ≤ 1k
2
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Let,
~ = A × (B~r ) − C~r
P
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Let,
~ = A × (B~r ) − C~r
P
= (A × B)~r − C~r
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Let,
~ = A × (B~r ) − C~r
P
= (A × B)~r − C~r
= (A × B − C )~r
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Let,
~ = A × (B~r ) − C~r
P
= (A × B)~r − C~r
= (A × B − C )~r
= ~0
Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1
Let,
~ = A × (B~r ) − C~r
P
= (A × B)~r − C~r
= (A × B − C )~r
= ~0
Will be zero regardless of the choice of ~r
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
1
Need to show that Pr [D~r 6= 0] ≥ 2 for any ~r
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication→ If D 6= 0, but D~r = 0
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication→ If D 6= 0, but D~r = 0
Let, D~r = 0, but D 6= 0 (False Positive)
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication→ If D 6= 0, but D~r = 0
Let, D~r = 0, but D 6= 0 (False Positive)
⇒ For some i, j, dij 6= 0
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication→ If D 6= 0, but D~r = 0
Let, D~r = 0, but D 6= 0 (False Positive)
⇒ For some i, j, dij 6= 0
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Let,
D = A × B − C and D 6= 0
Need to show that Pr [D~r 6= 0] ≥ 12 for any ~r
A bad ~r doesn’t discover incorrect multiplication→ If D 6= 0, but D~r = 0
Let, D~r = 0, but D 6= 0 (False Positive)
⇒ For some i, j, dij 6= 0
(D~v )i 6= 0
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .
Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .