LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX...

16
LECTURE 6 INTEGER & MATRIX MULTIPLICATION

Transcript of LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX...

Page 1: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

LECTURE 6

INTEGER & MATRIX MULTIPLICATION

Page 2: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Integer Multiplication-

:

Input : 2 n- digit integers X , Hyp 0pm !

Output ; Z=XYMultiplying 2 1 digit nubmses : top

will work w/ base dobut same db Addition of 2 I digit H : top

& analysis for base 2 . Shift by 1 digit" top

Primaysohodttts: Runtime; flatH : 2 3 45

y ; 6 7 89ever the shifts is# It 2-1 St

-r - d- t )

21 1 05

1 8 76 O et shift 4-121=0-47If 4 I 5- ← z

shifts

I 407 O e 3 shifts-7- 5 9 28 20 5-

Page 3: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Thonghtexpenhert-i.tt DC dig that divides X , Y Mto 2 ints

of nh- digits .

I > a ION't b Ex : a> 23 be 45

Yi clonk t d0=67 de

#XY= law"'tb) ( clothed)

- Y n digits = a clone ad WN't bcwnhtbd"

ii.7:47 'm't man xx↳one , adtbdhthtbd .

define a, b, c ,d as beforeVac -- DC-Muttu a , c)

Vad e a laid)

viii. this:b'

ar'

me""

→us

combine: lmp1 : race . Ion'

tmasitmp2.IOtmp : ad tube return;tmp1ttmp3t Vbd

Page 4: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Rvntnutthalysis, combine 8kg : Qin)Tink 4T LV) to in)

aahbbc2

9404121dat Ol n'0921 n') not faster-ra

YY , acwntladtbcdlohtbd.

Obj, we care about 3 number.

lilac Q : can we get these 3 numbers

ciiladtbc with only 3 recursive calls . of

①iilbd2 Mr digit members .

-

Page 5: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

-A: YES :

① a&m② bxd

③ Catty)x ( Ctd) = actdadeobctbd

↳ ③ -Cy - ( D= adtbbc② en

)

Karatsu.bo - 0pm 119627 Input IX. Y) are ' q

if 171,141=1 return XY . r'

define aibiccd as before.§Fa{Yjn④CtmNaed)10nAvac-ekoca.cl ④Nbd .

✓ bdzkolbcd)-

tmp - Kol atb ,Ctd)

→Oln )

Page 6: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

RontmeA-ralys.is#.Combme-Skp-?OLn)TCnI=3TCYz) to Ln)

8¥22,

a3

nbgp.nl - 5 'DFact : Can generalize ko to divide

k ints of Sta Mk .

⇒ Of plonk-D)⇒ O ( n

't') for any 60The fastest Ig :

O (n log nHog hogend

Page 7: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Matrix Multiplication :-

Input : 2 man matrices A.B

Output : CiAaB

, nannxn matrix j

t:÷÷÷i÷÷:s÷÷:÷÷÷÷ii÷:÷÷ .

Bydtn: cijay-2gaik-bkj-aizbajtaizbzj-cr.it 9inbron multiple orbs

* I multiplicate.'of my addition

atomic claret = 102 = Abn) ops.

I addDmlsubhutb If we stick to the Ifn of MNSofatomic

elements it of and compute each cij withOld 093

we get old ) alg ⇒ standardAtg .

Page 8: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Standard Atg LAB) pentru :for is I . . . n

for 5- I r . -n -7 @(pp) .

cCivil:O

for h : I r . .n

cciscjle : AliUk)#BENGT.

in.:::#Intent : Let's think of dividing A , D into

4%4%715 .

Cy 42

r⇒iE¥¥then each block behaves as an atomic elements

Page 9: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

"" Cij :( Air Bi ; ④ Aizu)4 Ymatrix addidµmatrixmultipliedhrs

Recall : Matrix Addrtos .

:÷÷:*:: :: : :cijzaijtbjj Ocd ) op .

Page 10: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

Damm 'Ll Aid , nxn maths ) Runtime Analysis '

Cn -DCMMKIAu.B.it#ABIR-

Chi 4 ( Ail,BiD④"lAh,BTCui " LAN ,BH④kCAu,B## The combine step.Cru U (Au,BcD④ U ( Au , -822

)nc,

return [ 41142-

Laid "L IHH 'Total Rusher.

Nicking additions perTent.HN/z)tO-ln4intohk.nIzo-C*Daa?zhi=soln4kn3?zotfa-

Page 11: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

strussenSAhg-l.tt , B mon matrices

Z, :Strasser ( Au ,

Biz -Bu) combine !

Zz ' " ( Aut Ah , Bu )$1275 -0174-02*2-6

732 " ( Azuay , B , , )Chi ZI④Zz

Zu : U l Azz,BzfB , , )Gli Zz④Zy

75 " U ( Aut Au,ButBzDG2=Z5 -104-04-02-7do

Zfz U ( Au -Air, But 1322 ) runtime at

27=11 LAI !- Ae , Bu -113,2) combine :0117 many or -0

Out)

Page 12: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

622 2- 1④Z~AM Bu - hi%BzztA#t Anbu= Ay Biz④ AnBzz

Runtime! Ten , = E-TING ) to laya-- 7 7222b = 2

du fl n'927ns. ) inenftftfpgDid

Page 13: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

History of MM-

201kg: n2.3.74

untpnp 1969 Old) 2.3728642

196920 ( n**) Ii n

FPI f ( p2-796 ) ly n

2.3728635

7920 ( n2.tt)8$: OC m2-522)8322 m2 .

-517

zn2.496

(IW86 = n

2.37g

* → = n2376

Page 14: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;
Page 15: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;
Page 16: LECTURE 6 - student.cs.uwaterloo.cacs341/lectures/lecture-6/lectur… · LECTURE 6 INTEGER & MATRIX MULTIPLICATION. IntegerMultiplication-: Input: 2 n-digit integers X, Hyp 0pm! Output;

EIofsub-blocksacthgasatomicelemerts-ccize.it:÷si¥¥¥÷EiCsl Gz C333 44

÷aAll XBI ,④ Aux By

- Ci , -- %)€22

EH END⇐

÷÷÷÷:*:*..=