import Mathlib /- KineticHook.lean The hook effect in one-pot (one-step) sandwich immunoassays, at any read time. Model. Capture antibody A (total A, dissociation constant K1, on-rate k1) and detection antibody C (total C, K2, k2) bind two independent epitopes of analyte B (total y), by mass action, in one well-mixed pot. Signal = ternary complex [ABC]. What is proved here (Lean 4 + Mathlib; no sorry): 1. tern_times_free [ABC] * [B] = [AB] * [BC] at every time t >= 0 (not only at equilibrium), for any solution of the six rate equations. 2. sandwich_closed_form Started with no complexes, the network has the exact solution [ABC](t) = occ1(t) * occ2(t) / y, where each occupancy is occ = 2*A*y / (A + y + K + d * coth(k*d*t/2)), d = sqrt((y + K - A)^2 + 4*A*K). 3. one_peak For any two site profiles (equilibrium, or kinetic at any two read times, so staggered or premixed protocols are covered) the dose-response has exactly one peak: strictly increasing up to a hook point y0, strictly decreasing after it. kinetic_one_peak The same statement for the kinetic read at time t. 4. peak_ge The hook point is at least min (A + K1) (C + K2), always. kinetic_peak_ge Read at time t, the hook point is at least min (max (A + K1) (1/(k1*t))) (max (C + K2) (1/(k2*t))). 5. kinetic_hook_first Explicit example where the kinetic hook point lies BELOW the equilibrium hook point: the signal at analyte 136741 is more than 10 percent below the signal at analyte 30465, while the equilibrium response is still rising at 136741. 6. surface_one_peak Sensor surface with mass transport (two-compartment model, d theta/dt = k (y (1 - theta) - K theta) / (1 + Da (1 - theta)), bulk analyte y held by flow, Damkohler number Da >= 0): at every read time the signal theta(t) * 2C/W has exactly one peak in y, for any detection profile. surface_one_peak_level The same, for any coverage obeying the exact level equation Elev = k K t (the implicit solution of the rate law). Notation. A Profile packages how one site responds through phi(d): phi(d) = d is equilibrium; phi(d) = d*(1+u)/(1-u) with u = exp(-(s*d)) is the kinetic solution read at s = k_on * t (this is d * coth(s*d/2)). W = A + y + K + phi(d), occupancy = 2*A*y/W, Tsig = occ1 * occ2 / y, and H = d(log W)/d(log y), so d(log Tsig)/d(log y) = 1 - H1 - H2. Checked on live.lean-lang.org (Lean 4, current Mathlib), 26 November 2026. -/ open Set namespace Hook noncomputable def dd (A K y : ℝ) : ℝ := Real.sqrt ((y + K - A)^2 + 4*A*K) lemma rad_pos {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : 0 < (y + K - A)^2 + 4*A*K := by have h := mul_pos hA hK nlinarith [sq_nonneg (y + K - A)] lemma dd_pos {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : 0 < dd A K y := Real.sqrt_pos.mpr (rad_pos hA hK y) lemma dd_sq {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : dd A K y ^ 2 = (y + K - A)^2 + 4*A*K := Real.sq_sqrt (rad_pos hA hK y).le lemma abs_m_lt {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : |y + K - A| < dd A K y := by apply (Real.lt_sqrt (abs_nonneg _)).mpr rw [sq_abs] have h := mul_pos hA hK linarith lemma dd_ge {A K : ℝ} (hK : 0 < K) {y : ℝ} (hy : 0 ≤ y) : y - A - K ≤ dd A K y := by have h : |y - A - K| ≤ dd A K y := by apply Real.abs_le_sqrt nlinarith [mul_nonneg hK.le hy] exact (abs_le.mp h).2 lemma hasDerivAt_dd {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : HasDerivAt (dd A K) ((y + K - A) / dd A K y) y := by have h1 : HasDerivAt (fun z : ℝ => (z + K - A)^2 + 4*A*K) (2*(y + K - A)) y := by have h := ((((hasDerivAt_id' y).add_const K).sub_const A).pow 2).add_const (4*A*K) exact (h : HasDerivAt (fun z : ℝ => (z + K - A)^2 + 4*A*K) _ y).congr_deriv (by norm_num) have h2 := h1.sqrt (rad_pos hA hK y).ne' have h3 : HasDerivAt (dd A K) (2*(y + K - A) / (2 * dd A K y)) y := h2 have hne := (dd_pos hA hK y).ne' exact h3.congr_deriv (by field_simp) /-- How one antibody site responds. φ d = d is equilibrium; φ d = d * coth (s * d / 2) is the kinetic solution read at s = k_on * t. -/ structure Profile where φ : ℝ → ℝ P : ℝ → ℝ Q : ℝ → ℝ hφ : ∀ d, 0 < d → HasDerivAt φ (P d) d hP : ∀ d, 0 < d → HasDerivAt P (Q d) d P_nonneg : ∀ d, 0 < d → 0 ≤ P d P_le_one : ∀ d, 0 < d → P d ≤ 1 Q_nonneg : ∀ d, 0 < d → 0 ≤ Q d le_φ : ∀ d, 0 < d → d ≤ φ d noncomputable def W (p : Profile) (A K y : ℝ) : ℝ := A + y + K + p.φ (dd A K y) noncomputable def W1 (p : Profile) (A K y : ℝ) : ℝ := 1 + p.P (dd A K y) * ((y + K - A) / dd A K y) noncomputable def W2 (p : Profile) (A K y : ℝ) : ℝ := p.Q (dd A K y) * ((y + K - A) / dd A K y) * ((y + K - A) / dd A K y) + p.P (dd A K y) * (4*A*K / dd A K y ^ 3) lemma W_ge (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : A + y + K + dd A K y ≤ W p A K y := by have h := p.le_φ (dd A K y) (dd_pos hA hK y) unfold W linarith lemma two_A_lt_W (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : 2*A < W p A K y := by have h1 := W_ge p hA hK y have h2 := (abs_lt.mp (abs_m_lt hA hK y)).1 linarith lemma two_y_le_W (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) {y : ℝ} (hy : 0 ≤ y) : 2*y ≤ W p A K y := by have h1 := W_ge p hA hK y have h2 := dd_ge (A := A) hK hy linarith lemma W_pos (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : 0 < W p A K y := by have h := two_A_lt_W p hA hK y linarith lemma hasDerivAt_W (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : HasDerivAt (W p A K) (W1 p A K y) y := by have hd := hasDerivAt_dd hA hK y have hφ := (p.hφ (dd A K y) (dd_pos hA hK y)).comp y hd have h := (((hasDerivAt_id' y).const_add A).add_const K).add hφ exact (h : HasDerivAt (W p A K) _ y).congr_deriv (by unfold W1; ring1) lemma hasDerivAt_W1 (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : HasDerivAt (W1 p A K) (W2 p A K y) y := by have hdpos := dd_pos hA hK y have hne := hdpos.ne' have hd := hasDerivAt_dd hA hK y have hP := (p.hP (dd A K y) hdpos).comp y hd have hm : HasDerivAt (fun z : ℝ => z + K - A) 1 y := ((hasDerivAt_id' y).add_const K).sub_const A have hq := hm.div hd hne have h := (hP.mul hq).const_add 1 have hsq := dd_sq hA hK y have h4 : 4*A*K = dd A K y ^ 2 - (y + K - A)^2 := by linarith refine (h : HasDerivAt (W1 p A K) _ y).congr_deriv ?_ unfold W2 rw [h4] simp only [Function.comp_apply, Pi.div_apply] field_simp lemma core_ineq {A K y d P Q φ : ℝ} (hA : 0 < A) (hK : 0 < K) (hy : 0 < y) (hd : 0 < d) (hsq : d^2 = (y + K - A)^2 + 4*A*K) (hP0 : 0 ≤ P) (hP1 : P ≤ 1) (hQ : 0 ≤ Q) (hφ : d ≤ φ) : 0 < ((1 + P*((y + K - A)/d)) + y*(Q*((y + K - A)/d)*((y + K - A)/d) + P*(4*A*K/d^3))) * (A + y + K + φ) - y*(1 + P*((y + K - A)/d))^2 := by have hAK : 0 < A*K := mul_pos hA hK obtain ⟨m, hm⟩ : ∃ m : ℝ, m = y + K - A := ⟨_, rfl⟩ rw [← hm] at hsq ⊢ have h1 : m < d := by by_contra hcon have h := not_lt.mp hcon have h3 := mul_self_le_mul_self hd.le h nlinarith have h2 : -d < m := by by_contra hcon have h := not_lt.mp hcon have h3 : d ≤ -m := by linarith have h4 := mul_self_le_mul_self hd.le h3 nlinarith obtain ⟨r, hr⟩ : ∃ r : ℝ, r = m/d := ⟨_, rfl⟩ rw [← hr] have hrd : r*d = m := by rw [hr]; field_simp have hr1 : r < 1 := by by_contra hcon have h := not_lt.mp hcon nlinarith [mul_le_mul_of_nonneg_right h hd.le] have hr2 : -1 < r := by by_contra hcon have h := not_lt.mp hcon nlinarith [mul_le_mul_of_nonneg_right h hd.le] have hc1 : P*r < 1 := by rcases hP1.lt_or_eq with h | h · nlinarith [mul_nonneg hP0 (sub_nonneg.mpr hr1.le)] · rw [h]; linarith have hc2 : -1 < P*r := by rcases hP1.lt_or_eq with h | h · nlinarith [mul_nonneg hP0 (by linarith : (0:ℝ) ≤ 1 + r)] · rw [h]; linarith have hrr : 0 ≤ Q*r*r := by nlinarith [mul_nonneg hQ (mul_self_nonneg r)] have hd3 : 0 < d^3 := pow_pos hd 3 have hPd : 0 ≤ P*(4*A*K/d^3) := by apply mul_nonneg hP0 refine div_nonneg ?_ hd3.le nlinarith have hW2 : 0 ≤ Q*r*r + P*(4*A*K/d^3) := by linarith have hkey : 0 < A + K + φ - y*(P*r) := by by_cases hm0 : m ≤ 0 · have hr0 : r ≤ 0 := by by_contra hcon have h := not_le.mp hcon nlinarith [mul_pos h hd] have h5 : 0 ≤ y*P := mul_nonneg hy.le hP0 have h6 : y*(P*r) ≤ 0 := by nlinarith [mul_nonneg h5 (neg_nonneg.mpr hr0)] linarith · have hm0 := not_le.mp hm0 have hr0 : 0 < r := by rw [hr]; exact div_pos hm0 hd have h5 : y*(P*r) ≤ y*r := by nlinarith [mul_nonneg (mul_nonneg hy.le hr0.le) (sub_nonneg.mpr hP1)] have hy' : y = m - K + A := by linarith have e1 : y*m = m^2 + (A - K)*m := by rw [hy']; ring have e2 := mul_pos (add_pos hA hK) (sub_pos.mpr h1) have e3 := mul_pos hK hm0 have h6 : y*m < (A + K)*d + d^2 := by nlinarith have h7 : y*r*d < (A + K + d)*d := by have e4 : y*r*d = y*m := by rw [mul_assoc, hrd] nlinarith have h8 : y*r < A + K + d := by by_contra hcon have h := not_lt.mp hcon nlinarith [mul_le_mul_of_nonneg_right h hd.le] linarith have hWpos : 0 < A + y + K + φ := by linarith have e1 := mul_pos (by linarith : (0:ℝ) < 1 + P*r) hkey have e2 := mul_nonneg (mul_nonneg hy.le hW2) hWpos.le have hfinal : ((1 + P*r) + y*(Q*r*r + P*(4*A*K/d^3))) * (A + y + K + φ) - y*(1 + P*r)^2 = (1 + P*r)*(A + K + φ - y*(P*r)) + y*(Q*r*r + P*(4*A*K/d^3))*(A + y + K + φ) := by ring rw [hfinal] linarith noncomputable def H (p : Profile) (A K y : ℝ) : ℝ := y * W1 p A K y / W p A K y lemma hasDerivAt_H (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (y : ℝ) : HasDerivAt (H p A K) (((W1 p A K y + y * W2 p A K y) * W p A K y - y * W1 p A K y ^ 2) / W p A K y ^ 2) y := by have hW := hasDerivAt_W p hA hK y have hW1 := hasDerivAt_W1 p hA hK y have hne := (W_pos p hA hK y).ne' have h := ((hasDerivAt_id' y).mul hW1).div hW hne refine (h : HasDerivAt (H p A K) _ y).congr_deriv ?_ simp only [Pi.mul_apply] ring lemma H_deriv_pos (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) {y : ℝ} (hy : 0 < y) : 0 < ((W1 p A K y + y * W2 p A K y) * W p A K y - y * W1 p A K y ^ 2) / W p A K y ^ 2 := by have hd := dd_pos hA hK y have hnum := core_ineq hA hK hy hd (dd_sq hA hK y) (p.P_nonneg _ hd) (p.P_le_one _ hd) (p.Q_nonneg _ hd) (p.le_φ _ hd) exact div_pos hnum (pow_pos (W_pos p hA hK y) 2) lemma H_strictMonoOn (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) : StrictMonoOn (H p A K) (Ioi 0) := by apply strictMonoOn_of_deriv_pos (convex_Ioi 0) · intro y _ exact (hasDerivAt_H p hA hK y).continuousAt.continuousWithinAt · intro y hy rw [interior_Ioi] at hy rw [(hasDerivAt_H p hA hK y).deriv] exact H_deriv_pos p hA hK hy noncomputable def Tsig (p1 p2 : Profile) (A C K1 K2 y : ℝ) : ℝ := (2*A*y / W p1 A K1 y) * (2*C*y / W p2 C K2 y) / y lemma hasDerivAt_Tsig (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y : ℝ} (hy : 0 < y) : HasDerivAt (Tsig p1 p2 A C K1 K2) (Tsig p1 p2 A C K1 K2 y * (1 - H p1 A K1 y - H p2 C K2 y) / y) y := by have hWa := hasDerivAt_W p1 hA hK1 y have hWc := hasDerivAt_W p2 hC hK2 y have ha := (W_pos p1 hA hK1 y).ne' have hc := (W_pos p2 hC hK2 y).ne' have hy0 := hy.ne' have h1 := ((hasDerivAt_id' y).const_mul (2*A)).div hWa ha have h2 := ((hasDerivAt_id' y).const_mul (2*C)).div hWc hc have h := (h1.mul h2).div (hasDerivAt_id' y) hy0 refine (h : HasDerivAt (Tsig p1 p2 A C K1 K2) _ y).congr_deriv ?_ unfold Tsig H simp only [Pi.mul_apply, Pi.div_apply] field_simp ring lemma Tsig_pos (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y : ℝ} (hy : 0 < y) : 0 < Tsig p1 p2 A C K1 K2 y := by have ha := W_pos p1 hA hK1 y have hc := W_pos p2 hC hK2 y unfold Tsig positivity lemma Tsig_le_self (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y : ℝ} (hy : 0 < y) : Tsig p1 p2 A C K1 K2 y ≤ y := by have ha := W_pos p1 hA hK1 y have hc := W_pos p2 hC hK2 y have ha2 := two_A_lt_W p1 hA hK1 y have hc2 := two_A_lt_W p2 hC hK2 y have e1 : 2*A*y / W p1 A K1 y ≤ y := by rw [div_le_iff₀ ha] nlinarith [mul_pos hy (sub_pos.mpr ha2)] have e2 : 2*C*y / W p2 C K2 y ≤ y := by rw [div_le_iff₀ hc] nlinarith [mul_pos hy (sub_pos.mpr hc2)] have e3 : 0 ≤ 2*C*y / W p2 C K2 y := by positivity have e4 := mul_le_mul e1 e2 e3 hy.le unfold Tsig rw [div_le_iff₀ hy] exact e4 lemma Tsig_le_div (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y : ℝ} (hy : 0 < y) : Tsig p1 p2 A C K1 K2 y ≤ A*C/y := by have ha := W_pos p1 hA hK1 y have hc := W_pos p2 hC hK2 y have ha2 := two_y_le_W p1 hA hK1 hy.le have hc2 := two_y_le_W p2 hC hK2 hy.le have e1 : 2*A*y / W p1 A K1 y ≤ A := by rw [div_le_iff₀ ha] nlinarith [mul_nonneg hA.le (sub_nonneg.mpr ha2)] have e2 : 2*C*y / W p2 C K2 y ≤ C := by rw [div_le_iff₀ hc] nlinarith [mul_nonneg hC.le (sub_nonneg.mpr hc2)] have e3 : 0 ≤ 2*C*y / W p2 C K2 y := by positivity have e4 := mul_le_mul e1 e2 e3 hA.le unfold Tsig exact div_le_div_of_nonneg_right e4 hy.le /-- One hook, always: for any two site profiles (equilibrium or kinetic, read at any times), the sandwich signal rises strictly up to a single peak y0 and falls strictly after it. -/ theorem one_peak (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) : ∃ y0 : ℝ, 0 < y0 ∧ H p1 A K1 y0 + H p2 C K2 y0 = 1 ∧ StrictMonoOn (Tsig p1 p2 A C K1 K2) (Ioc 0 y0) ∧ StrictAntiOn (Tsig p1 p2 A C K1 K2) (Ici y0) := by have hderiv : ∀ y, 0 < y → HasDerivAt (Tsig p1 p2 A C K1 K2) (Tsig p1 p2 A C K1 K2 y * (1 - H p1 A K1 y - H p2 C K2 y) / y) y := fun y hy => hasDerivAt_Tsig p1 p2 hA hC hK1 hK2 hy have hpos : ∀ y, 0 < y → 0 < Tsig p1 p2 A C K1 K2 y := fun y hy => Tsig_pos p1 p2 hA hC hK1 hK2 hy have hle1 : ∀ y, 0 < y → Tsig p1 p2 A C K1 K2 y ≤ y := fun y hy => Tsig_le_self p1 p2 hA hC hK1 hK2 hy have hle2 : ∀ y, 0 < y → Tsig p1 p2 A C K1 K2 y ≤ A*C/y := fun y hy => Tsig_le_div p1 p2 hA hC hK1 hK2 hy obtain ⟨t0, ht0⟩ : ∃ t0 : ℝ, t0 = Tsig p1 p2 A C K1 K2 1 := ⟨_, rfl⟩ have ht0pos : 0 < t0 := by rw [ht0]; exact hpos 1 one_pos have ht01 : t0 ≤ 1 := by rw [ht0]; exact hle1 1 one_pos have hAC : 0 < A*C := mul_pos hA hC have hA' := hA.ne' have hC' := hC.ne' have ht0' := ht0pos.ne' have hlo_pos : 0 < t0/2 := by positivity have hlo1 : t0/2 < 1 := by linarith have hhi1 : 1 < 2*(A*C)/t0 := by rw [lt_div_iff₀ ht0pos] have h := hle2 1 one_pos rw [← ht0, div_one] at h linarith have hcont : ContinuousOn (Tsig p1 p2 A C K1 K2) (Icc (t0/2) (2*(A*C)/t0)) := fun y hy => (hderiv y (lt_of_lt_of_le hlo_pos hy.1)).continuousAt.continuousWithinAt have h1mem : (1:ℝ) ∈ Icc (t0/2) (2*(A*C)/t0) := ⟨hlo1.le, hhi1.le⟩ obtain ⟨y0, hy0mem, hy0max⟩ := isCompact_Icc.exists_isMaxOn ⟨1, h1mem⟩ hcont have hf1 : t0 ≤ Tsig p1 p2 A C K1 K2 y0 := by rw [ht0]; exact isMaxOn_iff.mp hy0max 1 h1mem have hy0pos : 0 < y0 := lt_of_lt_of_le hlo_pos hy0mem.1 have hne_lo : y0 ≠ t0/2 := by intro h have h2 := hle1 (t0/2) hlo_pos rw [h] at hf1 linarith have hne_hi : y0 ≠ 2*(A*C)/t0 := by intro h have h2 := hle2 (2*(A*C)/t0) (by linarith) have h3 : A*C/(2*(A*C)/t0) = t0/2 := by field_simp rw [h] at hf1 linarith have hy0lo : t0/2 < y0 := lt_of_le_of_ne hy0mem.1 (Ne.symm hne_lo) have hy0hi : y0 < 2*(A*C)/t0 := lt_of_le_of_ne hy0mem.2 hne_hi have hloc : IsLocalMax (Tsig p1 p2 A C K1 K2) y0 := hy0max.isLocalMax (Icc_mem_nhds hy0lo hy0hi) have hzero := hloc.hasDerivAt_eq_zero (hderiv y0 hy0pos) have hN : H p1 A K1 y0 + H p2 C K2 y0 = 1 := by have hT := (hpos y0 hy0pos).ne' rcases div_eq_zero_iff.mp hzero with h | h · rcases mul_eq_zero.mp h with h' | h' · exact absurd h' hT · linarith · exact absurd h hy0pos.ne' have hH1 := H_strictMonoOn p1 hA hK1 have hH2 := H_strictMonoOn p2 hC hK2 refine ⟨y0, hy0pos, hN, ?_, ?_⟩ · apply strictMonoOn_of_deriv_pos (convex_Ioc 0 y0) · intro y hy exact (hderiv y hy.1).continuousAt.continuousWithinAt · intro y hy rw [interior_Ioc] at hy rw [(hderiv y hy.1).deriv] have h1 := hH1 (mem_Ioi.mpr hy.1) (mem_Ioi.mpr hy0pos) hy.2 have h2 := hH2 (mem_Ioi.mpr hy.1) (mem_Ioi.mpr hy0pos) hy.2 have h3 := hpos y hy.1 exact div_pos (mul_pos h3 (by linarith)) hy.1 · apply strictAntiOn_of_deriv_neg (convex_Ici y0) · intro y hy exact (hderiv y (lt_of_lt_of_le hy0pos hy)).continuousAt.continuousWithinAt · intro y hy rw [interior_Ici] at hy have hypos : 0 < y := lt_trans hy0pos hy rw [(hderiv y hypos).deriv] have h1 := hH1 (mem_Ioi.mpr hy0pos) (mem_Ioi.mpr hypos) hy have h2 := hH2 (mem_Ioi.mpr hy0pos) (mem_Ioi.mpr hypos) hy have h3 := hpos y hypos exact div_neg_of_neg_of_pos (mul_neg_of_pos_of_neg h3 (by linarith)) hypos /-- The hook point is unique: anything below the peak has slope sum below 1. -/ lemma below_peak (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y y0 : ℝ} (hy : 0 < y) (hy0 : 0 < y0) (h0 : H p1 A K1 y0 + H p2 C K2 y0 = 1) (h : H p1 A K1 y + H p2 C K2 y < 1) : y < y0 := by by_contra hcon have hle := not_lt.mp hcon have h1 := (H_strictMonoOn p1 hA hK1).monotoneOn (mem_Ioi.mpr hy0) (mem_Ioi.mpr hy) hle have h2 := (H_strictMonoOn p2 hC hK2).monotoneOn (mem_Ioi.mpr hy0) (mem_Ioi.mpr hy) hle linarith /-- Equilibrium profile. -/ noncomputable def eqProfile : Profile where φ := fun d => d P := fun _ => 1 Q := fun _ => 0 hφ := fun d _ => hasDerivAt_id' d hP := fun d _ => hasDerivAt_const d 1 P_nonneg := fun _ _ => zero_le_one P_le_one := fun _ _ => le_refl 1 Q_nonneg := fun _ _ => le_refl 0 le_φ := fun d _ => le_refl d noncomputable def uu (s d : ℝ) : ℝ := Real.exp (-(s*d)) lemma uu_pos (s d : ℝ) : 0 < uu s d := Real.exp_pos _ lemma uu_lt_one {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : uu s d < 1 := by have h0 := mul_pos hs hd have h : Real.exp (-(s*d)) < Real.exp 0 := Real.exp_lt_exp.mpr (by linarith) rw [Real.exp_zero] at h exact h lemma hasDerivAt_uu (s d : ℝ) : HasDerivAt (uu s) (-(s * uu s d)) d := by have h0 : HasDerivAt (fun x : ℝ => -(s*x)) (-s) d := by have h := ((hasDerivAt_id' d).const_mul s).neg exact (h : HasDerivAt (fun x : ℝ => -(s*x)) _ d).congr_deriv (by ring) have h := h0.exp exact (h : HasDerivAt (uu s) _ d).congr_deriv (by unfold uu; ring) noncomputable def kφ (s d : ℝ) : ℝ := d*(1 + uu s d)/(1 - uu s d) noncomputable def kP (s d : ℝ) : ℝ := (1 - uu s d * uu s d - 2*s*d*uu s d)/((1 - uu s d)*(1 - uu s d)) noncomputable def kQ (s d : ℝ) : ℝ := 2*s*uu s d*(s*d*(1 + uu s d) - 2*(1 - uu s d))/(1 - uu s d)^3 lemma hasDerivAt_kφ {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : HasDerivAt (kφ s) (kP s d) d := by have hu := hasDerivAt_uu s d have hne : 1 - uu s d ≠ 0 := (sub_pos.mpr (uu_lt_one hs hd)).ne' have hn := (hasDerivAt_id' d).mul (hu.const_add 1) have hD := hu.const_sub 1 have h := hn.div hD hne refine (h : HasDerivAt (kφ s) _ d).congr_deriv ?_ unfold kP simp only [Pi.mul_apply] field_simp ring lemma hasDerivAt_kP {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : HasDerivAt (kP s) (kQ s d) d := by have hu := hasDerivAt_uu s d have hne : 1 - uu s d ≠ 0 := (sub_pos.mpr (uu_lt_one hs hd)).ne' have hN := ((hu.mul hu).const_sub 1).sub (((hasDerivAt_id' d).const_mul (2*s)).mul hu) have hD := (hu.const_sub 1).mul (hu.const_sub 1) have h := hN.div hD (mul_ne_zero hne hne) refine (h : HasDerivAt (kP s) _ d).congr_deriv ?_ unfold kQ simp only [Pi.mul_apply, Pi.sub_apply] field_simp ring lemma one_sub_uu_le (s d : ℝ) : 1 - uu s d ≤ s*d := by have h := Real.add_one_le_exp (-(s*d)) unfold uu linarith lemma sinh_bound {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : 2*(s*d)*uu s d ≤ 1 - uu s d * uu s d := by have hw : 0 ≤ s*d := (mul_pos hs hd).le have h1 := Real.self_le_sinh_iff.mpr hw rw [Real.sinh_eq] at h1 have h2 : Real.exp (s*d) * uu s d = 1 := by unfold uu rw [← Real.exp_add] simp have hu := uu_pos s d have h3 : uu s d = Real.exp (-(s*d)) := rfl rw [← h3] at h1 nlinarith [mul_le_mul_of_nonneg_right h1 hu.le] lemma tanh_bound {w : ℝ} (hw : 0 ≤ w) : 2*(1 - Real.exp (-w)) ≤ w*(1 + Real.exp (-w)) := by have hE : ∀ x : ℝ, HasDerivAt (fun x : ℝ => Real.exp (-x)) (-Real.exp (-x)) x := by intro x have h := (hasDerivAt_neg' x).exp exact (h : HasDerivAt (fun x : ℝ => Real.exp (-x)) _ x).congr_deriv (by ring) have hf : ∀ x : ℝ, HasDerivAt (fun x : ℝ => x*(1 + Real.exp (-x)) - 2*(1 - Real.exp (-x))) (1 - (1 + x)*Real.exp (-x)) x := by intro x have h := ((hasDerivAt_id' x).mul ((hE x).const_add 1)).sub (((hE x).const_sub 1).const_mul 2) exact (h : HasDerivAt (fun x : ℝ => x*(1 + Real.exp (-x)) - 2*(1 - Real.exp (-x))) _ x).congr_deriv (by ring) have hmono : MonotoneOn (fun x : ℝ => x*(1 + Real.exp (-x)) - 2*(1 - Real.exp (-x))) (Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) · exact fun x _ => (hf x).continuousAt.continuousWithinAt · exact fun x _ => (hf x).differentiableAt.differentiableWithinAt · intro x _ rw [(hf x).deriv] have h1 := Real.add_one_le_exp x have h2 : Real.exp x * Real.exp (-x) = 1 := by rw [← Real.exp_add] simp have h3 := Real.exp_pos (-x) nlinarith [mul_le_mul_of_nonneg_right h1 h3.le] have h := hmono (mem_Ici.mpr le_rfl) (mem_Ici.mpr hw) hw have h0 : (0:ℝ)*(1 + Real.exp (-0)) - 2*(1 - Real.exp (-0)) = 0 := by simp have h' : (0:ℝ)*(1 + Real.exp (-0)) - 2*(1 - Real.exp (-0)) ≤ w*(1 + Real.exp (-w)) - 2*(1 - Real.exp (-w)) := h linarith lemma kP_nonneg {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : 0 ≤ kP s d := by have h1 := sinh_bound hs hd have h2 := sub_pos.mpr (uu_lt_one hs hd) unfold kP apply div_nonneg · linarith · exact (mul_pos h2 h2).le lemma kP_le_one {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : kP s d ≤ 1 := by have h1 := one_sub_uu_le s d have h2 := sub_pos.mpr (uu_lt_one hs hd) have hu := uu_pos s d unfold kP rw [div_le_one (mul_pos h2 h2)] nlinarith [mul_nonneg hu.le (sub_nonneg.mpr h1)] lemma kQ_nonneg {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : 0 ≤ kQ s d := by have h1 := tanh_bound (mul_pos hs hd).le have h2 := sub_pos.mpr (uu_lt_one hs hd) have hu := uu_pos s d have h3 : uu s d = Real.exp (-(s*d)) := rfl rw [← h3] at h1 unfold kQ apply div_nonneg · apply mul_nonneg · positivity · linarith · exact (pow_pos h2 3).le lemma le_kφ {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : d ≤ kφ s d := by have h2 := sub_pos.mpr (uu_lt_one hs hd) have hu := uu_pos s d unfold kφ rw [le_div_iff₀ h2] nlinarith [mul_pos hd hu] /-- Kinetic profile: the site has been binding for dimensionless time s = k_on * t. -/ noncomputable def kinProfile (s : ℝ) (hs : 0 < s) : Profile where φ := kφ s P := kP s Q := kQ s hφ := fun _ hd => hasDerivAt_kφ hs hd hP := fun _ hd => hasDerivAt_kP hs hd P_nonneg := fun _ hd => kP_nonneg hs hd P_le_one := fun _ hd => kP_le_one hs hd Q_nonneg := fun _ hd => kQ_nonneg hs hd le_φ := fun _ hd => le_kφ hs hd /-! ### Time course: the mass-action network and its exact solution -/ lemma const_of_deriv_zero {g : ℝ → ℝ} (hg : ∀ t, 0 ≤ t → HasDerivAt g 0 t) {t : ℝ} (ht : 0 ≤ t) : g t = g 0 := by have hcont : ContinuousOn g (Ici 0) := fun x hx => (hg x hx).continuousAt.continuousWithinAt have hdiff : DifferentiableOn ℝ g (interior (Ici 0)) := fun x hx => (hg x (interior_subset hx)).differentiableAt.differentiableWithinAt have h1 : MonotoneOn g (Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) hcont hdiff intro x hx rw [(hg x (interior_subset hx)).deriv] have h2 : AntitoneOn g (Ici 0) := by apply antitoneOn_of_deriv_nonpos (convex_Ici 0) hcont hdiff intro x hx rw [(hg x (interior_subset hx)).deriv] exact le_antisymm (h2 (mem_Ici.mpr le_rfl) (mem_Ici.mpr ht) ht) (h1 (mem_Ici.mpr le_rfl) (mem_Ici.mpr ht) ht) lemma zero_of_decay {y lam : ℝ → ℝ} (hy : ∀ t, 0 ≤ t → HasDerivAt y (-(lam t * y t)) t) (hlam : ∀ t, 0 ≤ t → 0 ≤ lam t) (h0 : y 0 = 0) {t : ℝ} (ht : 0 ≤ t) : y t = 0 := by have hz : ∀ x, 0 ≤ x → HasDerivAt (fun s => y s * y s) (-(2 * lam x * (y x * y x))) x := by intro x hx have h := (hy x hx).mul (hy x hx) exact (h : HasDerivAt (fun s => y s * y s) _ x).congr_deriv (by ring) have hcont : ContinuousOn (fun s => y s * y s) (Ici 0) := fun x hx => (hz x hx).continuousAt.continuousWithinAt have hdiff : DifferentiableOn ℝ (fun s => y s * y s) (interior (Ici 0)) := fun x hx => (hz x (interior_subset hx)).differentiableAt.differentiableWithinAt have hanti : AntitoneOn (fun s => y s * y s) (Ici 0) := by apply antitoneOn_of_deriv_nonpos (convex_Ici 0) hcont hdiff intro x hx have hx0 : 0 ≤ x := interior_subset hx rw [(hz x hx0).deriv] have h := mul_nonneg (hlam x hx0) (mul_self_nonneg (y x)) linarith have h := hanti (mem_Ici.mpr le_rfl) (mem_Ici.mpr ht) ht have h' : y t * y t ≤ y 0 * y 0 := h rw [h0] at h' have h2 := mul_self_nonneg (y t) have h3 : y t * y t = 0 := by linarith exact mul_self_eq_zero.mp h3 /-- The invariant: [ABC] * [B] = [AB] * [BC] at every time, not only at equilibrium. -/ theorem tern_times_free {k1 km1 k2 km2 : ℝ} {fA fB fC AB BC T : ℝ → ℝ} (hk1 : 0 ≤ k1) (hkm1 : 0 ≤ km1) (hk2 : 0 ≤ k2) (hkm2 : 0 ≤ km2) (hB : ∀ t, 0 ≤ t → HasDerivAt fB (-(k1 * fA t * fB t) + km1 * AB t - k2 * fC t * fB t + km2 * BC t) t) (hAB : ∀ t, 0 ≤ t → HasDerivAt AB (k1 * fA t * fB t - km1 * AB t - k2 * AB t * fC t + km2 * T t) t) (hBC : ∀ t, 0 ≤ t → HasDerivAt BC (k2 * fC t * fB t - km2 * BC t - k1 * fA t * BC t + km1 * T t) t) (hT : ∀ t, 0 ≤ t → HasDerivAt T (k2 * AB t * fC t - km2 * T t + k1 * fA t * BC t - km1 * T t) t) (hA0 : ∀ t, 0 ≤ t → 0 ≤ fA t) (hC0 : ∀ t, 0 ≤ t → 0 ≤ fC t) (h0 : T 0 * fB 0 = AB 0 * BC 0) {t : ℝ} (ht : 0 ≤ t) : T t * fB t = AB t * BC t := by have hD : ∀ x, 0 ≤ x → HasDerivAt (fun s => T s * fB s - AB s * BC s) (-((k1 * fA x + km1 + k2 * fC x + km2) * (T x * fB x - AB x * BC x))) x := by intro x hx have h := ((hT x hx).mul (hB x hx)).sub ((hAB x hx).mul (hBC x hx)) exact (h : HasDerivAt (fun s => T s * fB s - AB s * BC s) _ x).congr_deriv (by ring) have hlam : ∀ x, 0 ≤ x → 0 ≤ k1 * fA x + km1 + k2 * fC x + km2 := by intro x hx have h1 := mul_nonneg hk1 (hA0 x hx) have h2 := mul_nonneg hk2 (hC0 x hx) linarith have hzero := zero_of_decay (y := fun s => T s * fB s - AB s * BC s) (lam := fun x => k1 * fA x + km1 + k2 * fC x + km2) hD hlam (sub_eq_zero.mpr h0) ht have h' : T t * fB t - AB t * BC t = 0 := hzero linarith noncomputable def rp (A K B : ℝ) : ℝ := (A + B + K + dd A K B)/2 noncomputable def rm (A K B : ℝ) : ℝ := (A + B + K - dd A K B)/2 lemma rp_mul_rm {A K : ℝ} (hA : 0 < A) (hK : 0 < K) (B : ℝ) : rp A K B * rm A K B = A*B := by have h := dd_sq hA hK B unfold rp rm linear_combination (-1/4 : ℝ) * h lemma rp_pos {A K B : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) : 0 < rp A K B := by have h := dd_pos hA hK B unfold rp linarith lemma rm_pos {A K B : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) : 0 < rm A K B := by have h1 := rp_pos hA hK hB have h2 := rp_mul_rm hA hK B have h3 := mul_pos hA hB by_contra hcon have h4 := not_lt.mp hcon nlinarith [mul_nonneg h1.le (neg_nonneg.mpr h4)] lemma rm_le {A K B : ℝ} (hK : 0 < K) (hB : 0 < B) : rm A K B ≤ B := by have h : |B - A - K| ≤ dd A K B := by apply Real.abs_le_sqrt nlinarith [mul_nonneg hK.le hB.le] have h2 := (abs_le.mp h).1 unfold rm linarith /-- Closed-form occupancy of one site at time t (second-order reversible binding). -/ noncomputable def occU (A K k B t : ℝ) : ℝ := rp A K B * rm A K B * (1 - Real.exp (-(k * dd A K B * t))) / (rp A K B - rm A K B * Real.exp (-(k * dd A K B * t))) lemma occU_zero (A K k B : ℝ) : occU A K k B 0 = 0 := by unfold occU simp lemma exp_le_one_of {k d t : ℝ} (hk : 0 ≤ k) (hd : 0 < d) (ht : 0 ≤ t) : Real.exp (-(k*d*t)) ≤ 1 := by have h0 := mul_nonneg (mul_nonneg hk hd.le) ht have h : Real.exp (-(k*d*t)) ≤ Real.exp 0 := Real.exp_le_exp.mpr (by linarith) rw [Real.exp_zero] at h exact h lemma den_pos {A K k B t : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) (hk : 0 ≤ k) (ht : 0 ≤ t) : 0 < rp A K B - rm A K B * Real.exp (-(k * dd A K B * t)) := by have hd := dd_pos hA hK B have hu1 := exp_le_one_of hk hd ht have hm := rm_pos hA hK hB have hdiff : rp A K B - rm A K B = dd A K B := by unfold rp rm; ring nlinarith [mul_nonneg hm.le (sub_nonneg.mpr hu1)] lemma occ_ode_alg (P M u k d : ℝ) (hd : d = P - M) (hden : P - M*u ≠ 0) : ((P*M*(-(u*(-(k*d)))))*(P - M*u) - (P*M*(1 - u))*(-(M*(u*(-(k*d)))))) / (P - M*u)^2 = k*((P*M*(1 - u)/(P - M*u))^2 - (P + M)*(P*M*(1 - u)/(P - M*u)) + P*M) := by subst hd field_simp ring lemma hasDerivAt_occU {A K k B t : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) (hk : 0 ≤ k) (ht : 0 ≤ t) : HasDerivAt (occU A K k B) (k*((A - occU A K k B t)*(B - occU A K k B t) - K*occU A K k B t)) t := by have hden := (den_pos hA hK hB hk ht).ne' have h0 : HasDerivAt (fun x : ℝ => -(k * dd A K B * x)) (-(k * dd A K B)) t := by have h := ((hasDerivAt_id' t).const_mul (k * dd A K B)).neg exact (h : HasDerivAt (fun x : ℝ => -(k * dd A K B * x)) _ t).congr_deriv (by ring) have hu := h0.exp have hnum := (hu.const_sub 1).const_mul (rp A K B * rm A K B) have hdn := (hu.const_mul (rm A K B)).const_sub (rp A K B) have h := hnum.div hdn hden have hprod := rp_mul_rm hA hK B have hsum : rp A K B + rm A K B = A + B + K := by unfold rp rm; ring have hdiff : dd A K B = rp A K B - rm A K B := by unfold rp rm; ring have key := occ_ode_alg (rp A K B) (rm A K B) (Real.exp (-(k * dd A K B * t))) k (dd A K B) hdiff hden refine (h : HasDerivAt (occU A K k B) _ t).congr_deriv ?_ unfold occU obtain ⟨u, hu_def⟩ : ∃ u : ℝ, u = Real.exp (-(k * dd A K B * t)) := ⟨_, rfl⟩ obtain ⟨P, hP⟩ : ∃ P : ℝ, P = rp A K B := ⟨_, rfl⟩ obtain ⟨M, hM⟩ : ∃ M : ℝ, M = rm A K B := ⟨_, rfl⟩ rw [← hu_def, ← hP, ← hM] at key ⊢ rw [← hP, ← hM] at hprod hsum linear_combination key + k * hprod - (k * (P*M*(1 - u)/(P - M*u))) * hsum lemma occU_le {A K k B t : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) (hk : 0 ≤ k) (ht : 0 ≤ t) : occU A K k B t ≤ B := by have hden := den_pos hA hK hB hk ht have hd := dd_pos hA hK B have hu0 := Real.exp_pos (-(k * dd A K B * t)) have hm := rm_pos hA hK hB have hmB := rm_le (A := A) hK hB have hdiff : rp A K B - rm A K B = dd A K B := by unfold rp rm; ring unfold occU rw [div_le_iff₀ hden] nlinarith [mul_nonneg (mul_nonneg hm.le hu0.le) (by linarith : (0:ℝ) ≤ rp A K B - rm A K B), mul_nonneg (sub_nonneg.mpr hmB) hden.le] /-- Uniqueness: every physical solution of the one-site rate equation starting at 0 is the closed form. -/ lemma site_unique {A K k B : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) (hk : 0 ≤ k) {a : ℝ → ℝ} (ha : ∀ t, 0 ≤ t → HasDerivAt a (k*((A - a t)*(B - a t) - K*a t)) t) (haA : ∀ t, 0 ≤ t → a t ≤ A) (ha0 : a 0 = 0) {t : ℝ} (ht : 0 ≤ t) : a t = occU A K k B t := by have hz : ∀ x, 0 ≤ x → HasDerivAt (fun s => a s - occU A K k B s) (-((k*(A + B + K - a x - occU A K k B x)) * (a x - occU A K k B x))) x := by intro x hx have h := (ha x hx).sub (hasDerivAt_occU hA hK hB hk hx) exact (h : HasDerivAt (fun s => a s - occU A K k B s) _ x).congr_deriv (by ring) have hlam : ∀ x, 0 ≤ x → 0 ≤ k*(A + B + K - a x - occU A K k B x) := by intro x hx have h1 := haA x hx have h2 := occU_le hA hK hB hk hx apply mul_nonneg hk linarith have h := zero_of_decay (y := fun s => a s - occU A K k B s) (lam := fun x => k*(A + B + K - a x - occU A K k B x)) hz hlam (by simp [ha0, occU_zero]) ht have h' : a t - occU A K k B t = 0 := h linarith /-- For t > 0 the closed form is the kinetic profile read at s = k * t. -/ lemma occU_eq_kin {A K k B t : ℝ} (hA : 0 < A) (hK : 0 < K) (hB : 0 < B) (hk : 0 < k) (ht : 0 < t) : occU A K k B t = 2*A*B / W (kinProfile (k*t) (mul_pos hk ht)) A K B := by have hd := dd_pos hA hK B have hu1 : uu (k*t) (dd A K B) < 1 := uu_lt_one (mul_pos hk ht) hd have hue : Real.exp (-(k * dd A K B * t)) = uu (k*t) (dd A K B) := by unfold uu congr 1 ring have hprod := rp_mul_rm hA hK B have hden := den_pos hA hK hB hk.le ht.le have hW := W_pos (kinProfile (k*t) (mul_pos hk ht)) hA hK B have hWe : W (kinProfile (k*t) (mul_pos hk ht)) A K B = A + B + K + dd A K B * (1 + uu (k*t) (dd A K B))/(1 - uu (k*t) (dd A K B)) := rfl have h1 : 1 - uu (k*t) (dd A K B) ≠ 0 := (sub_pos.mpr hu1).ne' unfold occU rw [hue] at hden ⊢ rw [hprod, div_eq_div_iff hden.ne' hW.ne', hWe] unfold rp rm field_simp ring /-- The one-pot sandwich network, started with no complexes, has the exact solution [ABC](t) = occ1(t) * occ2(t) / Bt, with each occupancy the closed form above. -/ theorem sandwich_closed_form {k1 km1 k2 km2 At Bt Ct : ℝ} {fA fB fC AB BC T : ℝ → ℝ} (hk1 : 0 < k1) (hkm1 : 0 < km1) (hk2 : 0 < k2) (hkm2 : 0 < km2) (hAt : 0 < At) (hBt : 0 < Bt) (hCt : 0 < Ct) (hA : ∀ t, 0 ≤ t → HasDerivAt fA (-(k1 * fA t * fB t) + km1 * AB t - k1 * fA t * BC t + km1 * T t) t) (hB : ∀ t, 0 ≤ t → HasDerivAt fB (-(k1 * fA t * fB t) + km1 * AB t - k2 * fC t * fB t + km2 * BC t) t) (hC : ∀ t, 0 ≤ t → HasDerivAt fC (-(k2 * fC t * fB t) + km2 * BC t - k2 * AB t * fC t + km2 * T t) t) (hAB : ∀ t, 0 ≤ t → HasDerivAt AB (k1 * fA t * fB t - km1 * AB t - k2 * AB t * fC t + km2 * T t) t) (hBC : ∀ t, 0 ≤ t → HasDerivAt BC (k2 * fC t * fB t - km2 * BC t - k1 * fA t * BC t + km1 * T t) t) (hT : ∀ t, 0 ≤ t → HasDerivAt T (k2 * AB t * fC t - km2 * T t + k1 * fA t * BC t - km1 * T t) t) (hA0 : ∀ t, 0 ≤ t → 0 ≤ fA t) (hC0 : ∀ t, 0 ≤ t → 0 ≤ fC t) (iA : fA 0 = At) (iB : fB 0 = Bt) (iC : fC 0 = Ct) (iAB : AB 0 = 0) (iBC : BC 0 = 0) (iT : T 0 = 0) {t : ℝ} (ht : 0 < t) : T t = Tsig (kinProfile (k1*t) (mul_pos hk1 ht)) (kinProfile (k2*t) (mul_pos hk2 ht)) At Ct (km1/k1) (km2/k2) Bt := by have hk1' := hk1.ne' have hk2' := hk2.ne' have cA : ∀ x, 0 ≤ x → fA x + AB x + T x = At := by intro x hx have hg : ∀ s, 0 ≤ s → HasDerivAt (fun s => fA s + AB s + T s) 0 s := by intro s hs have h := ((hA s hs).add (hAB s hs)).add (hT s hs) exact (h : HasDerivAt (fun s => fA s + AB s + T s) _ s).congr_deriv (by ring) have h := const_of_deriv_zero hg hx have h' : fA x + AB x + T x = fA 0 + AB 0 + T 0 := h rw [iA, iAB, iT] at h' linarith have cB : ∀ x, 0 ≤ x → fB x + AB x + BC x + T x = Bt := by intro x hx have hg : ∀ s, 0 ≤ s → HasDerivAt (fun s => fB s + AB s + BC s + T s) 0 s := by intro s hs have h := (((hB s hs).add (hAB s hs)).add (hBC s hs)).add (hT s hs) exact (h : HasDerivAt (fun s => fB s + AB s + BC s + T s) _ s).congr_deriv (by ring) have h := const_of_deriv_zero hg hx have h' : fB x + AB x + BC x + T x = fB 0 + AB 0 + BC 0 + T 0 := h rw [iB, iAB, iBC, iT] at h' linarith have cC : ∀ x, 0 ≤ x → fC x + BC x + T x = Ct := by intro x hx have hg : ∀ s, 0 ≤ s → HasDerivAt (fun s => fC s + BC s + T s) 0 s := by intro s hs have h := ((hC s hs).add (hBC s hs)).add (hT s hs) exact (h : HasDerivAt (fun s => fC s + BC s + T s) _ s).congr_deriv (by ring) have h := const_of_deriv_zero hg hx have h' : fC x + BC x + T x = fC 0 + BC 0 + T 0 := h rw [iC, iBC, iT] at h' linarith have hinv := tern_times_free hk1.le hkm1.le hk2.le hkm2.le hB hAB hBC hT hA0 hC0 (by rw [iT, iAB]; ring) ht.le have ha : ∀ x, 0 ≤ x → HasDerivAt (fun s => AB s + T s) (k1*((At - (AB x + T x))*(Bt - (AB x + T x)) - km1/k1*(AB x + T x))) x := by intro x hx have h := (hAB x hx).add (hT x hx) refine (h : HasDerivAt (fun s => AB s + T s) _ x).congr_deriv ?_ rw [← cA x hx, ← cB x hx] field_simp ring have hc : ∀ x, 0 ≤ x → HasDerivAt (fun s => BC s + T s) (k2*((Ct - (BC x + T x))*(Bt - (BC x + T x)) - km2/k2*(BC x + T x))) x := by intro x hx have h := (hBC x hx).add (hT x hx) refine (h : HasDerivAt (fun s => BC s + T s) _ x).congr_deriv ?_ rw [← cC x hx, ← cB x hx] field_simp ring have ea := site_unique hAt (div_pos hkm1 hk1) hBt hk1.le ha (fun x hx => by have h1 := cA x hx; have h2 := hA0 x hx; linarith) (by simp [iAB, iT]) ht.le have ec := site_unique hCt (div_pos hkm2 hk2) hBt hk2.le hc (fun x hx => by have h1 := cC x hx; have h2 := hC0 x hx; linarith) (by simp [iBC, iT]) ht.le have ea' : AB t + T t = occU At (km1/k1) k1 Bt t := ea have ec' : BC t + T t = occU Ct (km2/k2) k2 Bt t := ec rw [occU_eq_kin hAt (div_pos hkm1 hk1) hBt hk1 ht] at ea' rw [occU_eq_kin hCt (div_pos hkm2 hk2) hBt hk2 ht] at ec' unfold Tsig rw [← ea', ← ec', eq_div_iff hBt.ne', ← cB t ht.le] linear_combination hinv /-- Kinetic hook theorem, as a corollary: at every read time t > 0 the one-pot sandwich dose-response has exactly one peak. -/ theorem kinetic_one_peak {k1 k2 t A C K1 K2 : ℝ} (hk1 : 0 < k1) (hk2 : 0 < k2) (ht : 0 < t) (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) : ∃ y0 : ℝ, 0 < y0 ∧ StrictMonoOn (Tsig (kinProfile (k1*t) (mul_pos hk1 ht)) (kinProfile (k2*t) (mul_pos hk2 ht)) A C K1 K2) (Ioc 0 y0) ∧ StrictAntiOn (Tsig (kinProfile (k1*t) (mul_pos hk1 ht)) (kinProfile (k2*t) (mul_pos hk2 ht)) A C K1 K2) (Ici y0) := by obtain ⟨y0, h1, _, h3, h4⟩ := one_peak (kinProfile (k1*t) (mul_pos hk1 ht)) (kinProfile (k2*t) (mul_pos hk2 ht)) hA hC hK1 hK2 exact ⟨y0, h1, h3, h4⟩ /-! ### Where the hook can be: universal lower bounds -/ lemma H_at_sum_le (p : Profile) {A K : ℝ} (hA : 0 < A) (hK : 0 < K) : H p A K (A + K) ≤ 1/2 := by have hd := dd_pos hA hK (A + K) have hsq := dd_sq hA hK (A + K) have hW := W_pos p hA hK (A + K) have hP1 := p.P_le_one _ hd have hWge := W_ge p hA hK (A + K) obtain ⟨q, hq⟩ : ∃ q : ℝ, q = (A + K + K - A)/dd A K (A + K) := ⟨_, rfl⟩ have e : (A + K)*q = dd A K (A + K)/2 := by rw [hq, mul_div_assoc', div_eq_div_iff hd.ne' two_ne_zero] nlinarith have e2 : p.P (dd A K (A + K)) * ((A + K)*q) = p.P (dd A K (A + K)) * (dd A K (A + K)/2) := by rw [e] unfold H W1 rw [← hq, div_le_iff₀ hW] nlinarith [mul_nonneg (sub_nonneg.mpr hP1) hd.le] /-- At any read time and for any protocol, the hook point is at least the smaller of (antibody concentration + K_D) over the two antibodies. -/ theorem peak_ge (p1 p2 : Profile) {A C K1 K2 : ℝ} (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y0 : ℝ} (hy0 : 0 < y0) (h0 : H p1 A K1 y0 + H p2 C K2 y0 = 1) : min (A + K1) (C + K2) ≤ y0 := by by_contra hcon have hlt := not_le.mp hcon have h1 : y0 < A + K1 := lt_of_lt_of_le hlt (min_le_left _ _) have h2 : y0 < C + K2 := lt_of_lt_of_le hlt (min_le_right _ _) have e1 := H_strictMonoOn p1 hA hK1 (mem_Ioi.mpr hy0) (mem_Ioi.mpr (by linarith)) h1 have e2 := H_strictMonoOn p2 hC hK2 (mem_Ioi.mpr hy0) (mem_Ioi.mpr (by linarith)) h2 have f1 := H_at_sum_le p1 hA hK1 have f2 := H_at_sum_le p2 hC hK2 linarith lemma cubic_bound {w : ℝ} (hw : 0 ≤ w) : 3*(1 - Real.exp (-w) * Real.exp (-w) - 2*w*Real.exp (-w)) ≤ w*((1 - Real.exp (-w))*(1 - Real.exp (-w))) := by have hE : ∀ x : ℝ, HasDerivAt (fun x : ℝ => Real.exp (-x)) (-Real.exp (-x)) x := by intro x have h := (hasDerivAt_neg' x).exp exact (h : HasDerivAt (fun x : ℝ => Real.exp (-x)) _ x).congr_deriv (by ring) have hG : ∀ x : ℝ, HasDerivAt (fun x : ℝ => 1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x))) (4*Real.exp (-x)*(x*(1 + Real.exp (-x)) - 2*(1 - Real.exp (-x)))) x := by intro x have hEE := (hE x).mul (hE x) have g1 := ((hE x).const_mul 4).const_add 1 have g2 := hEE.const_mul 5 have g3 := ((hasDerivAt_id' x).const_mul 4).mul (hE x) have g4 := ((hasDerivAt_id' x).const_mul 2).mul hEE have h := ((g1.sub g2).sub g3).sub g4 refine (h : HasDerivAt (fun x : ℝ => 1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x))) _ x).congr_deriv ?_ simp only [Pi.mul_apply] ring have hGmono : MonotoneOn (fun x : ℝ => 1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x))) (Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) · exact fun x _ => (hG x).continuousAt.continuousWithinAt · exact fun x _ => (hG x).differentiableAt.differentiableWithinAt · intro x hx have hx0 : 0 ≤ x := interior_subset hx rw [(hG x).deriv] have h1 := tanh_bound hx0 have h2 := Real.exp_pos (-x) apply mul_nonneg · linarith · linarith have hGnn : ∀ x : ℝ, 0 ≤ x → 0 ≤ 1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x)) := by intro x hx have h := hGmono (mem_Ici.mpr le_rfl) (mem_Ici.mpr hx) hx have h' : 1 + 4*Real.exp (-(0:ℝ)) - 5*(Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ))) - 4*0*Real.exp (-(0:ℝ)) - 2*0*(Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ))) ≤ 1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x)) := h have h0 : 1 + 4*Real.exp (-(0:ℝ)) - 5*(Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ))) - 4*0*Real.exp (-(0:ℝ)) - 2*0*(Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ))) = 0 := by norm_num linarith have hF : ∀ x : ℝ, HasDerivAt (fun x : ℝ => x*((1 - Real.exp (-x))*(1 - Real.exp (-x))) - 3*(1 - Real.exp (-x)*Real.exp (-x) - 2*x*Real.exp (-x))) (1 + 4*Real.exp (-x) - 5*(Real.exp (-x)*Real.exp (-x)) - 4*x*Real.exp (-x) - 2*x*(Real.exp (-x)*Real.exp (-x))) x := by intro x have h1E := (hE x).const_sub 1 have hA := (hasDerivAt_id' x).mul (h1E.mul h1E) have hEE := (hE x).mul (hE x) have hxE := ((hasDerivAt_id' x).const_mul 2).mul (hE x) have hB := ((hEE.const_sub 1).sub hxE).const_mul 3 have h := hA.sub hB refine (h : HasDerivAt (fun x : ℝ => x*((1 - Real.exp (-x))*(1 - Real.exp (-x))) - 3*(1 - Real.exp (-x)*Real.exp (-x) - 2*x*Real.exp (-x))) _ x).congr_deriv ?_ simp only [Pi.mul_apply] ring have hFmono : MonotoneOn (fun x : ℝ => x*((1 - Real.exp (-x))*(1 - Real.exp (-x))) - 3*(1 - Real.exp (-x)*Real.exp (-x) - 2*x*Real.exp (-x))) (Ici 0) := by apply monotoneOn_of_deriv_nonneg (convex_Ici 0) · exact fun x _ => (hF x).continuousAt.continuousWithinAt · exact fun x _ => (hF x).differentiableAt.differentiableWithinAt · intro x hx rw [(hF x).deriv] exact hGnn x (interior_subset hx) have h := hFmono (mem_Ici.mpr le_rfl) (mem_Ici.mpr hw) hw have h' : (0:ℝ)*((1 - Real.exp (-(0:ℝ)))*(1 - Real.exp (-(0:ℝ)))) - 3*(1 - Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ)) - 2*0*Real.exp (-(0:ℝ))) ≤ w*((1 - Real.exp (-w))*(1 - Real.exp (-w))) - 3*(1 - Real.exp (-w)*Real.exp (-w) - 2*w*Real.exp (-w)) := h have h0 : (0:ℝ)*((1 - Real.exp (-(0:ℝ)))*(1 - Real.exp (-(0:ℝ)))) - 3*(1 - Real.exp (-(0:ℝ))*Real.exp (-(0:ℝ)) - 2*0*Real.exp (-(0:ℝ))) = 0 := by norm_num linarith lemma kP_le_third {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : kP s d ≤ s*d/3 := by have h1 := cubic_bound (mul_pos hs hd).le have h2 := sub_pos.mpr (uu_lt_one hs hd) have h3 : uu s d = Real.exp (-(s*d)) := rfl rw [← h3] at h1 unfold kP rw [div_le_iff₀ (mul_pos h2 h2)] linarith lemma two_div_le_kφ {s d : ℝ} (hs : 0 < s) (hd : 0 < d) : 2/s ≤ kφ s d := by have h1 := tanh_bound (mul_pos hs hd).le have h2 := sub_pos.mpr (uu_lt_one hs hd) have h3 : uu s d = Real.exp (-(s*d)) := rfl rw [← h3] at h1 unfold kφ rw [div_le_div_iff₀ hs h2] linarith lemma H_kin_le_half {s A K y : ℝ} (hs : 0 < s) (hA : 0 < A) (hK : 0 < K) (hy : 0 < y) (hsy : s*y ≤ 1) : H (kinProfile s hs) A K y ≤ 1/2 := by have hd := dd_pos hA hK y have hW := W_pos (kinProfile s hs) hA hK y have hP0 : 0 ≤ kP s (dd A K y) := kP_nonneg hs hd have hP3 : kP s (dd A K y) ≤ s*dd A K y/3 := kP_le_third hs hd have hφ : 2/s ≤ kφ s (dd A K y) := two_div_le_kφ hs hd have h2y : 2*y ≤ 2/s := by rw [le_div_iff₀ hs]; linarith have hWe : W (kinProfile s hs) A K y = A + y + K + kφ s (dd A K y) := rfl have hW1e : W1 (kinProfile s hs) A K y = 1 + kP s (dd A K y) * ((y + K - A)/dd A K y) := rfl obtain ⟨q, hq⟩ : ∃ q : ℝ, q = (y + K - A)/dd A K y := ⟨_, rfl⟩ have hqd : q * dd A K y = y + K - A := by rw [hq]; field_simp unfold H rw [div_le_iff₀ hW, hWe, hW1e, ← hq] by_cases hq0 : q ≤ 0 · have h1 : kP s (dd A K y) * q ≤ 0 := by nlinarith [mul_nonneg hP0 (neg_nonneg.mpr hq0)] have h2 : y*(kP s (dd A K y) * q) ≤ 0 := by nlinarith [mul_nonneg hy.le (neg_nonneg.mpr h1)] linarith · have hq0' := not_le.mp hq0 have hm : 0 < y + K - A := by rw [← hqd]; exact mul_pos hq0' hd have e1 : kP s (dd A K y) * q ≤ s*(y + K - A)/3 := by have h := mul_le_mul_of_nonneg_right hP3 hq0'.le have e : s*dd A K y/3*q = s*(y + K - A)/3 := by rw [← hqd]; ring linarith have e2 : y*(kP s (dd A K y) * q) ≤ (y + K - A)/3 := by have h := mul_le_mul_of_nonneg_left e1 hy.le have h' : y*(s*(y + K - A)/3) ≤ (y + K - A)/3 := by nlinarith [mul_nonneg hm.le (sub_nonneg.mpr hsy)] linarith linarith /-- Kinetic design rule: read at time t, the hook point is at least min over the two antibodies of max (concentration + K_D, 1 / (k_on * t)). -/ theorem kinetic_peak_ge {s1 s2 A C K1 K2 : ℝ} (hs1 : 0 < s1) (hs2 : 0 < s2) (hA : 0 < A) (hC : 0 < C) (hK1 : 0 < K1) (hK2 : 0 < K2) {y0 : ℝ} (hy0 : 0 < y0) (h0 : H (kinProfile s1 hs1) A K1 y0 + H (kinProfile s2 hs2) C K2 y0 = 1) : min (max (A + K1) (1/s1)) (max (C + K2) (1/s2)) ≤ y0 := by by_contra hcon have hlt := not_le.mp hcon have h1 : y0 < max (A + K1) (1/s1) := lt_of_lt_of_le hlt (min_le_left _ _) have h2 : y0 < max (C + K2) (1/s2) := lt_of_lt_of_le hlt (min_le_right _ _) have m1 := H_strictMonoOn (kinProfile s1 hs1) hA hK1 have m2 := H_strictMonoOn (kinProfile s2 hs2) hC hK2 have f1 : H (kinProfile s1 hs1) A K1 y0 < 1/2 := by rcases lt_max_iff.mp h1 with h | h · have e := m1 (mem_Ioi.mpr hy0) (mem_Ioi.mpr (by linarith)) h have f := H_at_sum_le (kinProfile s1 hs1) hA hK1 linarith · have hpos : (0:ℝ) < 1/s1 := by positivity have e := m1 (mem_Ioi.mpr hy0) (mem_Ioi.mpr hpos) h have f := H_kin_le_half hs1 hA hK1 hpos (le_of_eq (mul_one_div_cancel hs1.ne')) linarith have f2 : H (kinProfile s2 hs2) C K2 y0 < 1/2 := by rcases lt_max_iff.mp h2 with h | h · have e := m2 (mem_Ioi.mpr hy0) (mem_Ioi.mpr (by linarith)) h have f := H_at_sum_le (kinProfile s2 hs2) hC hK2 linarith · have hpos : (0:ℝ) < 1/s2 := by positivity have e := m2 (mem_Ioi.mpr hy0) (mem_Ioi.mpr hpos) h have f := H_kin_le_half hs2 hC hK2 hpos (le_of_eq (mul_one_div_cancel hs2.ne')) linarith linarith /-! ### A read before equilibrium can hook first -/ lemma dd_eq {A K y r : ℝ} (hr : 0 ≤ r) (h : (y + K - A)^2 + 4*A*K = r^2) : dd A K y = r := by unfold dd rw [h] exact Real.sqrt_sq hr lemma uu_log {b : ℝ} (hb : 0 < b) (n : ℕ) {s d : ℝ} (h : s*d = n * Real.log b) : uu s d = (b^n)⁻¹ := by unfold uu rw [h, ← Real.log_pow, Real.exp_neg, Real.exp_log (pow_pos hb n)] lemma W_kin_val {s A K y d u : ℝ} (hs : 0 < s) (hd : dd A K y = d) (hu : uu s d = u) : W (kinProfile s hs) A K y = A + y + K + d*(1 + u)/(1 - u) := by have h : W (kinProfile s hs) A K y = A + y + K + dd A K y * (1 + uu s (dd A K y))/(1 - uu s (dd A K y)) := rfl rw [h, hd, hu] lemma H_eq_val {A K y d : ℝ} (hd : dd A K y = d) : H eqProfile A K y = y*(1 + 1*((y + K - A)/d))/(A + y + K + d) := by have h : H eqProfile A K y = y*(1 + 1*((y + K - A)/dd A K y))/(A + y + K + dd A K y) := rfl rw [h, hd] /-- At equilibrium one site never contributes more log-slope loss than y / (y + K). -/ lemma H_eq_le {A K y : ℝ} (hA : 0 < A) (hK : 0 < K) (hy : 0 < y) : H eqProfile A K y ≤ y/(y + K) := by have hd := dd_pos hA hK y have habs := abs_lt.mp (abs_m_lt hA hK y) have hW := W_pos eqProfile hA hK y have hyK : 0 < y + K := by linarith have hWe : W eqProfile A K y = A + y + K + dd A K y := rfl have hW1e : W1 eqProfile A K y = 1 + 1 * ((y + K - A)/dd A K y) := rfl obtain ⟨q, hq⟩ : ∃ q : ℝ, q = (y + K - A)/dd A K y := ⟨_, rfl⟩ have hqd : q * dd A K y = y + K - A := by rw [hq]; field_simp have hq1 : q < 1 := by rw [hq, div_lt_one hd]; exact habs.2 have hq2 : -1 < q := by rw [hq, lt_div_iff₀ hd]; linarith [habs.1] have key : (1 + q)*(y + K) ≤ A + y + K + dd A K y := by have e : y + K = q * dd A K y + A := by linarith have h1 : 0 ≤ (1 - q)*(1 + q)*dd A K y := mul_nonneg (mul_nonneg (by linarith) (by linarith)) hd.le have h2 : 0 ≤ (1 - q)*A := mul_nonneg (by linarith) hA.le have e' : q*(y + K) = q*(q * dd A K y + A) := by rw [e] nlinarith unfold H rw [div_le_div_iff₀ hW hyK, hWe, hW1e, ← hq] nlinarith [mul_le_mul_of_nonneg_left key hy.le] /-- Explicit witness (any concentration unit): capture antibody 3645 with K_D 2080, detection antibody 162400 with K_D 65, capture binding about 21.6 times faster than detection. At the chosen read time the signal at analyte 136741 is more than 10 percent BELOW the signal at analyte 30465, so the kinetic hook point lies below 136741, while the equilibrium hook point lies above 136741. -/ theorem kinetic_hook_first : ∃ (s1 s2 : ℝ) (hs1 : 0 < s1) (hs2 : 0 < s2), (Tsig (kinProfile s1 hs1) (kinProfile s2 hs2) 3645 162400 2080 65 136741 * (11/10) < Tsig (kinProfile s1 hs1) (kinProfile s2 hs2) 3645 162400 2080 65 30465) ∧ (∀ y0 : ℝ, 0 < y0 → StrictMonoOn (Tsig (kinProfile s1 hs1) (kinProfile s2 hs2) 3645 162400 2080 65) (Ioc 0 y0) → y0 < 136741) ∧ (∀ y0 : ℝ, 0 < y0 → H eqProfile 3645 2080 y0 + H eqProfile 162400 65 y0 = 1 → 136741 < y0) := by have hl2 : 0 < Real.log 2 := Real.log_pos (by norm_num) have hl43 : 0 < Real.log (4/3) := Real.log_pos (by norm_num) have hs1 : (0:ℝ) < 10 * Real.log 2 / 29420 := div_pos (mul_pos (by norm_num) hl2) (by norm_num) have hs2 : (0:ℝ) < Real.log (4/3) / 26406 := div_pos hl43 (by norm_num) refine ⟨10 * Real.log 2 / 29420, Real.log (4/3) / 26406, hs1, hs2, ?_⟩ have d10 : dd 3645 2080 30465 = 29420 := dd_eq (by norm_num) (by norm_num) have d20 : dd 162400 65 30465 = 132030 := dd_eq (by norm_num) (by norm_num) have d21 : dd 162400 65 136741 = 26406 := dd_eq (by norm_num) (by norm_num) have u10 : uu (10 * Real.log 2 / 29420) 29420 = ((2:ℝ)^10)⁻¹ := uu_log (by norm_num) 10 (by push_cast; ring) have u20 : uu (Real.log (4/3) / 26406) 132030 = ((4/3:ℝ)^5)⁻¹ := uu_log (by norm_num) 5 (by push_cast; ring) have u21 : uu (Real.log (4/3) / 26406) 26406 = ((4/3:ℝ)^1)⁻¹ := uu_log (by norm_num) 1 (by push_cast; ring) have hW10 : W (kinProfile (10 * Real.log 2 / 29420) hs1) 3645 2080 30465 = 67177870/1023 := by rw [W_kin_val hs1 d10 u10]; norm_num have hW20 : W (kinProfile (Real.log (4/3) / 26406) hs2) 162400 65 30465 = 317960340/781 := by rw [W_kin_val hs2 d20 u20]; norm_num have hW21 : W (kinProfile (Real.log (4/3) / 26406) hs2) 162400 65 136741 = 484048 := by rw [W_kin_val hs2 d21 u21]; norm_num have hx : (277642:ℝ) ≤ W (kinProfile (10 * Real.log 2 / 29420) hs1) 3645 2080 136741 := by have h1 := W_ge (kinProfile (10 * Real.log 2 / 29420) hs1) (A := 3645) (K := 2080) (by norm_num) (by norm_num) 136741 have h2 := (abs_lt.mp (abs_m_lt (A := 3645) (K := 2080) (by norm_num) (by norm_num) 136741)).2 linarith have part1 : Tsig (kinProfile (10 * Real.log 2 / 29420) hs1) (kinProfile (Real.log (4/3) / 26406) hs2) 3645 162400 2080 65 136741 * (11/10) < Tsig (kinProfile (10 * Real.log 2 / 29420) hs1) (kinProfile (Real.log (4/3) / 26406) hs2) 3645 162400 2080 65 30465 := by unfold Tsig rw [hW10, hW20, hW21] obtain ⟨x, hxdef⟩ : ∃ x : ℝ, x = W (kinProfile (10 * Real.log 2 / 29420) hs1) 3645 2080 136741 := ⟨_, rfl⟩ rw [← hxdef] at hx ⊢ have hxpos : (0:ℝ) < x := by linarith have e1 : 2*3645*136741/x ≤ 3645*136741/138821 := by rw [div_le_div_iff₀ hxpos (by norm_num : (0:ℝ) < 138821)] linarith have hk : (0:ℝ) ≤ 2*162400*136741/484048/136741*(11/10) := by norm_num have e2 := mul_le_mul_of_nonneg_right e1 hk have e3 : (3645:ℝ)*136741/138821*(2*162400*136741/484048/136741*(11/10)) < 2*3645*30465/(67177870/1023)*(2*162400*30465/(317960340/781))/30465 := by norm_num linarith refine ⟨part1, ?_, ?_⟩ · intro y0 hy0 hmono by_contra hcon have hle := not_lt.mp hcon have h := hmono (⟨by norm_num, by linarith⟩ : (30465:ℝ) ∈ Ioc 0 y0) (⟨by norm_num, hle⟩ : (136741:ℝ) ∈ Ioc 0 y0) (by norm_num : (30465:ℝ) < 136741) have hpos := Tsig_pos (kinProfile (10 * Real.log 2 / 29420) hs1) (kinProfile (Real.log (4/3) / 26406) hs2) (A := 3645) (C := 162400) (K1 := 2080) (K2 := 65) (by norm_num) (by norm_num) (by norm_num) (by norm_num) (y := 136741) (by norm_num) linarith · intro y0 hy0 h0 have hH1 := H_eq_le (A := 3645) (K := 2080) (y := 136741) (by norm_num) (by norm_num) (by norm_num) have hH2 := H_eq_val d21 have hnum : (136741:ℝ)/(136741 + 2080) + 136741*(1 + 1*((136741 + 65 - 162400)/26406))/(162400 + 136741 + 65 + 26406) < 1 := by norm_num have hsum : H eqProfile 3645 2080 136741 + H eqProfile 162400 65 136741 < 1 := by rw [hH2] linarith exact below_peak eqProfile eqProfile (by norm_num) (by norm_num) (by norm_num) (by norm_num) (by norm_num : (0:ℝ) < 136741) hy0 h0 hsum /-! ## Surface capture with mass transport (two-compartment sensor model) Coverage theta of a capture surface, bulk analyte y held fixed by flow, Damkohler number Da = k R / kM: d theta/dt = k (y (1 - theta) - K theta) / (1 + Da (1 - theta)). Writing s = theta (y + K) / y and Q = K theta / y, the exact solution satisfies Lev Da Q s = k K t, with Lev Da Q s = Q ell(s) + Da Q + Da Q^2 mm(s). -/ noncomputable def Lf (s : ℝ) : ℝ := -Real.log (1 - s) noncomputable def ell (s : ℝ) : ℝ := Lf s / s noncomputable def mm (s : ℝ) : ℝ := (Lf s - s) / (s * s) noncomputable def eL (s : ℝ) : ℝ := s / ((1 - s) * Lf s) - 1 noncomputable def eM (s : ℝ) : ℝ := s * s / ((1 - s) * (Lf s - s)) - 2 lemma hasDerivAt_Lf {s : ℝ} (hs : s < 1) : HasDerivAt Lf (1 / (1 - s)) s := by have h1 : (1:ℝ) - s ≠ 0 := (sub_pos.mpr hs).ne' have h := (((hasDerivAt_id' s).const_sub 1).log h1).neg exact (h : HasDerivAt Lf _ s).congr_deriv (by ring) lemma exp_neg_Lf {s : ℝ} (h1 : s < 1) : Real.exp (-Lf s) = 1 - s := by unfold Lf rw [neg_neg, Real.exp_log (sub_pos.mpr h1)] lemma Lf_gt {s : ℝ} (h0 : 0 < s) (h1 : s < 1) : s < Lf s := by have h := Real.add_one_lt_exp (neg_ne_zero.mpr h0.ne') have hpos : 0 < 1 - s := sub_pos.mpr h1 have h2 : Real.log (1 - s) < -s := by rw [Real.log_lt_iff_lt_exp hpos] linarith unfold Lf linarith lemma Lf_pos {s : ℝ} (h0 : 0 < s) (h1 : s < 1) : 0 < Lf s := lt_trans h0 (Lf_gt h0 h1) lemma Lf_le {s : ℝ} (_h0 : 0 < s) (h1 : s < 1) : (1 - s) * Lf s ≤ s := by have hpos : 0 < 1 - s := sub_pos.mpr h1 have h := Real.log_le_sub_one_of_pos (inv_pos.mpr hpos) rw [Real.log_inv] at h have h3 : (1 - s) * Lf s ≤ (1 - s) * ((1 - s)⁻¹ - 1) := mul_le_mul_of_nonneg_left (by unfold Lf; linarith) hpos.le have h4 : (1 - s) * ((1 - s)⁻¹ - 1) = s := by rw [mul_sub, mul_inv_cancel₀ hpos.ne'] ring linarith lemma Lf_tanh {s : ℝ} (h0 : 0 < s) (h1 : s < 1) : 2 * s ≤ (2 - s) * Lf s := by have h := tanh_bound (Lf_pos h0 h1).le rw [exp_neg_Lf h1] at h linarith lemma Lf_sinh {s : ℝ} (h0 : 0 < s) (h1 : s < 1) : 2 * (1 - s) * Lf s ≤ s * (2 - s) := by have h := sinh_bound one_pos (Lf_pos h0 h1) have hu : uu 1 (Lf s) = 1 - s := by unfold uu rw [one_mul, exp_neg_Lf h1] rw [hu] at h linarith lemma Lf_zero : Lf 0 = 0 := by simp [Lf] lemma ell_pos {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : 0 < ell s := div_pos (Lf_pos hs.1 hs.2) hs.1 lemma mm_pos {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : 0 < mm s := div_pos (sub_pos.mpr (Lf_gt hs.1 hs.2)) (mul_pos hs.1 hs.1) lemma eL_nonneg {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : 0 ≤ eL s := by have hD : 0 < (1 - s) * Lf s := mul_pos (sub_pos.mpr hs.2) (Lf_pos hs.1 hs.2) have h := Lf_le hs.1 hs.2 unfold eL rw [sub_nonneg, le_div_iff₀ hD] linarith lemma eM_nonneg {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : 0 ≤ eM s := by have hD : 0 < (1 - s) * (Lf s - s) := mul_pos (sub_pos.mpr hs.2) (sub_pos.mpr (Lf_gt hs.1 hs.2)) have h := Lf_sinh hs.1 hs.2 unfold eM rw [sub_nonneg, le_div_iff₀ hD] nlinarith lemma hasDerivAt_ell {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : HasDerivAt ell (ell s * eL s / s) s := by have h0 := hs.1 have h1 := hs.2 have hL := hasDerivAt_Lf h1 have h := hL.div (hasDerivAt_id' s) h0.ne' refine (h : HasDerivAt ell _ s).congr_deriv ?_ have hLp : Lf s ≠ 0 := (Lf_pos h0 h1).ne' have h1s : (1:ℝ) - s ≠ 0 := (sub_pos.mpr h1).ne' have hs0 : s ≠ 0 := h0.ne' unfold ell eL field_simp lemma hasDerivAt_mm {s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : HasDerivAt mm (mm s * eM s / s) s := by have h0 := hs.1 have h1 := hs.2 have hL := hasDerivAt_Lf h1 have hss : s * s ≠ 0 := (mul_pos h0 h0).ne' have h := (hL.sub (hasDerivAt_id' s)).div ((hasDerivAt_id' s).mul (hasDerivAt_id' s)) hss refine (h : HasDerivAt mm _ s).congr_deriv ?_ have hLs : Lf s - s ≠ 0 := (sub_pos.mpr (Lf_gt h0 h1)).ne' have h1s : (1:ℝ) - s ≠ 0 := (sub_pos.mpr h1).ne' have hs0 : s ≠ 0 := h0.ne' unfold mm eM simp only [Pi.sub_apply, Pi.mul_apply] field_simp ring lemma eL_mono : MonotoneOn eL (Ioo 0 1) := by have hd : ∀ s ∈ Ioo (0:ℝ) 1, HasDerivAt eL ((Lf s - s) / ((1 - s) * Lf s) ^ 2) s := by intro s hs have h0 := hs.1 have h1 := hs.2 have hL := hasDerivAt_Lf h1 have h1s : (1:ℝ) - s ≠ 0 := (sub_pos.mpr h1).ne' have hLp : Lf s ≠ 0 := (Lf_pos h0 h1).ne' have hD : (1 - s) * Lf s ≠ 0 := mul_ne_zero h1s hLp have h := ((hasDerivAt_id' s).div (((hasDerivAt_id' s).const_sub 1).mul hL) hD).sub_const 1 refine (h : HasDerivAt eL _ s).congr_deriv ?_ simp only [Pi.mul_apply] field_simp ring apply monotoneOn_of_deriv_nonneg (convex_Ioo 0 1) · exact fun s hs => (hd s hs).continuousAt.continuousWithinAt · intro s hs rw [interior_Ioo] at hs exact (hd s hs).differentiableAt.differentiableWithinAt · intro s hs rw [interior_Ioo] at hs rw [(hd s hs).deriv] exact div_nonneg (sub_nonneg.mpr (Lf_gt hs.1 hs.2).le) (sq_nonneg _) lemma eM_mono : MonotoneOn eM (Ioo 0 1) := by have hd : ∀ s ∈ Ioo (0:ℝ) 1, HasDerivAt eM (s * ((2 - s) * Lf s - 2 * s) / ((1 - s) * (Lf s - s)) ^ 2) s := by intro s hs have h0 := hs.1 have h1 := hs.2 have hL := hasDerivAt_Lf h1 have h1s : (1:ℝ) - s ≠ 0 := (sub_pos.mpr h1).ne' have hLs : Lf s - s ≠ 0 := (sub_pos.mpr (Lf_gt h0 h1)).ne' have hD : (1 - s) * (Lf s - s) ≠ 0 := mul_ne_zero h1s hLs have h := (((hasDerivAt_id' s).mul (hasDerivAt_id' s)).div (((hasDerivAt_id' s).const_sub 1).mul (hL.sub (hasDerivAt_id' s))) hD).sub_const 2 refine (h : HasDerivAt eM _ s).congr_deriv ?_ simp only [Pi.sub_apply, Pi.mul_apply] field_simp ring apply monotoneOn_of_deriv_nonneg (convex_Ioo 0 1) · exact fun s hs => (hd s hs).continuousAt.continuousWithinAt · intro s hs rw [interior_Ioo] at hs exact (hd s hs).differentiableAt.differentiableWithinAt · intro s hs rw [interior_Ioo] at hs rw [(hd s hs).deriv] have ht := Lf_tanh hs.1 hs.2 exact div_nonneg (mul_nonneg hs.1.le (by linarith)) (sq_nonneg _) /-- Tangent-line inequality for a function whose log-log slope e is non-decreasing. -/ lemma tangent_log {f e : ℝ → ℝ} (hf : ∀ s ∈ Ioo (0:ℝ) 1, HasDerivAt f (f s * e s / s) s) (hpos : ∀ s ∈ Ioo (0:ℝ) 1, 0 < f s) (he : MonotoneOn e (Ioo 0 1)) {a b : ℝ} (ha : a ∈ Ioo (0:ℝ) 1) (hb : b ∈ Ioo (0:ℝ) 1) : e a * (Real.log b - Real.log a) ≤ Real.log (f b) - Real.log (f a) := by have hGd : ∀ s ∈ Ioo (0:ℝ) 1, HasDerivAt (fun x => Real.log (f x) - e a * Real.log x) ((e s - e a) / s) s := by intro s hs have h := ((hf s hs).log (hpos s hs).ne').sub ((Real.hasDerivAt_log hs.1.ne').const_mul (e a)) refine h.congr_deriv ?_ have h1 := (hpos s hs).ne' have h2 := hs.1.ne' field_simp have hcont : ContinuousOn (fun x => Real.log (f x) - e a * Real.log x) (Ioo 0 1) := fun s hs => (hGd s hs).continuousAt.continuousWithinAt rcases le_total a b with hab | hab · have hsub : Icc a b ⊆ Ioo 0 1 := fun x hx => ⟨lt_of_lt_of_le ha.1 hx.1, lt_of_le_of_lt hx.2 hb.2⟩ have hm : MonotoneOn (fun x => Real.log (f x) - e a * Real.log x) (Icc a b) := by apply monotoneOn_of_deriv_nonneg (convex_Icc a b) (hcont.mono hsub) · intro x hx rw [interior_Icc] at hx exact (hGd x (hsub (Ioo_subset_Icc_self hx))).differentiableAt.differentiableWithinAt · intro x hx rw [interior_Icc] at hx have hx' := hsub (Ioo_subset_Icc_self hx) rw [(hGd x hx').deriv] exact div_nonneg (sub_nonneg.mpr (he ha hx' hx.1.le)) hx'.1.le have h := hm (left_mem_Icc.mpr hab) (right_mem_Icc.mpr hab) hab have h' : Real.log (f a) - e a * Real.log a ≤ Real.log (f b) - e a * Real.log b := h linarith · have hsub : Icc b a ⊆ Ioo 0 1 := fun x hx => ⟨lt_of_lt_of_le hb.1 hx.1, lt_of_le_of_lt hx.2 ha.2⟩ have hm : AntitoneOn (fun x => Real.log (f x) - e a * Real.log x) (Icc b a) := by apply antitoneOn_of_deriv_nonpos (convex_Icc b a) (hcont.mono hsub) · intro x hx rw [interior_Icc] at hx exact (hGd x (hsub (Ioo_subset_Icc_self hx))).differentiableAt.differentiableWithinAt · intro x hx rw [interior_Icc] at hx have hx' := hsub (Ioo_subset_Icc_self hx) rw [(hGd x hx').deriv] exact div_nonpos_of_nonpos_of_nonneg (sub_nonpos.mpr (he hx' ha hx.2.le)) hx'.1.le have h := hm (left_mem_Icc.mpr hab) (right_mem_Icc.mpr hab) hab have h' : Real.log (f a) - e a * Real.log a ≤ Real.log (f b) - e a * Real.log b := h linarith lemma mul_one_add_log_le {x y : ℝ} (hx : 0 < x) (hy : 0 < y) : x * (1 + Real.log (y / x)) ≤ y := by have h := Real.log_le_sub_one_of_pos (div_pos hy hx) have h2 : x * (y / x) = y := by field_simp nlinarith [mul_le_mul_of_nonneg_left h hx.le] noncomputable def Lev (Da Q s : ℝ) : ℝ := Q * ell s + Da * Q + Da * (Q * Q) * mm s noncomputable def Dn (Da Q s : ℝ) : ℝ := Q * ell s + Da * Q + 2 * (Da * (Q * Q) * mm s) noncomputable def Nm (Da Q s : ℝ) : ℝ := eL s * (Q * ell s) + eM s * (Da * (Q * Q) * mm s) noncomputable def eps (Da Q s : ℝ) : ℝ := Nm Da Q s / Dn Da Q s lemma Dn_pos {Da Q s : ℝ} (hDa : 0 ≤ Da) (hs : s ∈ Ioo (0:ℝ) 1) (hQ : 0 < Q) : 0 < Dn Da Q s := by have h1 := mul_pos hQ (ell_pos hs) have h2 := mul_nonneg hDa hQ.le have h3 := mul_nonneg (mul_nonneg hDa (mul_pos hQ hQ).le) (mm_pos hs).le unfold Dn linarith lemma Nm_nonneg {Da Q s : ℝ} (hDa : 0 ≤ Da) (hs : s ∈ Ioo (0:ℝ) 1) (hQ : 0 < Q) : 0 ≤ Nm Da Q s := by have h1 := mul_pos hQ (ell_pos hs) have h3 := mul_nonneg (mul_nonneg hDa (mul_pos hQ hQ).le) (mm_pos hs).le unfold Nm exact add_nonneg (mul_nonneg (eL_nonneg hs) h1.le) (mul_nonneg (eM_nonneg hs) h3) lemma eps_nonneg {Da Q s : ℝ} (hDa : 0 ≤ Da) (hs : s ∈ Ioo (0:ℝ) 1) (hQ : 0 < Q) : 0 ≤ eps Da Q s := div_nonneg (Nm_nonneg hDa hs hQ) (Dn_pos hDa hs hQ).le lemma log_ratio {a b c d : ℝ} (ha : 0 < a) (hb : 0 < b) (hc : 0 < c) (hd : 0 < d) : Real.log (a * b / (c * d)) = (Real.log a - Real.log c) + (Real.log b - Real.log d) := by rw [Real.log_div (mul_pos ha hb).ne' (mul_pos hc hd).ne', Real.log_mul ha.ne' hb.ne', Real.log_mul hc.ne' hd.ne'] ring /-- Two points on one level set: the convexity (gradient) inequality. -/ lemma two_point {Da Q1 Q2 s1 s2 τ : ℝ} (hDa : 0 ≤ Da) (hs1 : s1 ∈ Ioo (0:ℝ) 1) (hs2 : s2 ∈ Ioo (0:ℝ) 1) (hQ1 : 0 < Q1) (hQ2 : 0 < Q2) (h1 : Lev Da Q1 s1 = τ) (h2 : Lev Da Q2 s2 = τ) : (Real.log Q2 - Real.log Q1) * Dn Da Q1 s1 + (Real.log s2 - Real.log s1) * Nm Da Q1 s1 ≤ 0 := by have hl1 := ell_pos hs1 have hl2 := ell_pos hs2 have hm1 := mm_pos hs1 have hm2 := mm_pos hs2 have tl := tangent_log (fun s hs => hasDerivAt_ell hs) (fun s hs => ell_pos hs) eL_mono hs1 hs2 have tm := tangent_log (fun s hs => hasDerivAt_mm hs) (fun s hs => mm_pos hs) eM_mono hs1 hs2 have hQQ1 : 0 < Q1 * Q1 := mul_pos hQ1 hQ1 have hQQ2 : 0 < Q2 * Q2 := mul_pos hQ2 hQ2 -- term 1 have a1 := mul_one_add_log_le (mul_pos hQ1 hl1) (mul_pos hQ2 hl2) rw [log_ratio hQ2 hl2 hQ1 hl1] at a1 have b1 : Q1 * ell s1 * (1 + (Real.log Q2 - Real.log Q1) + eL s1 * (Real.log s2 - Real.log s1)) ≤ Q2 * ell s2 := by have := mul_le_mul_of_nonneg_left tl (mul_pos hQ1 hl1).le linarith -- term 2 have a2 := mul_one_add_log_le hQ1 hQ2 rw [Real.log_div hQ2.ne' hQ1.ne'] at a2 have b2 := mul_le_mul_of_nonneg_left a2 hDa -- term 3 have a3 := mul_one_add_log_le (mul_pos hQQ1 hm1) (mul_pos hQQ2 hm2) rw [log_ratio hQQ2 hm2 hQQ1 hm1, Real.log_mul hQ2.ne' hQ2.ne', Real.log_mul hQ1.ne' hQ1.ne'] at a3 have b3 : Q1 * Q1 * mm s1 * (1 + 2 * (Real.log Q2 - Real.log Q1) + eM s1 * (Real.log s2 - Real.log s1)) ≤ Q2 * Q2 * mm s2 := by have := mul_le_mul_of_nonneg_left tm (mul_pos hQQ1 hm1).le linarith have c3 := mul_le_mul_of_nonneg_left b3 hDa unfold Lev at h1 h2 unfold Dn Nm linarith lemma level_mono {Da Q1 Q2 s1 s2 τ : ℝ} (hDa : 0 ≤ Da) (hs1 : s1 ∈ Ioo (0:ℝ) 1) (hs2 : s2 ∈ Ioo (0:ℝ) 1) (hlt : s1 < s2) (hQ1 : 0 < Q1) (hQ2 : 0 < Q2) (h1 : Lev Da Q1 s1 = τ) (h2 : Lev Da Q2 s2 = τ) : Q2 ≤ Q1 ∧ eps Da Q1 s1 ≤ eps Da Q2 s2 := by have A := two_point hDa hs1 hs2 hQ1 hQ2 h1 h2 have B := two_point hDa hs2 hs1 hQ2 hQ1 h2 h1 have hσ : 0 < Real.log s2 - Real.log s1 := sub_pos.mpr (Real.log_lt_log hs1.1 hlt) have hD1 := Dn_pos hDa hs1 hQ1 have hD2 := Dn_pos hDa hs2 hQ2 have hN1 := Nm_nonneg hDa hs1 hQ1 have hN2 := Nm_nonneg hDa hs2 hQ2 have hr : Real.log Q2 - Real.log Q1 ≤ 0 := by by_contra hcon have hp := not_le.mp hcon nlinarith [mul_pos hp hD1, mul_nonneg hσ.le hN1] constructor · have := sub_nonpos.mp hr exact (Real.log_le_log_iff hQ2 hQ1).mp this · have A1 : (Real.log Q2 - Real.log Q1) * Dn Da Q1 s1 ≤ -((Real.log s2 - Real.log s1) * Nm Da Q1 s1) := by linarith have B1 : -((Real.log s2 - Real.log s1) * Nm Da Q2 s2) ≤ (Real.log Q2 - Real.log Q1) * Dn Da Q2 s2 := by linarith have A2 := mul_le_mul_of_nonneg_right A1 hD2.le have B2 := mul_le_mul_of_nonneg_right B1 hD1.le have C1 : (Real.log s2 - Real.log s1) * (Nm Da Q1 s1 * Dn Da Q2 s2 - Nm Da Q2 s2 * Dn Da Q1 s1) ≤ 0 := by nlinarith have C2 : Nm Da Q1 s1 * Dn Da Q2 s2 ≤ Nm Da Q2 s2 * Dn Da Q1 s1 := by by_contra hcon have hp := sub_pos.mpr (not_le.mp hcon) nlinarith [mul_pos hσ hp] unfold eps rw [div_le_div_iff₀ hD1 hD2] linarith lemma quad_root {a b τ : ℝ} (ha : 0 ≤ a) (hb : 0 < b) (hτ : 0 ≤ τ) : a * ((2*τ / (b + Real.sqrt (b*b + 4*a*τ))) * (2*τ / (b + Real.sqrt (b*b + 4*a*τ)))) + b * (2*τ / (b + Real.sqrt (b*b + 4*a*τ))) = τ := by obtain ⟨r, hr⟩ : ∃ r, r = Real.sqrt (b*b + 4*a*τ) := ⟨_, rfl⟩ rw [← hr] have hr0 : 0 ≤ r := by rw [hr]; exact Real.sqrt_nonneg _ have hr2 : r^2 = b*b + 4*a*τ := by rw [hr] exact Real.sq_sqrt (by nlinarith [mul_nonneg ha hτ, mul_self_nonneg b]) have hbr : 0 < b + r := by linarith have hbr' := hbr.ne' obtain ⟨Q, hQ⟩ : ∃ Q, Q = 2*τ / (b + r) := ⟨_, rfl⟩ rw [← hQ] have hQr : Q * (b + r) = 2*τ := by rw [hQ]; field_simp have h1 : (2*a*Q + b - r) * (b + r) = 0 := by linear_combination (2*a) * hQr - hr2 have h2 : 2*a*Q + b - r = 0 := by rcases mul_eq_zero.mp h1 with h | h · exact h · exact absurd h hbr' linear_combination (Q/2) * h2 + (1/2) * hQr lemma quad_lt {a b X Z : ℝ} (ha : 0 ≤ a) (hb : 0 < b) (hX : 0 < X) (hXZ : X < Z) : a * (X * X) + b * X < a * (Z * Z) + b * Z := by nlinarith [mul_nonneg ha (mul_nonneg (sub_nonneg.mpr hXZ.le) (by linarith : (0:ℝ) ≤ Z + X)), mul_pos hb (sub_pos.mpr hXZ)] lemma Lev_quad (Da Q s : ℝ) : Lev Da Q s = (Da * mm s) * (Q * Q) + (ell s + Da) * Q := by unfold Lev ring lemma Lev_lt {Da s X Z : ℝ} (hDa : 0 ≤ Da) (hs : s ∈ Ioo (0:ℝ) 1) (hX : 0 < X) (hXZ : X < Z) : Lev Da X s < Lev Da Z s := by rw [Lev_quad, Lev_quad] have h := ell_pos hs exact quad_lt (mul_nonneg hDa (mm_pos hs).le) (by linarith) hX hXZ lemma Lev_inj {Da s X Z : ℝ} (hDa : 0 ≤ Da) (hs : s ∈ Ioo (0:ℝ) 1) (hX : 0 < X) (hZ : 0 < Z) (h : Lev Da X s = Lev Da Z s) : X = Z := by rcases lt_trichotomy X Z with hl | he | hg · exact absurd h (Lev_lt hDa hs hX hl).ne · exact he · exact absurd h (Lev_lt hDa hs hZ hg).ne' lemma Lev_diag {Da s : ℝ} (hs : s ∈ Ioo (0:ℝ) 1) : Lev Da s s = (1 + Da) * Lf s := by have h0 : s ≠ 0 := hs.1.ne' unfold Lev ell mm field_simp ring /-- The level curve, solved explicitly for Q as a function of s. -/ noncomputable def Qf (Da τ s : ℝ) : ℝ := 2*τ / ((ell s + Da) + Real.sqrt ((ell s + Da) * (ell s + Da) + 4 * (Da * mm s) * τ)) lemma Qf_pos {Da τ s : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (0:ℝ) 1) : 0 < Qf Da τ s := by have h := ell_pos hs have h2 := Real.sqrt_nonneg ((ell s + Da) * (ell s + Da) + 4 * (Da * mm s) * τ) unfold Qf apply div_pos (by linarith) linarith lemma Lev_Qf {Da τ s : ℝ} (hDa : 0 ≤ Da) (hτ : 0 ≤ τ) (hs : s ∈ Ioo (0:ℝ) 1) : Lev Da (Qf Da τ s) s = τ := by have h := ell_pos hs have hq := quad_root (a := Da * mm s) (b := ell s + Da) (τ := τ) (mul_nonneg hDa (mm_pos hs).le) (by linarith) hτ rw [Lev_quad] unfold Qf linarith /-- Low end of the level curve (bulk concentration tending to zero). -/ noncomputable def smin (Da τ : ℝ) : ℝ := 1 - Real.exp (-(τ / (1 + Da))) lemma smin_pos {Da τ : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) : 0 < smin Da τ := by have h : -(τ / (1 + Da)) < 0 := neg_neg_of_pos (div_pos hτ (by linarith)) have h2 := Real.exp_lt_one_iff.mpr h unfold smin linarith lemma smin_lt_one (Da τ : ℝ) : smin Da τ < 1 := by have h := Real.exp_pos (-(τ / (1 + Da))) unfold smin linarith lemma lt_Lf_of_smin_lt {Da τ s : ℝ} (hDa : 0 ≤ Da) (hs : smin Da τ < s) (h1 : s < 1) : τ < (1 + Da) * Lf s := by have hpos : 0 < 1 - s := sub_pos.mpr h1 have h : Real.log (1 - s) < -(τ / (1 + Da)) := by rw [Real.log_lt_iff_lt_exp hpos] unfold smin at hs linarith have h2 : τ / (1 + Da) < Lf s := by unfold Lf linarith rw [div_lt_iff₀ (by linarith : (0:ℝ) < 1 + Da)] at h2 linarith lemma smin_lt_of_lt_Lf {Da τ s : ℝ} (hDa : 0 ≤ Da) (h1 : s < 1) (h : τ < (1 + Da) * Lf s) : smin Da τ < s := by have h2 : τ / (1 + Da) < Lf s := by rw [div_lt_iff₀ (by linarith : (0:ℝ) < 1 + Da)] linarith have h3 : Real.exp (-Lf s) < Real.exp (-(τ / (1 + Da))) := Real.exp_lt_exp.mpr (by linarith) rw [exp_neg_Lf h1] at h3 unfold smin linarith lemma mem_of_smin {Da τ s : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (smin Da τ) 1) : s ∈ Ioo (0:ℝ) 1 := ⟨lt_trans (smin_pos hDa hτ) hs.1, hs.2⟩ lemma Qf_lt {Da τ s : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (smin Da τ) 1) : Qf Da τ s < s := by have hs' := mem_of_smin hDa hτ hs have h1 := Lev_Qf hDa hτ.le hs' have h2 := Lev_diag (Da := Da) hs' have h3 := lt_Lf_of_smin_lt hDa hs.1 hs.2 by_contra hcon have hle := not_lt.mp hcon rcases eq_or_lt_of_le hle with he | hl · rw [← he] at h1 linarith · have := Lev_lt hDa hs' hs'.1 hl linarith /-- Damkohler-weighted log-slope of Q along the level curve: dQ/ds = -eps Q / s. -/ lemma hasDerivAt_Qf {Da τ s : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (0:ℝ) 1) : HasDerivAt (Qf Da τ) (-(eps Da (Qf Da τ s) s * Qf Da τ s / s)) s := by have hl := hasDerivAt_ell hs have hm := hasDerivAt_mm hs have hlp := ell_pos hs have hb := hl.add_const Da have hrad := (hb.mul hb).add (((hm.const_mul Da).const_mul 4).mul_const τ) have hradpos : 0 < (ell s + Da) * (ell s + Da) + 4 * (Da * mm s) * τ := by have := mul_nonneg (mul_nonneg hDa (mm_pos hs).le) hτ.le have hb0 : 0 < ell s + Da := by linarith nlinarith [mul_pos hb0 hb0] have hsq := hrad.sqrt hradpos.ne' have hden := hb.add hsq have hdenpos : 0 < (ell s + Da) + Real.sqrt ((ell s + Da) * (ell s + Da) + 4 * (Da * mm s) * τ) := by have := Real.sqrt_nonneg ((ell s + Da) * (ell s + Da) + 4 * (Da * mm s) * τ) linarith have hQ := (hasDerivAt_const s (2*τ)).div hden hdenpos.ne' obtain ⟨D, hD⟩ : ∃ D, HasDerivAt (Qf Da τ) D s := ⟨_, hQ⟩ have hF := ((hD.mul hl).add (hD.const_mul Da)).add (((hD.mul hD).const_mul Da).mul hm) have hev : (fun _ : ℝ => τ) =ᶠ[nhds s] (fun x => Lev Da (Qf Da τ x) x) := Filter.eventually_of_mem (Ioo_mem_nhds hs.1 hs.2) (fun x hx => (Lev_Qf hDa hτ.le hx).symm) have hF' := (hF : HasDerivAt (fun x => Lev Da (Qf Da τ x) x) _ s).congr_of_eventuallyEq hev have hX := hF'.unique (hasDerivAt_const s τ) have hQp := Qf_pos hDa hτ hs have h5 : D * Dn Da (Qf Da τ s) s + Qf Da τ s * Nm Da (Qf Da τ s) s / s = 0 := by unfold Dn Nm simp only [Pi.mul_apply] at hX linear_combination (Qf Da τ s) * hX have hDn := Dn_pos hDa hs hQp have h6 : D = -(Qf Da τ s * Nm Da (Qf Da τ s) s / s) / Dn Da (Qf Da τ s) s := by rw [eq_div_iff hDn.ne'] linarith refine hD.congr_deriv ?_ rw [h6] unfold eps ring /-- Bulk concentration along the level curve. -/ noncomputable def yf (K Da τ s : ℝ) : ℝ := K * (s / Qf Da τ s - 1) lemma yf_pos {K Da τ s : ℝ} (hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (smin Da τ) 1) : 0 < yf K Da τ s := by have hQ := Qf_pos hDa hτ (mem_of_smin hDa hτ hs) have h := Qf_lt hDa hτ hs have h2 : 1 < s / Qf Da τ s := by rw [one_lt_div hQ]; exact h unfold yf exact mul_pos hK (by linarith) lemma level_mono_Qf {Da τ s1 s2 : ℝ} (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs1 : s1 ∈ Ioo (0:ℝ) 1) (hs2 : s2 ∈ Ioo (0:ℝ) 1) (hlt : s1 < s2) : Qf Da τ s2 ≤ Qf Da τ s1 ∧ eps Da (Qf Da τ s1) s1 ≤ eps Da (Qf Da τ s2) s2 := level_mono hDa hs1 hs2 hlt (Qf_pos hDa hτ hs1) (Qf_pos hDa hτ hs2) (Lev_Qf hDa hτ.le hs1) (Lev_Qf hDa hτ.le hs2) lemma yf_strictMono {K Da τ : ℝ} (hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) : StrictMonoOn (yf K Da τ) (Ioo (smin Da τ) 1) := by intro s1 hs1 s2 hs2 hlt have hs1' := mem_of_smin hDa hτ hs1 have hs2' := mem_of_smin hDa hτ hs2 have hQ1 := Qf_pos hDa hτ hs1' have hQ2 := Qf_pos hDa hτ hs2' have hm := (level_mono_Qf hDa hτ hs1' hs2' hlt).1 have h : s1 / Qf Da τ s1 < s2 / Qf Da τ s2 := by rw [div_lt_div_iff₀ hQ1 hQ2] nlinarith [mul_le_mul_of_nonneg_left hm hs1'.1.le, mul_lt_mul_of_pos_right hlt hQ1] unfold yf exact mul_lt_mul_of_pos_left (by linarith) hK /-- Signal along the level curve: coverage times labeled fraction 2C/W at bulk yf. -/ noncomputable def Ssig (p : Profile) (C K2 K Da τ s : ℝ) : ℝ := (s - Qf Da τ s) * (2*C / W p C K2 (yf K Da τ s)) /-- Log-slope of the signal (in units of d ln y): coverage slope minus label slope. -/ noncomputable def Lam (p : Profile) (C K2 K Da τ s : ℝ) : ℝ := 1 - eps Da (Qf Da τ s) s / (1 + eps Da (Qf Da τ s) s) * (1 - Qf Da τ s / s) - H p C K2 (yf K Da τ s) lemma hasDerivAt_Ssig (p : Profile) {C K2 K Da τ s : ℝ} (hC : 0 < C) (hK2 : 0 < K2) (_hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (smin Da τ) 1) : HasDerivAt (Ssig p C K2 K Da τ) (Ssig p C K2 K Da τ s * ((1 + eps Da (Qf Da τ s) s) / (s - Qf Da τ s)) * Lam p C K2 K Da τ s) s := by have hs' := mem_of_smin hDa hτ hs have hQ := hasDerivAt_Qf hDa hτ hs' have hQp := Qf_pos hDa hτ hs' have hQs := Qf_lt hDa hτ hs have he := eps_nonneg hDa hs' hQp have hy := (((hasDerivAt_id' s).div hQ hQp.ne').sub_const 1).const_mul K have hW := (hasDerivAt_W p hC hK2 (yf K Da τ s)).comp s (hy : HasDerivAt (yf K Da τ) _ s) have hWp := W_pos p hC hK2 (yf K Da τ s) have hP := (hasDerivAt_const s (2*C)).div hW hWp.ne' have hS := ((hasDerivAt_id' s).sub hQ).mul hP refine (hS : HasDerivAt (Ssig p C K2 K Da τ) _ s).congr_deriv ?_ unfold Ssig Lam H simp only [Function.comp_apply, Pi.sub_apply, Pi.div_apply] obtain ⟨Wv, hWv⟩ : ∃ v, v = W p C K2 (yf K Da τ s) := ⟨_, rfl⟩ obtain ⟨W1v, hW1v⟩ : ∃ v, v = W1 p C K2 (yf K Da τ s) := ⟨_, rfl⟩ rw [← hWv, ← hW1v] rw [← hWv] at hWp unfold yf obtain ⟨Q, hQq⟩ : ∃ v, v = Qf Da τ s := ⟨_, rfl⟩ obtain ⟨e, hee⟩ : ∃ v, v = eps Da (Qf Da τ s) s := ⟨_, rfl⟩ rw [← hee, ← hQq] rw [← hQq] at hQp hQs rw [← hee] at he have h1 : s ≠ 0 := hs'.1.ne' have h2 : Q ≠ 0 := hQp.ne' have h3 : s - Q ≠ 0 := (sub_pos.mpr hQs).ne' have h4 : 1 + e ≠ 0 := by linarith have h5 : Wv ≠ 0 := hWp.ne' field_simp ring lemma Lam_strictAnti (p : Profile) {C K2 K Da τ : ℝ} (hC : 0 < C) (hK2 : 0 < K2) (hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) : StrictAntiOn (Lam p C K2 K Da τ) (Ioo (smin Da τ) 1) := by intro s1 hs1 s2 hs2 hlt have hs1' := mem_of_smin hDa hτ hs1 have hs2' := mem_of_smin hDa hτ hs2 have hQ1 := Qf_pos hDa hτ hs1' have hQ2 := Qf_pos hDa hτ hs2' have hQs1 := Qf_lt hDa hτ hs1 obtain ⟨hm, he⟩ := level_mono_Qf hDa hτ hs1' hs2' hlt have he1 := eps_nonneg hDa hs1' hQ1 have he2 := eps_nonneg hDa hs2' hQ2 have hH := H_strictMonoOn p hC hK2 (mem_Ioi.mpr (yf_pos hK hDa hτ hs1)) (mem_Ioi.mpr (yf_pos hK hDa hτ hs2)) (yf_strictMono hK hDa hτ hs1 hs2 hlt) have ha : eps Da (Qf Da τ s1) s1 / (1 + eps Da (Qf Da τ s1) s1) ≤ eps Da (Qf Da τ s2) s2 / (1 + eps Da (Qf Da τ s2) s2) := by rw [div_le_div_iff₀ (by linarith) (by linarith)] nlinarith have hb : Qf Da τ s2 / s2 ≤ Qf Da τ s1 / s1 := by rw [div_le_div_iff₀ hs2'.1 hs1'.1] nlinarith [mul_le_mul_of_nonneg_right hm hs1'.1.le, mul_lt_mul_of_pos_left hlt hQ1] have hb0 : 0 ≤ 1 - Qf Da τ s1 / s1 := by rw [sub_nonneg, div_le_one hs1'.1] exact hQs1.le have ha0 : 0 ≤ eps Da (Qf Da τ s2) s2 / (1 + eps Da (Qf Da τ s2) s2) := div_nonneg he2 (by linarith) have hprod := mul_le_mul ha (by linarith : 1 - Qf Da τ s1 / s1 ≤ 1 - Qf Da τ s2 / s2) hb0 ha0 unfold Lam linarith lemma Ssig_pos (p : Profile) {C K2 K Da τ s : ℝ} (hC : 0 < C) (hK2 : 0 < K2) (hDa : 0 ≤ Da) (hτ : 0 < τ) (hs : s ∈ Ioo (smin Da τ) 1) : 0 < Ssig p C K2 K Da τ s := by have hQs := Qf_lt hDa hτ hs have hW := W_pos p hC hK2 (yf K Da τ s) unfold Ssig exact mul_pos (sub_pos.mpr hQs) (div_pos (by linarith) hW) /-- Pure real analysis: a positive multiple of a strictly decreasing function as derivative, plus one rising and one falling pair, gives a single interior peak. -/ lemma unimodal_core {f c L : ℝ → ℝ} {a b : ℝ} (hf : ∀ s ∈ Ioo a b, HasDerivAt f (c s * L s) s) (hc : ∀ s ∈ Ioo a b, 0 < c s) (hL : StrictAntiOn L (Ioo a b)) (hup : ∃ u ∈ Ioo a b, ∃ v ∈ Ioo a b, u < v ∧ f u ≤ f v) (hdown : ∃ u ∈ Ioo a b, ∃ v ∈ Ioo a b, u < v ∧ f v ≤ f u) : ∃ s0 ∈ Ioo a b, StrictMonoOn f (Ioc a s0) ∧ StrictAntiOn f (Ico s0 b) := by obtain ⟨u1, hu1, v1, hv1, huv1, hf1⟩ := hup obtain ⟨u2, hu2, v2, hv2, huv2, hf2⟩ := hdown have hcont : ∀ s ∈ Ioo a b, ContinuousAt f s := fun s hs => (hf s hs).continuousAt -- some point with L > 0 have hA1 : 0 < L u1 := by by_contra hcon have h0 := not_lt.mp hcon have hanti : StrictAntiOn f (Icc u1 v1) := by apply strictAntiOn_of_deriv_neg (convex_Icc u1 v1) · intro x hx exact (hcont x ⟨lt_of_lt_of_le hu1.1 hx.1, lt_of_le_of_lt hx.2 hv1.2⟩).continuousWithinAt · intro x hx rw [interior_Icc] at hx have hx' : x ∈ Ioo a b := ⟨lt_trans hu1.1 hx.1, lt_trans hx.2 hv1.2⟩ rw [(hf x hx').deriv] have h1 := hL hu1 hx' hx.1 exact mul_neg_of_pos_of_neg (hc x hx') (by linarith) have := hanti (left_mem_Icc.mpr huv1.le) (right_mem_Icc.mpr huv1.le) huv1 linarith -- some point with L < 0 have hB1 : L v2 < 0 := by by_contra hcon have h0 := not_lt.mp hcon have hmono : StrictMonoOn f (Icc u2 v2) := by apply strictMonoOn_of_deriv_pos (convex_Icc u2 v2) · intro x hx exact (hcont x ⟨lt_of_lt_of_le hu2.1 hx.1, lt_of_le_of_lt hx.2 hv2.2⟩).continuousWithinAt · intro x hx rw [interior_Icc] at hx have hx' : x ∈ Ioo a b := ⟨lt_trans hu2.1 hx.1, lt_trans hx.2 hv2.2⟩ rw [(hf x hx').deriv] have h1 := hL hx' hv2 hx.2 exact mul_pos (hc x hx') (by linarith) have := hmono (left_mem_Icc.mpr huv2.le) (right_mem_Icc.mpr huv2.le) huv2 linarith set A : Set ℝ := {s | s ∈ Ioo a b ∧ 0 < L s} with hAdef have hAne : A.Nonempty := ⟨u1, hu1, hA1⟩ have hAbdd : ∀ x ∈ A, x < v2 := by intro x hx by_contra hcon have hle := not_lt.mp hcon rcases eq_or_lt_of_le hle with he | hl · rw [he] at hB1 linarith [hx.2] · have := hL hv2 hx.1 hl linarith [hx.2] have hbdd : BddAbove A := ⟨v2, fun x hx => (hAbdd x hx).le⟩ obtain ⟨s0, hs0⟩ : ∃ s0, s0 = sSup A := ⟨_, rfl⟩ have hu1s : u1 ≤ s0 := by rw [hs0]; exact le_csSup hbdd ⟨hu1, hA1⟩ have hs0v : s0 ≤ v2 := by rw [hs0]; exact csSup_le hAne (fun x hx => (hAbdd x hx).le) have hs0mem : s0 ∈ Ioo a b := ⟨lt_of_lt_of_le hu1.1 hu1s, lt_of_le_of_lt hs0v hv2.2⟩ have hleft : ∀ x ∈ Ioo a s0, 0 < L x := by intro x hx have hx' : x ∈ Ioo a b := ⟨hx.1, lt_trans hx.2 hs0mem.2⟩ obtain ⟨z, hz, hxz⟩ := exists_lt_of_lt_csSup hAne (by rw [← hs0]; exact hx.2) have := hL hx' hz.1 hxz linarith [hz.2] have hright : ∀ x ∈ Ioo s0 b, L x < 0 := by intro x hx have hx' : x ∈ Ioo a b := ⟨lt_trans hs0mem.1 hx.1, hx.2⟩ by_contra hcon have h0 := not_lt.mp hcon obtain ⟨m, hm⟩ : ∃ m, m = (s0 + x) / 2 := ⟨_, rfl⟩ have hm1 : s0 < m := by rw [hm]; linarith [hx.1] have hm2 : m < x := by rw [hm]; linarith [hx.1] have hm' : m ∈ Ioo a b := ⟨lt_trans hs0mem.1 hm1, lt_trans hm2 hx.2⟩ have hLm := hL hm' hx' hm2 have hmA : m ∈ A := ⟨hm', by linarith⟩ have := le_csSup hbdd hmA rw [← hs0] at this linarith refine ⟨s0, hs0mem, ?_, ?_⟩ · apply strictMonoOn_of_deriv_pos (convex_Ioc a s0) · intro x hx exact (hcont x ⟨hx.1, lt_of_le_of_lt hx.2 hs0mem.2⟩).continuousWithinAt · intro x hx rw [interior_Ioc] at hx have hx' : x ∈ Ioo a b := ⟨hx.1, lt_trans hx.2 hs0mem.2⟩ rw [(hf x hx').deriv] exact mul_pos (hc x hx') (hleft x hx) · apply strictAntiOn_of_deriv_neg (convex_Ico s0 b) · intro x hx exact (hcont x ⟨lt_of_lt_of_le hs0mem.1 hx.1, hx.2⟩).continuousWithinAt · intro x hx rw [interior_Ico] at hx have hx' : x ∈ Ioo a b := ⟨lt_trans hs0mem.1 hx.1, hx.2⟩ rw [(hf x hx').deriv] exact mul_neg_of_pos_of_neg (hc x hx') (hright x hx) /-- Exact time course of the two-compartment model, written in the bulk concentration y. -/ noncomputable def Elev (K Da θ y : ℝ) : ℝ := (K / (y + K)) * (1 + Da * (K / (y + K))) * Lf (θ * (y + K) / y) + Da * (K / (y + K)) * (1 - K / (y + K)) * (θ * (y + K) / y) lemma Elev_eq_Lev {K Da θ y : ℝ} (hK : 0 < K) (hy : 0 < y) (hθ : 0 < θ) : Elev K Da θ y = Lev Da (K * θ / y) (θ * (y + K) / y) := by unfold Elev obtain ⟨s, hs⟩ : ∃ s, s = θ * (y + K) / y := ⟨_, rfl⟩ rw [← hs] have hyK : y + K ≠ 0 := by linarith have hy0 : y ≠ 0 := hy.ne' have hs0 : s ≠ 0 := by rw [hs]; positivity have hθs : θ = s * y / (y + K) := by rw [hs]; field_simp subst hθs unfold Lev ell mm field_simp ring lemma transfer {K Da τ θ y : ℝ} (hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) (hy : 0 < y) (hθ : 0 < θ) (hθ1 : θ * (y + K) < y) (hE : Elev K Da θ y = τ) : θ * (y + K) / y ∈ Ioo (smin Da τ) 1 ∧ Qf Da τ (θ * (y + K) / y) = K * θ / y ∧ yf K Da τ (θ * (y + K) / y) = y := by have hs1 : θ * (y + K) / y < 1 := by rw [div_lt_one hy]; exact hθ1 have hs0 : 0 < θ * (y + K) / y := by positivity have hs : θ * (y + K) / y ∈ Ioo (0:ℝ) 1 := ⟨hs0, hs1⟩ have hQ : 0 < K * θ / y := by positivity have hdiff : θ * (y + K) / y - K * θ / y = θ := by field_simp ring have hQs : K * θ / y < θ * (y + K) / y := by linarith have hL := Elev_eq_Lev (Da := Da) hK hy hθ rw [hE] at hL have hlt : τ < (1 + Da) * Lf (θ * (y + K) / y) := by rw [← Lev_diag hs, hL] exact Lev_lt hDa hs hQ hQs have hmem : θ * (y + K) / y ∈ Ioo (smin Da τ) 1 := ⟨smin_lt_of_lt_Lf hDa hs1 hlt, hs1⟩ have hQf : Qf Da τ (θ * (y + K) / y) = K * θ / y := by apply Lev_inj hDa hs (Qf_pos hDa hτ hs) hQ rw [Lev_Qf hDa hτ.le hs] exact hL refine ⟨hmem, hQf, ?_⟩ unfold yf rw [hQf] have hK0 : K ≠ 0 := hK.ne' have hθ0 : θ ≠ 0 := hθ.ne' have hy0 : y ≠ 0 := hy.ne' field_simp ring lemma pos_of_Elev_pos {K Da θ y : ℝ} (hK : 0 < K) (hDa : 0 ≤ Da) (hy : 0 < y) (hE : 0 < Elev K Da θ y) : 0 < θ := by by_contra hcon have hle := not_lt.mp hcon have h1 : θ * (y + K) ≤ 0 := by nlinarith have hsv : θ * (y + K) / y ≤ 0 := div_nonpos_of_nonpos_of_nonneg h1 hy.le have hlog : 0 ≤ Real.log (1 - θ * (y + K) / y) := Real.log_nonneg (by linarith) have hLf : Lf (θ * (y + K) / y) ≤ 0 := by unfold Lf; linarith have hρ : 0 < K / (y + K) := div_pos hK (by linarith) have hρ1 : K / (y + K) < 1 := by rw [div_lt_one (by linarith)]; linarith have c1 : 0 ≤ (K / (y + K)) * (1 + Da * (K / (y + K))) := mul_nonneg hρ.le (by nlinarith [mul_nonneg hDa hρ.le]) have c2 : 0 ≤ Da * (K / (y + K)) * (1 - K / (y + K)) := mul_nonneg (mul_nonneg hDa hρ.le) (by linarith) have t1 := mul_nonpos_of_nonneg_of_nonpos c1 hLf have t2 := mul_nonpos_of_nonneg_of_nonpos c2 hsv unfold Elev at hE linarith /-- One hook on a sensor surface with mass transport, for any detection-antibody profile and any read time: if theta(y) is the exact surface coverage at bulk concentration y (the level equation Elev = tau, tau = k K t), the signal theta(y) * 2C/W rises strictly to a single peak y0 and falls strictly after it. -/ theorem surface_one_peak_level (p : Profile) {C K2 K Da τ : ℝ} (hC : 0 < C) (hK2 : 0 < K2) (hK : 0 < K) (hDa : 0 ≤ Da) (hτ : 0 < τ) (θ : ℝ → ℝ) (hθ : ∀ y, 0 < y → 0 < θ y ∧ θ y * (y + K) < y ∧ Elev K Da (θ y) y = τ) : ∃ y0 : ℝ, 0 < y0 ∧ StrictMonoOn (fun y => θ y * (2*C / W p C K2 y)) (Ioc 0 y0) ∧ StrictAntiOn (fun y => θ y * (2*C / W p C K2 y)) (Ici y0) := by have htr : ∀ y, 0 < y → θ y * (y + K) / y ∈ Ioo (smin Da τ) 1 ∧ yf K Da τ (θ y * (y + K) / y) = y ∧ Ssig p C K2 K Da τ (θ y * (y + K) / y) = θ y * (2*C / W p C K2 y) := by intro y hy obtain ⟨h1, h2, h3⟩ := hθ y hy obtain ⟨t1, t2, t3⟩ := transfer hK hDa hτ hy h1 h2 h3 refine ⟨t1, t3, ?_⟩ have hdiff : θ y * (y + K) / y - K * θ y / y = θ y := by have hy0 : y ≠ 0 := hy.ne' field_simp ring unfold Ssig rw [t2, t3, hdiff] have hyf := yf_strictMono hK hDa hτ have hsh : StrictMonoOn (fun y => θ y * (y + K) / y) (Ioi 0) := by intro y1 hy1 y2 hy2 hlt by_contra hcon have hle := not_lt.mp hcon have h := hyf.monotoneOn (htr y2 hy2).1 (htr y1 hy1).1 hle rw [(htr y1 hy1).2.1, (htr y2 hy2).2.1] at h linarith -- bounds on the signal have hSlo : ∀ y, 0 < y → θ y * (2*C / W p C K2 y) ≤ y / K := by intro y hy obtain ⟨h1, h2, _⟩ := hθ y hy have hW := W_pos p hC hK2 y have hW2 := two_A_lt_W p hC hK2 y have hfrac : 2*C / W p C K2 y ≤ 1 := by rw [div_le_one hW]; linarith have hθK : θ y ≤ y / K := by rw [le_div_iff₀ hK]; nlinarith calc θ y * (2*C / W p C K2 y) ≤ θ y * 1 := mul_le_mul_of_nonneg_left hfrac h1.le _ ≤ y / K := by linarith have hShi : ∀ y, 0 < y → θ y * (2*C / W p C K2 y) ≤ C / y := by intro y hy obtain ⟨h1, h2, _⟩ := hθ y hy have hW := W_pos p hC hK2 y have hW2 := two_y_le_W p hC hK2 hy.le have hθ1 : θ y ≤ 1 := by nlinarith have hfrac : 2*C / W p C K2 y ≤ C / y := by rw [div_le_div_iff₀ hW hy] nlinarith have hfrac0 : 0 ≤ 2*C / W p C K2 y := div_nonneg (by linarith) hW.le calc θ y * (2*C / W p C K2 y) ≤ 1 * (C / y) := mul_le_mul hθ1 hfrac hfrac0 zero_le_one _ = C / y := one_mul _ obtain ⟨S1, hS1⟩ : ∃ v, v = θ 1 * (2*C / W p C K2 1) := ⟨_, rfl⟩ have hS1pos : 0 < S1 := by rw [hS1, ← (htr 1 one_pos).2.2] exact Ssig_pos p hC hK2 hDa hτ (htr 1 one_pos).1 -- a rising pair and a falling pair, moved to the curve parameter obtain ⟨ya, hya⟩ : ∃ v : ℝ, v = min (1/2) (K * S1 / 2) := ⟨_, rfl⟩ have hya0 : 0 < ya := by rw [hya]; exact lt_min (by norm_num) (by positivity) have hya1 : ya < 1 := by rw [hya]; exact lt_of_le_of_lt (min_le_left _ _) (by norm_num) have hSa : θ ya * (2*C / W p C K2 ya) ≤ S1 := by have h := hSlo ya hya0 have h2 : ya / K ≤ S1 / 2 := by rw [div_le_iff₀ hK] have := min_le_right (1/2:ℝ) (K * S1 / 2) rw [← hya] at this linarith linarith obtain ⟨yb, hyb⟩ : ∃ v : ℝ, v = max 2 (2 * C / S1) := ⟨_, rfl⟩ have hyb1 : 1 < yb := by rw [hyb]; exact lt_of_lt_of_le (by norm_num) (le_max_left _ _) have hyb0 : 0 < yb := by linarith have hSb : θ yb * (2*C / W p C K2 yb) ≤ S1 := by have h := hShi yb hyb0 have h2 : C / yb ≤ S1 / 2 := by rw [div_le_iff₀ hyb0] have := le_max_right (2:ℝ) (2 * C / S1) rw [← hyb] at this have h3 : 2 * C / S1 * S1 = 2 * C := by field_simp nlinarith [mul_le_mul_of_nonneg_left this hS1pos.le] linarith have hup : ∃ u ∈ Ioo (smin Da τ) 1, ∃ v ∈ Ioo (smin Da τ) 1, u < v ∧ Ssig p C K2 K Da τ u ≤ Ssig p C K2 K Da τ v := by refine ⟨_, (htr ya hya0).1, _, (htr 1 one_pos).1, hsh (mem_Ioi.mpr hya0) (mem_Ioi.mpr one_pos) hya1, ?_⟩ rw [(htr ya hya0).2.2, (htr 1 one_pos).2.2, ← hS1] exact hSa have hdown : ∃ u ∈ Ioo (smin Da τ) 1, ∃ v ∈ Ioo (smin Da τ) 1, u < v ∧ Ssig p C K2 K Da τ v ≤ Ssig p C K2 K Da τ u := by refine ⟨_, (htr 1 one_pos).1, _, (htr yb hyb0).1, hsh (mem_Ioi.mpr one_pos) (mem_Ioi.mpr hyb0) hyb1, ?_⟩ rw [(htr yb hyb0).2.2, (htr 1 one_pos).2.2, ← hS1] exact hSb have hc : ∀ s ∈ Ioo (smin Da τ) 1, 0 < Ssig p C K2 K Da τ s * ((1 + eps Da (Qf Da τ s) s) / (s - Qf Da τ s)) := by intro s hs have hs' := mem_of_smin hDa hτ hs have he := eps_nonneg hDa hs' (Qf_pos hDa hτ hs') exact mul_pos (Ssig_pos p hC hK2 hDa hτ hs) (div_pos (by linarith) (sub_pos.mpr (Qf_lt hDa hτ hs))) obtain ⟨s0, hs0, hmono, hanti⟩ := unimodal_core (c := fun s => Ssig p C K2 K Da τ s * ((1 + eps Da (Qf Da τ s) s) / (s - Qf Da τ s))) (L := Lam p C K2 K Da τ) (fun s hs => hasDerivAt_Ssig p hC hK2 hK hDa hτ hs) hc (Lam_strictAnti p hC hK2 hK hDa hτ) hup hdown have hy0 := yf_pos hK hDa hτ hs0 have hsh0 : θ (yf K Da τ s0) * (yf K Da τ s0 + K) / yf K Da τ s0 = s0 := hyf.injOn (htr _ hy0).1 hs0 (htr _ hy0).2.1 refine ⟨yf K Da τ s0, hy0, ?_, ?_⟩ · intro y1 hy1 y2 hy2 hlt have hle : θ y2 * (y2 + K) / y2 ≤ s0 := by rw [← hsh0] exact hsh.monotoneOn (mem_Ioi.mpr hy2.1) (mem_Ioi.mpr hy0) hy2.2 have hl12 := hsh (mem_Ioi.mpr hy1.1) (mem_Ioi.mpr hy2.1) hlt have h := hmono ⟨(htr y1 hy1.1).1.1, le_trans hl12.le hle⟩ ⟨(htr y2 hy2.1).1.1, hle⟩ hl12 rw [(htr y1 hy1.1).2.2, (htr y2 hy2.1).2.2] at h exact h · intro y1 hy1 y2 hy2 hlt have hy1' : 0 < y1 := lt_of_lt_of_le hy0 hy1 have hy2' : 0 < y2 := lt_of_lt_of_le hy0 hy2 have hge : s0 ≤ θ y1 * (y1 + K) / y1 := by rw [← hsh0] exact hsh.monotoneOn (mem_Ioi.mpr hy0) (mem_Ioi.mpr hy1') hy1 have hl12 := hsh (mem_Ioi.mpr hy1') (mem_Ioi.mpr hy2') hlt have h := hanti ⟨hge, (htr y1 hy1').1.2⟩ ⟨le_trans hge hl12.le, (htr y2 hy2').1.2⟩ hl12 rw [(htr y1 hy1').2.2, (htr y2 hy2').2.2] at h exact h /-- The two-compartment rate law has the exact implicit solution Elev = k K t. -/ lemma ode_level {k K Da y : ℝ} (hK : 0 < K) (hDa : 0 ≤ Da) (hy : 0 < y) {θ : ℝ → ℝ} (hode : ∀ u, 0 ≤ u → HasDerivAt θ (k * (y * (1 - θ u) - K * θ u) / (1 + Da * (1 - θ u))) u) (h0 : θ 0 = 0) (hb : ∀ u, 0 ≤ u → θ u * (y + K) < y) {t : ℝ} (ht : 0 ≤ t) : Elev K Da (θ t) y = k * K * t := by have hg : ∀ u, 0 ≤ u → HasDerivAt (fun u => Elev K Da (θ u) y - k * K * u) 0 u := by intro u hu have hb' := hb u hu have hs := ((hode u hu).mul_const (y + K)).div_const y have hs1 : θ u * (y + K) / y < 1 := by rw [div_lt_one hy]; exact hb' have hL := (hasDerivAt_Lf hs1).comp u hs have h := ((hL.const_mul ((K / (y + K)) * (1 + Da * (K / (y + K))))).add (hs.const_mul (Da * (K / (y + K)) * (1 - K / (y + K))))).sub ((hasDerivAt_id' u).const_mul (k * K)) refine (h : HasDerivAt (fun u => Elev K Da (θ u) y - k * K * u) _ u).congr_deriv ?_ have hθ1 : θ u < 1 := by nlinarith have hden : 1 + Da * (1 - θ u) ≠ 0 := by have := mul_nonneg hDa (sub_nonneg.mpr hθ1.le) exact (by linarith : (0:ℝ) < 1 + Da * (1 - θ u)).ne' have h1s : 1 - θ u * (y + K) / y ≠ 0 := (sub_pos.mpr hs1).ne' have h2 : y - θ u * (y + K) ≠ 0 := (sub_pos.mpr hb').ne' have hyK : y + K ≠ 0 := by linarith have hy0 : y ≠ 0 := hy.ne' obtain ⟨N, hN⟩ : ∃ N, N = y * (1 - θ u) - K * θ u := ⟨_, rfl⟩ have hN0 : N ≠ 0 := by rw [hN] intro hc apply h2 linarith have e1 : 1 - θ u * (y + K) / y = N / y := by rw [hN] field_simp ring rw [e1, ← hN] field_simp rw [hN] ring have h := const_of_deriv_zero hg ht have hz : Elev K Da (θ 0) y = 0 := by rw [h0] simp [Elev, Lf_zero] rw [hz] at h linarith /-- Capstone: sensor surface with mass transport, read at any time t. For every bulk concentration y let theta(y, .) solve the two-compartment rate law from a bare surface and stay below equilibrium. Then the labeled signal theta(y, t) * 2C/W has exactly one peak in y, for any detection-antibody profile (equilibrium or kinetic). -/ theorem surface_one_peak (p : Profile) {C K2 K Da k t : ℝ} (hC : 0 < C) (hK2 : 0 < K2) (hK : 0 < K) (hDa : 0 ≤ Da) (hk : 0 < k) (ht : 0 < t) (θ : ℝ → ℝ → ℝ) (hode : ∀ y, 0 < y → ∀ u, 0 ≤ u → HasDerivAt (θ y) (k * (y * (1 - θ y u) - K * θ y u) / (1 + Da * (1 - θ y u))) u) (h0 : ∀ y, 0 < y → θ y 0 = 0) (hb : ∀ y, 0 < y → ∀ u, 0 ≤ u → θ y u * (y + K) < y) : ∃ y0 : ℝ, 0 < y0 ∧ StrictMonoOn (fun y => θ y t * (2*C / W p C K2 y)) (Ioc 0 y0) ∧ StrictAntiOn (fun y => θ y t * (2*C / W p C K2 y)) (Ici y0) := by have hτ : 0 < k * K * t := mul_pos (mul_pos hk hK) ht apply surface_one_peak_level p hC hK2 hK hDa hτ (fun y => θ y t) intro y hy show 0 < θ y t ∧ θ y t * (y + K) < y ∧ Elev K Da (θ y t) y = k * K * t have hE := ode_level hK hDa hy (hode y hy) (h0 y hy) (hb y hy) ht.le refine ⟨pos_of_Elev_pos hK hDa hy (by rw [hE]; exact hτ), hb y hy t ht.le, hE⟩ end Hook #print axioms Hook.one_peak #print axioms Hook.kinetic_one_peak #print axioms Hook.sandwich_closed_form #print axioms Hook.tern_times_free #print axioms Hook.peak_ge #print axioms Hook.kinetic_peak_ge #print axioms Hook.kinetic_hook_first #print axioms Hook.surface_one_peak #print axioms Hook.surface_one_peak_level