quantum computing sim

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

Re: quantum computing sim

Postby paul doe » Nov 08, 2017 3:07

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

Postby deltarho[1859] » Nov 08, 2017 7:20

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

Postby bluatigro » Nov 08, 2017 8:58

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

randomize timer

const as double pi = atn( 1 ) * 4

sub 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 = hl
end sub

type Qbit
public :
  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 double
end type
constructor Qbit() '' |0>
  x = 0
  y = 0
  z = 1
end constructor
sub Qbit.do_x() '' X gate
  rotate y , z , pi
end sub
sub Qbit.do_y() '' Y gate
  rotate x , z , pi
end sub
sub Qbit.do_z() '' Z gate
  rotate x , y , pi
end sub
sub Qbit.do_h() '' |+>
  z = iif( rnd < .5 , 1 , -1 )
end sub
sub Qbit.do_s() '' S gate
  rotate x , y , pi / 2
end sub
sub Qbit.do_s1() '' S1 gate
  rotate x , y , -pi / 2
end sub
sub Qbit.do_t() '' T gate
  rotate x , y , pi / 4
end sub
sub Qbit.do_t1() '' T1 gate
  rotate x , y , -pi / 4
end sub
function Qbit.get_state() as double
  return iif( z < 0 , 1.0 , 0.0 )
end function
const as integer numberOfQbits = 4
dim 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 if
end sub

bluatigro
Posts: 576
Joined: Apr 25, 2012 10:35
Location: netherlands

Re: quantum computing sim

Postby bluatigro » Feb 21, 2018 12:02

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

Postby bluatigro » Feb 27, 2018 9:47

i tryed somthing
based on several youtube's

i don't think it is whitout erro's

Code: Select all

'' bluatigro 27 feb 2018
'' qbit sim
const as double sqr2 = sqr( 1 / 2 )
type tqbit
public :
  dim as double i0 , i1
  declare function tostr() as string
end type
function tqbit.tostr() as string
  return str(i0)+"|0>"+str(i1)+"|1>"
end function
type tqbit2
public :
  dim as double i00 , i01 , i10 , i11
  declare function tostr() as string
  declare function lenght() as double
end
function tqbit2.tostr() as string
  return str(i00)+"|00>"+str(i01)+"|01>"+str(i10)+"|10>"+str(i11)+"|11>"
end function
function tqbit2.lenght() as double
  return sqr(i00^2+i01^2+i10^2+i11^2)
end function
function equal( a as double , b as double ) as integer
  return abs( a - b ) < 1e7
end function
function 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 q
end function
function notgate( q as tqbit ) as tqbit
  q.i0 *= -1
  q.i1 *= -1
  return q
end function
type tm44
public :
  dim as double m( 3 , 3 )
end type
dim shared as tm44 h
h.m( 1 , 0 ) = 1
h.m( 3 , 0 ) = 1
h.m( 0 , 1 ) = sqr2
h.m( 2 , 1 ) = 0-sqr2
h.m( 0 , 2 ) = sqr2
h.m( 2 , 2 ) = sqr2
h.m( 3 , 3 ) = 1
function 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 uit
end function

Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests