Infinite Square well: Abrupt change in well's length So, one of my homework problems reads

A particle is trapped in an infinitely deep square well of width $a$, suddenly the walls are separated by infinite distance so that the particle becomes free. What is the probability that the particle has momentum between $p$ and $p + dp$?

I know that if the wavefunction of a particle is $\Psi(x)$, then the probability of finding the momentum between $p$ and $p+\text{d}p$ is given by- $|a(p)|^2 \text{d}p$ where $a(p)$ is given by-
$$a(p)=\dfrac{1}{\sqrt{2\pi \hbar}}\displaystyle \int_{-\infty}^{+\infty}\Psi(x)\ e^{-ipx/\hbar}\ \text{d}x$$
So, the question is- How does the wavefunction change with this abrupt change in the well's dimensions. And what quantity does not change for the particle even after the change of length between walls. To the second question, I think the answer is energy, but which energy state should I assume the particle to be in if it is not mentioned beforehand, since the energy in a well is given by- $\dfrac{n^2h^2}{8mL^2}$?
 A: 
How does the wavefunction change with this abrupt change in the well's dimensions?

It doesn't. The term 'abrupt' implies that the change in the potential is so fast that the state of the system does not have time to react to the change before it is complete, so the state when the new situation becomes operative is identical to the state just before the change started. This makes the answer to your second question easy:

what quantity does not change for the particle even after the change of length between walls?

The wavefunction.
Now, the set-piece you quote does have a problem in that it does not specify the state of the system before the potential changes, so it's basically unanswerable unless you can make a well-justified argument that allows you to specify that state as a specific eigenstate of the energy, or some linear combination of them. Unfortunately, you're basically on your own on that front. If this is formal homework assigned by an instructor, then you should ask them what to do; if it's a textbook problem and you're self-studying, then find a better textbook.
A: Your approach is right while calculating a(p). Just be careful about the limits of integration. Don't assume wave function is spread everywhere but it's between 0 to a(the dimensions of the infinite square well).
Detailed solution of your problem can be found on the link https://www.sarthaks.com/445606/a-particle-is-trapped-in-an-infinitely-deep-square-well-of-width-a
