たふみ
May 17, 2020
160

# Introduction to Imaginary World

// Japanese
Goのcomplex (複素数) builtin typeについて話しました。

// English
I Talked about Go's complex builtin type.
As a real usage example, I picked up Quaternion and Quantum Information Science's Deutsch-Jozsa algorithm. This slide also has the implementation of Deutsch-Jozsa Algorithm in Go.
Used Library: https://github.com/itsubaki/q

May 17, 2020

## Transcript

1. ### Introduction to Imaginary World NEW DEBUG!! ~ 転職してプログラマーになったら 一切エラーがでないんだが ~

// たふみ, DE LIKER // 2020·05·17

5. ### Why Go? • Nice Standard Pkgs? • Clear Dependencies? •

Less Syntax Sugar? • Single Binary? • Cross Compile? • Simple Syntax? • Fast Build? • gofmt?

13. ### Fortran real re, im complex z z = (1.0,2.0) re

= real(z) ! Re im = aimag(z) ! Im end

15. ### C99 // GNU Extention #include <complex.h> ... double _Complex x

= 1.0 + 2.0i; // C99 Spec #include <complex.h> ... float _Complex x = 1.0 + 2.0 * _Complex_I; Ref https://cpplover.blogspot.com/2013/11/c99.html
16. ### C99 // GNU Extention #include <complex.h> ... double _Complex x

= 1.0 + 2.0i; // C99 Spec #include <complex.h> ... float _Complex x = 1.0 + 2.0 * _Complex_I; Ref https://cpplover.blogspot.com/2013/11/c99.html
17. ### Perl Ruby OCaml Haskell etc... Need to include std lib

(complex is not builtin type)
18. ### Go package main import ( "fmt" ) func main() {

z := 1 + 2i fmt.Printf("%T", z) } // output: complex128

20. ### You, the people have the power - the power to

create machines. The power to create happiness! You, the people, have the power to make this life free and beautiful, to make this life a wonderful adventure. Retrieved from “The Great Dictator” (1940)
21. ### You, the people have the power - the power to

create machines. The power to create happiness! You, the people, have the power to make this life free and beautiful, to make this life a wonderful adventure. Retrieved from “The Great Dictator” (1940)

25. ### Usage of Complex Number • Quaternion • Quantum Information Science

→ Let’s aGo !

28. ### Quaternion This needs 3 independent complex space, so it will

be lil hard to express in Go…
29. ### Quaternion is used for 3D Graphics rotation, like Games. Another

methods: - Euler angles (オイラー角) - Rotation Matrix (回転行列) FYI
30. ### Euler angles (オイラー角) Euler angles needs only 3 params. ...BUT,

- the computation is heavy - The problem of Gimbal Lock FYI
31. ### FYI Rotation Matrix (回転行列) Rotation Matrix needs 9 params ←

soooo many not good for memory resources
32. ### Quaternion (4元数) Quaternion needs 4 params. - No Gimbal Lock

- Balanced for memory & computating resources FYI

Far Away...

44. ### Unit Vector This is the corresponding 0, 1 to classic

computing in qubit

47. ### Unitary Evolution & Unitary Matrix * : Adjoint Matrix (随伴行列)

This shows that |ψ> changes with time to |ψ>’

49. ### Signiﬁcant Unitary Matrix (cont.) • Hadamard Matrix • Also called

“Hadamard Transform” when used as an operator • Particularly make the basis superposition which the probability of |0> and |1> is the same

52. ### Deutsch- Jozsa Algorithm • Multiply n+1’th bit by Pauli’s \sigma_x

• Multiply all the bits by Hadamard Operator • Multiply all the bits by U_f • Multiply first n bits by Hadamard Operator • If the observed classical first n bit array is 0...0, then it is constant function, otherwise balanced function.
53. ### Deutsch- Jozsa Algorithm (cont.) • f is Oracle, it is

like black box • So in classical computing, 2/n + 1 inputs must be evaluated. → must be asked 2^(n-1) + 1 times • Deutsch-Jozsa needs 1 time ask

)
57. ### Deutsch- Jozsa Impl // deutschjozsa return is given f is

constant, returns true. Otherwise retuens false. func deutschjozsa(size int, f func(_ *qsim.Q, _ ...qsim.Qubit)) string { q := qsim.New() is := make([]qsim.Qubit, size) for i := range is { is[i] = q.Zero() } o := q.One() // equivalent to o := q.Zero(); q.X(o); q.H(is...) q.H(o) // Apply func as Oracle Uf f(q, is...) q.H(is...) q.Measure(is...) return q.Binary() }

59. ### func balanced(space *qsim.Q, qs ...qsim.Qubit) { cnt := 0 for

_, q := range qs { if cnt%2 == 0 { space.Z(q) } cnt++ } } Deutsch- Jozsa Impl
60. ### Deutsch- Jozsa Impl func main() { fmt.Println("balanced: ", deutschjozsa(8, balanced))

fmt.Println("constant: ", deutschjozsa(8, constant)) }
61. ### Deutsch- Jozsa Impl deutsch-jozsa \$ make go run main.go balanced:

101010101 constant: 000000000
62. ### Introduction to Imaginary World NEW DEBUG!! ~ 転職してプログラマーになったら 一切エラーがでないんだが ~

// たふみ, DE LIKER // 2020·05·17 Follow me on Twitter → @CreatorQsF