I don't know if this is at all what you had in mind, but I just pushed a commit for a Wavefunction which now inherits only from Function and is still callable. Feedback is greatly appreciated, since I'm still new at this.
https://github.com/lazovich/sympy/commit/8a7650230f864455a877fe710e447d328cf3052c On Mon, Jun 13, 2011 at 2:32 PM, Tomo Lazovich <lazov...@fas.harvard.edu>wrote: > I think I'm a little confused about how this would work if I'm inheriting > from Function instead of Lambda. Is it still possible, by inheriting from > Function, to get behavior like this (maybe not the same exact constructor, > but the same general idea)? > > >> f = Wavefunction(x, x**2) > >> f(0) > 0 > > To get this, does eval() then have to return a Lambda? > > > On Sun, Jun 12, 2011 at 8:02 PM, Aaron Meurer <asmeu...@gmail.com> wrote: > >> OK, I would drop the Lambda subclassing and just write your own eval >> method. Among other things, this will let you use the more logical >> argument order WaveFunction(expr, var). >> >> Another thing about Lambda. If you do Lambda(x, x*y), then x is not >> considered a free variable of the Lambda. >> >> In [2]: Lambda(x, x*y).free_symbols >> Out[2]: set(y) >> >> Is this something that you want to hold for your WaveFunction? >> Consider that, for example, expr.diff(x) is always 0 if x is not a >> free_symbol of expr. >> >> Aaron Meurer >> >> On Sun, Jun 12, 2011 at 6:30 PM, Tomo Lazovich <lazov...@fas.harvard.edu> >> wrote: >> > Just for reference, this is what exists so far of the Wavefunction >> class. It >> > also has some doctests so you can see the usage. >> > >> > >> https://github.com/lazovich/sympy/blob/c9a3ceb0d1addd9c89c30b90cbe0e55c9467fe0a/sympy/physics/quantum/state.py#L521 >> > >> > On Sun, Jun 12, 2011 at 7:25 PM, Aaron Meurer <asmeu...@gmail.com> >> wrote: >> >> >> >> I think it will be cleaner to make it a class, even with the little >> >> you are doing. Note that if you just want something to return some >> >> expression (i.e., eval() would always return something), you could >> >> just use a Python function. >> >> >> >> By the way, Lambda really shouldn't even be in consideration. If you >> >> are naming something, that's a sign that you shouldn't use Lambda. >> >> It's similar with Python's lambda. You would never do >> >> >> >> mul = lambda x, y: x*y >> >> >> >> instead of >> >> >> >> def mul(x, y): >> >> return x*y >> >> >> >> Aaron Meurer >> >> >> >> On Sun, Jun 12, 2011 at 4:21 PM, Tomo Lazovich < >> lazov...@fas.harvard.edu> >> >> wrote: >> >> > I think Wavefunction applies more to the latter case, where there's a >> >> > known >> >> > function that we want to return. I sort of saw it as more of a >> >> > convenience >> >> > than anything else. For one, returning the expression itself, like >> >> > sin(n*pi*x/L), means that if you want to actually evaluate it at a >> point >> >> > you >> >> > have to use subs() (which I guess is not too bad, but its a little >> less >> >> > intuitive than simply getting the function and being able to call >> >> > psi(2)). >> >> > It also can provide some basic helper functions for calculating >> >> > probabilities (f*conjugate(f)) or normalization constants. The final >> >> > reason >> >> > I had is that it ended up making DifferentialOperator quite >> simple...as >> >> > simple as defining an _apply_operator_Wavefunction function (though I >> >> > guess >> >> > it's just as simple to write _apply_operator_Function or >> >> > _apply_operator_Lambda). I can go either way on this. >> >> > >> >> > Tomo >> >> > >> >> > On Sun, Jun 12, 2011 at 4:29 PM, Brian Granger <elliso...@gmail.com> >> >> > wrote: >> >> >> >> >> >> I am -1 on having a Wavefunction class. The reason is that a >> >> >> wavefunction is just a plain old function. There is no additional >> >> >> logic needed over a regular function. But I want to understand what >> >> >> you are using these functions for. I can think of two types of >> >> >> functions needed in quantum: >> >> >> >> >> >> * An undefined function for use in representing an unknown or >> abstract >> >> >> state: <x|psi> => psi(x). For this I would just use >> >> >> Function('psi')('x'). The name of the state (psi) can just be used >> >> >> for the name of the function. >> >> >> * A function for a known quantum state like the particle in a box. >> >> >> For this case, we should just return the special function, such as >> >> >> sin(n*pi*x/L), etc. >> >> >> >> >> >> Can you clarify how the functions you are using relate to these two >> >> >> cases? >> >> >> >> >> >> Cheers, >> >> >> >> >> >> Brian >> >> >> >> >> >> On Sat, Jun 11, 2011 at 2:56 PM, Tomo Lazovich >> >> >> <lazov...@fas.harvard.edu> >> >> >> wrote: >> >> >> > Lambda seems to work for me except for one thing. >> >> >> > >> >> >> > I have a class Wavefunction for representations of states in >> >> >> > continuous >> >> >> > bases. It subclasses Lambda and provides some additional >> convenience >> >> >> > functions. One thing it would like to do internally is calculate >> >> >> > self.expr*conjugate(self.expr). I've found, however, that because >> the >> >> >> > Lambda >> >> >> > uses dummy variables internally, even if I initialize the function >> >> >> > with >> >> >> > a >> >> >> > symbol set to real=True, that doesn't carry over to the internal >> >> >> > expression >> >> >> > and so the conjugate isn't very well simplified. Is there a way to >> >> >> > get >> >> >> > around this? >> >> >> > >> >> >> > Thanks! >> >> >> > >> >> >> > On Fri, Jun 10, 2011 at 9:19 PM, Aaron Meurer <asmeu...@gmail.com >> > >> >> >> > wrote: >> >> >> >> >> >> >> >> If you just want a placeholder to keep args, use >> UndefinedFunction. >> >> >> >> If you want it to have any more advanced functionality at all, >> >> >> >> create >> >> >> >> a subclass of Function. I admit I don't know anything at all >> about >> >> >> >> what you are doing, but it's very likely that the case is the >> >> >> >> latter. >> >> >> >> >> >> >> >> Aaron Meurer >> >> >> >> >> >> >> >> On Fri, Jun 10, 2011 at 5:08 PM, Vinzent Steinberg >> >> >> >> <vinzent.steinb...@googlemail.com> wrote: >> >> >> >> > On 10 Jun., 02:08, Brian Granger <elliso...@gmail.com> wrote: >> >> >> >> >> Definitely use the existing Function stuff in sympy. I am not >> >> >> >> >> sure >> >> >> >> >> you will even have to subclass to do this. >> >> >> >> > >> >> >> >> > There is also UndefinedFunction (BTW, I think we should rename >> it >> >> >> >> > to >> >> >> >> > AbstractFunction or similar) if you want a rather abstract >> >> >> >> > function. >> >> >> >> > If you want to implement something like sin, you should >> probably >> >> >> >> > use >> >> >> >> > Function. >> >> >> >> > >> >> >> >> > Vinzent >> >> >> >> > >> >> >> >> > -- >> >> >> >> > You received this message because you are subscribed to the >> Google >> >> >> >> > Groups "sympy" group. >> >> >> >> > To post to this group, send email to sympy@googlegroups.com. >> >> >> >> > To unsubscribe from this group, send email to >> >> >> >> > sympy+unsubscr...@googlegroups.com. >> >> >> >> > For more options, visit this group at >> >> >> >> > http://groups.google.com/group/sympy?hl=en. >> >> >> >> > >> >> >> >> > >> >> >> >> >> >> >> >> -- >> >> >> >> You received this message because you are subscribed to the >> Google >> >> >> >> Groups >> >> >> >> "sympy" group. >> >> >> >> To post to this group, send email to sympy@googlegroups.com. >> >> >> >> To unsubscribe from this group, send email to >> >> >> >> sympy+unsubscr...@googlegroups.com. >> >> >> >> For more options, visit this group at >> >> >> >> http://groups.google.com/group/sympy?hl=en. >> >> >> >> >> >> >> > >> >> >> > >> >> >> > >> >> >> > -- >> >> >> > Tomo Lazovich >> >> >> > Harvard College '11 >> >> >> > 278 Winthrop House Mail Center >> >> >> > Cambridge, MA 02138 >> >> >> > >> >> >> > -- >> >> >> > You received this message because you are subscribed to the Google >> >> >> > Groups >> >> >> > "sympy" group. >> >> >> > To post to this group, send email to sympy@googlegroups.com. >> >> >> > To unsubscribe from this group, send email to >> >> >> > sympy+unsubscr...@googlegroups.com. >> >> >> > For more options, visit this group at >> >> >> > http://groups.google.com/group/sympy?hl=en. >> >> >> > >> >> >> >> >> >> >> >> >> >> >> >> -- >> >> >> Brian E. Granger >> >> >> Cal Poly State University, San Luis Obispo >> >> >> bgran...@calpoly.edu and elliso...@gmail.com >> >> >> >> >> >> -- >> >> >> You received this message because you are subscribed to the Google >> >> >> Groups >> >> >> "sympy" group. >> >> >> To post to this group, send email to sympy@googlegroups.com. >> >> >> To unsubscribe from this group, send email to >> >> >> sympy+unsubscr...@googlegroups.com. >> >> >> For more options, visit this group at >> >> >> http://groups.google.com/group/sympy?hl=en. >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > Tomo Lazovich >> >> > Harvard College '11 >> >> > 278 Winthrop House Mail Center >> >> > Cambridge, MA 02138 >> >> > >> >> > -- >> >> > You received this message because you are subscribed to the Google >> >> > Groups >> >> > "sympy" group. >> >> > To post to this group, send email to sympy@googlegroups.com. >> >> > To unsubscribe from this group, send email to >> >> > sympy+unsubscr...@googlegroups.com. >> >> > For more options, visit this group at >> >> > http://groups.google.com/group/sympy?hl=en. >> >> > >> >> >> >> -- >> >> You received this message because you are subscribed to the Google >> Groups >> >> "sympy" group. >> >> To post to this group, send email to sympy@googlegroups.com. >> >> To unsubscribe from this group, send email to >> >> sympy+unsubscr...@googlegroups.com. >> >> For more options, visit this group at >> >> http://groups.google.com/group/sympy?hl=en. >> >> >> > >> > >> > >> > -- >> > Tomo Lazovich >> > Harvard College '11 >> > 278 Winthrop House Mail Center >> > Cambridge, MA 02138 >> > >> > -- >> > You received this message because you are subscribed to the Google >> Groups >> > "sympy" group. >> > To post to this group, send email to sympy@googlegroups.com. >> > To unsubscribe from this group, send email to >> > sympy+unsubscr...@googlegroups.com. >> > For more options, visit this group at >> > http://groups.google.com/group/sympy?hl=en. >> > >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sympy" group. >> To post to this group, send email to sympy@googlegroups.com. >> To unsubscribe from this group, send email to >> sympy+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/sympy?hl=en. >> >> > > > -- > Tomo Lazovich > Harvard College '11 > 278 Winthrop House Mail Center > Cambridge, MA 02138 > -- Tomo Lazovich Harvard College '11 278 Winthrop House Mail Center Cambridge, MA 02138 -- You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com. To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sympy?hl=en.