Loading [MathJax]/extensions/tex2jax.js

Tuesday, 25 February 2025

January book: Wong's "Introduction To Classical And Quantum Computing"

 It's nearly the end of February, so high time I wrote up January's book.  This is Introduction to Classical and Quantum Computing by Thomas Wong.  I think I first came across it, or at least really took a good look at it, when a colleague recommended it as a text for our new Applied Quantum Computing MSc. 

The author, Thomas Wong, has generously made the book freely downloadable from his website,  Having decided to make use of it for teaching, I shelled out for a copy at the rather cheap price (for a science textbook) of £11.76 for a print-on-demand paperback.  Unlike December's book, which was also print-on-demand,  Wong's book is well-formatted for printing.

I really like this book.  It does a difficult job - introducing enough classical computing, quantum mechanics and quantum computing - kinda three different and disparate topics despite the similar sounding names - and does a good job of it.  It's become my go-to textbook for the course I teach in quantum algorithms, though it is too basic for my masters-only quantum simulation class.  

Wong updates the book and produces more editions when the need arises.  I have found a few little typos in it as I have been working through derivations in preparation for teaching, and I keep them marked up in a copy that I will send to Wong in case he wants to make any more updates

Screenshot below a sample marked-up bit where I saw a typo.  That circled ket-bra should be a bra-ket


Saturday, 8 February 2025

ascii2spec.f90

Following up the last post, where I documented the function which maps the ASCII representation of the letters s, p, d, f, g, h, i, j, k, to the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,  I complete the job today where I mentioned that one reason to do this mapping is to allow translation between the letters and the numbers in a computer language in a mathematical way.

Before coding up the polynomial function which does the mapping, it is helpful / necessary to re-express it in a different form that is not so prone to rounding errors.  Such a thing can be done by writting the polynomial in Horner form, which results in 

 

Here, then is a Fortran code which uses this form of the polynomial, which it can evaluate without error (with the use of double precision intermediary values).  If you want to use it, you can use the module a2s.  A sample code showing that it works is included in the snippet below

! take the ascii value for a spectroscopic identifier (s, p, d, f etc)
! and return the corresponding l value (0, 1, 2, ) etc.

module a2s
  contains
  function ascii2spec(x)
    implicit none
    integer, parameter :: rk=selected_real_kind(16)
    integer :: ascii2spec
    integer :: x
    
    ascii2spec= NINT(4.726949979612458e10_rk + x*(-3.5777271221003e9_rk + & 
         x*(1.184502721723563e8_rk + x*(-2.2405263573528733e6_rk + &
         x*(26482.917002197904_rk + &
         x*(-200.30039731359176_rk + &
         x*(0.946665443609888_rk + &
         (-0.002556173250617695_rk + (47*x)/1.5567552e7_rk)*x)))))))
  end function ascii2spec
end module a2s

program a2s_test
  use a2s
  integer, parameter :: rk=selected_real_kind(16)
  integer :: x
  
  print *,"s",ascii2spec(iachar("s"))
  print *,"p",ascii2spec(iachar("p"))
  print *,"d",ascii2spec(iachar("d"))
  print *,"f",ascii2spec(iachar("f"))
  print *,"g",ascii2spec(iachar("g"))
  print *,"h",ascii2spec(iachar("h"))
  print *,"i",ascii2spec(iachar("i"))
  print *,"j",ascii2spec(iachar("j"))
  print *,"k",ascii2spec(iachar("k"))

end program a2s_test