mps-0.0.0
MatrixProductStatesinC++
 All Data Structures Namespaces Functions Variables Enumerations Enumerator Groups Pages
fock.cc
1 // -*- mode: c++; fill-column: 80; c-basic-offset: 2; indent-tabs-mode: nil -*-
2 /*
3  Copyright (c) 2010 Juan Jose Garcia Ripoll
4 
5  Tensor is free software; you can redistribute it and/or modify it
6  under the terms of the GNU Library General Public License as published
7  by the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Library General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #include <tensor/indices.h>
21 #include <mps/quantum.h>
22 #include <tensor/io.h>
23 
24 namespace mps {
25 
26  using tensor::index;
27 
31  RSparse number_operator(int nmax)
32  {
33  index d = nmax+1; // Matrix size
34  Indices ndx = iota(0, nmax);
35  RTensor n = linspace(0, nmax, nmax+1);
36  return RSparse(ndx, ndx, n, d, d);
37  }
38 
42  RSparse destruction_operator(int nmax)
43  {
44  index d = nmax+1; // Matrix size
45  Indices row = iota(0, nmax-1);
46  Indices col = iota(1, nmax);
47  RTensor n = sqrt(linspace(1.0, nmax, nmax));
48  return RSparse(row, col, n, d, d);
49  }
50 
54  RSparse creation_operator(int nmax)
55  {
56  index d = nmax+1; // Matrix size
57  Indices row = iota(1, nmax);
58  Indices col = iota(0, nmax-1);
59  RTensor n = sqrt(linspace(1.0, nmax, nmax));
60  return RSparse(row, col, n, d, d);
61  }
62 
66  RTensor coherent_state(double alpha, int nmax)
67  {
68  RTensor output(nmax+1);
69  double c = exp(-alpha*alpha/2.0);
70  for (int i = 0; i <= nmax; ) {
71  output.at(i) = c;
72  c = c * alpha / sqrt((double)(++i));
73  }
74  return output;
75  }
76 
80  CTensor coherent_state(cdouble alpha, int nmax)
81  {
82  CTensor output(nmax+1);
83  double a2 = abs(alpha);
84  cdouble c = exp(-a2*a2/2.0);
85  for (int i = 0; i <= nmax; ) {
86  output.at(i) = c;
87  c = c * alpha / sqrt((double)(++i));
88  }
89  return output;
90  }
91 
92 }
RTensor coherent_state(double alpha, int nmax)
Real coherent state truncated to a maximum of 'nmax' bosons.
Definition: fock.cc:66
RSparse creation_operator(int nmax)
Fock creation operator truncated to a maximum of 'nmax' bosons.
Definition: fock.cc:54
RSparse number_operator(int nmax)
Fock number operator truncated to a maximum of 'nmax' bosons.
Definition: fock.cc:31
RSparse destruction_operator(int nmax)
Fock destruction operator truncated to a maximum of 'nmax' bosons.
Definition: fock.cc:42