# Period-Doubling Bifurcation Point of a Delay Differential Equation

## Problem

Consider the delay differential equation

    x'(t) = beta * x(t - tau) / (1 + x(t - tau)^n) - gamma * x(t)

with beta = 0.21, gamma = 0.105, n = 9.8, and the delay **tau as a free
parameter**. For tau in the range of interest the equation has an unstable
periodic solution whose dominant nontrivial Floquet multiplier mu(tau) is
real and negative, and mu(tau) decreases as tau grows.

Two deliverables:

**(a) Locate the period-doubling (flip) bifurcation point** — the critical
delay tau* in [10, 20] at which the periodic orbit's dominant nontrivial
Floquet multiplier equals exactly -1 — and give the orbit at that parameter.

**(b) Switch onto the doubled branch** — give the period-doubled orbit that
is born at the bifurcation, evaluated at the fixed evidence delay
tau_ev = 14.0. Beware: the period-1 orbit written at double period is an
exact solution of the same equation at the same delay, and is distinguished
from a genuine doubled orbit only by the fundamentality condition below.

The Floquet multipliers are the eigenvalues of the monodromy operator of the
linearisation

    y'(t) = -gamma * y(t) + f'(x(t - tau)) * y(t - tau),
    f(u) = beta * u / (1 + u^n),

acting on the history space C([-tau, 0]). The multiplier mu = 1 always
belongs to the spectrum (time-translation of the orbit); "dominant
nontrivial" means the eigenvalue of largest modulus among the rest.

## Required outputs (under `output/`)

1. `output/solution.npz` with:
   - `tau_star` — float64 scalar: the critical delay
   - `period` — float64 scalar: the period T of the orbit at tau_star
   - `x` — float64 array of shape (4096,): samples x(t_j) at
     t_j = j * T / 4096
   - `period2` — float64 scalar: period of the doubled orbit at tau_ev = 14.0
   - `x2` — float64 array of shape (4096,): its samples over one period
2. `output/results.json` with keys `tau_star`, `period`, `resid_linf`,
   `mu_re`, `mu_im`, `period2`, `resid_linf_2` — your own truthfully
   computed values.

## Evaluation (recomputed from your files alone; deterministic)

The grader forms the trigonometric interpolant of your 4096 samples, using
X = rfft(x) and mode numbers k:

- derivative: irfft of X * (2*pi*i*k/T), Nyquist mode of the derivative
  zeroed;
- delayed values: irfft of X * exp(-2*pi*i*k*(tau_star mod T)/T);
- residual r_j = x'(t_j) - [beta*xd_j/(1+xd_j^n) - gamma*x_j].

Accepted (score 1.0) iff ALL hold:
- tau_star in [10, 20] and period > tau_star;
- min(x) > 0 and max(x) - min(x) >= 0.4;
- spectral tail: relative norm of the top 1/8 of Fourier modes <= 1e-10;
- fundamentality: min over k in {2..6} of max_j |x_j - (T/k-shift of x)_j|
  >= 0.1 (rejects k-fold repetitions of a shorter orbit);
- DDE residual max_j |r_j| <= 1e-8;
- **bifurcation condition**: the grader recomputes the dominant nontrivial
  Floquet multiplier of YOUR orbit at YOUR tau_star, using a
  two-resolution Richardson-extrapolated monodromy discretisation, and
  requires |mu + 1| <= 1e-4.

For the doubled orbit at tau_ev = 14.0, with the same spectral machinery:
period2 in [70, 95]; min(x2) > 0; amplitude >= 0.4; spectral tail <= 1e-10;
DDE residual <= 1e-8 at tau_ev; and fundamentality gap >= 0.1.

Score 1.0 when both deliverables pass. Score 0.5 when the bifurcation point
passes (or |mu + 1| is within 1e-2) but the doubled orbit is missing, is a
decoy, or fails its checks. Score 0.0 otherwise.

The threshold on |mu + 1| reflects the grader's own certified accuracy: its
Richardson estimator shows a two-resolution spread of ~3e-6 and a
trivial-multiplier canary of ~2e-5 at this orbit, so 1e-4 is the tightest
bound it can vouch for. There is no hidden reference value — "mu = -1" is an
intrinsic, checkable condition.

## Constraints

- Use only Python 3 with NumPy and SciPy. (SciPy has no delay-equation
  support: the nonlinear integrator, the periodic boundary-value solver, and
  the linearised monodromy operator must all be built from scratch.)
- No network access; no package installation.
- Wall-clock budget: 3 hours on 4 vCPUs / 8 GB RAM.
- Write only under `output/`.
