Recent Changes - Search:

HomePage

PmWiki

pmwiki.org

OperatorExpressions

Operators are used in many places in the toolkit. The syntax is

lattice ':' expression

important note: When using expressions on the command line, remember to enclose it in quotes, or the shell will interpret brackets, *,^ operators etc. itself, and produce very strange results! The quotes need not enclose the entire expression, lattice:"Sz(1)+Sz(2)" is fine.

The parser understands complex arithmetic (for example, 2+3i - you can also use i as a symbolic constant, as well as pi and e, and a few functions (sin, cos, exp, log, etc). These are easy to add if there are other functions that would be useful.

There are distinct functions available for constructing TriangularOperators and ProductOperators?.

Examples

lattice:H^2

The square of an operator, equivalent to H*H.

lattice:Sz(0)[0] * Sz(1)[0]

A correlation between two unit cells

lattice:Sz(0) * Sz(1)

A nearest-neighbor correlation, where the unit cell size is 1 (or where Sz is defined as a unit cell operator)

lattice:(exp(0.4i * pi) * Sz(1) + Sz(2))^2 + log(2) * Sz(3)

A more complicated example.

lattice:i * [H,A]

Commutator brackets are allowed, both for finite operators and triangular operators.

lattice:CH(1) * adjoint(CH(2)) + conj(Sz(3))

The adjoint() function is used to get the Hermitian conjugate. Conj() is the ordinary complex conjugate. Both functions can be used on operators or numbers. As a shorthand, ad() also works.

lattice:inner(S(1), S(2))

The inner product of operators inner(A,B) calculates {$A^\dagger B$}. This is mostly useful for {$SU(2)$}, as it is used to construct scalar operators in the most natural way.

For {$SU(2)$} vector operators, there is also cross and outer functions.

The dot() function is equivalent to ordinary multiplication for abelian operators, but for non-abelian operators it calculates the coupling to a scalar operator. Be careful using this function, as there is often an {$SU(2)$} coupling coefficient required, for example for the spin vector operator, dot(S,S) = -inner(S,S). This arises because a vector operator is naturally anti-Hermitian.

The parser also understands exp of an operator. So it is possible to write directly, for example,

exp(i*pi*Sz(0))

But care needs to be taken, since the implementation of exp is not very efficient -- for an operator acting on N sites, it coarse-grains to a large matrix operator, calculates the exponential, and then reconstructs the MPO representation. So exp(Sz(0)+Sz(100)) for example will not work. Also, it acts per unit cell, so if the unit cell is N sites, then even exp(Sz(0)) may not be possible. A more efficient implementation of the exponential is possible, at least in some limited cases, where it can be easily constructed that the MPO is a sum of local [and therefore commuting] terms, but this is not yet implemented.

Swap gates are defined. There are two forms,

swapb(a,b)[i,j]

is a 'bosonic' swap between site i of unit cell a, and site j of unit cell b. A bosonic swap ignores Fermion signs, so it generally isn't what you want to swap sites of a fermionic lattice. The swap(a,b)[i,j] version takes into account fermion signs, but isn't yet useable (needs debugging). So currently the only alternative for fermionic swaps is to construct the fermion phase operator by hand (this is not so difficult).

Precedence

Unary + and - operators have highest precedence.

Next precedence to the power operator ('^'), which associates right-to-left (a^b^c == a^(b^c)).

Multiplication and division have next highest precedence.

Lowest precedence to binary + and -.

FileGrid

filegrid(f,x,y,z) reads the file named "f", and returns the element at array index (x,y,z).

    The format of the file is the same as gnuplot 3D format.  The X direction is the rows.  The Y direction is the columns.  The Z direction is blocks separated by an empty line.

Example:

$ cat testfile
0 2
1 3

10 30
20 40
$ mp-expectation psi lat:"filegrid(testfile,0.5,0.5,0.5) *I(0)"
13.25

The filename doesn't need to be quoted, but it cannot contain a comma. Also it shouldn't include whitespace at the start or end, since these are ignored.

The contents of the file can contain numbers or an arbitrary expression, including an MPO. Currently function arguments don't work properly if filegrid is used in a function definition and it refers to arguments passed into the function.

The elements of the file are separated by whitespace. To use expressions that contain spaces, you can use quotes, or backslash escapes. For example:

$ cat testfile2
"2 * I(0)"
"4 * I(0)"
$ ./mp-expectation psi lat:"filegrid(testfile2,0.5)"
3
Edit - History - Print - Recent Changes - Search
Page last modified on July 24, 2022, at 01:17 PM