From 1da72aab81dc2d26ca4f66f1a570d5a89ce4633a Mon Sep 17 00:00:00 2001 From: libquantum Date: Thu, 27 Oct 2016 04:10:53 +0900 Subject: [PATCH] updated libquantum 0.1.1 source files --- CHANGES | 7 +++++++ INSTALL | 2 +- Makefile.in | 13 +++++++------ README | 2 +- configure | 18 +++++++++--------- expn.c | 23 +++++++++++++++++++++++ expn.h | 26 +++++++++++++++++++++++++- gates.c | 22 ++++++++++++++++++++-- gates.h | 13 +++++++------ oaddn.h | 24 ++++++++++++++++++++++++ omuln.c | 23 +++++++++++++++++++++++ omuln.h | 23 +++++++++++++++++++++++ quantum.h.in | 33 +++++++++++++++++---------------- shor.c | 2 +- 14 files changed, 188 insertions(+), 43 deletions(-) create mode 100644 CHANGES diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..8559544 --- /dev/null +++ b/CHANGES @@ -0,0 +1,7 @@ +libquantum 0.1.1: + - Completed rotation gates (quantum_r_z) + - Fixed a build problem with the demo program + - Fixed some header inconsistencies + +libquantum 0.1.0: + initial public release \ No newline at end of file diff --git a/INSTALL b/INSTALL index c54a95a..a3e824c 100644 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,4 @@ -libquantum 0.1.0 installation guide +libquantum 0.1.1 installation guide ----------------------------------- Contents: diff --git a/Makefile.in b/Makefile.in index 4a09328..e4f51aa 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,7 +37,7 @@ top_builddir=. MAJOR=0 MINOR=1 -RELEASE=0 +RELEASE=1 # Tools needed to build libquantum @@ -48,7 +48,7 @@ LIBTOOL=@LIBTOOL@ # Flags passed to C compiler CFLAGS=@CFLAGS@ -LDFLAGS=-rpath $(LIBDIR) -version-info 1:0:1 +LDFLAGS=-rpath $(LIBDIR) -version-info 1:1:1 # Dependencies @@ -103,23 +103,24 @@ install: libquantum.la # Build a demo showing Shor's factoring algorithm shor: libquantum.la shor.c Makefile - $(LIBTOOL) $(CC) $(CFLAGS) -o shor shor.c -I./ -lquantum -lm + $(LIBTOOL) $(CC) $(CFLAGS) -o shor shor.c -I./ -lquantum -static -lm # Make everything neat and tidy clean: -rm -rf .libs - rm shor libquantum.la *.lo *.o + -rm shor libquantum.la *.lo *.o distclean: -rm -rf .libs - rm shor *.lo *.o config.h quantum.h config.status config.log\ + -rm shor *.lo *.o config.h quantum.h config.status config.log\ libquantum.la dist: + -rm quantum.h config.h mkdir libquantum-$(MAJOR).$(MINOR).$(RELEASE) cp *.c *.h quantum.h.in Makefile.in config.h.in configure COPYING\ - install-sh ltmain.sh config.sub config.guess README INSTALL\ + install-sh ltmain.sh config.sub config.guess README INSTALL CHANGES\ libquantum-$(MAJOR).$(MINOR).$(RELEASE) tar czf libquantum-$(MAJOR).$(MINOR).$(RELEASE).tar.gz\ libquantum-$(MAJOR).$(MINOR).$(RELEASE)/ diff --git a/README b/README index bcfb059..7aee583 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -libquantum 0.1.0 README file +libquantum 0.1.1 README file ---------------------------- libquantum is a C library for quantum computing. It provides quantum diff --git a/configure b/configure index 0278ebb..a318d65 100755 --- a/configure +++ b/configure @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.57 for libquantum 0.1.0. +# Generated by GNU Autoconf 2.57 for libquantum 0.1.1. # # Report bugs to . # @@ -427,8 +427,8 @@ SHELL=${CONFIG_SHELL-/bin/sh} # Identity of this package. PACKAGE_NAME='libquantum' PACKAGE_TARNAME='libquantum' -PACKAGE_VERSION='0.1.0' -PACKAGE_STRING='libquantum 0.1.0' +PACKAGE_VERSION='0.1.1' +PACKAGE_STRING='libquantum 0.1.1' PACKAGE_BUGREPORT='libquantum@enyo.de' ac_unique_file="classic.c" @@ -938,7 +938,7 @@ if test "$ac_init_help" = "long"; then # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libquantum 0.1.0 to adapt to many kinds of systems. +\`configure' configures libquantum 0.1.1 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -999,7 +999,7 @@ fi if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libquantum 0.1.0:";; + short | recursive ) echo "Configuration of libquantum 0.1.1:";; esac cat <<\_ACEOF @@ -1092,7 +1092,7 @@ fi test -n "$ac_init_help" && exit 0 if $ac_init_version; then cat <<\_ACEOF -libquantum configure 0.1.0 +libquantum configure 0.1.1 generated by GNU Autoconf 2.57 Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002 @@ -1107,7 +1107,7 @@ cat >&5 <<_ACEOF This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libquantum $as_me 0.1.0, which was +It was created by libquantum $as_me 0.1.1, which was generated by GNU Autoconf 2.57. Invocation command line was $ $0 $@ @@ -8620,7 +8620,7 @@ _ASBOX } >&5 cat >&5 <<_CSEOF -This file was extended by libquantum $as_me 0.1.0, which was +This file was extended by libquantum $as_me 0.1.1, which was generated by GNU Autoconf 2.57. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -8680,7 +8680,7 @@ _ACEOF cat >>$CONFIG_STATUS <<_ACEOF ac_cs_version="\\ -libquantum config.status 0.1.0 +libquantum config.status 0.1.1 configured by $0, generated by GNU Autoconf 2.57, with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\" diff --git a/expn.c b/expn.c index c6c1022..274d902 100644 --- a/expn.c +++ b/expn.c @@ -1,3 +1,26 @@ +/* expn.c: x^a mod n + + Copyright 2003 Bjoern Butscher, Hendrik Weimer + + This file is part of libquantum + + libquantum is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + libquantum is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libquantum; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + +*/ + #include #include #include diff --git a/expn.h b/expn.h index 0857664..84f4b0f 100644 --- a/expn.h +++ b/expn.h @@ -1,9 +1,33 @@ +/* expn.h: Declarations for expn.c + + Copyright 2003 Bjoern Butscher, Hendrik Weimer + + This file is part of libquantum + + libquantum is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + libquantum is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libquantum; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + +*/ + #ifndef __EXPN_H #define __EXPN_H #include "qureg.h" -extern void quantum_exp_mod_n(int, int, int, int, quantum_reg *); +extern void quantum_exp_mod_n(int N, int x, int width_input, int width, + quantum_reg *reg); #endif diff --git a/gates.c b/gates.c index 3de406f..57c5762 100644 --- a/gates.c +++ b/gates.c @@ -404,8 +404,8 @@ quantum_r_x(int target, float gamma, quantum_reg *reg) m = quantum_new_matrix(2, 2); - m.t[0] = cos(gamma / 2); m.t[1] = IMAGINARY * sin(gamma / 2); - m.t[2] = IMAGINARY * sin(gamma / 2); m.t[3] = cos(gamma / 2); + m.t[0] = cos(gamma / 2); m.t[1] = -IMAGINARY * sin(gamma / 2); + m.t[2] = -IMAGINARY * sin(gamma / 2); m.t[3] = cos(gamma / 2); quantum_gate1(target, m, reg); @@ -431,6 +431,24 @@ quantum_r_y(int target, float gamma, quantum_reg *reg) } +/* Apply a rotation about the z-axis by the angle GAMMA */ + +void +quantum_r_z(int target, float gamma, quantum_reg *reg) +{ + int i; + + for(i=0; isize; i++) + { + if(reg->node[i].state & ((MAX_UNSIGNED) 1 << target)) + reg->node[i].amplitude *= quantum_cexp(gamma/2); + else + reg->node[i].amplitude *= quantum_cexp(-gamma/2); + } + + quantum_decohere(reg); +} + /* Apply a phase kick by the angle GAMMA */ void diff --git a/gates.h b/gates.h index bcf29c1..b2cb5c9 100644 --- a/gates.h +++ b/gates.h @@ -41,14 +41,15 @@ extern void quantum_swaptheleads_omuln_controlled(int control, int width, extern void quantum_gate1(int target, quantum_matrix m, quantum_reg *reg); -extern void quantum_r_x(int a, float gamma, quantum_reg *reg); -extern void quantum_r_y(int a, float gamma, quantum_reg *reg); +extern void quantum_r_x(int target, float gamma, quantum_reg *reg); +extern void quantum_r_y(int target, float gamma, quantum_reg *reg); +extern void quantum_r_z(int target, float gamma, quantum_reg *reg); -extern void quantum_hadamard(int a, quantum_reg *reg); -extern void quantum_walsh(int a, quantum_reg *reg); +extern void quantum_hadamard(int target, quantum_reg *reg); +extern void quantum_walsh(int target, quantum_reg *reg); -extern void quantum_phase_kick(int a, float gamma, quantum_reg *reg); -extern void quantum_cond_phase(int a, int b, quantum_reg *reg); +extern void quantum_phase_kick(int target, float gamma, quantum_reg *reg); +extern void quantum_cond_phase(int control, int target, quantum_reg *reg); extern int quantum_gate_counter(int inc); diff --git a/oaddn.h b/oaddn.h index 71c6687..3dbbaa2 100644 --- a/oaddn.h +++ b/oaddn.h @@ -1,3 +1,26 @@ +/* oaddn.h: Declarations for oaddn.c + + Copyright 2003 Bjoern Butscher, Hendrik Weimer + + This file is part of libquantum + + libquantum is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + libquantum is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libquantum; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + +*/ + #ifndef __OADDN_H #define __OADDN_H @@ -23,4 +46,5 @@ extern void addn(int,int,int, quantum_reg *); extern void addn_inv(int, int, int, quantum_reg *); extern void add_mod_n(int, int, int, quantum_reg *); + #endif diff --git a/omuln.c b/omuln.c index a55eb89..128f4fb 100644 --- a/omuln.c +++ b/omuln.c @@ -1,3 +1,26 @@ +/* omuln.c: Multiplication modulo an integer N + + Copyright 2003 Bjoern Butscher, Hendrik Weimer + + This file is part of libquantum + + libquantum is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + libquantum is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libquantum; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + +*/ + #include "defs.h" #include "matrix.h" #include "gates.h" diff --git a/omuln.h b/omuln.h index 8cf2afe..5329ba5 100644 --- a/omuln.h +++ b/omuln.h @@ -1,3 +1,26 @@ +/* omuln.h: Declarations for omuln.c + + Copyright 2003 Bjoern Butscher, Hendrik Weimer + + This file is part of libquantum + + libquantum is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 2 of the License, + or (at your option) any later version. + + libquantum is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with libquantum; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 + USA + +*/ + #ifndef __OMULN_H #define __OMULN_H diff --git a/quantum.h.in b/quantum.h.in index b7ba921..edc9ab5 100644 --- a/quantum.h.in +++ b/quantum.h.in @@ -74,28 +74,31 @@ extern void quantum_delete_qureg(quantum_reg *reg); extern void quantum_print_qureg(quantum_reg reg); extern void quantum_addscratch(int bits, quantum_reg *reg); -extern void quantum_cnot(int, int, quantum_reg *); -extern void quantum_toffoli(int, int, int, quantum_reg *); -extern void quantum_X_gate(int, quantum_reg *); -extern void quantum_Y_gate(int a, quantum_reg *reg); -extern void quantum_Z_gate(int a, quantum_reg *reg); -extern void quantum_gate1(quantum_matrix m, int a, quantum_reg *reg); -extern void quantum_r_x(int a, float gamma, quantum_reg *reg); -extern void quantum_r_y(int a, float gamma, quantum_reg *reg); -extern void quantum_phase_kick(int a, float gamma, quantum_reg *reg); -extern void quantum_hadamard(int a, quantum_reg *reg); -extern void quantum_walsh(int a, quantum_reg *reg); -extern void quantum_cond_phase(int a, int b, quantum_reg *reg); +extern void quantum_cnot(int control, int target, quantum_reg *reg); +extern void quantum_toffoli(int control1, int control2, int target, + quantum_reg *reg); +extern void quantum_sigma_x(int target, quantum_reg *reg); +extern void quantum_sigma_y(int target, quantum_reg *reg); +extern void quantum_sigma_z(int target, quantum_reg *reg); +extern void quantum_gate1(int target, quantum_matrix m, quantum_reg *reg); +extern void quantum_r_x(int target, float gamma, quantum_reg *reg); +extern void quantum_r_y(int target, float gamma, quantum_reg *reg); +extern void quantum_r_z(int target, float gamma, quantum_reg *reg); +extern void quantum_phase_kick(int target, float gamma, quantum_reg *reg); +extern void quantum_hadamard(int target, quantum_reg *reg); +extern void quantum_walsh(int target, quantum_reg *reg); +extern void quantum_cond_phase(int control, int target, quantum_reg *reg); extern int quantum_gate_counter(int inc); extern void quantum_qft(int width, quantum_reg *reg); -extern void quantum_exp_mod_n(int, int, int, int, quantum_reg *); +extern void quantum_exp_mod_n(int N, int x, int width_input, int width, + quantum_reg *reg); extern MAX_UNSIGNED quantum_measure(quantum_reg reg); extern int quantum_bmeasure(int pos, quantum_reg *reg); -extern quantum_matrix quantum_new_matrix(int ,int ); +extern quantum_matrix quantum_new_matrix(int cols, int rows); extern void quantum_delete_matrix(quantum_matrix *m); extern int quantum_ipow(int a, int b); @@ -109,8 +112,6 @@ extern float quantum_prob(COMPLEX_FLOAT a); extern void quantum_set_decoherence(float lambda); extern void quantum_decohere(quantum_reg *reg); -extern void quantum_add_hash(MAX_UNSIGNED a, int pos, quantum_reg *reg); - extern quantum_reg quantum_matrix2qureg(quantum_matrix *m, int width); extern quantum_matrix quantum_qureg2matrix(quantum_reg reg); diff --git a/shor.c b/shor.c index c2d4289..d662ba9 100644 --- a/shor.c +++ b/shor.c @@ -18,7 +18,7 @@ int main(int argc, char **argv) { if(argc==1) { - printf("Usage: sim [number]\n\n"); + printf("Usage: shor [number]\n\n"); return 3; }