import OAI.Combinatorics.PerfectMatching.DyadicEnvelope namespace OAI section namespace BinaryMatching.Algorithm noncomputable section open Finset lemma concave_affine_chord {S : Set ℝ} {f : ℝ → ℝ} (hf : ConcaveOn ℝ S f) {l u t p c : ℝ} (hl : l∈S) (hu : u∈S) (hlu : l exact Or.inl (by simpa only [dyadic_zero] using ht.2) | succ k ih => by_cases h : t≤dyadic (k+1) · exact Or.inl h · right rcases ih with h'|⟨j,hj,hjt⟩ · exact ⟨k,Nat.lt_succ_self k,le_of_not_ge h,h'⟩ · exact ⟨j,Nat.lt_succ_of_lt hj,hjt⟩ def phi (t : ℝ) : ℝ := Real.negMulLog t / Real.log 2 lemma log_two_pos : 0 if b then t else 1-t) ∈ MatchingEntropy.probabilitySimplex Bool := by constructor · intro b; cases b <;> simp [ht.1,sub_nonneg.mpr ht.2] · simp have hh := MatchingEntropy.entropy_le_log_card hp simp only [MatchingEntropy.entropy,Fintype.sum_bool,Fintype.card_bool,Bool.false_eq_true, ↓reduceIte,Nat.cast_ofNat] at hh have hn := Real.negMulLog_nonneg (sub_nonneg.mpr ht.2) (by linarith [ht.1] : 1-t≤1) unfold phi apply (div_le_one log_two_pos).2 linarith lemma phi_mul (u v : ℝ) : phi (u*v)=v*phi u+u*phi v := by simp only [phi,Real.negMulLog_mul]; ring lemma phi_lower_first (k : ℕ) {t : ℝ} (ht : t∈Set.Icc 0 (dyadic k)) : (k:ℝ)*t ≤ phi t := by simpa only [add_zero] using concave_affine_chord phi_concave (Set.mem_Ici.mpr le_rfl) (Set.mem_Ici.mpr (dyadic_nonneg k)) (dyadic_pos k) ht (p:=(k:ℝ)) (c:=0) (by simp [phi_zero]) (by rw [phi_dyadic]; ring) lemma phi_lower_chord (j : ℕ) {t : ℝ} (ht : t∈Set.Icc (dyadic (j+1)) (dyadic j)) : ((j:ℝ)-1)*t+dyadic j≤phi t := by apply concave_affine_chord phi_concave (Set.mem_Ici.mpr (dyadic_nonneg _)) (Set.mem_Ici.mpr (dyadic_nonneg _)) (show dyadic (j+1) linarith [hjt.2] end end BinaryMatching.Algorithm end end OAI