lib_qmat
Quick start on datastructures
This library uses three special datastructures to store the
information on finite dimensional basis sets (q_set), linear operators (q_mat),
and sets of linear operators acting on the same space (q_mats).
For example, a ladder operator acting on a space spanned by three vibrational basis functions \(s_1 = \{|v=0\rangle, |v=1\rangle, |v=2\rangle\}\) given by
would be defined by
lib_load lib_qmat
s1 = q_set([0; 1; 2], 'v')
// s1 = (OBJECT tlist) with fields:
//
// v
// _
// 1: 0
// 2: 1
// 3: 2
Ad = q_mat([ 0 0 0
1 0 0
sqrt(2) 0 0], s1)
// Ad = (OBJECT tlist) with fields:
//
// |v(3)>A(3;3)<v(3)|
// the values of the quantum numbers are stored in the field "q":
disp(s1.q)
// 0.
// 1.
// 2.
// The names of the quantum number(s) are stored in the field "qnames"
disp(s1.qnames)
// "v"
// The matrix is stored in the field A
disp(Ad.A)
// 0. 0. 0.
// 1. 0. 0.
// 1.4142136 0. 0.
// The basis set on which Ad is acting is in the field "s1"
disp(Ad.s1) // (this is the set "s1" defined above
// The codomain is in the field "s2", by default it is the same as "s1"
Ad.s2==s1
// ans =
// T
The sets == (is-equal) operator is defined for q_set datastructures
by operator overloading (see Scilab help overloading)). It returns
true (T) when the names and the values of the quantum numbers are the same,
so the equivalent statement without using overloading would be:
and(Ad.s2.names== Ad.s1.names & Ad.s2.q == Ad.s2.q)
// ans =
// T
Many operators, like multiplication * and addition + are defined for for
these datastructures, see below.
Overview: data structures
q_set: defining quantum numbers and basis sets
- [s1, prow, pcol] = q_set(q, qnames)
Define a basis set by specifying the names of the quantum numbers (
qnames) and the values of the quantum numbers (q)
Example
lib_load lib_qmat
qnames = ['j' 'm']
q = [0 0
1 -1
1 0
1 1]
s1 = q_set(q, qnames)
Defines the basis set:
Input arguments
- q:
A Scilab ::math::m times n matrix. Each row defines a basis function, each column a quantum number. The names of the quantum numbers are given by
qnames, with columnjofqcorresponding toqnames(j).If there is only one output argument (
s1), the quantum numbers inqmust be sorted lexicographically. If there are at least two output arguments, the matrixqwill be sorted if necessary.- qnames:
A character string with quantum numbers.
Output arguments
- prow:
If the rows or the matrix
qare sorted lexicographically,prowwill be an empty matrix. If not,prowwill be a permutation, such thatq(prow, :)is sorted lexicographically. If the rows ofqare not properly sorted and there is only one output argument, an error is returned.- pcol:
The first time a quantum number is used, it is added to a list of quantum numbers that is stored in a global character string (see
qs_names). This defines the order of quantum numbers. If the quantum numbers inqnamesare sorted,pcolwill be an empty matrix. If not,pcolwill be a permutation, such thatqnames(pcol)will be sorted.
- [s3, irow] = qs_extract(i, j, raw, s1)
This function is called when indexing a
q_set. Whenraw=%tit returnss1.q(i, j)and whenraw=%fit returnsq_sets3, where the names ares1.qnames(j). The indexjcan also be a character string with the names of the quantum numbers to be selected.The index
ican also be aq_set. In this case elements ofs1will be selected where the quantum number names that occur in bothiands1have the same values. In this case the default value israw=%f, i.e., aq_setis returned.The index
jcan also be aq_set, but in that caseimust be a colon. We haves1(s2) == s1(s2, :) == s1(:, s2).When
raw=%tor when all columns are selected,irowwill be the index of selected elementss1.q(irow,j). This is useful wheniorjis aq_set. Whenraw=%fand not all columns are selected, the indexirowwould not necessarily be unique, so an error message is given.
Example:
q = [1 1
1 2
2 1
2 2
2 3]
s1 = q_set(q, ['i' 'j'])
[q2, irow] = s1(1:2:$, 'j', %t)
// This will call
// [q2, irow] = qs_extract(1:2:$, 'j', %t, s1)
//
// It returns:
q2 = [1
1
3]
irow = 1:2:$
The raw flag may be skipped, its default value depends on the type of j.
When argument j is a constants, a boolean, or a string, the
default is, raw = %t.