In my early days of programming I often used to get memory related fatal errors in the following format:

Fatal error: Allowed memory size of &lt;some big number&gt; bytes exhausted 
(tried to allocate &lt;some small number&gt; bytes) in /path/to/filename.php 
on line &lt;some line number&gt;


I'm a little embarrassed to state that even though I have figured out how to solve them and take steps to avoid them altogether, I'm still not quite sure what exactly does the message translate to in simple words.

For example, if I get a message such as:

Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4000 bytes) 
in ........ on line 34


As things stand at the moment, I assume it to be stating that the script consumes 67108864 bytes of data, but only 4000 bytes are available during runtime.


Am I right in my assumption?
If not, what's the correct interpretation?



Question: Change of basis in non-linear Schrodinger equation
Answer: The linear terms it seems you can handle. As piece of general advice, the meaning of these terms are always clearly if integrate over the momentum coordinates of each of the fields, using delta functions to preserve the value. So the non-linear term would be
$$\sum_{q_1,q_2,q_3} g(q_1,q_2,q_3) \psi(q_1)^*\psi(q_2)\psi(q_3)\delta(-q_1+q_2+q_3 -k)$$

Maybe you can also see this way that the structure is determined by momentum conservation/translation invariance. Now when I integrate this by $\int\!dk\,e^{ikr}$, the $k$ integral is resolved trivially and I'm left with fourier transforms over the $q$s. Since Fourier transforms take multiplication to convolution, you can calculate that we get
$$\int dr_{123}\,\tilde{g}(r-r_1,r-r_2,r-r_3)\tilde{\psi}^*\!(r_1)\tilde{\psi}(r_2)\tilde{\psi}(r_3)$$

Which is more or less the most general third order nonlinear term you can write. In your case you can also reduce this further by using the real space transforms of $X$, either by plugging in directly to the first equation I wrote, or by calculating $\tilde{g}$ and plugging into the second.