Solve math problems step-by-step with full working. Use for: solve integral, solve differential equation, solve ODE, solve system of equations, find eigenvalues, solve optimization problem, homework help, exam problem, step-by-step solution, show your work, explain how to solve, tutorial. Triggers: "solve", "find", "show steps", "step by step", "how to solve", "homework", "exam", "explain the solution", "work through"
Solve university-level mathematics with rigorous step-by-step solutions.
Phase 1: ANALYZE
- What is given?
- What is asked?
- What type of problem? (ODE, integral, eigenvalue, optimization...)
- What method to use?
Phase 2: SOLVE (with SymPy verification at each step)
- Execute each step in Python
- Show intermediate results
- Catch errors early
Phase 3: VERIFY (REQUIRED - never skip)
- Substitute solution back into original
- Check numerically at specific points
- Test boundary/edge cases
<pattern name="Differential Equations">
```python
from sympy import *
x = symbols('x')
y = Function('y')
</pattern>
<pattern name="Linear Algebra">
```python
from sympy import Matrix, simplify, pprint
</pattern>
<pattern name="Series and Limits">
```python
from sympy import *
x, n = symbols('x n')
ode = Eq(y(x).diff(x, 2) + 4y(x), sin(2x)) print(f"Order: 2, Linear: Yes, Constant coefficients: Yes")
sol = dsolve(ode, y(x)) print(f"General solution: {sol}")
ics = {y(0): 0, y(x).diff(x).subs(x, 0): 1} sol_ivp = dsolve(ode, y(x), ics=ics) print(f"Particular solution: {sol_ivp}")
lhs = sol_ivp.rhs.diff(x, 2) + 4sol_ivp.rhs rhs = sin(2x) check = simplify(lhs - rhs) print(f"Verification (should be 0): {check}") assert check == 0, "Solution failed verification!"
</pattern>
<pattern name="Integrals">
```python
from sympy import *
x = symbols('x')
# Step 1: Set up integral
expr = x**2 * exp(-x)
a, b = 0, oo
# Step 2: Check convergence (for improper integrals)
print(f"Integrand behavior as x->oo: {limit(expr, x, oo)}")
# Step 3: Compute
result = integrate(expr, (x, a, b))
print(f"Symbolic result: {result}")
# Step 4: Verify numerically
from scipy.integrate import quad
import numpy as np
numerical, _ = quad(lambda t: t**2 * np.exp(-t), 0, 100)
print(f"Numerical check: {numerical}")
print(f"Match: {abs(float(result) - numerical) < 1e-6}")
A = Matrix([[1, 2], [3, 4]]) print("Matrix A:"); pprint(A)
eigenvals = A.eigenvals() print(f"Eigenvalues: {eigenvals}")
for val, mult, vecs in A.eigenvects(): print(f"lambda = {val}: eigenvector = {vecs[0].T}")
P, D = A.diagonalize() print("P ="); pprint(P) print("D ="); pprint(D)
check = simplify(P * D * P.inv() - A) print(f"PDP^(-1) - A = {check}") # should be zero matrix
</pattern>
<pattern name="Optimization with Constraints">
```python
from sympy import *
x, y, lam = symbols('x y lambda', real=True)
# Step 1: Define objective and constraint
f = x**2 + y**2 # minimize this
g = x + y - 1 # subject to g = 0
# Step 2: Set up Lagrangian
L = f - lam * g
# Step 3: Solve KKT conditions
eqs = [
Eq(diff(L, x), 0), # dL/dx = 0
Eq(diff(L, y), 0), # dL/dy = 0
Eq(g, 0) # constraint
]
critical = solve(eqs, [x, y, lam])
print(f"Critical points: {critical}")
# Step 4: Verify and classify
for point in critical:
x_val, y_val, lam_val = point
obj_val = f.subs([(x, x_val), (y, y_val)])
constraint_check = g.subs([(x, x_val), (y, y_val)])
print(f"Point ({x_val}, {y_val}): f = {obj_val}, g = {constraint_check}")
print("Taylor series of sin(x):") print(series(sin(x), x, 0, n=7))
print(f"Sum of 1/n^2: {Sum(1/n**2, (n, 1, oo)).doit()}") # = pi^2/6
print(f"lim (1+1/n)^n as n->oo: {limit((1 + 1/n)**n, n, oo)}") # = e
</pattern>
## Output Format
```markdown
## Problem
[Restate the problem clearly]
## Solution
### Step 1: [Analyze/Setup]
[Explanation of approach]
```python
# Code with output
[Explanation]
# Code with output
...
# Substitution check
# Numerical check
All checks passed.
$$ \boxed{\text{answer}} $$
## Domain Checklists
| Domain | Key Steps |
|--------|-----------|
| ODEs | Classify order/linearity, solve homogeneous + particular, apply ICs, verify by substitution |
| Integrals | Check convergence, compute, verify numerically |
| Linear Algebra | Check properties, compute, verify A = PDP^{-1} |
| Optimization | Find critical points, check Hessian/bordered Hessian, verify constraint satisfaction |