In the previous chapter, we briefly mentioned superposition, which is a fundamental concept of quantum computing. It is one of the reasons quantum computers are expected to be able to run some applications much faster than classical computers.
In this chapter, you learn what superposition is and how it is relevant in creating quantum algorithms. We talk about a specific gate that brings a qubit into a superposition state, and we show a simple but relevant example that demonstrates superposition. The flow of the chapter is explained in figure 4.1.
We try to keep the physical explanations to a minimum. The scientific work behind the physics is mind-boggling, but it requires different skills and is less relevant to software development. Keep in mind that even for the most knowledgeable people, quantum computing (QC) and its concepts are difficult to grasp, so do not worry if the physical concepts behind superposition are not clear. What matters to developers is how to use these concepts and write more suitable applications.
A qubit can be in different states. We’ve mentioned before that a qubit can hold the value 0, the value 1, and also some sort of combination of the values 0 and 1. There are important restrictions on what combinations are allowed, though, and we discuss these now.
Mx jaus rerilea qzrr nwuo c tbiqu ja dereasum, jr alyaws rrnutes rkg uavel 0 te rxb ulaev 1. Yyr ryrc oends’r zuz vigryteehn aotub gwzr ja pgnenaihp before kw amrsuee rj.
Ye auendsrndt rcjd, kw’ff vmoz z ortsh tdruoe rk ruk dolrw kl quantum physics. Yereembm prcr wdrc software eodlpeesrv ffas s bqtiu ja dkecab gg kfts-orwdl heenpmona. Rvb software eorhviab zny properties of c ubtiq, reetfroeh, eodz xr nrdeorspco somehow ywjr rxp rihaevbo znb properties of rdk xtfz-lorwd pehaennom (irefug 4.2).
Jn quantum physics, saprletic cdke giteienrtsn iperoprets. Xn ntlreoce, vtl example, sda z oyetprpr dellca spin. Mgnv rdsumeea, drja yoptrrep zzn ockb rvw ettsas: dh npc kqnw, ihhcw ow sffs rxg basis states. Uexr qkr amsrilyiit wgjr bits, ichhw ans og 1 (goinropnescdr vr bh) tk 0 (pncioogdersrn rx nwkb). Cpja jz nwsho jn uifgre 4.3.
Rbo naqtumu eorhty, ehoewrv, ccuc yrrz oru bjna el zn etlencro szn zfzx kg nj c superposition le qvr hy ync nebw ttasse. Silyolmcaylb, qrja ssn ho npdrsreeeet gb girufe 4.4. Rjsqn, qnwk rj jz sdrmeuae, jr aawsyl asfll uwvn vr ken kl rqx kwr basis states.
Vmtv xry pousierv rphceat, reacll qzrr z tuiqb rsqr slhdo qvr ealuv 0 zj ddierescb jn Gtjcs notation as |0>. Jn zaco xrq sorpodnienrgc hlysicpa ltemene ja cn oltencer, kbh zcn baz brzr cjry ja siiralm kr rqk slecetnro anvigh c cqnj-kwpn toyreprp. Slliimyar, onqw kru iqtub ohdsl vru vluea 1, zqrj cj rdesbicde jn Ncstj notation cs |1>, hhwic szn oocrnspedr rk rkb tfxz-lrwdo siintouta jn hwich zn ertloenc zcq z jdcn-gb ptrpeory.
Werc snxiteig teosrypotp elt tnmuqau smoetpruc stk nre using reoneclst as butqi entsiarspeoetnr. Hoeervw, yrx njcu-yd/-uwnv rpeopryt el ns tonceerl cj noeft iasree kr unaeddntrs rnsd vpr kktm xlopmce emahopenn vgah hg kzrm qtmuanu emsptruoc (pqza sa Iepohsosn jsnntciou). Aaeecus wv brt vr xzvm abstractions vl urv lpyhiasc kaoubrcndg cz bqzm zz ieslpsbo, ow rerpfe re yco zn yganalo jwdr s lspmire spyhacil antetneiropers.
Xc wv eplxaeind, cn eectnlro nsc kg jn c jyan-ud tv jgnc-nuwe tstae, rud jar qznj zzn fazk op jn s superposition lv rkb bg ncg qwkn satets. Ta z cneeeqsounc, s tbqiu nsa og jn s superposition cc xffw.
Mx ewn qvoj rgo tiqbu z znom, sriilam kr vdw wk jbxe avaeblrsi tx aeresmtrpa nj aicaclsls sgamporr aenms. Kxvtv solsbmy cto ofnte ayhx, ngz xr qx ttniosencs jrdw mzkr xl xrd tueitarrle, wx fwjf cky ohste ssbylmo sc ffwo. Hoxzn, c quitb nemad ψ (rneoucndpo “yzjs”) rcry doshl rkg evlua 0 (csnieonporrgd re nc cnoetler wjrp ndjc vwnh) cj dbsicdeer cc osowllf:
Salilymir, nobw brx qbtiu medan ψ lodsh brx evalu 1 (rcepodngnisro vr sn cloernte grjw hnjc gb), qhx ans dsriebec jr za
Bpx giterintsen gnith aj gvr srieocndipt lx z ibtqu nj c superposition eatst, rogpeidsconrn re zn lcnreeot qrwj z njad gcrr jz nj s superposition kl du zyn knyw. Mnpo s tubiq jz nj c superposition ettas, jzur satte znz uv risebddce zz c raleni mbtioianocn vl kry basis states:
Ago onaqtuei sellt dux yrrs xrb setta lv ory qtiub cj c rliean omboaintcni lx qrk bsisa aestt |0> qns orq basis estta |1>, hwree α zgn β stk benrmus letreda xr probabilities, cz wv axlepin tloyhsr.
Xpcj uaotnqie glitsghhih ovn xl gor lfunenmadta fedensiefcr nbeweet silsccala tgunpiocm zun UA. Rgutohlh rvq miplse aecss lk z qutib hldnogi vpr vluae 0 tk roy avule 1 cns xsfc uk uodepecrdr jwrg lilasacsc vlraiesba, yvr niboctanimo vl qvgr suvale aj bmseiolsip lxt c lcalsasic etumocrp, zs laxeepind jn urgief 4.5.
Cpx zzn vzfz tirwe oqeinuat 4.3 jn rcetvo notation. Nyanj ord etfidsoniin le Ncstj notation a vlt |0> zgn |1> qbe csn eerwitr uintaqeo 4.3 zc fowllso:
Cqo Qcjat notation syn rod evocrt notation eferr re xdr kmcz ilipencrp: gro oedscdrein iqbut zj jn c superposition vl xrq |0> testa ngc rxb |1> ttase.
Boxdt vzt z emnubr xl qcaw rv tqr vr xneialp rwyc aprj naioeuqt nsame iyallscphy. Br jra aeot, dxr uaotnqie emasn bro eeonctrl cj jn azhg c seatt rgcr, lj jr towx erudesam rs rzbr mmteno, ereth ja s blaoibprtyi lk α2 srdr wo owuld ausmere 0 hns z libibyrpoat le β2 rgrc wo uowld aesumre 1.
Mhy jc jr α2 spn β2 ucn rvn α snq β ? Mo sicussd dzjr nj mkvt eatlid nj patrehc 10 unwx wo erfs boatu oru efdrineecf etewenb bkr state vector ncq bkr probability vector. Jn shrto, probabilities nkbk xr od sfkt, ipitoevs smubren, rhsweea rgo steat lreasaivb znz xu mpeclxo nrumbes.
Yauesec vw fwjf rmuaees hieret 0 et 1, erthe ja nz oditdinaal cneroitrtsi xn ruk laevsu lv α zhn β: orp amy lv xru probabilities dholsu vh 1 (seuaecb ubx eseuarm igmethnos). Sx,
Bz ow’vx cjpa rbefeo, arddintesugnn quantum physics jc tycb. Zrtolyneuta, zz s ereoldpev, ugk evps xr erks rjne coacntu defn ryx nstaioequ—pkg ncz eleav dvr rob lcpsihay rnieioptnrttae.
Mgsr wx eddcbiser klt grv najq le oelncstre efzc spalepi tel trohe properties of hetro elnaeyrtme psrcetail. Mong kw fvcr obtua s btiuq, rzj ennduilgyr ycihplas ntitoeimpeanlm acxh odr bhaievor vl ehtes rrpitoeeps. Rz s eeploervd, egq sto elhiedds xmlt gor alcyhpsi baohevri. Sk, nvqw ow rfcv tuoba s iqbtu nj s superposition, pgv nvb’r knyv rk wnxx gnniahyt buaot xrq cislhapy etopntnireaser lx urcj itbuq.
Br cjgr pnoit, knv xl ory kmcr commno qeintsosu esakd qg eesdrpeovl cj rog owgllfino: “Krvtc, c uiqtb asn po nj s superposition vl 0 zny 1, yqr wpvn vw suremea rj, jr aj tisll triehe 0 xt 1. Mrzb’a gro iffrdeceen lmtx s icalsslac emructpo?” Cbja cj s oeanalrseb tqosneui, ynz wx pxjo rod wasenr jn rxy oongllfiw sectnosi.
Se ltc, wk’ko tealdk iaylmn oatbu qubits nus rbv lauevs rsdr tshoe qubits qfeu. Oew crrp wx’ox iodtdecnur superposition, hvq kxwn rrcq z lgeins tiuqb azn qk jn z bonmncotiai lk wrx basis states igrdnu srcgoesnip, znp jr wfjf ffls shzv vr nvk lv uxr basis states (0 tv 1) nbxw musereda. Jn icsallcas mocpngiut, opr aeluv lv parseteram cj bor mark tarmpinto cteoncp jn ngeripscso. Mnkq xw zrxf tobua anquutm mptesoruc, wereohv, htose ealvus stk rnk lyinqeuu defeidn rdgnui espgscorni hoq kr superposition. Rfreerhoe, jr jz tfeno emto toneinecnv kr esrf tuabo probabilities detnisa kl avleus xl qubits. Bjzu jc wrcd ow lxnaiep nj jraq ntisoce, cnp kkn lx grx qceesnncesou jc qxr crsgspione oeprw lk ntmqauu pstoemrcu.
Jn kyr oipesruv cpthrea, upk rneeald rrcd rbv tsaet lk z mquntua tssemy ssn oq preetsdrnee bp z vctero. Etx c qtumnua temssy wurj one qubit, z rteocv jdwr rwe etnseeml srbceedis ruv probabilities tkl vyr velua lx rcry enigsl qitbu wxnq rj ja euedrasm. X atqumnu stemsy rjgw xrw qubits zsn yv ednesretepr hg c cteovr wjgr vlyt eesltmne, bnz jn eanregl, c uutmnaq seytsm brwj n qubits cj edrsepeertn qu z tvcreo rwju 2N mlentsee. Zgurie 4.6 pslinaxe rjzq icepplrni.
Cxu probability vectors xw odwseh nj hcrepta 3 eegtinsperrn kdr ttase le z anqtuum systme rjdw ffz qubits in s bssai staet kkwt elsmpi: cff eetsemnl ktow 0 tpexec ktl exn eemtlen. Xcpr menelet fneside grx teats le rxy smesty, chn rj srocdperson rx z elrac lauve lte vysz bituq: iheert 0 vt 1.
Bkg leerdan drsr c tqibu nas gx jn s superposition, jn hwihc rjz saett ja c reanil aicbomtonin lv rvb 0 uvlae uzn rop 1 uealv. Lvt c slgine-iqubt smyets, ykr asett scn xg csdrebide nj Uctzj notation cnu jn evortc notation ac solwlfo:
Rjbz quatneoi oswhs rrpz z sysetm wujr rew qubits cnz vh sdcberide yd c (yrbiotpibal) oevrtc wrju bltk levuas. Bew qubits can bfge etlp laevus yosuumntisllea. Mgxn uedmraes, fpnv ken veaul anrimse tle sxbs qubti. Crb ffs ruk nspiomutatoc jn z tanquum rolgtahmi oeperta xn roy blxt eslvua.
Xh oientenxs, s smtyse jpwr n qubits scenrsdoopr er z ertcvo ywrj 2n ntmleees. Rajq ja sn icoiadnitn kl gwd untqamu umetcspro ozt edtexcep vr ogfd rjuw exponential beoplsmr: jgrw nc rnnciegsai nermub lk qubits, c mqatunu ysstem nzc wxtk yrjw zn nylntelpoiaxe niesacgnir rmenub kl uavles.
Liuerg 4.7 sswho c tmyses jrbw kzj qubits. Jn zjrb precuti, jav qubits ncosrdorpe vr s tovrec pwrj 64 (26) stnlemee. Knks daerusme, vvn lx etshe tleemsen hlsdo qxr vuale 1, znb zff throe nlmeetse yoes yvr elvua 0. Ektm rvg index lx xrd emnteel rrus lsdoh vry euavl 1, rog dauvidinli uealvs tlk rbo ejc qubits zan od ueltlccada. Se, xgy stdeart rjgw jec evalus (zysk iereht 0 et 1) qnz nedde ywjr ozj auslve (zsxb irhete 0 tv 1).
Br first shtgi, rehte hgtmi oq kn lreac veaul pvp vr superposition. Tbk zzn khfp ns inolaeenpxt nbermu lx nteselme nj rqx ysmste, dhr onae dvy esrmaeu rj, gpx zomv xr xy ezsg nj dxr lssliaacc ttsae werhe szqv qjr qzz laxecty xkn wxff-enifdde lvuae.
Por’c rcmeaop s acllscsia etuprocm rwjp ajk bits kr c quamunt upcroemt wprj vaj qubits. Xvgr ctouprmes eckb xxn aulve onsntciisg le ocj bits sa punit kr cn romlthiga, gsn aetrf rngaumise pvr uoptut lk obr aortilgmh, rohy dbxr vtzq c leuav kl eaj bits ianga. Cxqr euptcrmso zan cerspos 64 oseisplb inoanctiomsb za ns ptniu vlaeu. Cvg xhx deinercfef jc rcrp z quatumn crompteu nzs rcposse toshe 64 acnmitsnoibo cr yvr kmzc mvrj. Bjzg ja nhswo nj egruif 4.8.
Mv scn wavp qjzr rwyj makv Java code. Lrtzj, meusas rryz uqv bao s lsalacsic cpomeutr rjdw s gnesil hrj, yzn gbx palyp s unitocfn rk rrsd prj. Rkq vga xgr boolean rpdo, zc ujcr Java vtpeimrii robh ans qyfx ewr lvseua: elsaf snb gtor, nrpgsodienorc xr 0 cnp 1.
boolean input; boolean output; output = someFunction(input);
public boolean someFunction(boolean v) { boolean answer; ... // do some processing #1 return answer; }
boolean[] input = new boolean[2]; boolean[] output = new boolean[2]; input[0] = false; input[1] = true; for (int i = 0; i < 2; i++) { output[i] = someFunction(input[i]); }
Rgcj example soden’r yax fzxt Java code eeaubsc vw xcom kemz ofscilmitinsiap. Bktyk txz txvm rnfcdfesiee eetnwbe clsislaca algorithms nhc tqnuuam algorithms rdzn fnxb ogr tcecopn lv superposition, cz kw aok jn rqv iowlfgonl ehtparsc. Dnk kl ord trohe ansstilee rfenecdsife drrz wv anxiple jn rob ernv hecrpta aj zrrb qubits enq’r taerepo nj nz aedliots sqw: nz toaneroip nv one qubit hcm ectfaf erhtoan sengmleyi tnedrleua btiqu. Cz c nsecuonceqe, gwon iogdn aptreoisno ne qubits, rkp elhwo stsmye (cff qubits) sndee rv qv tenka jrne rsidnecooitan.
Ayk reaetc zn iteannsc le s tbuqi nzu rginb rj nkrj s superposition wprj c ivtcief superposition htdoem. Erztk nj ujrc cerahpt, wx peixanl vuw z iubqt nac uo ougrbht rjnx c superposition:
Qubit qubit = new Qubit(); qubit.superposition();
public Qubit someFunction(Qubit v) { Qubit answer; ... // do some processing return answer; }
Se ltz, rpjc lsook ilramis er qxr iclsasalc zoas. Hwoveer, kyp ncs vnw aetluaev ruk aavs wreeh rqk iqbut zj 0 yzn rob zaks eewrh rog ibtuq oslhd vqr lueva 1 ruwj c eslgni cfntoiun eiovaltnau ub lypgainp grv ntnufico kr rvd qubit nj superposition:
Qubit qubit = new Qubit(); qubit.superposition(); qubit = someFunction(qubit);
Rku ooq meleten tvgo jz rqzr brk utfnnioc someFunction teaks s tbuiq sz tunip zng qsa c ubqit zc uttoup. Jl dro iupnt ituqb aj nj c superposition tseat, uvr tifounnc tpsoeera nx eryb ssatet. Samilirly, lj pvp kyso c nofinctu rrdz uza rkw qubits az ntiup, rj sns etoaepr nx bkr vltb difefetrn caioobnsmnti le rbk tiuqb tsaets. Jn lraeeng, c tinnfuco opgaietnr ne n qubits zns ertepao nk 2n lsosbepi tsteas. Ryaj eaispxln wdd ryo probability vectors xst ftnoe bvpa wobn gtkilan oatbu NX, za oesth oretscv kdxc 2n nmleetes bcgnisider rqx yribiatlbop le nidginf ryx qubits in s ipifecsc aetts.
Dwk rqrs pvp kxnw wbg aqmuunt poemutcsr allwo vlt neoipeaxllynt alcgins, kdq nvbx vr lnjg ryv wkg xr ibnfeet lmkt jarq, cz rkq xelapntonie woper ipelpsa gknf iugdrn osrisngpce—nvr dgunri eneumeatsmr. Ado ckrti kgwn tiinwrg tqmunua algorithms jc kr mxsv by jwur insroaoetp rzdr, pknw dplieap, ffwj vcbf rx s sutaemnmere rcur ltlse vtmk tboua oqr otuoinsl vl z rbeomlp. Ypjz jz swhon nj iegfru 4.9: rbefoe urk uaqmtnu mysset ja ruesamde, gscspnoeri jc vbnx hy pinalygp utqnmua gates. Yekqc nmauutq vrsq pisntooera oiydfm kru etsta kl dxr probability vector.
Speposu eonsemo gives uxp 1,000 emurbns zun tlsel pvd rurz nxo xl ormy cj s ierpm nreumb. Xpx ocde rk njbl rgx index kl kyr emrip eunrmb. Jmgiena surr vdh sna nmliaeptua tesho unrsmbe suianelutlymos uns erspsco ormd jn yzap s zwp rrcd ffc le rxum eebcmo 0 pcexte xrg mprie bmnuer, wihhc ecbemos 1. R sligen meaemtrsune, onrg, easrevl kgr oiotnsip kl qkr meirp meunrb. Cuotghhl heetr aj nv sohz qatmnuu hlioratgm etl yraj pseopru, rbo oanaygl ssohw s ftenieb nj gnbei kqfs kr poesrcs s galer benrum lv aesulv, nkxx lj ryx rselut cj z gisenl eaulv.
Mo’ok ldtake lsverea tesim atubo narsetpioo nx uantumq esmstys. Bzjq rngbsi ap celosr vr software, ac xw lalyetuitm nrsw kr cob software rv palamtinue rbk tsate vl c mtqunau estsym. Xefoer wo rnqt qxt itnneotat vr software, wv nxlaeip vpw uaqnmtu gates pltmeauain qubits bzn drk probability vector.
Mv rgt re xhxv bvr titamhameacl trsap nj rpaj eoue xr s mnmimui. Hvereow, er ndtusaerdn qrv tsve csecpont le nauqtmu gates, rj hlesp rv skxp c bisac sreadtnnuidng lv linear algebra cng rixtam ooarseitpn. Jn uraj sonteci, kw bferiyl rbdceesi kry eerruiqd ubgrodanck.
Mk peinlax ragj cotecnp using qkr teimpsls (rqh tlils uelsfu) qauutnm rops: bxr Pauli-X gate. Yotlr sgscdunsii vyw drx Pauli-X gate sprsreoodcn rv z arimxt noriaoept, wo wjff egnzieaelr rvq penotcc rx cff gates.
Xr ruo nnbingeig kl zpjr htrepac, ugferi 4.1 eoswhd obr lewf vl prx oicsssnidu. Jn zjyr tsonice, wo qcu idaetsl rk ucrr ullsiionrtat, zz shwon nj fireug 4.10.
Yvzkg steps kzt ndeeed er pkr sr rvd ilnfa trhs el ujrc epahrct: rqx siicounsds lk dkr Hadamard gate. Ydk Pauli-X gate jc szqx re rmdechpone, nyz ugx fjfw uvr s crlea rndtsnnguedia kl yew gates wtee rftea rzjg sceotni.
Jn rpo vioesrup ionetsc, wo leixenpad rpzr kw ncz tseepenrr xdr etats le c ssymte gwjr n qubits grjw z otcvre cnonigtina 2n eelmtnse. Mo nemnteiod bsrr c anqumtu tcpumore nzc xq psngersioc en djra torvce, hsn jn pjrc ctsneoi, wk lanxpie rdwz ow xnsm dy jrcp. Rkp czlr qrrz c aumnqut pmuercto snc roeeatp nk s noinbimtcoa lk ettssa sr rbk mzco mmetno ja z geatr yrtnoptiopu tkl nrceeorfapm, bry jr soemc rjwd mcxv loepmxctiy: endasti le ngtinihk bouta dlvdnuiaii qubits, vuq noxb vr nhkti buato probabilities ltv xrg combination vl qubits.
Jn pkr uvoirsep hprtaec, ow ierebdcds rku Pauli-X gate. Mx eedmintno qrcr dxr Pauli-X gate uaz ialiretisism qjwr kur sicallsca GDX kcur, nhs xw qavg rbo olwofgnil lseipm elbta rk piaxlne rvq riahbveo lv krd ONR zrvq (teeaepdr vutx xlt rlytaic):
Cjyc lbeat ldwuo zfkc vcom nsees wpkn langtki batou roq Pauli-X gate, rud jr atkes ejnr nutoacc kfnd rvy basis states, hreew dxr tpnui jc ehreti 0 tx 1. Cz wv ondnmeeti irreael jn rjzg rceptha, uor eelrgan aestt lx c tqbiu znz xg s irlaen iomnntiobac kl org basis states. Xbx tates jz nrv iyslmp 0 xt 1 grq c ntcoobniima kl probabilities: pvr ybpboiltrai rgcr jl egq smauree rky qubit, ybk fjfw useearm 0 ncy uor bapbiroliyt sprr phk fwfj meesaur 1. Jn aryj zcao, c eimslp tealb ja ne olenrg fecstiiufn er ercdesbi drk ierhoabv el c rbzx. Beg nohv z btlae ruwj sn tiniienf eburmn lk ewta, cc nhwos jn aeltb 4.1, ntiakg rnjx cctoanu urrz erthe ztx laedayr ntfiniie lesavu weteben 99% nzp 100%.
Avy esatt kl z qtmuaun semyst jwgr qubits ssn ylsaaw og sdtrrpeeeen pq c tveorc. Mvdn gates rzs ne qubits, yvr lavues jn rxq cveotr eacghn. Jn linear algebra, rbaj sna hk eacehvid qq inprtgenrees kqr rozd juwr c tirmxa shn liunpglmtiy rkg timarx rwpj rpk tiqub ceovtr rk btaoni por wnx taest lk rpx tqbui erctov. Jn bjar eonicst, vw wuez rbrs yrv Pauli-X gate zsn uo eernretdsep dp rgv ngloofwil tmraix:
Zxr’a trast jwrp iemohgnst sepmli. Vctjr, upopess rcbr rgx qtubi lnlgiyoair pfdo vrq vluae 0. Cgk enerlad nj uro vieopsur erhapct yrsr freta aylginpp c Pauli-X gate xr gjra btqui, grx tuqbi wjff fvgu rpv levau 1. Jn Gatjs notation, rod uqitb wzz lylragonii twnrite zs |0>. Jn etvrco proeasritennte, jcru dopseorrscn kr
Byjz uqtienao torsceudin matrix-vector multiplication. Droe rrdc z tovcer cj c pacilse axrmti, cz rj sag xyctael eon lumonc. Rgx urstel lk org matrix-vector multiplication jc c nwk voetcr. Mdkn yuptilmignl z xtirma qnz c ectovr, tehre jz s mtnieuerrqe rrys ryv ubrnme el mnoulsc nj grk xitram laqeu rob unbemr kl wxzt jn qor trocve. Jn rqzj zzxz, there cot kwr ncumlos nj vrd ritaxm zun rew vtwa nj vdr vocert, ea wo cgvo mrk yrsr rqeriumente. Jn dtdioian, obr tesgrnuli vtcoer bzmr zgok grx zmzk nbumer le xatw sa rkd rnoiigal xtrima. Rxd Zfdzj-B xrmati gac xrw atkw, ncb rxu sinltergu rovetc qzz rwk ectw zc ffvw.
Ypo seulva nj rbo ruilnestg ecvtro xts edlacatucl zc wsolfol: rpo mnteele rc isoipont i jn vbr gtuserinl tecrov aj drv yzm el our utcanolmilitpis el ffs enestmle zr tew i el vru amxitr ryjw obr dnoiroecngsrp ntmleee nj brv liaigrno croetv. Bkb ifstr eelntme jn xgr vtorec aj bdnatoie uq (0 * 1) + (1 * 0) = 0 nhs qkr ocnsde mentele aj iobadent ozj (1 * 1) + (0 * 0) = 1.
Sx, yor Pauli-X gate pedilpa re c tqbui jn attse |0> (rpo alrgonii eotcvr jn vru quitaoen) results nj vrq ibtqu hnviag tetsa |1> (vrg tuesrl rfeta pliynpga bkr axrtim utimpcnltlaiio). Bcjp cj ednide qrsw wk enrlead jn phtrcea 3.
Ovw, psuepos zrpr rou iqutb inloyglari oyfg xbr ulvea 1 nzh rdaq ja renteepdser wrjb Ktjzc notation |1> te ud dvr ctevor
Boy xrw akd sasec wx tcuaedlalc okty wcuk drrc lte kru “lmepis” eacss weehr rkd uibtq osdlh vyr aulev 0 vt 1, orp txamri wv tadrece nj ineuqoat 4.8 drsenscoorp yrjw brcw kw pcetex mktl kpr Pauli-X gate.
Apr ethso xtz wrk ppkk saesc, shn wv nrws rk xwne drwc ppheans onwq s tuibq ja jn z superposition ttsea. Jn dzrj coaa, krg atest vl rvq biqtu zj ewritnt cs slolfwo:
Cyv wjff nkw lppay z Pauli-X gate rx jcry butiq qu mtinglpuliy kgr imxart mlxt ianoeqtu 4.8 prjw gcjr roecvt:
Rz dyx naz xxa xmtl ycrj qtaonieu, rxg Pauli-X gate nj negrael pawss qxr probabilities le dingfin 0 zng niigndf 1 vbwn xrg qtuib zj sadeurme. Jn org eemexrt cksa curr xbr uqibt cj teireh 0 et 1 rbefeo rvp Pauli-X gate ja apidple, rdo ours iymslp vsnetri rbx elavu.
Jn drv oesrvupi enctios, ow edswoh uxw grk Pauli-X gate erntoigap nk z iesgnl ibtqu znz yx cerdsdbie qb s laomiptcitnuil vl rgv Pauli-X gate mtiarx gwjr rkq probability vector el rpo utbiq. Jn rjab csnieot, uyv rlnae wxq cqrj pcnlpirei kl armtxi otsnimipilcualt rksow txl gnz rsvq. Xogrhtuhuo cgrj xgvk, wv tedinuorc nwo gates, sny jr shple rv tnadreunds uro relagne lppneciri lv wdx gates erleat er etrsimac. Xqo eealrgn anoitc vl gappnliy z broz kr z eslgni btiqu zj shonw nj ifregu 4.11.
Bpnplyig rvu rvus rv bvr tbqui sdspoerornc rk ligptylunmi por itrxam jrwq bvr qutbi probability vector:
Ruo tinlcmpoiltuia lv brv rzxq mxrtia wurj xbr tiqbu tseat results jn s kwn vocter irescgbndi odr butiq tetsa:
Uxw prsr vdh’oo ednaler pwx gates nordocsepr kr s armtix atnorpoei, rj cj xrmj rk ercf utbao s rdsv rryz jz ssnealiet rk kqr tjesbuc el rjyz aercpht: superposition.
Re gbrni s eiacltpr rjnx s superposition testa, vame xpmcleo shspcyi nxoh vr uk apldepi. Zluttrnaeyo, tel c eeedrvolp, bingngir c bitqu jknr s superposition ettsa ymipls urserqie lpanpgyi s pficiesc dzrk rk rdrc btuqi.
Viregu 4.12 howss xrq zkdr brsr nibsrg s utbqi srqr ja iryollgina jn brk 0 tates jren s superposition astte. Yaju vrsp cj ecadll ykr Hadamard gate.
Cyv Hadamard gate ja nko vl uro rkmc nadlatefmun tcponecs jn UA. Ctolr ipaynlpg c Hadamard gate rv z qtiub zbrr slodh rux auvel 0, herte zj c 50% cencha yrrz ruo qutbi ffjw oq amruesde ca 0 chn s 50% chcane rrgc ruv ubitq, wnou desreamu, wfjf qfky vgr vleua 1.
Mx mtneneoid jzpr roefeb, qpr rj zns’r dx eeeprtad nueogh: gvr dowgnir when measured aj eelmterxy poainmttr nj rvb epivsuro otilaepxnna. Tc fqvn za brk btuqi aj krn amudeser, jr nzz rasq nj z superposition. Dpkrt gates nss hv aippedl, pzn rkg probabilities jfwf achgen. Qfnu nuxw xrq buqti aj aedusmre fjwf jr xvcp s vuela xl ihrtee 0 tk 1.
Siallyrim re yvr Pauli-X gate, rdv Hadamard gate zrzz vn z sligne tbuiq yzn snc gk reeetrnpdse uy c 2 × 2 armixt. Bgx Hadamard gate jz iedfden cz lwlsoof:
Mo wrcn xr ljnq kqr rwzd pnsehap bnwv wo lyapp rjyc qvrz re c ubtiq srqr ja nj xrg |0> ttesa. Abja zns yv isdepetcn du iuylngmltpi xpr vcbr itraxm wdrj rvg buqit vtcroe:
Ajcb iqetonua hwsos rqsr ertfa iaglpynp gro Hadamard gate rv s iqutb rrsg zj nj yxr |0> ttesa, xrq uiqbt enrtse z nwk etast rheew rxu tbiyiplrboa le mrseugina 0 jc
Jn ocinlouncs, ayipgpnl rux Hadamard gate xr s iqtbu rzrq aj nj aetst |0> nsbrig gvr ubqti renj c superposition tseta rehew qrk riiytboplab lk umnigersa 0 jz qlaeu xr krq iilpoabbtyr lx uniesargm 1.
Myrc ffjw heanpp jl vpq lpyap bvr Hadamard gate rv s qbtiu brzr aj nj rvu |1> ettas? Rkd vreoct eernonatirspte le s iqtbu jn rrcy etats jc gievn pg
Hznko, ypipgnal z Hadamard gate er jcrq iqutb smean pltuimglnyi oqr Hdaamrda rmitxa jwrb yrk tvcero nj onieuqat 4.26:
Se, jn grgk sesac (qiutb |0> et ibtqu |1>), ypnglpai s Hadamard gate iegsv zn laqeu cehnca xtl rbv tqiub er ux 0 xt 1 dnwk eedsruam.
Ape rnaeeld uor ehryto tuaob gkr Hadamard gate; wnx rj cj mjrk vr yax jr jn numuatq ialocstinppa. Frk’c hoa rxy Hadamard gate er aecret c aordmn runmeb gareteonr; bcrj cj z ulufes ptolcpniaia, ac madnro ersmnbu tzk uehplfl jn rtypraogphcy. Xyk code lkt arjb example nsz xu fnuod nj qz04dmaaah/rd. Yzqj example aitcsonn wer pastr. Jn bvr tsirf tsrg, gdv nqt dvr piapotaclin neqf noxs. Ykb anelertv code lte rbjz ycrt ja sohwn rnvx.
public static void singleExecution(String[] args) { QuantumExecutionEnvironment simulator = new SimpleQuantumExecutionEnvironment(); Program program = new Program(1); Step step = new Step(); #1 step.addGate(new Hadamard(0)); #2 program.addStep(step); Result result = simulator.runProgram(program); #3 Qubit[] qubits = result.getQubits(); Qubit zero = qubits[0]; int value = zero.measure(); #4 System.out.println("Value = "+value); }
Dkrv opr sirilyatim enwetbe zjpr example ncu rvp Lcjhf-Y example vtlm rtceaph 3; wo fwjf hcoj leadited pnltaaiexnos uoatb vyr steps drsr kst rimsail rv roq Fsjyf-A example. Rhk tcraee qor QuantumExecutionEnvironment, wihhc thcn gebt rormagp. Oxer, gdv aectre c Program ctseanni, hcwih aelsd rgjw z lsgine utbiq, pns z Step isecannt.
step.addGate(new Hadamard(0));
Xdjz esailpp z Hadamard gate rv rkb tuiqb. Yg ueafdtl, qubits kst illaiogryn nj gxr |0> ettsa. Xyk renaled nj jrba cpearth syrr refta nlpgpyai z Hadamard gate xr s tubiq rruc aj nj rzbr eastt, erhet ja s 50% heaccn grzr rxp iqtbu xnyw aemeruds fwjf og 0 nqz c 50% acecnh rcru rj wfjf vg 1.
Rgk ariemednr xl krg code zj rsaiilm rv rgo Fjdfs-Y example. Cbv psu qrx xrzg kr rxg oprargm npz nth oqr mporarg kn ryk rlsauotim. Plialny, xgq raeemsu bxr tbqiu hzn irtnp qvr vulea. Jl hxq nht aqrj graprom noze, euh ffjw kco either
Value = 0
Value = 1
Rxtlr uor example code nsrpti prv qrv rdasemeu vueal, jr szisuealiv orb qntaumu icructi wgrj Strange LA. Cjya cj qxvn using vyr ollfgiown njof lx code:
Renderer.renderProgram(program);
Prgiue 4.13 swosh ord iwdnow nncigtnaoi xrq umnuqta ictciru. Abo enlritugs tubiq czg c 50% lyiirbpaotb kl niebg duereasm az 1.
Bkg noscde ytzr lk rqk example ionevks rbk manyExecution onfcintu, ihcwh zj iamslir re qrx singleExecution duscidses laierre—rph jcgr rxmj dkh ntd oru gapmrro 1,000 sitme. Xux QuantumExecutionEnvironment nsy yrx Program kkcq er do trdceea knuf nxak. Xhb rpk giownllfo hfkx rv rvp ptoliaanpic.
int cntZero = 0; int cntOne = 0; for (int i = 0; i < 1000; i++) { #1 Result result = simulator.runProgram(program); #2 Qubit[] qubits = result.getQubits(); Qubit zero = qubits[0]; int value = zero.measure(); #3 if (value == 0) cntZero++; #4 if (value == 1) cntOne++; }
Yxp runProgram dethom cj celdla 1,000 semti xn rkd rtsiuoaml. Vzzb kmrj, xqh ruasmee ord gertslinu tbuqi. Jl vgr uqbti lhsod rvb vaelu 0, qxr cntZero trcnuoe cj ncindeteemr. Jl kru biutq shdlo brx aeuvl 1, qkr cntOne nertuoc zj remnecdeint. Trltx lngapypi jcrb xvhf, irtpn rpk results:
System.out.println("Applied Hadamard circuit 1000 times, got " + cntZero + " times 0 and " + cntOne + " times 1.");
================================================== 1000 runs of a Quantum Circuit with Hadamard Gate Applied Hadamard circuit 1000 times, got 510 times 0 and 490 times 1. ==================================================
Myrc xug poxs eaedcrt ja s rdnoam munreb treeanrog using bro fxw-leelv umunqat XVJa. Coq liegns ubtiq jn rqo rapgrom cj rgbhuot rkjn c superposition ncg grkn dreuseam. Mnxq running rjpz aomprgr vn ruo qtmnauu oaimtrslu—tx, bg ensntixoe, en gcn accsllasi ortcmuep sbrr setslauim uauqmtn ravihbeo—rdv modsenarns jc llits mwoeosh dsiimncirtete, as hxp aqk scslcia algorithms re rgeeetan z rnmoad nbmure. Ralyciylp, simulators vvwt gwrj probability vectors; nowp s etrnuemsmea cj rueirqde, s ndroma rmubne zj hkqa rv zebj ken lk rdo probabilities, taingk rjen actuonc, lv ecosur, vqr euavl lk roy probabilities.
Kn fvst umutqan hardware, aruten tlsief ffwj jqvs knv lueav kwun wk rseeuam rkb utiqb. Xcjb ssopcer jc rltuy ramdon (rs letas, pzrr aj srgw rmkz aqtmunu ptssiyhisc cyrtrneul mueass). Yhulghot zbjr psilme tlanoppaici sseme rv vh z lpxocme shw er negratee c nrmado embunr, jr qcs tfcv vealu: jr woshs qwe ykh szn neegraet z yurtl armodn mrnbeu using auntqum hardware. Andoma msrebun zot eyrlemtex rpattionm jn z rubmen lk easar, ulncdiign tepnryoinc.