Create an own operator dependent of other

I want to create a new operator but it is dependent of the “N” operator for sitetype Boson:
NewOp = e^{i \theta \hat{n}}
One thing I tried it was defining with:
ITensors.op(::OpName"Exponent",::SiteType"Boson")
but the entry of this kind should be a matrix, I apologize if is a simple question, I’m new using DMRG.
Thanks

To define boson type operators I think you need to use this syntax

ITensors.op(::OpName"Exponent", ::SiteType"Boson", d::Int) = exp(i * theta * N(d))

where N(d) is a function that creates a d x d matrix representing the \hat{n} operator. I’m not sure if you can/how to take advantage op("N", siteindex) here…

Anyways, I think the easiest would be to use

NewOp = exp(i * theta * op("N", siteindex))

If you do it like this, you can’t use expect(psi, “Exponent”) or similar things that require the operator to be defined with ITensors.op, but I think it should work fine. For convenience you could define it as a function

NewOp(theta, siteindex) = exp(i * theta * op("N", siteindex))

Thanks for replying ttolppanen!
I find useful but when I try to use on opSum, the program gives an error, before use on opSum I add:

Exponent = op(Exponent, sites)   

with sites defined as:

sites = siteinds("Boson", L; dim = 5 ,  conserve_number = false, conserve_qns= true )   

L is an integer.

I haven’t used opSum before, but I think for it to work you need to use the ITensors.op way of creating an operator.
I think you could try

ITensors.op(::OpName"Exponent", ::SiteType"Boson", d::Int) = exp(i * theta * make_n_matrix(d))

with

function make_n_matrix(d)
    n = zeros(d, d)
    for i in 1:d
        n[i, i] = i - 1
    end
    return n
end

I think if you need many values for \theta you might have to do something like this

ITensors.op(::OpName"Exponent1/2", ::SiteType"Boson", d::Int) = exp(i * 1/2 * make_n_matrix(d))
ITensors.op(::OpName"Exponent1/4", ::SiteType"Boson", d::Int) = exp(i * 1/4 * make_n_matrix(d))

But try it out and see if it works :slight_smile:

1 Like