JuliaAttic / QuBase.jl

A foundational library for quantum mechanics in Julia
Other
43 stars 6 forks source link

Tensor products for states and operators #16

Closed jrevels closed 9 years ago

jrevels commented 9 years ago

This PR delivers a set of tensor product functions for QuArrays and their duals. Like our current set of multiplication functions, these functions only cover objects of N < 3 with orthonormal bases.

In addition, I realized that having basis types parameterize the number of factors can break construction of QuArrays where bases along different dimensions have different numbers of factors, e.g.

qa = QuArray(randn(4,4), FiniteBasis(4), FiniteBasis(2,2))
ERROR: `QuArray{B<:AbstractBasis{S<:AbstractStructure},T,N,A}` has no method matching QuArray{B<:AbstractBasis{S<:AbstractStructure},T,N,A}(::Array{Float64,2}, ::(FiniteBasis{Orthonormal,1},FiniteBasis{Orthonormal,2}))
 in QuArray at /Users/jarrettrevels/.julia/QuBase/src/arrays/quarray.jl:24

I removed the factor parameterization for FiniteBasis in order to allow operations like |A⟩⟨B|⟨C| --> |A⟩⟨BC|. I don't explicitly know when that kind of operation would be useful, but I think it's mathematically valid to define linear maps between spaces with explicit factors (e.g. H_BC) to a space without explicit factors (e.g. H_A), so I went ahead and did so. I might be over-generalizing here...

acroy commented 9 years ago

I removed the factor parameterization for FiniteBasis in order to allow operations like |A⟩⟨B|⟨C| --> |A⟩⟨BC| ...

I can't really come up with a use case either. Would it be better/sufficient to force the user to explicitly convert either |A> or <BC|?

jrevels commented 9 years ago

Would it be better/sufficient to force the user to explicitly convert either |A> or <BC|?

I suppose so - I can always re-implement the more general thing if we end up actually needing it.

Also, I believe that's the same thing as saying we won't allow mixed-order tensor products...which makes writing the tensor product generally really easy (for orthonormal bases, anyway).

The most recent commits on this branch...

Thoughts?

acroy commented 9 years ago

Looks good, although I haven't tested it. Could you rebase & squash your commits?