JuliaAttic / QuBase.jl

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

Basic Expression Support #46

Open Roger-luo opened 8 years ago

Roger-luo commented 8 years ago

Will QuArray support storing base's expression? or a new subtype of QuArray?

my problem is,for example:

to store a specific state like

\frac{1}{\sqrt{2}}(sin(\frac{\pi}{a}x)+sin(\frac{2\pi}{a}x))

the QuArray type can store it like this at present

a = QuArray([x->1/sqrt(2)*sin(2/a)*sin(1*pi/a*x),x->1/sqrt(2)*sin(2/a)*sin(2*pi/a*x)])

however I hope the coeffs can be isolated from the base' expressions

acroy commented 8 years ago

I think right now this is not easily possible. Note that QuArrays are really meant to be containers for the coefficients. The information about the basis would be stored in a separate type, but there isn't much support yet. Basically, I could imagine to have a basis type, which stores expressions for the basis functions and roughly does what you want. Isolating coefficients from an expression might be tricky to do in general, but maybe one could have some convention and then use macros to extract coefficients and basis-function expressions. All of this would be a cool feature of course!

Having said this, I think you might want to have a look at @jrevels QuDirac package. He might also have an idea regarding the basis types ...

Roger-luo commented 8 years ago

And about storing a state with expression of basis.what about a subtype of QuArray that have a field to store Functions. Cause not only expressions should be store. Sometimes a variable points to a solver with specific parameters

#pretend this to be some kind of numerical solver
function state(a,b,c)
 return sin(a*b*c)
end

and to store a state like

1/sqrt(2)*state(1,2,3)+1/sqrt(2)*state(2,3,4)

a type that can really stores a function is needed.And specific expressions can also be stored as function,for example

function state_of_an_oscillator(n)
        return supose_this_is_an_expression()
end

I wrote a simple one in https://github.com/Roger-luo/AdiaRoll.jl/blob/master/src/base.jl

jrevels commented 8 years ago

You can do this with QuDirac.jl, but that package only works with Julia v0.3 and won't be updated until Julia v0.5 releases.