## quantum computing sim

General FreeBASIC programming questions.
paul doe
Posts: 777
Joined: Jul 25, 2017 17:22
Location: Argentina

### Re: quantum computing sim

deltarho[1859] wrote:An explanation is required.

Indeed =D

Makes you wonder how reality even manages to remain bounded, if at all =D
Really, a pleasure sharing thoughts with you. I rarely have the chance of talking about these kind of things with someone this side of my computer screen. Hope the OP doesn't mind, as it seems both of us are apparently bound to rant wherever we go ;D
deltarho[1859]
Posts: 1569
Joined: Jan 02, 2017 0:34
Location: UK

### Re: quantum computing sim

paul doe wrote:Makes you wonder how reality even manages to remain bounded, if at all =D

I think because the random process is deterministic. If we toss an unbiased coin an infinite number of times the total number of heads divided by the total number of tails will be exactly one. So, we can determine the result. What we cannot do is determine the result of an individual toss. Quantum mechanics depends upon that. Quantum mechanics is much more accurate compared with empirical data than is relativistic mechanics. Even more accurate is Quantum Electrodynamics (QED) and that is even more obscure than quantum mechanics. We have a different story with chaos, which is non-deterministic. The quantum world may seem chaotic but it is the opposite.

Another factor keeping reality bounded is the speed of light. If an object came into the universe travelling faster than the speed of light it would never slow down to the speed of light - it would take an infinite amount of energy to do that. So, the speed of light is not a limit - it is a boundary.

Added: I have just ordered a book for my Kindle, 'Predictably Irrational: The Hidden Forces that Shape Our Decisions.'

Sounds right up my street. <laugh>
bluatigro
Posts: 576
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: quantum computing sim

update :
some error's that you al noticed removed

Code: Select all

`'' bluatigro 8 nov 2017'' quantum computer sim'' based on :'' https://quantumexperience.ng.bluemix.net/qx/experiencerandomize timerconst as double pi = atn( 1 ) * 4sub rotate( byref k as double , byref l as double , r as double )  dim as double s = sin( r ) , c = cos( r ) , hk , hl  hk = k * c - l * s  hl = k * s + l * c  k = hk  l = hlend subtype Qbitpublic :  dim as double x , y , z  declare constructor()  declare sub do_x()  declare sub do_y()  declare sub do_z()  declare sub do_h()  declare sub do_s()  declare sub do_s1()  declare sub do_t()  declare sub do_t1()  declare function get_state() as doubleend type constructor Qbit() '' |0>   x = 0  y = 0  z = 1end constructor sub Qbit.do_x() '' X gate  rotate y , z , piend subsub Qbit.do_y() '' Y gate  rotate x , z , piend subsub Qbit.do_z() '' Z gate  rotate x , y , piend subsub Qbit.do_h() '' |+>  z = iif( rnd < .5 , 1 , -1 )end subsub Qbit.do_s() '' S gate  rotate x , y , pi / 2end subsub Qbit.do_s1() '' S1 gate  rotate x , y , -pi / 2end subsub Qbit.do_t() '' T gate  rotate x , y , pi / 4end subsub Qbit.do_t1() '' T1 gate  rotate x , y , -pi / 4end subfunction Qbit.get_state() as double  return iif( z < 0 , 1.0 , 0.0 )end functionconst as integer numberOfQbits = 4dim shared as Qbit q( numberOfQbits )sub cnot( byref control as Qbit , byref target as Qbit )  if control.get_state() then    target.z = 1 - target.get_state()  end ifend sub`
bluatigro
Posts: 576
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: quantum computing sim

i fount some info on YouTube
s = sqr( 1 / 2 )
s^2 = 1/2

H( 1 |0> ) = s |0> + s |1>
H( 1 |1> ) = s |0> - s |1>

H( s |0> + s |1> ) = s * H( |0> ) + s * H( |1> )
= s * ( s |0> + s |1> ) + s * ( s |0> - s|1> )
= 1/2 * |0> + 1/2 * |1> + 1/2 * |0> - 1/2 * |1>
= 1 |0> + 0 |1>

Not( a |0> + b |1> ) = -a |0> - b |1>

e ^ ( i * x ) = cos( x ) + i * sin( x )

qureg x[1]
x = a |0> + b |1>
V(t,x) = x = b |0> + a * ( e ^ i * t ) |1>

i m not shure how to code this
i think we need complex number's
bluatigro
Posts: 576
Joined: Apr 25, 2012 10:35
Location: netherlands

### Re: quantum computing sim

i tryed somthing
`'' bluatigro 27 feb 2018'' qbit simconst as double sqr2 = sqr( 1 / 2 )type tqbitpublic :  dim as double i0 , i1  declare function tostr() as stringend type function tqbit.tostr() as string  return str(i0)+"|0>"+str(i1)+"|1>"end functiontype tqbit2public :  dim as double i00 , i01 , i10 , i11  declare function tostr() as string  declare function lenght() as doubleendfunction tqbit2.tostr() as string  return str(i00)+"|00>"+str(i01)+"|01>"+str(i10)+"|10>"+str(i11)+"|11>"end functionfunction tqbit2.lenght() as double  return sqr(i00^2+i01^2+i10^2+i11^2)end functionfunction equal( a as double , b as double ) as integer  return abs( a - b ) < 1e7end functionfunction hgate( q as tqbit ) as tqbit  if q.i0 = 1 then    q.i0 = sqr2     q.i1 = sqr2   end if  if i0 = -1 then    q.i0 = 0-sqr2     q.i1 = 0-sqr2 )  end if  if i1 = 1 then    q.i0 = sqr2     q.i1 = 0-sqr2   end if  if i1 = -1 then    q.i0 = 0-sqr2     q.i1 = sqr2   end if  if equal( i0 , sqr2 ) and equal( i1 , sqr2 ) then    q.i0 = 1     q.i1 = 0   end if  if equal( i0 , sqr2 ) and equal( i1 , 0-sqr2 ) then    q.i0 = 0     q.i1 = 1   end if  if equal( i0 , 0-sqr2 ) and equal( i1 , sqr2 ) then    q.i0 = 0     q.i1 = -1   end if  if equal( i0 , 0-sqr2 ) and equal( i1 , 0-sqr2 ) then    q.i0 = -1     q.i1 = 0   end if  return qend functionfunction notgate( q as tqbit ) as tqbit  q.i0 *= -1  q.i1 *= -1  return qend functiontype tm44public :  dim as double m( 3 , 3 )end type dim shared as tm44 hh.m( 1 , 0 ) = 1h.m( 3 , 0 ) = 1h.m( 0 , 1 ) = sqr2h.m( 2 , 1 ) = 0-sqr2h.m( 0 , 2 ) = sqr2h.m( 2 , 2 ) = sqr2h.m( 3 , 3 ) = 1function h2gate( q as tqbit2 ) as tqbit2  dim as integer i  dim as tqbit2 uit  for i = 0 to 3    uit.i00 += h.m( i , 0 ) * q.i00    uit.i01 += h.m( i , 1 ) * q.i01    uit.i10 += h.m( i , 2 ) * q.i10    uit.i11 += h.m( i , 0 ) * q.i11  next i  dim as double l = uit.lenght()  uit.i00 /= l  uit.i01 /= l  uit.i10 /= l  uit.i11 /= l  return uitend function`