Download as pdf or txt
Download as pdf or txt
You are on page 1of 84

Randomized Algorithms

Matrix Multiplication

Md. Bakhtiar Hasan

Lecturer
Department of Computer Science and Engineering
Islamic University of Technology
Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time
I Correct output

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time
I Correct output
I “Probably Fast”

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time
I Correct output
I “Probably Fast”→ Las Vegas Algorithms

MBH (CSE, IUT) Randomized Algorithms 2/7


Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time
I Correct output
I “Probably Fast”→ Las Vegas Algorithms

“Probably Correct” + “Probably Fast”


MBH (CSE, IUT) Randomized Algorithms 2/7
Randomized/Probabilistic Algorithms

Generates a random number, r ∈ {1, . . . , R}


Make decisions based on r ’s value
Example:
• Recursive Algorithm
• Generate r in every level of recursion
On the same input on different executions
• Produce different outputs
I Might be wrong
I Reduce the probability of incorrect output
I Deterministic runtime
I “Probably Correct”→ Monte Carlo Algorithms
• Run for different # of steps
I Expected runtime→ e.g.: Expected polynomial time
I Correct output
I “Probably Fast”→ Las Vegas Algorithms

“Probably Correct” + “Probably Fast”→ Atlantic City Algorithms


MBH (CSE, IUT) Randomized Algorithms 2/7
Checking Matrix Multiplication

Given n × n matrices, A, B, C

MBH (CSE, IUT) Randomized Algorithms 3/7


Checking Matrix Multiplication

Given n × n matrices, A, B, C
Verify whether A × B = C or not

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

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

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?

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

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 )

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 )

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 )

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 )

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

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 )

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

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

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)

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

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)

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

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 )

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

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

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
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

MBH (CSE, IUT) Randomized Algorithms 3/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


1
Such that Pr [ri = 1] = 2 independently for i = 1, . . . , n

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)
• Calculate A(B~r )

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)
• Calculate A(B~r )→ A(n × n) and B~r (n × 1)

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)
• Calculate A(B~r )→ A(n × n) and B~r (n × 1)
• Calculate C~r

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)
• Calculate A(B~r )→ A(n × n) and B~r (n × 1)
• Calculate C~r → C (n × n) and ~r (n × 1)

MBH (CSE, IUT) Randomized Algorithms 4/7


Frievald’s Algorithm

Choose a random binary vector, ~r [1 . . . n]


Such that Pr [ri = 1] = 12 independently for i = 1, . . . , n
If A(B~r ) − C~r = ~0, then output YES
Else output NO
3 matrix-vector products
• Calculate B~r → B(n × n) and ~r (n × 1)
• Calculate A(B~r )→ A(n × n) and B~r (n × 1)
• Calculate C~r → C (n × n) and ~r (n × 1)
Complexity: O(n2 )

MBH (CSE, IUT) Randomized Algorithms 4/7


Correctness Analysis

Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

Claim
If A × B = C , then Pr [A × B~r − C~r = 0] = 1

Let,
~ = A × (B~r ) − C~r
P

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 5/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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)

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

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

MBH (CSE, IUT) Randomized Algorithms 6/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0
For each bad ~r , we have one good r~0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0
For each bad ~r , we have one good r~0 → More if multiple change

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0
For each bad ~r , we have one good r~0 → More if multiple change
# of r~0 where D r~0 6= ~0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0
For each bad ~r , we have one good r~0 → More if multiple change
# of r~0 where D r~0 6= ~0 ≥ # of ~r where D~r = ~0

MBH (CSE, IUT) Randomized Algorithms 7/7


Correctness Analysis

Claim
If A × B 6= C , then Pr [A × B~r − C~r 6= 0] ≥ 21 .

Take any ~r such that D~r = 0


Let, r~0 = (~r + ~v )
D r~0 = D(~r + ~v )
= D~r + D~v
= 0 + D~v
6= ~0
Only one change can turn a bad ~r into a good r~0
For each bad ~r , we have one good r~0 → More if multiple change
# of r~0 where D r~0 6= ~0 ≥ # of ~r where D~r = ~0
1
Pr [D~r 6= 0] ≥ 2

MBH (CSE, IUT) Randomized Algorithms 7/7

You might also like