>> Help me put this into maxima. \Psi(x, t) = \psi(x)e^{-iEt/\hbar}. |\Psi(x, t)|^2

```maxima
/* Define the wavefunction Psi(x, t) */
Psi(x, t) := psi(x) * %e^(-%i * E * t / %hbar);

/* Calculate the probability density |Psi(x, t)|^2 */
probability_density(x, t) := abs(Psi(x, t))^2;

/* To see the result, you can evaluate it (though it will remain symbolic without defining psi(x), E, t, and %hbar) */
probability_density(x, t);
```

**Explanation:**

1. **`Psi(x, t) := psi(x) * %e^(-%i * E * t / %hbar);`**:
   - This line defines a function `Psi` that takes two arguments, `x` and `t`.
   - `:=` is the assignment operator in Maxima.
   - `psi(x)` represents the spatial part of the wavefunction, which is a function of `x`.
   - `%e` represents the base of the natural logarithm (Euler's number).
   - `%i` represents the imaginary unit (√-1).
   - `E` represents the energy.
   - `t` represents time.
   - `%hbar` represents the reduced Planck constant (ħ). Maxima uses `%` to denote mathematical constants.

2. **`probability_density(x, t) := abs(Psi(x, t))^2;`**:
   - This line defines a function `probability_density` that also takes `x` and `t` as arguments.
   - `abs(z)` calculates the absolute value (or modulus) of a complex number `z`. For a complex number `a + bi`, `abs(a + bi) = sqrt(a^2 + b^2)`.
   - When you square the absolute value of a complex number, `|z|^2 = z * conjugate(z)`, where `conjugate(z)` is the complex conjugate of `z` (obtained by changing the sign of the imaginary part).

**How Maxima Evaluates `abs(Psi(x, t))^2`:**

Let's break down how Maxima will handle the calculation:

1. **`Psi(x, t) = psi(x) * %e^(-%i * E * t / %hbar)`**

2. **`conjugate(Psi(x, t))`**: The complex conjugate of `Psi(x, t)` will be:
   `conjugate(psi(x)) * conjugate(%e^(-%i * E * t / %hbar))`

   Assuming `psi(x)` is a real-valued function (which is often the case in basic quantum mechanics examples), `conjugate(psi(x)) = psi(x)`.

   The conjugate of `e^(-iθ)` is `e^(iθ)`. Therefore, `conjugate(%e^(-%i * E * t / %hbar)) = %e^(%i * E * t / %hbar)`.

   So, `conjugate(Psi(x, t)) = psi(x) * %e^(%i * E * t / %hbar)`.

3. **`abs(Psi(x, t))^2 = Psi(x, t) * conjugate(Psi(x, t))`**:
   `abs(Psi(x, t))^2 = (psi(x) * %e^(-%i * E * t / %hbar)) * (psi(x) * %e^(%i * E * t / %hbar))`
   `abs(Psi(x, t))^2 = psi(x)^2 * %e^(-%i * E * t / %hbar + %i * E * t / %hbar)`
   `abs(Psi(x, t))^2 = psi(x)^2 * %e^(0)`
   `abs(Psi(x, t))^2 = psi(x)^2 * 1`
   `abs(Psi(x, t))^2 = psi(x)^2`

**Therefore, when you evaluate `probability_density(x, t);` in Maxima, it will likely simplify to `psi(x)^2` (assuming `psi(x)` is real).**

**To use this in further calculations, you would need to define the specific form of `psi(x)`, and potentially assign values to `E` and `%hbar` if needed for numerical evaluation.**

...

>> In the equation %e^(-%i * E * t / %hbar); does Maxima assume that E is real or complex?

In the equation `%e^(-%i * E * t / %hbar);`, **Maxima does not inherently assume whether `E` is real or complex.**

When Maxima encounters a symbolic variable like `E`, it treats it as a general algebraic symbol that can represent either a real or a complex number. It will only make assumptions if you explicitly tell it to.

**Here's how Maxima handles it:**

* **Symbolic Manipulation:** Maxima will perform algebraic manipulations on the expression without needing to know the nature of `E`. For example, if you were to take the derivative with respect to `t`, it would do so symbolically, treating `E` as a constant with respect to `t`.

* **No Automatic Simplification Based on Real/Complex:** Maxima won't automatically simplify the expression in a way that assumes `E` is real or complex. For example, it won't automatically take the real or imaginary part of the expression unless you explicitly ask it to using functions like `realpart()` and `imagpart()`.

**To make Maxima treat `E` as real or complex, you would need to use the `assume` command:**

* **Assuming `E` is real:**
   ```maxima
   assume(E, real);
   ```

* **Assuming `E` is positive real:**
   ```maxima
   assume(E > 0, real);
   ```

* **Assuming `E` is complex (you can also specify the form):**
   ```maxima
   assume(E, complex);
   assume(E = er + %i*ei); /* Assume E has real part 'er' and imaginary part 'ei' */
   ```

**Without any `assume` statements, Maxima will treat `E` as a general symbolic quantity.** This allows for maximum flexibility, as the expression remains valid whether `E` is real or complex. However, if you need Maxima to perform simplifications or evaluations that depend on the nature of `E`, you will need to provide that information using `assume`.

In the context of the time-dependent Schrödinger equation and the given wavefunction, the energy `E` is typically considered to be a real number representing the energy eigenvalue. If you intend to work with this assumption, it would be good practice to include `assume(E, real);` in your Maxima session before further manipulations.

>> E = er + %i*ei;
>>
abs(E)^2;

>> I expect to get er^2 + ei^2 but I get E^2 instead. What can I do?

You are absolutely correct in your expectation. The issue is that you defined `E` as a symbolic expression, and when you take the absolute value squared of a symbolic variable that hasn't been explicitly declared as complex, Maxima doesn't automatically expand it into its real and imaginary parts.

Here's how you can get the desired result `er^2 + ei^2` in Maxima:

**Method 1: Use `rectform` after taking the absolute value squared**

The `rectform()` function converts a complex expression into its rectangular form (a + bi). When you take the absolute value squared, the imaginary parts should cancel out, and `rectform` can help simplify the result.

```maxima
E : er + %i*ei;
abs_E_squared : abs(E)^2;
rectform(abs_E_squared);
```

**Explanation:**

1. `E : er + %i*ei;`: You correctly define `E`.
2. `abs_E_squared : abs(E)^2;`: This calculates the symbolic absolute value squared.
3. `rectform(abs_E_squared);`: This function takes the result and tries to express it in the form `a + bi`. In this case, the imaginary part will be zero, leaving you with the real part, which should be `er^2 + ei^2`.

**Method 2: Explicitly use the definition of absolute value squared for complex numbers**

For a complex number `z = a + bi`, `|z|^2 = z * conjugate(z)`. You can use the `conjugate()` function in Maxima:

```maxima
E : er + %i*ei;
abs_E_squared : E * conjugate(E);
expand(abs_E_squared);
```

**Explanation:**

1. `E : er + %i*ei;`: Define `E`.
2. `abs_E_squared : E * conjugate(E);`: Calculate `E` multiplied by its complex conjugate.
3. `expand(abs_E_squared);`: This function expands the product, which will result in `(er + %i*ei) * (er - %i*ei) = er^2 - (%i*ei)^2 = er^2 - (-ei^2) = er^2 + ei^2`.

**Method 3: Use `assume` to declare `er` and `ei` as real**

If you tell Maxima that `er` and `ei` are real, it might perform the simplification automatically when you take the absolute value squared.

```maxima
assume(er, real);
assume(ei, real);
E : er + %i*ei;
abs(E)^2;
```

**Explanation:**

By assuming `er` and `ei` are real, Maxima understands the properties of real numbers and how they interact with the imaginary unit `%i` when calculating the absolute value.

**Which method should you use?**

* **Method 2 (using `conjugate` and `expand`) is generally the most direct and reliable way to get the absolute value squared of a complex expression in Maxima.** It explicitly uses the definition.
* **Method 1 (using `rectform`) can also work well in many cases.**
* **Method 3 (using `assume`) is useful if you know that `er` and `ei` will always be real in your context.** It can lead to more automatic simplifications in other parts of your calculations as well. However, if `er` or `ei` could potentially be complex in other scenarios, you might not want to make this assumption globally.

I recommend trying **Method 2** first, as it directly applies the definition of the absolute value squared for complex numbers.

