ΊέΊέί£

ΊέΊέί£Share a Scribd company logo
Beyond Problem Solving
2022. 09. 30(금)
18:00 ~ 21:00
Freivalds Algorithm
0
0
1
0
1
1
1
0
1 2 3 15 -1 -5 -2 8 9 0
1 6 8 -4 2 5 -1 9 9 9
7 7 7 7 7 7 7 7 7 7
-8 -1 7 8 5 8 9 28 9 1
X =
?
?
?
?
𝑂𝑂(𝑛𝑛2)
Freivalds Algorithm은 ν–‰λ ¬ A,B 그리고 Cκ°€ μžˆμ„ λ•Œ,
AB=Cκ°€ True/False인지 𝑂𝑂(𝑛𝑛2
)의 μ‹œκ°„λ³΅μž‘λ„λ‘œ νŒλ³„ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜μ΄λ‹€.
Freivalds Algorithm
A
M
K
B
K
N
M C
N
X =
r
1
N r
1
N
X X
( )
A
M
K
B
K
N
M C
N
X = 𝑂𝑂(𝑛𝑛3
)
𝑂𝑂(𝑛𝑛2
) 𝑂𝑂(𝑛𝑛2
)
Freivalds Algorithm
A
M
K
B
K
N
M C
N
X =
r
1
N r
1
N
X X
( )
𝑂𝑂(𝑛𝑛2
) 𝑂𝑂(𝑛𝑛2)
A
M
K
Br
K
1
M Cr
1
X =
𝑂𝑂(𝑛𝑛2
)
Freivalds Algorithm
A
M
K
Br
K
1
M Cr
1
X =
𝑂𝑂(𝑛𝑛2
)
ABr
M
1
M Cr
1
=
𝑂𝑂(𝑛𝑛)
𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 인지 k번 κ²€μ‚¬ν•œλ‹€.
Freivalds Algorithm
𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀.
Freivalds Algorithm
𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀.
1 2 3 -15
1 6 8 -4
7 7 7 7
1 2 3
1 6 8
7 7 7
-8 -1 7
X
24 35 40 -2
63 94 107 17
63 105 126 -84
40 27 17 173
=
M
K
N
K M
N
1
0
1
1
X
-11
5
21
62
187
105
230
24 35 40 -2
63 94 107 17
63 105 126 -84
40 27 17 173
1
0
1
1
X
1 2 3
1 6 8
7 7 7
-8 -1 7
X
1 2 3 -15
1 6 8 -4
7 7 7 7
62
187
105
230
=
Freivalds Algorithm
𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀.
κ·Έλ ‡λ‹€κ³  𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 일 λ•Œ 𝐴𝐴𝐴𝐴 = 𝐢𝐢 λŠ” μ•„λ‹ˆλ‹€!
Freivalds Algorithm
κ·Έλ ‡μ§€λ§Œ 𝐴𝐴 𝐡𝐡𝐡𝐡 β‰  𝐢𝐢𝐢𝐢 이라면 𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 이닀.
𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀.
κ·Έλ ‡λ‹€κ³  𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 일 λ•Œ 𝐴𝐴𝐴𝐴 = 𝐢𝐢 λŠ” μ•„λ‹ˆλ‹€!
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ 
P(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ 
P(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
P 𝐷𝐷𝐷𝐷 = 0 < P(�
𝑗𝑗=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)
열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ λ³΄λ‹€ ν•˜λ‚˜λ§Œ 0일 ν™•λ₯ μ΄ 더 λ†’λ‹€.
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ 
P(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
P 𝐷𝐷𝐷𝐷 = 0 < P(�
𝑗𝑗=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)
μ—¬κΈ°μ„œ μš°μΈ‘ν•­μ„ π‘Ÿπ‘Ÿ
𝑗𝑗에 λŒ€ν•œ μ‹μœΌλ‘œ λ°”κΎΈμ–΄ 보면 μœ„μ™€ κ°™λ‹€.
P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ
𝑗𝑗 =
(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗
𝑑𝑑𝑖𝑖𝑖𝑖
)
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ 
P(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
μ΄λŠ” π‘Ÿπ‘Ÿ
𝑗𝑗 κ°€ μ–΄λ– ν•œ 값을 κ°€μ§ˆ ν™•λ₯ μΈλ° r은 0λ˜λŠ” 1만 κ°€λŠ₯ν•˜λ‹€.
P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ
𝑗𝑗 =
(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗
𝑑𝑑𝑖𝑖𝑖𝑖
)
P(π‘Ÿπ‘Ÿ
𝑗𝑗)
P(π‘Ÿπ‘Ÿ
𝑗𝑗 = 0), P π‘Ÿπ‘Ÿ
𝑗𝑗 = 1 λͺ¨λ‘ 각각
1
2
이닀.
Freivalds Algorithm
𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€.
𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€)
𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€.
ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€.
𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ 
P(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
μ΄λŠ” π‘Ÿπ‘Ÿ
𝑗𝑗 κ°€ μ–΄λ– ν•œ 값을 κ°€μ§ˆ ν™•λ₯ μΈλ° r은 0λ˜λŠ” 1만 κ°€λŠ₯ν•˜λ‹€.
P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ
𝑗𝑗 =
(βˆ‘π‘—π‘—=0
𝑁𝑁
𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ
𝑗𝑗
𝑑𝑑𝑖𝑖𝑖𝑖
)
P(π‘Ÿπ‘Ÿ
𝑗𝑗)
P(π‘Ÿπ‘Ÿ
𝑗𝑗 = 0), P π‘Ÿπ‘Ÿ
𝑗𝑗 = 1 λͺ¨λ‘ 각각
1
2
이닀.
P 𝐷𝐷𝐷𝐷 = 0 <
1
2
이고 이λ₯Ό K번 λ°˜λ³΅ν•˜λ©΄ μ˜€λ‹΅λ₯ μ€
1
2π‘˜π‘˜ 둜 쀄어든닀.
Matrix multiply(Matrix& A, Matrix& B) {
int M = A.size();
int K = B.size();
int N = B[0].size();
Matrix C(M, vector<int>(N, 0));
for (int m = 0; m < M; m++) {
for (int n = 0; n < N; n++) {
int c = 0;
for (int k = 0; k < K; k++) {
c += A[m][k] * B[k][n];
}
C[m][n] = c;
}
}
return C;
}
C++
Freivalds Algorithm Matrix create_random_matrix(int rows, int cols) {
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> rand_int(-100,100);
Matrix mat(rows, vector<int>(cols, 0));
for (int y = 0; y < rows; y++) {
for (int x = 0; x < cols; x++) {
mat[y][x] = rand_int(gen);
}
}
return mat;
}
C++
bool Freivalds(Matrix& A, Matrix& B, Matrix& C) {
int t = 20;
const int K = B.size();
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> rand_int(0,1);
while (t--) {
vector<int> r(K);
generate(r.begin(), r.end(), [&]()->int {return rand_int(gen); });
vector<int> Br(K);
for (int i = 0; i < K; i++) {
Br[i] = inner_product(r.begin(), r.end(), B[i].begin(), 0);
}
for (int i = 0; i < K; i++) {
int ABr = inner_product(Br.begin(), Br.end(), A[i].begin(), 0);
int Cr = inner_product(r.begin(), r.end(), C[i].begin(), 0);
if (ABr!=Cr)
return false;
}
}
return true;
}
C++

More Related Content

Featured (20)

Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
Artificial Intelligence, Data and Competition – SCHREPEL – June 2024 OECD dis...
OECD Directorate for Financial and Enterprise Affairs
Μύ
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
Μύ
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Μύ
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Μύ
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
Μύ
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
Μύ
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Μύ
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
Μύ
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Μύ
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
Μύ
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Μύ
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Μύ
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
Μύ
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
Μύ
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Μύ
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Μύ
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
Μύ
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Μύ
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Μύ
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
Μύ
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
How to Leverage AI to Boost Employee Wellness - Lydia Di Francesco - SocialHR...
SocialHRCamp
Μύ
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Μύ
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Μύ
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
Μύ
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
Μύ
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Μύ
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Μύ
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
Μύ
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Μύ
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Μύ
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
Μύ
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
Μύ
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Μύ
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Μύ
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
Μύ
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Μύ
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky
Μύ

[FreivaldsAlgorithm]The Freivalds Algorithm is an algorithm that determines whether AB=C is true/false with a time complexity of O(n2) when there are matrices A, B, and C. This is a slide with an explanation and implementation code.

  • 1. Beyond Problem Solving 2022. 09. 30(금) 18:00 ~ 21:00
  • 2. Freivalds Algorithm 0 0 1 0 1 1 1 0 1 2 3 15 -1 -5 -2 8 9 0 1 6 8 -4 2 5 -1 9 9 9 7 7 7 7 7 7 7 7 7 7 -8 -1 7 8 5 8 9 28 9 1 X = ? ? ? ? 𝑂𝑂(𝑛𝑛2) Freivalds Algorithm은 ν–‰λ ¬ A,B 그리고 Cκ°€ μžˆμ„ λ•Œ, AB=Cκ°€ True/False인지 𝑂𝑂(𝑛𝑛2 )의 μ‹œκ°„λ³΅μž‘λ„λ‘œ νŒλ³„ν•˜λŠ” μ•Œκ³ λ¦¬μ¦˜μ΄λ‹€.
  • 3. Freivalds Algorithm A M K B K N M C N X = r 1 N r 1 N X X ( ) A M K B K N M C N X = 𝑂𝑂(𝑛𝑛3 ) 𝑂𝑂(𝑛𝑛2 ) 𝑂𝑂(𝑛𝑛2 )
  • 4. Freivalds Algorithm A M K B K N M C N X = r 1 N r 1 N X X ( ) 𝑂𝑂(𝑛𝑛2 ) 𝑂𝑂(𝑛𝑛2) A M K Br K 1 M Cr 1 X = 𝑂𝑂(𝑛𝑛2 )
  • 5. Freivalds Algorithm A M K Br K 1 M Cr 1 X = 𝑂𝑂(𝑛𝑛2 ) ABr M 1 M Cr 1 = 𝑂𝑂(𝑛𝑛) 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 인지 k번 κ²€μ‚¬ν•œλ‹€.
  • 6. Freivalds Algorithm 𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀.
  • 7. Freivalds Algorithm 𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀. 1 2 3 -15 1 6 8 -4 7 7 7 7 1 2 3 1 6 8 7 7 7 -8 -1 7 X 24 35 40 -2 63 94 107 17 63 105 126 -84 40 27 17 173 = M K N K M N 1 0 1 1 X -11 5 21 62 187 105 230 24 35 40 -2 63 94 107 17 63 105 126 -84 40 27 17 173 1 0 1 1 X 1 2 3 1 6 8 7 7 7 -8 -1 7 X 1 2 3 -15 1 6 8 -4 7 7 7 7 62 187 105 230 =
  • 8. Freivalds Algorithm 𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀. κ·Έλ ‡λ‹€κ³  𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 일 λ•Œ 𝐴𝐴𝐴𝐴 = 𝐢𝐢 λŠ” μ•„λ‹ˆλ‹€!
  • 9. Freivalds Algorithm κ·Έλ ‡μ§€λ§Œ 𝐴𝐴 𝐡𝐡𝐡𝐡 β‰  𝐢𝐢𝐢𝐢 이라면 𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 이닀. 𝐴𝐴𝐴𝐴 = 𝐢𝐢 이라면 λ‹Ήμ—°νžˆ 𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 이닀. κ·Έλ ‡λ‹€κ³  𝐴𝐴 𝐡𝐡𝐡𝐡 = 𝐢𝐢𝐢𝐢 일 λ•Œ 𝐴𝐴𝐴𝐴 = 𝐢𝐢 λŠ” μ•„λ‹ˆλ‹€!
  • 10. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
  • 11. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
  • 12. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€.
  • 13. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€. P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯  P(βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯ 
  • 14. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€. P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯  P(βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯  P 𝐷𝐷𝐷𝐷 = 0 < P(οΏ½ 𝑗𝑗=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0) 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯ λ³΄λ‹€ ν•˜λ‚˜λ§Œ 0일 ν™•λ₯ μ΄ 더 λ†’λ‹€.
  • 15. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€. P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯  P(βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯  P 𝐷𝐷𝐷𝐷 = 0 < P(οΏ½ 𝑗𝑗=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0) μ—¬κΈ°μ„œ μš°μΈ‘ν•­μ„ π‘Ÿπ‘Ÿ 𝑗𝑗에 λŒ€ν•œ μ‹μœΌλ‘œ λ°”κΎΈμ–΄ 보면 μœ„μ™€ κ°™λ‹€. P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ 𝑗𝑗 = (βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 𝑑𝑑𝑖𝑖𝑖𝑖 )
  • 16. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€. P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯  P(βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯  μ΄λŠ” π‘Ÿπ‘Ÿ 𝑗𝑗 κ°€ μ–΄λ– ν•œ 값을 κ°€μ§ˆ ν™•λ₯ μΈλ° r은 0λ˜λŠ” 1만 κ°€λŠ₯ν•˜λ‹€. P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ 𝑗𝑗 = (βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 𝑑𝑑𝑖𝑖𝑖𝑖 ) P(π‘Ÿπ‘Ÿ 𝑗𝑗) P(π‘Ÿπ‘Ÿ 𝑗𝑗 = 0), P π‘Ÿπ‘Ÿ 𝑗𝑗 = 1 λͺ¨λ‘ 각각 1 2 이닀.
  • 17. Freivalds Algorithm 𝐷𝐷 = 𝐴𝐴𝐴𝐴 βˆ’ 𝐢𝐢 라고 μ •μ˜ν•œλ‹€. 𝐷𝐷 β‰  0 (𝐴𝐴𝐴𝐴 β‰  𝐢𝐢 μ΄λ―€λ‘œ DλŠ” μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ‹€) 𝐷𝐷 β‰  0 (Dκ°€ μ˜ν–‰λ ¬μ΄ μ•„λ‹ˆλ―€λ‘œ D의 μ›μ†Œ 𝑑𝑑𝑖𝑖𝑖𝑖 쀑 ν•˜λ‚˜ 이상은 λ°˜λ“œμ‹œ 0이 μ•„λ‹ˆλ‹€. ν•˜μ§€λ§Œ 𝐷𝐷𝐷𝐷 = 0 이기 λ•Œλ¬Έμ— βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0이 λ˜μ–΄μ•Ό ν•œλ‹€. 𝐷𝐷𝐷𝐷 = 0 μ΄μ§€λ§Œ 𝐷𝐷 β‰  0 κ²½μš°μ™€ ν™•λ₯ μ„ μ°Ύμ•„μ•Ό ν•œλ‹€. P(𝐷𝐷𝐷𝐷 = 0) 은 열벑터 λͺ¨λ‘κ°€ 0이 될 ν™•λ₯  P(βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 = 0)은 μ—΄λ²‘ν„°μ˜ μ›μ†Œ 1κ°œκ°€ 0일 ν™•λ₯  μ΄λŠ” π‘Ÿπ‘Ÿ 𝑗𝑗 κ°€ μ–΄λ– ν•œ 값을 κ°€μ§ˆ ν™•λ₯ μΈλ° r은 0λ˜λŠ” 1만 κ°€λŠ₯ν•˜λ‹€. P 𝐷𝐷𝐷𝐷 = 0 < P(π‘Ÿπ‘Ÿ 𝑗𝑗 = (βˆ‘π‘—π‘—=0 𝑁𝑁 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗) βˆ’ 𝑑𝑑𝑖𝑖𝑖𝑖 οΏ½ π‘Ÿπ‘Ÿ 𝑗𝑗 𝑑𝑑𝑖𝑖𝑖𝑖 ) P(π‘Ÿπ‘Ÿ 𝑗𝑗) P(π‘Ÿπ‘Ÿ 𝑗𝑗 = 0), P π‘Ÿπ‘Ÿ 𝑗𝑗 = 1 λͺ¨λ‘ 각각 1 2 이닀. P 𝐷𝐷𝐷𝐷 = 0 < 1 2 이고 이λ₯Ό K번 λ°˜λ³΅ν•˜λ©΄ μ˜€λ‹΅λ₯ μ€ 1 2π‘˜π‘˜ 둜 쀄어든닀.
  • 18. Matrix multiply(Matrix& A, Matrix& B) { int M = A.size(); int K = B.size(); int N = B[0].size(); Matrix C(M, vector<int>(N, 0)); for (int m = 0; m < M; m++) { for (int n = 0; n < N; n++) { int c = 0; for (int k = 0; k < K; k++) { c += A[m][k] * B[k][n]; } C[m][n] = c; } } return C; } C++ Freivalds Algorithm Matrix create_random_matrix(int rows, int cols) { random_device rd; mt19937 gen(rd()); uniform_int_distribution<int> rand_int(-100,100); Matrix mat(rows, vector<int>(cols, 0)); for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { mat[y][x] = rand_int(gen); } } return mat; } C++ bool Freivalds(Matrix& A, Matrix& B, Matrix& C) { int t = 20; const int K = B.size(); random_device rd; mt19937 gen(rd()); uniform_int_distribution<int> rand_int(0,1); while (t--) { vector<int> r(K); generate(r.begin(), r.end(), [&]()->int {return rand_int(gen); }); vector<int> Br(K); for (int i = 0; i < K; i++) { Br[i] = inner_product(r.begin(), r.end(), B[i].begin(), 0); } for (int i = 0; i < K; i++) { int ABr = inner_product(Br.begin(), Br.end(), A[i].begin(), 0); int Cr = inner_product(r.begin(), r.end(), C[i].begin(), 0); if (ABr!=Cr) return false; } } return true; } C++